-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWHOCommon.cql
167 lines (133 loc) · 5.71 KB
/
WHOCommon.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
library WHOCommon
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1'
include FHIRCommon version '4.0.1' called FC
context Patient
define function Official(identifiers List<Identifier>):
singleton from (identifiers I where I.use = 'official')
define function Official(addresses List<Address>):
singleton from (addresses A where A.use = 'official')
define function Official(names List<HumanName>):
singleton from (names N where N.use = 'official')
define function Mobile(contactPoints List<ContactPoint>):
singleton from (contactPoints P where P.use = 'mobile')
define function Only(allergies List<AllergyIntolerance>):
singleton from allergies
define function Only(appointments List<Appointment>):
singleton from appointments
define function Only(careplans List<CarePlan>):
singleton from careplans
define function Only(conditions List<Condition>):
singleton from conditions
define function Only(encounters List<Encounter>):
singleton from encounters
define function Only(immunizations List<Immunization>):
singleton from immunizations
define function Only(medicationrequests List<MedicationRequest>):
singleton from medicationrequests
define function Only(observations List<Observation>):
singleton from observations
define function Only(procedures List<Procedure>):
singleton from procedures
define function Only(serviceRequests List<ServiceRequest>):
singleton from serviceRequests
define function Only(dosages List<Dosage>):
singleton from dosages
define function Only(doses List<FHIR.Dosage.DoseAndRate>):
singleton from doses
define function Earliest(observations List<Observation>):
First(
observations O
sort by issued
)
define function Latest(observations List<Observation>):
Last(
observations O
sort by issued
)
define function MostRecent(observations List<Observation>):
Last(
observations O
sort by issued
)
define function MostRecent(procedures List<Procedure>):
Last(
procedures P
sort by start of FC.ToInterval(performed)
)
define function Lowest(observations List<Observation>):
First(
observations O
sort by (value as FHIR.Quantity)
)
define function Highest(observations List<Observation>):
Last(
observations O
sort by (value as FHIR.Quantity)
)
/*
@description: Returns any WHO core extensions defined on the given resource with the specified id.
@comment: NOTE: Extensions are not the preferred approach, but are used as a way to access
content that is defined by extensions but not yet surfaced in the
CQL model info.
*/
define function Extensions(domainResource DomainResource, id String):
domainResource.extension E
where E.url = ('http://fhir.org/guides/who/core/StructureDefinition/' + id)
return E
/*
@description: Returns the single WHO core extension (if present) on the given resource with the specified id.
@comment: This function uses singleton from to ensure that a run-time exception is thrown if there
is more than one extension on the given resource with the specified id.
*/
define function Extension(domainResource DomainResource, id String):
singleton from "Extensions"(domainResource, id)
/*
@description: Returns any WHO core extensions defined on the given element with the specified id.
@comment: NOTE: Extensions are not the preferred approach, but are used as a way to access
content that is defined by extensions but not yet surfaced in the CQL model info.
*/
define function Extensions(element Element, id String):
element.extension E
where E.url = ('http://fhir.org/guides/who/core/StructureDefinition/' + id)
return E
/*
@description: Returns the single WHO core extension (if present) on the given element with the specified id.
@comment: This function uses singleton from to ensure that a run-time exception is thrown if there
is more than one extension on the given resource with the specified url.
*/
define function Extension(element Element, id String):
singleton from Extensions(element, id)
/*
@description: Returns any WHO core modifier extensions defined on the given resource with the specified id.
@comment: NOTE: Extensions are not the preferred approach, but are used as a way to access
content that is defined by extensions but not yet surfaced in the
CQL model info.
*/
define function ModifierExtensions(domainResource DomainResource, id String):
domainResource.modifierExtension E
where E.url = ('http://fhir.org/guides/who/core/StructureDefinition/' + id)
return E
/*
@description: Returns the single WHO core modifier extension (if present) on the given resource with the specified id.
@comment: This function uses singleton from to ensure that a run-time exception is thrown if there
is more than one extension on the given resource with the specified url.
*/
define function ModifierExtension(domainResource DomainResource, id String):
singleton from ModifierExtensions(domainResource, id)
/*
@description: Returns any WHO core modifier extensions defined on the given element with the specified id.
@comment: NOTE: Extensions are not the preferred approach, but are used as a way to access
content that is defined by extensions but not yet surfaced in the CQL model info.
*/
define function ModifierExtensions(element BackboneElement, id String):
element.modifierExtension E
where E.url = ('http://fhir.org/guides/who/core/StructureDefinition/' + id)
return E
/*
@description: Returns the single WHO core modifier extension (if present) on the given element with the specified id.
@comment: This function uses singleton from to ensure that a run-time exception is thrown if there
is more than one extension on the given resource with the specified url.
*/
define function ModifierExtension(element BackboneElement, id String):
singleton from ModifierExtensions(element, id)