forked from cqframework/cqf-exercises
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exercises09.cql
104 lines (88 loc) · 3.57 KB
/
Exercises09.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
94
95
96
97
98
99
100
101
102
103
104
/*
Patterns
Primitives
Choices
Slices
Simple Extensions
Complex Extensions
QI Core Patterns
Negation Patterns
CPG Patterns
*/
library Exercises09
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" display 'American Indian or Alaska Native'
code "Alaska Native": '1735-0' from "CDC Race and Ethnicity Codes" display 'Alaska Native'
code "Blood pressure": '85354-9' from "LOINC" display 'Blood pressure panel with all children optional'
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
/*
Update this library to use FHIRHelpers and simplify the expressions to take advantage of the
implicit conversions in FHIRHelpers
This includes deleting the ToQuantity, ToCode and ToConcept functions at the end
of this library, they are provided implicitly as part of FHIRHelpers and the
conversions.
*/
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 ToCode(O.value as FHIR.Coding)) contains "American Indian or Alaska Native"
and (detailed O return ToCode(O.value as FHIR.Coding)) contains "Alaska Native"
define function ToQuantity(quantity FHIR.Quantity):
if quantity is null then
null
else
System.Quantity { value: quantity.value.value, unit: quantity.code.value }
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
}