WHO SMART Guidelines - HIV
0.3.0 - ci-build

WHO SMART Guidelines - HIV - Local Development build (v0.3.0) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

Library: HIVIndicatorElements (Experimental)

Official URL: http://smart.who.int/hiv/Library/HIVIndicatorElements Version: 0.3.0
Draft as of 2024-08-18 Computable Name: HIVIndicatorElements

Description not yet available for HIVIndicatorElements.

Generated Narrative: Library HIVIndicatorElements

Related Artifacts

Depends OnLibrary WHOConceptsWHOConcepts
Depends OnLibrary WCWHOCommon
Depends OnLibrary WEWHOElements
Depends OnLibrary ConceptsHIVConcepts
Depends OnLibrary ConceptsCustomHIVConceptsCustom
Depends OnLibrary ElementsHIVElements
Depends OnLibrary CommonHIVCommon
Depends OnLibrary ConfigHIVConfig

Parameters

Measurement Periodin01Period
Patientout01Patient
Community_testingout01boolean
Facility_testingout01boolean
ANC_caseout01boolean
methadone_prescribed at dateout0*MedicationRequest
OAMT_initiatedout01boolean
OAMT_retainedout01boolean
PEP Prescribed before start of Measurement Period and Completedout0*MedicationStatement
PEP Prescribed during Measurement Period and Completedout0*MedicationStatement
HIV Test Positive After PEP Prescribed during Measurement Periodout0*Observation
Patient Deceased during Measurement Periodout01boolean
Viral load test result D.DE387out0*Observation
Elevated Viral load test during Measurement Periodout0*Observation
Negative Tests within Measurement Periodout0*Observation
First Negative Test within Measurement Periodout01Observation
Negative Tests after First Negative Testout0*Observation
Lost to Follow Up during the measurement periodout01boolean
ART Medication Statementout0*MedicationStatement
On ARTout01boolean
ART Start Dateout0*dateTime
ART Duration in Monthsout0*integer
By ART initiationout01string
By Geographic Region Stratifierout01string
hiv_exposure_typeout0*string
settingout0*string
ancout0*string
TB_diagnosedout01boolean
TB_presumptiveout01boolean
tbout0*string
prep_productout0*string
prep_experienceout0*string
prep_dosingout0*string
Lost to follow-upout0*MedicationStatement
Is lost to follow-upout01boolean
Has transferred outout01boolean
Has death documentedout01boolean
Refused stopped treatmentout01boolean
On ART H.DE47out01boolean
Treatment outcome categoryout0*string
Already knew positiveout01boolean
Newly diagnosedout01boolean
Negative H.DE37out01boolean
HIV status of partner or contactout01Coding
Visit date A.DE3out0*Observation
Visit date A.DE3 Valueout0*Resource
Age In Yearsout01integer
Age In Monthsout01integer
Age In Daysout01integer
By Age Stratifierout01string
By Age Stratifier 2out01string
By Age Stratifier 3out01string
By Administrative Gender Stratifierout01Coding
Referred through partner services Observationout0*Observation
Referred through partner servicesout01boolean
Partner or contact of an HIV testing client non-index case Conditionout0*Condition
Partner or contact of an HIV testing client non-index case Observationout0*Observation
Partner or contact of an HIV testing client non-index caseout01boolean
Type of contact or partner for partner services Observationout0*Observation
Type of contact or partner for partner servicesout01boolean
Biological child Conditionout0*Condition
Biological child Observationout0*Observation
Biological childout01boolean
Drug-injecting partner B.DE10 Conditionout0*Condition
Drug-injecting partner B.DE10 Observationout0*Observation
Drug-injecting partner B.DE10out01boolean
Sexual partner B.DE11 Conditionout0*Condition
Sexual partner B.DE11 Observationout0*Observation
Sexual partner B.DE11out01boolean
Social contact B.DE12 Conditionout0*Condition
Social contact B.DE12 Observationout0*Observation
Social contact B.DE12out01boolean
Testing entry point Observationout0*Observation
Testing entry pointout01boolean
Community-level testing Conditionout0*Condition
Community-level testing Observationout0*Observation
Community-level testingout01boolean
Facility-level testing Conditionout0*Condition
Facility-level testing Observationout0*Observation
Facility-level testingout01boolean
Currently pregnant B.DE29 Observationout0*Observation
Currently pregnant B.DE29out01boolean
Breastfeeding B.DE32 Observationout0*Observation
Breastfeeding B.DE32out01boolean
Partner HIV status reported Observationout0*Observation
Partner HIV status reportedout01boolean
HIV-positive B.DE34 Conditionout0*Condition
HIV-positive B.DE34 Observationout0*Observation
HIV-positive B.DE34out01boolean
HIV-negative B.DE35 Conditionout0*Condition
HIV-negative B.DE35 Observationout0*Observation
HIV-negative B.DE35out01boolean
Unknown B.DE36 Conditionout0*Condition
Unknown B.DE36 Observationout0*Observation
Unknown B.DE36out01boolean
Key population member type Observationout0*Observation
Is Key population memberout01boolean
patientGroupsout0*string
Sex workerout01boolean
Men who have sex with menout01boolean
Trans and gender-diverse peopleout01boolean
People who inject drugsout0*Observation
People living in prisons and other closed settingsout01boolean
HIV test results returned in measurement periodout0*Observation
Has HIV test results returned in measurement periodout01boolean
HIV exposure type Observationout0*Observation
HIV exposure typeout01boolean
Occupational Conditionout0*Condition
Occupational Observationout0*Observation
Occupationalout01boolean
Non-occupational violent Conditionout0*Condition
Non-occupational violent Observationout0*Observation
Non-occupational violentout01boolean
Non-occupational consensual sex Conditionout0*Condition
Non-occupational consensual sex Observationout0*Observation
Non-occupational consensual sexout01boolean
Date informed of HIV-positive diagnosisout0*Observation
Date informed of HIV-positive diagnosis Valueout0*Resource
HIV diagnosis dateout0*Observation
HIV diagnosis date Valueout0*Resource
ART start date B.DE72out0*Observation
ART start date B.DE72 Valueout0*Resource
HIV test type B.DE81out0*Observation
HIV test type B.DE81 Valueout0*Resource
Non-Self HIV test with date and results returned in measurement periodout0*Observation
Non-Self HIV test date and results returned within measurement period for HIV-positive resultout0*Observation
Negative HIV test within measurement periodout0*Observation
HIV Status Positive Conditionout0*Condition
HIV Status Positive Observationout0*Observation
Has HIV-positive Statusout01boolean
HIV Status Negative Observationout0*Observation
HIV Status Stratifierout01Coding
HIV Status positive at last measurement period Conditionout0*Condition
HIV Status positive at last measurement period Observationout0*Observation
Has HIV-positive Status at last measurment periodout01boolean
HIV Status Negative Conditionout0*Condition
Probable route of transmission Observationout0*Observation
Probable route of transmissionout01boolean
Heterosexual sex Conditionout0*Condition
Heterosexual sex Observationout0*Observation
Heterosexual sexout01boolean
Sex between men Conditionout0*Condition
Sex between men Observationout0*Observation
Sex between menout01boolean
Unprotected intercourse during sex work Conditionout0*Condition
Unprotected intercourse during sex work Observationout0*Observation
Unprotected intercourse during sex workout01boolean
Injecting drug use with unsterile equipment Conditionout0*Condition
Injecting drug use with unsterile equipment Observationout0*Observation
Injecting drug use with unsterile equipmentout01boolean
Nosocomial Conditionout0*Condition
Nosocomial Observationout0*Observation
Nosocomialout01boolean
Vertical Conditionout0*Condition
Vertical Observationout0*Observation
Verticalout01boolean
Other B.DE128 Conditionout0*Condition
Other B.DE128 Observationout0*Observation
Other B.DE128out01boolean
VMMC procedure dateout0*Observation
VMMC procedure date Valueout0*Resource
VMMC_adverse_eventout0*AdverseEvent
VMMC_adverse_event_typeout01Coding
VMMC_adverse_event_Intraoperativeout0*AdverseEvent
VMMC_adverse_event_Postoperativeout0*AdverseEvent
VMMC_adverse_event_timingout01Coding
Adverse event severity Observationout0*Observation
Adverse event severityout01boolean
Moderate Conditionout0*Condition
Moderate Observationout0*Observation
Moderateout01boolean
Severe Conditionout0*Condition
Severe Observationout0*Observation
Severeout01boolean
Timing of adverse event Observationout0*Observation
Timing of adverse eventout01boolean
Intraoperative Conditionout0*Condition
Intraoperative Observationout0*Observation
Intraoperativeout01boolean
Postoperative Conditionout0*Condition
Postoperative Observationout0*Observation
Postoperativeout01boolean
Type of adverse VMMC event Observationout0*Observation
Type of adverse VMMC eventout01boolean
Abnormal pain Conditionout0*Condition
Abnormal pain Observationout0*Observation
Abnormal painout01boolean
Anaesthesia-related effects Conditionout0*Condition
Anaesthesia-related effects Observationout0*Observation
Anaesthesia-related effectsout01boolean
Bleeding Conditionout0*Condition
Bleeding Observationout0*Observation
Bleedingout01boolean
Damage to the penis Conditionout0*Condition
Damage to the penis Observationout0*Observation
Damage to the penisout01boolean
Difficulty urinating Conditionout0*Condition
Difficulty urinating Observationout0*Observation
Difficulty urinatingout01boolean
Excessive bleeding Conditionout0*Condition
Excessive bleeding Observationout0*Observation
Excessive bleedingout01boolean
Excessive skin removal Conditionout0*Condition
Excessive skin removal Observationout0*Observation
Excessive skin removalout01boolean
Excessive swelling Conditionout0*Condition
Excessive swelling Observationout0*Observation
Excessive swellingout01boolean
Haematoma Conditionout0*Condition
Haematoma Observationout0*Observation
Haematomaout01boolean
Infection Conditionout0*Condition
Infection Observationout0*Observation
Infectionout01boolean
Injury to glans Conditionout0*Condition
Injury to glans Observationout0*Observation
Injury to glansout01boolean
Scar or disfigurement Conditionout0*Condition
Scar or disfigurement Observationout0*Observation
Scar or disfigurementout01boolean
Sharps injury to personnel Conditionout0*Condition
Sharps injury to personnel Observationout0*Observation
Sharps injury to personnelout01boolean
Wound disruption Conditionout0*Condition
Wound disruption Observationout0*Observation
Wound disruptionout01boolean
Other B.DE222 Conditionout0*Condition
Other B.DE222 Observationout0*Observation
Other B.DE222out01boolean
At elevated risk for HIV acquisition B.DE225out01boolean
Syndrome/STI diagnosed B.DE226 Observationout0*Observation
Syndrome/STI diagnosed B.DE226out01boolean
Urethral discharge syndrome B.DE227 Conditionout0*Condition
Urethral discharge syndrome B.DE227 Observationout0*Observation
Urethral discharge syndrome B.DE227out01boolean
Vaginal discharge syndrome B.DE228 Conditionout0*Condition
Vaginal discharge syndrome B.DE228 Observationout0*Observation
Vaginal discharge syndrome B.DE228out01boolean
Lower Abdominal pain B.DE229 Conditionout0*Condition
Lower Abdominal pain B.DE229 Observationout0*Observation
Lower Abdominal pain B.DE229out01boolean
Genital ulcer disease syndrome B.DE230 Conditionout0*Condition
Genital ulcer disease syndrome B.DE230 Observationout0*Observation
Genital ulcer disease syndrome B.DE230out01boolean
Anorectal discharge B.DE231 Conditionout0*Condition
Anorectal discharge B.DE231 Observationout0*Observation
Anorectal discharge B.DE231out01boolean
Sent for testing B.DE232 Conditionout0*Condition
Sent for testing B.DE232 Observationout0*Observation
Sent for testing B.DE232out01boolean
Other B.DE233 Conditionout0*Condition
Other B.DE233 Observationout0*Observation
Other B.DE233out01boolean
Any STI syndrome diagnosed B.DE235 Observationout0*Observation
Any STI syndrome diagnosed B.DE235out01boolean
Syphilis test date B.DE249out01boolean
Syphilis test result B.DE250out01boolean
Positive B.DE251out01boolean
Negative B.DE252out01boolean
Inconclusive B.DE253out01boolean
Syphilis treatment start date B.DE254out0*Observation
Syphilis treatment start date B.DE254 Valueout0*Resource
Gonorrhoea test date B.DE255out0*Observation
Gonorrhoea test date B.DE255 Valueout0*Resource
Gonorrhoea test result B.DE256 Observationout0*Observation
Gonorrhoea test result B.DE256out01boolean
Positive B.DE257 Conditionout0*Condition
Positive B.DE257 Observationout0*Observation
Positive B.DE257out01boolean
Negative B.DE258 Conditionout0*Condition
Negative B.DE258 Observationout0*Observation
Negative B.DE258out01boolean
Inconclusive B.DE259 Conditionout0*Condition
Inconclusive B.DE259 Observationout0*Observation
Inconclusive B.DE259out01boolean
Gonorrhoea treatment start date B.DE260out0*Observation
Gonorrhoea treatment start date B.DE260 Valueout0*Resource
Type of specimen B.DE261 Observationout0*Observation
Type of specimen B.DE261out01boolean
Blood B.DE262 Conditionout0*Condition
Blood B.DE262 Observationout0*Observation
Blood B.DE262out01boolean
Urine B.DE263 Conditionout0*Condition
Urine B.DE263 Observationout0*Observation
Urine B.DE263out01boolean
Cervical or vaginal swab B.DE264 Conditionout0*Condition
Cervical or vaginal swab B.DE264 Observationout0*Observation
Cervical or vaginal swab B.DE264out01boolean
Urethral or penile swab B.DE265 Conditionout0*Condition
Urethral or penile swab B.DE265 Observationout0*Observation
Urethral or penile swab B.DE265out01boolean
Rectal swab B.DE266 Conditionout0*Condition
Rectal swab B.DE266 Observationout0*Observation
Rectal swab B.DE266out01boolean
Other B.DE267 Conditionout0*Condition
Other B.DE267 Observationout0*Observation
Other B.DE267out01boolean
Neisseria gonorrhoeae test type B.DE276 Observationout0*Observation
Neisseria gonorrhoeae test type B.DE276out01boolean
NAAT B.DE277 Conditionout0*Condition
NAAT B.DE277 Observationout0*Observation
NAAT B.DE277out01boolean
POC Test B.DE278 Conditionout0*Condition
POC Test B.DE278 Observationout0*Observation
POC Test B.DE278out01boolean
Culture B.DE279 Conditionout0*Condition
Culture B.DE279 Observationout0*Observation
Culture B.DE279out01boolean
Microscopy B.DE280 Conditionout0*Condition
Microscopy B.DE280 Observationout0*Observation
Microscopy B.DE280out01boolean
Other B.DE281 Conditionout0*Condition
Other B.DE281 Observationout0*Observation
Other B.DE281out01boolean
PrEP dosing type Observationout0*Observation
PrEP dosing typeout01boolean
Daily oral PrEP Conditionout0*Condition
Daily oral PrEP Observationout0*Observation
Daily oral PrEPout01boolean
Event-driven PrEP 2+1+1 Conditionout0*Condition
Event-driven PrEP 2+1+1 Observationout0*Observation
Event-driven PrEP 2+1+1out01boolean
Other PrEP dosing type Conditionout0*Condition
Other PrEP dosing type Observationout0*Observation
Other PrEP dosing typeout01boolean
Experience with PrEP Observationout0*Observation
Experience with PrEPout01boolean
First-time user C.DE25 Conditionout0*Condition
First-time user C.DE25 Observationout0*Observation
First-time user C.DE25out01boolean
Continuing user Conditionout0*Condition
Continuing user Observationout0*Observation
Continuing userout01boolean
Restarting following a period of not taking PrEP Conditionout0*Condition
Restarting following a period of not taking PrEP Observationout0*Observation
Restarting following a period of not taking PrEPout01boolean
Date client completes PEP courseout0*Observation
Date client completes PEP course Valueout0*Resource
Date medications prescribed C.DE74out0*Observation
Date medications prescribed C.DE74 Valueout0*Resource
Medications prescribed C.DE75 Observationout0*Observation
Medications prescribed C.DE75out01boolean
HIV PREP Activeout01boolean
PrEP for HIV prevention Conditionout0*Condition
PrEP for HIV prevention Observationout0*Observation
PrEP for HIV preventionout01boolean
PEP for HIV prevention Conditionout0*Condition
PEP for HIV prevention Observationout0*Observation
PEP for HIV preventionout01boolean
Other C.DE78 Conditionout0*Condition
Other C.DE78 Observationout0*Observation
Other C.DE78out01boolean
PrEP product prescribed Observationout0*Observation
PrEP product prescribedout01boolean
Oral PrEP Conditionout0*Condition
Oral PrEP Observationout0*Observation
Oral PrEPout01boolean
Dapivirine vaginal ring DVR C.DE82 Conditionout0*Condition
Dapivirine vaginal ring DVR C.DE82 Observationout0*Observation
Dapivirine vaginal ring DVR C.DE82out01boolean
CAB-LA C.DE83 Conditionout0*Condition
CAB-LA C.DE83 Observationout0*Observation
CAB-LA C.DE83out01boolean
Other C.DE84 Conditionout0*Condition
Other C.DE84 Observationout0*Observation
Other C.DE84out01boolean
Number of days prescribed C.DE121out0*Observation
Number of days prescribed C.DE121 Valueout0*Resource
Condom type Observationout0*Observation
Condom typeout01boolean
Male condom Conditionout0*Condition
Male condom Observationout0*Observation
Male condomout01boolean
Female condom Conditionout0*Condition
Female condom Observationout0*Observation
Female condomout01boolean
Number of HIV self-test kits distributedout0*Observation
Number of HIV self-test kits distributed Valueout0*Resource
HIV self-test distributed for use by Observationout0*Observation
HIV self-test distributed for use byout01boolean
Self Conditionout0*Condition
Self Observationout0*Observation
Selfout01boolean
Family member Conditionout0*Condition
Family member Observationout0*Observation
Family memberout01boolean
Drug-injecting partner C.DE146 Conditionout0*Condition
Drug-injecting partner C.DE146 Observationout0*Observation
Drug-injecting partner C.DE146out01boolean
Sexual partner C.DE147 Conditionout0*Condition
Sexual partner C.DE147 Observationout0*Observation
Sexual partner C.DE147out01boolean
Social contact C.DE148 Conditionout0*Condition
Social contact C.DE148 Observationout0*Observation
Social contact C.DE148out01boolean
Currently pregnant D.DE31 Observationout0*Observation
Currently pregnant D.DE31out01boolean
Breastfeeding D.DE32 Observationout0*Observation
Breastfeeding D.DE32out01boolean
On ART D.DE38out01boolean
ART start date within measurement periodout0*dateTime
ART stopped during measurement periodout0*dateTime
ART start typeout01boolean
First-time user of ARTout01boolean
Restarting ARTout01boolean
Current ART regimen Observationout0*Observation
Current ART regimenout01boolean
HBsAg test date D.DE161out0*Observation
HBsAg test date D.DE161 Valueout0*Resource
HBsAg test result D.DE162 Observationout0*Observation
HBsAg test result D.DE162out01boolean
Positive D.DE163 Conditionout0*Condition
Positive D.DE163 Observationout0*Observation
Positive D.DE163out01boolean
Negative D.DE164 Conditionout0*Condition
Negative D.DE164 Observationout0*Observation
Negative D.DE164out01boolean
Indeterminate D.DE165 Conditionout0*Condition
Indeterminate D.DE165 Observationout0*Observation
Indeterminate D.DE165out01boolean
HBV treatment TDF start dateout0*Observation
HBV treatment TDF start date Valueout0*Resource
HCV test date D.DE169out0*Observation
HCV test date D.DE169 Valueout0*Resource
HCV test result D.DE170 Observationout0*Observation
HCV test result D.DE170out01boolean
Positive D.DE171 Conditionout0*Condition
Positive D.DE171 Observationout0*Observation
Positive D.DE171out01boolean
Negative D.DE172 Conditionout0*Condition
Negative D.DE172 Observationout0*Observation
Negative D.DE172out01boolean
Indeterminate D.DE173 Conditionout0*Condition
Indeterminate D.DE173 Observationout0*Observation
Indeterminate D.DE173out01boolean
HCV treatment start dateout0*Observation
HCV treatment start date Valueout0*Resource
HCV treatment completion dateout0*Observation
HCV treatment completion date Valueout0*Resource
HCV viral load test date D.DE178out0*Observation
HCV viral load test date D.DE178 Valueout0*Resource
HCV viral load test result D.DE179 Observationout0*Observation
HCV viral load test result D.DE179out01boolean
Detected D.DE180 Conditionout0*Condition
Detected D.DE180 Observationout0*Observation
Detected D.DE180out01boolean
Not detected D.DE181 Conditionout0*Condition
Not detected D.DE181 Observationout0*Observation
Not detected D.DE181out01boolean
HCV medicine type Observationout0*Observation
HCV medicine typeout01boolean
Interferon Conditionout0*Condition
Interferon Observationout0*Observation
Interferonout01boolean
Direct acting antivirals Conditionout0*Condition
Direct acting antivirals Observationout0*Observation
Direct acting antiviralsout01boolean
Currently on TDF-based ART Observationout0*Observation
Currently on TDF-based ARTout01boolean
Date viral load test results received by client D.DE193out0*Observation
Date of viral load sample collection D.DE194out01boolean
Reason ART stopped D.DE217 Observationout0*Observation
Reason ART stopped D.DE217out01boolean
Toxicity/side effects D.DE218 Conditionout0*Condition
Toxicity/side effects D.DE218 Observationout0*Observation
Toxicity/side effects D.DE218out01boolean
Severe illness, hospitalization D.DE219 Conditionout0*Condition
Severe illness, hospitalization D.DE219 Observationout0*Observation
Severe illness, hospitalization D.DE219out01boolean
Drugs out of stock Conditionout0*Condition
Drugs out of stock Observationout0*Observation
Drugs out of stockout01boolean
Client lacks finances Conditionout0*Condition
Client lacks finances Observationout0*Observation
Client lacks financesout01boolean
Excluded HIV infection in infant D.DE222 Conditionout0*Condition
Excluded HIV infection in infant D.DE222 Observationout0*Observation
Excluded HIV infection in infant D.DE222out01boolean
Other reason for stopping ART D.DE223 Conditionout0*Condition
Other reason for stopping ART D.DE223 Observationout0*Observation
Other reason for stopping ART D.DE223out01boolean
Risk factors, comorbidities and coinfections signs and symptoms Observationout0*Observation
Risk factors, comorbidities and coinfections signs and symptomsout01boolean
Presumptive TB D.DE282 Conditionout0*Condition
Presumptive TB D.DE282 Observationout0*Observation
Presumptive TB D.DE282out01boolean
Baseline CD4 count D.DE367out0*Observation
Baseline CD4 count D.DE367 Valueout0*Resource
Date of baseline CD4 count test D.DE368out0*Observation
Date of baseline CD4 count test D.DE368 Valueout0*Resource
Viral load test result D.DE387 Valueout0*Resource
Reason for HIV viral load test Observationout0*Observation
Reason for HIV viral load testout01boolean
Routine viral load test Conditionout0*Condition
Routine viral load test Observationout0*Observation
Routine viral load testout01boolean
Targeted viral load monitoring Conditionout0*Condition
Targeted viral load monitoring Observationout0*Observation
Targeted viral load monitoringout01boolean
Initial viral load test Conditionout0*Condition
Initial viral load test Observationout0*Observation
Initial viral load testout01boolean
Follow-up viral load test after receiving enhanced adherence counselling Conditionout0*Condition
Follow-up viral load test after receiving enhanced adherence counselling Observationout0*Observation
Follow-up viral load test after receiving enhanced adherence counsellingout01boolean
Date viral load test results received by client D.DE417out0*Observation
Date viral load test results received by client D.DE417 Valueout0*Resource
Reason for ARV drug regimen substitution Observationout0*Observation
Reason for ARV drug regimen substitutionout01boolean
Toxicity/side effects D.DE419 Conditionout0*Condition
Toxicity/side effects D.DE419 Observationout0*Observation
Toxicity/side effects D.DE419out01boolean
Drug-drug interaction Conditionout0*Condition
Drug-drug interaction Observationout0*Observation
Drug-drug interactionout01boolean
Pregnancy Conditionout0*Condition
Pregnancy Observationout0*Observation
Pregnancyout01boolean
New TB Conditionout0*Condition
New TB Observationout0*Observation
New TBout01boolean
New drug available Conditionout0*Condition
New drug available Observationout0*Observation
New drug availableout01boolean
Drug out of stock Conditionout0*Condition
Drug out of stock Observationout0*Observation
Drug out of stockout01boolean
Other reason for regimen substitution Conditionout0*Condition
Other reason for regimen substitution Observationout0*Observation
Other reason for regimen substitutionout01boolean
Medications prescribed D.DE457 Observationout0*Observation
Medications prescribed D.DE457out01boolean
Date medications prescribed D.DE458out0*Observation
Date medications prescribed D.DE458 Valueout0*Resource
Dose of medications prescribedout0*Observation
Dose of medications prescribed Valueout0*Resource
Number of days medications prescribedout0*Observation
Number of days medications prescribed Valueout0*Resource
Type of treatment-limiting toxicity Observationout0*Observation
Type of treatment-limiting toxicityout01boolean
Gastrointestinal Conditionout0*Condition
Gastrointestinal Observationout0*Observation
Gastrointestinalout01boolean
Skin issues Conditionout0*Condition
Skin issues Observationout0*Observation
Skin issuesout01boolean
Peripheral neuropathy Conditionout0*Condition
Peripheral neuropathy Observationout0*Observation
Peripheral neuropathyout01boolean
Central nervous system symptoms Conditionout0*Condition
Central nervous system symptoms Observationout0*Observation
Central nervous system symptomsout01boolean
Weight gain Conditionout0*Condition
Weight gain Observationout0*Observation
Weight gainout01boolean
Hepatic dysfunction Conditionout0*Condition
Hepatic dysfunction Observationout0*Observation
Hepatic dysfunctionout01boolean
Haematological disorders Conditionout0*Condition
Haematological disorders Observationout0*Observation
Haematological disordersout01boolean
Fatigue Conditionout0*Condition
Fatigue Observationout0*Observation
Fatigueout01boolean
Headache D.DE475 Conditionout0*Condition
Headache D.DE475 Observationout0*Observation
Headache D.DE475out01boolean
Bone dysfunction Conditionout0*Condition
Bone dysfunction Observationout0*Observation
Bone dysfunctionout01boolean
Metabolic symptoms Conditionout0*Condition
Metabolic symptoms Observationout0*Observation
Metabolic symptomsout01boolean
Kidney dysfunction Conditionout0*Condition
Kidney dysfunction Observationout0*Observation
Kidney dysfunctionout01boolean
Unexpected adverse drug reaction Conditionout0*Condition
Unexpected adverse drug reaction Observationout0*Observation
Unexpected adverse drug reactionout01boolean
New regimen after switch to second-line regimenout0*MedicationStatement
New regimen after switch to third-line regimenout0*MedicationStatement
Dates of substitution within second-line regimenout0*Observation
Dates of substitution within second-line regimen Valueout0*Resource
Dates of substitution within third-line regimenout0*Observation
Dates of substitution within third-line regimen Valueout0*Resource
Enhanced adherence counselling provided Observationout0*Observation
Enhanced adherence counselling providedout01boolean
Date of cervical cancer screening testout0*Observation
Date of cervical cancer screening test Valueout0*Resource
Lifetime screening test numberout0*Observation
Lifetime screening test number Valueout0*Resource
Date of diagnosis of cervical precancer lesions or invasive cervical cancerout0*Observation
Date of diagnosis of cervical precancer lesions or invasive cervical cancer Valueout0*Resource
Cervical cancer screening outcome Observationout0*Observation
Cervical cancer screening outcomeout01boolean
Positive for cervical precancer lesions Conditionout0*Condition
Positive for cervical precancer lesions Observationout0*Observation
Positive for cervical precancer lesionsout01boolean
Negative for cervical precancer lesions Conditionout0*Condition
Negative for cervical precancer lesions Observationout0*Observation
Negative for cervical precancer lesionsout01boolean
Cervical cancer diagnosis Observationout0*Observation
Cervical cancer diagnosisout01boolean
Cervical precancer lesions Conditionout0*Condition
Cervical precancer lesions Observationout0*Observation
Cervical precancer lesionsout01boolean
Invasive cervical cancer Conditionout0*Condition
Invasive cervical cancer Observationout0*Observation
Invasive cervical cancerout01boolean
Cervical cancer stage at diagnosis Observationout0*Observation
Cervical cancer stage at diagnosisout01boolean
Stage 0 Conditionout0*Condition
Stage 0 Observationout0*Observation
Stage 0out01boolean
Stage I Conditionout0*Condition
Stage I Observationout0*Observation
Stage Iout01boolean
Stage II Conditionout0*Condition
Stage II Observationout0*Observation
Stage IIout01boolean
Stage III Conditionout0*Condition
Stage III Observationout0*Observation
Stage IIIout01boolean
Stage IV Conditionout0*Condition
Stage IV Observationout0*Observation
Stage IVout01boolean
Date of treatment for cervical precancer lesionsout0*Observation
Date of treatment for cervical precancer lesions Valueout0*Resource
Invasive cervical cancer treatment episodeout0*Observation
Invasive cervical cancer treatment episode Valueout0*Resource
Invasive cervical cancer treatment method Observationout0*Observation
Invasive cervical cancer treatment methodout01boolean
Conization Conditionout0*Condition
Conization Observationout0*Observation
Conizationout01boolean
Trachelectomy Conditionout0*Condition
Trachelectomy Observationout0*Observation
Trachelectomyout01boolean
Hysterectomy Conditionout0*Condition
Hysterectomy Observationout0*Observation
Hysterectomyout01boolean
Management of invasive cervical cancer Conditionout0*Condition
Management of invasive cervical cancer Observationout0*Observation
Management of invasive cervical cancerout01boolean
Radiotherapy Conditionout0*Condition
Radiotherapy Observationout0*Observation
Radiotherapyout01boolean
Chemotherapy Conditionout0*Condition
Chemotherapy Observationout0*Observation
Chemotherapyout01boolean
Chemoradiation Conditionout0*Condition
Chemoradiation Observationout0*Observation
Chemoradiationout01boolean
Other D.DE739 Conditionout0*Condition
Other D.DE739 Observationout0*Observation
Other D.DE739out01boolean
Eligible for DSD ARTout01boolean
Date DSD ART eligibility assessedout01boolean
Currently enrolled in DSD ART modelout01boolean
DSD ART start dateout01boolean
DSD ART models Observationout0*Observation
DSD ART modelsout01boolean
Fast track ART refill Conditionout0*Condition
Fast track ART refill Observationout0*Observation
Fast track ART refillout01boolean
Facility adherence club Conditionout0*Condition
Facility adherence club Observationout0*Observation
Facility adherence clubout01boolean
Community ART distribution point Conditionout0*Condition
Community ART distribution point Observationout0*Observation
Community ART distribution pointout01boolean
CHW/peer educator community ART group Conditionout0*Condition
CHW/peer educator community ART group Observationout0*Observation
CHW/peer educator community ART groupout01boolean
Patient/client community ART group Conditionout0*Condition
Patient/client community ART group Observationout0*Observation
Patient/client community ART groupout01boolean
Other DSD ART model Conditionout0*Condition
Other DSD ART model Observationout0*Observation
Other DSD ART modelout01boolean
Syndrome/STI diagnosed D.DE778 Observationout0*Observation
Syndrome/STI diagnosed D.DE778out01boolean
Urethral discharge syndrome D.DE779 Conditionout0*Condition
Urethral discharge syndrome D.DE779 Observationout0*Observation
Urethral discharge syndrome D.DE779out01boolean
Vaginal discharge syndrome D.DE780 Conditionout0*Condition
Vaginal discharge syndrome D.DE780 Observationout0*Observation
Vaginal discharge syndrome D.DE780out01boolean
Lower Abdominal pain D.DE781 Conditionout0*Condition
Lower Abdominal pain D.DE781 Observationout0*Observation
Lower Abdominal pain D.DE781out01boolean
Genital ulcer disease syndrome D.DE782 Conditionout0*Condition
Genital ulcer disease syndrome D.DE782 Observationout0*Observation
Genital ulcer disease syndrome D.DE782out01boolean
Anorectal discharge D.DE783 Conditionout0*Condition
Anorectal discharge D.DE783 Observationout0*Observation
Anorectal discharge D.DE783out01boolean
Sent for testing D.DE784 Conditionout0*Condition
Sent for testing D.DE784 Observationout0*Observation
Sent for testing D.DE784out01boolean
Other D.DE785 Conditionout0*Condition
Other D.DE785 Observationout0*Observation
Other D.DE785out01boolean
Any STI syndrome diagnosed D.DE787 Observationout0*Observation
Any STI syndrome diagnosed D.DE787out01boolean
Syphilis test date D.DE801out0*Observation
Syphilis test date D.DE801 Valueout0*Resource
Syphilis test result D.DE802 Observationout0*Observation
Syphilis test result D.DE802out01boolean
Positive D.DE803 Conditionout0*Condition
Positive D.DE803 Observationout0*Observation
Positive D.DE803out01boolean
Negative D.DE804 Conditionout0*Condition
Negative D.DE804 Observationout0*Observation
Negative D.DE804out01boolean
Inconclusive D.DE805 Conditionout0*Condition
Inconclusive D.DE805 Observationout0*Observation
Inconclusive D.DE805out01boolean
Syphilis treatment start date D.DE806out0*Observation
Syphilis treatment start date D.DE806 Valueout0*Resource
Gonorrhoea test date D.DE807out0*Observation
Gonorrhoea test date D.DE807 Valueout0*Resource
Gonorrhoea test result D.DE808 Observationout0*Observation
Gonorrhoea test result D.DE808out01boolean
Positive D.DE809 Conditionout0*Condition
Positive D.DE809 Observationout0*Observation
Positive D.DE809out01boolean
Negative D.DE810 Conditionout0*Condition
Negative D.DE810 Observationout0*Observation
Negative D.DE810out01boolean
Inconclusive D.DE811 Conditionout0*Condition
Inconclusive D.DE811 Observationout0*Observation
Inconclusive D.DE811out01boolean
Gonorrhoea treatment start date D.DE812out0*Observation
Gonorrhoea treatment start date D.DE812 Valueout0*Resource
Type of specimen D.DE813 Observationout0*Observation
Type of specimen D.DE813out01boolean
Blood D.DE814 Conditionout0*Condition
Blood D.DE814 Observationout0*Observation
Blood D.DE814out01boolean
Urine D.DE815 Conditionout0*Condition
Urine D.DE815 Observationout0*Observation
Urine D.DE815out01boolean
Cervical or vaginal swab D.DE816 Conditionout0*Condition
Cervical or vaginal swab D.DE816 Observationout0*Observation
Cervical or vaginal swab D.DE816out01boolean
Urethral or penile swab D.DE817 Conditionout0*Condition
Urethral or penile swab D.DE817 Observationout0*Observation
Urethral or penile swab D.DE817out01boolean
Rectal swab D.DE818 Conditionout0*Condition
Rectal swab D.DE818 Observationout0*Observation
Rectal swab D.DE818out01boolean
Other D.DE819 Conditionout0*Condition
Other D.DE819 Observationout0*Observation
Other D.DE819out01boolean
Neisseria gonorrhoeae test type D.DE828 Observationout0*Observation
Neisseria gonorrhoeae test type D.DE828out01boolean
NAAT D.DE829 Conditionout0*Condition
NAAT D.DE829 Observationout0*Observation
NAAT D.DE829out01boolean
POC Test D.DE830 Conditionout0*Condition
POC Test D.DE830 Observationout0*Observation
POC Test D.DE830out01boolean
Culture D.DE831 Conditionout0*Condition
Culture D.DE831 Observationout0*Observation
Culture D.DE831out01boolean
Microscopy D.DE832 Conditionout0*Condition
Microscopy D.DE832 Observationout0*Observation
Microscopy D.DE832out01boolean
Other D.DE833 Conditionout0*Condition
Other D.DE833 Observationout0*Observation
Other D.DE833out01boolean
TB diagnosis result Observationout0*Observation
TB diagnosis resultout01boolean
Diagnosed TB Conditionout0*Condition
Diagnosed TB Observationout0*Observation
Diagnosed TBout01boolean
TB excluded Conditionout0*Condition
TB excluded Observationout0*Observation
TB excludedout01boolean
Presumptive TB D.DE945 Observationout0*Observation
Presumptive TB D.DE945out01boolean
Date of TB diagnosisout01boolean
TB preventive treatment TPT start date in measurement periodout0*dateTime
TB preventive treatment TPT completed in measurement periodout0*MedicationStatement
TB screening resultout01boolean
Screen positive for TBout01boolean
Screen negative for TBout01boolean
Inconclusive D.DE989out01boolean
TB screening dateout01boolean
TB diagnostic test categoryout01boolean
LF-LAMout01boolean
mWRD test for TBout01boolean
Microscopy - Sputum acid-fast bacilli AFBout01boolean
TB Cultureout01boolean
TB diagnostic test dateout01boolean
TB treatment start dateout01boolean
Eligible for TB preventive treatment Observationout0*Observation
Eligible for TB preventive treatmentout01boolean
TPT regimenout0*MedicationStatement
On TPT regimenout01boolean
TPT regimen typeout0*CodeableConcept
TB preventive treatment TPT status Observationout0*Observation
TB preventive treatment TPT statusout01boolean
Not started Conditionout0*Condition
Not started Observationout0*Observation
Not startedout01boolean
On TPT Conditionout0*Condition
On TPT Observationout0*Observation
On TPTout01boolean
On TPT with interruptions Conditionout0*Condition
On TPT with interruptions Observationout0*Observation
On TPT with interruptionsout01boolean
On hold Conditionout0*Condition
On hold Observationout0*Observation
On holdout01boolean
Completed Conditionout0*Condition
Completed Observationout0*Observation
Completedout01boolean
Timing of ART initiation Observationout0*Observation
Timing of ART initiationout01boolean
Already on ART at first antenatal care visit Conditionout0*Condition
Already on ART at first antenatal care visit Observationout0*Observation
Already on ART at first antenatal care visitout01boolean
Newly on ART during pregnancy Conditionout0*Condition
Newly on ART during pregnancy Observationout0*Observation
Newly on ART during pregnancyout01boolean
Newly on ART during labour and delivery Conditionout0*Condition
Newly on ART during labour and delivery Observationout0*Observation
Newly on ART during labour and deliveryout01boolean
Delivery dateout0*Observation
Delivery date Valueout0*Resource
Place of deliveryout01boolean
Health facilityout01boolean
Homeout01boolean
Other E.DE70out01boolean
ANC contact date E.DE85out01boolean
Infant date of birthout0*Observation
Infant date of birth Valueout0*Resource
Age of infant in daysout0*integer
Age of infant in hoursout0*integer
Age of infant in weeksout0*integer
Age of infant in yearsout0*integer
HIV-exposed infant or child E.DE112out0*Observation
is HIV-exposed infant or child E.DE112out01boolean
Key population member type E.DE114 Observationout0*Observation
Is Key population member type E.DE114out01boolean
HIV test type E.DE168 Observationout0*Observation
HIV test type E.DE168out01boolean
Rapid diagnostic test for HIV E.DE169 Conditionout0*Condition
Rapid diagnostic test for HIV E.DE169 Observationout0*Observation
Rapid diagnostic test for HIV E.DE169out01boolean
Enzyme immunoassay for HIV E.DE170 Conditionout0*Condition
Enzyme immunoassay for HIV E.DE170 Observationout0*Observation
Enzyme immunoassay for HIV E.DE170out01boolean
Nucleic acid test for HIV E.DE171 Conditionout0*Condition
Nucleic acid test for HIV E.DE171 Observationout0*Observation
Nucleic acid test for HIV E.DE171out01boolean
Dual HIV/syphilis rapid diagnostic test E.DE172 Conditionout0*Condition
Dual HIV/syphilis rapid diagnostic test E.DE172 Observationout0*Observation
Dual HIV/syphilis rapid diagnostic test E.DE172out01boolean
Maternal and child health service visit Observationout0*Observation
Maternal and child health service visitout01boolean
12-month visit Conditionout0*Condition
12-month visit Observationout0*Observation
12-month visitout01boolean
24-month visit Conditionout0*Condition
24-month visit Observationout0*Observation
24-month visitout01boolean
First visit after the end of breastfeeding Conditionout0*Condition
First visit after the end of breastfeeding Observationout0*Observation
First visit after the end of breastfeedingout01boolean
Registered in birth cohort Observationout0*Observation
Registered in birth cohortout01boolean
HIV test date E.DE224out0*Observation
HIV test date E.DE224 Valueout0*Resource
Infant HIV status Observationout0*Observation
Infant HIV statusout01boolean
HIV-positive E.DE226 Conditionout0*Condition
HIV-positive E.DE226 Observationout0*Observation
HIV-positive E.DE226out01boolean
HIV-negative E.DE227 Conditionout0*Condition
HIV-negative E.DE227 Observationout0*Observation
HIV-negative E.DE227out01boolean
Unknown E.DE228 Conditionout0*Condition
Unknown E.DE228 Observationout0*Observation
Unknown E.DE228out01boolean
Infant ART start dateout0*Observation
Infant ART start date Valueout0*Resource
Final diagnosis of HIV-exposed infant E.DE230 Observationout0*Observation
Final diagnosis of HIV-exposed infant E.DE230out01boolean
HIV-positive E.DE231 Conditionout0*Condition
HIV-positive E.DE231 Observationout0*Observation
HIV-positive E.DE231out01boolean
HIV-negative and no longer breastfeeding Conditionout0*Condition
HIV-negative and no longer breastfeeding Observationout0*Observation
HIV-negative and no longer breastfeedingout01boolean
HIV status unknown Conditionout0*Condition
HIV status unknown Observationout0*Observation
HIV status unknownout01boolean
Baseline CD4 count G.DE3out0*Observation
Baseline CD4 count G.DE3 Valueout0*Resource
Date of viral load sample collection G.DE8out0*Observation
Date of viral load sample collection G.DE8 Valueout0*Resource
Viral load test result G.DE12out0*Observation
Viral load test result G.DE12 Valueout0*Resource
HBsAg test date G.DE17out0*Observation
HBsAg test date G.DE17 Valueout0*Resource
HBsAg test result G.DE18 Observationout0*Observation
HBsAg test result G.DE18out01boolean
Positive G.DE19 Conditionout0*Condition
Positive G.DE19 Observationout0*Observation
Positive G.DE19out01boolean
Negative G.DE20 Conditionout0*Condition
Negative G.DE20 Observationout0*Observation
Negative G.DE20out01boolean
Indeterminate G.DE21 Conditionout0*Condition
Indeterminate G.DE21 Observationout0*Observation
Indeterminate G.DE21out01boolean
HCV test date G.DE42out0*Observation
HCV test date G.DE42 Valueout0*Resource
HCV test result G.DE43 Observationout0*Observation
HCV test result G.DE43out01boolean
Positive G.DE44 Conditionout0*Condition
Positive G.DE44 Observationout0*Observation
Positive G.DE44out01boolean
Negative G.DE45 Conditionout0*Condition
Negative G.DE45 Observationout0*Observation
Negative G.DE45out01boolean
Indeterminate G.DE46 Conditionout0*Condition
Indeterminate G.DE46 Observationout0*Observation
Indeterminate G.DE46out01boolean
HCV viral load test date G.DE47out0*Observation
HCV viral load test date G.DE47 Valueout0*Resource
HCV viral load test result G.DE48 Observationout0*Observation
HCV viral load test result G.DE48out01boolean
Detected G.DE49 Conditionout0*Condition
Detected G.DE49 Observationout0*Observation
Detected G.DE49out01boolean
Not detected G.DE50 Conditionout0*Condition
Not detected G.DE50 Observationout0*Observation
Not detected G.DE50out01boolean
Syphilis test date G.DE69out0*Observation
Syphilis test date G.DE69 Valueout0*Resource
Syphilis test result G.DE70 Observationout0*Observation
Syphilis test result G.DE70out01boolean
Positive G.DE71 Conditionout0*Condition
Positive G.DE71 Observationout0*Observation
Positive G.DE71out01boolean
Negative G.DE72 Conditionout0*Condition
Negative G.DE72 Observationout0*Observation
Negative G.DE72out01boolean
Inconclusive G.DE73 Conditionout0*Condition
Inconclusive G.DE73 Observationout0*Observation
Inconclusive G.DE73out01boolean
HIV treatment outcomeout01boolean
Date ART stopped H.DE73out0*Observation
Date ART stopped H.DE73 Valueout0*Resource
Reason ART stopped H.DE74 Observationout0*Observation
Reason ART stopped H.DE74out01boolean
Toxicity/side effects H.DE75out01boolean
Severe illness, hospitalization H.DE76 Conditionout0*Condition
Severe illness, hospitalization H.DE76 Observationout0*Observation
Severe illness, hospitalization H.DE76out01boolean
Drugs out of stock Conditionout0*Condition
Drugs out of stock Observationout0*Observation
Drugs out of stock out01boolean
Client lacks finances Conditionout0*Condition
Client lacks finances Observationout0*Observation
Client lacks finances out01boolean
Excluded HIV infection in infant H.DE79 Conditionout0*Condition
Excluded HIV infection in infant H.DE79 Observationout0*Observation
Excluded HIV infection in infant H.DE79out01boolean
Other reason for stopping ART H.DE80 Conditionout0*Condition
Other reason for stopping ART H.DE80 Observationout0*Observation
Other reason for stopping ART H.DE80out01boolean
At elevated risk for HIV acquisition PRV.DE1out01boolean
PrEP serviceout01boolean
OAMTout01boolean
NSPout01boolean
STI servicesout01boolean
VMMCout01boolean
Other PRV.DE8out01boolean
HIV prevention interventionout0*string
HIV.PRV.DE2 - HIV prevention interventionout01boolean
Date accessed HIV prevention interventionout01boolean
HIV status of contact Observationout0*Observation
HIV status of contactout01boolean
HIV-positive PRV.DE12 Conditionout0*Condition
HIV-positive PRV.DE12 Observationout0*Observation
HIV-positive PRV.DE12out01boolean
HIV-negative PRV.DE13 Conditionout0*Condition
HIV-negative PRV.DE13 Observationout0*Observation
HIV-negative PRV.DE13out01boolean
Unknown PRV.DE14 Conditionout0*Condition
Unknown PRV.DE14 Observationout0*Observation
Unknown PRV.DE14out01boolean
Date injecting equipment providedout0*Observation
Date injecting equipment provided Valueout0*Resource
Date OAMT initiatedout0*Observation
Date OAMT initiated Valueout0*Resource
Currently on OAMT Observationout0*Observation
Currently on OAMTout01boolean
Retained on OAMT Observationout0*Observation
Retained on OAMTout01boolean
Date of loss to follow-up or OAMT stoppedout0*Observation
Date of loss to follow-up or OAMT stopped Valueout0*Resource
Date medications prescribed PRV.DE27out0*Observation
Date medications prescribed PRV.DE27 Valueout0*Resource
Number of days prescribed PRV.DE28out0*Observation
Number of days prescribed PRV.DE28 Valueout0*Resource
HIV test date SRV.DE1out0*Observation
HIV test date SRV.DE1 Valueout0*Resource
HIV test result SRV.DE2 Observationout0*Observation
HIV test result SRV.DE2out01boolean
Baseline CD4 count SRV.DE3out0*Observation
Baseline CD4 count SRV.DE3 Valueout0*Resource
Date of baseline CD4 count test SRV.DE4out01boolean
ART start date SRV.DE6out0*Observation
ART start date SRV.DE6 Valueout0*Resource
Currently pregnant SRV.DE7 Observationout0*Observation
Currently pregnant SRV.DE7out01boolean
Date of viral load sample collection SRV.DE12out0*Observation
Date of viral load sample collection SRV.DE12 Valueout0*Resource
Viral load test result SRV.DE13out0*Observation
Viral load test result SRV.DE13 Valueout0*Resource
Visit date SRV.DE15out01boolean
ANC contact date SRV.DE18out0*Observation
ANC contact date SRV.DE18 Valueout0*Resource
HIV-exposed infant or child SRV.DE20 Observationout0*Observation
HIV-exposed infant or child SRV.DE20out01boolean
Final diagnosis of HIV-exposed infant SRV.DE22 Observationout0*Observation
Final diagnosis of HIV-exposed infant SRV.DE22out01boolean
Other priority populations Observationout0*Observation
Other priority populationsout01boolean
Reporting period end dateout0*Observation
Reporting period end date Valueout0*Resource
Reporting period start dateout0*Observation
Reporting period start date Valueout0*Resource
Reporting dateout0*Observation
Reporting date Valueout0*Resource

Contents

text/cql

library HIVIndicatorElements

using FHIR version '4.0.1'

//include fhir.cqf.common.FHIRCommon called FC
include FHIRHelpers version '4.0.1'

include WHOConcepts
include WHOCommon called WC
include WHOElements called WE

include HIVConcepts called Concepts
include HIVConceptsCustom called ConceptsCustom
include HIVElements called Elements
include HIVCommon called Common
include HIVConfig called Config

parameter "Measurement Period" Interval<Date> default Interval[@2024-01-01, @2024-12-30]

context Patient

/**
 * HIV Elements
 */

/* General Data Elements */

// From Common

define "Community_testing":
  exists([Observation] O
    with [Encounter] E
      such that O.encounter.references(E) and exists(E.location.physicalType PT where PT ~  Concepts."Community-level testing") 
  where (O.status in { 'final', 'amended' }
  and O.code ~ Concepts."Rapid diagnostic test for HIV - HIV.B.DE82"
  and O.issued after start of "Measurement Period"
  and O.issued before end of "Measurement Period"))
  

/*@triggeredBy Encounter with location = facility level testing*/
define "Facility_testing":
  exists([Observation] O
    with [Encounter] E
      such that O.encounter.references(E) and exists(E.location.physicalType PT where PT ~  Concepts."Facility-level testing")
  where (O.status in { 'final', 'amended' }
  and O.code ~ Concepts."Rapid diagnostic test for HIV - HIV.B.DE82"
  and O.issued after start of "Measurement Period"
  and O.issued before end of "Measurement Period")
  )

//lifted this from ANC DAK
define "ANC_case":
exists(
    [EpisodeOfCare] EOC
    where exists(EOC.type T where T ~ Concepts."Already on ART at first antenatal care visit")
    and (exists (
      EOC.statusHistory H
      where H.period overlaps "Measurement Period"
    ) 
    or (
      EOC.period overlaps "Measurement Period"
    )
    )
    )
  
define "methadone_prescribed at date":
[MedicationRequest] MR
  where MR.status = 'completed'
    and MR.intent = 'order'
    and MR.medication ~ ConceptsCustom."methadone"
    //and "GetMedicationDailyDose"(MR.dosageInstruction, "DosesPerDay"(singleton from MR.dosageInstruction.timing.repeat.frequencyMax)) >= 60 'mg/d'
    and Common.MedicationRequestPeriod(MR) starts before start of "Measurement Period"
    and Common.MedicationRequestPeriod(MR) ends after end of "Measurement Period"

define "OAMT_initiated":
exists(
    [EpisodeOfCare] EOC
    where exists(EOC.type T where T ~ Concepts."OAMT")
    and (exists (
      EOC.statusHistory H
      where H.period starts after start of "Measurement Period"
      and H.period starts before end of "Measurement Period"
    ) 
    or (
      EOC.period starts after start of "Measurement Period"
      and EOC.period starts before end of "Measurement Period"
    )
    )
    )

define "OAMT_retained":
exists(
    [EpisodeOfCare] EOC
    where exists(EOC.type T where T ~ Concepts."OAMT")
    and (exists (
      EOC.statusHistory H
      where H.period starts after start of "Measurement Period"
      and H.period starts before end of "Measurement Period"
      and H.period ends after (end of "Measurement Period" + 6 months)
    ) 
    or (
      EOC.period starts after start of "Measurement Period"
      and EOC.period starts before end of "Measurement Period"
      and (EOC.period ends after (end of "Measurement Period" + 6 months)
      or end of EOC.period is null)
    )
    )
    )


define "PEP Prescribed before start of Measurement Period and Completed":
  [MedicationStatement] MS
    with [MedicationRequest] MR
      such that MS.basedOn.references(MR) and MR.status = 'completed'
        and MR.intent = 'order'
        and MR.medication ~ Concepts."PEP for HIV prevention"
        and MR.authoredOn before end of "Measurement Period"
  where (MS.status = 'completed'
  and exists(MS.reasonCode C where C ~ Concepts."PrEP for HIV prevention")
  )

define "PEP Prescribed during Measurement Period and Completed":
  [MedicationStatement] MS
    with [MedicationRequest] MR
      such that MS.basedOn.references(MR) and MR.status = 'completed'
        and MR.intent = 'order'
        and MR.medication ~ Concepts."PEP for HIV prevention"
        and MR.authoredOn after start of "Measurement Period"
        and MR.authoredOn before end of "Measurement Period"
  where (MS.status = 'completed'
  and exists(MS.reasonCode C where C ~ Concepts."PrEP for HIV prevention")
  )

define "HIV Test Positive After PEP Prescribed during Measurement Period":
  [Observation: Concepts."HIV test result - HIV.B.DE111"] O
    with [MedicationRequest] MR
      such that O.basedOn.references(MR) and MR.status = 'completed'
        and MR.intent = 'order'
        and MR.medication ~ Concepts."PEP for HIV prevention"
        and MR.authoredOn after start of "Measurement Period"
        and MR.authoredOn before end of "Measurement Period"
        and O.issued before (MR.authoredOn + 3 months)
  where ( O.status in {'final', 'amended'}
    and O.value ~ Concepts."HIV-positive - HIV.B.DE112"
  )


define "Patient Deceased during Measurement Period":
  case 
    when Patient.deceased is FHIR.boolean and Patient.deceased ~ true then Patient.meta.lastUpdated before end of  "Measurement Period" and  Patient.meta.lastUpdated after start of "Measurement Period"
    when Patient.deceased is FHIR.dateTime then Patient.deceased as FHIR.dateTime before end of  "Measurement Period" and Patient.deceased as FHIR.dateTime after start of "Measurement Period"
    else false
  end


// HIV Testing
define "Elevated Viral load test during Measurement Period":
  "Viral load test result D.DE387" VL
    with Elements."viral load sample collection" P 
    such that VL.partOf.references(P) and P.performed.toInterval() during "Measurement Period"
    where VL.value > 1000 
    sort by start of effective.toInterval()


define "Negative Tests within Measurement Period":
  Elements."HIV-negative test result" O
    // with Elements."At elevated risk for HIV acquisition B.DE225" HIV
    // such that O.hasMember.references(HIV)
    where O.effective.toInterval() starts during "Measurement Period"
    sort by start of effective.toInterval()

define "First Negative Test within Measurement Period":
  (First("Negative Tests within Measurement Period"))

define "Negative Tests after First Negative Test":
  Elements."HIV-negative test result" O
    // with Elements."At elevated risk for HIV acquisition B.DE225" HIV
    //   such that O.hasMember.references(HIV)
    where  O.effective.toInterval() starts after start of "First Negative Test within Measurement Period".effective.toInterval()
      and O.effective.toInterval() starts before (start of "First Negative Test within Measurement Period".effective.toInterval() + Config."Testing Interval")
    sort by start of effective.toInterval()

define "Lost to Follow Up during the measurement period":
  exists(Elements."On ART H.DE47" H
   where H.effective starts before end of "Measurement Period"
    and H.effective ends after start of "Measurement Period"
	  and not (H.effective ends after (end of "Measurement Period" - Config."LTFU Days"))
   )

// HIV Status

// ART Status

define "ART Medication Statement":
  Elements."ART Medication Statement" MS
  where MS.effective.toInterval() overlaps "Measurement Period"
  sort by start of effective.toInterval()

define "On ART":
  exists "ART Medication Statement"

define "ART Start Date":
  "ART Medication Statement" MS
  return start of MS.effective.toInterval()

define "ART Duration in Months":
  "ART Medication Statement" MS
  return duration in months of MS.effective.toInterval()

define "By ART initiation":
  case
    when Sum("ART Duration in Months") < 12 then '<12 months on ART'
    when Sum("ART Duration in Months") >= 12 then '12+ months on ART'
    else 'Unknown'
  end

// Geographic Region
define "By Geographic Region Stratifier":
    First(Patient.address A where A.use in { 'home' }).state

/*
 * Other Stratifiers
 */
define hiv_exposure_type:
  List<String>{
    if Elements.Exposure_Occupational then 'Occupational' else null,
    if Elements.Exposure_Non_Occupational_violent then 'Non-occupational violent' else null,
    if Elements.Exposure_Non_Occupational_consensual_sex then 'Non-occupational consensual sex' else null
  }

define setting:
  List<String>{
    if Community_testing then 'Community-level testing' else null,
    if Facility_testing then 'Facility-level testing' else null
  }

define anc:
  List<String>{
    if ANC_case then 'ANC case' else null
  }

define tb:
  List<String>{
    if TB_diagnosed then 'Diagnosed TB' else null,
    if TB_presumptive then 'Presumptive TB' else null
  }

define prep_product:
  List<String>{
    if Elements."PREP Product Oral" then 'PREP Product Oral' else null,
    if Elements."PREP Product long-acting device" then 'PREP Product long-acting device' else null,
    if Elements."PREP Product long-acting injectable" then 'PREP Product long-acting injectable' else null
  }

define prep_experience:
  List<String>{
    if Elements."PREP first time" then 'PREP first time' else null,
    if Elements."PREP Continuing user" then 'PREP Continuing user' else null,
    if Elements."PREP Restarting" then 'PREP Restarting' else null
  }

define prep_dosing:
  List<String>{
    if Elements."Daily_oral_PrEP" then 'Daily oral PrEP' else null,
    if Elements."Event_driven_PrEP" then 'Event driven PrEP' else null,
    if Elements."other_dosing_PrEP" then 'Other PrEP dosing type' else null
  }

define "Treatment outcome category":
  List<String>{
    if "Is lost to follow-up" then 'LTFU' else null,
    if "Has transferred out" then 'Transfer Out' else null,
    if "Has death documented" then 'Death' else null,
    if "Refused stopped treatment" then 'Stopped' else null,
    if "On ART H.DE47" then 'On ART' else null
  }

define "HIV status of partner or contact":
  case 
      when "Already knew positive" then Concepts."Already knew positive"
      when "Newly diagnosed" then Concepts."Newly diagnosed"
      when "Negative H.DE37" then Concepts."Negative - HIV.H.DE37"
      else null
  end




// Auto-generated Elements from DAK Data Dictionary
//   Entries based on DAK Data Dictionary for Data Elements marked as used
//   in at least one Decision Support Table or Aggregate Indicator

/*
@dataElement: HIV.A.DE3 - Visit date
@activity: HIV.A2 Gather client details
@description: The date and time of the client's visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "Visit date A.DE3":
  Elements."Visit date A.DE3" O
    where O.effective.toInterval() during "Measurement Period"
define "Visit date A.DE3 Value":
  "Visit date A.DE3" O
  return O.value
/* End of Visit date A.DE3 */

/*
@dataElement: HIV.A.DE17 - Age
@activity: HIV.A6.1 Review sociodemographic data with client | HIV.A5 Create new client record
@description: Calculated age (number of years) of the client based on date of birth
*/
define "Age In Years":
  AgeInYearsAt(start of "Measurement Period")

define "Age In Months":
  AgeInMonthsAt(start of "Measurement Period")

define "Age In Days":
  AgeInDaysAt(start of "Measurement Period")



/*
 * By Age Stratifiers
 * (0–4, 5–9, 10–14, 15–19, 20–24, 25–29, 30–34, 35–39, 40–44, 45–49, 50+ years)
 * 
 */
define "By Age Stratifier":
  case 
      when "Age In Years" <= 4 then '0-4'
      when "Age In Years" <= 9 then '5-9'
      when "Age In Years" <= 14 then '10–14'
      when "Age In Years" <= 19 then '15–19'
      when "Age In Years" <= 24 then '20–24'
      when "Age In Years" <= 29 then '25–29'
      when "Age In Years" <= 34 then '30–34'
      when "Age In Years" <= 39 then '35–39'
      when "Age In Years" <= 44 then '40–44'
      when "Age In Years" <= 49 then '45–49'
      when "Age In Years" >= 50 then '50+'
      else null
  end
  
  /*
 * By Age Stratifiers
 * Age (0–4, 5–9, 10–14, 15–19, 20–24, 25–49, 50+ years)
 * 
 */
define "By Age Stratifier 2":
  case 
      when "Age In Years" <= 4 then '0-4'
      when "Age In Years" <= 9 then '5-9'
      when "Age In Years" <= 14 then '10–14'
      when "Age In Years" <= 19 then '15–19'
      when "Age In Years" <= 24 then '20–24'
      when "Age In Years" <= 49 then '25–49'
      when "Age In Years" >= 50 then '50+'
      else null
  end

define "By Age Stratifier 3":
  case 
      when "Age In Years" >= 15 and "Age In Years"<= 19 then '15-19'
      when "Age In Years" <= 24 then '20-24'
      when "Age In Years" <= 49 then '25–49'
      when "Age In Years" >= 50 then '50+'
      else null
  end

/* End of Age */






/*
@dataElement: HIV.A.DE18 - Gender
@activity: HIV.A6.1 Review sociodemographic data with client | HIV.A5 Create new client record
@description: Gender of the client
*/

/*
 * By Administrative Gender of Patient Stratifier
 * Need to expand codes
 */

define "By Administrative Gender Stratifier":
  case 
      when Patient.gender = 'male' then Concepts."Male"
      when Patient.gender = 'female' then Concepts."Female"
      when Patient.gender = 'transgender female' then Concepts."Transgender female"
      when Patient.gender = 'transgender male' then Concepts."Transgender male"
      else Concepts."Other - HIV.A.DE23"
  end

/*
@dataElement: HIV.B.DE5 - Referred through partner services
@activity: HIV.B1 Determine reason for visit
@description: Client reported coming to the facility after receiving a provider-assisted referral or patient referral from a contact or partner
*/
// TODO: Replace placeholder with relevant CQL logic
define "Referred through partner services":
  exists "Referred through partner services Observation"
define "Referred through partner services Observation":
  Elements."Referred through partner services Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Referred through partner services */

/*
@dataElement: HIV.B.DE6 - Partner or contact of an index case
@activity: HIV.B1 Determine reason for visit
@description: The client is a contact or partner of a person diagnosed with HIV (an index case)
*/

/* End of Partner or contact of an index case */

/*
@dataElement: HIV.B.DE7 - Partner or contact of an HIV testing client non-index case
@activity: HIV.B1 Determine reason for visit
@description: The client is a contact or partner identified through partner or social network services, but is not known to be a partner of an index-case
*/
// TODO: Replace placeholder with relevant CQL logic
define "Partner or contact of an HIV testing client non-index case":
  exists "Partner or contact of an HIV testing client non-index case Condition"
    or exists "Partner or contact of an HIV testing client non-index case Observation"
define "Partner or contact of an HIV testing client non-index case Condition":
  Elements."Partner or contact of an HIV testing client non-index case Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Partner or contact of an HIV testing client non-index case Observation":
  Elements."Partner or contact of an HIV testing client non-index case Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Partner or contact of an HIV testing client non-index case */

/*
@dataElement: HIV.B.DE8 - Type of contact or partner for partner services
@activity: HIV.B1 Determine reason for visit
@description: Client's relationship to the person that referred the client for partner services or family services
*/
// TODO: Replace placeholder with relevant CQL logic
define "Type of contact or partner for partner services":
  exists "Type of contact or partner for partner services Observation"
define "Type of contact or partner for partner services Observation":
  Elements."Type of contact or partner for partner services Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Type of contact or partner for partner services */

/*
@dataElement: HIV.B.DE9 - Biological child
@activity: HIV.B1 Determine reason for visit
@description: Client is the biological child of the person that referred the client for family services
*/
// TODO: Replace placeholder with relevant CQL logic
define "Biological child":
  exists "Biological child Condition"
    or exists "Biological child Observation"
define "Biological child Condition":
  Elements."Biological child Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Biological child Observation":
  Elements."Biological child Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Biological child */

/*
@dataElement: HIV.B.DE10 - Drug-injecting partner
@activity: HIV.B1 Determine reason for visit
@description: Client is a drug-injecting partner of the person that referred the client for partner services
*/
// TODO: Replace placeholder with relevant CQL logic
define "Drug-injecting partner B.DE10":
  exists "Drug-injecting partner B.DE10 Condition"
    or exists "Drug-injecting partner B.DE10 Observation"
define "Drug-injecting partner B.DE10 Condition":
  Elements."Drug-injecting partner B.DE10 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Drug-injecting partner B.DE10 Observation":
  Elements."Drug-injecting partner B.DE10 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Drug-injecting partner B.DE10 */

/*
@dataElement: HIV.B.DE11 - Sexual partner
@activity: HIV.B1 Determine reason for visit
@description: Client is a sexual partner of the person that referred the client for partner services
*/
// TODO: Replace placeholder with relevant CQL logic
define "Sexual partner B.DE11":
  exists "Sexual partner B.DE11 Condition"
    or exists "Sexual partner B.DE11 Observation"
define "Sexual partner B.DE11 Condition":
  Elements."Sexual partner B.DE11 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Sexual partner B.DE11 Observation":
  Elements."Sexual partner B.DE11 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Sexual partner B.DE11 */

/*
@dataElement: HIV.B.DE12 - Social contact
@activity: HIV.B1 Determine reason for visit
@description: Client is a social contact of the person that referred the client for social-network services
*/
// TODO: Replace placeholder with relevant CQL logic
define "Social contact B.DE12":
  exists "Social contact B.DE12 Condition"
    or exists "Social contact B.DE12 Observation"
define "Social contact B.DE12 Condition":
  Elements."Social contact B.DE12 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Social contact B.DE12 Observation":
  Elements."Social contact B.DE12 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Social contact B.DE12 */

/*
@dataElement: HIV.B.DE15 - Testing entry point
@activity: HIV.B1 Determine reason for visit
@description: Whether testing is happening in the community or at a facility
*/
// TODO: Replace placeholder with relevant CQL logic
define "Testing entry point":
  exists "Testing entry point Observation"
define "Testing entry point Observation":
  Elements."Testing entry point Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Testing entry point */

/*
@dataElement: HIV.B.DE16 - Community-level testing
@activity: HIV.B1 Determine reason for visit
@description: Testing is happening in the community, which includes mobile testing
*/
// TODO: Replace placeholder with relevant CQL logic
define "Community-level testing":
  exists "Community-level testing Condition"
    or exists "Community-level testing Observation"
define "Community-level testing Condition":
  Elements."Community-level testing Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Community-level testing Observation":
  Elements."Community-level testing Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Community-level testing */

/*
@dataElement: HIV.B.DE17 - Facility-level testing
@activity: HIV.B1 Determine reason for visit
@description: Testing is happening at a facility
*/
// TODO: Replace placeholder with relevant CQL logic
define "Facility-level testing":
  exists "Facility-level testing Condition"
    or exists "Facility-level testing Observation"
define "Facility-level testing Condition":
  Elements."Facility-level testing Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Facility-level testing Observation":
  Elements."Facility-level testing Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Facility-level testing */

/*
@dataElement: HIV.B.DE29 - Currently pregnant
@activity: HIV.B6 Capture or update client history
@description: Client is currently pregnant
*/
// TODO: Replace placeholder with relevant CQL logic
define "Currently pregnant B.DE29":
  exists "Currently pregnant B.DE29 Observation"
define "Currently pregnant B.DE29 Observation":
  Elements."Currently pregnant B.DE29 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Currently pregnant B.DE29 */

/*
@dataElement: HIV.B.DE32 - Breastfeeding
@activity: HIV.B6 Capture or update client history
@description: Infant is being breastfed by mother
*/
// TODO: Replace placeholder with relevant CQL logic
define "Breastfeeding B.DE32":
  exists "Breastfeeding B.DE32 Observation"
define "Breastfeeding B.DE32 Observation":
  Elements."Breastfeeding B.DE32 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Breastfeeding B.DE32 */

/*
@dataElement: HIV.B.DE33 - Partner HIV status reported
@activity: HIV.B6 Capture or update client history
@description: The HIV status of the client's partner.
*/
// TODO: Replace placeholder with relevant CQL logic
define "Partner HIV status reported":
  exists "Partner HIV status reported Observation"
define "Partner HIV status reported Observation":
  Elements."Partner HIV status reported Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Partner HIV status reported */

/*
@dataElement: HIV.B.DE34 - HIV-positive
@activity: HIV.B6 Capture or update client history
@description: Client's partner is HIV-positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-positive B.DE34":
  exists "HIV-positive B.DE34 Condition"
    or exists "HIV-positive B.DE34 Observation"
define "HIV-positive B.DE34 Condition":
  Elements."HIV-positive B.DE34 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-positive B.DE34 Observation":
  Elements."HIV-positive B.DE34 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-positive B.DE34 */

/*
@dataElement: HIV.B.DE35 - HIV-negative
@activity: HIV.B6 Capture or update client history
@description: Client's partner is HIV-negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-negative B.DE35":
  exists "HIV-negative B.DE35 Condition"
    or exists "HIV-negative B.DE35 Observation"
define "HIV-negative B.DE35 Condition":
  Elements."HIV-negative B.DE35 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-negative B.DE35 Observation":
  Elements."HIV-negative B.DE35 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-negative B.DE35 */

/*
@dataElement: HIV.B.DE36 - Unknown
@activity: HIV.B6 Capture or update client history
@description: Don't know HIV status - client does not know partner's HIV status
*/
// TODO: Replace placeholder with relevant CQL logic
define "Unknown B.DE36":
  exists "Unknown B.DE36 Condition"
    or exists "Unknown B.DE36 Observation"
define "Unknown B.DE36 Condition":
  Elements."Unknown B.DE36 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Unknown B.DE36 Observation":
  Elements."Unknown B.DE36 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Unknown B.DE36 */

/*
@dataElement: HIV.B.DE50 - Key population member type
@activity: HIV.B6 Capture or update client history
@description: The type of key population that the client is included in
*/
define "Is Key population member":
  exists "Key population member type Observation"

define "Key population member type Observation":
  Elements."Key population member type Observation" O
    where O.effective.toInterval() before end of "Measurement Period"
    or O.issued before end of "Measurement Period"

// Stratifier
define patientGroups:
  "Key population member type Observation" O
  return Combine(O.code.coding.code, ':')
/* End of Key population member type B.DE50 */

/*
@dataElement: HIV.B.DE51 - Sex worker
@activity: HIV.B6 Capture or update client history
@description: Client is a sex worker
*/
define "Sex worker":
  exists("Key population member type Observation" O
    where O.value ~ Concepts."Sex worker - HIV.B.DE51")
/* End of Sex worker B.DE51 */

/*
@dataElement: HIV.B.DE52 - Men who have sex with men
@activity: HIV.B6 Capture or update client history
@description: Client is a man who has sex with men
*/
define "Men who have sex with men":
  exists("Key population member type Observation" O
    where O.value ~ Concepts."Men who have sex with men")
/* End of Men who have sex with men */

/*
@dataElement: HIV.B.DE53 - Trans and gender-diverse people
@activity: HIV.B6 Capture or update client history
@description: Client identifies as trans and gender-diverse
*/
define "Trans and gender-diverse people":
  exists("Key population member type Observation" O
    where O.value ~ Concepts."Trans and gender-diverse people - HIV.B.DE53")
/* End of Trans and gender-diverse people B.DE53 */

/*
@dataElement: HIV.B.DE54 - People who inject drugs
@activity: HIV.B6 Capture or update client history
@description: Client is a person who injects drugs
*/
define "People who inject drugs":
  "Key population member type Observation" O
    where O.value ~ Concepts."People who inject drugs - HIV.B.DE54"

/* End of People who inject drugs B.DE54 */

/*
@dataElement: HIV.B.DE55 - People living in prisons and other closed settings
@activity: HIV.B6 Capture or update client history
@description: Client lives in a prison or another closed setting
*/
define "People living in prisons and other closed settings":
  exists("Key population member type Observation" O
    where O.value ~ Concepts."People living in prisons and other closed settings")
/* End of People living in prisons and other closed settings */

/*
@dataElement: HIV.B.DE60 - Date HIV test results returned
@activity: HIV.B6 Capture or update client history
@description: Date HIV test result returned to client
*/
define "HIV test results returned in measurement period":
  Elements."HIV test" O
   where O.issued during "Measurement Period"

define "Has HIV test results returned in measurement period":
  exists("HIV test results returned in measurement period")
/* End of Date HIV test results returned */

/*
@dataElement: HIV.B.DE61 - HIV exposure type
@activity: HIV.B6 Capture or update client history
@description: Ways in which the client was exposed to HIV
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV exposure type":
  exists "HIV exposure type Observation"
define "HIV exposure type Observation":
  Elements."HIV exposure type Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV exposure type */

/*
@dataElement: HIV.B.DE62 - Occupational
@activity: HIV.B6 Capture or update client history
@description: Occupational exposure to HIV
*/
// TODO: Replace placeholder with relevant CQL logic
define "Occupational":
  exists "Occupational Condition"
    or exists "Occupational Observation"
define "Occupational Condition":
  Elements."Occupational Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Occupational Observation":
  Elements."Occupational Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Occupational */

/*
@dataElement: HIV.B.DE63 - Non-occupational violent
@activity: HIV.B6 Capture or update client history
@description: Non-occupational violent exposure to HIV
*/
// TODO: Replace placeholder with relevant CQL logic
define "Non-occupational violent":
  exists "Non-occupational violent Condition"
    or exists "Non-occupational violent Observation"
define "Non-occupational violent Condition":
  Elements."Non-occupational violent Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Non-occupational violent Observation":
  Elements."Non-occupational violent Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Non-occupational violent */

/*
@dataElement: HIV.B.DE64 - Non-occupational consensual sex
@activity: HIV.B6 Capture or update client history
@description: Exposure to HIV through non-occupational consensual sex
*/
// TODO: Replace placeholder with relevant CQL logic
define "Non-occupational consensual sex":
  exists "Non-occupational consensual sex Condition"
    or exists "Non-occupational consensual sex Observation"
define "Non-occupational consensual sex Condition":
  Elements."Non-occupational consensual sex Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Non-occupational consensual sex Observation":
  Elements."Non-occupational consensual sex Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Non-occupational consensual sex */

/*
@dataElement: HIV.B.DE65 - Date informed of HIV-positive diagnosis
@activity: HIV.B6 Capture or update client history
@description: The date on which the client was diagnosed with HIV
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date informed of HIV-positive diagnosis":
  Elements."Date informed of HIV-positive diagnosis" O
    where O.effective.toInterval() during "Measurement Period"
define "Date informed of HIV-positive diagnosis Value":
  "Date informed of HIV-positive diagnosis" O
  return O.value
/* End of Date informed of HIV-positive diagnosis */

/*
@dataElement: HIV.B.DE71 - HIV diagnosis date
@activity: HIV.B8 Provide post-test counselling
@description: Date diagnosis was returned to client
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV diagnosis date":
  Elements."HIV diagnosis date" O
    where O.effective.toInterval() during "Measurement Period"
define "HIV diagnosis date Value":
  "HIV diagnosis date" O
  return O.value
/* End of HIV diagnosis date */

/*
@dataElement: HIV.B.DE72 - ART start date
@activity: HIV.B8 Provide post-test counselling
@description: The date on which the client started or restarted antiretroviral therapy (ART)
*/
// TODO: Replace placeholder with relevant CQL logic
define "ART start date B.DE72":
  Elements."ART start date B.DE72" O
    where O.effective.toInterval() during "Measurement Period"
define "ART start date B.DE72 Value":
  "ART start date B.DE72" O
  return O.value
/* End of ART start date B.DE72 */

/*
@dataElement: HIV.B.DE81 - HIV test type
@activity: HIV.B7 Test for HIV using testing algorithm
@description: Type of HIV test
*/
define "HIV test type B.DE81":
  Elements."HIV test type B.DE81" O
    where O.effective.toInterval() during "Measurement Period"
define "HIV test type B.DE81 Value":
  "HIV test type B.DE81" O
  return O.value
/* End of HIV test type B.DE81 */

/*
@dataElement: HIV.B.DE110 - HIV test date
@activity: HIV.B7 Test for HIV using testing algorithm
@description: Date of the HIV test
*/
define "Non-Self HIV test with date and results returned in measurement period":
  Elements."Non-Self HIV test" O
  where start of O.effective.toInterval() during "Measurement Period"
    and O.issued during "Measurement Period"

/* End of HIV test date B.DE110 */

/*
@dataElement: HIV.B.DE112 - HIV-positive
@activity: HIV.B7 Test for HIV using testing algorithm
@description: Test result is HIV-positive
*/

define "Non-Self HIV test date and results returned within measurement period for HIV-positive result":
  "Non-Self HIV test with date and results returned in measurement period" O
    where O.value ~ Concepts."HIV-positive - HIV.B.DE112"
/* End of HIV-positive B.DE112 */

/* HIV-negative test */
define "Negative HIV test within measurement period":
  Elements."HIV test" O
  where O.effective.toInterval() overlaps "Measurement Period"
    and O.value ~ Concepts."HIV-negative - HIV.B.DE113"

/*
@dataElement: HIV.B.DE115 - HIV status
@activity: HIV.B7 Test for HIV using testing algorithm
@description: HIV status reported after applying the national HIV testing algorithm. No single HIV test can provide an HIV-positive diagnosis.
*/
// define "HIV Status":
//   case 
//       when exists("HIV Positive Condition") then Concepts."HIV-positive - HIV.B.DE116"
//       when not exists("HIV Positive Condition") and exists(Elements."HIV Negative Observation" O where O.issued before end of "Measurement Period") then  Concepts."HIV-negative - HIV.B.DE117"
//       else Concepts."Unknown - HIV.B.DE118"
//   end

define "HIV Status Stratifier":
  case 
      when "Has HIV-positive Status" then Concepts."HIV-positive - HIV.B.DE116"
      when not exists("HIV Status Positive Condition") and exists("HIV Status Negative Observation") then  Concepts."HIV-negative - HIV.B.DE117"
      else Concepts."Unknown - HIV.B.DE118"
  end



/* End of HIV status */

/*
@dataElement: HIV.B.DE116 - HIV-positive
@activity: HIV.B7 Test for HIV using testing algorithm
@description: Client is HIV-positive
*/
define "Has HIV-positive Status at last measurment period":
  exists "HIV Status positive at last measurement period Condition"
  or exists "HIV Status positive at last measurement period Observation"
  
define "HIV Status positive at last measurement period Condition":
  Elements."HIV Status Positive Condition" C
  where C.onset.toInterval() starts before (start of "Measurement Period" - duration in days of "Measurement Period")

define "HIV Status positive at last measurement period Observation":
  Elements."HIV Status Positive Observation" O
  where O.effective.toInterval() starts before (start of "Measurement Period" - duration in days of "Measurement Period")

define "Has HIV-positive Status":
  exists "HIV Status Positive Condition"
  or exists "HIV Status Positive Observation"

define "HIV Status Positive Condition":
  Elements."HIV Status Positive Condition" C
  where C.onset before end of "Measurement Period"

define "HIV Status Positive Observation":
  Elements."HIV Status Positive Observation" O
  where O.issued before end of "Measurement Period"
  or O.effective.toInterval() starts before end of "Measurement Period"

/* End of HIV-positive B.DE116 */

define "HIV Status Negative Observation":
  Elements."HIV Status Negative Observation" O
  where O.issued before end of "Measurement Period"
  or O.effective.toInterval() starts before end of "Measurement Period"

define "HIV Status Negative Condition":
  Elements."HIV Status Negative Condition" C
  where C.onset before end of "Measurement Period"

/*
@dataElement: HIV.B.DE121 - Probable route of transmission
@activity: HIV.B8 Provide post-test counselling
@description: Probable route(s) of transmission of HIV to client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Probable route of transmission":
  exists "Probable route of transmission Observation"
define "Probable route of transmission Observation":
  Elements."Probable route of transmission Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Probable route of transmission */

/*
@dataElement: HIV.B.DE122 - Heterosexual sex
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission was through heterosexual sex
*/
// TODO: Replace placeholder with relevant CQL logic
define "Heterosexual sex":
  exists "Heterosexual sex Condition"
    or exists "Heterosexual sex Observation"
define "Heterosexual sex Condition":
  Elements."Heterosexual sex Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Heterosexual sex Observation":
  Elements."Heterosexual sex Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Heterosexual sex */

/*
@dataElement: HIV.B.DE123 - Sex between men
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission was through sex between men
*/
// TODO: Replace placeholder with relevant CQL logic
define "Sex between men":
  exists "Sex between men Condition"
    or exists "Sex between men Observation"
define "Sex between men Condition":
  Elements."Sex between men Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Sex between men Observation":
  Elements."Sex between men Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Sex between men */

/*
@dataElement: HIV.B.DE124 - Unprotected intercourse during sex work
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission was through unprotected intercourse during sex work
*/
// TODO: Replace placeholder with relevant CQL logic
define "Unprotected intercourse during sex work":
  exists "Unprotected intercourse during sex work Condition"
    or exists "Unprotected intercourse during sex work Observation"
define "Unprotected intercourse during sex work Condition":
  Elements."Unprotected intercourse during sex work Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Unprotected intercourse during sex work Observation":
  Elements."Unprotected intercourse during sex work Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Unprotected intercourse during sex work */

/*
@dataElement: HIV.B.DE125 - Injecting drug use with unsterile equipment
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission was through injecting drug use with unsterile equipment
*/
// TODO: Replace placeholder with relevant CQL logic
define "Injecting drug use with unsterile equipment":
  exists "Injecting drug use with unsterile equipment Condition"
    or exists "Injecting drug use with unsterile equipment Observation"
define "Injecting drug use with unsterile equipment Condition":
  Elements."Injecting drug use with unsterile equipment Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Injecting drug use with unsterile equipment Observation":
  Elements."Injecting drug use with unsterile equipment Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Injecting drug use with unsterile equipment */

/*
@dataElement: HIV.B.DE126 - Nosocomial
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission was nosocomial
*/
// TODO: Replace placeholder with relevant CQL logic
define "Nosocomial":
  exists "Nosocomial Condition"
    or exists "Nosocomial Observation"
define "Nosocomial Condition":
  Elements."Nosocomial Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Nosocomial Observation":
  Elements."Nosocomial Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Nosocomial */

/*
@dataElement: HIV.B.DE127 - Vertical
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission to an infant was during pregnancy, labour, delivery and breastfeeding (vertical transmission)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Vertical":
  exists "Vertical Condition"
    or exists "Vertical Observation"
define "Vertical Condition":
  Elements."Vertical Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Vertical Observation":
  Elements."Vertical Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Vertical */

/*
@dataElement: HIV.B.DE128 - Other
@activity: HIV.B8 Provide post-test counselling
@description: Probable route of HIV transmission was other and may include needle accidents, blood transfusion, blood products or organ/tissue donations, tattoos, piercings, circumcision, or acupuncture.
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other B.DE128":
  exists "Other B.DE128 Condition"
    or exists "Other B.DE128 Observation"
define "Other B.DE128 Condition":
  Elements."Other B.DE128 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other B.DE128 Observation":
  Elements."Other B.DE128 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other B.DE128 */

/*
@dataElement: HIV.B.DE198 - VMMC procedure date
@activity: HIV.B21 Offer prevention options
@description: Date on which a voluntary medical male circumcision procedure was performed
*/
// TODO: Replace placeholder with relevant CQL logic
define "VMMC procedure date":
  Elements."VMMC procedure date" O
    where O.effective.toInterval() during "Measurement Period"
define "VMMC procedure date Value":
  "VMMC procedure date" O
  return O.value
/* End of VMMC procedure date */

/*
@dataElement: HIV.B.DE201 - Adverse event severity
@activity: HIV.B21 Offer prevention options
@description: Severity of the adverse event associated with voluntary medical male circumcision (VMMC) procedure
*/

define "VMMC_adverse_event":
[AdverseEvent] AE 
  with [Procedure] P
      such that AE.suspectEntity.instance.references(P) and P.status = 'completed' 
      and P.code ~  Concepts."Voluntary medical male circumcision VMMC"
      and P.performed after start of "Measurement Period"
      and P.performed before end of "Measurement Period"
      and AE.date <= (P.performed + 30 days)
      and AE.date >= (P.performed)
  where AE.actuality = 'actual'


define "VMMC_adverse_event_type":
    case 
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Abnormal pain") then  Concepts."Abnormal pain"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Anaesthesia-related effects") then  Concepts."Anaesthesia-related effects"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Damage to the penis") then  Concepts."Damage to the penis"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Difficulty urinating") then  Concepts."Difficulty urinating"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Excessive bleeding") then  Concepts."Excessive bleeding"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Excessive skin removal") then  Concepts."Excessive skin removal"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Excessive swelling") then  Concepts."Excessive swelling"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Haematoma") then  Concepts."Haematoma"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Infection") then  Concepts."Infection"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Injury to glans") then  Concepts."Injury to glans"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Scar or disfigurement") then  Concepts."Scar or disfigurement"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Sharps injury to personnel") then  Concepts."Sharps injury to personnel"
        when exists("VMMC_adverse_event" AE where AE.event ~ Concepts."Wound disruption") then  Concepts."Wound disruption"
        else Concepts."Other - HIV.B.DE222"
    end

define "VMMC_adverse_event_Intraoperative":
[AdverseEvent] AE 
  with [Procedure] P
      such that AE.suspectEntity.instance.references(P) and P.status = 'completed' 
      and P.code ~  Concepts."Voluntary medical male circumcision VMMC"
      and P.performed after start of "Measurement Period"
      and P.performed before end of "Measurement Period"
      and AE.date = P.performed
  where AE.actuality = 'actual'

define "VMMC_adverse_event_Postoperative":
[AdverseEvent] AE 
  with [Procedure] P
      such that AE.suspectEntity.instance.references(P) and P.status = 'completed' 
      and P.code ~  Concepts."Voluntary medical male circumcision VMMC"
      and P.performed after start of "Measurement Period"
      and P.performed before end of "Measurement Period"
      and AE.date <= (P.performed + 30 days)
      and AE.date > (P.performed)
  where AE.actuality = 'actual'

define "VMMC_adverse_event_timing":
  case 
      when exists(VMMC_adverse_event_Intraoperative) then  Concepts."Intraoperative"
      when exists(VMMC_adverse_event_Postoperative) then  Concepts."Postoperative"
      else null
  end

// TODO: Replace placeholder with relevant CQL logic
define "Adverse event severity":
  exists "Adverse event severity Observation"
define "Adverse event severity Observation":
  Elements."Adverse event severity Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Adverse event severity */

/*
@dataElement: HIV.B.DE202 - Moderate
@activity: HIV.B21 Offer prevention options
@description: Severity of the adverse event associated with VMMC procedure was moderate
*/
// TODO: Replace placeholder with relevant CQL logic
define "Moderate":
  exists "Moderate Condition"
    or exists "Moderate Observation"
define "Moderate Condition":
  Elements."Moderate Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Moderate Observation":
  Elements."Moderate Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Moderate */

/*
@dataElement: HIV.B.DE203 - Severe
@activity: HIV.B21 Offer prevention options
@description: Severity of the adverse event associated with VMMC procedure was severe
*/
// TODO: Replace placeholder with relevant CQL logic
define "Severe":
  exists "Severe Condition"
    or exists "Severe Observation"
define "Severe Condition":
  Elements."Severe Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Severe Observation":
  Elements."Severe Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Severe */

/*
@dataElement: HIV.B.DE204 - Timing of adverse event
@activity: HIV.B21 Offer prevention options
@description: When the adverse event associated with VMMC procedure occurred
*/
// TODO: Replace placeholder with relevant CQL logic
define "Timing of adverse event":
  exists "Timing of adverse event Observation"
define "Timing of adverse event Observation":
  Elements."Timing of adverse event Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Timing of adverse event */

/*
@dataElement: HIV.B.DE205 - Intraoperative
@activity: HIV.B21 Offer prevention options
@description: The adverse event associated with VMMC procedure occurred during the procedure
*/
// TODO: Replace placeholder with relevant CQL logic
define "Intraoperative":
  exists "Intraoperative Condition"
    or exists "Intraoperative Observation"
define "Intraoperative Condition":
  Elements."Intraoperative Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Intraoperative Observation":
  Elements."Intraoperative Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Intraoperative */

/*
@dataElement: HIV.B.DE206 - Postoperative
@activity: HIV.B21 Offer prevention options
@description: The adverse event associated with VMMC procedure occurred within the first 30 days after the procedure
*/
// TODO: Replace placeholder with relevant CQL logic
define "Postoperative":
  exists "Postoperative Condition"
    or exists "Postoperative Observation"
define "Postoperative Condition":
  Elements."Postoperative Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Postoperative Observation":
  Elements."Postoperative Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Postoperative */

/*
@dataElement: HIV.B.DE207 - Type of adverse VMMC event
@activity: HIV.B21 Offer prevention options
@description: Type of adverse event associated with voluntary medical male circumcision (VMMC) procedure
*/
// TODO: Replace placeholder with relevant CQL logic
define "Type of adverse VMMC event":
  exists "Type of adverse VMMC event Observation"
define "Type of adverse VMMC event Observation":
  Elements."Type of adverse VMMC event Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Type of adverse VMMC event */

/*
@dataElement: HIV.B.DE208 - Abnormal pain
@activity: HIV.B21 Offer prevention options
@description: Client experienced abnormal pain
*/
// TODO: Replace placeholder with relevant CQL logic
define "Abnormal pain":
  exists "Abnormal pain Condition"
    or exists "Abnormal pain Observation"
define "Abnormal pain Condition":
  Elements."Abnormal pain Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Abnormal pain Observation":
  Elements."Abnormal pain Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Abnormal pain */

/*
@dataElement: HIV.B.DE209 - Anaesthesia-related effects
@activity: HIV.B21 Offer prevention options
@description: Client had anaesthesia-related effects
*/
// TODO: Replace placeholder with relevant CQL logic
define "Anaesthesia-related effects":
  exists "Anaesthesia-related effects Condition"
    or exists "Anaesthesia-related effects Observation"
define "Anaesthesia-related effects Condition":
  Elements."Anaesthesia-related effects Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Anaesthesia-related effects Observation":
  Elements."Anaesthesia-related effects Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Anaesthesia-related effects */

/*
@dataElement: HIV.B.DE210 - Bleeding
@activity: HIV.B21 Offer prevention options
@description: Client had bleeding
*/
// TODO: Replace placeholder with relevant CQL logic
define "Bleeding":
  exists "Bleeding Condition"
    or exists "Bleeding Observation"
define "Bleeding Condition":
  Elements."Bleeding Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Bleeding Observation":
  Elements."Bleeding Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Bleeding */

/*
@dataElement: HIV.B.DE211 - Damage to the penis
@activity: HIV.B21 Offer prevention options
@description: Client had damage to the penis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Damage to the penis":
  exists "Damage to the penis Condition"
    or exists "Damage to the penis Observation"
define "Damage to the penis Condition":
  Elements."Damage to the penis Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Damage to the penis Observation":
  Elements."Damage to the penis Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Damage to the penis */

/*
@dataElement: HIV.B.DE212 - Difficulty urinating
@activity: HIV.B21 Offer prevention options
@description: Client had difficulty urinating
*/
// TODO: Replace placeholder with relevant CQL logic
define "Difficulty urinating":
  exists "Difficulty urinating Condition"
    or exists "Difficulty urinating Observation"
define "Difficulty urinating Condition":
  Elements."Difficulty urinating Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Difficulty urinating Observation":
  Elements."Difficulty urinating Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Difficulty urinating */

/*
@dataElement: HIV.B.DE213 - Excessive bleeding
@activity: HIV.B21 Offer prevention options
@description: Client experienced excessive bleeding
*/
// TODO: Replace placeholder with relevant CQL logic
define "Excessive bleeding":
  exists "Excessive bleeding Condition"
    or exists "Excessive bleeding Observation"
define "Excessive bleeding Condition":
  Elements."Excessive bleeding Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Excessive bleeding Observation":
  Elements."Excessive bleeding Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Excessive bleeding */

/*
@dataElement: HIV.B.DE214 - Excessive skin removal
@activity: HIV.B21 Offer prevention options
@description: Client experienced excessive skin removal
*/
// TODO: Replace placeholder with relevant CQL logic
define "Excessive skin removal":
  exists "Excessive skin removal Condition"
    or exists "Excessive skin removal Observation"
define "Excessive skin removal Condition":
  Elements."Excessive skin removal Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Excessive skin removal Observation":
  Elements."Excessive skin removal Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Excessive skin removal */

/*
@dataElement: HIV.B.DE215 - Excessive swelling
@activity: HIV.B21 Offer prevention options
@description: Client experienced excessive swelling
*/
// TODO: Replace placeholder with relevant CQL logic
define "Excessive swelling":
  exists "Excessive swelling Condition"
    or exists "Excessive swelling Observation"
define "Excessive swelling Condition":
  Elements."Excessive swelling Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Excessive swelling Observation":
  Elements."Excessive swelling Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Excessive swelling */

/*
@dataElement: HIV.B.DE216 - Haematoma
@activity: HIV.B21 Offer prevention options
@description: Client experienced haematoma
*/
// TODO: Replace placeholder with relevant CQL logic
define "Haematoma":
  exists "Haematoma Condition"
    or exists "Haematoma Observation"
define "Haematoma Condition":
  Elements."Haematoma Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Haematoma Observation":
  Elements."Haematoma Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Haematoma */

/*
@dataElement: HIV.B.DE217 - Infection
@activity: HIV.B21 Offer prevention options
@description: Client experienced infection
*/
// TODO: Replace placeholder with relevant CQL logic
define "Infection":
  exists "Infection Condition"
    or exists "Infection Observation"
define "Infection Condition":
  Elements."Infection Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Infection Observation":
  Elements."Infection Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Infection */

/*
@dataElement: HIV.B.DE218 - Injury to glans
@activity: HIV.B21 Offer prevention options
@description: Client experienced injury to glans
*/
// TODO: Replace placeholder with relevant CQL logic
define "Injury to glans":
  exists "Injury to glans Condition"
    or exists "Injury to glans Observation"
define "Injury to glans Condition":
  Elements."Injury to glans Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Injury to glans Observation":
  Elements."Injury to glans Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Injury to glans */

/*
@dataElement: HIV.B.DE219 - Scar or disfigurement
@activity: HIV.B21 Offer prevention options
@description: Client experienced scar or disfigurement
*/
// TODO: Replace placeholder with relevant CQL logic
define "Scar or disfigurement":
  exists "Scar or disfigurement Condition"
    or exists "Scar or disfigurement Observation"
define "Scar or disfigurement Condition":
  Elements."Scar or disfigurement Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Scar or disfigurement Observation":
  Elements."Scar or disfigurement Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Scar or disfigurement */

/*
@dataElement: HIV.B.DE220 - Sharps injury to personnel
@activity: HIV.B21 Offer prevention options
@description: During VMMC procedure there was sharps injury to personnel
*/
// TODO: Replace placeholder with relevant CQL logic
define "Sharps injury to personnel":
  exists "Sharps injury to personnel Condition"
    or exists "Sharps injury to personnel Observation"
define "Sharps injury to personnel Condition":
  Elements."Sharps injury to personnel Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Sharps injury to personnel Observation":
  Elements."Sharps injury to personnel Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Sharps injury to personnel */

/*
@dataElement: HIV.B.DE221 - Wound disruption
@activity: HIV.B21 Offer prevention options
@description: Client experienced wound disruption
*/
// TODO: Replace placeholder with relevant CQL logic
define "Wound disruption":
  exists "Wound disruption Condition"
    or exists "Wound disruption Observation"
define "Wound disruption Condition":
  Elements."Wound disruption Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Wound disruption Observation":
  Elements."Wound disruption Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Wound disruption */

/*
@dataElement: HIV.B.DE222 - Other
@activity: HIV.B21 Offer prevention options
@description: Client experienced other adverse VMMC event
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other B.DE222":
  exists "Other B.DE222 Condition"
    or exists "Other B.DE222 Observation"
define "Other B.DE222 Condition":
  Elements."Other B.DE222 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other B.DE222 Observation":
  Elements."Other B.DE222 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other B.DE222 */

/*
@dataElement: HIV.B.DE225 - At elevated risk for HIV acquisition
@activity: HIV.B6 Capture or update client history
@description: Client is at elevated risk for HIV acquisition
*/

define "At elevated risk for HIV acquisition B.DE225":
  exists(Elements."At elevated risk for HIV acquisition B.DE225" C
    where C.prevalenceInterval() overlaps "Measurement Period")
/* End of At elevated risk for HIV acquisition B.DE225 */

/*
@dataElement: HIV.B.DE226 - Syndrome/STI diagnosed
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Syndrome or STI for which client is diagnosed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syndrome/STI diagnosed B.DE226":
  exists "Syndrome/STI diagnosed B.DE226 Observation"
define "Syndrome/STI diagnosed B.DE226 Observation":
  Elements."Syndrome/STI diagnosed B.DE226 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Syndrome/STI diagnosed B.DE226 */

/*
@dataElement: HIV.B.DE227 - Urethral discharge syndrome
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Client diagnosed with urethral discharge syndrome
*/
// TODO: Replace placeholder with relevant CQL logic
define "Urethral discharge syndrome B.DE227":
  exists "Urethral discharge syndrome B.DE227 Condition"
    or exists "Urethral discharge syndrome B.DE227 Observation"
define "Urethral discharge syndrome B.DE227 Condition":
  Elements."Urethral discharge syndrome B.DE227 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Urethral discharge syndrome B.DE227 Observation":
  Elements."Urethral discharge syndrome B.DE227 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Urethral discharge syndrome B.DE227 */

/*
@dataElement: HIV.B.DE228 - Vaginal discharge syndrome
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Client diagnosed with vaginal discharge syndrome
*/
// TODO: Replace placeholder with relevant CQL logic
define "Vaginal discharge syndrome B.DE228":
  exists "Vaginal discharge syndrome B.DE228 Condition"
    or exists "Vaginal discharge syndrome B.DE228 Observation"
define "Vaginal discharge syndrome B.DE228 Condition":
  Elements."Vaginal discharge syndrome B.DE228 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Vaginal discharge syndrome B.DE228 Observation":
  Elements."Vaginal discharge syndrome B.DE228 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Vaginal discharge syndrome B.DE228 */

/*
@dataElement: HIV.B.DE229 - Lower Abdominal pain 
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Client diagnosed with lower abdominal pain
*/
// TODO: Replace placeholder with relevant CQL logic
define "Lower Abdominal pain  B.DE229":
  exists "Lower Abdominal pain  B.DE229 Condition"
    or exists "Lower Abdominal pain  B.DE229 Observation"
define "Lower Abdominal pain  B.DE229 Condition":
  Elements."Lower Abdominal pain  B.DE229 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Lower Abdominal pain  B.DE229 Observation":
  Elements."Lower Abdominal pain  B.DE229 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Lower Abdominal pain  B.DE229 */

/*
@dataElement: HIV.B.DE230 - Genital ulcer disease syndrome
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Client diagnosed with genital ulcer disease syndrome
*/
// TODO: Replace placeholder with relevant CQL logic
define "Genital ulcer disease syndrome B.DE230":
  exists "Genital ulcer disease syndrome B.DE230 Condition"
    or exists "Genital ulcer disease syndrome B.DE230 Observation"
define "Genital ulcer disease syndrome B.DE230 Condition":
  Elements."Genital ulcer disease syndrome B.DE230 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Genital ulcer disease syndrome B.DE230 Observation":
  Elements."Genital ulcer disease syndrome B.DE230 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Genital ulcer disease syndrome B.DE230 */

/*
@dataElement: HIV.B.DE231 - Anorectal discharge
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Client diagnosed with anorectal discharge
*/
// TODO: Replace placeholder with relevant CQL logic
define "Anorectal discharge B.DE231":
  exists "Anorectal discharge B.DE231 Condition"
    or exists "Anorectal discharge B.DE231 Observation"
define "Anorectal discharge B.DE231 Condition":
  Elements."Anorectal discharge B.DE231 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Anorectal discharge B.DE231 Observation":
  Elements."Anorectal discharge B.DE231 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Anorectal discharge B.DE231 */

/*
@dataElement: HIV.B.DE232 - Sent for testing
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Specimen sent for testing
*/
// TODO: Replace placeholder with relevant CQL logic
define "Sent for testing B.DE232":
  exists "Sent for testing B.DE232 Condition"
    or exists "Sent for testing B.DE232 Observation"
define "Sent for testing B.DE232 Condition":
  Elements."Sent for testing B.DE232 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Sent for testing B.DE232 Observation":
  Elements."Sent for testing B.DE232 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Sent for testing B.DE232 */

/*
@dataElement: HIV.B.DE233 - Other
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Other syndrome/STI diagnosed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other B.DE233":
  exists "Other B.DE233 Condition"
    or exists "Other B.DE233 Observation"
define "Other B.DE233 Condition":
  Elements."Other B.DE233 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other B.DE233 Observation":
  Elements."Other B.DE233 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other B.DE233 */

/*
@dataElement: HIV.B.DE235 - Any STI syndrome diagnosed
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Was the client diagnosed with any of the five STI syndromes during this visit?
*/
// TODO: Replace placeholder with relevant CQL logic
define "Any STI syndrome diagnosed B.DE235":
  exists "Any STI syndrome diagnosed B.DE235 Observation"
define "Any STI syndrome diagnosed B.DE235 Observation":
  Elements."Any STI syndrome diagnosed B.DE235 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Any STI syndrome diagnosed B.DE235 */

/*
@dataElement: HIV.B.DE249 - Syphilis test date
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Date of syphilis test
*/

define "Syphilis test date B.DE249":
  exists(Elements."Syphilis test date B.DE249" P
    where P.performed.toInterval() during "Measurement Period")
/* End of Syphilis test date B.DE249 */

/*
@dataElement: HIV.B.DE250 - Syphilis test result
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Result from syphilis test
*/

define "Syphilis test result B.DE250":
  exists(Elements."Syphilis test result B.DE250" O
    where O.effective.toInterval() during "Measurement Period")
/* End of Syphilis test result B.DE250 */

/*
@dataElement: HIV.B.DE251 - Positive
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Test result is positive for syphilis
*/

define "Positive B.DE251":
  exists Elements."Positive B.DE251" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive B.DE251 */

/*
@dataElement: HIV.B.DE252 - Negative
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Test result is negative for syphilis
*/

define "Negative B.DE252":
  exists Elements."Negative B.DE252" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative B.DE252 */

/*
@dataElement: HIV.B.DE253 - Inconclusive
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Test result is inconclusive
*/

define "Inconclusive B.DE253":
  exists Elements."Inconclusive B.DE253" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Inconclusive B.DE253 */

/*
@dataElement: HIV.B.DE254 - Syphilis treatment start date
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Date of initiation of syphilis treatment
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syphilis treatment start date B.DE254":
  Elements."Syphilis treatment start date B.DE254" O
    where O.effective.toInterval() during "Measurement Period"
define "Syphilis treatment start date B.DE254 Value":
  "Syphilis treatment start date B.DE254" O
  return O.value
/* End of Syphilis treatment start date B.DE254 */

/*
@dataElement: HIV.B.DE255 - Gonorrhoea test date
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Date of Gonorrhoea test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gonorrhoea test date B.DE255":
  Elements."Gonorrhoea test date B.DE255" O
    where O.effective.toInterval() during "Measurement Period"
define "Gonorrhoea test date B.DE255 Value":
  "Gonorrhoea test date B.DE255" O
  return O.value
/* End of Gonorrhoea test date B.DE255 */

/*
@dataElement: HIV.B.DE256 - Gonorrhoea test result
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Result from Gonorrhoea test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gonorrhoea test result B.DE256":
  exists "Gonorrhoea test result B.DE256 Observation"
define "Gonorrhoea test result B.DE256 Observation":
  Elements."Gonorrhoea test result B.DE256 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Gonorrhoea test result B.DE256 */

/*
@dataElement: HIV.B.DE257 - Positive
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Test result is positive for Neisseria gonorrhoeae
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive B.DE257":
  exists "Positive B.DE257 Condition"
    or exists "Positive B.DE257 Observation"
define "Positive B.DE257 Condition":
  Elements."Positive B.DE257 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive B.DE257 Observation":
  Elements."Positive B.DE257 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive B.DE257 */

/*
@dataElement: HIV.B.DE258 - Negative
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Test result is negative for Neisseria gonorrhoeae
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative B.DE258":
  exists "Negative B.DE258 Condition"
    or exists "Negative B.DE258 Observation"
define "Negative B.DE258 Condition":
  Elements."Negative B.DE258 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative B.DE258 Observation":
  Elements."Negative B.DE258 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative B.DE258 */

/*
@dataElement: HIV.B.DE259 - Inconclusive
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Test result is inconclusive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Inconclusive B.DE259":
  exists "Inconclusive B.DE259 Condition"
    or exists "Inconclusive B.DE259 Observation"
define "Inconclusive B.DE259 Condition":
  Elements."Inconclusive B.DE259 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Inconclusive B.DE259 Observation":
  Elements."Inconclusive B.DE259 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Inconclusive B.DE259 */

/*
@dataElement: HIV.B.DE260 - Gonorrhoea treatment start date
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Date of initiation of Gonorrhoea treatment
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gonorrhoea treatment start date B.DE260":
  Elements."Gonorrhoea treatment start date B.DE260" O
    where O.effective.toInterval() during "Measurement Period"
define "Gonorrhoea treatment start date B.DE260 Value":
  "Gonorrhoea treatment start date B.DE260" O
  return O.value
/* End of Gonorrhoea treatment start date B.DE260 */

/*
@dataElement: HIV.B.DE261 - Type of specimen
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Type of specimen to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Type of specimen B.DE261":
  exists "Type of specimen B.DE261 Observation"
define "Type of specimen B.DE261 Observation":
  Elements."Type of specimen B.DE261 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Type of specimen B.DE261 */

/*
@dataElement: HIV.B.DE262 - Blood
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Blood specimen to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Blood B.DE262":
  exists "Blood B.DE262 Condition"
    or exists "Blood B.DE262 Observation"
define "Blood B.DE262 Condition":
  Elements."Blood B.DE262 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Blood B.DE262 Observation":
  Elements."Blood B.DE262 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Blood B.DE262 */

/*
@dataElement: HIV.B.DE263 - Urine
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Urine specimen to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Urine B.DE263":
  exists "Urine B.DE263 Condition"
    or exists "Urine B.DE263 Observation"
define "Urine B.DE263 Condition":
  Elements."Urine B.DE263 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Urine B.DE263 Observation":
  Elements."Urine B.DE263 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Urine B.DE263 */

/*
@dataElement: HIV.B.DE264 - Cervical or vaginal swab
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Cervical or vaginal swab to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Cervical or vaginal swab B.DE264":
  exists "Cervical or vaginal swab B.DE264 Condition"
    or exists "Cervical or vaginal swab B.DE264 Observation"
define "Cervical or vaginal swab B.DE264 Condition":
  Elements."Cervical or vaginal swab B.DE264 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Cervical or vaginal swab B.DE264 Observation":
  Elements."Cervical or vaginal swab B.DE264 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Cervical or vaginal swab B.DE264 */

/*
@dataElement: HIV.B.DE265 - Urethral or penile swab
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Urethral or penile swab to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Urethral or penile swab B.DE265":
  exists "Urethral or penile swab B.DE265 Condition"
    or exists "Urethral or penile swab B.DE265 Observation"
define "Urethral or penile swab B.DE265 Condition":
  Elements."Urethral or penile swab B.DE265 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Urethral or penile swab B.DE265 Observation":
  Elements."Urethral or penile swab B.DE265 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Urethral or penile swab B.DE265 */

/*
@dataElement: HIV.B.DE266 - Rectal swab
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Rectal swab to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Rectal swab B.DE266":
  exists "Rectal swab B.DE266 Condition"
    or exists "Rectal swab B.DE266 Observation"
define "Rectal swab B.DE266 Condition":
  Elements."Rectal swab B.DE266 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Rectal swab B.DE266 Observation":
  Elements."Rectal swab B.DE266 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Rectal swab B.DE266 */

/*
@dataElement: HIV.B.DE267 - Other
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Other specimen type to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other B.DE267":
  exists "Other B.DE267 Condition"
    or exists "Other B.DE267 Observation"
define "Other B.DE267 Condition":
  Elements."Other B.DE267 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other B.DE267 Observation":
  Elements."Other B.DE267 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other B.DE267 */

/*
@dataElement: HIV.B.DE276 - Neisseria gonorrhoeae test type
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Type of diagnostic test used for Neisseria gonorrhoeae
*/
// TODO: Replace placeholder with relevant CQL logic
define "Neisseria gonorrhoeae test type B.DE276":
  exists "Neisseria gonorrhoeae test type B.DE276 Observation"
define "Neisseria gonorrhoeae test type B.DE276 Observation":
  Elements."Neisseria gonorrhoeae test type B.DE276 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Neisseria gonorrhoeae test type B.DE276 */

/*
@dataElement: HIV.B.DE277 - NAAT
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Nucleic Acid Amplification Test (NAAT) used
*/
// TODO: Replace placeholder with relevant CQL logic
define "NAAT B.DE277":
  exists "NAAT B.DE277 Condition"
    or exists "NAAT B.DE277 Observation"
define "NAAT B.DE277 Condition":
  Elements."NAAT B.DE277 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "NAAT B.DE277 Observation":
  Elements."NAAT B.DE277 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of NAAT B.DE277 */

/*
@dataElement: HIV.B.DE278 - POC Test
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Point-of-care (POC) test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "POC Test B.DE278":
  exists "POC Test B.DE278 Condition"
    or exists "POC Test B.DE278 Observation"
define "POC Test B.DE278 Condition":
  Elements."POC Test B.DE278 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "POC Test B.DE278 Observation":
  Elements."POC Test B.DE278 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of POC Test B.DE278 */

/*
@dataElement: HIV.B.DE279 - Culture
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Culture test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "Culture B.DE279":
  exists "Culture B.DE279 Condition"
    or exists "Culture B.DE279 Observation"
define "Culture B.DE279 Condition":
  Elements."Culture B.DE279 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Culture B.DE279 Observation":
  Elements."Culture B.DE279 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Culture B.DE279 */

/*
@dataElement: HIV.B.DE280 - Microscopy
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Microscopy test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "Microscopy B.DE280":
  exists "Microscopy B.DE280 Condition"
    or exists "Microscopy B.DE280 Observation"
define "Microscopy B.DE280 Condition":
  Elements."Microscopy B.DE280 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Microscopy B.DE280 Observation":
  Elements."Microscopy B.DE280 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Microscopy B.DE280 */

/*
@dataElement: HIV.B.DE281 - Other
@activity: HIV.B23 Offer sexual and reproductive health services
@description: Other type of test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other B.DE281":
  exists "Other B.DE281 Condition"
    or exists "Other B.DE281 Observation"
define "Other B.DE281 Condition":
  Elements."Other B.DE281 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other B.DE281 Observation":
  Elements."Other B.DE281 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other B.DE281 */

/*
@dataElement: HIV.C.DE11 - PrEP dosing type
@activity: HIV.C3 Capture or update client history
@description: Way in which pre-exposure prophylaxis (PrEP) is taken (daily or event-driven)
*/
// TODO: Replace placeholder with relevant CQL logic
define "PrEP dosing type":
  exists "PrEP dosing type Observation"
define "PrEP dosing type Observation":
  Elements."PrEP dosing type Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of PrEP dosing type */

/*
@dataElement: HIV.C.DE12 - Daily oral PrEP
@activity: HIV.C3 Capture or update client history
@description: Pre-exposure prophylaxis (PrEP) is taken every day
*/
// TODO: Replace placeholder with relevant CQL logic
define "Daily oral PrEP":
  exists "Daily oral PrEP Condition"
    or exists "Daily oral PrEP Observation"
define "Daily oral PrEP Condition":
  Elements."Daily oral PrEP Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Daily oral PrEP Observation":
  Elements."Daily oral PrEP Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Daily oral PrEP */

/*
@dataElement: HIV.C.DE13 - Event-driven PrEP 2+1+1
@activity: HIV.C3 Capture or update client history
@description: Event-driven pre-exposure prophylaxis (PrEP) is taken on an even-driven basis (2+1+1)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Event-driven PrEP 2+1+1":
  exists "Event-driven PrEP 2+1+1 Condition"
    or exists "Event-driven PrEP 2+1+1 Observation"
define "Event-driven PrEP 2+1+1 Condition":
  Elements."Event-driven PrEP 2+1+1 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Event-driven PrEP 2+1+1 Observation":
  Elements."Event-driven PrEP 2+1+1 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Event-driven PrEP 2+1+1 */

/*
@dataElement: HIV.C.DE14 - Other PrEP dosing type
@activity: HIV.C3 Capture or update client history
@description: Other PrEP dosing type
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other PrEP dosing type":
  exists "Other PrEP dosing type Condition"
    or exists "Other PrEP dosing type Observation"
define "Other PrEP dosing type Condition":
  Elements."Other PrEP dosing type Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other PrEP dosing type Observation":
  Elements."Other PrEP dosing type Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other PrEP dosing type */

/*
@dataElement: HIV.C.DE24 - Experience with PrEP
@activity: HIV.C3 Capture or update client history
@description: The client's experience in taking PrEP
*/
// TODO: Replace placeholder with relevant CQL logic
define "Experience with PrEP":
  exists "Experience with PrEP Observation"
define "Experience with PrEP Observation":
  Elements."Experience with PrEP Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Experience with PrEP */

/*
@dataElement: HIV.C.DE25 - First-time user
@activity: HIV.C3 Capture or update client history
@description: The client has never used pre-exposure prophylaxis (PrEP) before (naive)
*/
// TODO: Replace placeholder with relevant CQL logic
define "First-time user C.DE25":
  exists "First-time user C.DE25 Condition"
    or exists "First-time user C.DE25 Observation"
define "First-time user C.DE25 Condition":
  Elements."First-time user C.DE25 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "First-time user C.DE25 Observation":
  Elements."First-time user C.DE25 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of First-time user C.DE25 */

/*
@dataElement: HIV.C.DE26 - Continuing user
@activity: HIV.C3 Capture or update client history
@description: The client has used PrEP before and is continuing to use PrEP
*/
// TODO: Replace placeholder with relevant CQL logic
define "Continuing user":
  exists "Continuing user Condition"
    or exists "Continuing user Observation"
define "Continuing user Condition":
  Elements."Continuing user Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Continuing user Observation":
  Elements."Continuing user Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Continuing user */

/*
@dataElement: HIV.C.DE27 - Restarting following a period of not taking PrEP
@activity: HIV.C3 Capture or update client history
@description: The client is restarting PrEP following a period of not taking PrEP
*/
// TODO: Replace placeholder with relevant CQL logic
define "Restarting following a period of not taking PrEP":
  exists "Restarting following a period of not taking PrEP Condition"
    or exists "Restarting following a period of not taking PrEP Observation"
define "Restarting following a period of not taking PrEP Condition":
  Elements."Restarting following a period of not taking PrEP Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Restarting following a period of not taking PrEP Observation":
  Elements."Restarting following a period of not taking PrEP Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Restarting following a period of not taking PrEP */

/*
@dataElement: HIV.C.DE35 - Date client completes PEP course
@activity: HIV.C3 Capture or update client history
@description: Date client completes PEP course
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date client completes PEP course":
  Elements."Date client completes PEP course" O
    where O.effective.toInterval() during "Measurement Period"
define "Date client completes PEP course Value":
  "Date client completes PEP course" O
  return O.value
/* End of Date client completes PEP course */

/*
@dataElement: HIV.C.DE74 - Date medications prescribed
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Date the client was prescribed medications
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date medications prescribed C.DE74":
  Elements."Date medications prescribed C.DE74" O
    where O.effective.toInterval() during "Measurement Period"
define "Date medications prescribed C.DE74 Value":
  "Date medications prescribed C.DE74" O
  return O.value
/* End of Date medications prescribed C.DE74 */

/*
@dataElement: HIV.C.DE75 - Medications prescribed
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Medications the client was prescribed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Medications prescribed C.DE75":
  exists "Medications prescribed C.DE75 Observation"
define "Medications prescribed C.DE75 Observation":
  Elements."Medications prescribed C.DE75 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Medications prescribed C.DE75 */

/*
@dataElement: HIV.C.DE76 - PrEP for HIV prevention
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed pre-exposure prophylaxis (PrEP) for HIV prevention
*/
define "HIV PREP Active":
   exists(Elements."HIV PREP Active" H
   where H.effective starts before end of "Measurement Period"
    and (H.effective ends after start of "Measurement Period"
    or end of H.effective  ~  null)
   )
// TODO: Replace placeholder with relevant CQL logic
define "PrEP for HIV prevention":
  exists "PrEP for HIV prevention Condition"
    or exists "PrEP for HIV prevention Observation"
define "PrEP for HIV prevention Condition":
  Elements."PrEP for HIV prevention Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "PrEP for HIV prevention Observation":
  Elements."PrEP for HIV prevention Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of PrEP for HIV prevention */

/*
@dataElement: HIV.C.DE77 - PEP for HIV prevention
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed post-exposure prophylaxis (PEP) for HIV prevention
*/
// TODO: Replace placeholder with relevant CQL logic
define "PEP for HIV prevention":
  exists "PEP for HIV prevention Condition"
    or exists "PEP for HIV prevention Observation"
define "PEP for HIV prevention Condition":
  Elements."PEP for HIV prevention Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "PEP for HIV prevention Observation":
  Elements."PEP for HIV prevention Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of PEP for HIV prevention */

/*
@dataElement: HIV.C.DE78 - Other
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed other medications
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other C.DE78":
  exists "Other C.DE78 Condition"
    or exists "Other C.DE78 Observation"
define "Other C.DE78 Condition":
  Elements."Other C.DE78 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other C.DE78 Observation":
  Elements."Other C.DE78 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other C.DE78 */

/*
@dataElement: HIV.C.DE80 - PrEP product prescribed
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: PrEP product that the client was prescribed
*/
// TODO: Replace placeholder with relevant CQL logic
define "PrEP product prescribed":
  exists "PrEP product prescribed Observation"
define "PrEP product prescribed Observation":
  Elements."PrEP product prescribed Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of PrEP product prescribed */

/*
@dataElement: HIV.C.DE81 - Oral PrEP
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed oral PrEP
*/
// TODO: Replace placeholder with relevant CQL logic
define "Oral PrEP":
  exists "Oral PrEP Condition"
    or exists "Oral PrEP Observation"
define "Oral PrEP Condition":
  Elements."Oral PrEP Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Oral PrEP Observation":
  Elements."Oral PrEP Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Oral PrEP */

/*
@dataElement: HIV.C.DE82 - Dapivirine vaginal ring DVR
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed dapivirine vaginal ring (DVR)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Dapivirine vaginal ring DVR C.DE82":
  exists "Dapivirine vaginal ring DVR C.DE82 Condition"
    or exists "Dapivirine vaginal ring DVR C.DE82 Observation"
define "Dapivirine vaginal ring DVR C.DE82 Condition":
  Elements."Dapivirine vaginal ring DVR C.DE82 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Dapivirine vaginal ring DVR C.DE82 Observation":
  Elements."Dapivirine vaginal ring DVR C.DE82 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Dapivirine vaginal ring DVR C.DE82 */

/*
@dataElement: HIV.C.DE83 - CAB-LA
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed long-acting cabotegravir (CAB-LA)
*/
// TODO: Replace placeholder with relevant CQL logic
define "CAB-LA C.DE83":
  exists "CAB-LA C.DE83 Condition"
    or exists "CAB-LA C.DE83 Observation"
define "CAB-LA C.DE83 Condition":
  Elements."CAB-LA C.DE83 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "CAB-LA C.DE83 Observation":
  Elements."CAB-LA C.DE83 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of CAB-LA C.DE83 */

/*
@dataElement: HIV.C.DE84 - Other
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Client was prescribed other PrEP product
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other C.DE84":
  exists "Other C.DE84 Condition"
    or exists "Other C.DE84 Observation"
define "Other C.DE84 Condition":
  Elements."Other C.DE84 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other C.DE84 Observation":
  Elements."Other C.DE84 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other C.DE84 */

/*
@dataElement: HIV.C.DE121 - Number of days prescribed
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Days of medication client has been prescribed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Number of days prescribed C.DE121":
  Elements."Number of days prescribed C.DE121" O
    where O.effective.toInterval() during "Measurement Period"
define "Number of days prescribed C.DE121 Value":
  "Number of days prescribed C.DE121" O
  return O.value
/* End of Number of days prescribed C.DE121 */

/*
@dataElement: HIV.C.DE138 - Condom type
@activity: HIV.C10 Counsel on risk and prevention
@description: Type of condom provided to client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Condom type":
  exists "Condom type Observation"
define "Condom type Observation":
  Elements."Condom type Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Condom type */

/*
@dataElement: HIV.C.DE139 - Male condom
@activity: HIV.C10 Counsel on risk and prevention
@description: Male condoms were provided to the client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Male condom":
  exists "Male condom Condition"
    or exists "Male condom Observation"
define "Male condom Condition":
  Elements."Male condom Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Male condom Observation":
  Elements."Male condom Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Male condom */

/*
@dataElement: HIV.C.DE140 - Female condom
@activity: HIV.C10 Counsel on risk and prevention
@description: Female condoms were provided to the client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Female condom":
  exists "Female condom Condition"
    or exists "Female condom Observation"
define "Female condom Condition":
  Elements."Female condom Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Female condom Observation":
  Elements."Female condom Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Female condom */

/*
@dataElement: HIV.C.DE142 - Number of HIV self-test kits distributed
@activity: HIV.C10 Counsel on risk and prevention
@description: Number of HIV self-test kits distributed to the client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Number of HIV self-test kits distributed":
  Elements."Number of HIV self-test kits distributed" O
    where O.effective.toInterval() during "Measurement Period"
define "Number of HIV self-test kits distributed Value":
  "Number of HIV self-test kits distributed" O
  return O.value
/* End of Number of HIV self-test kits distributed */

/*
@dataElement: HIV.C.DE143 - HIV self-test distributed for use by
@activity: HIV.C10 Counsel on risk and prevention
@description: Whom the client plans to give the HIV self-test kit (self, sexual partner, social contact, etc.)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV self-test distributed for use by":
  exists "HIV self-test distributed for use by Observation"
define "HIV self-test distributed for use by Observation":
  Elements."HIV self-test distributed for use by Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV self-test distributed for use by */

/*
@dataElement: HIV.C.DE144 - Self
@activity: HIV.C10 Counsel on risk and prevention
@description: Client plans to use the self-test kit
*/
// TODO: Replace placeholder with relevant CQL logic
define "Self":
  exists "Self Condition"
    or exists "Self Observation"
define "Self Condition":
  Elements."Self Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Self Observation":
  Elements."Self Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Self */

/*
@dataElement: HIV.C.DE145 - Family member
@activity: HIV.C10 Counsel on risk and prevention
@description: Client plans to give the self-test kit to a family member to use
*/
// TODO: Replace placeholder with relevant CQL logic
define "Family member":
  exists "Family member Condition"
    or exists "Family member Observation"
define "Family member Condition":
  Elements."Family member Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Family member Observation":
  Elements."Family member Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Family member */

/*
@dataElement: HIV.C.DE146 - Drug-injecting partner
@activity: HIV.C10 Counsel on risk and prevention
@description: Client plans to give the self-test kit to a drug-injecting partner
*/
// TODO: Replace placeholder with relevant CQL logic
define "Drug-injecting partner C.DE146":
  exists "Drug-injecting partner C.DE146 Condition"
    or exists "Drug-injecting partner C.DE146 Observation"
define "Drug-injecting partner C.DE146 Condition":
  Elements."Drug-injecting partner C.DE146 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Drug-injecting partner C.DE146 Observation":
  Elements."Drug-injecting partner C.DE146 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Drug-injecting partner C.DE146 */

/*
@dataElement: HIV.C.DE147 - Sexual partner
@activity: HIV.C10 Counsel on risk and prevention
@description: Client plans to give the self-test kit to a sexual partner
*/
// TODO: Replace placeholder with relevant CQL logic
define "Sexual partner C.DE147":
  exists "Sexual partner C.DE147 Condition"
    or exists "Sexual partner C.DE147 Observation"
define "Sexual partner C.DE147 Condition":
  Elements."Sexual partner C.DE147 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Sexual partner C.DE147 Observation":
  Elements."Sexual partner C.DE147 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Sexual partner C.DE147 */

/*
@dataElement: HIV.C.DE148 - Social contact
@activity: HIV.C10 Counsel on risk and prevention
@description: Client plans to give the self-test kit to a social contact
*/
// TODO: Replace placeholder with relevant CQL logic
define "Social contact C.DE148":
  exists "Social contact C.DE148 Condition"
    or exists "Social contact C.DE148 Observation"
define "Social contact C.DE148 Condition":
  Elements."Social contact C.DE148 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Social contact C.DE148 Observation":
  Elements."Social contact C.DE148 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Social contact C.DE148 */

/*
@dataElement: HIV.D.DE31 - Currently pregnant
@activity: HIV.D8 Capture or update client history
@description: Client is currently pregnant
*/
// TODO: Replace placeholder with relevant CQL logic
define "Currently pregnant D.DE31":
  exists "Currently pregnant D.DE31 Observation"
define "Currently pregnant D.DE31 Observation":
  Elements."Currently pregnant D.DE31 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Currently pregnant D.DE31 */

/*
@dataElement: HIV.D.DE32 - Breastfeeding
@activity: HIV.D8 Capture or update client history
@description: Client is giving infant breast milk
*/
// TODO: Replace placeholder with relevant CQL logic
define "Breastfeeding D.DE32":
  exists "Breastfeeding D.DE32 Observation"
define "Breastfeeding D.DE32 Observation":
  Elements."Breastfeeding D.DE32 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Breastfeeding D.DE32 */

/*
@dataElement: HIV.D.DE38 - On ART
@activity: HIV.D8 Capture or update client history
@description: Client is currently taking ART
*/

define "On ART D.DE38":
  exists(Elements."On ART D.DE38" ART
   where ART.effective.toInterval() starts before end of "Measurement Period"
    and (ART.effective.toInterval() ends after start of "Measurement Period")
   )
/* End of On ART D.DE38 */

/*
@dataElement: HIV.D.DE39 - ART start date
@activity: HIV.D8 Capture or update client history
@description: The date on which the client started or restarted ART
*/
/* End of ART start date D.DE39 */
define "ART start date within measurement period":
  Elements."ART start date D.DE39" d
    where d during "Measurement Period"
/*
@dataElement: HIV.D.DE41 - Date ART stopped
@activity: HIV.D8 Capture or update client history
@description: Date on which client stopped ART
*/
define "ART stopped during measurement period":
  Elements."Date ART stopped D.DE41" d
    where d during "Measurement Period"
/* End of Date ART stopped D.DE41 */

/*
@dataElement: HIV.D.DE43 - ART start type
@activity: HIV.D8 Capture or update client history
@description: Whether the client is ART naive or is restarting ART
*/

define "ART start type":
  exists Elements."ART start type"

/* End of ART start type */

/*
@dataElement: HIV.D.DE44 - First-time user of ART
@activity: HIV.D8 Capture or update client history
@description: Client is ART naive, having never taken ART to treat HIV before
*/

define "First-time user of ART":
  exists Elements."First-time user of ART" O
    where O.effective.toInterval() during "Measurement Period"
/* End of First-time user of ART */

/*
@dataElement: HIV.D.DE45 - Restarting ART
@activity: HIV.D8 Capture or update client history
@description: Client is restarting ART after stopping treatment for any reason
*/

define "Restarting ART":
  exists Elements."Restarting ART" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Restarting ART */

/*
@dataElement: HIV.D.DE75 - Current ART regimen
@activity: HIV.D8 Capture or update client history
@description: The current ART regimen the client is taking
*/
// TODO: Replace placeholder with relevant CQL logic
define "Current ART regimen":
  exists "Current ART regimen Observation"
define "Current ART regimen Observation":
  Elements."Current ART regimen Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Current ART regimen */

/*
@dataElement: HIV.D.DE161 - HBsAg test date
@activity: HIV.D12 Determine recommended screenings and tests
@description: Date client was tested for hepatitis B virus (HBV)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HBsAg test date D.DE161":
  Elements."HBsAg test date D.DE161" O
    where O.effective.toInterval() during "Measurement Period"
define "HBsAg test date D.DE161 Value":
  "HBsAg test date D.DE161" O
  return O.value
/* End of HBsAg test date D.DE161 */

/*
@dataElement: HIV.D.DE162 - HBsAg test result
@activity: HIV.D12 Determine recommended screenings and tests
@description: Hepatitis B virus test result (HBsAg)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HBsAg test result D.DE162":
  exists "HBsAg test result D.DE162 Observation"
define "HBsAg test result D.DE162 Observation":
  Elements."HBsAg test result D.DE162 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HBsAg test result D.DE162 */

/*
@dataElement: HIV.D.DE163 - Positive
@activity: HIV.D12 Determine recommended screenings and tests
@description: HBsAg test result was positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive D.DE163":
  exists "Positive D.DE163 Condition"
    or exists "Positive D.DE163 Observation"
define "Positive D.DE163 Condition":
  Elements."Positive D.DE163 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive D.DE163 Observation":
  Elements."Positive D.DE163 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive D.DE163 */

/*
@dataElement: HIV.D.DE164 - Negative
@activity: HIV.D12 Determine recommended screenings and tests
@description: HBsAg test result was negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative D.DE164":
  exists "Negative D.DE164 Condition"
    or exists "Negative D.DE164 Observation"
define "Negative D.DE164 Condition":
  Elements."Negative D.DE164 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative D.DE164 Observation":
  Elements."Negative D.DE164 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative D.DE164 */

/*
@dataElement: HIV.D.DE165 - Indeterminate
@activity: HIV.D12 Determine recommended screenings and tests
@description: HBsAg test result was indeterminate
*/
// TODO: Replace placeholder with relevant CQL logic
define "Indeterminate D.DE165":
  exists "Indeterminate D.DE165 Condition"
    or exists "Indeterminate D.DE165 Observation"
define "Indeterminate D.DE165 Condition":
  Elements."Indeterminate D.DE165 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Indeterminate D.DE165 Observation":
  Elements."Indeterminate D.DE165 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Indeterminate D.DE165 */

/*
@dataElement: HIV.D.DE167 - HBV treatment TDF start date
@activity: HIV.D12 Determine recommended screenings and tests
@description: Date when client started treatment (TDF) for hepatitis B virus (HBV)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HBV treatment TDF start date":
  Elements."HBV treatment TDF start date" O
    where O.effective.toInterval() during "Measurement Period"
define "HBV treatment TDF start date Value":
  "HBV treatment TDF start date" O
  return O.value
/* End of HBV treatment TDF start date */

/*
@dataElement: HIV.D.DE169 - HCV test date
@activity: HIV.D12 Determine recommended screenings and tests
@description: Date client was tested for hepatitis C virus (HCV antibody, HCV RNA or HCV core antigen)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV test date D.DE169":
  Elements."HCV test date D.DE169" O
    where O.effective.toInterval() during "Measurement Period"
define "HCV test date D.DE169 Value":
  "HCV test date D.DE169" O
  return O.value
/* End of HCV test date D.DE169 */

/*
@dataElement: HIV.D.DE170 - HCV test result
@activity: HIV.D12 Determine recommended screenings and tests
@description: Hepatitis C virus test result (HCV antibody, HCV RNA or HCV core antigen)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV test result D.DE170":
  exists "HCV test result D.DE170 Observation"
define "HCV test result D.DE170 Observation":
  Elements."HCV test result D.DE170 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HCV test result D.DE170 */

/*
@dataElement: HIV.D.DE171 - Positive
@activity: HIV.D12 Determine recommended screenings and tests
@description: HCV test result was positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive D.DE171":
  exists "Positive D.DE171 Condition"
    or exists "Positive D.DE171 Observation"
define "Positive D.DE171 Condition":
  Elements."Positive D.DE171 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive D.DE171 Observation":
  Elements."Positive D.DE171 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive D.DE171 */

/*
@dataElement: HIV.D.DE172 - Negative
@activity: HIV.D12 Determine recommended screenings and tests
@description: HCV test result was negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative D.DE172":
  exists "Negative D.DE172 Condition"
    or exists "Negative D.DE172 Observation"
define "Negative D.DE172 Condition":
  Elements."Negative D.DE172 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative D.DE172 Observation":
  Elements."Negative D.DE172 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative D.DE172 */

/*
@dataElement: HIV.D.DE173 - Indeterminate
@activity: HIV.D12 Determine recommended screenings and tests
@description: HCV test result was indeterminate
*/
// TODO: Replace placeholder with relevant CQL logic
define "Indeterminate D.DE173":
  exists "Indeterminate D.DE173 Condition"
    or exists "Indeterminate D.DE173 Observation"
define "Indeterminate D.DE173 Condition":
  Elements."Indeterminate D.DE173 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Indeterminate D.DE173 Observation":
  Elements."Indeterminate D.DE173 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Indeterminate D.DE173 */

/*
@dataElement: HIV.D.DE175 - HCV treatment start date
@activity: HIV.D12 Determine recommended screenings and tests
@description: Date when client started treatment for hepatitis C virus (HCV)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV treatment start date":
  Elements."HCV treatment start date" O
    where O.effective.toInterval() during "Measurement Period"
define "HCV treatment start date Value":
  "HCV treatment start date" O
  return O.value
/* End of HCV treatment start date */

/*
@dataElement: HIV.D.DE176 - HCV treatment completion date
@activity: HIV.D12 Determine recommended screenings and tests
@description: Date when client completed treatment for hepatitis C virus (HCV)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV treatment completion date":
  Elements."HCV treatment completion date" O
    where O.effective.toInterval() during "Measurement Period"
define "HCV treatment completion date Value":
  "HCV treatment completion date" O
  return O.value
/* End of HCV treatment completion date */

/*
@dataElement: HIV.D.DE178 - HCV viral load test date
@activity: HIV.D12 Determine recommended screenings and tests
@description: Hepatitis C viral load test date
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV viral load test date D.DE178":
  Elements."HCV viral load test date D.DE178" O
    where O.effective.toInterval() during "Measurement Period"
define "HCV viral load test date D.DE178 Value":
  "HCV viral load test date D.DE178" O
  return O.value
/* End of HCV viral load test date D.DE178 */

/*
@dataElement: HIV.D.DE179 - HCV viral load test result
@activity: HIV.D12 Determine recommended screenings and tests
@description: Hepatitis C viral load test result (qualitative)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV viral load test result D.DE179":
  exists "HCV viral load test result D.DE179 Observation"
define "HCV viral load test result D.DE179 Observation":
  Elements."HCV viral load test result D.DE179 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HCV viral load test result D.DE179 */

/*
@dataElement: HIV.D.DE180 - Detected
@activity: HIV.D12 Determine recommended screenings and tests
@description: HCV was detected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Detected D.DE180":
  exists "Detected D.DE180 Condition"
    or exists "Detected D.DE180 Observation"
define "Detected D.DE180 Condition":
  Elements."Detected D.DE180 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Detected D.DE180 Observation":
  Elements."Detected D.DE180 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Detected D.DE180 */

/*
@dataElement: HIV.D.DE181 - Not detected
@activity: HIV.D12 Determine recommended screenings and tests
@description: HCV was not detected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Not detected D.DE181":
  exists "Not detected D.DE181 Condition"
    or exists "Not detected D.DE181 Observation"
define "Not detected D.DE181 Condition":
  Elements."Not detected D.DE181 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Not detected D.DE181 Observation":
  Elements."Not detected D.DE181 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Not detected D.DE181 */

/*
@dataElement: HIV.D.DE182 - HCV medicine type
@activity: HIV.D12 Determine recommended screenings and tests
@description: Type of medicine client is prescribed
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV medicine type":
  exists "HCV medicine type Observation"
define "HCV medicine type Observation":
  Elements."HCV medicine type Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HCV medicine type */

/*
@dataElement: HIV.D.DE183 - Interferon
@activity: HIV.D12 Determine recommended screenings and tests
@description: Client is prescribed interferon
*/
// TODO: Replace placeholder with relevant CQL logic
define "Interferon":
  exists "Interferon Condition"
    or exists "Interferon Observation"
define "Interferon Condition":
  Elements."Interferon Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Interferon Observation":
  Elements."Interferon Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Interferon */

/*
@dataElement: HIV.D.DE184 - Direct acting antivirals
@activity: HIV.D12 Determine recommended screenings and tests
@description: Client is prescribed direct acting antivirals
*/
// TODO: Replace placeholder with relevant CQL logic
define "Direct acting antivirals":
  exists "Direct acting antivirals Condition"
    or exists "Direct acting antivirals Observation"
define "Direct acting antivirals Condition":
  Elements."Direct acting antivirals Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Direct acting antivirals Observation":
  Elements."Direct acting antivirals Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Direct acting antivirals */

/*
@dataElement: HIV.D.DE185 - Currently on TDF-based ART
@activity: HIV.D12 Determine recommended screenings and tests
@description: Client is currently on TDF-based ART regimen
*/
// TODO: Replace placeholder with relevant CQL logic
define "Currently on TDF-based ART":
  exists "Currently on TDF-based ART Observation"
define "Currently on TDF-based ART Observation":
  Elements."Currently on TDF-based ART Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Currently on TDF-based ART */

/*
@dataElement: HIV.D.DE193 - Date viral load test results received by client
@activity: HIV.D10 Counsel returning client
@description: The date on which the client received results from viral load test
*/

define "Date viral load test results received by client D.DE193":
  Elements."Date viral load test results received by client D.DE193" O
    where O.issued.toInterval() during "Measurement Period"

/* End of Date viral load test results received by client D.DE193 */

/*
@dataElement: HIV.D.DE194 - Date of viral load sample collection
@activity: HIV.D10 Counsel returning client
@description: Date and time when the sample was collected to test the client's HIV viral load
*/

define "Date of viral load sample collection D.DE194":
  exists(Elements."Date of viral load sample collection D.DE194" P
  where P.performed.toInterval() during "Measurement Period")
/* End of Date of viral load sample collection D.DE194 */

/*
@dataElement: HIV.D.DE217 - Reason ART stopped
@activity: HIV.D10 Counsel returning client
@description: Reason client intentionally stopped ART
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reason ART stopped D.DE217":
  exists "Reason ART stopped D.DE217 Observation"
define "Reason ART stopped D.DE217 Observation":
  Elements."Reason ART stopped D.DE217 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Reason ART stopped D.DE217 */

/*
@dataElement: HIV.D.DE218 - Toxicity/side effects
@activity: HIV.D10 Counsel returning client
@description: Client stopped ART because of toxicity/side effects
*/
// TODO: Replace placeholder with relevant CQL logic
define "Toxicity/side effects D.DE218":
  exists "Toxicity/side effects D.DE218 Condition"
    or exists "Toxicity/side effects D.DE218 Observation"
define "Toxicity/side effects D.DE218 Condition":
  Elements."Toxicity/side effects D.DE218 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Toxicity/side effects D.DE218 Observation":
  Elements."Toxicity/side effects D.DE218 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Toxicity/side effects D.DE218 */

/*
@dataElement: HIV.D.DE219 - Severe illness, hospitalization
@activity: HIV.D10 Counsel returning client
@description: Client stopped ART because of severe illness, hospitalization
*/
// TODO: Replace placeholder with relevant CQL logic
define "Severe illness, hospitalization D.DE219":
  exists "Severe illness, hospitalization D.DE219 Condition"
    or exists "Severe illness, hospitalization D.DE219 Observation"
define "Severe illness, hospitalization D.DE219 Condition":
  Elements."Severe illness, hospitalization D.DE219 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Severe illness, hospitalization D.DE219 Observation":
  Elements."Severe illness, hospitalization D.DE219 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Severe illness, hospitalization D.DE219 */

/*
@dataElement: HIV.D.DE220 - Drugs out of stock
@activity: HIV.D10 Counsel returning client
@description: Client stopped ART because drugs were out of stock
*/
// TODO: Replace placeholder with relevant CQL logic
define "Drugs out of stock":
  exists "Drugs out of stock Condition"
    or exists "Drugs out of stock Observation"
define "Drugs out of stock Condition":
  Elements."Drugs out of stock Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Drugs out of stock Observation":
  Elements."Drugs out of stock Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Drugs out of stock */

/*
@dataElement: HIV.D.DE221 - Client lacks finances
@activity: HIV.D10 Counsel returning client
@description: Client stopped ART because of lack of finances
*/
// TODO: Replace placeholder with relevant CQL logic
define "Client lacks finances":
  exists "Client lacks finances Condition"
    or exists "Client lacks finances Observation"
define "Client lacks finances Condition":
  Elements."Client lacks finances Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Client lacks finances Observation":
  Elements."Client lacks finances Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Client lacks finances */

/*
@dataElement: HIV.D.DE222 - Excluded HIV infection in infant
@activity: HIV.D10 Counsel returning client
@description: Client stopped ART because HIV infection in infant was excluded
*/
// TODO: Replace placeholder with relevant CQL logic
define "Excluded HIV infection in infant D.DE222":
  exists "Excluded HIV infection in infant D.DE222 Condition"
    or exists "Excluded HIV infection in infant D.DE222 Observation"
define "Excluded HIV infection in infant D.DE222 Condition":
  Elements."Excluded HIV infection in infant D.DE222 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Excluded HIV infection in infant D.DE222 Observation":
  Elements."Excluded HIV infection in infant D.DE222 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Excluded HIV infection in infant D.DE222 */

/*
@dataElement: HIV.D.DE223 - Other reason for stopping ART
@activity: HIV.D10 Counsel returning client
@description: Client stopped ART because of other reason
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other reason for stopping ART D.DE223":
  exists "Other reason for stopping ART D.DE223 Condition"
    or exists "Other reason for stopping ART D.DE223 Observation"
define "Other reason for stopping ART D.DE223 Condition":
  Elements."Other reason for stopping ART D.DE223 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other reason for stopping ART D.DE223 Observation":
  Elements."Other reason for stopping ART D.DE223 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other reason for stopping ART D.DE223 */

/*
@dataElement: HIV.D.DE259 - Risk factors, comorbidities and coinfections signs and symptoms
@activity: HIV.D14 Prevent, screen, and manage comorbidities and coinfections
@description: Signs and symptoms of opportunistic infections or other comorbidities experienced by client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Risk factors, comorbidities and coinfections signs and symptoms":
  exists "Risk factors, comorbidities and coinfections signs and symptoms Observation"
define "Risk factors, comorbidities and coinfections signs and symptoms Observation":
  Elements."Risk factors, comorbidities and coinfections signs and symptoms Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Risk factors, comorbidities and coinfections signs and symptoms */

/*
@dataElement: HIV.D.DE282 - Presumptive TB
@activity: HIV.D14 Prevent, screen, and manage comorbidities and coinfections
@description: Client's comorbidities or coinfections or symptoms of these include presumptive TB
*/
// TODO: Replace placeholder with relevant CQL logic
define "Presumptive TB D.DE282":
  exists "Presumptive TB D.DE282 Condition"
    or exists "Presumptive TB D.DE282 Observation"
define "Presumptive TB D.DE282 Condition":
  Elements."Presumptive TB D.DE282 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Presumptive TB D.DE282 Observation":
  Elements."Presumptive TB D.DE282 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Presumptive TB D.DE282 */

/*
@dataElement: HIV.D.DE367 - Baseline CD4 count
@activity: HIV.D20 Diagnostics
@description: CD4 count performed at HIV diagnosis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Baseline CD4 count D.DE367":
  Elements."Baseline CD4 count D.DE367" O
    where O.effective.toInterval() during "Measurement Period"
define "Baseline CD4 count D.DE367 Value":
  "Baseline CD4 count D.DE367" O
  return O.value
/* End of Baseline CD4 count D.DE367 */

/*
@dataElement: HIV.D.DE368 - Date of baseline CD4 count test
@activity: HIV.D20 Diagnostics
@description: Date and time when baseline CD4 count test was conducted
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of baseline CD4 count test D.DE368":
  Elements."Date of baseline CD4 count test D.DE368" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of baseline CD4 count test D.DE368 Value":
  "Date of baseline CD4 count test D.DE368" O
  return O.value
/* End of Date of baseline CD4 count test D.DE368 */

/*
@dataElement: HIV.D.DE387 - Viral load test result
@activity: HIV.D20 Diagnostics
@description: Result from the viral load test in number of copies/mL
*/

define "Viral load test result D.DE387":
  Elements."Viral load test result D.DE387" O
    where O.effective.toInterval() during "Measurement Period"
define "Viral load test result D.DE387 Value":
  "Viral load test result D.DE387" O
  return O.value
/* End of Viral load test result D.DE387 */

/*
@dataElement: HIV.D.DE391 - Reason for HIV viral load test
@activity: HIV.D20 Diagnostics
@description: Whether the viral load is being tested for routine monitoring on a set schedule or for targeted monitoring for suspected treatment failure
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reason for HIV viral load test":
  exists "Reason for HIV viral load test Observation"
define "Reason for HIV viral load test Observation":
  Elements."Reason for HIV viral load test Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Reason for HIV viral load test */

/*
@dataElement: HIV.D.DE392 - Routine viral load test
@activity: HIV.D20 Diagnostics
@description: Routine refers to viral load tests obtained at standard intervals following ART initiation to monitor viral load response to ART
*/
// TODO: Replace placeholder with relevant CQL logic
define "Routine viral load test":
  exists "Routine viral load test Condition"
    or exists "Routine viral load test Observation"
define "Routine viral load test Condition":
  Elements."Routine viral load test Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Routine viral load test Observation":
  Elements."Routine viral load test Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Routine viral load test */

/*
@dataElement: HIV.D.DE393 - Targeted viral load monitoring
@activity: HIV.D20 Diagnostics
@description: Targeted refers to viral load tests obtained based on a specific clinical indication (such as concern about disease progression or failure to respond to ART)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Targeted viral load monitoring":
  exists "Targeted viral load monitoring Condition"
    or exists "Targeted viral load monitoring Observation"
define "Targeted viral load monitoring Condition":
  Elements."Targeted viral load monitoring Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Targeted viral load monitoring Observation":
  Elements."Targeted viral load monitoring Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Targeted viral load monitoring */

/*
@dataElement: HIV.D.DE394 - Initial viral load test
@activity: HIV.D20 Diagnostics
@description: The first viral load test of the client
*/
// TODO: Replace placeholder with relevant CQL logic
define "Initial viral load test":
  exists "Initial viral load test Condition"
    or exists "Initial viral load test Observation"
define "Initial viral load test Condition":
  Elements."Initial viral load test Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Initial viral load test Observation":
  Elements."Initial viral load test Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Initial viral load test */

/*
@dataElement: HIV.D.DE395 - Follow-up viral load test after receiving enhanced adherence counselling
@activity: HIV.D20 Diagnostics
@description: A follow-up viral load test within 3-6 months after enhanced adherence counselling after client received a high viral load test result
*/
// TODO: Replace placeholder with relevant CQL logic
define "Follow-up viral load test after receiving enhanced adherence counselling":
  exists "Follow-up viral load test after receiving enhanced adherence counselling Condition"
    or exists "Follow-up viral load test after receiving enhanced adherence counselling Observation"
define "Follow-up viral load test after receiving enhanced adherence counselling Condition":
  Elements."Follow-up viral load test after receiving enhanced adherence counselling Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Follow-up viral load test after receiving enhanced adherence counselling Observation":
  Elements."Follow-up viral load test after receiving enhanced adherence counselling Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Follow-up viral load test after receiving enhanced adherence counselling */

/*
@dataElement: HIV.D.DE417 - Date viral load test results received by client
@activity: HIV.D20 Diagnostics
@description: The date on which the client received results from a viral load test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date viral load test results received by client D.DE417":
  Elements."Date viral load test results received by client D.DE417" O
    where O.effective.toInterval() during "Measurement Period"
define "Date viral load test results received by client D.DE417 Value":
  "Date viral load test results received by client D.DE417" O
  return O.value
/* End of Date viral load test results received by client D.DE417 */

/*
@dataElement: HIV.D.DE418 - Reason for ARV drug regimen substitution
@activity: HIV.D21 Determine regimen and treatment options
@description: Reason why a substitution was made to the antiretroviral (ARV) drug regimen
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reason for ARV drug regimen substitution":
  exists "Reason for ARV drug regimen substitution Observation"
define "Reason for ARV drug regimen substitution Observation":
  Elements."Reason for ARV drug regimen substitution Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Reason for ARV drug regimen substitution */

/*
@dataElement: HIV.D.DE419 - Toxicity/side effects
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made to the regimen because of toxicity/side effects
*/
// TODO: Replace placeholder with relevant CQL logic
define "Toxicity/side effects D.DE419":
  exists "Toxicity/side effects D.DE419 Condition"
    or exists "Toxicity/side effects D.DE419 Observation"
define "Toxicity/side effects D.DE419 Condition":
  Elements."Toxicity/side effects D.DE419 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Toxicity/side effects D.DE419 Observation":
  Elements."Toxicity/side effects D.DE419 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Toxicity/side effects D.DE419 */

/*
@dataElement: HIV.D.DE420 - Drug-drug interaction
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made to the regimen because of a drug-drug interaction
*/
// TODO: Replace placeholder with relevant CQL logic
define "Drug-drug interaction":
  exists "Drug-drug interaction Condition"
    or exists "Drug-drug interaction Observation"
define "Drug-drug interaction Condition":
  Elements."Drug-drug interaction Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Drug-drug interaction Observation":
  Elements."Drug-drug interaction Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Drug-drug interaction */

/*
@dataElement: HIV.D.DE421 - Pregnancy
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made to the regimen because of pregnancy
*/
// TODO: Replace placeholder with relevant CQL logic
define "Pregnancy":
  exists "Pregnancy Condition"
    or exists "Pregnancy Observation"
define "Pregnancy Condition":
  Elements."Pregnancy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Pregnancy Observation":
  Elements."Pregnancy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Pregnancy */

/*
@dataElement: HIV.D.DE422 - New TB
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made to the regimen because of new tuberculosis (TB)
*/
// TODO: Replace placeholder with relevant CQL logic
define "New TB":
  exists "New TB Condition"
    or exists "New TB Observation"
define "New TB Condition":
  Elements."New TB Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "New TB Observation":
  Elements."New TB Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of New TB */

/*
@dataElement: HIV.D.DE423 - New drug available
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made to the regimen because a new drug was available
*/
// TODO: Replace placeholder with relevant CQL logic
define "New drug available":
  exists "New drug available Condition"
    or exists "New drug available Observation"
define "New drug available Condition":
  Elements."New drug available Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "New drug available Observation":
  Elements."New drug available Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of New drug available */

/*
@dataElement: HIV.D.DE424 - Drug out of stock
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made to the regimen because drug was out of stock
*/
// TODO: Replace placeholder with relevant CQL logic
define "Drug out of stock":
  exists "Drug out of stock Condition"
    or exists "Drug out of stock Observation"
define "Drug out of stock Condition":
  Elements."Drug out of stock Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Drug out of stock Observation":
  Elements."Drug out of stock Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Drug out of stock */

/*
@dataElement: HIV.D.DE425 - Other reason for regimen substitution
@activity: HIV.D21 Determine regimen and treatment options
@description: A substitution was made for another reason
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other reason for regimen substitution":
  exists "Other reason for regimen substitution Condition"
    or exists "Other reason for regimen substitution Observation"
define "Other reason for regimen substitution Condition":
  Elements."Other reason for regimen substitution Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other reason for regimen substitution Observation":
  Elements."Other reason for regimen substitution Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other reason for regimen substitution */

/*
@dataElement: HIV.D.DE457 - Medications prescribed
@activity: HIV.D23 Prescribe
@description: Name or regimen code of all other medications prescribed during the visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "Medications prescribed D.DE457":
  exists "Medications prescribed D.DE457 Observation"
define "Medications prescribed D.DE457 Observation":
  Elements."Medications prescribed D.DE457 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Medications prescribed D.DE457 */

/*
@dataElement: HIV.D.DE458 - Date medications prescribed
@activity: HIV.D23 Prescribe
@description: Date the medications were prescribed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date medications prescribed D.DE458":
  Elements."Date medications prescribed D.DE458" O
    where O.effective.toInterval() during "Measurement Period"
define "Date medications prescribed D.DE458 Value":
  "Date medications prescribed D.DE458" O
  return O.value
/* End of Date medications prescribed D.DE458 */

/*
@dataElement: HIV.D.DE459 - Dose of medications prescribed
@activity: HIV.D23 Prescribe
@description: Number of doses (quantity taken at a single point in time) of drugs prescribed/dispensed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Dose of medications prescribed":
  Elements."Dose of medications prescribed" O
    where O.effective.toInterval() during "Measurement Period"
define "Dose of medications prescribed Value":
  "Dose of medications prescribed" O
  return O.value
/* End of Dose of medications prescribed */

/*
@dataElement: HIV.D.DE460 - Number of days medications prescribed
@activity: HIV.D23 Prescribe
@description: Number of days supply of each medication or regimen prescribed during the visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "Number of days medications prescribed":
  Elements."Number of days medications prescribed" O
    where O.effective.toInterval() during "Measurement Period"
define "Number of days medications prescribed Value":
  "Number of days medications prescribed" O
  return O.value
/* End of Number of days medications prescribed */

/*
@dataElement: HIV.D.DE466 - Type of treatment-limiting toxicity
@activity: HIV.D21 Determine regimen and treatment options
@description: Type of treatment-limiting toxicity experienced by client. Treatment-limiting toxicity is defined as a serious adverse drug reaction that results in drug discontinuation or substitution. In addition, any reaction that leads to treatment interruption or requires changing the drug or regimen because of an adverse drug reaction is also considered a serious adverse drug reaction.
*/
// TODO: Replace placeholder with relevant CQL logic
define "Type of treatment-limiting toxicity":
  exists "Type of treatment-limiting toxicity Observation"
define "Type of treatment-limiting toxicity Observation":
  Elements."Type of treatment-limiting toxicity Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Type of treatment-limiting toxicity */

/*
@dataElement: HIV.D.DE467 - Gastrointestinal
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to GI issues (nausea, diarrhoea, abdominal pain, vomiting)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gastrointestinal":
  exists "Gastrointestinal Condition"
    or exists "Gastrointestinal Observation"
define "Gastrointestinal Condition":
  Elements."Gastrointestinal Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Gastrointestinal Observation":
  Elements."Gastrointestinal Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Gastrointestinal */

/*
@dataElement: HIV.D.DE468 - Skin issues
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to skin issues (rash, hypersensitivity reaction)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Skin issues":
  exists "Skin issues Condition"
    or exists "Skin issues Observation"
define "Skin issues Condition":
  Elements."Skin issues Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Skin issues Observation":
  Elements."Skin issues Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Skin issues */

/*
@dataElement: HIV.D.DE469 - Peripheral neuropathy
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to peripheral neuropathy (burning/numbness/ tingling)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Peripheral neuropathy":
  exists "Peripheral neuropathy Condition"
    or exists "Peripheral neuropathy Observation"
define "Peripheral neuropathy Condition":
  Elements."Peripheral neuropathy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Peripheral neuropathy Observation":
  Elements."Peripheral neuropathy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Peripheral neuropathy */

/*
@dataElement: HIV.D.DE470 - Central nervous system symptoms
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to central nervous system symptoms (dizzy, anxiety, nightmare, depression, seizures)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Central nervous system symptoms":
  exists "Central nervous system symptoms Condition"
    or exists "Central nervous system symptoms Observation"
define "Central nervous system symptoms Condition":
  Elements."Central nervous system symptoms Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Central nervous system symptoms Observation":
  Elements."Central nervous system symptoms Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Central nervous system symptoms */

/*
@dataElement: HIV.D.DE471 - Weight gain
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to weight gain
*/
// TODO: Replace placeholder with relevant CQL logic
define "Weight gain":
  exists "Weight gain Condition"
    or exists "Weight gain Observation"
define "Weight gain Condition":
  Elements."Weight gain Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Weight gain Observation":
  Elements."Weight gain Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Weight gain */

/*
@dataElement: HIV.D.DE472 - Hepatic dysfunction
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to hepatic dysfunction (jaundice)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Hepatic dysfunction":
  exists "Hepatic dysfunction Condition"
    or exists "Hepatic dysfunction Observation"
define "Hepatic dysfunction Condition":
  Elements."Hepatic dysfunction Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Hepatic dysfunction Observation":
  Elements."Hepatic dysfunction Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Hepatic dysfunction */

/*
@dataElement: HIV.D.DE473 - Haematological disorders
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to haematological (anaemia, neutropenia) disorders
*/
// TODO: Replace placeholder with relevant CQL logic
define "Haematological disorders":
  exists "Haematological disorders Condition"
    or exists "Haematological disorders Observation"
define "Haematological disorders Condition":
  Elements."Haematological disorders Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Haematological disorders Observation":
  Elements."Haematological disorders Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Haematological disorders */

/*
@dataElement: HIV.D.DE474 - Fatigue
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to fatigue
*/
// TODO: Replace placeholder with relevant CQL logic
define "Fatigue":
  exists "Fatigue Condition"
    or exists "Fatigue Observation"
define "Fatigue Condition":
  Elements."Fatigue Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Fatigue Observation":
  Elements."Fatigue Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Fatigue */

/*
@dataElement: HIV.D.DE475 - Headache
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to headache
*/
// TODO: Replace placeholder with relevant CQL logic
define "Headache D.DE475":
  exists "Headache D.DE475 Condition"
    or exists "Headache D.DE475 Observation"
define "Headache D.DE475 Condition":
  Elements."Headache D.DE475 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Headache D.DE475 Observation":
  Elements."Headache D.DE475 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Headache D.DE475 */

/*
@dataElement: HIV.D.DE476 - Bone dysfunction
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to bone dysfunction (fractures, osteopenia)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Bone dysfunction":
  exists "Bone dysfunction Condition"
    or exists "Bone dysfunction Observation"
define "Bone dysfunction Condition":
  Elements."Bone dysfunction Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Bone dysfunction Observation":
  Elements."Bone dysfunction Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Bone dysfunction */

/*
@dataElement: HIV.D.DE477 - Metabolic symptoms
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to metabolic symptoms (body fat changes, hyperglycaemia, dyslipidaemia)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Metabolic symptoms":
  exists "Metabolic symptoms Condition"
    or exists "Metabolic symptoms Observation"
define "Metabolic symptoms Condition":
  Elements."Metabolic symptoms Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Metabolic symptoms Observation":
  Elements."Metabolic symptoms Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Metabolic symptoms */

/*
@dataElement: HIV.D.DE478 - Kidney dysfunction
@activity: HIV.D21 Determine regimen and treatment options
@description: Treatment-limiting toxicity due to kidney dysfunction (nephrolithiasis, renal insufficiency)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Kidney dysfunction":
  exists "Kidney dysfunction Condition"
    or exists "Kidney dysfunction Observation"
define "Kidney dysfunction Condition":
  Elements."Kidney dysfunction Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Kidney dysfunction Observation":
  Elements."Kidney dysfunction Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Kidney dysfunction */

/*
@dataElement: HIV.D.DE479 - Unexpected adverse drug reaction
@activity: HIV.D21 Determine regimen and treatment options
@description: Client experienced an unexpected adverse drug reaction
*/
// TODO: Replace placeholder with relevant CQL logic
define "Unexpected adverse drug reaction":
  exists "Unexpected adverse drug reaction Condition"
    or exists "Unexpected adverse drug reaction Observation"
define "Unexpected adverse drug reaction Condition":
  Elements."Unexpected adverse drug reaction Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Unexpected adverse drug reaction Observation":
  Elements."Unexpected adverse drug reaction Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Unexpected adverse drug reaction */

/*
HIV.D.DE485
New regimen after switch to second-line regimen
*/

define "New regimen after switch to second-line regimen":
  Elements."New regimen after switch to second-line regimen" MS
  where start of MS.effective.toInterval() during "Measurement Period"


/*
HIV.D.DE491
New regimen after switch to third-line regimen
*/

define "New regimen after switch to third-line regimen":
  Elements."New regimen after switch to third-line regimen" MS
  where start of MS.effective.toInterval() during "Measurement Period"

/*
@dataElement: HIV.D.DE487 - Dates of substitution within second-line regimen
@activity: HIV.D21 Determine regimen and treatment options
@description: Date on which ARV drug regimen for client was changed within the second-line regimen (substitution)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Dates of substitution within second-line regimen":
  Elements."Dates of substitution within second-line regimen" O
    where O.effective.toInterval() during "Measurement Period"
define "Dates of substitution within second-line regimen Value":
  "Dates of substitution within second-line regimen" O
  return O.value
/* End of Dates of substitution within second-line regimen */

/*
@dataElement: HIV.D.DE493 - Dates of substitution within third-line regimen
@activity: HIV.D21 Determine regimen and treatment options
@description: Date on which ARV drug regimen for client was changed within the third-line (substitution)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Dates of substitution within third-line regimen":
  Elements."Dates of substitution within third-line regimen" O
    where O.effective.toInterval() during "Measurement Period"
define "Dates of substitution within third-line regimen Value":
  "Dates of substitution within third-line regimen" O
  return O.value
/* End of Dates of substitution within third-line regimen */

/*
@dataElement: HIV.D.DE496 - Enhanced adherence counselling provided
@activity: HIV.D24 Counsel
@description: Enhanced adherence counselling was provided to the client during the visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "Enhanced adherence counselling provided":
  exists "Enhanced adherence counselling provided Observation"
define "Enhanced adherence counselling provided Observation":
  Elements."Enhanced adherence counselling provided Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Enhanced adherence counselling provided */

/*
@dataElement: HIV.D.DE656 - Date of cervical cancer screening test
@activity: HIV.D28 Offer other services
@description: Date of cervical cancer screening test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of cervical cancer screening test":
  Elements."Date of cervical cancer screening test" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of cervical cancer screening test Value":
  "Date of cervical cancer screening test" O
  return O.value
/* End of Date of cervical cancer screening test */

/*
@dataElement: HIV.D.DE657 - Lifetime screening test number
@activity: HIV.D28 Offer other services
@description: Client's lifetime number of screenings for cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Lifetime screening test number":
  Elements."Lifetime screening test number" O
    where O.effective.toInterval() during "Measurement Period"
define "Lifetime screening test number Value":
  "Lifetime screening test number" O
  return O.value
/* End of Lifetime screening test number */

/*
@dataElement: HIV.D.DE705 - Date of diagnosis of cervical precancer lesions or invasive cervical cancer
@activity: HIV.D28 Offer other services
@description: Date of diagnosis of cervical precancer lesions or invasive cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of diagnosis of cervical precancer lesions or invasive cervical cancer":
  Elements."Date of diagnosis of cervical precancer lesions or invasive cervical cancer" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of diagnosis of cervical precancer lesions or invasive cervical cancer Value":
  "Date of diagnosis of cervical precancer lesions or invasive cervical cancer" O
  return O.value
/* End of Date of diagnosis of cervical precancer lesions or invasive cervical cancer */

/*
@dataElement: HIV.D.DE706 - Cervical cancer screening outcome
@activity: HIV.D28 Offer other services
@description: Client's screening outcome for cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Cervical cancer screening outcome":
  exists "Cervical cancer screening outcome Observation"
define "Cervical cancer screening outcome Observation":
  Elements."Cervical cancer screening outcome Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Cervical cancer screening outcome */

/*
@dataElement: HIV.D.DE707 - Positive for cervical precancer lesions
@activity: HIV.D28 Offer other services
@description: Screening outcome for cervical precancer lesions is positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive for cervical precancer lesions":
  exists "Positive for cervical precancer lesions Condition"
    or exists "Positive for cervical precancer lesions Observation"
define "Positive for cervical precancer lesions Condition":
  Elements."Positive for cervical precancer lesions Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive for cervical precancer lesions Observation":
  Elements."Positive for cervical precancer lesions Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive for cervical precancer lesions */

/*
@dataElement: HIV.D.DE708 - Negative for cervical precancer lesions
@activity: HIV.D28 Offer other services
@description: Screening outcome for cervical precancer lesions is negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative for cervical precancer lesions":
  exists "Negative for cervical precancer lesions Condition"
    or exists "Negative for cervical precancer lesions Observation"
define "Negative for cervical precancer lesions Condition":
  Elements."Negative for cervical precancer lesions Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative for cervical precancer lesions Observation":
  Elements."Negative for cervical precancer lesions Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative for cervical precancer lesions */

/*
@dataElement: HIV.D.DE709 - Cervical cancer diagnosis
@activity: HIV.D28 Offer other services
@description: Type of cervical cancer diagnosis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Cervical cancer diagnosis":
  exists "Cervical cancer diagnosis Observation"
define "Cervical cancer diagnosis Observation":
  Elements."Cervical cancer diagnosis Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Cervical cancer diagnosis */

/*
@dataElement: HIV.D.DE710 - Cervical precancer lesions
@activity: HIV.D28 Offer other services
@description: Client is diagnosed with cervical precancer lesions
*/
// TODO: Replace placeholder with relevant CQL logic
define "Cervical precancer lesions":
  exists "Cervical precancer lesions Condition"
    or exists "Cervical precancer lesions Observation"
define "Cervical precancer lesions Condition":
  Elements."Cervical precancer lesions Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Cervical precancer lesions Observation":
  Elements."Cervical precancer lesions Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Cervical precancer lesions */

/*
@dataElement: HIV.D.DE711 - Invasive cervical cancer
@activity: HIV.D28 Offer other services
@description: Client is diagnosed with invasive cervical cancer disease
*/
// TODO: Replace placeholder with relevant CQL logic
define "Invasive cervical cancer":
  exists "Invasive cervical cancer Condition"
    or exists "Invasive cervical cancer Observation"
define "Invasive cervical cancer Condition":
  Elements."Invasive cervical cancer Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Invasive cervical cancer Observation":
  Elements."Invasive cervical cancer Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Invasive cervical cancer */

/*
@dataElement: HIV.D.DE712 - Cervical cancer stage at diagnosis
@activity: HIV.D28 Offer other services
@description: Cervical cancer stage at diagnosis of cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Cervical cancer stage at diagnosis":
  exists "Cervical cancer stage at diagnosis Observation"
define "Cervical cancer stage at diagnosis Observation":
  Elements."Cervical cancer stage at diagnosis Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Cervical cancer stage at diagnosis */

/*
@dataElement: HIV.D.DE713 - Stage 0
@activity: HIV.D28 Offer other services
@description: Stage 0 cervical cancer at diagnosis of cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Stage 0":
  exists "Stage 0 Condition"
    or exists "Stage 0 Observation"
define "Stage 0 Condition":
  Elements."Stage 0 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Stage 0 Observation":
  Elements."Stage 0 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Stage 0 */

/*
@dataElement: HIV.D.DE714 - Stage I
@activity: HIV.D28 Offer other services
@description: Stage I cervical cancer at diagnosis of cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Stage I":
  exists "Stage I Condition"
    or exists "Stage I Observation"
define "Stage I Condition":
  Elements."Stage I Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Stage I Observation":
  Elements."Stage I Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Stage I */

/*
@dataElement: HIV.D.DE715 - Stage II
@activity: HIV.D28 Offer other services
@description: Stage II cervical cancer at diagnosis of cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Stage II":
  exists "Stage II Condition"
    or exists "Stage II Observation"
define "Stage II Condition":
  Elements."Stage II Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Stage II Observation":
  Elements."Stage II Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Stage II */

/*
@dataElement: HIV.D.DE716 - Stage III
@activity: HIV.D28 Offer other services
@description: Stage III cervical cancer at diagnosis of cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Stage III":
  exists "Stage III Condition"
    or exists "Stage III Observation"
define "Stage III Condition":
  Elements."Stage III Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Stage III Observation":
  Elements."Stage III Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Stage III */

/*
@dataElement: HIV.D.DE717 - Stage IV
@activity: HIV.D28 Offer other services
@description: Stage IV cervical cancer at diagnosis of cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Stage IV":
  exists "Stage IV Condition"
    or exists "Stage IV Observation"
define "Stage IV Condition":
  Elements."Stage IV Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Stage IV Observation":
  Elements."Stage IV Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Stage IV */

/*
@dataElement: HIV.D.DE718 - Date of treatment for cervical precancer lesions
@activity: HIV.D28 Offer other services
@description: Date of treatment for cervical precancer lesions
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of treatment for cervical precancer lesions":
  Elements."Date of treatment for cervical precancer lesions" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of treatment for cervical precancer lesions Value":
  "Date of treatment for cervical precancer lesions" O
  return O.value
/* End of Date of treatment for cervical precancer lesions */

/*
@dataElement: HIV.D.DE730 - Invasive cervical cancer treatment episode
@activity: HIV.D28 Offer other services
@description: Client's lifetime number of treatments for invasive cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Invasive cervical cancer treatment episode":
  Elements."Invasive cervical cancer treatment episode" O
    where O.effective.toInterval() during "Measurement Period"
define "Invasive cervical cancer treatment episode Value":
  "Invasive cervical cancer treatment episode" O
  return O.value
/* End of Invasive cervical cancer treatment episode */

/*
@dataElement: HIV.D.DE731 - Invasive cervical cancer treatment method
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method
*/
// TODO: Replace placeholder with relevant CQL logic
define "Invasive cervical cancer treatment method":
  exists "Invasive cervical cancer treatment method Observation"
define "Invasive cervical cancer treatment method Observation":
  Elements."Invasive cervical cancer treatment method Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Invasive cervical cancer treatment method */

/*
@dataElement: HIV.D.DE732 - Conization
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a conization
*/
// TODO: Replace placeholder with relevant CQL logic
define "Conization":
  exists "Conization Condition"
    or exists "Conization Observation"
define "Conization Condition":
  Elements."Conization Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Conization Observation":
  Elements."Conization Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Conization */

/*
@dataElement: HIV.D.DE733 - Trachelectomy
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a trachelectomy
*/
// TODO: Replace placeholder with relevant CQL logic
define "Trachelectomy":
  exists "Trachelectomy Condition"
    or exists "Trachelectomy Observation"
define "Trachelectomy Condition":
  Elements."Trachelectomy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Trachelectomy Observation":
  Elements."Trachelectomy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Trachelectomy */

/*
@dataElement: HIV.D.DE734 - Hysterectomy
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a hysterectomy
*/
// TODO: Replace placeholder with relevant CQL logic
define "Hysterectomy":
  exists "Hysterectomy Condition"
    or exists "Hysterectomy Observation"
define "Hysterectomy Condition":
  Elements."Hysterectomy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Hysterectomy Observation":
  Elements."Hysterectomy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Hysterectomy */

/*
@dataElement: HIV.D.DE735 - Management of invasive cervical cancer
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is management of invasive cervical cancer
*/
// TODO: Replace placeholder with relevant CQL logic
define "Management of invasive cervical cancer":
  exists "Management of invasive cervical cancer Condition"
    or exists "Management of invasive cervical cancer Observation"
define "Management of invasive cervical cancer Condition":
  Elements."Management of invasive cervical cancer Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Management of invasive cervical cancer Observation":
  Elements."Management of invasive cervical cancer Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Management of invasive cervical cancer */

/*
@dataElement: HIV.D.DE736 - Radiotherapy
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a radiotherapy
*/
// TODO: Replace placeholder with relevant CQL logic
define "Radiotherapy":
  exists "Radiotherapy Condition"
    or exists "Radiotherapy Observation"
define "Radiotherapy Condition":
  Elements."Radiotherapy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Radiotherapy Observation":
  Elements."Radiotherapy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Radiotherapy */

/*
@dataElement: HIV.D.DE737 - Chemotherapy
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a chemotherapy
*/
// TODO: Replace placeholder with relevant CQL logic
define "Chemotherapy":
  exists "Chemotherapy Condition"
    or exists "Chemotherapy Observation"
define "Chemotherapy Condition":
  Elements."Chemotherapy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Chemotherapy Observation":
  Elements."Chemotherapy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Chemotherapy */

/*
@dataElement: HIV.D.DE738 - Chemoradiation
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a chemoradiation
*/
// TODO: Replace placeholder with relevant CQL logic
define "Chemoradiation":
  exists "Chemoradiation Condition"
    or exists "Chemoradiation Observation"
define "Chemoradiation Condition":
  Elements."Chemoradiation Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Chemoradiation Observation":
  Elements."Chemoradiation Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Chemoradiation */

/*
@dataElement: HIV.D.DE739 - Other
@activity: HIV.D28 Offer other services
@description: Invasive cervical cancer treatment method is a not in list
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other D.DE739":
  exists "Other D.DE739 Condition"
    or exists "Other D.DE739 Observation"
define "Other D.DE739 Condition":
  Elements."Other D.DE739 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other D.DE739 Observation":
  Elements."Other D.DE739 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other D.DE739 */

/*
@dataElement: HIV.D.DE760 - Eligible for DSD ART
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is eligible for differentiated service delivery (DSD) for ART
*/

define "Eligible for DSD ART":
  exists Elements."Eligible for DSD ART" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Eligible for DSD ART */

/*
@dataElement: HIV.D.DE761 - Date DSD ART eligibility assessed
@activity: HIV.D21 Determine regimen and treatment options
@description: Date client was assessed for eligibility for differentiated service delivery (DSD) for ART
*/

define "Date DSD ART eligibility assessed":
  exists(Elements."Date DSD ART eligibility assessed" P where P during "Measurement Period")

/* End of Date DSD ART eligibility assessed */

/*
@dataElement: HIV.D.DE762 - Currently enrolled in DSD ART model
@activity: HIV.D21 Determine regimen and treatment options
@description: Client currently enrolled in differentiated service delivery (DSD) ART model
*/

define "Currently enrolled in DSD ART model":
  exists(
    [EpisodeOfCare] EOC
    where exists(EOC.type T where T ~ Concepts."Currently enrolled in DSD ART model")
    and (exists (
      EOC.statusHistory H
      where H.period starts after start of "Measurement Period"
      and H.period starts before end of "Measurement Period"
    ) 
    or (
      EOC.period starts after start of "Measurement Period"
      and EOC.period starts before end of "Measurement Period"
    )
    )
  )
/* End of Currently enrolled in DSD ART model */

/*
@dataElement: HIV.D.DE763 - DSD ART start date
@activity: HIV.D21 Determine regimen and treatment options
@description: Date client started on differentiated service delivery (DSD) for ART
*/

define "DSD ART start date":
  exists(Elements."DSD ART start date" t where t starts during "Measurement Period")
/* End of DSD ART start date */

/*
@dataElement: HIV.D.DE764 - DSD ART models
@activity: HIV.D21 Determine regimen and treatment options
@description: Type of DSD ART model client is enrolled in (country-specific)
*/
// TODO: Replace placeholder with relevant CQL logic
define "DSD ART models":
  exists "DSD ART models Observation"
define "DSD ART models Observation":
  Elements."DSD ART models Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of DSD ART models */

/*
@dataElement: HIV.D.DE765 - Fast track ART refill
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is enrolled in fast track ART refill (DSD ART model)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Fast track ART refill":
  exists "Fast track ART refill Condition"
    or exists "Fast track ART refill Observation"
define "Fast track ART refill Condition":
  Elements."Fast track ART refill Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Fast track ART refill Observation":
  Elements."Fast track ART refill Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Fast track ART refill */

/*
@dataElement: HIV.D.DE766 - Facility adherence club
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is enrolled in facility adherence club (DSD ART model)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Facility adherence club":
  exists "Facility adherence club Condition"
    or exists "Facility adherence club Observation"
define "Facility adherence club Condition":
  Elements."Facility adherence club Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Facility adherence club Observation":
  Elements."Facility adherence club Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Facility adherence club */

/*
@dataElement: HIV.D.DE767 - Community ART distribution point
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is enrolled in community ART distribution point (DSD ART model)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Community ART distribution point":
  exists "Community ART distribution point Condition"
    or exists "Community ART distribution point Observation"
define "Community ART distribution point Condition":
  Elements."Community ART distribution point Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Community ART distribution point Observation":
  Elements."Community ART distribution point Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Community ART distribution point */

/*
@dataElement: HIV.D.DE768 - CHW/peer educator community ART group
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is enrolled in community health worker/peer educator community ART group (DSD ART model)
*/
// TODO: Replace placeholder with relevant CQL logic
define "CHW/peer educator community ART group":
  exists "CHW/peer educator community ART group Condition"
    or exists "CHW/peer educator community ART group Observation"
define "CHW/peer educator community ART group Condition":
  Elements."CHW/peer educator community ART group Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "CHW/peer educator community ART group Observation":
  Elements."CHW/peer educator community ART group Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of CHW/peer educator community ART group */

/*
@dataElement: HIV.D.DE769 - Patient/client community ART group
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is enrolled in patient/client community ART group (DSD ART model)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Patient/client community ART group":
  exists "Patient/client community ART group Condition"
    or exists "Patient/client community ART group Observation"
define "Patient/client community ART group Condition":
  Elements."Patient/client community ART group Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Patient/client community ART group Observation":
  Elements."Patient/client community ART group Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Patient/client community ART group */

/*
@dataElement: HIV.D.DE770 - Other DSD ART model
@activity: HIV.D21 Determine regimen and treatment options
@description: Client is enrolled in another DSD ART model
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other DSD ART model":
  exists "Other DSD ART model Condition"
    or exists "Other DSD ART model Observation"
define "Other DSD ART model Condition":
  Elements."Other DSD ART model Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other DSD ART model Observation":
  Elements."Other DSD ART model Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other DSD ART model */

/*
@dataElement: HIV.D.DE778 - Syndrome/STI diagnosed
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Syndrome or STI for which client is diagnosed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syndrome/STI diagnosed D.DE778":
  exists "Syndrome/STI diagnosed D.DE778 Observation"
define "Syndrome/STI diagnosed D.DE778 Observation":
  Elements."Syndrome/STI diagnosed D.DE778 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Syndrome/STI diagnosed D.DE778 */

/*
@dataElement: HIV.D.DE779 - Urethral discharge syndrome
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Client diagnosed with urethral discharge syndrome
*/
// TODO: Replace placeholder with relevant CQL logic
define "Urethral discharge syndrome D.DE779":
  exists "Urethral discharge syndrome D.DE779 Condition"
    or exists "Urethral discharge syndrome D.DE779 Observation"
define "Urethral discharge syndrome D.DE779 Condition":
  Elements."Urethral discharge syndrome D.DE779 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Urethral discharge syndrome D.DE779 Observation":
  Elements."Urethral discharge syndrome D.DE779 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Urethral discharge syndrome D.DE779 */

/*
@dataElement: HIV.D.DE780 - Vaginal discharge syndrome
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Client diagnosed with vaginal discharge syndrome
*/
// TODO: Replace placeholder with relevant CQL logic
define "Vaginal discharge syndrome D.DE780":
  exists "Vaginal discharge syndrome D.DE780 Condition"
    or exists "Vaginal discharge syndrome D.DE780 Observation"
define "Vaginal discharge syndrome D.DE780 Condition":
  Elements."Vaginal discharge syndrome D.DE780 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Vaginal discharge syndrome D.DE780 Observation":
  Elements."Vaginal discharge syndrome D.DE780 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Vaginal discharge syndrome D.DE780 */

/*
@dataElement: HIV.D.DE781 - Lower Abdominal pain 
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Client diagnosed with lower abdominal pain
*/
// TODO: Replace placeholder with relevant CQL logic
define "Lower Abdominal pain  D.DE781":
  exists "Lower Abdominal pain  D.DE781 Condition"
    or exists "Lower Abdominal pain  D.DE781 Observation"
define "Lower Abdominal pain  D.DE781 Condition":
  Elements."Lower Abdominal pain  D.DE781 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Lower Abdominal pain  D.DE781 Observation":
  Elements."Lower Abdominal pain  D.DE781 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Lower Abdominal pain  D.DE781 */

/*
@dataElement: HIV.D.DE782 - Genital ulcer disease syndrome
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Client diagnosed with genital ulcer disease syndrome
*/
// TODO: Replace placeholder with relevant CQL logic
define "Genital ulcer disease syndrome D.DE782":
  exists "Genital ulcer disease syndrome D.DE782 Condition"
    or exists "Genital ulcer disease syndrome D.DE782 Observation"
define "Genital ulcer disease syndrome D.DE782 Condition":
  Elements."Genital ulcer disease syndrome D.DE782 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Genital ulcer disease syndrome D.DE782 Observation":
  Elements."Genital ulcer disease syndrome D.DE782 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Genital ulcer disease syndrome D.DE782 */

/*
@dataElement: HIV.D.DE783 - Anorectal discharge
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Client diagnosed with anorectal discharge
*/
// TODO: Replace placeholder with relevant CQL logic
define "Anorectal discharge D.DE783":
  exists "Anorectal discharge D.DE783 Condition"
    or exists "Anorectal discharge D.DE783 Observation"
define "Anorectal discharge D.DE783 Condition":
  Elements."Anorectal discharge D.DE783 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Anorectal discharge D.DE783 Observation":
  Elements."Anorectal discharge D.DE783 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Anorectal discharge D.DE783 */

/*
@dataElement: HIV.D.DE784 - Sent for testing
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Specimen sent for testing
*/
// TODO: Replace placeholder with relevant CQL logic
define "Sent for testing D.DE784":
  exists "Sent for testing D.DE784 Condition"
    or exists "Sent for testing D.DE784 Observation"
define "Sent for testing D.DE784 Condition":
  Elements."Sent for testing D.DE784 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Sent for testing D.DE784 Observation":
  Elements."Sent for testing D.DE784 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Sent for testing D.DE784 */

/*
@dataElement: HIV.D.DE785 - Other
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Other syndrome/STI diagnosed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other D.DE785":
  exists "Other D.DE785 Condition"
    or exists "Other D.DE785 Observation"
define "Other D.DE785 Condition":
  Elements."Other D.DE785 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other D.DE785 Observation":
  Elements."Other D.DE785 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other D.DE785 */

/*
@dataElement: HIV.D.DE787 - Any STI syndrome diagnosed
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Was the client diagnosed with any of the five STI syndromes during this visit?
*/
// TODO: Replace placeholder with relevant CQL logic
define "Any STI syndrome diagnosed D.DE787":
  exists "Any STI syndrome diagnosed D.DE787 Observation"
define "Any STI syndrome diagnosed D.DE787 Observation":
  Elements."Any STI syndrome diagnosed D.DE787 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Any STI syndrome diagnosed D.DE787 */

/*
@dataElement: HIV.D.DE801 - Syphilis test date
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Date of syphilis test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syphilis test date D.DE801":
  Elements."Syphilis test date D.DE801" O
    where O.effective.toInterval() during "Measurement Period"
define "Syphilis test date D.DE801 Value":
  "Syphilis test date D.DE801" O
  return O.value
/* End of Syphilis test date D.DE801 */

/*
@dataElement: HIV.D.DE802 - Syphilis test result
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Result from syphilis test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syphilis test result D.DE802":
  exists "Syphilis test result D.DE802 Observation"
define "Syphilis test result D.DE802 Observation":
  Elements."Syphilis test result D.DE802 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Syphilis test result D.DE802 */

/*
@dataElement: HIV.D.DE803 - Positive
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Test result is positive for syphilis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive D.DE803":
  exists "Positive D.DE803 Condition"
    or exists "Positive D.DE803 Observation"
define "Positive D.DE803 Condition":
  Elements."Positive D.DE803 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive D.DE803 Observation":
  Elements."Positive D.DE803 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive D.DE803 */

/*
@dataElement: HIV.D.DE804 - Negative
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Test result is negative for syphilis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative D.DE804":
  exists "Negative D.DE804 Condition"
    or exists "Negative D.DE804 Observation"
define "Negative D.DE804 Condition":
  Elements."Negative D.DE804 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative D.DE804 Observation":
  Elements."Negative D.DE804 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative D.DE804 */

/*
@dataElement: HIV.D.DE805 - Inconclusive
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Test result is inconclusive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Inconclusive D.DE805":
  exists "Inconclusive D.DE805 Condition"
    or exists "Inconclusive D.DE805 Observation"
define "Inconclusive D.DE805 Condition":
  Elements."Inconclusive D.DE805 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Inconclusive D.DE805 Observation":
  Elements."Inconclusive D.DE805 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Inconclusive D.DE805 */

/*
@dataElement: HIV.D.DE806 - Syphilis treatment start date
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Date of initiation of syphilis treatment
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syphilis treatment start date D.DE806":
  Elements."Syphilis treatment start date D.DE806" O
    where O.effective.toInterval() during "Measurement Period"
define "Syphilis treatment start date D.DE806 Value":
  "Syphilis treatment start date D.DE806" O
  return O.value
/* End of Syphilis treatment start date D.DE806 */

/*
@dataElement: HIV.D.DE807 - Gonorrhoea test date
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Date of Gonorrhoea test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gonorrhoea test date D.DE807":
  Elements."Gonorrhoea test date D.DE807" O
    where O.effective.toInterval() during "Measurement Period"
define "Gonorrhoea test date D.DE807 Value":
  "Gonorrhoea test date D.DE807" O
  return O.value
/* End of Gonorrhoea test date D.DE807 */

/*
@dataElement: HIV.D.DE808 - Gonorrhoea test result
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Result from Gonorrhoea test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gonorrhoea test result D.DE808":
  exists "Gonorrhoea test result D.DE808 Observation"
define "Gonorrhoea test result D.DE808 Observation":
  Elements."Gonorrhoea test result D.DE808 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Gonorrhoea test result D.DE808 */

/*
@dataElement: HIV.D.DE809 - Positive
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Test result is positive for Neisseria gonorrhoeae
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive D.DE809":
  exists "Positive D.DE809 Condition"
    or exists "Positive D.DE809 Observation"
define "Positive D.DE809 Condition":
  Elements."Positive D.DE809 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive D.DE809 Observation":
  Elements."Positive D.DE809 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive D.DE809 */

/*
@dataElement: HIV.D.DE810 - Negative
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Test result is negative for Neisseria gonorrhoeae
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative D.DE810":
  exists "Negative D.DE810 Condition"
    or exists "Negative D.DE810 Observation"
define "Negative D.DE810 Condition":
  Elements."Negative D.DE810 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative D.DE810 Observation":
  Elements."Negative D.DE810 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative D.DE810 */

/*
@dataElement: HIV.D.DE811 - Inconclusive
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Test result is inconclusive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Inconclusive D.DE811":
  exists "Inconclusive D.DE811 Condition"
    or exists "Inconclusive D.DE811 Observation"
define "Inconclusive D.DE811 Condition":
  Elements."Inconclusive D.DE811 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Inconclusive D.DE811 Observation":
  Elements."Inconclusive D.DE811 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Inconclusive D.DE811 */

/*
@dataElement: HIV.D.DE812 - Gonorrhoea treatment start date
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Date of initiation of Gonorrhoea treatment
*/
// TODO: Replace placeholder with relevant CQL logic
define "Gonorrhoea treatment start date D.DE812":
  Elements."Gonorrhoea treatment start date D.DE812" O
    where O.effective.toInterval() during "Measurement Period"
define "Gonorrhoea treatment start date D.DE812 Value":
  "Gonorrhoea treatment start date D.DE812" O
  return O.value
/* End of Gonorrhoea treatment start date D.DE812 */

/*
@dataElement: HIV.D.DE813 - Type of specimen
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Type of specimen to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Type of specimen D.DE813":
  exists "Type of specimen D.DE813 Observation"
define "Type of specimen D.DE813 Observation":
  Elements."Type of specimen D.DE813 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Type of specimen D.DE813 */

/*
@dataElement: HIV.D.DE814 - Blood
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Blood specimen to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Blood D.DE814":
  exists "Blood D.DE814 Condition"
    or exists "Blood D.DE814 Observation"
define "Blood D.DE814 Condition":
  Elements."Blood D.DE814 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Blood D.DE814 Observation":
  Elements."Blood D.DE814 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Blood D.DE814 */

/*
@dataElement: HIV.D.DE815 - Urine
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Urine specimen to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Urine D.DE815":
  exists "Urine D.DE815 Condition"
    or exists "Urine D.DE815 Observation"
define "Urine D.DE815 Condition":
  Elements."Urine D.DE815 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Urine D.DE815 Observation":
  Elements."Urine D.DE815 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Urine D.DE815 */

/*
@dataElement: HIV.D.DE816 - Cervical or vaginal swab
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Cervical or vaginal swab to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Cervical or vaginal swab D.DE816":
  exists "Cervical or vaginal swab D.DE816 Condition"
    or exists "Cervical or vaginal swab D.DE816 Observation"
define "Cervical or vaginal swab D.DE816 Condition":
  Elements."Cervical or vaginal swab D.DE816 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Cervical or vaginal swab D.DE816 Observation":
  Elements."Cervical or vaginal swab D.DE816 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Cervical or vaginal swab D.DE816 */

/*
@dataElement: HIV.D.DE817 - Urethral or penile swab
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Urethral or penile swab to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Urethral or penile swab D.DE817":
  exists "Urethral or penile swab D.DE817 Condition"
    or exists "Urethral or penile swab D.DE817 Observation"
define "Urethral or penile swab D.DE817 Condition":
  Elements."Urethral or penile swab D.DE817 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Urethral or penile swab D.DE817 Observation":
  Elements."Urethral or penile swab D.DE817 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Urethral or penile swab D.DE817 */

/*
@dataElement: HIV.D.DE818 - Rectal swab
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Rectal swab to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Rectal swab D.DE818":
  exists "Rectal swab D.DE818 Condition"
    or exists "Rectal swab D.DE818 Observation"
define "Rectal swab D.DE818 Condition":
  Elements."Rectal swab D.DE818 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Rectal swab D.DE818 Observation":
  Elements."Rectal swab D.DE818 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Rectal swab D.DE818 */

/*
@dataElement: HIV.D.DE819 - Other
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Other specimen type to be collected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other D.DE819":
  exists "Other D.DE819 Condition"
    or exists "Other D.DE819 Observation"
define "Other D.DE819 Condition":
  Elements."Other D.DE819 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other D.DE819 Observation":
  Elements."Other D.DE819 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other D.DE819 */

/*
@dataElement: HIV.D.DE828 - Neisseria gonorrhoeae test type
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Type of diagnostic test used for Neisseria gonorrhoeae
*/
// TODO: Replace placeholder with relevant CQL logic
define "Neisseria gonorrhoeae test type D.DE828":
  exists "Neisseria gonorrhoeae test type D.DE828 Observation"
define "Neisseria gonorrhoeae test type D.DE828 Observation":
  Elements."Neisseria gonorrhoeae test type D.DE828 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Neisseria gonorrhoeae test type D.DE828 */

/*
@dataElement: HIV.D.DE829 - NAAT
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Nucleic Acid Amplification Test (NAAT) used
*/
// TODO: Replace placeholder with relevant CQL logic
define "NAAT D.DE829":
  exists "NAAT D.DE829 Condition"
    or exists "NAAT D.DE829 Observation"
define "NAAT D.DE829 Condition":
  Elements."NAAT D.DE829 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "NAAT D.DE829 Observation":
  Elements."NAAT D.DE829 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of NAAT D.DE829 */

/*
@dataElement: HIV.D.DE830 - POC Test
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Point-of-care (POC) test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "POC Test D.DE830":
  exists "POC Test D.DE830 Condition"
    or exists "POC Test D.DE830 Observation"
define "POC Test D.DE830 Condition":
  Elements."POC Test D.DE830 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "POC Test D.DE830 Observation":
  Elements."POC Test D.DE830 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of POC Test D.DE830 */

/*
@dataElement: HIV.D.DE831 - Culture
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Culture test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "Culture D.DE831":
  exists "Culture D.DE831 Condition"
    or exists "Culture D.DE831 Observation"
define "Culture D.DE831 Condition":
  Elements."Culture D.DE831 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Culture D.DE831 Observation":
  Elements."Culture D.DE831 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Culture D.DE831 */

/*
@dataElement: HIV.D.DE832 - Microscopy
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Microscopy test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "Microscopy D.DE832":
  exists "Microscopy D.DE832 Condition"
    or exists "Microscopy D.DE832 Observation"
define "Microscopy D.DE832 Condition":
  Elements."Microscopy D.DE832 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Microscopy D.DE832 Observation":
  Elements."Microscopy D.DE832 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Microscopy D.DE832 */

/*
@dataElement: HIV.D.DE833 - Other
@activity: HIV.D26 Offer sexual and reproductive health services
@description: Other type of test used
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other D.DE833":
  exists "Other D.DE833 Condition"
    or exists "Other D.DE833 Observation"
define "Other D.DE833 Condition":
  Elements."Other D.DE833 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other D.DE833 Observation":
  Elements."Other D.DE833 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other D.DE833 */

/*
@dataElement: HIV.D.DE939 - TB diagnosis result
@activity: HIV.D8 Capture or update client history
@description: Final result of the TB investigation (bacteriological and/or clinical)
*/
// TODO: Replace placeholder with relevant CQL logic
define "TB diagnosis result":
  exists "TB diagnosis result Observation"
define "TB diagnosis result Observation":
  Elements."TB diagnosis result Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of TB diagnosis result */

/*
@dataElement: HIV.D.DE940 - Diagnosed TB
@activity: HIV.D8 Capture or update client history
@description: Client is diagnosed with TB disease
*/
define TB_diagnosed:
  exists(
    ([Condition] C
    where C.clinicalStatus ~ ConceptsCustom."active"
    and exists(C.category CC where CC ~ ConceptsCustom."encounter-diagnosis")
    and C.code ~ Concepts."Diagnosed TB"
    and C.onset during "Measurement Period")
  )

// TODO: Replace placeholder with relevant CQL logic
define "Diagnosed TB":
  exists "Diagnosed TB Condition"
    or exists "Diagnosed TB Observation"
define "Diagnosed TB Condition":
  Elements."Diagnosed TB Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Diagnosed TB Observation":
  Elements."Diagnosed TB Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Diagnosed TB */

/*
@dataElement: HIV.D.DE941 - TB excluded
@activity: HIV.D8 Capture or update client history
@description: Client is not diagnosed with TB
*/
// TODO: Replace placeholder with relevant CQL logic
define "TB excluded":
  exists "TB excluded Condition"
    or exists "TB excluded Observation"
define "TB excluded Condition":
  Elements."TB excluded Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "TB excluded Observation":
  Elements."TB excluded Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of TB excluded */

/*
@dataElement: HIV.D.DE945 - Presumptive TB
@activity: HIV.D8 Capture or update client history
@description: Client has signs or symptoms of tuberculosis (TB) without laboratory confirmation
*/
define TB_presumptive:
  exists(
    ([Condition] C
    where C.clinicalStatus ~ ConceptsCustom."active"
    and exists(C.category CC where CC ~ ConceptsCustom."encounter-diagnosis")
    and C.code ~ Concepts."Presumptive TB - HIV.D.DE945"
    and C.onset during "Measurement Period")
  )

// TODO: Replace placeholder with relevant CQL logic
define "Presumptive TB D.DE945":
  exists "Presumptive TB D.DE945 Observation"
define "Presumptive TB D.DE945 Observation":
  Elements."Presumptive TB D.DE945 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Presumptive TB D.DE945 */

/*
@dataElement: HIV.D.DE952 - Date of TB diagnosis
@activity: HIV.D8 Capture or update client history
@description: The date when the diagnosis was established
*/

define "Date of TB diagnosis":
  start of First(Elements."Date of TB diagnosis") during "Measurement Period"

/* End of Date of TB diagnosis */

/*
@dataElement: HIV.D.DE954 - TB preventive treatment TPT start date
@activity: HIV.D8 Capture or update client history
@description: The date on which the client began taking TPT
*/
define "TB preventive treatment TPT start date in measurement period":
  Elements."TB preventive treatment TPT start date" D
    where D in "Measurement Period"

define "TB preventive treatment TPT completed in measurement period":
  Elements."TPT regimen" MS
    where start of MS.effective.toInterval() in "Measurement Period"
      and MS.status = 'completed'
/* End of TB preventive treatment TPT start date */

/*
@dataElement: HIV.D.DE986 - TB screening result
@activity: HIV.D4 Screen for TB
@description: Record the result of the tuberculosis (TB) screening
*/

define "TB screening result":
  exists (Elements."TB screening result")
/* End of TB screening result */

/*
@dataElement: HIV.D.DE987 - Screen positive for TB
@activity: HIV.D4 Screen for TB
@description: Screening result was positive for tuberculosis (TB)
*/

define "Screen positive for TB":
  exists Elements."Screen positive for TB" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Screen positive for TB */

/*
@dataElement: HIV.D.DE988 - Screen negative for TB
@activity: HIV.D4 Screen for TB
@description: Screening result was negative for tuberculosis (TB)
*/

define "Screen negative for TB":
  exists Elements."Screen negative for TB" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Screen negative for TB */

/*
@dataElement: HIV.D.DE989 - Inconclusive
@activity: HIV.D4 Screen for TB
@description: Screening result was inconclusive for tuberculosis (TB)
*/

define "Inconclusive D.DE989":
  exists Elements."Inconclusive D.DE989" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Inconclusive D.DE989 */

/*
@dataElement: HIV.D.DE990 - TB screening date
@activity: HIV.D4 Screen for TB
@description: Date the TB screening was conducted
*/

define "TB screening date":
  exists (Elements."TB screening date" P
    where P.performed.toInterval() during "Measurement Period")

/* End of TB screening date */

/*
@dataElement: HIV.D.DE992 - TB diagnostic test category
@activity: HIV.D4 Screen for TB
@description: The type of diagnostic test performed to detect tuberculosis (TB) disease
*/

define "TB diagnostic test category":
  exists (Elements."TB diagnostic test category")
/* End of TB diagnostic test category */

/*
@dataElement: HIV.D.DE993 - LF-LAM
@activity: HIV.D4 Screen for TB
@description: Client tested for tuberculosis with a lateral flow urine lipoarabinomannan assay
*/

define "LF-LAM":
  exists (Elements."LF-LAM" O
     where O.performed.toInterval() during "Measurement Period")
/* End of LF-LAM */

/*
@dataElement: HIV.D.DE994 - mWRD test for TB
@activity: HIV.D4 Screen for TB
@description: Client tested with a WHO-recommended molecular diagnostic test to detect Mycobacterium tuberculosis (MTB)
*/

define "mWRD test for TB":
  exists (Elements."mWRD test for TB" O
     where O.performed.toInterval() during "Measurement Period")
/* End of mWRD test for TB */

/*
@dataElement: HIV.D.DE995 - Microscopy - Sputum acid-fast bacilli AFB
@activity: HIV.D4 Screen for TB
@description: Client tested for tuberculosis with a sputum acid-fast bacilli (AFB)
*/

define "Microscopy - Sputum acid-fast bacilli AFB":
    exists (Elements."Microscopy - Sputum acid-fast bacilli AFB" O
     where O.performed.toInterval() during "Measurement Period")
/* End of Microscopy - Sputum acid-fast bacilli AFB */

/*
@dataElement: HIV.D.DE996 - TB Culture
@activity: HIV.D4 Screen for TB
@description: Client tested for tuberculosis (TB) with a culture
*/

define "TB Culture":
  exists (Elements."TB Culture" O
     where O.performed.toInterval() during "Measurement Period")
/* End of TB Culture */

/*
@dataElement: HIV.D.DE997 - TB diagnostic test date
@activity: HIV.D4 Screen for TB
@description: The date when TB diagnostic test was performed
*/

define "TB diagnostic test date":
  exists(Elements."TB diagnostic test date" P where P during "Measurement Period")

/* End of TB diagnostic test date */

/*
@dataElement: HIV.D.DE1001 - TB treatment start date
@activity: HIV.D8 Capture or update client history
@description: The date on which the client start or restarted tuberculosis (TB) treatment
*/

define "TB treatment start date":
  exists(Elements."TB treatment start date" MS where MS during "Measurement Period")
/* End of TB treatment start date */

/*
@dataElement: HIV.D.DE1017 - Eligible for TB preventive treatment
@activity: HIV.D14 Prevent, screen, and manage comorbidities and coinfections
@description: Client is eligible for tuberculosis preventive treatment (TPT)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Eligible for TB preventive treatment":
  exists "Eligible for TB preventive treatment Observation"
define "Eligible for TB preventive treatment Observation":
  Elements."Eligible for TB preventive treatment Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Eligible for TB preventive treatment */

/*
@dataElement: HIV.D.DE1028 - TPT regimen type
@activity: HIV.D4 Screen for TB
@description: Type of TPT regimen the client is currently on
*/
define "On TPT regimen":
  exists "TPT regimen"

define "TPT regimen":
  Elements."TPT regimen" MS
    where MS.effective.toInterval() during "Measurement Period"

define "TPT regimen type":
  "TPT regimen" MS
  return Common.ExtractMedicationCode(MS.medication)

/* End of TPT regimen type */

/*
@dataElement: HIV.D.DE1034 - TB preventive treatment TPT status
@activity: HIV.D4 Screen for TB
@description: Indicates the current status of TB preventive treatment (TPT)
*/
// TODO: Replace placeholder with relevant CQL logic
define "TB preventive treatment TPT status":
  exists "TB preventive treatment TPT status Observation"
define "TB preventive treatment TPT status Observation":
  Elements."TB preventive treatment TPT status Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of TB preventive treatment TPT status */

/*
@dataElement: HIV.D.DE1035 - Not started
@activity: HIV.D4 Screen for TB
@description: The client did not start the TB preventive treatment (TPT)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Not started":
  exists "Not started Condition"
    or exists "Not started Observation"
define "Not started Condition":
  Elements."Not started Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Not started Observation":
  Elements."Not started Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Not started */

/*
@dataElement: HIV.D.DE1036 - On TPT
@activity: HIV.D4 Screen for TB
@description: The client started the TB preventive treatment (TPT) and is currently taking the medication, without treatment interruptions
*/
// TODO: Replace placeholder with relevant CQL logic
define "On TPT":
  exists "On TPT Condition"
    or exists "On TPT Observation"
define "On TPT Condition":
  Elements."On TPT Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "On TPT Observation":
  Elements."On TPT Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of On TPT */

/*
@dataElement: HIV.D.DE1037 - On TPT with interruptions
@activity: HIV.D4 Screen for TB
@description: The client started the TB preventive treatment (TPT) and is currently taking the medication, with treatment interruptions
*/
// TODO: Replace placeholder with relevant CQL logic
define "On TPT with interruptions":
  exists "On TPT with interruptions Condition"
    or exists "On TPT with interruptions Observation"
define "On TPT with interruptions Condition":
  Elements."On TPT with interruptions Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "On TPT with interruptions Observation":
  Elements."On TPT with interruptions Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of On TPT with interruptions */

/*
@dataElement: HIV.D.DE1038 - On hold
@activity: HIV.D4 Screen for TB
@description: The health care worker has temporarily stopped the TB preventive treatment (TPT), but TPT is expected to continue again later. May also be called 'suspended'.
*/
// TODO: Replace placeholder with relevant CQL logic
define "On hold":
  exists "On hold Condition"
    or exists "On hold Observation"
define "On hold Condition":
  Elements."On hold Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "On hold Observation":
  Elements."On hold Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of On hold */

/*
@dataElement: HIV.D.DE1039 - Completed
@activity: HIV.D4 Screen for TB
@description: TB preventive treatment (TPT) was completed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Completed":
  exists "Completed Condition"
    or exists "Completed Observation"
define "Completed Condition":
  Elements."Completed Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Completed Observation":
  Elements."Completed Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Completed */

/*
@dataElement: HIV.E.DE41 - Timing of ART initiation
@activity: HIV.E1 Capture or update mother's history
@description: When the pregnant woman or mother initiated ART, for women living with HIV.
*/
// TODO: Replace placeholder with relevant CQL logic
define "Timing of ART initiation":
  exists "Timing of ART initiation Observation"
define "Timing of ART initiation Observation":
  Elements."Timing of ART initiation Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Timing of ART initiation */

/*
@dataElement: HIV.E.DE42 - Already on ART at first antenatal care visit
@activity: HIV.E1 Capture or update mother's history
@description: The pregnant woman was already on antiretroviral therapy (ART) at first antenatal care visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "Already on ART at first antenatal care visit":
  exists "Already on ART at first antenatal care visit Condition"
    or exists "Already on ART at first antenatal care visit Observation"
define "Already on ART at first antenatal care visit Condition":
  Elements."Already on ART at first antenatal care visit Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Already on ART at first antenatal care visit Observation":
  Elements."Already on ART at first antenatal care visit Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Already on ART at first antenatal care visit */

/*
@dataElement: HIV.E.DE43 - Newly on ART during pregnancy
@activity: HIV.E1 Capture or update mother's history
@description: The pregnant woman started ART during her pregnancy
*/
// TODO: Replace placeholder with relevant CQL logic
define "Newly on ART during pregnancy":
  exists "Newly on ART during pregnancy Condition"
    or exists "Newly on ART during pregnancy Observation"
define "Newly on ART during pregnancy Condition":
  Elements."Newly on ART during pregnancy Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Newly on ART during pregnancy Observation":
  Elements."Newly on ART during pregnancy Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Newly on ART during pregnancy */

/*
@dataElement: HIV.E.DE44 - Newly on ART during labour and delivery
@activity: HIV.E1 Capture or update mother's history
@description: The woman started ART during labour and delivery
*/
// TODO: Replace placeholder with relevant CQL logic
define "Newly on ART during labour and delivery":
  exists "Newly on ART during labour and delivery Condition"
    or exists "Newly on ART during labour and delivery Observation"
define "Newly on ART during labour and delivery Condition":
  Elements."Newly on ART during labour and delivery Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Newly on ART during labour and delivery Observation":
  Elements."Newly on ART during labour and delivery Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Newly on ART during labour and delivery */

/*
@dataElement: HIV.E.DE46 - Delivery date
@activity: HIV.E1 Capture or update mother's history
@description: Date on which the woman delivered
*/
// TODO: Replace placeholder with relevant CQL logic
define "Delivery date":
  Elements."Delivery date" O
    where O.effective.toInterval() during "Measurement Period"
define "Delivery date Value":
  "Delivery date" O
  return O.value
/* End of Delivery date */

/*
@dataElement: HIV.E.DE67 - Place of delivery
@activity: HIV.E1 Capture or update mother's history
@description: The type of place where the woman delivered
*/
// TODO: Replace placeholder with relevant CQL logic
define "Place of delivery":
  exists (Elements."Place of delivery" P
  where P.performed.toInterval() during "Measurement Period")
/* End of Place of delivery */

/*
@dataElement: HIV.E.DE68 - Health facility
@activity: HIV.E1 Capture or update mother's history
@description: The woman delivered at a health facility
*/
// TODO: Replace placeholder with relevant CQL logic
define "Health facility":
  exists (Elements."Health facility" P
  where P.performed.toInterval() during "Measurement Period")
/* End of Health facility */

/*
@dataElement: HIV.E.DE69 - Home
@activity: HIV.E1 Capture or update mother's history
@description: The woman delivered at home
*/
// TODO: Replace placeholder with relevant CQL logic
define "Home":
  exists (Elements."Health facility" P
  where P.performed.toInterval() during "Measurement Period")
/* End of Home */

/*
@dataElement: HIV.E.DE70 - Other
@activity: HIV.E1 Capture or update mother's history
@description: The woman delivered at another location that is not at home or at a health facility
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other E.DE70":
  exists (Elements."Other E.DE70" P
  where P.performed.toInterval() during "Measurement Period")
/* End of Other E.DE70 */

/*
@dataElement: HIV.E.DE85 - ANC contact date
@activity: HIV.E1 Capture or update mother's history
@description: The date and time of the client's ANC contact (in the ANC DAK this is called 'Contact date')
*/

define "ANC contact date E.DE85":
  exists(Elements."ANC contact date E.DE85" E where E during "Measurement Period")

/* End of ANC contact date E.DE85 */

/*
@dataElement: HIV.E.DE87 - Infant date of birth
@activity: HIV.E1 Capture or update mother's history
@description: The infant's date of birth (DOB) if known
*/
// TODO: Replace placeholder with relevant CQL logic
define "Infant date of birth":
  Elements."Infant date of birth" O
    where O.effective.toInterval() during "Measurement Period"
define "Infant date of birth Value":
  "Infant date of birth" O
  return O.value
/* End of Infant date of birth */

/*
@dataElement: HIV.E.DE90 - Age of infant
@activity: HIV.E1 Capture or update mother's history
@description: Infant age calculated using date of birth
*/
define "Age of infant in days":
  "Infant date of birth Value" bd
    return CalculateAgeInDaysAt(bd, start of "Measurement Period")

define "Age of infant in hours":
  "Infant date of birth Value" bd
    return CalculateAgeInHoursAt(bd, start of "Measurement Period")

define "Age of infant in weeks":
  "Infant date of birth Value" bd 
    return CalculateAgeInWeeksAt(bd, start of "Measurement Period")

define "Age of infant in years":
  "Infant date of birth Value" bd
    return CalculateAgeInYearsAt(bd, start of "Measurement Period")
/* End of Age of infant */

/*
@dataElement: HIV.E.DE112 - HIV-exposed infant or child
@activity: HIV.F6 Check whether infant/child had HIV exposure
@description: Whether the infant or child was determined to have had HIV exposure
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-exposed infant or child E.DE112":
  Elements."HIV-exposed infant or child E.DE112" O
    where O.effective.toInterval() during "Measurement Period"
define "is HIV-exposed infant or child E.DE112":
  exists "HIV-exposed infant or child E.DE112"
/* End of HIV-exposed infant or child E.DE112 */

/*
@dataElement: HIV.E.DE114 - Key population member type
@activity: HIV.E1 Capture or update mother's history
@description: The type of key population that the infant's mother is included in
*/
// TODO: Replace placeholder with relevant CQL logic
define "Is Key population member type E.DE114":
  exists "Key population member type E.DE114 Observation"
define "Key population member type E.DE114 Observation":
  Elements."Key population member type E.DE114 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Key population member type E.DE114 */

/*
@dataElement: HIV.E.DE168 - HIV test type
@activity: HIV.E4 Test mother for HIV using testing algorithm
@description: Type of HIV test
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV test type E.DE168":
  exists "HIV test type E.DE168 Observation"
define "HIV test type E.DE168 Observation":
  Elements."HIV test type E.DE168 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV test type E.DE168 */

/*
@dataElement: HIV.E.DE169 - Rapid diagnostic test for HIV
@activity: HIV.E4 Test mother for HIV using testing algorithm
@description: Antibody test for HIV performed with a rapid diagnostic (RDT)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Rapid diagnostic test for HIV E.DE169":
  exists "Rapid diagnostic test for HIV E.DE169 Condition"
    or exists "Rapid diagnostic test for HIV E.DE169 Observation"
define "Rapid diagnostic test for HIV E.DE169 Condition":
  Elements."Rapid diagnostic test for HIV E.DE169 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Rapid diagnostic test for HIV E.DE169 Observation":
  Elements."Rapid diagnostic test for HIV E.DE169 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Rapid diagnostic test for HIV E.DE169 */

/*
@dataElement: HIV.E.DE170 - Enzyme immunoassay for HIV
@activity: HIV.E4 Test mother for HIV using testing algorithm
@description: Antibody test for HIV performed with an enzyme immunoassay (EIA)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Enzyme immunoassay for HIV E.DE170":
  exists "Enzyme immunoassay for HIV E.DE170 Condition"
    or exists "Enzyme immunoassay for HIV E.DE170 Observation"
define "Enzyme immunoassay for HIV E.DE170 Condition":
  Elements."Enzyme immunoassay for HIV E.DE170 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Enzyme immunoassay for HIV E.DE170 Observation":
  Elements."Enzyme immunoassay for HIV E.DE170 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Enzyme immunoassay for HIV E.DE170 */

/*
@dataElement: HIV.E.DE171 - Nucleic acid test for HIV
@activity: HIV.E4 Test mother for HIV using testing algorithm
@description: Virological test, which includes testing for early infant diagnosis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Nucleic acid test for HIV E.DE171":
  exists "Nucleic acid test for HIV E.DE171 Condition"
    or exists "Nucleic acid test for HIV E.DE171 Observation"
define "Nucleic acid test for HIV E.DE171 Condition":
  Elements."Nucleic acid test for HIV E.DE171 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Nucleic acid test for HIV E.DE171 Observation":
  Elements."Nucleic acid test for HIV E.DE171 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Nucleic acid test for HIV E.DE171 */

/*
@dataElement: HIV.E.DE172 - Dual HIV/syphilis rapid diagnostic test
@activity: HIV.E4 Test mother for HIV using testing algorithm
@description: Antibody test for HIV and syphilis performed with a rapid diagnostic
*/
// TODO: Replace placeholder with relevant CQL logic
define "Dual HIV/syphilis rapid diagnostic test E.DE172":
  exists "Dual HIV/syphilis rapid diagnostic test E.DE172 Condition"
    or exists "Dual HIV/syphilis rapid diagnostic test E.DE172 Observation"
define "Dual HIV/syphilis rapid diagnostic test E.DE172 Condition":
  Elements."Dual HIV/syphilis rapid diagnostic test E.DE172 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Dual HIV/syphilis rapid diagnostic test E.DE172 Observation":
  Elements."Dual HIV/syphilis rapid diagnostic test E.DE172 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Dual HIV/syphilis rapid diagnostic test E.DE172 */

/*
@dataElement: HIV.E.DE173 - Maternal and child health service visit
@activity: HIV.E1 Capture or update mother's history
@description: Maternal and child health service visit attended by an HIV-exposed infant
*/
// TODO: Replace placeholder with relevant CQL logic
define "Maternal and child health service visit":
  exists "Maternal and child health service visit Observation"
define "Maternal and child health service visit Observation":
  Elements."Maternal and child health service visit Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Maternal and child health service visit */

/*
@dataElement: HIV.E.DE174 - 12-month visit
@activity: HIV.E1 Capture or update mother's history
@description: HIV-exposed infant attending MCH services for a 12-month visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "12-month visit":
  exists "12-month visit Condition"
    or exists "12-month visit Observation"
define "12-month visit Condition":
  Elements."12-month visit Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "12-month visit Observation":
  Elements."12-month visit Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of 12-month visit */

/*
@dataElement: HIV.E.DE175 - 24-month visit
@activity: HIV.E1 Capture or update mother's history
@description: HIV-exposed infants attending MCH services for a 24-month visit
*/
// TODO: Replace placeholder with relevant CQL logic
define "24-month visit":
  exists "24-month visit Condition"
    or exists "24-month visit Observation"
define "24-month visit Condition":
  Elements."24-month visit Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "24-month visit Observation":
  Elements."24-month visit Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of 24-month visit */

/*
@dataElement: HIV.E.DE176 - First visit after the end of breastfeeding
@activity: HIV.E1 Capture or update mother's history
@description: HIV-exposed infant attending MCH services for a first visit after the end of breastfeeding
*/
// TODO: Replace placeholder with relevant CQL logic
define "First visit after the end of breastfeeding":
  exists "First visit after the end of breastfeeding Condition"
    or exists "First visit after the end of breastfeeding Observation"
define "First visit after the end of breastfeeding Condition":
  Elements."First visit after the end of breastfeeding Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "First visit after the end of breastfeeding Observation":
  Elements."First visit after the end of breastfeeding Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of First visit after the end of breastfeeding */

/*
@dataElement: HIV.E.DE179 - Registered in birth cohort
@activity: HIV.F3 Capture or update infant's/child's history
@description: Whether the infant has been registered in a birth cohort
*/
// TODO: Replace placeholder with relevant CQL logic
define "Registered in birth cohort":
  exists "Registered in birth cohort Observation"
define "Registered in birth cohort Observation":
  Elements."Registered in birth cohort Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Registered in birth cohort */

/*
@dataElement: HIV.E.DE224 - HIV test date
@activity: HIV.F8 Test infant/child for HIV using testing algorithm
@description: Date of the HIV test
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV test date E.DE224":
  Elements."HIV test date E.DE224" O
    where O.effective.toInterval() during "Measurement Period"
define "HIV test date E.DE224 Value":
  "HIV test date E.DE224" O
  return O.value
/* End of HIV test date E.DE224 */

/*
@dataElement: HIV.E.DE225 - Infant HIV status
@activity: HIV.F8 Test infant/child for HIV using testing algorithm
@description: HIV status reported after applying the HIV testing algorithm. No single HIV test can provide an HIV-positive diagnosis.
*/
// TODO: Replace placeholder with relevant CQL logic
define "Infant HIV status":
  exists "Infant HIV status Observation"
define "Infant HIV status Observation":
  Elements."Infant HIV status Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Infant HIV status */

/*
@dataElement: HIV.E.DE226 - HIV-positive
@activity: HIV.F8 Test infant/child for HIV using testing algorithm
@description: Infant is HIV-positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-positive E.DE226":
  exists "HIV-positive E.DE226 Condition"
    or exists "HIV-positive E.DE226 Observation"
define "HIV-positive E.DE226 Condition":
  Elements."HIV-positive E.DE226 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-positive E.DE226 Observation":
  Elements."HIV-positive E.DE226 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-positive E.DE226 */

/*
@dataElement: HIV.E.DE227 - HIV-negative
@activity: HIV.F8 Test infant/child for HIV using testing algorithm
@description: Infant is HIV-negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-negative E.DE227":
  exists "HIV-negative E.DE227 Condition"
    or exists "HIV-negative E.DE227 Observation"
define "HIV-negative E.DE227 Condition":
  Elements."HIV-negative E.DE227 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-negative E.DE227 Observation":
  Elements."HIV-negative E.DE227 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-negative E.DE227 */

/*
@dataElement: HIV.E.DE228 - Unknown
@activity: HIV.F8 Test infant/child for HIV using testing algorithm
@description: Infant has unknown HIV status
*/
// TODO: Replace placeholder with relevant CQL logic
define "Unknown E.DE228":
  exists "Unknown E.DE228 Condition"
    or exists "Unknown E.DE228 Observation"
define "Unknown E.DE228 Condition":
  Elements."Unknown E.DE228 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Unknown E.DE228 Observation":
  Elements."Unknown E.DE228 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Unknown E.DE228 */

/*
@dataElement: HIV.E.DE229 - Infant ART start date
@activity: HIV.F16 Immediately start infant on ART
@description: The date on which the infant was started or restarted on antiretroviral therapy (ART)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Infant ART start date":
  Elements."Infant ART start date" O
    where O.effective.toInterval() during "Measurement Period"
define "Infant ART start date Value":
  "Infant ART start date" O
  return O.value
/* End of Infant ART start date */

/*
@dataElement: HIV.E.DE230 - Final diagnosis of HIV-exposed infant
@activity: HIV.F20 Record infant's/child's final HIV diagnosis
@description: HIV-exposed infant final status at 18 months or 3 months after cessation of breastfeeding (whichever is later).
*/
// TODO: Replace placeholder with relevant CQL logic
define "Final diagnosis of HIV-exposed infant E.DE230":
  exists "Final diagnosis of HIV-exposed infant E.DE230 Observation"
define "Final diagnosis of HIV-exposed infant E.DE230 Observation":
  Elements."Final diagnosis of HIV-exposed infant E.DE230 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Final diagnosis of HIV-exposed infant E.DE230 */

/*
@dataElement: HIV.E.DE231 - HIV-positive
@activity: HIV.F20 Record infant's/child's final HIV diagnosis
@description: The infant is HIV-positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-positive E.DE231":
  exists "HIV-positive E.DE231 Condition"
    or exists "HIV-positive E.DE231 Observation"
define "HIV-positive E.DE231 Condition":
  Elements."HIV-positive E.DE231 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-positive E.DE231 Observation":
  Elements."HIV-positive E.DE231 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-positive E.DE231 */

/*
@dataElement: HIV.E.DE232 - HIV-negative and no longer breastfeeding
@activity: HIV.F20 Record infant's/child's final HIV diagnosis
@description: The infant is HIV-negative and the mother has quit breastfeeding
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-negative and no longer breastfeeding":
  exists "HIV-negative and no longer breastfeeding Condition"
    or exists "HIV-negative and no longer breastfeeding Observation"
define "HIV-negative and no longer breastfeeding Condition":
  Elements."HIV-negative and no longer breastfeeding Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-negative and no longer breastfeeding Observation":
  Elements."HIV-negative and no longer breastfeeding Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-negative and no longer breastfeeding */

/*
@dataElement: HIV.E.DE233 - HIV status unknown
@activity: HIV.F20 Record infant's/child's final HIV diagnosis
@description: The final HIV status of the child is unknown because the infant died, was lost to follow-up or transferred out without ever having an HIV-positive diagnosis or is active in care but was not tested at 18 months
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV status unknown":
  exists "HIV status unknown Condition"
    or exists "HIV status unknown Observation"
define "HIV status unknown Condition":
  Elements."HIV status unknown Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV status unknown Observation":
  Elements."HIV status unknown Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV status unknown */

/*
@dataElement: HIV.G.DE3 - Baseline CD4 count
@activity: HIV.D20 Diagnostics
@description: CD4 count performed at HIV diagnosis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Baseline CD4 count G.DE3":
  Elements."Baseline CD4 count G.DE3" O
    where O.effective.toInterval() during "Measurement Period"
define "Baseline CD4 count G.DE3 Value":
  "Baseline CD4 count G.DE3" O
  return O.value
/* End of Baseline CD4 count G.DE3 */

/*
@dataElement: HIV.G.DE8 - Date of viral load sample collection
@activity: HIV.D20 Diagnostics
@description: Date and time when the sample was collected to test the client's HIV viral load
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of viral load sample collection G.DE8":
  Elements."Date of viral load sample collection G.DE8" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of viral load sample collection G.DE8 Value":
  "Date of viral load sample collection G.DE8" O
  return O.value
/* End of Date of viral load sample collection G.DE8 */

/*
@dataElement: HIV.G.DE12 - Viral load test result
@activity: HIV.D20 Diagnostics
@description: Result from the viral load test in number of copies/mL
*/
// TODO: Replace placeholder with relevant CQL logic
define "Viral load test result G.DE12":
  Elements."Viral load test result G.DE12" O
    where O.effective.toInterval() during "Measurement Period"
define "Viral load test result G.DE12 Value":
  "Viral load test result G.DE12" O
  return O.value
/* End of Viral load test result G.DE12 */

/*
@dataElement: HIV.G.DE17 - HBsAg test date
@activity: HIV.D20 Diagnostics
@description: Date client was tested for hepatitis B virus (HBV)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HBsAg test date G.DE17":
  Elements."HBsAg test date G.DE17" O
    where O.effective.toInterval() during "Measurement Period"
define "HBsAg test date G.DE17 Value":
  "HBsAg test date G.DE17" O
  return O.value
/* End of HBsAg test date G.DE17 */

/*
@dataElement: HIV.G.DE18 - HBsAg test result
@activity: HIV.D20 Diagnostics
@description: Hepatitis B virus test result (HBsAg)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HBsAg test result G.DE18":
  exists "HBsAg test result G.DE18 Observation"
define "HBsAg test result G.DE18 Observation":
  Elements."HBsAg test result G.DE18 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HBsAg test result G.DE18 */

/*
@dataElement: HIV.G.DE19 - Positive
@activity: HIV.D20 Diagnostics
@description: HBsAg test result was positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive G.DE19":
  exists "Positive G.DE19 Condition"
    or exists "Positive G.DE19 Observation"
define "Positive G.DE19 Condition":
  Elements."Positive G.DE19 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive G.DE19 Observation":
  Elements."Positive G.DE19 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive G.DE19 */

/*
@dataElement: HIV.G.DE20 - Negative
@activity: HIV.D20 Diagnostics
@description: HBsAg test result was negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative G.DE20":
  exists "Negative G.DE20 Condition"
    or exists "Negative G.DE20 Observation"
define "Negative G.DE20 Condition":
  Elements."Negative G.DE20 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative G.DE20 Observation":
  Elements."Negative G.DE20 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative G.DE20 */

/*
@dataElement: HIV.G.DE21 - Indeterminate
@activity: HIV.D20 Diagnostics
@description: HBsAg test result was indeterminate
*/
// TODO: Replace placeholder with relevant CQL logic
define "Indeterminate G.DE21":
  exists "Indeterminate G.DE21 Condition"
    or exists "Indeterminate G.DE21 Observation"
define "Indeterminate G.DE21 Condition":
  Elements."Indeterminate G.DE21 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Indeterminate G.DE21 Observation":
  Elements."Indeterminate G.DE21 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Indeterminate G.DE21 */

/*
@dataElement: HIV.G.DE42 - HCV test date
@activity: HIV.D20 Diagnostics
@description: Date client was tested for hepatitis C virus (HCV antibody, HCV RNA or HCV core antigen)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV test date G.DE42":
  Elements."HCV test date G.DE42" O
    where O.effective.toInterval() during "Measurement Period"
define "HCV test date G.DE42 Value":
  "HCV test date G.DE42" O
  return O.value
/* End of HCV test date G.DE42 */

/*
@dataElement: HIV.G.DE43 - HCV test result
@activity: HIV.D20 Diagnostics
@description: Hepatitis C virus test result (HCV antibody, HCV RNA or HCV core antigen)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV test result G.DE43":
  exists "HCV test result G.DE43 Observation"
define "HCV test result G.DE43 Observation":
  Elements."HCV test result G.DE43 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HCV test result G.DE43 */

/*
@dataElement: HIV.G.DE44 - Positive
@activity: HIV.D20 Diagnostics
@description: HCV test result was positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive G.DE44":
  exists "Positive G.DE44 Condition"
    or exists "Positive G.DE44 Observation"
define "Positive G.DE44 Condition":
  Elements."Positive G.DE44 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive G.DE44 Observation":
  Elements."Positive G.DE44 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive G.DE44 */

/*
@dataElement: HIV.G.DE45 - Negative
@activity: HIV.D20 Diagnostics
@description: HCV test result was negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative G.DE45":
  exists "Negative G.DE45 Condition"
    or exists "Negative G.DE45 Observation"
define "Negative G.DE45 Condition":
  Elements."Negative G.DE45 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative G.DE45 Observation":
  Elements."Negative G.DE45 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative G.DE45 */

/*
@dataElement: HIV.G.DE46 - Indeterminate
@activity: HIV.D20 Diagnostics
@description: HCV test result was indeterminate
*/
// TODO: Replace placeholder with relevant CQL logic
define "Indeterminate G.DE46":
  exists "Indeterminate G.DE46 Condition"
    or exists "Indeterminate G.DE46 Observation"
define "Indeterminate G.DE46 Condition":
  Elements."Indeterminate G.DE46 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Indeterminate G.DE46 Observation":
  Elements."Indeterminate G.DE46 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Indeterminate G.DE46 */

/*
@dataElement: HIV.G.DE47 - HCV viral load test date
@activity: HIV.D20 Diagnostics
@description: Hepatitis C viral load test date
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV viral load test date G.DE47":
  Elements."HCV viral load test date G.DE47" O
    where O.effective.toInterval() during "Measurement Period"
define "HCV viral load test date G.DE47 Value":
  "HCV viral load test date G.DE47" O
  return O.value
/* End of HCV viral load test date G.DE47 */

/*
@dataElement: HIV.G.DE48 - HCV viral load test result
@activity: HIV.D20 Diagnostics
@description: Hepatitis C viral load test result (qualitative)
*/
// TODO: Replace placeholder with relevant CQL logic
define "HCV viral load test result G.DE48":
  exists "HCV viral load test result G.DE48 Observation"
define "HCV viral load test result G.DE48 Observation":
  Elements."HCV viral load test result G.DE48 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HCV viral load test result G.DE48 */

/*
@dataElement: HIV.G.DE49 - Detected
@activity: HIV.D20 Diagnostics
@description: HCV was detected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Detected G.DE49":
  exists "Detected G.DE49 Condition"
    or exists "Detected G.DE49 Observation"
define "Detected G.DE49 Condition":
  Elements."Detected G.DE49 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Detected G.DE49 Observation":
  Elements."Detected G.DE49 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Detected G.DE49 */

/*
@dataElement: HIV.G.DE50 - Not detected
@activity: HIV.D20 Diagnostics
@description: HCV was not detected
*/
// TODO: Replace placeholder with relevant CQL logic
define "Not detected G.DE50":
  exists "Not detected G.DE50 Condition"
    or exists "Not detected G.DE50 Observation"
define "Not detected G.DE50 Condition":
  Elements."Not detected G.DE50 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Not detected G.DE50 Observation":
  Elements."Not detected G.DE50 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Not detected G.DE50 */

/*
@dataElement: HIV.G.DE69 - Syphilis test date
@activity: HIV.D20 Diagnostics
@description: Date of syphilis test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syphilis test date G.DE69":
  Elements."Syphilis test date G.DE69" O
    where O.effective.toInterval() during "Measurement Period"
define "Syphilis test date G.DE69 Value":
  "Syphilis test date G.DE69" O
  return O.value
/* End of Syphilis test date G.DE69 */

/*
@dataElement: HIV.G.DE70 - Syphilis test result
@activity: HIV.D20 Diagnostics
@description: Result from syphilis test
*/
// TODO: Replace placeholder with relevant CQL logic
define "Syphilis test result G.DE70":
  exists "Syphilis test result G.DE70 Observation"
define "Syphilis test result G.DE70 Observation":
  Elements."Syphilis test result G.DE70 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Syphilis test result G.DE70 */

/*
@dataElement: HIV.G.DE71 - Positive
@activity: HIV.D20 Diagnostics
@description: Test result is positive for syphilis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Positive G.DE71":
  exists "Positive G.DE71 Condition"
    or exists "Positive G.DE71 Observation"
define "Positive G.DE71 Condition":
  Elements."Positive G.DE71 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Positive G.DE71 Observation":
  Elements."Positive G.DE71 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Positive G.DE71 */

/*
@dataElement: HIV.G.DE72 - Negative
@activity: HIV.D20 Diagnostics
@description: Test result is negative for syphilis
*/
// TODO: Replace placeholder with relevant CQL logic
define "Negative G.DE72":
  exists "Negative G.DE72 Condition"
    or exists "Negative G.DE72 Observation"
define "Negative G.DE72 Condition":
  Elements."Negative G.DE72 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Negative G.DE72 Observation":
  Elements."Negative G.DE72 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Negative G.DE72 */

/*
@dataElement: HIV.G.DE73 - Inconclusive
@activity: HIV.D20 Diagnostics
@description: Test result is inconclusive
*/
// TODO: Replace placeholder with relevant CQL logic
define "Inconclusive G.DE73":
  exists "Inconclusive G.DE73 Condition"
    or exists "Inconclusive G.DE73 Observation"
define "Inconclusive G.DE73 Condition":
  Elements."Inconclusive G.DE73 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Inconclusive G.DE73 Observation":
  Elements."Inconclusive G.DE73 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Inconclusive G.DE73 */

/*
@dataElement: HIV.H.DE35 - Already knew positive
@activity: HIV.B6 Capture or update client history
@description: The partner or contact of the index case already knew they are HIV-positive
*/

define "Already knew positive":
  exists(Elements."Already knew positive" O where O.issued during "Measurement Period")
/* End of Already knew positive */

/*
@dataElement: HIV.H.DE36 - Newly diagnosed
@activity: HIV.B6 Capture or update client history
@description: The partner or contact of the index case is newly diagnosed as HIV-positive
*/

define "Newly diagnosed":
  exists(Elements."Newly diagnosed" O where O.issued during "Measurement Period")
/* End of Newly diagnosed */

/*
@dataElement: HIV.H.DE37 - Negative
@activity: HIV.B6 Capture or update client history
@description: The partner or contact of the index case is newly diagnosed is HIV-negative
*/

define "Negative H.DE37":
  exists(Elements."Negative H.DE37" O where O.issued during "Measurement Period")
/* End of Negative H.DE37 */

/*
@dataElement: HIV.H.DE41 - HIV treatment outcome
@activity: HIV.H3 Record outreach and result
@description: The outcome for the client which is used for reporting retention/attrition.
*/

define "HIV treatment outcome":
  exists Elements."HIV treatment outcome" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV treatment outcome */

/*
@dataElement: HIV.H.DE42 - Lost to follow-up
@activity: HIV.H3 Record outreach and result
@description: Twenty-eight days or more since last missed appointment 
*/
define "Lost to follow-up":
  Elements."On ART H.DE47" H
   where H.effective starts before end of "Measurement Period"
    and H.effective ends after start of "Measurement Period"
	and not (H.effective ends after (end of "Measurement Period" - Config."LTFU Days"))


define "Is lost to follow-up":
  exists("Lost to follow-up")

/* End of Lost to follow-up */

/*
@dataElement: HIV.H.DE43 - Transferred out
@activity: HIV.H3 Record outreach and result
@description: The client transferred to another facility
*/

define "Has transferred out":
  exists(Elements."Transferred out" t where t ends during "Measurement Period")
/* End of Transferred out */

/*
@dataElement: HIV.H.DE44 - Death documented
@activity: HIV.H3 Record outreach and result
@description: People living with HIV previously on ART who are confirmed to have died from any cause
*/
define "Has death documented":
  Elements."Death documented" before end of "Measurement Period"
/* End of Death documented */

/*
@dataElement: HIV.H.DE45 - Refused stopped treatment
@activity: HIV.H3 Record outreach and result
@description: Client was contacted and confirmed to have stopped ART (reasons may include stigma and discrimination, faith healing, etc.)
*/

define "Refused stopped treatment":
    exists(Elements."Refused stopped treatment" O where O.effective.toInterval() during "Measurement Period")
/* End of Refused stopped treatment */

/*
@dataElement: HIV.H.DE47 - On ART
@activity: HIV.H3 Record outreach and result
@description: Client is currently taking ART 
*/
define "On ART H.DE47":
  exists(Elements."On ART H.DE47" ART
   where ART.effective.toInterval() starts before end of "Measurement Period"
    and (ART.effective.toInterval() ends after start of "Measurement Period")
   )
/* End of On ART H.DE47 */

/*
@dataElement: HIV.H.DE73 - Date ART stopped
@activity: HIV.H3 Record outreach and result
@description: Date on which client stopped ART
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date ART stopped H.DE73":
  Elements."Date ART stopped H.DE73" O
    where O.effective.toInterval() during "Measurement Period"
define "Date ART stopped H.DE73 Value":
  "Date ART stopped H.DE73" O
  return O.value
/* End of Date ART stopped H.DE73 */

/*
@dataElement: HIV.H.DE74 - Reason ART stopped
@activity: HIV.H3 Record outreach and result
@description: Reason why client intentionally stopped ART
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reason ART stopped H.DE74":
  exists "Reason ART stopped H.DE74 Observation"
define "Reason ART stopped H.DE74 Observation":
  Elements."Reason ART stopped H.DE74 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Reason ART stopped H.DE74 */

/*
@dataElement: HIV.H.DE75 - Toxicity/side effects
@activity: HIV.H3 Record outreach and result
@description: Client stopped ART because of toxicity/side effects
*/

define "Toxicity/side effects H.DE75":
  exists([MedicationStatement] MS
    where MS.status in {'stopped'}
    and exists(MS.reasonCode C where C ~ Concepts."On ART - HIV.H.DE47")
    and exists(MS.statusReason R where R ~ Concepts."Toxicity/side effects - HIV.H.DE75")
    and start of MS.effective.toInterval() during "Measurement Period")
/* End of Toxicity/side effects H.DE75 */

/*
@dataElement: HIV.H.DE76 - Severe illness, hospitalization
@activity: HIV.H3 Record outreach and result
@description: Client stopped ART because of severe illness, hospitalization
*/
// TODO: Replace placeholder with relevant CQL logic
define "Severe illness, hospitalization H.DE76":
  exists "Severe illness, hospitalization H.DE76 Condition"
    or exists "Severe illness, hospitalization H.DE76 Observation"
define "Severe illness, hospitalization H.DE76 Condition":
  Elements."Severe illness, hospitalization H.DE76 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Severe illness, hospitalization H.DE76 Observation":
  Elements."Severe illness, hospitalization H.DE76 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Severe illness, hospitalization H.DE76 */

/*
@dataElement: HIV.H.DE77 - Drugs out of stock 
@activity: HIV.H3 Record outreach and result
@description: Client stopped ART because of drugs being out of stock 
*/
// TODO: Replace placeholder with relevant CQL logic
define "Drugs out of stock ":
  exists "Drugs out of stock  Condition"
    or exists "Drugs out of stock  Observation"
define "Drugs out of stock  Condition":
  Elements."Drugs out of stock  Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Drugs out of stock  Observation":
  Elements."Drugs out of stock  Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Drugs out of stock  */

/*
@dataElement: HIV.H.DE78 - Client lacks finances 
@activity: HIV.H3 Record outreach and result
@description: Client stopped ART because client lacked finances 
*/
// TODO: Replace placeholder with relevant CQL logic
define "Client lacks finances ":
  exists "Client lacks finances  Condition"
    or exists "Client lacks finances  Observation"
define "Client lacks finances  Condition":
  Elements."Client lacks finances  Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Client lacks finances  Observation":
  Elements."Client lacks finances  Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Client lacks finances  */

/*
@dataElement: HIV.H.DE79 - Excluded HIV infection in infant
@activity: HIV.H3 Record outreach and result
@description: Client stopped ART because the infant was determined to not have HIV
*/
// TODO: Replace placeholder with relevant CQL logic
define "Excluded HIV infection in infant H.DE79":
  exists "Excluded HIV infection in infant H.DE79 Condition"
    or exists "Excluded HIV infection in infant H.DE79 Observation"
define "Excluded HIV infection in infant H.DE79 Condition":
  Elements."Excluded HIV infection in infant H.DE79 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Excluded HIV infection in infant H.DE79 Observation":
  Elements."Excluded HIV infection in infant H.DE79 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Excluded HIV infection in infant H.DE79 */

/*
@dataElement: HIV.H.DE80 - Other reason for stopping ART
@activity: HIV.H3 Record outreach and result
@description: Client stopped ART for other reason
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other reason for stopping ART H.DE80":
  exists "Other reason for stopping ART H.DE80 Condition"
    or exists "Other reason for stopping ART H.DE80 Observation"
define "Other reason for stopping ART H.DE80 Condition":
  Elements."Other reason for stopping ART H.DE80 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Other reason for stopping ART H.DE80 Observation":
  Elements."Other reason for stopping ART H.DE80 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other reason for stopping ART H.DE80 */

/*
@dataElement: HIV.PRV.DE1 - At elevated risk for HIV acquisition
@activity: HIV.B6 Capture or update client history
@description: Client is at elevated risk for HIV acquisition, defined according to country/programme context
*/
// TODO: Replace placeholder with relevant CQL logic
define "At elevated risk for HIV acquisition PRV.DE1":
  exists(Elements."At elevated risk for HIV acquisition PRV.DE1" O 
  where O.effective.toInterval() during "Measurement Period")
/* End of At elevated risk for HIV acquisition PRV.DE1 */

/*
@dataElement: HIV.PRV.DE2 - HIV prevention intervention
@activity: HIV.B6 Capture or update client history
@description: HIV prevention intervention that client accessed
*/

//(including PrEP, OAMT, NSP, STI services, VMMC) 
define "HIV prevention intervention":
  List<String>{
    if "PrEP service" then 'PrEP' else null,
    if "OAMT" then 'OAMT' else null,
    if "NSP" then 'NSP' else null,
    if "STI services" then 'STI services' else null,
    if "VMMC" then 'VMMC' else null,
    if "Other PRV.DE8" then 'other prevention' else null
  }

  define "HIV.PRV.DE2 - HIV prevention intervention":
    "PrEP service" or "OAMT" or "NSP" or "STI services" or "VMMC" or "Other PRV.DE8"


/* End of HIV prevention intervention */

/*
@dataElement: HIV.PRV.DE3 - PrEP service
@activity: HIV.B6 Capture or update client history
@description: Client accessed PrEP services
*/

define "PrEP service":
  exists(Elements."PrEP service" prep
   where prep.effective.toInterval() during "Measurement Period"
   )
/* End of PrEP service */

/*
@dataElement: HIV.PRV.DE4 - OAMT
@activity: HIV.B6 Capture or update client history
@description: Client accessed opioid agonist maintenance treatment (OAMT) services
*/

define "OAMT":
  exists(Elements."OAMT" t where t during "Measurement Period")
/* End of OAMT */

/*
@dataElement: HIV.PRV.DE5 - NSP
@activity: HIV.B6 Capture or update client history
@description: Client accessed needle-syringe programme (NSP) services
*/

define "NSP":
  exists(Elements."NSP" DUS where DUS.timing.toInterval() during "Measurement Period")
/* End of NSP */

/*
@dataElement: HIV.PRV.DE6 - STI services
@activity: HIV.B6 Capture or update client history
@description: Client accessed sexually transmitted infection (STI) services
*/

define "STI services":
  exists(Elements."STI services" STI where STI.performed.toInterval() during "Measurement Period")
/* End of STI services */

/*
@dataElement: HIV.PRV.DE7 - VMMC
@activity: HIV.B6 Capture or update client history
@description: Client accessed voluntary medical male circumcision (VMMC) services
*/

define "VMMC":
  exists(Elements."VMMC" V where V.performed.toInterval() during "Measurement Period")
/* End of VMMC */

/*
@dataElement: HIV.PRV.DE8 - Other
@activity: HIV.B6 Capture or update client history
@description: Client accessed other HIV prevention services
*/

define "Other PRV.DE8":
  exists(Elements."Other PRV.DE8" O
    where O.effective.toInterval() during "Measurement Period")
/* End of Other PRV.DE8 */

/*
@dataElement: HIV.PRV.DE10 - Date accessed HIV prevention intervention
@activity: HIV.B6 Capture or update client history
@description: Date the client accessed HIV prevention intervention
*/

define "Date accessed HIV prevention intervention":
  exists (Elements."Date accessed HIV prevention intervention" t where t included in "Measurement Period")
/* End of Date accessed HIV prevention intervention */

/*
@dataElement: HIV.PRV.DE11 - HIV status of contact
@activity: HIV.B6 Capture or update client history
@description: The HIV status of the client's contact
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV status of contact":
  exists "HIV status of contact Observation"
define "HIV status of contact Observation":
  Elements."HIV status of contact Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV status of contact */

/*
@dataElement: HIV.PRV.DE12 - HIV-positive
@activity: HIV.B6 Capture or update client history
@description: Client's contact is HIV-positive
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-positive PRV.DE12":
  exists "HIV-positive PRV.DE12 Condition"
    or exists "HIV-positive PRV.DE12 Observation"
define "HIV-positive PRV.DE12 Condition":
  Elements."HIV-positive PRV.DE12 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-positive PRV.DE12 Observation":
  Elements."HIV-positive PRV.DE12 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-positive PRV.DE12 */

/*
@dataElement: HIV.PRV.DE13 - HIV-negative
@activity: HIV.B6 Capture or update client history
@description: Client's contact is HIV-negative
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-negative PRV.DE13":
  exists "HIV-negative PRV.DE13 Condition"
    or exists "HIV-negative PRV.DE13 Observation"
define "HIV-negative PRV.DE13 Condition":
  Elements."HIV-negative PRV.DE13 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "HIV-negative PRV.DE13 Observation":
  Elements."HIV-negative PRV.DE13 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-negative PRV.DE13 */

/*
@dataElement: HIV.PRV.DE14 - Unknown
@activity: HIV.B6 Capture or update client history
@description: Client does not know contact's HIV status
*/
// TODO: Replace placeholder with relevant CQL logic
define "Unknown PRV.DE14":
  exists "Unknown PRV.DE14 Condition"
    or exists "Unknown PRV.DE14 Observation"
define "Unknown PRV.DE14 Condition":
  Elements."Unknown PRV.DE14 Condition" C
    where C.prevalenceInterval() overlaps before "Measurement Period"
      or C.prevalenceInterval() overlaps after "Measurement Period"
define "Unknown PRV.DE14 Observation":
  Elements."Unknown PRV.DE14 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Unknown PRV.DE14 */

/*
@dataElement: HIV.PRV.DE15 - Date injecting equipment provided
@activity: HIV.B21 Offer prevention options
@description: Date client was provided with injecting equipment
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date injecting equipment provided":
  Elements."Date injecting equipment provided" O
    where O.effective.toInterval() during "Measurement Period"
define "Date injecting equipment provided Value":
  "Date injecting equipment provided" O
  return O.value
/* End of Date injecting equipment provided */

/*
@dataElement: HIV.PRV.DE17 - Date OAMT initiated
@activity: HIV.B21 Offer prevention options
@description: Date client initiated opioid agonist maintenance treatment (OAMT)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date OAMT initiated":
  Elements."Date OAMT initiated" O
    where O.effective.toInterval() during "Measurement Period"
define "Date OAMT initiated Value":
  "Date OAMT initiated" O
  return O.value
/* End of Date OAMT initiated */

/*
@dataElement: HIV.PRV.DE20 - Currently on OAMT
@activity: HIV.B6 Capture or update client history
@description: Client is currently on opioid agonist maintenance treatment (OAMT) at reporting date, defined according to country/program to account for medication dispensed and LTFU criterion
*/
// TODO: Replace placeholder with relevant CQL logic
define "Currently on OAMT":
  exists "Currently on OAMT Observation"
define "Currently on OAMT Observation":
  Elements."Currently on OAMT Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Currently on OAMT */

/*
@dataElement: HIV.PRV.DE21 - Retained on OAMT
@activity: HIV.B6 Capture or update client history
@description: Client is retained on opioid agonist maintenance treatment (OAMT) at reporting date, defined according to country/program to account for medication dispensed and LTFU criterion
*/
// TODO: Replace placeholder with relevant CQL logic
define "Retained on OAMT":
  exists "Retained on OAMT Observation"
define "Retained on OAMT Observation":
  Elements."Retained on OAMT Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Retained on OAMT */

/*
@dataElement: HIV.PRV.DE25 - Date of loss to follow-up or OAMT stopped
@activity: HIV.B6 Capture or update client history
@description: Date of loss to follow-up or opioid agonist maintenance treatment (OAMT) stopped
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of loss to follow-up or OAMT stopped":
  Elements."Date of loss to follow-up or OAMT stopped" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of loss to follow-up or OAMT stopped Value":
  "Date of loss to follow-up or OAMT stopped" O
  return O.value
/* End of Date of loss to follow-up or OAMT stopped */

/*
@dataElement: HIV.PRV.DE27 - Date medications prescribed
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Date the client was prescribed medications
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date medications prescribed PRV.DE27":
  Elements."Date medications prescribed PRV.DE27" O
    where O.effective.toInterval() during "Measurement Period"
define "Date medications prescribed PRV.DE27 Value":
  "Date medications prescribed PRV.DE27" O
  return O.value
/* End of Date medications prescribed PRV.DE27 */

/*
@dataElement: HIV.PRV.DE28 - Number of days prescribed
@activity: HIV.C23 Prescribe or administer PrEP or PEP
@description: Days of medication client has been prescribed
*/
// TODO: Replace placeholder with relevant CQL logic
define "Number of days prescribed PRV.DE28":
  Elements."Number of days prescribed PRV.DE28" O
    where O.effective.toInterval() during "Measurement Period"
define "Number of days prescribed PRV.DE28 Value":
  "Number of days prescribed PRV.DE28" O
  return O.value
/* End of Number of days prescribed PRV.DE28 */

/*
@dataElement: HIV.SRV.DE1 - HIV test date
@activity: HIV.F8 Test infant/child for HIV using testing algorithm
@description: Date of the HIV test
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV test date SRV.DE1":
  Elements."HIV test date SRV.DE1" O
    where O.effective.toInterval() during "Measurement Period"
define "HIV test date SRV.DE1 Value":
  "HIV test date SRV.DE1" O
  return O.value
/* End of HIV test date SRV.DE1 */

/*
@dataElement: HIV.SRV.DE2 - HIV test result
@activity: HIV.B7 Test for HIV using testing algorithm
@description: The result from HIV testing after applying the testing algorithm
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV test result SRV.DE2":
  exists "HIV test result SRV.DE2 Observation"
define "HIV test result SRV.DE2 Observation":
  Elements."HIV test result SRV.DE2 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV test result SRV.DE2 */

/*
@dataElement: HIV.SRV.DE3 - Baseline CD4 count
@activity: HIV.D20 Diagnostics
@description: CD4 count performed at HIV diagnosis
*/

define "Baseline CD4 count SRV.DE3":
  Elements."Baseline CD4 count SRV.DE3" O
    where O.effective.toInterval() during "Measurement Period"
define "Baseline CD4 count SRV.DE3 Value":
  "Baseline CD4 count SRV.DE3" O
  return O.value
/* End of Baseline CD4 count SRV.DE3 */

/*
@dataElement: HIV.SRV.DE4 - Date of baseline CD4 count test
@activity: HIV.D20 Diagnostics
@description: Date and time when baseline CD4 count test was conducted
*/

define "Date of baseline CD4 count test SRV.DE4":
  exists(Elements."Date of baseline CD4 count test SRV.DE4" O where O starts during "Measurement Period")
/* End of Date of baseline CD4 count test SRV.DE4 */

/*
@dataElement: HIV.SRV.DE6 - ART start date
@activity: HIV.B8 Provide post-test counselling
@description: The date on which the client started or restarted antiretroviral therapy (ART)
*/
// TODO: Replace placeholder with relevant CQL logic
define "ART start date SRV.DE6":
  Elements."ART start date SRV.DE6" O
    where O.effective.toInterval() during "Measurement Period"
define "ART start date SRV.DE6 Value":
  "ART start date SRV.DE6" O
  return O.value
/* End of ART start date SRV.DE6 */

/*
@dataElement: HIV.SRV.DE7 - Currently pregnant
@activity: HIV.B6 Capture or update client history
@description: Client is currently pregnant
*/
// TODO: Replace placeholder with relevant CQL logic
define "Currently pregnant SRV.DE7":
  exists "Currently pregnant SRV.DE7 Observation"
define "Currently pregnant SRV.DE7 Observation":
  Elements."Currently pregnant SRV.DE7 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Currently pregnant SRV.DE7 */

/*
@dataElement: HIV.SRV.DE12 - Date of viral load sample collection
@activity: HIV.D10 Counsel returning client
@description: Date and time when the sample was collected to test the client's HIV viral load
*/
// TODO: Replace placeholder with relevant CQL logic
define "Date of viral load sample collection SRV.DE12":
  Elements."Date of viral load sample collection SRV.DE12" O
    where O.effective.toInterval() during "Measurement Period"
define "Date of viral load sample collection SRV.DE12 Value":
  "Date of viral load sample collection SRV.DE12" O
  return O.value
/* End of Date of viral load sample collection SRV.DE12 */

/*
@dataElement: HIV.SRV.DE13 - Viral load test result
@activity: HIV.D20 Diagnostics
@description: Result from the viral load test in number of copies/mL
*/
// TODO: Replace placeholder with relevant CQL logic
define "Viral load test result SRV.DE13":
  Elements."Viral load test result SRV.DE13" O
    where O.effective.toInterval() during "Measurement Period"
define "Viral load test result SRV.DE13 Value":
  "Viral load test result SRV.DE13" O
  return O.value
/* End of Viral load test result SRV.DE13 */

/*
@dataElement: HIV.SRV.DE15 - Visit date
@activity: HIV.A2 Gather client details
@description: The date and time of the client's visit
*/

define "Visit date SRV.DE15":
  exists(Elements."Visit date SRV.DE15" E
    where start of E.period.toInterval() during "Measurement Period")
/* End of Visit date SRV.DE15 */

/*
@dataElement: HIV.SRV.DE18 - ANC contact date
@activity: HIV.E1 Capture or update mother's history
@description: The date and time of the client's ANC contact (in the ANC DAK this is called 'Contact date')
*/
// TODO: Replace placeholder with relevant CQL logic
define "ANC contact date SRV.DE18":
  Elements."ANC contact date SRV.DE18" O
    where O.effective.toInterval() during "Measurement Period"
define "ANC contact date SRV.DE18 Value":
  "ANC contact date SRV.DE18" O
  return O.value
/* End of ANC contact date SRV.DE18 */

/*
@dataElement: HIV.SRV.DE20 - HIV-exposed infant or child
@activity: HIV.F6 Check whether infant/child had HIV exposure
@description: Whether the infant or child was determined to have had HIV exposure
*/
// TODO: Replace placeholder with relevant CQL logic
define "HIV-exposed infant or child SRV.DE20":
  exists "HIV-exposed infant or child SRV.DE20 Observation"
define "HIV-exposed infant or child SRV.DE20 Observation":
  Elements."HIV-exposed infant or child SRV.DE20 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of HIV-exposed infant or child SRV.DE20 */

/*
@dataElement: HIV.SRV.DE22 - Final diagnosis of HIV-exposed infant
@activity: HIV.F20 Record infant's/child's final HIV diagnosis
@description: HIV-exposed infant final status at 18 months or 3 months after cessation of breastfeeding (whichever is later).
*/
// TODO: Replace placeholder with relevant CQL logic
define "Final diagnosis of HIV-exposed infant SRV.DE22":
  exists "Final diagnosis of HIV-exposed infant SRV.DE22 Observation"
define "Final diagnosis of HIV-exposed infant SRV.DE22 Observation":
  Elements."Final diagnosis of HIV-exposed infant SRV.DE22 Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Final diagnosis of HIV-exposed infant SRV.DE22 */

/*
@dataElement: HIV.Config.DE19 - Other priority populations
@activity: HIV.Configuration
@description: Other populations of priority of HIV prevention and care in local context (provided during adaptation)
*/
// TODO: Replace placeholder with relevant CQL logic
define "Other priority populations":
  exists "Other priority populations Observation"
define "Other priority populations Observation":
  Elements."Other priority populations Observation" O
    where O.effective.toInterval() during "Measurement Period"
/* End of Other priority populations */

/*
@dataElement: HIV.Config.DE20 - Reporting period end date
@activity: HIV.Configuration
@description: End date of the reporting period
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reporting period end date":
  Elements."Reporting period end date" O
    where O.effective.toInterval() during "Measurement Period"
define "Reporting period end date Value":
  "Reporting period end date" O
  return O.value
/* End of Reporting period end date */

/*
@dataElement: HIV.Config.DE21 - Reporting period start date
@activity: HIV.Configuration
@description: Start date of the reporting period
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reporting period start date":
  Elements."Reporting period start date" O
    where O.effective.toInterval() during "Measurement Period"
define "Reporting period start date Value":
  "Reporting period start date" O
  return O.value
/* End of Reporting period start date */

/*
@dataElement: HIV.Config.DE22 - Reporting date
@activity: HIV.Configuration
@description: Reporting date, for surveys performed on a specific date
*/
// TODO: Replace placeholder with relevant CQL logic
define "Reporting date":
  Elements."Reporting date" O
    where O.effective.toInterval() during "Measurement Period"
define "Reporting date Value":
  "Reporting date" O
  return O.value
/* End of Reporting date */


/*
 * Custom elements and logic for use DT and IND CQL Libraries
 */

Content not shown - (application/elm+xml, size = 3Mb )