Using CQL with FHIR
1.0.0-ballot - Ballot International flag

This page is part of the Using CQL with FHIR Implementation Guide (v1.0.0-ballot: STU1 Ballot 1) based on FHIR (HL7® FHIR® Standard) R4. . For a full list of available versions, see the Directory of published versions

Example Library: ANC Cohort

Active as of 2023-12-20

Related Artifacts

depends-onFHIR model informationhttp://example.org/fhir/Library/FHIR-ModelInfo
depends-onLibrary FHIRHelpershttp://example.org/fhir/Library/FHIRHelpers
depends-onLibrary FCFHIR Common
depends-onCode system ANCM Concept CodesANCM Concept Codes

Parameters

Is pregnancy confirmedout01boolean
Is Antenatal Care Applicableout01boolean

Data Requirements

Type: Observation (Observation)
FilterValue
codeOne of these codes: ANCM Concept Codes ANC.B4.DE1: Pregnancy confirmed

Contents

text/cql

library ANCCohort

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'
include FHIRCommon called FC

codesystem "ANCM Concept Codes": 'http://fhir.org/guides/who/smart-anc-mini/CodeSystem/concept-codes'

code "Pregnancy confirmed": 'ANC.B4.DE1' from "ANCM Concept Codes" display 'Pregnancy confirmed'

define "Is Antenatal Care Applicable":
  "Is pregnancy confirmed" is true


/* Copied from ANCMContactDataElements */
/*
  @dataElement: ANC.B4.DE1 Pregnancy confirmed
  @activity: ANC.B4 Confirm pregnancy
  @description: Pregnancy has been confirmed
*/
define "Is pregnancy confirmed":
  MostRecent(
    Final([Observation: "Pregnancy confirmed"])
  ).value as boolean

/* Copied from WHOCommon */
define function Final(observations List<Observation>):
  observations O
    where O.status in { 'final', 'amended', 'corrected' }
      and Coalesce(ModifierExtension(O, 'who-notDone').value, false) is false
      and O.value is not null

define function MostRecent(observations List<Observation>):
  Last(
    observations O
      sort by issued
  )

/*
@description: Returns any WHO core modifier extensions defined on the given resource with the specified id.
@comment: NOTE: Extensions are not the preferred approach, but are used as a way to access
content that is defined by extensions but not yet surfaced in the
CQL model info.
*/
define function ModifierExtensions(domainResource DomainResource, id String):
  domainResource.modifierExtension E
	  where E.url = ('http://fhir.org/guides/who/core/StructureDefinition/' + id)
		return E

/*
@description: Returns the single WHO core modifier extension (if present) on the given resource with the specified id.
@comment: This function uses singleton from to ensure that a run-time exception is thrown if there
is more than one extension on the given resource with the specified url.
*/
define function ModifierExtension(domainResource DomainResource, id String):
  singleton from ModifierExtensions(domainResource, id)

Content not shown - (application/elm+xml, size = 24Kb)

Content not shown - (application/elm+json, size = 42Kb)