-
Notifications
You must be signed in to change notification settings - Fork 18
/
evaluate-measure.sh
executable file
·124 lines (106 loc) · 2.45 KB
/
evaluate-measure.sh
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
#!/usr/bin/env bash
# Usage: ./evaluate-measure.sh -f <query>.cql <server-base>
# Takes a CQL file, creates a Library resource from it, references that from a
# Measure resource and calls $evaluate-measure on it.
library() {
cat <<END
{
"resourceType": "Library",
"status": "active",
"type" : {
"coding" : [
{
"system": "http://terminology.hl7.org/CodeSystem/library-type",
"code" : "logic-library"
}
]
},
"content": [
{
"contentType": "text/cql"
}
]
}
END
}
measure() {
cat <<END
{
"resourceType": "Measure",
"status": "active",
"subjectCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/resource-types",
"code": "Patient"
}
]
},
"scoring": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-scoring",
"code": "cohort"
}
]
},
"group": [
{
"population": [
{
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-population",
"code": "initial-population"
}
]
},
"criteria": {
"language": "text/cql",
"expression": "InInitialPopulation"
}
}
]
}
]
}
END
}
create-library() {
library | jq -cM ".url = \"urn:uuid:$1\" | .content[0].data = \"$2\""
}
create-measure() {
measure | jq -cM ".url = \"urn:uuid:$1\" | .library[0] = \"urn:uuid:$2\" | .subjectCodeableConcept.coding[0].code = \"$3\""
}
post() {
curl -sH "Content-Type: application/fhir+json" -d @- "${BASE}/$1"
}
evaluate-measure() {
time curl -s "${BASE}/Measure/$1/\$evaluate-measure?periodStart=2000&periodEnd=2019"
}
usage()
{
echo "Usage: $0 -f QUERY_FILE [ -t type ] BASE"
exit 2
}
unset FILE TYPE BASE
while getopts 'f:t:' c
do
case ${c} in
f) FILE=$OPTARG ;;
t) TYPE=$OPTARG ;;
esac
done
shift $((OPTIND-1))
BASE=$1
[[ -z "$FILE" ]] && usage
[[ -z "$TYPE" ]] && TYPE="Patient"
[[ -z "$BASE" ]] && usage
DATA=$(cat ${FILE} | base64 | tr -d '\n')
LIBRARY_URI=$(uuidgen | tr '[:upper:]' '[:lower:]')
MEASURE_URI=$(uuidgen | tr '[:upper:]' '[:lower:]')
create-library ${LIBRARY_URI} ${DATA} | post "Library" > /dev/null
MEASURE_ID=$(create-measure ${MEASURE_URI} ${LIBRARY_URI} ${TYPE} | post "Measure" | jq -r .id)
COUNT=$(evaluate-measure ${MEASURE_ID} | jq ".group[0].population[0].count")
echo "Count: ${COUNT}"