Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Elements.cql naming and error fixes #15

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 130 additions & 27 deletions input/cql/HIVCommon.cql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include HIVConceptsCustom called HCC

parameter "Measurement Period" Interval<Date> default Interval[@2020-01-01, @2020-12-31]
parameter "Measurement Date" Date default @2020-01-01
parameter "Testing Interval" System.Quantity default 3 months
parameter "Intervention Interval" System.Quantity default 7 days

context Patient

Expand All @@ -26,6 +28,10 @@ define "HIV Positive Condition":
where C.clinicalStatus ~ HCC."active"
and exists(C.category CC where CC ~ HCC."encounter-diagnosis")
and C.code ~ HC."HIV-positive - HIV.B.DE116"
sort by start of onset.toInterval()

define "First HIV Positive Condition":
First("HIV Positive Condition")

define "HIV Positive Observation":
[Observation] O
Expand All @@ -51,14 +57,14 @@ define "HIV test resulted":
and O.code ~ HC."Rapid diagnostic test for HIV - HIV.B.DE82"

define "HIV Treatment Active":
[MedicationStatement] MS
where MS.status = 'recorded'
[MedicationStatement] MS
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."On ART - HIV.H.DE47")

sort by effective

define "HIV PREP Active":
[MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."PrEP for HIV prevention")

define "Client is at elevated risk for HIV acquisition":
Expand Down Expand Up @@ -86,7 +92,7 @@ define "PEP Prescribed before start of Measurement Period and Completed":
and MR.intent = 'order'
and MR.medication ~ HC."PEP for HIV prevention"
and MR.authoredOn before end of "Measurement Period"
where (MS.status = 'recorded'
where (MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."PrEP for HIV prevention")
)

Expand All @@ -98,7 +104,7 @@ define "PEP Prescribed during Measurement Period and Completed":
and MR.medication ~ HC."PEP for HIV prevention"
and MR.authoredOn after start of "Measurement Period"
and MR.authoredOn before end of "Measurement Period"
where (MS.status = 'recorded'
where (MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."PrEP for HIV prevention")
)

Expand All @@ -117,15 +123,15 @@ define "HIV Test Positive After PEP Prescribed during Measurement Period":

define "Needle Syringe Dispensed":
[DeviceUseStatement] DUS
with [Observation: HC."Key population member* - HIV.E.DE113"] O
with [Observation: HC."Key population member - HIV.E.DE113"] O
such that DUS.reasonReference.references(O)
and O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."People who inject drugs - HIV.B.DE54"
where DUS.status = 'completed'

define PWID_person:
[Observation: HC."Key population member* - HIV.E.DE113"] O
[Observation: HC."Key population member - HIV.E.DE113"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."People who inject drugs - HIV.B.DE54"
Expand Down Expand Up @@ -297,39 +303,39 @@ define "HIV Status":

define SW:
exists (
[Observation: HC."Key population member* - HIV.E.DE113"] O
[Observation: HC."Key population member - HIV.E.DE113"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."Sex worker - HIV.B.DE51"
)

define MSM:
exists (
[Observation: HC."Key population member* - HIV.E.DE113"] O
[Observation: HC."Key population member - HIV.E.DE113"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."Men who have sex with men"
)

define Trans:
exists (
[Observation: HC."Key population member* - HIV.E.DE113"] O
[Observation: HC."Key population member - HIV.E.DE113"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."Trans and gender-diverse people - HIV.B.DE53"
)

define PWID:
exists (
[Observation: HC."Key population member* - HIV.E.DE113"] O
[Observation: HC."Key population member - HIV.E.DE113"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."People who inject drugs - HIV.B.DE54"
)

define Prisoner:
exists (
[Observation: HC."Key population member* - HIV.E.DE113"] O
[Observation: HC."Key population member - HIV.E.DE113"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."People living in prisons and other closed settings"
Expand All @@ -356,23 +362,23 @@ define "HIV Status":

define Exposure_Occupational:
exists (
[Observation: HC."HIV exposure type*"] O
[Observation: HC."HIV exposure type"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."Occupational"
)

define Exposure_Non_Occupational_violent:
exists (
[Observation: HC."HIV exposure type*"] O
[Observation: HC."HIV exposure type"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."Non-occupational violent"
)

define Exposure_Non_Occupational_consensual_sex:
exists (
[Observation: HC."HIV exposure type*"] O
[Observation: HC."HIV exposure type"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.value ~ HC."Non-occupational consensual sex"
Expand Down Expand Up @@ -424,7 +430,7 @@ exists(

define "PREP Product Oral":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and (MS.medication ~ HC."TDF + FTC - HIV.C.DE18" or
MS.medication ~ HC."TDF - HIV.C.DE19" or
Expand All @@ -434,56 +440,56 @@ exists(

define "PREP Product long-acting device":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and MS.medication ~ HC."Dapivirine vaginal ring DVR - HIV.C.DE22"
)

define "PREP Product long-acting injectable":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and MS.medication ~ HC."CAB-LA - HIV.C.DE23"
)

define "PREP first time":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and exists(MS.statusReason SR where SR ~ HC."First-time user - HIV.C.DE25")
)

define "PREP Continuing user":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and exists(MS.statusReason SR where SR ~ HC."Continuing user")
)

define "PREP Restarting":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and exists(MS.statusReason SR where SR ~ HC."Restarting following a period of not taking PrEP")
)

define "Daily_oral_PrEP":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and exists(MS.dosage.additionalInstruction AI where AI ~ HC."Daily oral PrEP")
)

define "Event_driven_PrEP":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and exists(MS.dosage.additionalInstruction AI where AI ~ HC."Event-driven PrEP 2+1+1")
)

define "other_dosing_PrEP":
exists([MedicationStatement] MS
where MS.status = 'recorded'
where MS.status = 'completed'
and exists(MS.reasonCode C where C ~ HC."Currently on PrEP")
and exists(MS.dosage.additionalInstruction AI where AI ~ HC."Other PrEP dosing type")
)
Expand Down Expand Up @@ -783,7 +789,7 @@ define "VMMC_adverse_event_Intraoperative":
and AE.date = P.performed
where AE.actuality = 'actual'

define "VMMC_adverse_event_Postoperative":
define "VMMC_adverse_event_Postoperative":
[AdverseEvent] AE
with [Procedure] P
such that AE.suspectEntity.instance.references(P) and P.status = 'completed'
Expand All @@ -799,4 +805,101 @@ define "VMMC_adverse_event_Intraoperative":
when exists(VMMC_adverse_event_Intraoperative) then HC."Intraoperative"
when exists(VMMC_adverse_event_Postoperative) then HC."Postoperative"
else null
end
end


define "Partner or contact of an index case":
[Observation: HC."Referred through partner services"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.code ~ HC."Partner or contact of an index case"

define "Drug-injecting partner":
[Observation: HC."Type of contact or partner for partner services"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.code ~ HC."Drug-injecting partner - HIV.B.DE10"

define "Sexual partner":
[Observation: HC."Type of contact or partner for partner services"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.code ~ HC."Sexual partner - HIV.B.DE11"


define "First HIV Treatment":
First("HIV Treatment Active")


define "Time to start ART":
case
when difference in days between start of "First HIV Treatment".effective.toInterval() and start of "First HIV Positive Condition".onset.toInterval() <= 7 then HC."Within 7 days of HIV diagnosis"
when difference in days between start of "First HIV Treatment".effective.toInterval() and start of "First HIV Positive Condition".onset.toInterval() <= 30 then HC."Within 30 days of HIV diagnosis"
when difference in days between start of "First HIV Treatment".effective.toInterval() and start of "First HIV Positive Condition".onset.toInterval() <= 90 then HC."Within 90 days of HIV diagnosis"
else null
end

//HIV status of partner or contact (already known positive, newly diagnosed positive, negative)

define "already known positive":
[Observation: HC."HIV status of partner or contact"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.code ~ HC."Already knew positive"

define "Newly diagnosed":
[Observation: HC."HIV status of partner or contact"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.code ~ HC."Newly diagnosed"

define "Negative - HIV.H.DE37":
[Observation: HC."HIV status of partner or contact"] O
where O.status in { 'final', 'amended', 'corrected' }
and exists(O.category OC where OC ~ HCC."social-history")
and O.code ~ HC."Negative - HIV.H.DE37"

define "HIV status of partner or contact":
case
when exists("already known positive") then HC."Already knew positive"
when exists("Newly diagnosed") then HC."Newly diagnosed"
when exists("Negative - HIV.H.DE37") then HC."Negative - HIV.H.DE37"
else null
end


//need to define
define STI_testing:
[Procedure] P
where P.status = 'completed'
and P.code ~ HC."STI testing and treatment services"


//(including PrEP, OAMT, NSP, STI services, VMMC)
define "HIV prevention intervention":
List<String>{
if exists("HIV PREP Active") then 'PrEP' else null,
if OAMT_initiated then 'OAMT' else null,
if exists("Needle Syringe Dispensed") then 'NSP' else null,
if exists(STI_testing) then 'STI services' else null,
if exists(VMMC_done) then 'VMMC' else null
}

define "Negative Tests within Measurement Period":
"HIV Negative Observation" O
with "Client is at elevated risk for HIV acquisition" HIV
such that O.hasMember.references(HIV)
and O.issued after start of "Measurement Period"
and O.issued before end of "Measurement Period"
sort by issued

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

define "Negative Tests after First Negative Test":
"HIV Negative Observation" O
with "Client is at elevated risk for HIV acquisition" HIV
such that O.hasMember.references(HIV)
where O.issued after "First Negative Test within Measurement Period".issued
and O.issued before ("First Negative Test within Measurement Period".issued + "Testing Interval")
sort by issued
Loading
Loading