forked from cqframework/cqf-exercises
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exercises03.cql
314 lines (220 loc) · 5.63 KB
/
Exercises03.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
Operators
Comparisons
Equality vs Equivalence
Arithmetic
Rounding and Exponents
String Manipulation
Date Comparison
Date Arithmetic
Calendar Durations vs UCUM
Duration and Difference
Conditionals
Operator Precedence
*/
library Exercises03
// # String Equality and Equivalence
define "String Equality":
('Abel' = 'abel') is _____
define "String Equivalence":
('Abel' ~ 'abel') is _____
define "String Comparison":
('Abel' < 'abel') is _____
define "String Inequality":
('Abel' != 'abel') is _____
define "String Inequivalence":
('Abel' !~ 'abel') is _____
define "String Equality With Null":
('Abel' = null) is _____
define "String Equivalence With Null":
('Abel' ~ null) is _____
// # Equality vs Equivalence
define T1: { X: 1, Y: null }
define T2: { X: 1, Y: null }
define T3: { X: 1, Y: 2 }
define TEqual:
(T1 = T2) is _____
define TEqualWithNull:
(T2 = T3) is _____
define TEquivalent:
(T2 ~ T3) is _____
define C1:
Code {
code: 'ABC',
display: 'Code ABC',
system: 'http://example.com',
version: '2017-01'
}
define C2:
Code {
code: 'ABC',
display: 'Variant Description',
system: 'http://example.com',
version: '2017-05'
}
define CEqual:
(C1 = C2) is _____
define CEquivalent:
(C1 ~ C2) is _____
// # Arithmetic Operators
define "Standard Precedence":
(2 + 5 * 10 = 52) is _____
define "Force Precedence":
((2 + 5) * 10 = 70) is _____
define "Division Always Results in a Decimal":
(10 / 2 = 5.0) is _____
define "Truncated Divide for Integer Division":
(10 div 2 = 5) is _____
define "Modulo is the Remainder":
(10 mod 2 = 0) is _____
define "Negation":
(-(10) = -10) is _____
define "Absolute Value":
(Abs(-10) = 10) is _____
define "Successor Of":
(successor of 1 = 2) is _____
define "Predecessor Of":
(predecessor of 1 = 0) is _____
define "Minimum Integer":
(minimum Integer = -2147483647 - 1) is _____
define "Maximum Integer":
(maximum Integer = 2147483647) is _____
// # Rounding And Exponents
define "Default Round":
(Round(5.5) = 6) is ____
define "Precision Round":
(Round(5.55, 1) = 5.6) is _____
define "Truncate":
(Truncate(5.5) = 5) is _____
define "Truncate Negative":
(Truncate(-5.5) = -5) is _____
define "Floor":
(Floor(5.5) = 5) is _____
define "Floor Negative":
(Floor(-5.5) = -6) is _____
define "Ceiling":
(Ceiling(5.5) = 6) is _____
define "Ceiling Negative":
(Ceiling(-5.5) = -5) is _____
define "Integer Exponent":
(2 ^ 5 = 25) is _____
define "Decimal Exponent":
(25 ^ 0.5 = 5) is _____
define "Logarithm Base 5":
(Log(25, 5) = 2) is _____
define "Logarithm Base 25":
(Log(5, 25) = 0.5) is _____
define "Natural Logarithm":
(Ln(10) = 2.30258209288405) is _____
define "Exponent":
(Exp(2.30258509288405) = 10) is _____
/*
For the remaining definitions, modify each expression so that it returns true, if it doesn't already
*/
// # String Manipulation
define "String Concatenate":
'AB' + 'CD'
define "String Concatenate With Nulls":
'AB' + null
define "String Null Concatenate":
'AB' & null & 'CD'
define "String Length":
Length('ABCD')
define "String Indexer":
'ABCD'[0]
define "PositionOf":
PositionOf('C', 'ABCDCBA')
define "LastPositionOf":
LastPositionOf('C', 'ABCDCBA')
define "StartsWith":
StartsWith('AB', 'ABCDCBA')
define "EndsWith":
EndsWith('AB', 'ABCDCBA')
define "Matches":
Matches('ABCD', 'AB.*')
define "ReplaceMatches":
ReplaceMatches('ABCD', 'C', 'X')
// # Date Comparisons
define "Date Equal":
@2014-01-15 = @2014-02-15
define "Date Less Than":
@2014-01-15 < @2014-02-15
define "Date Less Or Equal":
@2014-01-15 <= @2014-02-15
define "Same Year As":
@2014-01-15 same year as @2014-02-15
define "Same Year Or Before":
@2012-01-15 same year or before @2014-02-15
define "Before Year Of":
@2012-01-15 before year of @2014-02-15
// # Date Arithmetic
define "Day Quantity":
1 day
define "Years Quantity":
2 years
define "Minutes Quantity":
30 minutes
define "UCUM Days":
1 'd'
define "UCUM Annum":
2 'a'
define "UCUM Minutes":
30 'min'
define "1 Year Ago":
Today() - 1 year
define "Add 30 Minutes":
@2014-02-01T14:30 + 30 minutes
define "Add 24 Months":
@2014 + 24 months
define "Calendar Years Equivalent To UCUM Annum (a)":
1 year ~ 1 'a'
define "Calendar Months Equivalent To UCUM Month (mo)":
1 month ~ 1 'mo'
define "Calendar Weeks Equal To UCUM Weeks (wk)":
1 week = 1 'wk'
define "Calendar Days Equal To UCUM Days (d)":
1 day = 1 'd'
define "Calendar Hours Equal To UCUM Hours (h)":
1 hour = 1 'h'
define "Calendar Minutes Equal To UCUM Minutes (min)":
1 minute = 1 'min'
define "Calendar Seconds Equal To UCUM Seconds (s)":
1 second = 1 's'
define "Calendar Milliseconds Equal To UCUM Milliseconds (ms)":
1 millisecond = 1 'ms'
// # Duration And Difference
define "Duration In Months Between":
duration in months between @2014-01-31 and @2014-02-01
define "Difference In Months Between":
difference in months between @2014-01-31 and @2014-02-01
// # Conditionals
/*
The definitions in this sections are examples, not exercises, no need to modify them to return true
*/
define strength:
10.0 'mg/mL'
define "If Conditional":
if strength.value < 0.1 then
Quantity {
value: strength.value * 1000,
unit: 'mcg' + Substring(strength.unit, 2)
}
else
strength
define unit:
'MG/ACTUAT'
define "Selected Case Conditional":
case unit
when 'MG' then 'mg'
when 'MG/ACTUAT' then 'mg/{actuat}'
when 'MG/HR' then 'mg/h'
when 'MG/ML' then 'mg/mL'
else '{' + unit + '}'
end
define doseFormCode:
316897
define "Conditional Case":
case
when doseFormCode = 316897 then 12.6
else 30
end