-
Notifications
You must be signed in to change notification settings - Fork 24
/
131_FHIR.cql
93 lines (78 loc) · 3.36 KB
/
131_FHIR.cql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
library TestFHIR
using FHIR version '4.0.1'
codesystem "LOINC": 'http://loinc.org'
codesystem "Marital Status Codes": 'http://terminology.hl7.org/CodeSystem/v3-MaritalStatus'
codesystem "CDC Race and Ethnicity Codes": 'urn:oid:2.16.840.1.113883.6.238'
valueset "Marital Status": 'http://hl7.org/fhir/ValueSet/marital-status'
code "Marital Status - Married": 'M' from "Marital Status Codes"
code "American Indian or Alaska Native": '1002-5' from "CDC Race and Ethnicity Codes"
code "Alaska Native": '1735-0' from "CDC Race and Ethnicity Codes"
code "Blood pressure": '85354-9' from "LOINC" display 'blood pressure'
code "Diastolic blood pressure": '8462-4' from "LOINC" display 'Diastolic blood pressure'
code "Systolic blood pressure": '8480-6' from "LOINC" display 'Systolic blood pressure'
context Patient
define TestPrimitives:
Patient P
where P.gender.value = 'male'
and P.active.value is true
and P.birthDate.value before Today()
and ToConcept(P.maritalStatus) in "Marital Status"
and ToConcept(P.maritalStatus) ~ "Marital Status - Married"
define TestChoice:
Patient P
where (P.deceased as FHIR.boolean).value is false
or (P.deceased as FHIR.dateTime).value before Today()
define TestSlices:
[Observation: "Blood pressure"] BP
let
SystolicBP: singleton from (BP.component C where ToConcept(C.code) ~ "Systolic blood pressure"),
DiastolicBP: singleton from (BP.component C where ToConcept(C.code) ~ "Diastolic blood pressure")
where ToQuantity(SystolicBP.value as FHIR.Quantity) < 140 'mm[Hg]'
and ToQuantity(DiastolicBP.value as FHIR.Quantity) < 90 'mm[Hg]'
define TestSimpleExtensions:
Patient P
let birthsex: singleton from (P.extension E
where E.url.value = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex')
where (birthsex.value as FHIR.code).value = 'M'
define TestComplexExtensions:
Patient P
let
race: singleton from (P.extension E
where E.url.value = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race'),
ombCategory: race.extension E where E.url.value = 'ombCategory',
detailed: race.extension E where E.url.value = 'detailed'
where (ombCategory O return ToConcept(O.value as FHIR.CodeableConcept)) contains "American Indian or Alaska Native"
and (detailed O return ToConcept(O.value as FHIR.CodeableConcept)) contains "Alaska Native"
define function ToInterval(period FHIR.Period):
if period is null then
null
else
Interval[period."start".value, period."end".value]
define function ToQuantity(quantity FHIR.Quantity):
if quantity is null then
null
else
System.Quantity { value: quantity.value.value, unit: quantity.unit.value }
define function ToInterval(range FHIR.Range):
if range is null then
null
else
Interval[ToQuantity(range.low), ToQuantity(range.high)]
define function ToCode(coding FHIR.Coding):
if coding is null then
null
else
System.Code {
code: coding.code.value,
system: coding.system.value,
version: coding.version.value,
display: coding.display.value
}
define function ToConcept(concept FHIR.CodeableConcept):
if concept is null then
null
else
System.Concept {
codes: concept.coding C return ToCode(C),
display: concept.text.value
}