-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathevaluate-measure.sh
More file actions
executable file
·150 lines (131 loc) · 3.99 KB
/
evaluate-measure.sh
File metadata and controls
executable file
·150 lines (131 loc) · 3.99 KB
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
#!/bin/bash
set -euo pipefail
# 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-identifier",
"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() {
curl -s "$base/Measure/$1/\$evaluate-measure?periodStart=2000&periodEnd=2030"
}
evaluate-measure-list() {
curl -sd '{"resourceType": "Parameters", "parameter": [{"name": "periodStart", "valueDate": "2000"}, {"name": "periodEnd", "valueDate": "2030"}, {"name": "reportType", "valueCode": "subject-list"}]}' \
-H "Content-Type: application/fhir+json" "$base/Measure/$1/\$evaluate-measure"
}
usage()
{
echo "Usage: $0 -f QUERY_FILE [ -t subject-type ] [ -r report-type ] base"
echo ""
echo "Example subject-types: Patient, Specimen; default is Patient"
echo "Possible report-types: subject-list, population; default is population"
exit 2
}
unset file subject_type report_type base
while getopts 'f:t:r:' c
do
case ${c} in
f) file=$OPTARG ;;
t) subject_type=$OPTARG ;;
r) report_type=$OPTARG ;;
*) usage ;;
esac
done
shift $((OPTIND-1))
base=$1
[[ -z "$file" ]] && usage
[[ -z "$subject_type" ]] && subject_type="Patient"
[[ -z "$base" ]] && usage
subject_type_lower=$(echo $subject_type | tr '[:upper:]' '[:lower:]')
data=$(base64 < "$file" | 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} ${subject_type} | post "Measure" | jq -r .id | tr -d '\r')
if [ "subject-list" = "$report_type" ]; then
echo "Generating a report including the list of matching ${subject_type_lower}s..."
measure_report=$(evaluate-measure-list ${measure_id})
count=$(echo $measure_report | jq -r '.group[0].population[0].count' | tr -d '\r')
list_reference=$(echo $measure_report | jq -r '.group[0].population[0].subjectResults.reference' | tr -d '\r')
list_id=$(echo $list_reference | cut -d '/' -f2)
echo "Found $count ${subject_type_lower}s that can be found on List $base/$list_reference."
echo ""
echo "Please use the following blazectl command to download the ${subject_type_lower}s:"
echo " blazectl download --server $base $subject_type -q '_list=$list_id' -o ${subject_type_lower}s.ndjson"
else
echo "Generating a population count report..."
measure_report=$(evaluate-measure ${measure_id})
count=$(echo $measure_report | jq -r '.group[0].population[0].count' | tr -d '\r')
echo "Found $count ${subject_type_lower}s."
fi