<Library xmlns="http://hl7.org/fhir">
   <id value="CMS986FHIRMalnutritionScore"></id>
   <meta>
      <profile value="http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-shareablelibrary"></profile>
      <profile value="http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-computablelibrary"></profile>
      <profile value="http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-publishablelibrary"></profile>
      <profile value="http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-executablelibrary"></profile>
      <profile value="http://hl7.org/fhir/uv/cql/StructureDefinition/cql-library"></profile>
      <profile value="http://hl7.org/fhir/uv/cql/StructureDefinition/elm-json-library"></profile>
      <profile value="http://hl7.org/fhir/uv/cql/StructureDefinition/elm-xml-library"></profile>
   </meta>
   <language value="en"></language>
   <text>
      <status value="extensions"></status>
      <div xmlns="http://www.w3.org/1999/xhtml" class="col-12"> 
         <table class="narrative-table"> 
            <tbody> 
               <tr> 
                  <th colspan="2" scope="row" class="row-header">Metadata</th> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Title</th> 
                  <td class="content-container">CMS986FHIRMalnutritionScore</td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Version</th> 
                  <td class="content-container">1.0.000</td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Identifier</th> 
                  <td class="content-container">CMS986FHIRMalnutritionScore</td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Steward (Publisher)</th> 
                  <td class="content-container">Academy of Nutrition and Dietetics</td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Description</th> 
                  <td class="content-container">CMS986FHIRMalnutritionScore</td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Type</th> 
                  <td class="content-container">[http://terminology.hl7.org/CodeSystem/library-type#logic-library]</td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Data Requirement</th> 
                  <td class="content-container"> 
                     <em>Type</em>: ServiceRequest 
                     <br></br> 
                     <em>Profile(s)</em>:  http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest 
                     <br></br>   
                     <em>Must Support Elements</em>: code, status, status.value, intent, intent.value, authoredOn, authoredOn.value 
                     <br></br>  
                     <em>Code Filter(s)</em>: 
                     <br></br>  
                     <span class="tab-one">
                        <em>Path</em>: code
                     </span> 
                     <br></br>  
                     <span class="tab-one">
                        <em>ValueSet</em>:
                     </span> http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.101 
                     <br></br>   
                  </td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Data Requirement</th> 
                  <td class="content-container"> 
                     <em>Type</em>: ServiceRequest 
                     <br></br> 
                     <em>Profile(s)</em>:  http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest 
                     <br></br>   
                     <em>Must Support Elements</em>: code, status, status.value, intent, intent.value, authoredOn, authoredOn.value 
                     <br></br>  
                     <em>Code Filter(s)</em>: 
                     <br></br>  
                     <span class="tab-one">
                        <em>Path</em>: code
                     </span> 
                     <br></br>  
                     <span class="tab-one">
                        <em>ValueSet</em>:
                     </span> http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.91 
                     <br></br>   
                  </td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Data Requirement</th> 
                  <td class="content-container"> 
                     <em>Type</em>: Procedure 
                     <br></br> 
                     <em>Profile(s)</em>:  http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-procedure 
                     <br></br>   
                     <em>Must Support Elements</em>: code, status, status.value, performed 
                     <br></br>  
                     <em>Code Filter(s)</em>: 
                     <br></br>  
                     <span class="tab-one">
                        <em>Path</em>: code
                     </span> 
                     <br></br>  
                     <span class="tab-one">
                        <em>ValueSet</em>:
                     </span> http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.101 
                     <br></br>   
                  </td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Data Requirement</th> 
                  <td class="content-container"> 
                     <em>Type</em>: Procedure 
                     <br></br> 
                     <em>Profile(s)</em>:  http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-procedure 
                     <br></br>   
                     <em>Must Support Elements</em>: code, status, status.value, performed 
                     <br></br>  
                     <em>Code Filter(s)</em>: 
                     <br></br>  
                     <span class="tab-one">
                        <em>Path</em>: code
                     </span> 
                     <br></br>  
                     <span class="tab-one">
                        <em>ValueSet</em>:
                     </span> http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.91 
                     <br></br>   
                  </td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Data Requirement</th> 
                  <td class="content-container"> 
                     <em>Type</em>: Condition 
                     <br></br> 
                     <em>Profile(s)</em>:  http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-problems-health-concerns 
                     <br></br>   
                     <em>Must Support Elements</em>: code 
                     <br></br>  
                     <em>Code Filter(s)</em>: 
                     <br></br>  
                     <span class="tab-one">
                        <em>Path</em>: code
                     </span> 
                     <br></br>  
                     <span class="tab-one">
                        <em>ValueSet</em>:
                     </span> http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.55 
                     <br></br>   
                  </td> 
               </tr> 
               <tr> 
                  <th scope="row" class="row-header">Data Requirement</th> 
                  <td class="content-container"> 
                     <em>Type</em>: Encounter 
                     <br></br> 
                     <em>Profile(s)</em>:  http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter 
                     <br></br>   
                     <em>Must Support Elements</em>: type, period, status, status.value 
                     <br></br>  
                     <em>Code Filter(s)</em>: 
                     <br></br>  
                     <span class="tab-one">
                        <em>Path</em>: type
                     </span> 
                     <br></br>  
                     <span class="tab-one">
                        <em>ValueSet</em>:
                     </span> http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307 
                     <br></br>   
                  </td> 
               </tr> 
               <tr> 
                  <th colspan="2" scope="row" class="row-header">Library Content</th> 
               </tr>  
               <tr> 
                  <th scope="row" class="row-header">CQL Content</th> 
                  <td> 
                     <a name="cql-content"> </a> 
                     <pre style="border: none;" class="content-container highlight language-cql"><code class="language-cql">library CMS986FHIRMalnutritionScore version '1.0.000'

using QICore version '6.0.0'

include FHIRHelpers version '4.4.000' called FHIRHelpers
include SupplementalDataElements version '5.1.000' called SDE
include QICoreCommon version '4.0.000' called QICoreCommon
include CQMCommon version '4.1.000' called CQMCommon
include Status version '1.15.000' called Status

valueset "Encounter Inpatient": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307'
valueset "Hospice Status": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.101'
valueset "Hospice Care Referral or Admission": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.365'
valueset "Dietitian Referral": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.91'
valueset "Malnutrition Diagnosis": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.55'
valueset "Malnutrition Risk Screening": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.92'
valueset "Malnutrition Screening Finding of At Risk Result": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.89'
valueset "Malnutrition Screening Finding of Not At Risk Result": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.34'
valueset "Nutrition Assessment": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.21'
valueset "Nutrition Assessment Status Finding of Moderately Malnourished": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.47'
valueset "Nutrition Assessment Status Finding of Well Nourished or Not Malnourished or Mildly Malnourished": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.96'
valueset "Nutrition Assessment Status Finding of Severely Malnourished": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.43'
valueset "Nutrition Care Plan": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.93'

parameter "Measurement Period" Interval&lt;DateTime&gt;

context Patient

define "SDE Ethnicity":
  SDE."SDE Ethnicity"

define "SDE Payer Type":
  SDE."SDE Payer"

define "SDE Race":
  SDE."SDE Race"

define "SDE Sex":
  SDE."SDE Sex"

define "Measure Population":
  "Initial Population"

define "Initial Population":
  [Encounter: "Encounter Inpatient"] EncounterInpatient
    where EncounterInpatient.period ends during day of "Measurement Period"
      and AgeInYearsAt(date from start of EncounterInpatient.period) &gt;= 18
      and ( duration in hours of EncounterInpatient.period &gt;= 24 )
      and EncounterInpatient.status = 'finished'

define "Measure Population Exclusion":
  "Encounters with Discharge for Hospice Care"
    union "Encounters with Hospice during Eligible Encounter"

define "Encounters with Discharge for Hospice Care":
  "Measure Population" QualifyingEncounter
    where QualifyingEncounter.hospitalization.dischargeDisposition in "Hospice Care Referral or Admission"

/*define "Intervention Hospice Care":
    ( ["ServiceRequest": "Hospice Status"] HospiceStatusOrder
    where HospiceStatusOrder.status in { 'active', 'completed', 'on-hold' }
        and HospiceStatusOrder.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
  )
    union ( ["Procedure": "Hospice Status"] HospiceStatusPerformed
            where HospiceStatusPerformed.status in { 'completed', 'in-progress' } 
           )

define "Encounters with Hospice during Eligible Encounter":
    "Measure Population" QualifyingEncounter
    with "Intervention Hospice Care" HospiceStatus
            such that Coalesce (start of HospiceStatus.performed.toInterval(), HospiceStatus.authoredOn) during day of QualifyingEncounter.hospitalizationWithObservation ( )
*/
//Testing definitions based on Codev comment



define "Intervention Hospice Care":
  ( ["ServiceRequest": "Hospice Status"] HospiceStatusOrder
      where HospiceStatusOrder.status in { 'active', 'completed', 'on-hold' }
        and HospiceStatusOrder.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
      return HospiceStatusOrder.authoredOn
  )
    union ( ["Procedure": "Hospice Status"] HospiceStatusPerformed
        where HospiceStatusPerformed.status in { 'completed', 'in-progress' }
        return start of HospiceStatusPerformed.performed.toInterval ( )
    )

define "Encounters with Hospice during Eligible Encounter":
  "Measure Population" QualifyingEncounter
    with "Intervention Hospice Care" HospiceStatusDate
      such that HospiceStatusDate during day of QualifyingEncounter.hospitalizationWithObservation ( )

/*define "Intervention Dietitian Referral":
( ["ServiceRequest": "Dietitian Referral"] DietitianReferralOrder
    where DietitianReferralOrder.status in { 'active', 'completed', 'on-hold' }
        and DietitianReferralOrder.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
  
  )
    union ( ["Procedure": "Dietitian Referral"] DietitianReferralPerformed
            where DietitianReferralPerformed.status in { 'completed', 'in-progress' } 
           )

define "Encounters with Dietitian Referral":
    "Measure Population" QualifyingEncounter
    with "Intervention Dietitian Referral" DietitianReferral
            such that Coalesce (start of DietitianReferral.performed.toInterval(), DietitianReferral.authoredOn) during day of QualifyingEncounter.hospitalizationWithObservation ( )
*/
//New definition from Codev comments



define "Intervention Dietitian Referral":
  ( ["ServiceRequest": "Dietitian Referral"] DietitianReferralOrder
      where DietitianReferralOrder.status in { 'active', 'completed', 'on-hold' }
        and DietitianReferralOrder.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
      return DietitianReferralOrder.authoredOn
  )
    union ( ["Procedure": "Dietitian Referral"] DietitianReferralPerformed
        where DietitianReferralPerformed.status in { 'completed', 'in-progress' }
        return start of DietitianReferralPerformed.performed.toInterval ( )
    )

define "Encounters with Dietitian Referral":
  "Measure Population" QualifyingEncounter
    with "Intervention Dietitian Referral" DietitianReferralDate
      such that DietitianReferralDate during day of QualifyingEncounter.hospitalizationWithObservation ( )

define "Encounters with Malnutrition Risk Screening":
  "Encounters with Malnutrition Risk Screening Not At Risk"
    union "Encounters with Malnutrition Risk Screening At Risk"

define "Encounters with Malnutrition Risk Screening or with Dietitian Referral":
  "Encounters with Malnutrition Risk Screening"
    union "Encounters with Dietitian Referral"

define "Encounters with Malnutrition Risk Screening Not At Risk":
  "Measure Population" QualifyingEncounter
    with ["ObservationScreeningAssessment": "Malnutrition Risk Screening"] MalnutritionRiskScreening
      such that MalnutritionRiskScreening.status in { 'final', 'amended', 'corrected' }
        and MalnutritionRiskScreening.effective.toInterval ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
        and ( MalnutritionRiskScreening.value as Concept in "Malnutrition Screening Finding of Not At Risk Result" )

define "Encounters with Malnutrition Not At Risk Screening and without Dietitian Referral":
  "Encounters with Malnutrition Risk Screening Not At Risk"
    except "Encounters with Dietitian Referral"

define "Encounters with Malnutrition Risk Screening At Risk":
  "Measure Population" QualifyingEncounter
    with ["ObservationScreeningAssessment": "Malnutrition Risk Screening"] MalnutritionRiskScreening
      such that MalnutritionRiskScreening.status in { 'final', 'amended', 'corrected' }
        and MalnutritionRiskScreening.effective.toInterval ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
        and ( MalnutritionRiskScreening.value as Concept in "Malnutrition Screening Finding of At Risk Result" )

define "Encounters with Malnutrition Risk Screening At Risk or with Dietitian Referral":
  "Encounters with Malnutrition Risk Screening At Risk"
    union "Encounters with Dietitian Referral"
   

/*define function "Last Nutrition Assessment Day During Encounter"(QualifyingEncounter Encounter):
  Max("Nutrition Assessment Performed" NutritionAssessmentTuple
    where NutritionAssessmentTuple.HospEncId = QualifyingEncounter.id
    return NutritionAssessmentTuple.NutrAssessTimingLatest
  )

define "Nutrition Assessment Performed":
    from
    "Measure Population" QualifyingEncounter,
    ["ObservationScreeningAssessment": "Nutrition Assessment"] NutritionAssessment
        where NutritionAssessment.status in { 'final', 'amended', 'corrected' }
            and NutritionAssessment.effective.toInterval ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
            and NutritionAssessment.value is not null
            return Tuple {
        HospEncId: QualifyingEncounter.id,
        NutrAssessTimingLatest: NutritionAssessment.effective.latest()
        }
*/
//Test definition per CODev feedback



define function "Last Nutrition Assessment Day During Encounter"(QualifyingEncounter Encounter):
  Max(["ObservationScreeningAssessment": "Nutrition Assessment"] NutritionAssessment
      where NutritionAssessment.status in { 'final', 'amended', 'corrected' }
        and NutritionAssessment.effective.toInterval() during QualifyingEncounter.hospitalizationWithObservation()
        and NutritionAssessment.value is not null
      return NutritionAssessment.effective.latest()
  )

define "Encounter With Most Recent Nutrition Assessment And Identified Status":
  "Encounters with Malnutrition Risk Screening At Risk or with Dietitian Referral" QualifyingEncounter
    with ["ObservationScreeningAssessment": "Nutrition Assessment"] NutritionAssessment
      such that ( NutritionAssessment.status in { 'final', 'amended', 'corrected' }
          and NutritionAssessment.effective.toInterval ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
          and ( NutritionAssessment.value as Concept in "Nutrition Assessment Status Finding of Well Nourished or Not Malnourished or Mildly Malnourished"
              or ( NutritionAssessment.value as Concept in "Nutrition Assessment Status Finding of Moderately Malnourished" )
              or ( NutritionAssessment.value as Concept in "Nutrition Assessment Status Finding of Severely Malnourished" )
          )
          and NutritionAssessment.effective.latest ( ) same day as "Last Nutrition Assessment Day During Encounter"(QualifyingEncounter)
      )

define "Encounter With Most Recent Nutrition Assessment Status of Moderately Or Severely Malnourished":
  "Measure Population" QualifyingEncounter
    with ["ObservationScreeningAssessment": "Nutrition Assessment"] NutritionAssessment
      such that NutritionAssessment.status in { 'final', 'amended', 'corrected' }
        and NutritionAssessment.effective.toInterval ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
        and ( NutritionAssessment.value as Concept in "Nutrition Assessment Status Finding of Moderately Malnourished"
            or NutritionAssessment.value as Concept in "Nutrition Assessment Status Finding of Severely Malnourished"
        )
        and NutritionAssessment.effective.latest ( ) same day as "Last Nutrition Assessment Day During Encounter"(QualifyingEncounter)

define "Encounter With Most Recent Nutrition Assessment Status of Not or Mildly Malnourished":
  "Measure Population" QualifyingEncounter
    with ["ObservationScreeningAssessment": "Nutrition Assessment"] NutritionAssessment
      such that ( NutritionAssessment.status in { 'final', 'amended', 'corrected' }
          and NutritionAssessment.effective.toInterval ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
          and ( NutritionAssessment.value as Concept in "Nutrition Assessment Status Finding of Well Nourished or Not Malnourished or Mildly Malnourished" )
          and NutritionAssessment.effective.latest ( ) same day as "Last Nutrition Assessment Day During Encounter"(QualifyingEncounter)
      )

define "Encounters with Malnutrition Diagnosis":
  ( "Measure Population" QualifyingEncounter
      where exists ( "Has Malnutrition Diagnosis" MalnutritionDiagnosis
          where MalnutritionDiagnosis.prevalenceInterval ( ) overlaps day of QualifyingEncounter.hospitalizationWithObservation ( )
      )
  )
    union "Encounters With Encounter Diagnosis Of Malnutrition Diagnosis"

define "Has Malnutrition Diagnosis":
  [ConditionProblemsHealthConcerns: "Malnutrition Diagnosis"] MalnutritionDiagnosis
    where MalnutritionDiagnosis.prevalenceInterval ( ) overlaps "Measurement Period"
      and MalnutritionDiagnosis.isVerified ( )

define "Encounters With Encounter Diagnosis Of Malnutrition Diagnosis":
  "Measure Population" QualifyingEncounter
    where QualifyingEncounter.reasonCode in "Malnutrition Diagnosis"
      or QualifyingEncounter.encounterDiagnosis ( ).verified ( ).code in "Malnutrition Diagnosis"

define fluent function isVerified(condition Choice&lt;QICore.ConditionProblemsHealthConcerns, QICore.ConditionEncounterDiagnosis&gt;):
  condition.verificationStatus is not null implies ( condition.verificationStatus ~ QICoreCommon."confirmed"
      or condition.verificationStatus ~ QICoreCommon."unconfirmed"
      or condition.verificationStatus ~ QICoreCommon."provisional"
      or condition.verificationStatus ~ QICoreCommon."differential"
  )

define "Encounters with Nutrition Care Plan":
  "Measure Population" QualifyingEncounter
    with ["Procedure": "Nutrition Care Plan"] NutritionCarePlan
      such that NutritionCarePlan.status in { 'completed', 'in-progress' }
        and NutritionCarePlan.performed.earliest ( ) during QualifyingEncounter.hospitalizationWithObservation ( )

define function "Measure Observation 1"(MalnutritionRiskScreening Encounter):
  if "Encounters with Malnutrition Risk Screening or with Dietitian Referral" contains MalnutritionRiskScreening then 1 
    else 0

define function "Measure Observation 2"(NutritionAssessment Encounter):
  if "Encounters with Malnutrition Not At Risk Screening and without Dietitian Referral" contains NutritionAssessment then 0 
    else if "Encounters with Malnutrition Risk Screening At Risk or with Dietitian Referral" contains NutritionAssessment then if "Encounter With Most Recent Nutrition Assessment And Identified Status" contains NutritionAssessment then 1 
    else 0 
    else 0

define function "Measure Observation 3"(MalnutritionDiagnosis Encounter):
  if "Encounters with Malnutrition Not At Risk Screening and without Dietitian Referral" contains MalnutritionDiagnosis then 0 
    else if "Encounters with Malnutrition Risk Screening At Risk or with Dietitian Referral" contains MalnutritionDiagnosis then if "Encounters with Malnutrition Diagnosis" contains MalnutritionDiagnosis then if "Encounter With Most Recent Nutrition Assessment Status of Not or Mildly Malnourished" contains MalnutritionDiagnosis then 0 
    else if "Encounter With Most Recent Nutrition Assessment Status of Moderately Or Severely Malnourished" contains MalnutritionDiagnosis then 1 
    else 0 
    else 0 
    else 0

define function "Measure Observation 4"(NutritionCarePlan Encounter):
  if "Encounters with Malnutrition Not At Risk Screening and without Dietitian Referral" contains NutritionCarePlan then 0 
    else if "Encounters with Malnutrition Risk Screening At Risk or with Dietitian Referral" contains NutritionCarePlan then if "Encounters with Nutrition Care Plan" contains NutritionCarePlan then if "Encounter With Most Recent Nutrition Assessment Status of Not or Mildly Malnourished" contains NutritionCarePlan then 0 
    else if "Encounter With Most Recent Nutrition Assessment Status of Moderately Or Severely Malnourished" contains NutritionCarePlan then 1 
    else 0 
    else 0 
    else 0

define function "Total Malnutrition Care Score Eligible Occurrences"(QualifyingEncounter Encounter):
  if "Encounters with Malnutrition Risk Screening or with Dietitian Referral" contains QualifyingEncounter
    and "Encounters with Malnutrition Risk Screening Not At Risk" contains QualifyingEncounter
    and not ( "Encounters with Dietitian Referral" contains QualifyingEncounter ) then 1 
    else if ( "Encounters with Malnutrition Risk Screening or with Dietitian Referral" contains QualifyingEncounter
      and "Encounters with Malnutrition Risk Screening At Risk" contains QualifyingEncounter
      or "Encounters with Dietitian Referral" contains QualifyingEncounter
  )
    and "Encounter With Most Recent Nutrition Assessment Status of Not or Mildly Malnourished" contains QualifyingEncounter
    or not ( "Encounter With Most Recent Nutrition Assessment And Identified Status" contains QualifyingEncounter ) then 2 
    else 4

define function "Measure Observation Total Malnutrition Components Score"(QualifyingEncounter Encounter):
  Sum({ "Measure Observation 1"(QualifyingEncounter), "Measure Observation 2"(QualifyingEncounter), "Measure Observation 3"(QualifyingEncounter), "Measure Observation 4"(QualifyingEncounter) })

define function "Measure Observation Total Malnutrition Care Score as Percentage"(QualifyingEncounter Encounter):
  100 * ( "Measure Observation Total Malnutrition Components Score"(QualifyingEncounter) / "Total Malnutrition Care Score Eligible Occurrences"(QualifyingEncounter) )</code></pre> 
                  </td> 
               </tr>   
               <tr> 
                  <th colspan="2" scope="row" class="row-header">Generated using version 0.4.9 of the sample-content-ig Liquid templates</th> 
               </tr> 
            </tbody> 
         </table> 
      </div>
   </text>
   <url value="https://madie.cms.gov/Library/CMS986FHIRMalnutritionScore"></url>
   <identifier>
      <use value="official"></use>
      <system value="https://madie.cms.gov/login"></system>
      <value value="CMS986FHIRMalnutritionScore"></value>
   </identifier>
   <version value="1.0.000"></version>
   <name value="CMS986FHIRMalnutritionScore"></name>
   <title value="CMS986FHIRMalnutritionScore"></title>
   <status value="active"></status>
   <experimental value="false"></experimental>
   <type>
      <coding>
         <system value="http://terminology.hl7.org/CodeSystem/library-type"></system>
         <code value="logic-library"></code>
      </coding>
   </type>
   <date value="2025-11-24T17:18:50+00:00"></date>
   <publisher value="Academy of Nutrition and Dietetics"></publisher>
   <description value="CMS986FHIRMalnutritionScore"></description>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="QICore model information"></display>
      <resource value="http://hl7.org/fhir/Library/QICore-ModelInfo"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Library FHIRHelpers"></display>
      <resource value="https://madie.cms.gov/Library/FHIRHelpers|4.4.000"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Library QICoreCommon"></display>
      <resource value="https://madie.cms.gov/Library/QICoreCommon|4.0.000"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Library CQMCommon"></display>
      <resource value="https://madie.cms.gov/Library/CQMCommon|4.1.000"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Library SDE"></display>
      <resource value="https://madie.cms.gov/Library/SupplementalDataElements|5.1.000"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Library Status"></display>
      <resource value="https://madie.cms.gov/Library/Status|1.15.000"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Encounter Inpatient"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Hospice Care Referral or Admission"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.365"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Hospice Status"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.101"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Malnutrition Risk Screening"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.92"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Malnutrition Screening Finding of Not At Risk Result"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.34"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Malnutrition Screening Finding of At Risk Result"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.89"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Dietitian Referral"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.91"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Nutrition Assessment"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.21"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Nutrition Assessment Status Finding of Well Nourished or Not Malnourished or Mildly Malnourished"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.96"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Nutrition Assessment Status Finding of Moderately Malnourished"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.47"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Nutrition Assessment Status Finding of Severely Malnourished"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.43"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Malnutrition Diagnosis"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.55"></resource>
   </relatedArtifact>
   <relatedArtifact>
      <type value="depends-on"></type>
      <display value="Value set Nutrition Care Plan"></display>
      <resource value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.93"></resource>
   </relatedArtifact>
   <dataRequirement>
      <type value="ServiceRequest"></type>
      <profile value="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest"></profile>
      <mustSupport value="code"></mustSupport>
      <mustSupport value="status"></mustSupport>
      <mustSupport value="status.value"></mustSupport>
      <mustSupport value="intent"></mustSupport>
      <mustSupport value="intent.value"></mustSupport>
      <mustSupport value="authoredOn"></mustSupport>
      <mustSupport value="authoredOn.value"></mustSupport>
      <codeFilter>
         <path value="code"></path>
         <valueSet value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.101"></valueSet>
      </codeFilter>
   </dataRequirement>
   <dataRequirement>
      <type value="ServiceRequest"></type>
      <profile value="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest"></profile>
      <mustSupport value="code"></mustSupport>
      <mustSupport value="status"></mustSupport>
      <mustSupport value="status.value"></mustSupport>
      <mustSupport value="intent"></mustSupport>
      <mustSupport value="intent.value"></mustSupport>
      <mustSupport value="authoredOn"></mustSupport>
      <mustSupport value="authoredOn.value"></mustSupport>
      <codeFilter>
         <path value="code"></path>
         <valueSet value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.91"></valueSet>
      </codeFilter>
   </dataRequirement>
   <dataRequirement>
      <type value="Procedure"></type>
      <profile value="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-procedure"></profile>
      <mustSupport value="code"></mustSupport>
      <mustSupport value="status"></mustSupport>
      <mustSupport value="status.value"></mustSupport>
      <mustSupport value="performed"></mustSupport>
      <codeFilter>
         <path value="code"></path>
         <valueSet value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.101"></valueSet>
      </codeFilter>
   </dataRequirement>
   <dataRequirement>
      <type value="Procedure"></type>
      <profile value="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-procedure"></profile>
      <mustSupport value="code"></mustSupport>
      <mustSupport value="status"></mustSupport>
      <mustSupport value="status.value"></mustSupport>
      <mustSupport value="performed"></mustSupport>
      <codeFilter>
         <path value="code"></path>
         <valueSet value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.91"></valueSet>
      </codeFilter>
   </dataRequirement>
   <dataRequirement>
      <type value="Condition"></type>
      <profile value="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-problems-health-concerns"></profile>
      <mustSupport value="code"></mustSupport>
      <codeFilter>
         <path value="code"></path>
         <valueSet value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1095.55"></valueSet>
      </codeFilter>
   </dataRequirement>
   <dataRequirement>
      <type value="Encounter"></type>
      <profile value="http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter"></profile>
      <mustSupport value="type"></mustSupport>
      <mustSupport value="period"></mustSupport>
      <mustSupport value="status"></mustSupport>
      <mustSupport value="status.value"></mustSupport>
      <codeFilter>
         <path value="type"></path>
         <valueSet value="http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307"></valueSet>
      </codeFilter>
   </dataRequirement>
   <content>
      <contentType value="text/cql"></contentType>
      <data value="[encoded data, 23632 characters]"></data>
   </content>
   <content>
      <contentType value="application/elm+json"></contentType>
      <data value="[encoded data, 1029844 characters]"></data>
   </content>
</Library>