CMS FHIR Prototype Measure Calculation Tool IG
0.1.0 - CI Build

CMS FHIR Prototype Measure Calculation Tool IG, published by HL7 International - [Some] Work Group. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/mct-ig/ and changes regularly. See the Directory of published versions

## : MAT Global Common Functions QICore4 - TTL Representation

Draft as of 2026-02-27

Raw ttl | Download

    @prefix fhir: <http://hl7.org/fhir/> .
    @prefix owl: <http://www.w3.org/2002/07/owl#> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

    # - resource -------------------------------------------------------------------

     a fhir:Library ;
      fhir:nodeRole fhir:treeRoot ;
      fhir:id [ fhir:v "MATGlobalCommonFunctionsQICore4"] ; #
      fhir:text [
    fhir:status [ fhir:v "extensions" ] ;
    fhir:div [ fhir:v "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n    <table class=\"grid dict\">\n        \n        <tr>\n            <th scope=\"row\"><b>Id: </b></th>\n            <td style=\"padding-left: 4px;\">MATGlobalCommonFunctionsQICore4</td>\n        </tr>\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Url: </b></th>\n            <td style=\"padding-left: 4px;\"><a href=\"Library-MATGlobalCommonFunctionsQICore4.html\">MAT Global Common Functions QICore4</a></td>\n        </tr>\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Version: </b></th>\n            <td style=\"padding-left: 4px;\">0.1.0</td>\n        </tr>\n        \n        \n        \n        <tr>\n            <th scope=\"row\"><b>Name: </b></th>\n            <td style=\"padding-left: 4px;\">MATGlobalCommonFunctionsQICore4</td>\n        </tr>\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Title: </b></th>\n            <td style=\"padding-left: 4px;\">MAT Global Common Functions QICore4</td>\n        </tr>\n        \n        \n        \n        <tr>\n            <th scope=\"row\"><b>Status: </b></th>\n            <td style=\"padding-left: 4px;\">draft</td>\n        </tr>\n        \n        \n        \n        <tr>\n            <th scope=\"row\"><b>Type: </b></th>\n            <td style=\"padding-left: 4px;\">\n                \n                    \n                        \n                        <p style=\"margin-bottom: 5px;\">\n                            <b>system: </b> <span><a href=\"http://terminology.hl7.org/7.0.1/CodeSystem-library-type.html\">http://terminology.hl7.org/CodeSystem/library-type</a></span>\n                        </p>\n                        \n                        \n                        <p style=\"margin-bottom: 5px;\">\n                            <b>code: </b> <span>logic-library</span>\n                        </p>\n                        \n                        \n                    \n                \n                \n            </td>\n        </tr>\n        \n        \n        \n        <tr>\n            <th scope=\"row\"><b>Date: </b></th>\n            <td style=\"padding-left: 4px;\">2026-02-27 18:11:00+0000</td>\n        </tr>\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Publisher: </b></th>\n            <td style=\"padding-left: 4px;\">HL7 International - [Some] Work Group</td>\n        </tr>\n        \n        \n        \n        \n        \n        \n        <tr>\n            <th scope=\"row\"><b>Jurisdiction: </b></th>\n            <td style=\"padding-left: 4px;\">US</td>\n        </tr>\n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        <tr>\n          <td colspan=\"2\">\n            <table>\n              <tr><th><a id=\"cql-content\"><b>Content: </b></a> text/cql</th></tr>\n              <tr><td><pre><code class=\"language-cql\">/*#xD;\n@update: BTR 2020-03-31 -&amp;gt;#xD;\nIncremented version to 5.0.000#xD;\nUpdated FHIR version to 4.0.1#xD;\nChanged timezone keyword to timezoneoffset for use with CQL 1.4#xD;\nRemoved Normalize Onset in favor of more general Normalize Interval#xD;\nUpdated CodeSystems for ConditionVerificationStatusCodes and RoleCodes#xD;\n#xD;\n@update: BTR 2021-05-13 -&amp;gt;#xD;\nAdded ActiveCondition Codes and Inactive Condition Codes value sets#xD;\nAdded function documentation throughout#xD;\nFixed EDVisit not using Last#xD;\nUpdated prevalence period to use an inclusive boundary if the condition is active#xD;\nAdded HasStart, HasEnd, Earliest, and Latest functions#xD;\nRemoved ToDate and Age calculation functions#xD;\n#xD;\n@update: BTR 2021-06-25 -&amp;gt;#xD;\nAdded GetBaseExtension overloads for Element#xD;\n#xD;\n@update: BTR 2022-05-24 -&amp;gt;#xD;\nUpdate for 2022 AU content#xD;\nRefactor to use CQF.FHIRCommon#xD;\n#xD;\n@update: BTR 2022-06-14 -&amp;gt;#xD;\nUpdate to use QICore#xD;\nRename from MATGlobalCommonFunctionsFHIR4 to MATGlobalCommonFunctionsQICore4#xD;\nAdded fluent functions#xD;\nRemoved Normalize Interval#xD;\n*/#xD;\nlibrary MATGlobalCommonFunctionsQICore4 version '7.0.000'#xD;\n#xD;\nusing QICore version '4.1.1'#xD;\n#xD;\ninclude FHIRHelpers version '4.0.013' called FHIRHelpers#xD;\ninclude QICoreCommon version '1.0.000' called QICoreCommon#xD;\n#xD;\nvalueset &amp;quot;Emergency Department Visit&amp;quot;: 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292'#xD;\nvalueset &amp;quot;Encounter Inpatient&amp;quot;: 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307'#xD;\nvalueset &amp;quot;Intensive Care Unit&amp;quot;: 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1029.206'#xD;\nvalueset &amp;quot;Observation Services&amp;quot;: 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.143'#xD;\nvalueset &amp;quot;Outpatient Surgery Service&amp;quot;: 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.38'#xD;\nvalueset &amp;quot;Present on Admission or Clinically Undetermined&amp;quot;: 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1147.197'#xD;\n#xD;\nparameter &amp;quot;Measurement Period&amp;quot; Interval&amp;lt;DateTime&amp;gt;#xD;\n  default Interval[@2022-01-01T00:00:00.0, @2023-01-01T00:00:00.0)#xD;\n#xD;\ncontext Patient#xD;\n#xD;\ndefine &amp;quot;Inpatient Encounter&amp;quot;:#xD;\n  [Encounter: &amp;quot;Encounter Inpatient&amp;quot;] EncounterInpatient#xD;\n		where EncounterInpatient.status = 'finished'#xD;\n	    and &amp;quot;LengthInDays&amp;quot;(EncounterInpatient.period) &amp;lt;= 120#xD;\n			and EncounterInpatient.period ends during day of &amp;quot;Measurement Period&amp;quot;#xD;\n#xD;\n/*#xD;\n@description: Returns an interval of date values extracted from the input interval of date-time values#xD;\n@comment: This function returns an interval constructed using the `date from` extractor on the start#xD;\nand end values of the input date-time interval. Note that using a precision specifier such as `day of`#xD;\nas part of a timing phrase is preferred to communicate intent to perform day-level comparison, as well#xD;\nas for general readability.#xD;\n*/#xD;\ndefine function &amp;quot;ToDateInterval&amp;quot;(period Interval&amp;lt;DateTime&amp;gt;):#xD;\n  Interval[date from start of period, date from end of period]#xD;\n#xD;\n/*#xD;\nCalculates the difference in calendar days between the start and end of the given interval.#xD;\n*/#xD;\ndefine function &amp;quot;LengthInDays&amp;quot;(Value Interval&amp;lt;DateTime&amp;gt; ):#xD;\n  difference in days between start of Value and end of Value#xD;\n#xD;\n/*#xD;\nCalculates the difference in calendar days between the start and end of the given interval.#xD;\n*/#xD;\ndefine fluent function lengthInDays(Value Interval&amp;lt;DateTime&amp;gt; ):#xD;\n  difference in days between start of Value and end of Value#xD;\n#xD;\n/*#xD;\nReturns the most recent emergency department visit, if any, that occurs 1 hour or less prior to the given encounter.#xD;\n*/#xD;\ndefine function &amp;quot;ED Visit&amp;quot;(TheEncounter Encounter ):#xD;\n  Last(#xD;\n    [Encounter: &amp;quot;Emergency Department Visit&amp;quot;] EDVisit#xD;\n      where EDVisit.status = 'finished'#xD;\n        and EDVisit.period ends 1 hour or less on or before start of TheEncounter.period#xD;\n      sort by end of period#xD;\n    )#xD;\n#xD;\n/*#xD;\nReturns the most recent emergency department visit, if any, that occurs 1 hour or less prior to the given encounter.#xD;\n*/#xD;\ndefine fluent function edVisit(TheEncounter Encounter ):#xD;\n  Last(#xD;\n    [Encounter: &amp;quot;Emergency Department Visit&amp;quot;] EDVisit#xD;\n      where EDVisit.status = 'finished'#xD;\n        and EDVisit.period ends 1 hour or less on or before start of TheEncounter.period#xD;\n      sort by end of period#xD;\n    )#xD;\n#xD;\n/*#xD;\nHospitalization returns the total interval for admission to discharge for the given encounter, or for the admission of any immediately prior emergency department visit to the discharge of the given encounter.#xD;\n*/#xD;\ndefine function &amp;quot;Hospitalization&amp;quot;(TheEncounter Encounter ):#xD;\n  ( &amp;quot;ED Visit&amp;quot;(TheEncounter) ) X#xD;\n    return#xD;\n        if X is null then TheEncounter.period#xD;\n        else Interval[start of X.period, end of TheEncounter.period)#xD;\n#xD;\n/*#xD;\nHospitalization returns the total interval for admission to discharge for the given encounter, or for the admission of any immediately prior emergency department visit to the discharge of the given encounter.#xD;\n*/#xD;\ndefine fluent function hospitalization(TheEncounter Encounter ):#xD;\n  ( &amp;quot;ED Visit&amp;quot;(TheEncounter) ) X#xD;\n    return#xD;\n        if X is null then TheEncounter.period#xD;\n        else Interval[start of X.period, end of TheEncounter.period]#xD;\n#xD;\n/*#xD;\nReturns list of all locations within an encounter, including locations for immediately prior ED visit.#xD;\n*/#xD;\ndefine function &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter Encounter ):#xD;\n  ( &amp;quot;ED Visit&amp;quot;(TheEncounter) ) EDEncounter#xD;\n    return#xD;\n        if EDEncounter is null then TheEncounter.location#xD;\n        else flatten { EDEncounter.location, TheEncounter.location }#xD;\n#xD;\n/*#xD;\nReturns list of all locations within an encounter, including locations for immediately prior ED visit.#xD;\n*/#xD;\ndefine fluent function hospitalizationLocations(TheEncounter Encounter ):#xD;\n  ( &amp;quot;ED Visit&amp;quot;(TheEncounter) ) EDEncounter#xD;\n    return#xD;\n        if EDEncounter is null then TheEncounter.location#xD;\n        else flatten { EDEncounter.location, TheEncounter.location }#xD;\n#xD;\n/*#xD;\nReturns the length of stay in days (i.e. the number of days between admission and discharge) for the given encounter, or from the admission of any immediately prior emergency department visit to the discharge of the encounter#xD;\n*/#xD;\ndefine function &amp;quot;Hospitalization Length of Stay&amp;quot;(TheEncounter Encounter ):#xD;\n  LengthInDays(&amp;quot;Hospitalization&amp;quot;(TheEncounter))#xD;\n#xD;\n/*#xD;\nReturns the length of stay in days (i.e. the number of days between admission and discharge) for the given encounter, or from the admission of any immediately prior emergency department visit to the discharge of the encounter#xD;\n*/#xD;\ndefine fluent function hospitalizationLengthOfStay(TheEncounter Encounter ):#xD;\n  LengthInDays(&amp;quot;Hospitalization&amp;quot;(TheEncounter))#xD;\n#xD;\n/*#xD;\nReturns admission time for an encounter or for immediately prior emergency department visit.#xD;\n*/#xD;\ndefine function &amp;quot;Hospital Admission Time&amp;quot;(TheEncounter Encounter ):#xD;\n  start of &amp;quot;Hospitalization&amp;quot;(TheEncounter)#xD;\n#xD;\n/*#xD;\nReturns admission time for an encounter or for immediately prior emergency department visit.#xD;\n*/#xD;\ndefine fluent function hospitalAdmissionTime(TheEncounter Encounter ):#xD;\n  start of &amp;quot;Hospitalization&amp;quot;(TheEncounter)#xD;\n#xD;\n/*#xD;\nHospital Discharge Time returns the discharge time for an encounter#xD;\n*/#xD;\ndefine function &amp;quot;Hospital Discharge Time&amp;quot;(TheEncounter Encounter ):#xD;\n  end of TheEncounter.period#xD;\n#xD;\n/*#xD;\nHospital Discharge Time returns the discharge time for an encounter#xD;\n*/#xD;\ndefine fluent function hospitalDischargeTime(TheEncounter Encounter ):#xD;\n  end of TheEncounter.period#xD;\n#xD;\n/*#xD;\nReturns earliest arrival time for an encounter including any prior ED visit.#xD;\n*/#xD;\ndefine function &amp;quot;Hospital Arrival Time&amp;quot;(TheEncounter Encounter ):#xD;\n  start of First(#xD;\n  	    ( &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter) ) HospitalLocation#xD;\n  			sort by start of period#xD;\n  	).period#xD;\n#xD;\n/*#xD;\nReturns earliest arrival time for an encounter including any prior ED visit.#xD;\n*/#xD;\ndefine fluent function hospitalArrivalTime(TheEncounter Encounter ):#xD;\n  start of First(#xD;\n  	    ( &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter) ) HospitalLocation#xD;\n  			sort by start of period#xD;\n  	).period#xD;\n#xD;\n/*#xD;\nReturns the latest departure time for encounter including any prior ED visit. #xD;\n*/#xD;\ndefine function &amp;quot;Hospital Departure Time&amp;quot;(TheEncounter Encounter):#xD;\n	end of Last(#xD;\n	    ( &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter) ) HospitalLocation#xD;\n			sort by start of period#xD;\n	).period#xD;\n#xD;\n/*#xD;\nReturns the latest departure time for encounter including any prior ED visit. #xD;\n*/#xD;\ndefine fluent function hospitalDepartureTime(TheEncounter Encounter):#xD;\n	end of Last(#xD;\n	    ( &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter) ) HospitalLocation#xD;\n			sort by start of period#xD;\n	).period#xD;\n#xD;\ndefine function &amp;quot;Emergency Department Arrival Time&amp;quot;(TheEncounter Encounter):#xD;\n	start of (#xD;\n	    singleton from (#xD;\n	        ( &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter) ) HospitalLocation#xD;\n				where GetLocation(HospitalLocation.location).type in &amp;quot;Emergency Department Visit&amp;quot;#xD;\n		)#xD;\n	).period#xD;\n#xD;\ndefine fluent function emergencyDepartmentArrivalTime(TheEncounter Encounter):#xD;\n	start of (#xD;\n	    singleton from (#xD;\n	        ( &amp;quot;Hospitalization Locations&amp;quot;(TheEncounter) ) HospitalLocation#xD;\n				where GetLocation(HospitalLocation.location).type in &amp;quot;Emergency Department Visit&amp;quot;#xD;\n		)#xD;\n	).period#xD;\n#xD;\n/*#xD;\nHospitalization with Observation and Outpatient Surgery Service returns the total interval from the start of any immediately prior emergency department visit, outpatient surgery visit or observation visit to the discharge of the given encounter.#xD;\n*/#xD;\ndefine function &amp;quot;HospitalizationWithObservationAndOutpatientSurgeryService&amp;quot;(TheEncounter &amp;quot;Encounter&amp;quot; ):#xD;\n  TheEncounter Visit#xD;\n	  let ObsVisit: Last([Encounter: &amp;quot;Observation Services&amp;quot;] LastObs#xD;\n		  	where LastObs.status = 'finished'#xD;\n          and LastObs.period ends 1 hour or less on or before start of Visit.period#xD;\n			  sort by	end of period#xD;\n    	),#xD;\n    	VisitStart: Coalesce(start of ObsVisit.period, start of Visit.period),#xD;\n    	EDVisit: Last([Encounter: &amp;quot;Emergency Department Visit&amp;quot;] LastED#xD;\n			  where LastED.status = 'finished'#xD;\n          and LastED.period ends 1 hour or less on or before VisitStart#xD;\n			  sort by	end of period#xD;\n    	),#xD;\n    	VisitStartWithED: Coalesce(start of EDVisit.period, VisitStart),#xD;\n    	OutpatientSurgeryVisit: Last([Encounter: &amp;quot;Outpatient Surgery Service&amp;quot;] LastSurgeryOP#xD;\n			  where LastSurgeryOP.period ends 1 hour or less on or before VisitStartWithED#xD;\n			  sort by	end of period#xD;\n    	)#xD;\n  	return Interval[Coalesce(start of OutpatientSurgeryVisit.period, VisitStartWithED), end of Visit.period]#xD;\n#xD;\n/*#xD;\nHospitalization with Observation and Outpatient Surgery Service returns the total interval from the start of any immediately prior emergency department visit, outpatient surgery visit or observation visit to the discharge of the given encounter.#xD;\n*/#xD;\ndefine fluent function hospitalizationWithObservationAndOutpatientSurgeryService(TheEncounter &amp;quot;Encounter&amp;quot; ):#xD;\n  TheEncounter Visit#xD;\n	  let ObsVisit: Last([Encounter: &amp;quot;Observation Services&amp;quot;] LastObs#xD;\n		  	where LastObs.status = 'finished'#xD;\n          and LastObs.period ends 1 hour or less on or before start of Visit.period#xD;\n			  sort by	end of period#xD;\n    	),#xD;\n    	VisitStart: Coalesce(start of ObsVisit.period, start of Visit.period),#xD;\n    	EDVisit: Last([Encounter: &amp;quot;Emergency Department Visit&amp;quot;] LastED#xD;\n			  where LastED.status = 'finished'#xD;\n          and LastED.period ends 1 hour or less on or before VisitStart#xD;\n			  sort by	end of period#xD;\n    	),#xD;\n    	VisitStartWithED: Coalesce(start of EDVisit.period, VisitStart),#xD;\n    	OutpatientSurgeryVisit: Last([Encounter: &amp;quot;Outpatient Surgery Service&amp;quot;] LastSurgeryOP#xD;\n			  where LastSurgeryOP.period ends 1 hour or less on or before VisitStartWithED#xD;\n			  sort by	end of period#xD;\n    	)#xD;\n  	return Interval[Coalesce(start of OutpatientSurgeryVisit.period, VisitStartWithED), end of Visit.period]#xD;\n#xD;\n/*#xD;\nHospitalization with Observation returns the total interval from the start of any immediately prior emergency department visit through the observation visit to the discharge of the given encounter#xD;\n*/#xD;\ndefine function &amp;quot;HospitalizationWithObservation&amp;quot;(TheEncounter Encounter ):#xD;\n  TheEncounter Visit#xD;\n  		let ObsVisit: Last([Encounter: &amp;quot;Observation Services&amp;quot;] LastObs#xD;\n  				where LastObs.status = 'finished'#xD;\n            and LastObs.period ends 1 hour or less on or before start of Visit.period#xD;\n  				sort by end of period#xD;\n  			),#xD;\n  			VisitStart: Coalesce(start of ObsVisit.period, start of Visit.period),#xD;\n  			EDVisit: Last([Encounter: &amp;quot;Emergency Department Visit&amp;quot;] LastED#xD;\n  				where LastED.status = 'finished'#xD;\n            and LastED.period ends 1 hour or less on or before VisitStart#xD;\n  				sort by end of period#xD;\n  			)#xD;\n  		return Interval[Coalesce(start of EDVisit.period, VisitStart), end of Visit.period]#xD;\n#xD;\n/*#xD;\nHospitalization with Observation returns the total interval from the start of any immediately prior emergency department visit through the observation visit to the discharge of the given encounter#xD;\n*/#xD;\ndefine fluent function hospitalizationWithObservation(TheEncounter Encounter ):#xD;\n  TheEncounter Visit#xD;\n  		let ObsVisit: Last([Encounter: &amp;quot;Observation Services&amp;quot;] LastObs#xD;\n  				where LastObs.status = 'finished'#xD;\n            and LastObs.period ends 1 hour or less on or before start of Visit.period#xD;\n  				sort by end of period#xD;\n  			),#xD;\n  			VisitStart: Coalesce(start of ObsVisit.period, start of Visit.period),#xD;\n  			EDVisit: Last([Encounter: &amp;quot;Emergency Department Visit&amp;quot;] LastED#xD;\n  				where LastED.status = 'finished'#xD;\n            and LastED.period ends 1 hour or less on or before VisitStart#xD;\n  				sort by end of period#xD;\n  			)#xD;\n  		return Interval[Coalesce(start of EDVisit.period, VisitStart), end of Visit.period]#xD;\n#xD;\n/*#xD;\nHospitalization with Observation Length of Stay returns the length in days from the start of any immediately prior emergency department visit through the observation visit to the discharge of the given encounter#xD;\n*/#xD;\ndefine function &amp;quot;HospitalizationWithObservationLengthofStay&amp;quot;(TheEncounter &amp;quot;Encounter&amp;quot; ):#xD;\n  &amp;quot;LengthInDays&amp;quot;(&amp;quot;HospitalizationWithObservation&amp;quot;(TheEncounter))#xD;\n#xD;\n/*#xD;\nHospitalization with Observation Length of Stay returns the length in days from the start of any immediately prior emergency department visit through the observation visit to the discharge of the given encounter#xD;\n*/#xD;\ndefine fluent function hospitalizationWithObservationLengthofStay(TheEncounter &amp;quot;Encounter&amp;quot; ):#xD;\n  &amp;quot;LengthInDays&amp;quot;(&amp;quot;HospitalizationWithObservation&amp;quot;(TheEncounter))#xD;\n#xD;\n/*#xD;\nFirst Inpatient Intensive Care Unit returns the first intensive care unit for the given encounter, without considering any immediately prior emergency department visit.#xD;\n*/#xD;\ndefine function &amp;quot;FirstInpatientIntensiveCareUnit&amp;quot;(Encounter Encounter ):#xD;\n  First((Encounter.location)HospitalLocation#xD;\n  			where GetLocation(HospitalLocation.location).type in &amp;quot;Intensive Care Unit&amp;quot;#xD;\n  				and HospitalLocation.period during Encounter.period#xD;\n  			sort by start of period#xD;\n  	)#xD;\n#xD;\n/*#xD;\nFirst Inpatient Intensive Care Unit returns the first intensive care unit for the given encounter, without considering any immediately prior emergency department visit.#xD;\n*/#xD;\ndefine fluent function firstInpatientIntensiveCareUnit(Encounter Encounter ):#xD;\n  First((Encounter.location)HospitalLocation#xD;\n  			where GetLocation(HospitalLocation.location).type in &amp;quot;Intensive Care Unit&amp;quot;#xD;\n  				and HospitalLocation.period during Encounter.period#xD;\n  			sort by start of period#xD;\n  	)#xD;\n#xD;\n/*#xD;\nReturns the Condition resources referenced by the diagnosis element of the Encounter#xD;\n*/#xD;\ndefine function &amp;quot;EncounterDiagnosis&amp;quot;(Encounter Encounter ):#xD;\n  Encounter.diagnosis D#xD;\n	return singleton from ([Condition] C where C.id = D.condition.reference.getId())#xD;\n#xD;\n/*#xD;\nReturns the Condition resources referenced by the diagnosis element of the Encounter#xD;\n*/#xD;\ndefine fluent function encounterDiagnosis(Encounter Encounter ):#xD;\n  Encounter.diagnosis D#xD;\n    return singleton from ([Condition] C where C.id = D.condition.reference.getId())#xD;\n#xD;\n/*#xD;\nReturns the Condition resource for the given reference#xD;\n@deprecated#xD;\n*/#xD;\ndefine function &amp;quot;GetCondition&amp;quot;(reference Reference):#xD;\n  singleton from ([Condition] C where C.id = reference.reference.getId())#xD;\n#xD;\n/*#xD;\nReturns the Condition resource for the given reference#xD;\n*/#xD;\ndefine fluent function getCondition(reference Reference):#xD;\n  singleton from ([Condition] C where C.id = reference.reference.getId())#xD;\n#xD;\n/*#xD;\nReturns the condition that is specified as the principal diagnosis for the encounter#xD;\n*/#xD;\ndefine function &amp;quot;PrincipalDiagnosis&amp;quot;(Encounter Encounter ):#xD;\n	singleton from ((Encounter.diagnosis D where D.rank = 1) PD#xD;\n      return singleton from ([Condition] C where C.id = PD.condition.reference.getId())#xD;\n	)#xD;\n#xD;\n/*#xD;\nReturns the condition that is specified as the principal diagnosis for the encounter#xD;\n*/#xD;\ndefine fluent function principalDiagnosis(Encounter Encounter ):#xD;\n	singleton from ((Encounter.diagnosis D where D.rank = 1) PD#xD;\n      return singleton from ([Condition] C where C.id = PD.condition.reference.getId())#xD;\n	)#xD;\n#xD;\n/*#xD;\nReturns the Location resource specified by the given reference#xD;\n*/#xD;\ndefine function &amp;quot;GetLocation&amp;quot;(reference Reference ):#xD;\n  singleton from (#xD;\n    [Location] L where L.id = reference.reference.getId()#xD;\n  )#xD;\n#xD;\n/*#xD;\nReturns the Location resource specified by the given reference#xD;\n*/#xD;\ndefine fluent function getLocation(reference Reference ):#xD;\n  singleton from (#xD;\n    [Location] L where L.id = reference.reference.getId()#xD;\n  )#xD;\n#xD;\n/*#xD;\nReturns the medication code for the given MedicationRequest#xD;\n*/#xD;\ndefine function &amp;quot;GetMedicationCode&amp;quot;(request MedicationRequest ):#xD;\n  if request.medication is Concept then#xD;\n  	  request.medication as Concept#xD;\n  	else#xD;\n  	  (singleton from ([Medication] M where M.id = (request.medication as Reference).reference.getId())).code#xD;\n#xD;\n/*#xD;\nReturns the medication code for the given MedicationRequest#xD;\n*/#xD;\ndefine fluent function getMedicationCode(request MedicationRequest ):#xD;\n  if request.medication is Concept then#xD;\n  	  request.medication as Concept#xD;\n  	else#xD;\n  	  (singleton from ([Medication] M where M.id = (request.medication as Reference).reference.getId())).code#xD;\n#xD;\n</code></pre></td></tr>\n            </table>\n          </td>\n        </tr>\n        \n        \n        \n    </table>\n</div>"^^rdf:XMLLiteral ]
      ] ; #
      fhir:extension ( [
    fhir:url [
    fhir:v "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-softwaresystem"^^xsd:anyURI ;
    fhir:l <http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-softwaresystem>     ] ;
    fhir:value [
    a fhir:Reference ;
    fhir:l fhir:Device/cqf-tooling ;
    fhir:reference [ fhir:v "Device/cqf-tooling" ]     ]
      ] ) ; #
      fhir:url [
    fhir:v "http://cms.gov/fhir/mct/Library/MATGlobalCommonFunctionsQICore4"^^xsd:anyURI ;
    fhir:l <http://cms.gov/fhir/mct/Library/MATGlobalCommonFunctionsQICore4>
      ] ; #
      fhir:version [ fhir:v "0.1.0"] ; #
      fhir:name [ fhir:v "MATGlobalCommonFunctionsQICore4"] ; #
      fhir:title [ fhir:v "MAT Global Common Functions QICore4"] ; #
      fhir:status [ fhir:v "draft"] ; #
      fhir:type [
        ( fhir:coding [
    fhir:system [
    fhir:v "http://terminology.hl7.org/CodeSystem/library-type"^^xsd:anyURI ;
    fhir:l <http://terminology.hl7.org/CodeSystem/library-type>       ] ;
    fhir:code [ fhir:v "logic-library" ]     ] )
      ] ; #
      fhir:date [ fhir:v "2026-02-27T18:11:00+00:00"^^xsd:dateTime] ; #
      fhir:publisher [ fhir:v "HL7 International - [Some] Work Group"] ; #
      fhir:contact ( [
        ( fhir:telecom [
    fhir:system [ fhir:v "url" ] ;
    fhir:value [ fhir:v "http://hl7.org/Special/committees/[something]" ]     ] )
      ] ) ; #
      fhir:jurisdiction ( [
        ( fhir:coding [
    fhir:system [
    fhir:v "urn:iso:std:iso:3166"^^xsd:anyURI ;
    fhir:l <urn:iso:std:iso:3166>       ] ;
    fhir:code [ fhir:v "US" ]     ] )
      ] ) ; #
      fhir:content ( [
    fhir:contentType [ fhir:v "text/cql" ] ;
    fhir:data [ fhir:v " "^^xsd:base64Binary ]
      ] ) . #