-
Notifications
You must be signed in to change notification settings - Fork 18
/
evaluate-measure.sh
executable file
·149 lines (129 loc) · 3.7 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
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
#!/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() {
curl -s "$BASE/Measure/$1/\$evaluate-measure?periodStart=2000&periodEnd=2030"
}
evaluate-measure-list() {
curl -sd '{"resourceType": "Parameters", "parameter": [{"name": "periodStart", "value": "2000"}, {"name": "periodEnd", "value": "2030"}, {"name": "reportType", "value": "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 ;;
esac
done
shift $((OPTIND-1))
BASE=$1
[[ -z "$FILE" ]] && usage
[[ -z "$SUBJECT_TYPE" ]] && SUBJECT_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} ${SUBJECT_TYPE} | post "Measure" | jq -r .id)
if [ "subject-list" = "$REPORT_TYPE" ]; then
echo "Generating a report including the list of matching subjects..."
MEASURE_REPORT=$(evaluate-measure-list ${MEASURE_ID})
COUNT=$(echo $MEASURE_REPORT | jq -r '.group[0].population[0].count')
LIST_REFERENCE=$(echo $MEASURE_REPORT | jq -r '.group[0].population[0].subjectResults.reference')
echo "Found $COUNT subjects that can be found on List $BASE/$LIST_REFERENCE."
echo "The individual subject URLs are:"
for REFERENCE in $(curl -s "$BASE/$LIST_REFERENCE" | jq -r '.entry[].item.reference')
do
echo "$BASE/$REFERENCE"
done
else
echo "Generating a population count report..."
MEASURE_REPORT=$(evaluate-measure ${MEASURE_ID})
COUNT=$(echo $MEASURE_REPORT | jq -r '.group[0].population[0].count')
echo "Found $COUNT subjects."
fi