WHO Immunization Implementation Guide
0.2.0 - ci-build

WHO Immunization Implementation Guide, published by WHO. This guide is not an authorized publication; it is the continuous build for version 0.2.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/WorldHealthOrganization/smart-immunizations/ and changes regularly. See the Directory of published versions

Library: IMMZEncounterElements

Official URL: http://smart.who.int/immunizations/Library/IMMZEncounterElements Version: 0.2.0
Draft as of 2025-08-08 Computable Name: IMMZEncounterElements

This library defines encounter-based elements used throughout the Immunization CPG

Title: IMMZEncounterElements
Id: IMMZEncounterElements
Version: 0.2.0
Url: IMMZEncounterElements
Status: draft
Type:

system: http://terminology.hl7.org/CodeSystem/library-type

code: logic-library

Date: 2025-08-08 19:12:11+0000
Publisher: WHO
Description:

This library defines encounter-based elements used throughout the Immunization CPG

Related Artifacts:

Dependencies

Parameters:
NameTypeMinMaxIn/Out
Todaydate01In
EncounterIdstring01In
PatientPatient01Out
Doses Administered to PatientImmunization0*Out
Draft Medication Request for PatientMedicationRequest0*Out
Live Attenuated VaccinesImmunization0*Out
Date of Latest Live Attenuated Vaccinedate01Out
Current Patient Age In Yearsinteger01Out
Current Patient Age In Monthsinteger01Out
Current Patient Age In Weeksinteger01Out
Current Patient Age In Daysinteger01Out
No live vaccine was administeredboolean01Out
Live vaccine was administered in the last 4 weeksboolean01Out
No live vaccine was administered in the last 4 weeksboolean01Out
CI Currently pregnant ObservationObservation0*Out
CI Currently pregnant ConditionCondition0*Out
The client is pregnantboolean01Out
CI History of anaphylactic reactions ObservationObservation0*Out
CI History of anaphylactic reactions ConditionCondition0*Out
The client has history of anaphylactic reactionsboolean01Out
CI Severe allergic reactions ObservationObservation0*Out
CI Severe allergic reactions ConditionCondition0*Out
The client has history of severe allergic reactionsboolean01Out
CI Severely immunocompromised ObservationObservation0*Out
CI Severely immunocompromised ConditionCondition0*Out
The client is severely immunocompromisedboolean01Out
CI Severely immunosuppressed ObservationObservation0*Out
CI Severely immunosuppressed ConditionCondition0*Out
The client is severely immunosuppressedboolean01Out
CI Symptomatic HIV infection ObservationObservation0*Out
CI Symptomatic HIV infection ConditionCondition0*Out
The client has a symptomatic HIV infectionboolean01Out
CI Immunodeficiency syndromes ObservationObservation0*Out
CI Immunodeficiency syndromes ConditionCondition0*Out
The client has immunodeficiency syndromesboolean01Out
CI Exposed to immunosuppressive treatment ObservationObservation0*Out
CI Exposed to immunosuppressive treatment ConditionCondition0*Out
The client is exposed to immunosuppressive treatmentboolean01Out
CI Severe acute illness ObservationObservation0*Out
CI Severe acute illness ConditionCondition0*Out
The client currently has a severe acute illnessboolean01Out
CI Prior history of intussusception ObservationObservation0*Out
CI Prior history of intussusception ConditionCondition0*Out
The client has prior history of intussusceptionboolean01Out
CI Altered immunocompetence ObservationObservation0*Out
CI Altered immunocompetence ConditionCondition0*Out
The client has altered immunocompetenceboolean01Out
CI Spina bifida ObservationObservation0*Out
CI Spina bifida ConditionCondition0*Out
The client has spina bifidaboolean01Out
CI Bladder exstrophy ObservationObservation0*Out
CI Bladder exstrophy ConditionCondition0*Out
The client has bladder exstrophyboolean01Out
Immunocompromised ObservationObservation0*Out
Client is immunocompromisedboolean01Out
CI Immunocompromised ObservationObservation0*Out
CI Immunocompromised ConditionCondition0*Out
The client is immunocompromisedboolean01Out
CI Planning to get pregnant in the next month ObservationObservation0*Out
CI Planning to get pregnant in the next month ConditionCondition0*Out
The client is planning to get pregnant in next monthboolean01Out
CI Receiving blood products ObservationObservation0*Out
CI Receiving blood products ConditionCondition0*Out
The client is receiving blood productsboolean01Out
CI TB disease ObservationObservation0*Out
CI TB disease ConditionCondition0*Out
The client has TB diseaseboolean01Out
CI Breastfeeding ObservationObservation0*Out
CI Breastfeeding ConditionCondition0*Out
The client is lactatingboolean01Out
CI Acute gastroenteritis ObservationObservation0*Out
CI Acute gastroenteritis ConditionCondition0*Out
The client has acute gastroenteritisboolean01Out
CI Moderate to severe fever ObservationObservation0*Out
CI Moderate to severe fever ConditionCondition0*Out
The client has moderate to severe feverboolean01Out
CI Hypersensitivity to vaccine components ObservationObservation0*Out
CI Hypersensitivity to vaccine components ConditionCondition0*Out
The client has hypersensitivity to any component of the vaccineboolean01Out
CI Taking antibiotics ObservationObservation0*Out
CI Taking antibiotics ConditionCondition0*Out
The client is currently taking antibioticsboolean01Out
CI Chronic gastrointestinal disease ObservationObservation0*Out
CI Chronic gastrointestinal disease ConditionCondition0*Out
The client has chronic gastrointestinal diseaseboolean01Out
Client's HIV status is positiveboolean01Out
Client's HIV status is negative or unknownboolean01Out
Client is currently receiving antiretroviral therapyboolean01Out
Client is currently not receiving antiretroviral therapyboolean01Out
Immunologically stable ObservationObservation0*Out
Client is immunologically stableboolean01Out
Client is not immunologically stableboolean01Out
TB infection test result ObservationObservation0*Out
Client's TB infection test result is negativeboolean01Out
Client's TB infection test result is positiveboolean01Out
Client's TB infection test result is unknown (test not done or no result yet)boolean01Out
Clinically well ObservationObservation0*Out
Client is not clinically wellboolean01Out
Client is clinically wellboolean01Out
Client is not immunocompromisedboolean01Out
Birth weight in grams ObservationObservation0*Out
Birth weight in grams ValueQuantity01Out
Birth weight in gramsdecimal01Out
Client's weight at birth was over 2000 gboolean01Out
Client's weight at birth was below 2000 gboolean01Out
Preterm birth ObservationObservation0*Out
Client was a premature infant at birthboolean01Out
Client was not a premature infant at birthboolean01Out
Completed the primary vaccination series ObservationObservation0*Out
At high risk for pneumococcal infection ObservationObservation0*Out
Client is at high risk for pneumococcal infectionboolean01Out
Client is not at high risk for pneumococcal infectionboolean01Out
Date when primary vaccination series was completed ObservationObservation0*Out
Completed the booster series ObservationObservation0*Out
Content: text/cql
library IMMZEncounterElements

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'

include WHOConcepts
include WHOCommon called WC
include WHOEncounterElements called WE

include IMMZConcepts called Concepts
include IMMZCommon called Common
include IMMZElements called Elements

parameter Today Date default Today()
parameter EncounterId String

context Patient

/**
 * @dataElement All Doses Administered to Patient
 */
define "Doses Administered to Patient":
  Elements."Doses Administered to Patient" I
    where I.occurrence.toInterval() same day or before Today

/*
@dataElement: Draft Medication Request for Patient
*/
define "Draft Medication Request for Patient":
  Elements."Draft Medication Request for Patient" MR
    where MR.encounter.references(EncounterId) 
      or MR.authoredOn.toInterval() same day or before Today
  	sort by date from (authoredOn as FHIR.dateTime) desc

/*
@dataElement Live attenuated vaccines
*/
define "Live Attenuated Vaccines":
  Elements."Live Attenuated Vaccines" I
    where I.occurrence.toInterval() same day or before Today

/*
@dataElement Date and time of last live attenuated vaccine
*/
define "Date of Latest Live Attenuated Vaccine":
  date from start of "Live Attenuated Vaccines".mostRecent().occurrence.toInterval()
  
/** 
 * @dataElement Patient age in years
 */
define "Current Patient Age In Years":
  AgeInYearsAt(Today)

/** 
 * @dataElement Patient age in months
 */
define "Current Patient Age In Months":
  AgeInMonthsAt(Today)

/** 
 * @dataElement Patient age in weeks
 */
define "Current Patient Age In Weeks":
  AgeInWeeksAt(Today)

/** 
 * @dataElement Patient age in days
 */
define "Current Patient Age In Days":
  AgeInDaysAt(Today)

/*
@input: No live vaccine was administered
@pseudocode: Today's date − latest "Date and time of vaccination" (where "Live vaccine" = TRUE) IS NULL
*/
define "No live vaccine was administered":
  not exists("Live Attenuated Vaccines")

/*
@input: Live vaccine was administered in the last 4 weeks
@pseudocode: Today's date − latest "Date and time of vaccination" (where "Live vaccine" = TRUE) < 4 weeks
*/
define "Live vaccine was administered in the last 4 weeks":
	"Date of Latest Live Attenuated Vaccine" is not null 
    and duration in weeks between "Date of Latest Live Attenuated Vaccine" and Today < 4

/*
@input: No live vaccine was administered in the last 4 weeks
@pseudocode: Today's date − latest "Date and time of vaccination" (where "Live vaccine" = TRUE) ≥ 4 weeks
*/
define "No live vaccine was administered in the last 4 weeks":
  not("Live vaccine was administered in the last 4 weeks")

/*
@input: The client is pregnant
@pseudocode: "Potential contraindications" = "Currently pregnant"
*/
define "The client is pregnant":
  exists "CI Currently pregnant Observation"
  or exists "CI Currently pregnant Condition"
  or exists WE."Pregnant Observation"

/*
@internal: Observation for currently pregnant
*/
define "CI Currently pregnant Observation":
  Elements."CI Currently pregnant Observation" O
    where O.encounter.references(EncounterId)
      or O.effective.toInterval() starts same day or after Today - 9 months

/*
@internal: Condition for currently pregnant
*/
define "CI Currently pregnant Condition":
  Elements."CI Currently pregnant Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has history of anaphylactic reactions
@pseudocode: "Potential contraindications" = "History of anaphylactic reactions"
*/
define "The client has history of anaphylactic reactions":
  exists "CI History of anaphylactic reactions Observation"
    or exists "CI History of anaphylactic reactions Condition"
    
/*
@internal: Observation for History of anaphylactic reactions
*/
define "CI History of anaphylactic reactions Observation":
  Elements."CI History of anaphylactic reactions Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for History of anaphylactic reactions
*/
define "CI History of anaphylactic reactions Condition":
  Elements."CI History of anaphylactic reactions Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has history of severe allergic reactions
@pseudocode: "Potential contraindications" = "Severe allergic reactions"
*/
define "The client has history of severe allergic reactions":
  exists "CI Severe allergic reactions Observation"
    or exists "CI Severe allergic reactions Condition"
    
/*
@internal: Observation for Severe allergic reactions
*/
define "CI Severe allergic reactions Observation":
  Elements."CI Severe allergic reactions Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Severe allergic reactions
*/
define "CI Severe allergic reactions Condition":
  Elements."CI Severe allergic reactions Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is severely immunocompromised
@pseudocode: "Potential contraindications" = "Severely immunocompromised"
*/
define "The client is severely immunocompromised":
  exists "CI Severely immunocompromised Observation"
    or exists "CI Severely immunocompromised Condition"
    
/*
@internal: Observation for Severely immunocompromised
*/
define "CI Severely immunocompromised Observation":
  Elements."CI Severely immunocompromised Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Severely immunocompromised
*/
define "CI Severely immunocompromised Condition":
  Elements."CI Severely immunocompromised Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is severely immunosuppressed
@pseudocode: "Potential contraindications" = "Severely immunosuppressed"
*/
define "The client is severely immunosuppressed":
  exists "CI Severely immunosuppressed Observation"
    or exists "CI Severely immunosuppressed Condition"
    
/*
@internal: Observation for Severely immunosuppressed
*/
define "CI Severely immunosuppressed Observation":
  Elements."CI Severely immunosuppressed Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Severely immunosuppressed
*/
define "CI Severely immunosuppressed Condition":
  Elements."CI Severely immunosuppressed Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has a symptomatic HIV infection
@pseudocode: "Potential contraindications" = "Symptomatic HIV infection"
*/
define "The client has a symptomatic HIV infection":
  exists "CI Symptomatic HIV infection Observation"
    or exists "CI Symptomatic HIV infection Condition"
    
/*
@internal: Observation for Symptomatic HIV infection
*/
define "CI Symptomatic HIV infection Observation":
  Elements."CI Symptomatic HIV infection Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Symptomatic HIV infection
*/
define "CI Symptomatic HIV infection Condition":
  Elements."CI Symptomatic HIV infection Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has immunodeficiency syndromes
@pseudocode: "Potential contraindications" = "Immunodeficiency syndromes"
*/
define "The client has immunodeficiency syndromes":
  exists "CI Immunodeficiency syndromes Observation"
    or exists "CI Immunodeficiency syndromes Condition"
    
/*
@internal: Observation for Immunodeficiency syndromes
*/
define "CI Immunodeficiency syndromes Observation":
  Elements."CI Immunodeficiency syndromes Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Immunodeficiency syndromes
*/
define "CI Immunodeficiency syndromes Condition":
  Elements."CI Immunodeficiency syndromes Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is exposed to immunosuppressive treatment
@pseudocode: "Potential contraindications" = "Exposed to immunosuppressive treatment"
*/
define "The client is exposed to immunosuppressive treatment":
  exists "CI Exposed to immunosuppressive treatment Observation"
    or exists "CI Exposed to immunosuppressive treatment Condition"
    
/*
@internal: Observation for Exposed to immunosuppressive treatment
*/
define "CI Exposed to immunosuppressive treatment Observation":
  Elements."CI Exposed to immunosuppressive treatment Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Exposed to immunosuppressive treatment
*/
define "CI Exposed to immunosuppressive treatment Condition":
  Elements."CI Exposed to immunosuppressive treatment Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client currently has a severe acute illness
@pseudocode: "Potential contraindications" = "Severe acute illness"
*/
define "The client currently has a severe acute illness":
  exists "CI Severe acute illness Observation"
    or exists "CI Severe acute illness Condition"
    
/*
@internal: Observation for Severe acute illness
*/
define "CI Severe acute illness Observation":
  Elements."CI Severe acute illness Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Severe acute illness
*/
define "CI Severe acute illness Condition":
  Elements."CI Severe acute illness Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has prior history of intussusception
@pseudocode: "Potential contraindications" = "Prior history of intussusception"
*/
define "The client has prior history of intussusception":
  exists "CI Prior history of intussusception Observation"
    or exists "CI Prior history of intussusception Condition"
    
/*
@internal: Observation for Prior history of intussusception
*/
define "CI Prior history of intussusception Observation":
  Elements."CI Prior history of intussusception Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Prior history of intussusception
*/
define "CI Prior history of intussusception Condition":
  Elements."CI Prior history of intussusception Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has altered immunocompetence
@pseudocode: "Potential contraindications" = "Altered immunocompetence"
*/
define "The client has altered immunocompetence":
  exists "CI Altered immunocompetence Observation"
    or exists "CI Altered immunocompetence Condition"
    
/*
@internal: Observation for Altered immunocompetence
*/
define "CI Altered immunocompetence Observation":
  Elements."CI Altered immunocompetence Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Altered immunocompetence
*/
define "CI Altered immunocompetence Condition":
  Elements."CI Altered immunocompetence Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has spina bifida
@pseudocode: "Potential contraindications" = "Spina bifida"
*/
define "The client has spina bifida":
  exists "CI Spina bifida Observation"
    or exists "CI Spina bifida Condition"
    
/*
@internal: Observation for Spina bifida
*/
define "CI Spina bifida Observation":
  Elements."CI Spina bifida Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Spina bifida
*/
define "CI Spina bifida Condition":
  Elements."CI Spina bifida Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has bladder exstrophy
@pseudocode: "Potential contraindications" = "Bladder exstrophy"
*/
define "The client has bladder exstrophy":
  exists "CI Bladder exstrophy Observation"
    or exists "CI Bladder exstrophy Condition"
    
/*
@internal: Observation for Bladder exstrophy
*/
define "CI Bladder exstrophy Observation":
  Elements."CI Bladder exstrophy Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Bladder exstrophy
*/
define "CI Bladder exstrophy Condition":
  Elements."CI Bladder exstrophy Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is immunocompromised
@pseudocode: "Potential contraindications" = "Immunocompromised"
*/
define "The client is immunocompromised":
  "Client is immunocompromised"
    or exists "CI Immunocompromised Observation"
    or exists "CI Immunocompromised Condition"

/*
@internal: Observation for Immunocompromised
*/
define "CI Immunocompromised Observation":
  Elements."CI Immunocompromised Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Immunocompromised
*/
define "CI Immunocompromised Condition":
  Elements."CI Immunocompromised Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is planning to get pregnant in next month
@pseudocode: "Potential contraindications" = "Planning to get pregnant in the next month"
*/
define "The client is planning to get pregnant in next month":
  exists "CI Planning to get pregnant in the next month Observation"
    or exists "CI Planning to get pregnant in the next month Condition"

/*
@internal: Observation for Planning to get pregnant in the next month
*/
define "CI Planning to get pregnant in the next month Observation":
  Elements."CI Planning to get pregnant in the next month Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Planning to get pregnant in the next month
*/
define "CI Planning to get pregnant in the next month Condition":
  Elements."CI Planning to get pregnant in the next month Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is receiving blood products
@pseudocode: "Potential contraindications" = "Receiving blood products"
*/
define "The client is receiving blood products":
  exists "CI Receiving blood products Observation"
    or exists "CI Receiving blood products Condition"

/*
@internal: Observation for Receiving blood products
*/
define "CI Receiving blood products Observation":
  Elements."CI Receiving blood products Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Receiving blood products
*/
define "CI Receiving blood products Condition":
  Elements."CI Receiving blood products Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has TB disease
@pseudocode: "Potential contraindications" = "TB disease"
*/
define "The client has TB disease":
  exists "CI TB disease Observation"
    or exists "CI TB disease Condition"

/*
@internal: Observation for TB disease
*/
define "CI TB disease Observation":
  Elements."CI TB disease Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for TB disease
*/
define "CI TB disease Condition":
  Elements."CI TB disease Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is lactating
@pseudocode: "Potential contraindications" = "Breastfeeding"
*/
define "The client is lactating":
  exists "CI Breastfeeding Observation"
    or exists "CI Breastfeeding Condition"

/*
@internal: Observation for Breastfeeding
*/
define "CI Breastfeeding Observation":
  Elements."CI Breastfeeding Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Breastfeeding
*/
define "CI Breastfeeding Condition":
  Elements."CI Breastfeeding Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has acute gastroenteritis
@pseudocode: "Potential contraindications" = "Acute gastroenteritis"
*/
define "The client has acute gastroenteritis":
  exists "CI Acute gastroenteritis Observation"
    or exists "CI Acute gastroenteritis Condition"

/*
@internal: Observation for Acute gastroenteritis
*/
define "CI Acute gastroenteritis Observation":
  Elements."CI Acute gastroenteritis Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Acute gastroenteritis
*/
define "CI Acute gastroenteritis Condition":
  Elements."CI Acute gastroenteritis Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has moderate to severe fever
@pseudocode: "Potential contraindications" = "Moderate to severe fever"
*/
define "The client has moderate to severe fever":
  exists "CI Moderate to severe fever Observation"
    or exists "CI Moderate to severe fever Condition"

/*
@internal: Observation for Moderate to severe fever
*/
define "CI Moderate to severe fever Observation":
  Elements."CI Moderate to severe fever Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Moderate to severe fever
*/
define "CI Moderate to severe fever Condition":
  Elements."CI Moderate to severe fever Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has hypersensitivity to any component of the vaccine
@pseudocode: "Potential contraindications" = "Hypersensitivity to vaccine components"
*/
define "The client has hypersensitivity to any component of the vaccine":
  exists "CI Hypersensitivity to vaccine components Observation"
    or exists "CI Hypersensitivity to vaccine components Condition"

/*
@internal: Observation for Hypersensitivity to vaccine components
*/
define "CI Hypersensitivity to vaccine components Observation":
  Elements."CI Hypersensitivity to vaccine components Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Hypersensitivity to vaccine components
*/
define "CI Hypersensitivity to vaccine components Condition":
  Elements."CI Hypersensitivity to vaccine components Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client is currently taking antibiotics
@pseudocode: "Potential contraindications" = "Taking antibiotics"
*/
define "The client is currently taking antibiotics":
  exists "CI Taking antibiotics Observation"
    or exists "CI Taking antibiotics Condition"

/*
@internal: Observation for Taking antibiotics
*/
define "CI Taking antibiotics Observation":
  Elements."CI Taking antibiotics Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Taking antibiotics
*/
define "CI Taking antibiotics Condition":
  Elements."CI Taking antibiotics Condition" C
    where C.prevalenceInterval() includes Today

/*
@input: The client has chronic gastrointestinal disease
@pseudocode: "Potential contraindications" = "Chronic gastrointestinal disease"
*/
define "The client has chronic gastrointestinal disease":
  exists "CI Chronic gastrointestinal disease Observation"
    or exists "CI Chronic gastrointestinal disease Condition"

/*
@internal: Observation for Chronic gastrointestinal disease
*/
define "CI Chronic gastrointestinal disease Observation":
  Elements."CI Chronic gastrointestinal disease Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Condition for Chronic gastrointestinal disease
*/
define "CI Chronic gastrointestinal disease Condition":
  Elements."CI Chronic gastrointestinal disease Condition" C
    where C.prevalenceInterval() includes Today



/*
@input: Client's HIV status is negative or unknown
@pseudocode: "HIV status" ≠ "HIV-positive"
*/
define "Client's HIV status is negative or unknown":
  not "Client's HIV status is positive"

/*
@input: Client's HIV status is positive
@pseudocode: "HIV status" = "HIV-positive"
*/
define "Client's HIV status is positive":
  exists( (Elements."HIV status Observation".encounterOrOnBefore(EncounterId, Today)) O
    where O.value ~ Concepts."HIV-positive" )

/*
@input: Client is currently receiving antiretroviral therapy
@pseudocode: "Currently on ART" = TRUE
*/
define "Client is currently receiving antiretroviral therapy":
  Elements."Currently on ART Observation".encounterOrOnBefore(EncounterId, Today).mostRecent().value = true

/*
@input: Client is currently not receiving antiretroviral therapy
@pseudocode: "Currently on ART" = FALSE
*/
define "Client is currently not receiving antiretroviral therapy":
  not "Client is currently receiving antiretroviral therapy"

/*
@internal: Immunologically stable Observation
*/
define "Immunologically stable Observation":
  Elements."Immunologically stable Observation".encounterOrOnBefore(EncounterId, Today)

/*
@input: Client is immunologically stable
@pseudocode: "Immunologically stable" = TRUE
*/
define "Client is immunologically stable":
  First("Immunologically stable Observation").value = true

/*
@input: Client is not immunologically stable
@pseudocode: "Immunologically stable" = FALSE
*/
define "Client is not immunologically stable":
  First("Immunologically stable Observation").value = false

/*
@internal: Immunologically stable Observation
*/
define "TB infection test result Observation":
  Elements."TB infection test result Observation".encounterOrOnBefore(EncounterId, Today)

/*
@input: Client's TB infection test result is negative
@pseudocode: "TB infection test result" = "Negative"
*/
define "Client's TB infection test result is negative":
  First( "TB infection test result Observation" ).value ~ Concepts."TB-Negative"
/*
@input: Client's TB infection test result is unknown (test not done or no result yet)
@pseudocode: "TB infection test result" IS NULL
*/
define "Client's TB infection test result is unknown (test not done or no result yet)":
  not exists( "TB infection test result Observation" ) or (
    not ("Client's TB infection test result is negative") and not ("Client's TB infection test result is positive")
  )
/*
@input: Client's TB infection test result is positive
@pseudocode: "TB infection test result" = "Positive"
*/
define "Client's TB infection test result is positive":
  First( "TB infection test result Observation" ).value ~ Concepts."TB-Positive"

/*
@internal: Clinically well Observation
*/
define "Clinically well Observation":
  Elements."Clinically well Observation".encounterOrOnBefore(EncounterId, Today)

/*
@input: Client is not clinically well
@pseudocode: "Clinically well" = FALSE
*/
define "Client is not clinically well":
  First( "Clinically well Observation" ).value = false

/*
@input: Client is clinically well
@pseudocode: "Clinically well" = TRUE
*/
define "Client is clinically well":
  First( "Clinically well Observation" ).value = true 

/*
@internal: Immunocompromised Observation
*/
define "Immunocompromised Observation":
  ([Observation: Concepts."Immunocompromised"] O
    sort by end of effective.toInterval() desc).complete()

/*
@input: Client is immunocompromised
@pseudocode: "Immunocompromised" = TRUE
*/
define "Client is immunocompromised":
  exists( "Immunocompromised Observation" ) and
  First( "Immunocompromised Observation" ).value = true 

/*
@input: Client is not immunocompromised
@pseudocode: "Immunocompromised" ≠ TRUE
*/
define "Client is not immunocompromised":
  not "Client is immunocompromised"

/*
@internal: Birth weight in grams Observation
*/
define "Birth weight in grams Observation":
  Elements."Birth weight in grams Observation".encounterOrOnBefore(EncounterId, Today)

define "Birth weight in grams Value":
  First("Birth weight in grams Observation").value as FHIR.Quantity

define "Birth weight in grams":
  "Birth weight in grams Value".value as FHIR.decimal

/*
@input: Client's weight at birth was over 2000 g
@pseudocode: "Birth weight in grams"  ≥ 2000
*/
define "Client's weight at birth was over 2000 g":
  "Birth weight in grams" >= 2000

/*
@input: Client's weight at birth was below 2000 g
@pseudocode: "Birth weight in grams" < 2000
*/
define "Client's weight at birth was below 2000 g":
  "Birth weight in grams" < 2000

/*
@internal: Preterm birth Observation
*/
define "Preterm birth Observation":
  Elements."Preterm birth Observation".encounterOrOnBefore(EncounterId, Today)

/*
@input: Client was not a premature infant at birth
@pseudocode: "Preterm birth" ≠  TRUE
*/
define "Client was not a premature infant at birth":
  not("Client was a premature infant at birth")

/*
@input: Client was a premature infant at birth
@pseudocode: "Preterm birth" =  TRUE
*/
define "Client was a premature infant at birth":
  exists( "Preterm birth Observation" O where O.value = true )

/*
@internal: Completed the primary vaccination series Observation
*/
define "Completed the primary vaccination series Observation":
  Elements."Completed the primary vaccination series Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: At high risk for pneumococcal infection Observation
*/
define "At high risk for pneumococcal infection Observation":
  Elements."At high risk for pneumococcal infection Observation".encounterOrOnBefore(EncounterId, Today)

/*
@input: Client is at high risk for pneumococcal infection
@pseudocode: "At high risk for pneumococcal infection" = TRUE
*/
define "Client is at high risk for pneumococcal infection":
  exists( "At high risk for pneumococcal infection Observation" O where O.value = true )

/*
@input: Client is not at high risk for pneumococcal infection
@pseudocode: "At high risk for pneumococcal infection" = FALSE
*/
define "Client is not at high risk for pneumococcal infection":
  exists( "At high risk for pneumococcal infection Observation" O where O.value = false )

/*
@internal: Date when primary vaccination series was completed Observation
*/
define "Date when primary vaccination series was completed Observation":
  Elements."Date when primary vaccination series was completed Observation".encounterOrOnBefore(EncounterId, Today)

/*
@internal: Completed the booster series Observation
*/
define "Completed the booster series Observation":
  Elements."Completed the booster series Observation".encounterOrOnBefore(EncounterId, Today)
Content: application/elm+xml
Encoded data (358460 characters)