-
Notifications
You must be signed in to change notification settings - Fork 24
/
123_TimingWithChoiceElements.cql
37 lines (27 loc) · 1.33 KB
/
123_TimingWithChoiceElements.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
library TimingWithChoiceElements
/*
Based on EXM125, best-practices for resolving timings represented as choice-types
*/
using FHIR version '4.0.0'
include FHIRHelpers version '4.0.0' called FHIRHelpers
include MATGlobalCommonFunctions_FHIR4 version '4.0.000' called Global
valueset "Mammography": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.108.12.1018'
parameter "Measurement Period" Interval<DateTime>
default Interval[@2019-01-01T00:00:00.0, @2020-01-01T00:00:00.0)
context Patient
// Consider the effective element of DiagnosticReport
// http://hl7.org/fhir/diagnosticreport-definitions.html#DiagnosticReport.effective_x_
define "Numerator":
exists (
[DiagnosticReport: "Mammography"] Mammogram
where ( Global."Normalize Interval"(Mammogram.effective) ends 27 months or less before day of end of "Measurement Period" )
and Mammogram.status in { 'final', 'amended', 'corrected', 'appended' }
)
/*
The "Normalize Interval" function accounts for the fact that the data may be provided with either a DateTime or an Interval:
*/
define function "Normalize Interval"(choice Choice<FHIR.dateTime, FHIR.Period>):
if choice is FHIR.dateTime then
Interval[FHIRHelpers.ToDateTime(choice as FHIR.dateTime), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]
else
FHIRHelpers.ToInterval(choice as FHIR.Period)