Skip to content

Commit 62aaa02

Browse files
authored
Merge pull request #188 from samply/develop_ehds2_cql
Add EHDS2 CQL to develop branch
2 parents 49be488 + a9279d1 commit 62aaa02

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
define InInitialPopulation:

resources/cql/EHDS2_OBSERVATION

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
define ObservationList:
2+
if InInitialPopulation then [Observation] else {} as List<Observation>
3+
4+
// Return the value in the given system for the given Observation
5+
define function ObservationValueCode(observation FHIR.Observation, system_var String):
6+
(observation.value as CodeableConcept).coding.where(system = system_var).code.first()
7+
8+
// Check to see if there are any Observation resources with the
9+
// given system/value pair.
10+
define function ExistsObservationValueCode(system_var String, code_var String):
11+
exists from [Observation] O
12+
where ObservationValueCode(O, system_var) = code_var
13+
14+
// Return the value associated with the extension with the given URL for the given Observation
15+
define function BaseObservationExtensionValue(observation FHIR.Observation, url_var String):
16+
observation.extension.where(url = url_var).value
17+
18+
// Return the value of the Observation extension with the given URL
19+
define function ObservationExtensionValue(observation FHIR.Observation, url_var String):
20+
SensibleString(BaseObservationExtensionValue(observation, url_var))
21+
22+
define function ExistsObservationExtensionValue(url_var String, value_var String):
23+
exists from [Observation] O
24+
where ObservationExtensionValue(O, url_var) = value_var
25+
26+
// Return the pathogen type for the given Observation
27+
define function PathogenCode(observation FHIR.Observation):
28+
ObservationValueCode(observation, 'https://ecdc.amr/pathogen-codes')
29+
30+
// Check to see if there are any Observation resources with the
31+
// given pathogen type.
32+
define function ExistsPathogenCode(code_var String):
33+
ExistsObservationValueCode('https://ecdc.amr/pathogen-codes', code_var)
34+
35+
// Return the antibiotic type for the given Observation
36+
define function AntibioticCode(observation FHIR.Observation):
37+
ObservationValueCode(observation, 'https://ecdc.amr/antibiotic-codes')
38+
39+
// Check to see if there are any Observation resources with the
40+
// given antibiotic type.
41+
define function ExistsAntibioticCode(code_var String):
42+
ExistsObservationValueCode('https://ecdc.amr/antibiotic-codes', code_var)
43+
44+
// Return the resistance type for the given Observation
45+
define function SirCode(observation FHIR.Observation):
46+
ObservationValueCode(observation, 'https://ecdc.amr/sir-codes')
47+
48+
// Check to see if there are any Observation resources with the
49+
// given resistance type.
50+
define function ExistsSirCode(code_var String):
51+
ExistsObservationValueCode('https://ecdc.amr/sir-codes', code_var)
52+
53+
// Return the data source for the given Observation
54+
define function DataSource(observation FHIR.Observation):
55+
ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationDataSource')
56+
57+
// Check to see if there are any Observation resources with the
58+
// given data source.
59+
define function ExistsDataSource(value_var String):
60+
ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationDataSource', value_var)
61+
62+
// Return the isolate ID for the given Observation
63+
define function IsolateId(observation FHIR.Observation):
64+
ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationIsolateId')
65+
66+
// Check to see if there are any Observation resources with the
67+
// given isolate ID.
68+
define function ExistsIsolateId(value_var String):
69+
ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationIsolateId', value_var)
70+
71+
// Return the patient type for the given Observation
72+
define function PatientType(observation FHIR.Observation):
73+
ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationPatientType')
74+
75+
// Check to see if there are any Observation resources with the
76+
// given patient type.
77+
define function ExistsPatientType(value_var String):
78+
ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationPatientType', value_var)
79+
80+
// Return the reference guidelines SIR for the given Observation
81+
define function ReferenceGuidelinesSir(observation FHIR.Observation):
82+
ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationReferenceGuidelinesSIR')
83+
84+
// Check to see if there are any Observation resources with the
85+
// given reference guidelines SIR.
86+
define function ExistsReferenceGuidelinesSir(value_var String):
87+
ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationReferenceGuidelinesSIR', value_var)
88+
89+
// Return the reporting country for the given Observation
90+
define function ReportingCountry(observation FHIR.Observation):
91+
ObservationExtensionValue(observation, 'https://ecdc.amr/fhir/StructureDefinition/ObservationReportingCountry')
92+
93+
// Check to see if there are any Observation resources with the
94+
// given reporting country.
95+
define function ExistsReportingCountry(value_var String):
96+
ExistsObservationExtensionValue('https://ecdc.amr/fhir/StructureDefinition/ObservationReportingCountry', value_var)
97+
98+
// Return the year from the date used for statistics
99+
define function YearDateUsedForStatistics(observation FHIR.Observation):
100+
year from observation.issued
101+
102+
// Return the month from the date used for statistics
103+
define function MonthDateUsedForStatistics(observation FHIR.Observation):
104+
month from observation.issued
105+
106+
// Return the year-month from the date used for statistics
107+
define function YearMonthDateUsedForStatistics(observation FHIR.Observation):
108+
ToString(YearDateUsedForStatistics(observation)) + '-' + ToString(MonthDateUsedForStatistics(observation))
109+
110+
// Return the the date valid from
111+
define function DateValidFrom(observation FHIR.Observation):
112+
ToDate(observation.effective as dateTime)
113+
114+
// Return the year from the date valid from
115+
define function YearDateValidFrom(observation FHIR.Observation):
116+
year from DateValidFrom(observation)
117+
118+
// Return the month from the date valid from
119+
define function MonthDateValidFrom(observation FHIR.Observation):
120+
month from DateValidFrom(observation)
121+
122+
// Return the year-month from the date valid from
123+
define function YearMonthDateValidFrom(observation FHIR.Observation):
124+
ToString(YearDateValidFrom(observation)) + '-' + ToString(MonthDateValidFrom(observation))
125+

resources/cql/EHDS2_PATIENT

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Return the value of the Patient extension with the given URL.
2+
// Return "Unknown" if not available or empty.
3+
define function PatientExtensionValue(url_var String):
4+
SensibleString(Patient.extension.where(url = url_var).value)
5+
6+
// Return gender of patient
7+
define Gender:
8+
SensibleString(Patient.gender)
9+
10+
// Return age of patient, as an integer
11+
define AgeInYears:
12+
ToInteger(PatientExtensionValue('https://ecdc.amr/fhir/StructureDefinition/PatientAge'))
13+
14+
// Round patient age to the nearest multiple of 10 (i/p for a histogram).
15+
// Return result as a string
16+
define AgeClass:
17+
ToString((AgeInYears div 10) * 10)
18+
19+
// Return ID of hospital associated with patient
20+
define HospitalId:
21+
PatientExtensionValue('https://ecdc.amr/fhir/StructureDefinition/PatientHospitalId')
22+
23+
// Return hospital unit type associated with patient
24+
define HospitalUnitType:
25+
PatientExtensionValue('https://ecdc.amr/fhir/StructureDefinition/PatientHospitalUnitType')
26+
27+
// Return laboratory code associated with patient
28+
define LaboratoryCode:
29+
PatientExtensionValue('https://ecdc.amr/fhir/StructureDefinition/PatientLaboratoryCode')
30+

resources/cql/EHDS2_SPECIMEN

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
define SpecimenList:
2+
if InInitialPopulation then [Specimen] else {} as List<Specimen>
3+
4+
// Return the isolate ID for the given Specimen
5+
define function SpecimenIsolateId(specimen FHIR.Specimen):
6+
SensibleString(specimen.id)
7+
8+
// Check to see if there are any Specimen resources with the
9+
// given isolate ID.
10+
define function ExistsSpecimenIsolateId(id_var String):
11+
exists from [Specimen] S
12+
where SpecimenIsolateId(S) = id_var
13+

resources/cql/EHDS2_UTIL

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Return "val" if the supplied string value is sensible.
2+
// Return "Unknown" if null or empty.
3+
define function SensibleString(val String):
4+
if (val is null or val = '' or val = '-')
5+
then 'Unkown'
6+
else val
7+

0 commit comments

Comments
 (0)