Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.
Merged
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
142 changes: 103 additions & 39 deletions CRD-DTR/RemsDrugs/R4/files/RemsDrugsPrepopulation-0.1.0.cql
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,124 @@ include DTRHelpers version '0.1.0' called DTR
codesystem "ICD-10-CM": 'http://hl7.org/fhir/sid/icd-10-cm'
codesystem "LOINC": 'http://loinc.org'
codesystem "SNOMED-CT": 'http://snomed.info/sct'
codesystem "RXNORM": 'http://www.nlm.nih.gov/research/umls/rxnorm'

valueset "OrganTransplantHistoryValueSet": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.81'
valueset "OrganTransplantProcedureValueSet": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.90'
valueset "ImmunosuppressiveMedicationValueSet": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.192'
valueset "ImmunosuppressiveSupportiveMedicationValueSet": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.193'

valueset "HepaticMedicalHistory": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.198'
valueset "TuralioValueSet": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.197'

code "29463-7": '29463-7' from "LOINC"
code "2183102": '2183102' from "RXNORM"
code "AST": '1920-8' from "LOINC"
code "ALT": '1742-6' from "LOINC"
code "GGT": '2324-2' from "LOINC"
code "TotalBilirubin": '1975-2' from "LOINC"
code "DirectBilirubin": '1968-7' from "LOINC"
code "ALP": '13874-3' from "LOINC"
code "Albumin": '1751-7' from "LOINC"
code "PT": '5902-2' from "LOINC"

parameter medication_request MedicationRequest
parameter medication_dispense MedicationDispense

context Patient

define "QualifyingTransplant": [Condition: "OrganTransplantHistoryValueSet"]

define "QualifyingTransplantProcedures": [Procedure: "OrganTransplantProcedureValueSet"]

define "QualifyingTransplantCodings": DTR.CodesFromConditions("QualifyingTransplant") union DTR.CodesFromProcedures("QualifyingTransplantProcedures")

// get the first transplant date
define "TransplantDate":
if exists("QualifyingTransplant") then First("QualifyingTransplant").recordedDate.value
else First("QualifyingTransplantProcedures").performed.value union First("QualifyingTransplantProcedures").performed.start.value

// Get all medication related information
define "MedicationCodingFromParameter": Coalesce(medication_request.medication.coding, medication_dispense.medication.coding)

define MedicationCoding: singleton from (
"MedicationCodingFromParameter" CODING
where CODING in "ImmunosuppressiveMedicationValueSet"
or CODING in "ImmunosuppressiveSupportiveMedicationValueSet")

define "MedicationName": MedicationCoding.display.value

define "MedicationCode" : MedicationCoding.code.value
// get observations
define "WeightList": [Observation: "29463-7"]
define "LatestWeight": CDS.MostRecent(CDS.WithUnit(CDS.Verified("WeightList"),'mg'))
define "LatestWeightResult": DTR.GetObservationValue("LatestWeight")

define "MedicationDosage": Coalesce(medication_request.dosageInstruction[0], medication_dispense.dosageInstruction[0])
define "Turalio": [MedicationStatement: "TuralioValueSet"]
define "TakingTuralio": exists("Turalio")
define "TuralioDate":
if "TakingTuralio"
then First("Turalio").effective.value
else
null

define "MedicationDoseAndRate": MedicationDosage.doseAndRate[0]
define "LatestAST": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "AST"]), 'U/L'))
define "ASTResult": (convert DTR.GetObservationValue("LatestAST") to String) + ' U/L'
define "ASTDate":
if exists("LatestAST")
then "LatestAST".issued.value
else
null

define "MedicationDoseWithUnit": ToString(MedicationDoseAndRate.dose.value.value) + ' ' + MedicationDoseAndRate.dose.unit.value
define "LatestALT": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "ALT"]), 'U/L'))
define "ALTResult": (convert DTR.GetObservationValue("LatestALT") to String) + ' U/L'
define "ALTDate":
if exists("LatestALT")
then "LatestALT".issued.value
else
null

define "MedicationRoute": MedicationDosage.route.coding[0].display.value
define "LatestGGT": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "GGT"]), 'U/L'))
define "GGTResult": (convert DTR.GetObservationValue("LatestGGT") to String) + ' U/L'
define "GGTDate":
if exists("LatestGGT")
then "LatestGGT".issued.value
else
null

define "MedicationFrequency" : ToString(MedicationDosage.timing.repeat.frequency.value) + ' per ' + ToString(MedicationDosage.timing.repeat.period.value) + '' + MedicationDosage.timing.repeat.periodUnit.value
define "LatestTotalBilirubin": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "TotalBilirubin"]), 'mg/dL'))
define "TotalBilirubinResult": (convert DTR.GetObservationValue("LatestTotalBilirubin") to String) + ' mg/dL'
define "TotalBilirubinDate":
if exists("LatestTotalBilirubin")
then "LatestTotalBilirubin".issued.value
else
null

define CurrentDiagnoses:
DTR.CodesFromConditions(CDS.Confirmed(CDS.ActiveOrRecurring([Condition]))) except QualifyingTransplant
define "LatestDirectBilirubin": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "DirectBilirubin"]), 'mg/dL'))
define "DirectBilirubinResult": (convert DTR.GetObservationValue("LatestDirectBilirubin") to String) + ' mg/dL'
define "DirectBilirubinDate":
if exists("LatestDirectBilirubin")
then "LatestDirectBilirubin".issued.value
else
null

define "MedicationQuantity": Coalesce(medication_dispense.quantity.value, medication_request.dispenseRequest.quantity.value.value)
define "LatestALP": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "ALP"]), 'U/L'))
define "ALPResult": (convert DTR.GetObservationValue("LatestALP") to String) + ' U/L'
define "ALPDate":
if exists("LatestALP")
then "LatestALP".issued.value
else
null

define "MedicationRefill":
if medication_request.dispenseRequest is not null
then medication_request.dispenseRequest.numberOfRepeatsAllowed.value
define "LatestAlbumin": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "Albumin"]), 'g/dL'))
define "AlbuminResult": (convert DTR.GetObservationValue("LatestAlbumin") to String) + ' g/dL'
define "AlbuminDate":
if exists("LatestAlbumin")
then "LatestAlbumin".issued.value
else
null
null

define "IsMedicationRequest": medication_request.id is not null
define "LatestPT": CDS.MostRecent(CDS.WithUnit(CDS.Verified([Observation: "PT"]), 's'))
define "PTResult": (convert DTR.GetObservationValue("LatestPT") to String) + ' s'
define "PTDate":
if exists("LatestPT")
then "LatestPT".issued.value
else
null

define "MedList": [MedicationStatement] M
where M.status.value = 'active'

define "TakingMeds": not exists("MedList")
define function GetMedicationsTupleList(MedStatementList List<MedicationStatement>):
distinct(
flatten(
MedStatementList MedStatement
let MedicationList:
(MedStatement.medication.coding) CODING
return (FHIRHelpers.ToCode(CODING).display + ' - ' + FHIRHelpers.ToCode(CODING).code)

return MedicationList
)
)
define "Meds": GetMedicationsTupleList(MedList)
define "MedsString":
Meds M
aggregate Result starting '': Result + ', ' + M

define "MedicalHistoryList": [Condition: "HepaticMedicalHistory"]
define "MedicalHistory": DTR.CodesFromConditions(CDS.Confirmed("MedicalHistoryList"))
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
}
]
},
{
"type": "Condition",
"codeFilter": [
{
"path": "code",
"valueSet": "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.198"
}
]
},
{
"type": "Procedure",
"codeFilter": [
Expand All @@ -63,6 +72,18 @@
"valueSet": "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.193"
}
]
},
{
"type": "Observation"
},
{
"type": "MedicationStatement",
"codeFilter": [
{
"path": "code",
"valueSet": "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1219.197"
}
]
}
],
"content": [
Expand Down
Loading