-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
207 lines (183 loc) · 6.99 KB
/
index.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo AUC Guidance App</title>
</head>
<body>
<div>
<form id='auc_form' onsubmit="return evaluateFormContent()">
<input type="hidden" id="provider" name="provider">
<table>
<caption>Enter Patient Demographics</caption>
<tr>
<th><label for="gender">Gender</label></th>
<td>
<select name="gender" required>
<option id="male" value="male">Male</option>
<option id="female" value="female">Female</option>
<option id="other" value="other">Other</option>
</select>
</td>
</tr>
<tr>
<th><label for="age">Age</label></th>
<td><input id="age" name="age" required></td>
</tr>
<tr>
<th><label for="indication">Indication</label></th>
<td>
<input id="indications" list="indicationsData" name="indication" required>
<datalist id="indicationsData">
<option id="13213009" value="13213009">congenital heart disease</option>
<option id="25064002" value="25064002">headache</option>
<option id="279039007" value="279039007">lower back pain</option>
<option id="423341008" value="423341008">optic disc edema</option>
<option id="27355003" value="27355003">toothache</option>
</datalist>
</td>
</tr>
<tr>
<th><label for="procedure">Procedure</label></th>
<td>
<input id="orders" list="proceduresData" name="procedure" required>
<datalist id="proceduresData">
<option id="75561" value="75561">cardiac mri</option>
<option id="70450" value="70450">ct scan - no contrast material</option>
<option id="71275" value="71275">cta - with contrast material</option>
<option id="72133" value="72133">lumbar spine ct scan</option>
<option id="70544" value="70544">mra - head</option>
</datalist>
</td>
</tr>
</table>
<input type="submit" value="Evaluate" />
</form>
</div>
<br>
<div>Current rating is:</div><div id='rating'>Waiting for data...</div>
<br>
<div id='button_panel' style='display:none'>
<button id="close_btn" onclick='closeApp()' style='background-color: rgb(255, 95, 95);'>Close App</button>
<button id="update_btn" onclick='updateApp()' style='background-color: rgb(127, 255, 95);'>Update ERH</button>
</div>
<script>let module = {};</script>
<script src="auc.js"></script>
<script src="node_modules/fhirclient/build/fhir-client.js"></script>
<script src="http://wzrd.in/standalone/uuid%2Fv4@latest"></script>
<script>
const QCDSMID = 'G-1011';
let appContext = null;
async function getContext(client) {
const appContextStr = client.state.tokenResponse.appContext || '{}';
appContext = JSON.parse(appContextStr);
const indications = appContext.indications || [-1];
const orders = appContext.orders || [-1];
return {
indication: indications.pop() || -1,
order: orders.pop() || -1,
patient: await client.patient.read(),
user: await client.user.read(),
};
}
function populateForm(context) {
const patient = context.patient;
const then = new Date(patient.birthDate),
now = new Date();
const msPerYear = 365.25 * 24 * 60 * 60 * 1000;
const age = (now.getTime() - then.getTime()) / msPerYear;
document.getElementById('provider').value = context.user.id;
document.getElementById('age').value = Math.round(age);
document.getElementById(context.patient.gender).setAttribute('selected', 1);
if (context.indication !== -1) {
document.getElementById('indications').value = context.indication;
}
if (context.order !== -1) {
document.getElementById('orders').value = context.order;
}
}
function evaluateFormContent() {
document.getElementById('rating').innerText = getRating();
return false; // prevent page refresh
}
function getRating() {
const order = document.getElementById('orders').value;
const reasons = document.getElementById('indications').value;
return evaluate(order, [reasons]);
}
function showRating() {
document.getElementById('rating').innerText = getRating();
}
function showButtons() {
// BONUS: only show these if there's a UI available *to* update.
document.getElementById('button_panel').style.display = 'block';
}
if (typeof FHIR === 'undefined') {
throw new Error('Unable to load the FHIR client. Halting page load.');
}
const messagingHandle = 'demo_auc_guideline_consultation_app';
const targetWindow = window.parent !== window.self ? window.parent : window.opener;
const targetOrigin = 'http://sandbox.cds-hooks.org';
FHIR.oauth2.ready()
.then(getContext)
.then(populateForm)
.then(showRating)
.then(showButtons)
.catch(console.error);
function closeApp() {
targetWindow.postMessage({
messagingHandle,
messageId: uuidv4(),
messageType: 'ui.done'
}, targetOrigin)
}
function addRating(draftOrder, rating) {
// BONUS: make this reuseable elsewhere, or import from a module.
draftOrder.resource.extension = [
{
"url": "http://fhir.org/argonaut/Extension/pama-rating",
"valueCodeableConcept": {
"coding": [
{
"system": "http://fhir.org/argonaut/CodeSystem/pama-rating",
"code": rating
}
]
}
},
{
"url": "http://fhir.org/argonaut/Extension/pama-rating-qcdsm-consulted",
"valueString": QCDSMID
},
{
"url": "http://fhir.org/argonaut/Extension/pama-rating-consult-id",
"valueUri": `urn:${ uuidv4() }`
}
];
}
function applyFormData(draftOrder) {
const orderId = document.getElementById('orders');
const orderText = document.getElementById(orderId.value).innerText;
const indicationId = document.getElementById('indications');
const indicationText = document.getElementById(indicationId.value).innerText;
draftOrder.resource.code.coding[0].code = orderId.value;
draftOrder.resource.code.coding[0].display = orderText;
draftOrder.resource.reasonCode[0].coding[0].code = indicationId.value;
draftOrder.resource.reasonCode[0].coding[0].display = indicationText;
}
function updateApp() {
const draftOrder = appContext.draftOrder;
const rating = getRating();
applyFormData(draftOrder);
addRating(draftOrder, rating);
targetWindow.postMessage({
payload: draftOrder,
messagingHandle,
messageId: uuidv4(),
messageType: 'scratchpad.update'
}, targetOrigin);
closeApp(); // Keep, enable once v3.0 is done.
}
</script>
</body>
</html>