-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path127_ProcedurePerformancePeriod.cql
61 lines (48 loc) · 2.54 KB
/
127_ProcedurePerformancePeriod.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
library ProcedurePerformancePeriod
/*
Based on EXM130
Illustrates determining procedure performance period
*/
using FHIR version '4.0.0'
include FHIRHelpers version '4.0.0' called FHIRHelpers
include MATGlobalCommonFunctions_FHIR4 version '4.0.000' called Global
valueset "Total Colectomy": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1019'
parameter "Measurement Period" Interval<DateTime>
default Interval[@2019-01-01T00:00:00.0, @2020-01-01T00:00:00.0)
context Patient
/*
Consider the Procedure performed element:
http://hl7.org/fhir/STU3/procedure-definitions.html#Procedure.performed_x_
http://hl7.org/fhir/procedure-definitions.html#Procedure.performed_x_
In STU3 it is defined as a choice of dateTime|Period
In R4, it is defined as a choice of dateTime|Period|string|Age|Range
Note that for R4, QI-Core constrains out the "string" type
For STU3, the standard "Normalize Interval" function works:
*/
define "Total Colectomy Performed":
[Procedure: "Total Colectomy"] Colectomy
where Colectomy.status = 'completed'
and Global."Normalize Interval"(Colectomy.performed) starts on or before end of "Measurement Period"
/*
But for R4, we need to expand the "Normalize Interval function to allow for the new types:
*/
define function "Normalize Interval"(choice Choice<FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instant, FHIR.string, FHIR.Age, FHIR.Range>):
case
when choice is FHIR.dateTime then
Interval[FHIRHelpers.ToDateTime(choice as FHIR.dateTime), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]
when choice is FHIR.Period then
FHIRHelpers.ToInterval(choice as FHIR.Period)
when choice is FHIR.instant then
Interval[FHIRHelpers.ToDateTime(choice as FHIR.instant), FHIRHelpers.ToDateTime(choice as FHIR.instant)]
when choice is FHIR.Age then
Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age),
FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age) + 1 year)
when choice is FHIR.Range then
Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).low),
FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).high) + 1 year)
when choice is FHIR.Timing then
Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute a single interval from a Timing type')
when choice is FHIR.string then
Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute an interval from a String value')
else null as Interval<DateTime>
end