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

## : QiCore Common - JSON Representation

Draft as of 2026-02-27

Raw json | Download

    {
      "resourceType" : "Library",
      "id" : "QICoreCommon",
      "text" : {
        "status" : "extensions",
        "div" : "<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;\">QICoreCommon</td>\n        </tr>\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Url: </b></th>\n            <td style=\"padding-left: 4px;\"><a href=\"Library-QICoreCommon.html\">QiCore Common</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;\">QICoreCommon</td>\n        </tr>\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Title: </b></th>\n            <td style=\"padding-left: 4px;\">QiCore Common</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\">/*\r\n@author: Stan Rankins\r\n@description: Common terminologies and functions used in QI-Core-based CQL artifacts\r\n@update: Fashioned after FHIRCommon Version 4.0.012 for use in ecqm-content-qicore-2022 repos\r\n*/\r\nlibrary QICoreCommon version '1.0.000'\r\n\r\nusing QICore version '4.1.1'\r\n\r\ninclude FHIRHelpers version '4.0.013'\r\n\r\ncodesystem &amp;quot;LOINC&amp;quot;: 'http://loinc.org'\r\ncodesystem &amp;quot;SNOMEDCT&amp;quot;: 'http://snomed.info/sct'\r\ncodesystem &amp;quot;ICD10CM&amp;quot;: 'http://hl7.org/fhir/sid/icd-10-cm'\r\ncodesystem &amp;quot;RoleCode&amp;quot;: 'http://terminology.hl7.org/CodeSystem/v3-RoleCode'\r\ncodesystem &amp;quot;Diagnosis Role&amp;quot;: 'http://terminology.hl7.org/CodeSystem/diagnosis-role'\r\ncodesystem &amp;quot;RequestIntent&amp;quot;: 'http://terminology.hl7.org/CodeSystem/request-intent'\r\ncodesystem &amp;quot;MedicationRequestCategory&amp;quot;: 'http://terminology.hl7.org/CodeSystem/medicationrequest-category'\r\ncodesystem &amp;quot;ConditionClinicalStatusCodes&amp;quot;: 'http://terminology.hl7.org/CodeSystem/condition-clinical'\r\ncodesystem &amp;quot;ConditionVerificationStatusCodes&amp;quot;: 'http://terminology.hl7.org/CodeSystem/condition-ver-status'\r\ncodesystem &amp;quot;AllergyIntoleranceClinicalStatusCodes&amp;quot;: 'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical'\r\ncodesystem &amp;quot;AllergyIntoleranceVerificationStatusCodes&amp;quot;: 'http://terminology.hl7.org/CodeSystem/allergyintolerance-verification'\r\ncodesystem &amp;quot;ConditionCategoryCodes&amp;quot;: 'http://terminology.hl7.org/CodeSystem/condition-category'\r\ncodesystem &amp;quot;ObservationCategoryCodes&amp;quot;: 'http://terminology.hl7.org/CodeSystem/observation-category'\r\n\r\nvalueset &amp;quot;Active Condition&amp;quot;: 'http://fhir.org/guides/cqf/common/ValueSet/active-condition'\r\nvalueset &amp;quot;Inactive Condition&amp;quot;: 'http://fhir.org/guides/cqf/common/ValueSet/inactive-condition'\r\n\r\ncode &amp;quot;Birthdate&amp;quot;: '21112-8' from &amp;quot;LOINC&amp;quot; display 'Birth date'\r\ncode &amp;quot;Dead&amp;quot;: '419099009' from &amp;quot;SNOMEDCT&amp;quot; display 'Dead'\r\ncode &amp;quot;ER&amp;quot;: 'ER' from &amp;quot;RoleCode&amp;quot; display 'Emergency room'\r\ncode &amp;quot;ICU&amp;quot;: 'ICU' from &amp;quot;RoleCode&amp;quot; display 'Intensive care unit'\r\ncode &amp;quot;Billing&amp;quot;: 'billing' from &amp;quot;Diagnosis Role&amp;quot; display 'Billing'\r\n\r\n// Condition Clinical Status Codes - Consider value sets for these\r\ncode &amp;quot;active&amp;quot;: 'active' from &amp;quot;ConditionClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;recurrence&amp;quot;: 'recurrence' from &amp;quot;ConditionClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;relapse&amp;quot;: 'relapse' from &amp;quot;ConditionClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;inactive&amp;quot;: 'inactive' from &amp;quot;ConditionClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;remission&amp;quot;: 'remission' from &amp;quot;ConditionClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;resolved&amp;quot;: 'resolved' from &amp;quot;ConditionClinicalStatusCodes&amp;quot;\r\n\r\n// Condition Verification Status Codes - Consider value sets for these\r\ncode &amp;quot;unconfirmed&amp;quot;: 'unconfirmed' from ConditionVerificationStatusCodes\r\ncode &amp;quot;provisional&amp;quot;: 'provisional' from ConditionVerificationStatusCodes\r\ncode &amp;quot;differential&amp;quot;: 'differential' from ConditionVerificationStatusCodes\r\ncode &amp;quot;confirmed&amp;quot;: 'confirmed' from ConditionVerificationStatusCodes\r\ncode &amp;quot;refuted&amp;quot;: 'refuted' from ConditionVerificationStatusCodes\r\ncode &amp;quot;entered-in-error&amp;quot;: 'entered-in-error' from ConditionVerificationStatusCodes\r\n\r\ncode &amp;quot;allergy-active&amp;quot;: 'active' from &amp;quot;AllergyIntoleranceClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;allergy-inactive&amp;quot;: 'inactive' from &amp;quot;AllergyIntoleranceClinicalStatusCodes&amp;quot;\r\ncode &amp;quot;allergy-resolved&amp;quot;: 'resolved' from &amp;quot;AllergyIntoleranceClinicalStatusCodes&amp;quot;\r\n\r\n// Allergy/Intolerance Verification Status Codes - Consider value sets for these\r\ncode &amp;quot;allergy-unconfirmed&amp;quot;: 'unconfirmed' from AllergyIntoleranceVerificationStatusCodes\r\ncode &amp;quot;allergy-confirmed&amp;quot;: 'confirmed' from AllergyIntoleranceVerificationStatusCodes\r\ncode &amp;quot;allergy-refuted&amp;quot;: 'refuted' from AllergyIntoleranceVerificationStatusCodes\r\n\r\n// MedicationRequest Category Codes\r\ncode &amp;quot;Community&amp;quot;: 'community' from &amp;quot;MedicationRequestCategory&amp;quot; display 'Community'\r\ncode &amp;quot;Discharge&amp;quot;: 'discharge' from &amp;quot;MedicationRequestCategory&amp;quot; display 'Discharge'\r\n\r\n// Diagnosis Role Codes\r\ncode &amp;quot;AD&amp;quot;: 'AD' from &amp;quot;Diagnosis Role&amp;quot; display 'Admission diagnosis'\r\ncode &amp;quot;DD&amp;quot;: 'DD' from &amp;quot;Diagnosis Role&amp;quot; display 'Discharge diagnosis'\r\ncode &amp;quot;CC&amp;quot;: 'CC' from &amp;quot;Diagnosis Role&amp;quot; display 'Chief complaint'\r\ncode &amp;quot;CM&amp;quot;: 'CM' from &amp;quot;Diagnosis Role&amp;quot; display 'Comorbidity diagnosis'\r\ncode &amp;quot;pre-op&amp;quot;: 'pre-op' from &amp;quot;Diagnosis Role&amp;quot; display 'pre-op diagnosis'\r\ncode &amp;quot;post-op&amp;quot;: 'post-op' from &amp;quot;Diagnosis Role&amp;quot; display 'post-op diagnosis'\r\ncode &amp;quot;billing&amp;quot;: 'billing' from &amp;quot;Diagnosis Role&amp;quot; display 'billing diagnosis'\r\n\r\n// Observation Category Codes\r\ncode &amp;quot;social-history&amp;quot;: 'social-history' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Social History'\r\ncode &amp;quot;vital-signs&amp;quot;: 'vital-signs' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Vital Signs'\r\ncode &amp;quot;imaging&amp;quot;: 'imaging' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Imaging'\r\ncode &amp;quot;laboratory&amp;quot;: 'laboratory' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Laboratory'\r\ncode &amp;quot;procedure&amp;quot;: 'procedure' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Procedure'\r\ncode &amp;quot;survey&amp;quot;: 'survey' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Survey'\r\ncode &amp;quot;exam&amp;quot;: 'exam' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Exam'\r\ncode &amp;quot;therapy&amp;quot;: 'therapy' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Therapy'\r\ncode &amp;quot;activity&amp;quot;: 'activity' from &amp;quot;ObservationCategoryCodes&amp;quot; display 'Activity'\r\n\r\n// Condition Category Codes\r\ncode &amp;quot;problem-list-item&amp;quot;: 'problem-list-item' from &amp;quot;ConditionCategoryCodes&amp;quot; display 'Problem List Item'\r\ncode &amp;quot;encounter-diagnosis&amp;quot;: 'encounter-diagnosis' from &amp;quot;ConditionCategoryCodes&amp;quot; display 'Encounter Diagnosis'\r\n\r\ncontext Patient\r\n\r\n/*\r\n@description: Normalizes a value that is a choice of timing-valued types to an equivalent interval\r\n@comment: Normalizes a choice type of DateTime, Quanitty, Interval&amp;lt;DateTime&amp;gt;, or Interval&amp;lt;Quantity&amp;gt; types\r\nto an equivalent interval. This selection of choice types is a superset of the majority of choice types that are used as possible\r\nrepresentations for timing-valued elements in QICore, allowing this function to be used across any resource.\r\n\r\nThe input can be provided as a DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt; or Interval&amp;lt;Quantity&amp;gt;.\r\nThe intent of this function is to provide a clear and concise mechanism to treat single\r\nelements that have multiple possible representations as intervals so that logic doesn't have to account\r\nfor the variability. More complex calculations (such as medication request period or dispense period\r\ncalculation) need specific guidance and consideration. That guidance may make use of this function, but\r\nthe focus of this function is on single element calculations where the semantics are unambiguous.\r\nIf the input is a DateTime, the result a DateTime Interval beginning and ending on that DateTime.\r\nIf the input is a Quantity, the quantity is expected to be a calendar-duration interpreted as an Age, \r\nand the result is a DateTime Interval beginning on the Date the patient turned that age and ending immediately before one year later.\r\nIf the input is a DateTime Interval, the result is the input.\r\nIf the input is a Quantity Interval, the quantities are expected to be calendar-durations interpreted as an Age, and the result\r\nis a DateTime Interval beginning on the date the patient turned the age given as the start of the quantity interval, and ending \r\nimmediately before one year later than the date the patient turned the age given as the end of the quantity interval.\r\nAny other input will reslt in a null DateTime Interval\r\n*/\r\ndefine function ToInterval(choice Choice&amp;lt;DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt;, Interval&amp;lt;Quantity&amp;gt;&amp;gt;):\r\n  case\r\n\t  when choice is DateTime then\r\n    \tInterval[choice as DateTime, choice as DateTime]\r\n\t\twhen choice is Interval&amp;lt;DateTime&amp;gt; then\r\n  \t\tchoice as Interval&amp;lt;DateTime&amp;gt;\r\n\t\twhen choice is Quantity then\r\n\t\t  Interval[Patient.birthDate + (choice as Quantity),\r\n\t\t\t  Patient.birthDate + (choice as Quantity) + 1 year)\r\n\t\twhen choice is Interval&amp;lt;Quantity&amp;gt; then\r\n\t\t  Interval[Patient.birthDate + (choice.low as Quantity),\r\n\t\t\t  Patient.birthDate + (choice.high as Quantity) + 1 year)\r\n\t\telse\r\n\t\t\tnull as Interval&amp;lt;DateTime&amp;gt;\r\n\tend\r\n\r\n/*\r\n@description: Normalizes a value that is a choice of timing-valued types to an equivalent interval\r\n@comment: Normalizes a choice type of DateTime, Quanitty, Interval&amp;lt;DateTime&amp;gt;, or Interval&amp;lt;Quantity&amp;gt; types\r\nto an equivalent interval. This selection of choice types is a superset of the majority of choice types that are used as possible\r\nrepresentations for timing-valued elements in QICore, allowing this function to be used across any resource.\r\n\r\nThe input can be provided as a DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt; or Interval&amp;lt;Quantity&amp;gt;.\r\nThe intent of this function is to provide a clear and concise mechanism to treat single\r\nelements that have multiple possible representations as intervals so that logic doesn't have to account\r\nfor the variability. More complex calculations (such as medication request period or dispense period\r\ncalculation) need specific guidance and consideration. That guidance may make use of this function, but\r\nthe focus of this function is on single element calculations where the semantics are unambiguous.\r\nIf the input is a DateTime, the result a DateTime Interval beginning and ending on that DateTime.\r\nIf the input is a Quantity, the quantity is expected to be a calendar-duration interpreted as an Age, \r\nand the result is a DateTime Interval beginning on the Date the patient turned that age and ending immediately before one year later.\r\nIf the input is a DateTime Interval, the result is the input.\r\nIf the input is a Quantity Interval, the quantities are expected to be calendar-durations interpreted as an Age, and the result\r\nis a DateTime Interval beginning on the date the patient turned the age given as the start of the quantity interval, and ending \r\nimmediately before one year later than the date the patient turned the age given as the end of the quantity interval.\r\nAny other input will reslt in a null DateTime Interval\r\n*/\r\ndefine fluent function toInterval(choice Choice&amp;lt;DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt;, Interval&amp;lt;Quantity&amp;gt;&amp;gt;):\r\n  case\r\n\t  when choice is DateTime then\r\n    \tInterval[choice as DateTime, choice as DateTime]\r\n\t\twhen choice is Interval&amp;lt;DateTime&amp;gt; then\r\n  \t\tchoice as Interval&amp;lt;DateTime&amp;gt;\r\n\t\twhen choice is Quantity then\r\n\t\t  Interval[Patient.birthDate + (choice as Quantity),\r\n\t\t\t  Patient.birthDate + (choice as Quantity) + 1 year)\r\n\t\twhen choice is Interval&amp;lt;Quantity&amp;gt; then\r\n\t\t  Interval[Patient.birthDate + (choice.low as Quantity),\r\n\t\t\t  Patient.birthDate + (choice.high as Quantity) + 1 year)\r\n\t\telse\r\n\t\t\tnull as Interval&amp;lt;DateTime&amp;gt;\r\n\tend\r\n\r\n/*\r\n@description: Returns an interval representing the normalized abatement of a given Condition.\r\n@comment: If the abatement element of the Condition is represented as a DateTime, the result\r\nis an interval beginning and ending on that DateTime.\r\nIf the abatement is represented as a Quantity, the quantity is expected to be a calendar-duration and is interpreted as the age of the patient. The\r\nresult is an interval from the date the patient turned that age to immediately before one year later.\r\nIf the abatement is represented as a Quantity Interval, the quantities are expected to be calendar-durations and are interpreted as an age range during\r\nwhich the abatement occurred. The result is an interval from the date the patient turned the starting age of the quantity interval, and ending immediately\r\nbefore one year later than the date the patient turned the ending age of the quantity interval.\r\n*/\r\ndefine function ToAbatementInterval(condition Condition):\r\n\tif condition.abatement is DateTime then\r\n\t  Interval[condition.abatement as DateTime, condition.abatement as DateTime]\r\n\telse if condition.abatement is Quantity then\r\n\t\tInterval[Patient.birthDate + (condition.abatement as Quantity),\r\n\t\t\tPatient.birthDate + (condition.abatement as Quantity) + 1 year)\r\n\telse if condition.abatement is Interval&amp;lt;Quantity&amp;gt; then\r\n\t  Interval[Patient.birthDate + (condition.abatement.low as Quantity),\r\n\t\t  Patient.birthDate + (condition.abatement.high as Quantity) + 1 year)\r\n\telse if condition.abatement is Interval&amp;lt;DateTime&amp;gt; then\r\n\t  Interval[condition.abatement.low, condition.abatement.high)\r\n\telse null as Interval&amp;lt;DateTime&amp;gt;\r\n\r\n/*\r\n@description: Returns an interval representing the normalized abatement of a given Condition.\r\n@comment: If the abatement element of the Condition is represented as a DateTime, the result\r\nis an interval beginning and ending on that DateTime.\r\nIf the abatement is represented as a Quantity, the quantity is expected to be a calendar-duration and is interpreted as the age of the patient. The\r\nresult is an interval from the date the patient turned that age to immediately before one year later.\r\nIf the abatement is represented as a Quantity Interval, the quantities are expected to be calendar-durations and are interpreted as an age range during\r\nwhich the abatement occurred. The result is an interval from the date the patient turned the starting age of the quantity interval, and ending immediately\r\nbefore one year later than the date the patient turned the ending age of the quantity interval.\r\n*/\r\ndefine fluent function toAbatementInterval(condition Condition):\r\n\tif condition.abatement is DateTime then\r\n\t  Interval[condition.abatement as DateTime, condition.abatement as DateTime]\r\n\telse if condition.abatement is Quantity then\r\n\t\tInterval[Patient.birthDate + (condition.abatement as Quantity),\r\n\t\t\tPatient.birthDate + (condition.abatement as Quantity) + 1 year)\r\n\telse if condition.abatement is Interval&amp;lt;Quantity&amp;gt; then\r\n\t  Interval[Patient.birthDate + (condition.abatement.low as Quantity),\r\n\t\t  Patient.birthDate + (condition.abatement.high as Quantity) + 1 year)\r\n\telse if condition.abatement is Interval&amp;lt;DateTime&amp;gt; then\r\n\t  Interval[condition.abatement.low, condition.abatement.high)\r\n\telse null as Interval&amp;lt;DateTime&amp;gt;\r\n\r\n/*\r\n@description: Returns an interval representing the normalized prevalence period of a given Condition.\r\n@comment: Uses the ToInterval and ToAbatementInterval functions to determine the widest potential interval from\r\nonset to abatement as specified in the given Condition. If the condition is active, the resulting interval will have\r\na closed ending boundary. If the condition is not active, the resulting interval will have an open ending boundary.\r\n*/\r\ndefine function ToPrevalenceInterval(condition Condition):\r\nif condition.clinicalStatus ~ &amp;quot;active&amp;quot;\r\n  or condition.clinicalStatus ~ &amp;quot;recurrence&amp;quot;\r\n  or condition.clinicalStatus ~ &amp;quot;relapse&amp;quot; then\r\n  Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition)]\r\nelse\r\n  Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition))\r\n\r\n/*\r\n@description: Returns an interval representing the normalized prevalence period of a given Condition.\r\n@comment: Uses the ToInterval and ToAbatementInterval functions to determine the widest potential interval from\r\nonset to abatement as specified in the given Condition. If the condition is active, the resulting interval will have\r\na closed ending boundary. If the condition is not active, the resulting interval will have an open ending boundary.\r\n*/\r\ndefine fluent function toPrevalenceInterval(condition Condition):\r\nif condition.clinicalStatus ~ &amp;quot;active&amp;quot;\r\n  or condition.clinicalStatus ~ &amp;quot;recurrence&amp;quot;\r\n  or condition.clinicalStatus ~ &amp;quot;relapse&amp;quot; then\r\n  Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition)]\r\nelse\r\n  Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition))\r\n\r\n/*\r\n@description: Returns the tail of the given uri (i.e. everything after the last slash in the URI).\r\n@comment: This function can be used to determine the logical id of a given resource. It can be used in\r\na single-server environment to trace references. However, this function does not attempt to resolve\r\nor distinguish the base of the given url, and so cannot be used safely in multi-server environments.\r\n*/\r\ndefine function GetId(uri String ):\r\n  Last(Split(uri, '/'))\r\n\r\n/*\r\n@description: Returns the tail of the given uri (i.e. everything after the last slash in the URI).\r\n@comment: This function can be used to determine the logical id of a given resource. It can be used in\r\na single-server environment to trace references. However, this function does not attempt to resolve\r\nor distinguish the base of the given url, and so cannot be used safely in multi-server environments.\r\n*/\r\ndefine fluent function getId(uri String):\r\n  Last(Split(uri, '/'))\r\n\r\n/*\r\n@description: Given an interval, return true if the interval has a starting boundary specified \r\n(i.e. the start of the interval is not null and not the minimum DateTime value)\r\n*/\r\ndefine function &amp;quot;HasStart&amp;quot;(period Interval&amp;lt;DateTime&amp;gt; ):\r\n  not ( start of period is null\r\n      or start of period = minimum DateTime\r\n  )\r\n\r\n/*\r\n@description: Given an interval, return true if the interval has a starting boundary specified \r\n(i.e. the start of the interval is not null and not the minimum DateTime value)\r\n*/\r\ndefine fluent function hasStart(period Interval&amp;lt;DateTime&amp;gt; ):\r\n  not ( start of period is null\r\n      or start of period = minimum DateTime\r\n  )\r\n\r\n/*\r\n@description: Given an interval, returns true if the interval has an ending boundary specified \r\n(i.e. the end of the interval is not null and not the maximum DateTime value)\r\n*/\r\ndefine function &amp;quot;HasEnd&amp;quot;(period Interval&amp;lt;DateTime&amp;gt; ):\r\n  not (\r\n    end of period is null\r\n      or end of period = maximum DateTime\r\n  )\r\n\r\n/*\r\n@description: Given an interval, returns true if the interval has an ending boundary specified \r\n(i.e. the end of the interval is not null and not the maximum DateTime value)\r\n*/\r\ndefine fluent function hasEnd(period Interval&amp;lt;DateTime&amp;gt; ):\r\n  not (\r\n    end of period is null\r\n      or end of period = maximum DateTime\r\n  )\r\n\r\n/*\r\n@description: Given an interval, returns the ending point if the interval has an ending boundary specified, \r\notherwise, returns the starting point\r\n*/\r\ndefine function &amp;quot;Latest&amp;quot;(choice Choice&amp;lt;DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt;, Interval&amp;lt;Quantity&amp;gt;&amp;gt; ):\r\n  (choice.toInterval()) period\r\n    return\r\n      if (HasEnd(period)) then end of period\r\n      else start of period\r\n\r\n/*\r\n@description: Given an interval, returns the ending point if the interval has an ending boundary specified, \r\notherwise, returns the starting point\r\n*/\r\ndefine fluent function latest(choice Choice&amp;lt;DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt;, Interval&amp;lt;Quantity&amp;gt;&amp;gt; ):\r\n  (choice.toInterval()) period\r\n    return\r\n      if (HasEnd(period)) then end of period\r\n      else start of period\r\n\r\n/*\r\n@description: Given an interval, return the starting point if the interval has a starting boundary specified, \r\notherwise, return the ending point\r\n*/\r\ndefine function &amp;quot;Earliest&amp;quot;(choice Choice&amp;lt;DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt;, Interval&amp;lt;Quantity&amp;gt;&amp;gt; ):\r\n  (choice.toInterval()) period\r\n    return\r\n      if (HasStart(period)) then start of period\r\n      else end of period\r\n\r\n/*\r\n@description: Given an interval, return the starting point if the interval has a starting boundary specified, \r\notherwise, return the ending point\r\n*/\r\ndefine fluent function earliest(choice Choice&amp;lt;DateTime, Quantity, Interval&amp;lt;DateTime&amp;gt;, Interval&amp;lt;Quantity&amp;gt;&amp;gt; ):\r\n  (choice.toInterval()) period\r\n    return\r\n      if (HasStart(period)) then start of period\r\n      else end of period\r\n\r\n/*\r\n@description: Creates a list of integers from 1 to how many days are in the interval. Note, this wont create an index for\r\nthe final day if it is less than 24 hours. This also includes the first 24 hour period.\r\n*/\r\ndefine function &amp;quot;Interval To Day Numbers&amp;quot;(Period Interval&amp;lt;DateTime&amp;gt;):\r\n  ( expand { Interval[1, duration in days between start of Period and end of Period]} ) DayNumber\r\n    return end of DayNumber\r\n\r\n/*\r\n@description: Creates a list of integers from 1 to how many days are in the interval. Note, this wont create an index for\r\nthe final day if it is less than 24 hours. This also includes the first 24 hour period.\r\n*/\r\ndefine fluent function toDayNumbers(Period Interval&amp;lt;DateTime&amp;gt;):\r\n  ( expand { Interval[1, duration in days between start of Period and end of Period]} ) DayNumber\r\n    return end of DayNumber\r\n\r\n/*\r\n@description: Creates a list of 24 hour long intervals in an interval paired with the index (1 indexed) to which 24 hour interval it is.\r\nNote that the result will include intervals that are closed at the beginning and open at the end\r\n*/\r\ndefine function &amp;quot;Days In Period&amp;quot;(Period Interval&amp;lt;DateTime&amp;gt;):\r\n  ( &amp;quot;Interval To Day Numbers&amp;quot;(Period)) DayIndex\r\n    let startPeriod: start of Period + (24 hours * (DayIndex - 1)),\r\n    endPeriod: if (hours between startPeriod and end of Period &amp;lt; 24) then startPeriod\r\n      else start of Period + (24 hours * DayIndex)\r\n    return Tuple {\r\n      dayIndex: DayIndex,\r\n      dayPeriod: Interval[startPeriod, endPeriod)\r\n    }\r\n\r\n/*\r\n@description: Creates a list of 24 hour long intervals in an interval paired with the index (1 indexed) to which 24 hour interval it is.\r\nNote that the result will include intervals that are closed at the beginning and open at the end\r\n*/\r\ndefine fluent function daysInPeriod(Period Interval&amp;lt;DateTime&amp;gt;):\r\n  ( &amp;quot;Interval To Day Numbers&amp;quot;(Period)) DayIndex\r\n    let startPeriod: start of Period + (24 hours * (DayIndex - 1)),\r\n    endPeriod: if (hours between startPeriod and end of Period &amp;lt; 24) then startPeriod\r\n      else start of Period + (24 hours * DayIndex)\r\n    return Tuple {\r\n      dayIndex: DayIndex,\r\n      dayPeriod: Interval[startPeriod, endPeriod)\r\n    }</code></pre></td></tr>\n            </table>\n          </td>\n        </tr>\n        \n        \n        \n    </table>\n</div>"
      },
      "extension" : [
        {
          "url" : "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-softwaresystem",
          "valueReference" : {
            🔗 "reference" : "Device/cqf-tooling"
          }
        }
      ],
      "url" : "http://cms.gov/fhir/mct/Library/QICoreCommon",
      "version" : "0.1.0",
      "name" : "QICoreCommon",
      "title" : "QiCore Common",
      "status" : "draft",
      "type" : {
        "coding" : [
          {
            "system" : "http://terminology.hl7.org/CodeSystem/library-type",
            "code" : "logic-library"
          }
        ]
      },
      "date" : "2026-02-27T18:11:00+00:00",
      "publisher" : "HL7 International - [Some] Work Group",
      "contact" : [
        {
          "telecom" : [
            {
              "system" : "url",
              "value" : "http://hl7.org/Special/committees/[something]"
            }
          ]
        }
      ],
      "jurisdiction" : [
        {
          "coding" : [
            {
              "system" : "urn:iso:std:iso:3166",
              "code" : "US"
            }
          ]
        }
      ],
      "content" : [
        {
          "contentType" : "text/cql",
          "data" : " "
        }
      ]
    }