Id: FHIRCommon Version: 0.1.0 Url: FHIRCommon Status: draft Type: system: http://terminology.hl7.org/CodeSystem/library-type code: logic-library Date: 2026-05-11 22:31:14+0000 Publisher: Clinical Quality Framework Jurisdiction: 001 Related Artifacts: Dependencies http://fhir.org/guides/cqf/aphl/chronic-ds/Library/FHIRHelpers|4.1.000 LOINC SNOMED CT (all versions) International Classification of Diseases, Tenth Revision, Clinical Modification (ICD-10-CM) RoleCode Diagnosis Role http://terminology.hl7.org/CodeSystem/request-intent MedicationRequest Category Codes Condition Clinical Status Codes ConditionVerificationStatus AllergyIntolerance Clinical Status Codes AllergyIntolerance Verification Status Condition Category Codes Observation Category Codes Parameters: Name Type Min Max In/Out Patient Patient 0 1 Out Data Requirements: Type Profile MS Code Filter Patient http://hl7.org/fhir/StructureDefinition/Patient Content: text/cql /*#xD; @author: Bryn Rhodes#xD; @description: Common terminologies and functions used in FHIR-based CQL artifacts#xD; @update: Version 4.0.002 for use in ecqm-content-r4-2022 repository#xD; @source: http://fhir.org/guides/cqf/common/Library/FHIRCommon#xD; @update: Version 1.1.000, based on MAT versioning#xD; */#xD; library FHIRCommon version '1.1.000'#xD; #xD; using FHIR version '4.0.1'#xD; #xD; include FHIRHelpers version '4.1.000' called FHIRHelpers#xD; #xD; codesystem "LOINC": 'http://loinc.org'#xD; codesystem "SNOMEDCT": 'http://snomed.info/sct'#xD; codesystem "ICD10CM": 'http://hl7.org/fhir/sid/icd-10-cm'#xD; codesystem "RoleCode": 'http://terminology.hl7.org/CodeSystem/v3-RoleCode'#xD; codesystem "Diagnosis Role": 'http://terminology.hl7.org/CodeSystem/diagnosis-role'#xD; codesystem "RequestIntent": 'http://terminology.hl7.org/CodeSystem/request-intent'#xD; codesystem "MedicationRequestCategory": 'http://terminology.hl7.org/CodeSystem/medicationrequest-category'#xD; codesystem "ConditionClinicalStatusCodes": 'http://terminology.hl7.org/CodeSystem/condition-clinical'#xD; codesystem "ConditionVerificationStatusCodes": 'http://terminology.hl7.org/CodeSystem/condition-ver-status'#xD; codesystem "AllergyIntoleranceClinicalStatusCodes": 'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical'#xD; codesystem "AllergyIntoleranceVerificationStatusCodes": 'http://terminology.hl7.org/CodeSystem/allergyintolerance-verification'#xD; codesystem "ConditionCategoryCodes": 'http://terminology.hl7.org/CodeSystem/condition-category'#xD; codesystem "ObservationCategoryCodes": 'http://terminology.hl7.org/CodeSystem/observation-category'#xD; #xD; // NOT in VSAC so can't be included in the MAT#xD; //valueset "Active Condition": 'http://fhir.org/guides/cqf/common/ValueSet/active-condition'#xD; //valueset "Inactive Condition": 'http://fhir.org/guides/cqf/common/ValueSet/inactive-condition'#xD; #xD; code "Birthdate": '21112-8' from "LOINC" display 'Birth date'#xD; code "Dead": '419099009' from "SNOMEDCT" display 'Dead'#xD; code "ER": 'ER' from "RoleCode" display 'Emergency room'#xD; code "ICU": 'ICU' from "RoleCode" display 'Intensive care unit'#xD; code "Billing": 'billing' from "Diagnosis Role" display 'Billing'#xD; #xD; // Condition Clinical Status Codes - Consider value sets for these#xD; code "active": 'active' from "ConditionClinicalStatusCodes"#xD; code "recurrence": 'recurrence' from "ConditionClinicalStatusCodes"#xD; code "relapse": 'relapse' from "ConditionClinicalStatusCodes"#xD; code "inactive": 'inactive' from "ConditionClinicalStatusCodes"#xD; code "remission": 'remission' from "ConditionClinicalStatusCodes"#xD; code "resolved": 'resolved' from "ConditionClinicalStatusCodes"#xD; #xD; // Condition Verification Status Codes - Consider value sets for these#xD; code "unconfirmed": 'unconfirmed' from ConditionVerificationStatusCodes#xD; code "provisional": 'provisional' from ConditionVerificationStatusCodes#xD; code "differential": 'differential' from ConditionVerificationStatusCodes#xD; code "confirmed": 'confirmed' from ConditionVerificationStatusCodes#xD; code "refuted": 'refuted' from ConditionVerificationStatusCodes#xD; code "entered-in-error": 'entered-in-error' from ConditionVerificationStatusCodes#xD; #xD; code "allergy-active": 'active' from "AllergyIntoleranceClinicalStatusCodes"#xD; code "allergy-inactive": 'inactive' from "AllergyIntoleranceClinicalStatusCodes"#xD; code "allergy-resolved": 'resolved' from "AllergyIntoleranceClinicalStatusCodes"#xD; #xD; // Allergy/Intolerance Verification Status Codes - Consider value sets for these#xD; code "allergy-unconfirmed": 'unconfirmed' from AllergyIntoleranceVerificationStatusCodes#xD; code "allergy-confirmed": 'confirmed' from AllergyIntoleranceVerificationStatusCodes#xD; code "allergy-refuted": 'refuted' from AllergyIntoleranceVerificationStatusCodes#xD; #xD; // MedicationRequest Category Codes#xD; code "Community": 'community' from "MedicationRequestCategory" display 'Community'#xD; code "Discharge": 'discharge' from "MedicationRequestCategory" display 'Discharge'#xD; #xD; // Diagnosis Role Codes#xD; code "AD": 'AD' from "Diagnosis Role" display 'Admission diagnosis'#xD; code "DD": 'DD' from "Diagnosis Role" display 'Discharge diagnosis'#xD; code "CC": 'CC' from "Diagnosis Role" display 'Chief complaint'#xD; code "CM": 'CM' from "Diagnosis Role" display 'Comorbidity diagnosis'#xD; code "pre-op": 'pre-op' from "Diagnosis Role" display 'pre-op diagnosis'#xD; code "post-op": 'post-op' from "Diagnosis Role" display 'post-op diagnosis'#xD; code "billing": 'billing' from "Diagnosis Role" display 'billing diagnosis'#xD; #xD; // Observation Category Codes#xD; code "social-history": 'social-history' from "ObservationCategoryCodes" display 'Social History'#xD; code "vital-signs": 'vital-signs' from "ObservationCategoryCodes" display 'Vital Signs'#xD; code "imaging": 'imaging' from "ObservationCategoryCodes" display 'Imaging'#xD; code "laboratory": 'laboratory' from "ObservationCategoryCodes" display 'Laboratory'#xD; code "procedure": 'procedure' from "ObservationCategoryCodes" display 'Procedure'#xD; code "survey": 'survey' from "ObservationCategoryCodes" display 'Survey'#xD; code "exam": 'exam' from "ObservationCategoryCodes" display 'Exam'#xD; code "therapy": 'therapy' from "ObservationCategoryCodes" display 'Therapy'#xD; code "activity": 'activity' from "ObservationCategoryCodes" display 'Activity'#xD; #xD; // Condition Category Codes#xD; code "problem-list-item": 'problem-list-item' from "ConditionCategoryCodes" display 'Problem List Item'#xD; code "encounter-diagnosis": 'encounter-diagnosis' from "ConditionCategoryCodes" display 'Encounter Diagnosis'#xD; #xD; context Patient#xD; #xD; /*#xD; @description: Normalizes a value that is a choice of timing-valued types to an equivalent interval#xD; @comment: Normalizes a choice type of FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instance, FHIR.string, FHIR.Age, or FHIR.Range types#xD; to an equivalent interval. This selection of choice types is a superset of the majority of choice types that are used as possible#xD; representations for timing-valued elements in FHIR, allowing this function to be used across any resource.#xD; #xD; The input can be provided as a dateTime, Period, Timing, instant, string, Age, or Range.#xD; The intent of this function is to provide a clear and concise mechanism to treat single#xD; elements that have multiple possible representations as intervals so that logic doesn't have to account#xD; for the variability. More complex calculations (such as medication request period or dispense period#xD; calculation) need specific guidance and consideration. That guidance may make use of this function, but#xD; the focus of this function is on single element calculations where the semantics are unambiguous.#xD; If the input is a dateTime, the result a DateTime Interval beginning and ending on that dateTime.#xD; If the input is a Period, the result is a DateTime Interval.#xD; If the input is a Timing, an error is raised indicating a single interval cannot be computed from a Timing.#xD; If the input is an instant, the result is a DateTime Interval beginning and ending on that instant.#xD; If the input is a string, an error is raised indicating a single interval cannot be computed from a string.#xD; If the input is an Age, the result is a DateTime Interval beginning when the patient was the given Age,#xD; and ending immediately prior to when the patient was the given Age plus one year.#xD; If the input is a Range, the result is a DateTime Interval beginning when the patient was the Age given#xD; by the low end of the Range, and ending immediately prior to when the patient was the Age given by the#xD; high end of the Range plus one year.#xD; #xD; NOTE: Due to the#xD; complexity of determining a single interval from a Timing or String type, this function will throw a run-time exception if it is used#xD; with a Timing or String.#xD; */#xD; define function ToInterval(choice Choice<FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instant, FHIR.string, FHIR.Age, FHIR.Range>):#xD; case#xD; when choice is FHIR.dateTime then#xD; Interval[FHIRHelpers.ToDateTime(choice as FHIR.dateTime), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]#xD; when choice is FHIR.Period then#xD; FHIRHelpers.ToInterval(choice as FHIR.Period)#xD; when choice is FHIR.instant then#xD; Interval[FHIRHelpers.ToDateTime(choice as FHIR.instant), FHIRHelpers.ToDateTime(choice as FHIR.instant)]#xD; when choice is FHIR.Age then#xD; Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age),#xD; FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age) + 1 year)#xD; when choice is FHIR.Range then#xD; Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).low),#xD; FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).high) + 1 year)#xD; when choice is FHIR.Timing then#xD; //Interval[FHIRHelpers.ToDateTime(choice as FHIR.timing), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]#xD; Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute a single interval from a Timing type')#xD; when choice is FHIR.string then#xD; Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute an interval from a String value')#xD; else#xD; null as Interval<DateTime>#xD; end#xD; #xD; define function ToIntervalFromList(value List<FHIR.dateTime>):#xD; value v#xD; return ToInterval(v)#xD; #xD; define function NullToEmptyInterval(value List<Interval<DateTime>>):#xD; if value is not null then value else { }#xD; #xD; define function ToTimingInterval(timing FHIR.Timing):#xD; convert (#xD; NullToEmptyInterval(ToIntervalFromList(timing.event))#xD; union NullToEmptyInterval({ToInterval(timing.repeat.bounds as FHIR.Period)})#xD; ) to List<Interval<DateTime>> except { null }#xD; #xD; /*#xD; @description: Returns an interval representing the normalized Abatement of a given Condition resource.#xD; @comment: NOTE: Due to the complexity of determining an interval from a String, this function will throw#xD; a run-time exception if used with a Condition instance that has a String as the abatement value.#xD; */#xD; define function ToAbatementInterval(condition Condition):#xD; if condition.abatement is FHIR.dateTime then#xD; Interval[FHIRHelpers.ToDateTime(condition.abatement as FHIR.dateTime), FHIRHelpers.ToDateTime(condition.abatement as FHIR.dateTime)]#xD; else if condition.abatement is FHIR.Period then#xD; FHIRHelpers.ToInterval(condition.abatement as FHIR.Period)#xD; else if condition.abatement is FHIR.string then#xD; Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute an interval from a String value')#xD; else if condition.abatement is FHIR.Age then#xD; Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(condition.abatement as FHIR.Age),#xD; FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(condition.abatement as FHIR.Age) + 1 year)#xD; else if condition.abatement is FHIR.Range then#xD; Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((condition.abatement as FHIR.Range).low),#xD; FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((condition.abatement as FHIR.Range).high) + 1 year)#xD; else if condition.abatement is FHIR.boolean then#xD; Interval[end of ToInterval(condition.onset), condition.recordedDate)#xD; else null#xD; #xD; /*#xD; @description: Returns an interval representing the normalized prevalence period of a given Condition resource.#xD; @comment: Uses the ToInterval and ToAbatementInterval functions to determine the widest potential interval from#xD; onset to abatement as specified in the given Condition.#xD; */#xD; define function ToPrevalenceInterval(condition Condition):#xD; if condition.clinicalStatus ~ "active"#xD; or condition.clinicalStatus ~ "recurrence"#xD; or condition.clinicalStatus ~ "relapse" then#xD; Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition)]#xD; else#xD; Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition))#xD; #xD; /*#xD; @description: Returns any extensions defined on the given resource with the specified url.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the#xD; CQL model info.#xD; */#xD; define function Extensions(domainResource DomainResource, url String):#xD; domainResource.extension E#xD; where E.url = url#xD; return E#xD; #xD; /*#xD; @description: Returns the single extension (if present) on the given resource with the specified url.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function Extension(domainResource DomainResource, url String):#xD; singleton from "Extensions"(domainResource, url)#xD; #xD; /*#xD; @description: Returns any extensions defined on the given element with the specified url.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the CQL model info.#xD; */#xD; define function Extensions(element Element, url String):#xD; element.extension E#xD; where E.url = url#xD; return E#xD; #xD; /*#xD; @description: Returns the single extension (if present) on the given element with the specified url.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function Extension(element Element, url String):#xD; singleton from Extensions(element, url)#xD; #xD; /*#xD; @description: Returns any modifier extensions defined on the given resource with the specified url.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the#xD; CQL model info.#xD; */#xD; define function ModifierExtensions(domainResource DomainResource, url String):#xD; domainResource.modifierExtension E#xD; where E.url = url#xD; return E#xD; #xD; /*#xD; @description: Returns the single modifier extension (if present) on the given resource with the specified url.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function ModifierExtension(domainResource DomainResource, url String):#xD; singleton from ModifierExtensions(domainResource, url)#xD; #xD; /*#xD; @description: Returns any modifier extensions defined on the given element with the specified url.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the CQL model info.#xD; */#xD; define function ModifierExtensions(element BackboneElement, url String):#xD; element.modifierExtension E#xD; where E.url = url#xD; return E#xD; #xD; /*#xD; @description: Returns the single modifier extension (if present) on the given element with the specified url.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function ModifierExtension(element BackboneElement, url String):#xD; singleton from ModifierExtensions(element, url)#xD; #xD; /*#xD; @description: Returns any base-FHIR extensions defined on the given resource with the specified id.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the CQL model info.#xD; */#xD; define function BaseExtensions(domainResource DomainResource, id String):#xD; domainResource.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single base-FHIR extension (if present) on the given resource with the specified id.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function BaseExtension(domainResource DomainResource, id String):#xD; singleton from BaseExtensions(domainResource, id)#xD; #xD; /*#xD; @description: Returns any base-FHIR extensions defined on the given element with the specified id.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the CQL model info.#xD; */#xD; define function BaseExtensions(element Element, id String):#xD; element.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single base-FHIR extension (if present) on the given element with the specified id.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function BaseExtension(element Element, id String):#xD; singleton from BaseExtensions(element, id)#xD; #xD; /*#xD; @description: Returns any base-FHIR modifier extensions defined on the given resource with the specified id.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the CQL model info.#xD; */#xD; define function BaseModifierExtensions(domainResource DomainResource, id String):#xD; domainResource.modifierExtension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single base-FHIR modifier extension (if present) on the given resource with the specified id.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function BaseModifierExtension(domainResource DomainResource, id String):#xD; singleton from BaseModifierExtensions(domainResource, id)#xD; #xD; /*#xD; @description: Returns any base-FHIR modifier extensions defined on the given element with the specified id.#xD; @comment: NOTE: Extensions are not the preferred approach, but are used as a way to access#xD; content that is defined by extensions but not yet surfaced in the CQL model info.#xD; */#xD; define function BaseModifierExtensions(element BackboneElement, id String):#xD; element.modifierExtension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single base-FHIR extension (if present) on the given element with the specified id.#xD; @comment: This function uses singleton from to ensure that a run-time exception is thrown if there#xD; is more than one extension on the given resource with the specified url.#xD; */#xD; define function BaseModifierExtension(element BackboneElement, id String):#xD; singleton from BaseModifierExtensions(element, id)#xD; Content: application/elm+xml Encoded data (337404 characters) Content: application/elm+json Encoded data (640772 characters)
Code system ConditionClinicalStatusCodes
Code system ConditionVerificationStatusCodes
Code system AllergyIntoleranceClinicalStatusCodes
Code system AllergyIntoleranceVerificationStatusCodes