Id: AlphoraCommon Version: 0.1.0 Url: AlphoraCommon 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 http://fhir.org/guides/cqf/aphl/chronic-ds/Library/FHIRCommon|1.1.000 Observation Category Codes Condition Clinical Status 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 library AlphoraCommon#xD; #xD; using FHIR version '4.0.1'#xD; #xD; include FHIRHelpers version '4.1.000' called FHIRHelpers#xD; include FHIRCommon version '1.1.000' called FC #xD; #xD; codesystem "ObservationCategoryCodes": 'http://terminology.hl7.org/CodeSystem/observation-category'#xD; codesystem "ConditionClinicalStatusCodes": 'http://terminology.hl7.org/CodeSystem/condition-clinical'#xD; #xD; code "laboratory": 'laboratory' from "ObservationCategoryCodes" display 'laboratory'#xD; code "exam": 'exam' from "ObservationCategoryCodes" display 'exam'#xD; code "survey": 'survey' from "ObservationCategoryCodes" display 'survey'#xD; code "vital-signs": 'vital-signs' from "ObservationCategoryCodes" display 'vital-signs'#xD; code "active": 'active' from "ConditionClinicalStatusCodes"#xD; #xD; context Patient#xD; #xD; define function Official(identifiers List<Identifier>):#xD; singleton from (identifiers I where I.use = 'official')#xD; #xD; define function Official(names List<HumanName>):#xD; singleton from (names N where N.use = 'official')#xD; #xD; define function Only(observations List<Observation>):#xD; singleton from observations#xD; #xD; define function Earliest(observations List<Observation>):#xD; First(#xD; observations O#xD; sort by issued#xD; )#xD; #xD; define function Latest(observations List<Observation>):#xD; Last(#xD; observations O#xD; sort by effective#xD; )#xD; #xD; define function MostRecent(observations List<Observation>):#xD; Last(#xD; observations O#xD; sort by start of FC.ToInterval(effective)#xD; )#xD; #xD; define function MostRecent(encounters List<Encounter>):#xD; Last(#xD; encounters O#xD; sort by start of period#xD; )#xD; #xD; define function MostRecent(servicerequest List<ServiceRequest>):#xD; Last(#xD; servicerequest O#xD; sort by authoredOn#xD; )#xD; #xD; define function MostRecent(procedures List<Procedure>):#xD; Last(#xD; procedures O#xD; sort by (performed as FHIR.dateTime)#xD; )#xD; #xD; define function Lowest(observations List<Observation>):#xD; First(#xD; observations O#xD; sort by (value as FHIR.Quantity)#xD; )#xD; #xD; define function Highest(observations List<Observation>):#xD; Last(#xD; observations O#xD; sort by (value as FHIR.Quantity)#xD; )#xD; #xD; define function MaxDates(assessmentsDates List<Interval<DateTime>>)#xD; returns Interval<DateTime>:#xD; First((#xD; (assessmentsDates) AssessmentDates#xD; return Tuple{ AssessmentDate: AssessmentDates}#xD; ) StartDate#xD; sort by start of AssessmentDate descending#xD; ).AssessmentDate#xD; #xD; define function MaxDates(assessmentsDates List<Interval<Date>>)#xD; returns Interval<Date>:#xD; First((#xD; (assessmentsDates) AssessmentDates#xD; return Tuple{ AssessmentDate: AssessmentDates}#xD; ) StartDate#xD; sort by start of AssessmentDate descending#xD; ).AssessmentDate#xD; #xD; define function MinDates(assessmentsDates List<Interval<DateTime>>)#xD; returns Interval<DateTime>:#xD; First((#xD; (assessmentsDates) AssessmentDates#xD; where not(start of AssessmentDates is null)#xD; return Tuple{ AssessmentDate: AssessmentDates}#xD; ) StartDate#xD; sort by start of AssessmentDate ascending#xD; ).AssessmentDate#xD; #xD; define function GetId(uri String):#xD; Last(Split(uri, '/'))#xD; #xD; /*define function GetId(uri List<String>):#xD; uri uri#xD; return GetId(uri)#xD; */#xD; define function GetIdList(list List<String>):#xD; list uri#xD; return Last(Split(uri, '/'))#xD; #xD; /*#xD; @description: verifies that quantity types have the given unit.#xD; @comment: NOTE: This function evaluates correctly in the cql-language plugin as of 2.10.1 but not in the cql-tooling traslator as of 9/20/21#xD; */#xD; /* define function WithUnit(value FHIR.Quantity, unit String):#xD; (#xD; value quantity#xD; where (#xD; quantity.code.value ~ unit#xD; or quantity.unit.value ~ unit#xD; )#xD; ) is not null#xD; */#xD; #xD; /*#xD; @description: Returns any Alphora 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#xD; CQL model info.#xD; */#xD; define function Extensions(domainResource DomainResource, id String):#xD; domainResource.extension E#xD; where E.url = ('http://content.alphora.com/fhir/dqm' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single Alphora 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 id.#xD; */#xD; define function Extension(domainResource DomainResource, id String):#xD; singleton from "Extensions"(domainResource, id)#xD; #xD; /*#xD; @description: Returns any Alphora 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 Extensions(element Element, id String):#xD; element.extension E#xD; where E.url = ('http://content.alphora.com/fhir/dqm' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single Alphora 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 Extension(element Element, id String):#xD; singleton from Extensions(element, id)#xD; #xD; /*#xD; @description: Returns any Alphora 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#xD; CQL model info.#xD; */#xD; define function ModifierExtensions(domainResource DomainResource, id String):#xD; domainResource.modifierExtension E#xD; where E.url = ('http://content.alphora.com/fhir/dqm' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single Alphora 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 ModifierExtension(domainResource DomainResource, id String):#xD; singleton from ModifierExtensions(domainResource, id)#xD; #xD; /*#xD; @description: Returns any Alphora 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 ModifierExtensions(element BackboneElement, id String):#xD; element.modifierExtension E#xD; where E.url = ('http://content.alphora.com/fhir/dqm' + id)#xD; return E#xD; #xD; /*#xD; @description: Returns the single Alphora modifier 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 ModifierExtension(element BackboneElement, id String):#xD; singleton from ModifierExtensions(element, id)#xD; #xD; #xD; /* QI-CORE Extensions */#xD; #xD; /*#xD; 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 QICoreModifierExtensions(domainResource DomainResource, url String):#xD; domainResource.modifierExtension E#xD; where E.url = ('http://hl7.org/fhir/us/qicore/StructureDefinition/' + url)#xD; return E#xD; #xD; define function QICoreModifierExtension(domainResource DomainResource, url String):#xD; singleton from QICoreModifierExtensions(domainResource, url)#xD; #xD; define function QICoreExtensions(domainResource DomainResource, url String):#xD; domainResource.extension E#xD; where E.url = ('http://hl7.org/fhir/us/qicore/StructureDefinition/' + url)#xD; return E#xD; #xD; define function QICoreExtension(domainResource DomainResource, url String):#xD; singleton from QICoreExtensions(domainResource, url)#xD; #xD; define function GetBaseModifierExtensions(domainResource DomainResource, url String):#xD; domainResource.modifierExtension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/' + url)#xD; return E#xD; #xD; define function GetBaseModifierExtension(domainResource DomainResource, url String):#xD; singleton from GetBaseModifierExtensions(domainResource, url)#xD; #xD; define function GetBaseExtensions(domainResource DomainResource, url String):#xD; domainResource.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/' + url)#xD; return E#xD; #xD; define function GetBaseExtension(domainResource DomainResource, url String):#xD; singleton from GetBaseExtensions(domainResource, url)#xD; #xD; define function GetUSModifierExtensions(domainResource DomainResource, url String):#xD; domainResource.modifierExtension E#xD; where E.url = ('http://hl7.org/fhir/us/core/StructureDefinition/' + url)#xD; return E#xD; #xD; define function GetUSModifierExtension(domainResource DomainResource, url String):#xD; singleton from GetUSModifierExtensions(domainResource, url)#xD; #xD; define function GetUSExtensions(domainResource DomainResource, url String):#xD; domainResource.extension E#xD; where E.url = ('http://hl7.org/fhir/us/core/StructureDefinition/' + url)#xD; return E#xD; #xD; define function GetUSExtension(domainResource DomainResource, url String):#xD; singleton from GetUSExtensions(domainResource, url)#xD; #xD; define function GetExtensionValue(extension Extension):#xD; extension.value.value#xD; #xD; define function ResourceNotDone(notDone DomainResource):#xD; QICoreModifierExtension(notDone, 'qicore-notDone')#xD; #xD; define function ResourceNotDoneReason(notDoneReason DomainResource):#xD; QICoreExtension(notDoneReason, 'qicore-notDoneReason')#xD; #xD; define function ResourceNotDoneReason(choice Choice<FHIR.Communication, FHIR.Immunization, FHIR.MedicationAdministration, FHIR.MedicationDispense, FHIR.MedicationRequest, FHIR.Observation, FHIR.Procedure, FHIR.ServiceRequest>):#xD; case#xD; when choice is FHIR.Observation then#xD; ResourceNotDoneReason(choice as FHIR.Observation)#xD; when choice is FHIR.ServiceRequest then#xD; ResourceDoNotPerformReason(choice as FHIR.ServiceRequest)#xD; else null#xD; end#xD; #xD; define function ResourceDoNotPerformReason(doNotPerformReason DomainResource):#xD; QICoreExtension(doNotPerformReason, 'qicore-doNotPerformReason') #xD; #xD; define function ResourceNotDoneRecorded(recorded DomainResource):#xD; QICoreExtension(recorded, 'qicore-recorded')#xD; #xD; define function ResourceNotDoneRecorded(choice Choice<FHIR.Communication, FHIR.Immunization, FHIR.MedicationAdministration, FHIR.MedicationDispense, FHIR.MedicationRequest, FHIR.Observation, FHIR.Procedure, FHIR.ServiceRequest>):#xD; case#xD; when choice is FHIR.Communication then#xD; QICoreExtension(choice as FHIR.Communication, 'qicore-recorded')#xD; when choice is FHIR.MedicationAdministration then#xD; QICoreExtension(choice as FHIR.MedicationAdministration, 'qicore-recorded')#xD; when choice is FHIR.MedicationDispense then#xD; QICoreExtension(choice as FHIR.MedicationDispense, 'qicore-recorded')#xD; when choice is FHIR.Procedure then#xD; QICoreExtension(choice as FHIR.Procedure, 'qicore-recorded')#xD; else null#xD; end#xD; #xD; define function NotDoneValueSet(choice Choice<FHIR.Communication, FHIR.DeviceRequest, FHIR.Immunization, FHIR.MedicationAdministration, FHIR.MedicationDispense, FHIR.MedicationRequest,#xD; FHIR.Observation, FHIR.Procedure, FHIR.ServiceRequest>):#xD; case#xD; when choice is FHIR.Communication then#xD; GetExtensionValue(#xD; singleton from (choice.reasonCode.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.DeviceRequest then#xD; GetExtensionValue(#xD; singleton from (choice.code.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.Immunization then#xD; GetExtensionValue(#xD; singleton from (choice.vaccineCode.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.MedicationAdministration then#xD; GetExtensionValue(#xD; singleton from (choice.medication.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.MedicationDispense then#xD; GetExtensionValue(#xD; singleton from (choice.medication.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.MedicationRequest then#xD; GetExtensionValue(#xD; singleton from (choice.medication.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.Observation then#xD; GetExtensionValue(#xD; singleton from (choice.code.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.Procedure then#xD; GetExtensionValue(#xD; singleton from (choice.code.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; when choice is FHIR.ServiceRequest then#xD; GetExtensionValue(#xD; singleton from (choice.code.coding.extension E#xD; where E.url = ('http://hl7.org/fhir/StructureDefinition/valueset-reference')#xD; ))#xD; else null#xD; end#xD; #xD; #xD; define function AbsentData(observation List<FHIR.Observation>, enc List<FHIR.Encounter>, code1 System.Code, valueset1 System.ValueSet)#xD; returns List<FHIR.Observation>:#xD; (QualifiedObservations(observation)) Obs#xD; with enc QualifyingEnc#xD; such that Coalesce(end of FC.ToInterval(Obs.effective), end of FC.ToInterval(Obs.issued)) same day as end of QualifyingEnc.period#xD; where exists(#xD; Obs.component c where(#xD; c.code as CodeableConcept ~ code1#xD; or c.code as CodeableConcept in valueset1#xD; ))#xD; and not exists(Obs.component c where(c.value is not null))#xD; or (ResourceNotDone(Obs).value as FHIR.boolean = true#xD; and (ResourceNotDoneReason(Obs).value as CodeableConcept ~ code1#xD; or ResourceNotDoneReason(Obs).value as CodeableConcept in valueset1))#xD; #xD; /* Common Resource Qualifications and Negations */#xD; define function QualifiedEncounters(value List<FHIR.Encounter>):#xD; value Encounter#xD; where (#xD; //planned | arrived | triaged | in-progress | onleave | finished | cancelled | entered-in-error | unknown#xD; Encounter.status ~ 'arrived'#xD; or Encounter.status ~ 'in-progress'#xD; or Encounter.status ~ 'finished'#xD; or Encounter.status ~ 'onleave'#xD; or Encounter.status ~ 'triaged'#xD; )#xD; #xD; define function QualifiedConditions(value List<FHIR.Condition>):#xD; value Condition#xD; where (#xD; FHIRHelpers.ToConcept(Condition.clinicalStatus) ~ FC."active"#xD; )#xD; and (#xD; FHIRHelpers.ToConcept(Condition.verificationStatus) ~ FC."confirmed"#xD; )#xD; #xD; define function QualifiedProcedures(value List<FHIR.Procedure>):#xD; value Procedure#xD; where (#xD; //preparation | in-progress | not-done | on-hold | stopped | completed | entered-in-error | unknown#xD; Procedure.status ~ 'completed'#xD; )#xD; #xD; define function QualifiedDeviceRequests(value List<FHIR.DeviceRequest>):#xD; value DeviceRequest#xD; where (#xD; //draft | active | on-hold | revoked | completed | entered-in-error | unknown#xD; DeviceRequest.status ~ 'completed'#xD; or DeviceRequest.status ~ 'active'#xD; and DeviceRequest.intent ~ 'order'#xD; )#xD; #xD; define function QualifiedObservations(value List<FHIR.Observation>):#xD; value Observation#xD; where (#xD; //registered | preliminary | final | amended | corrected | cancelled | entered-in-error | unknown#xD; Observation.status ~ 'final'#xD; or Observation.status ~ 'amended'#xD; or Observation.status ~ 'corrected'#xD; )#xD; #xD; define function FinalSurveyObservations(value List<FHIR.Observation>):#xD; value Observation#xD; where (#xD; //registered | preliminary | final | amended | corrected | cancelled | entered-in-error | unknown#xD; Observation.status ~ 'final'#xD; or Observation.status ~ 'amended'#xD; or Observation.status ~ 'corrected'#xD; and exists(Observation.category ObservationCategory#xD; where ( ObservationCategory ) ~ "survey")#xD; )#xD; #xD; define function LaboratoryObservation(value List<FHIR.Observation>):#xD; value Observation#xD; where (#xD; //registered | preliminary | final | amended | corrected | cancelled | entered-in-error | unknown#xD; Observation.status ~ 'final'#xD; or Observation.status ~ 'amended'#xD; or Observation.status ~ 'corrected'#xD; and exists(Observation.category ObservationCategory#xD; where ( ObservationCategory ) ~ "laboratory" or (ObservationCategory) is null)#xD; )#xD; #xD; #xD; define function QualifiedMedicationRequests(value List<FHIR.MedicationRequest>):#xD; value MedicationRequest#xD; where (#xD; //active | on-hold | cancelled | completed | entered-in-error | stopped | draft | unknown#xD; (MedicationRequest.status ~ 'active'#xD; or MedicationRequest.status ~ 'completed'#xD; )#xD; and (#xD; MedicationRequest.doNotPerform is null#xD; or MedicationRequest.doNotPerform = false#xD; )#xD; and MedicationRequest.intent ~ 'order'#xD; )#xD; #xD; define function QualifiedMedicationStatements(value List<FHIR.MedicationStatement>):#xD; value MedicationStatement#xD; where (#xD; // active | completed | entered-in-error | intended | stopped | on-hold | unknown | not-taken#xD; MedicationStatement.status ~ 'active'#xD; or MedicationStatement.status ~ 'completed'#xD; )#xD; #xD; define function QualifiedMedicationDispenses(value List<FHIR.MedicationDispense>):#xD; value MedicationDispense#xD; // preparation | in-progress | cancelled | on-hold | completed | entered-in-error | stopped | declined | unknown#xD; where (#xD; MedicationDispense.status ~ 'on-hold'#xD; or MedicationDispense.status ~ 'in-progress'#xD; or MedicationDispense.status ~ 'completed'#xD; )#xD; #xD; define function QualifiedServiceRequests(value List<FHIR.ServiceRequest>):#xD; value ServiceRequest#xD; where (#xD; //draft | active | on-hold | revoked | completed | entered-in-error | unknown#xD; ServiceRequest.status ~ 'active'#xD; or ServiceRequest.status ~ 'completed'#xD; and ServiceRequest.intent ~ 'order'#xD; )#xD; and (#xD; ServiceRequest.doNotPerform is null#xD; or ServiceRequest.doNotPerform = false#xD; )#xD; #xD; define function QualifiedAllergyIntolerances(value List<FHIR.AllergyIntolerance>):#xD; value AllergyIntolerance#xD; where (#xD; //active | inactive | resolved#xD; FHIRHelpers.ToConcept(AllergyIntolerance.clinicalStatus) ~ FC."allergy-active"#xD; )#xD; and (#xD; //unconfirmed | confirmed | refuted | entered-in-error#xD; FHIRHelpers.ToConcept(AllergyIntolerance.verificationStatus) ~ FC."allergy-confirmed"#xD; )#xD; #xD; define function QualifiedImmunizations(value List<FHIR.Immunization>):#xD; value Immunization#xD; where (#xD; //completed | entered-in-error | not-done#xD; Immunization.status ~ 'completed'#xD; )#xD; #xD; define function QualifiedCommunications(value List<FHIR.Communication>):#xD; value Communication#xD; where (#xD; //preparation | in-progress | not-done | on-hold | stopped | completed | entered-in-error | unknown#xD; Communication.status ~ 'completed'#xD; )#xD; #xD; define function QualifiedMedications(value List<FHIR.Medication>):#xD; value Medication#xD; where (#xD; //active | inactive | entered-in-error#xD; Medication.status ~ 'active'#xD; )#xD; #xD; define function QualifiedMedicationAdministrations(value List<FHIR.MedicationAdministration>):#xD; value MedicationAdministration#xD; where (#xD; //in-progress | not-done | on-hold | completed | entered-in-error | stopped | unknown#xD; MedicationAdministration.status ~ 'completed'#xD; )#xD; #xD; define function QualifiedLocations(value List<FHIR.Location>):#xD; value Location#xD; where (#xD; //active | suspended | inactive#xD; Location.status ~ 'active'#xD; )#xD; #xD; define function NotDoneObservations(value List<FHIR.Observation>):#xD; value Observation#xD; where (#xD; //registered | preliminary | final | amended | corrected | cancelled | entered-in-error | unknown#xD; Observation.status ~ 'final'#xD; )#xD; and (#xD; ResourceNotDone(Observation).value as FHIR.boolean = true#xD; )#xD; #xD; define function NotRequestedServiceRequests(value List<FHIR.ServiceRequest>):#xD; value ServiceRequest#xD; where (#xD; //draft | active | on-hold | revoked | completed | entered-in-error | unknown#xD; ServiceRequest.status ~ 'completed'#xD; )#xD; and (#xD; ServiceRequest.doNotPerform = true#xD; )#xD; #xD; define function NotRequestedMedicationRequests(value List<FHIR.MedicationRequest>):#xD; value MedicationRequest#xD; where (#xD; //active | on-hold | cancelled | completed | entered-in-error | stopped | draft | unknown#xD; MedicationRequest.status ~ 'completed'#xD; and MedicationRequest.doNotPerform = true#xD; )#xD; #xD; define function NotDoneProcedures(value List<FHIR.Procedure>):#xD; value Procedure#xD; where (#xD; //preparation | in-progress | not-done | on-hold | stopped | completed | entered-in-error | unknown#xD; Procedure.status ~ 'not-done'#xD; )#xD; #xD; define function NotDoneMedicationAdministrations(value List<FHIR.MedicationAdministration>):#xD; value MedicationAdministration#xD; where (#xD; //in-progress | not-done | on-hold | completed | entered-in-error | stopped | unknown#xD; MedicationAdministration.status ~ 'not-done'#xD; )#xD; Content: application/elm+xml Encoded data (546312 characters) Content: application/elm+json Encoded data (981256 characters)
Code system ConditionClinicalStatusCodes