-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
463 lines (363 loc) · 18.3 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
<!DOCTYPE html>
<html>
<head>
<title>Afib Risk</title>
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<script src="jquery.js"></script>
<script src="lodash.js"></script>
<script src="fhir-client.js"></script>
<script src="moment.js"></script>
<script src="fhirAtlas.js"></script>
<script src="popper.js"></script>
<script src="bootstrap.js"></script>
<!-- materialize.css-->
<link href="bootstrap.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">
<style>
</style>
</head>
<body>
<table class="fullWidth explanation">
<tr>
<td class="left">
<span style="font-size: 1.4em;">CHA₂DS₂-VASc Score for Atrial Fibrillation Stroke Risk</span>
<br>
<span class="small">Autofilling medical calculator with information from the EHR </span>
</td>
<td class="left">
<span id="creditsToggle" type="button" data-toggle="modal" data-target="#creditsModal">Credits</span>
<br>
<span id="progress">Loading</span>
</td>
</tr>
</table>
<table id="parent">
<tr>
<td class='parentTd'>
<div id="gTableParent">
<table class='gTable fullWidth'>
<thead>
<tr><th class='thLabel'>Criteria</th><th class='infoFromEHR'>EHR Information</th></tr>
</thead>
<tbody>
<tr>
<td>Age</td>
<td class='center'>
<div class="gfhirAssist" data-component="gAgeAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gAge" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText"><65</span><span class="btnIncrement">0</span></span><input class="btn btn-outline-secondary" type="radio" name="gAge" value=0></label>
<label for="gAge" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">65-74</span><span class="btnIncrement">+1</span></span><input type="radio" name="gAge" value=1></label>
<label for="gAge" data-state="2" class="btn btn-outline-secondary"><span><span class="btnText">>=75</span><span class="btnIncrement">+2</span></span><input type="radio" name="gAge" value=2></label>
</div>
</td>
</tr>
<tr>
<td>Gender</td>
<td class='center'>
<div class="gfhirAssist" data-component="gGenderAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gGender" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText">Male</span><span class="btnIncrement">0</span></span><input type="radio" name="gGender" value=0></label>
<label for="gGender" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">Female</span><span class="btnIncrement">1</span></span><input class="btn btn-outline-secondary" type="radio" name="gGender" value=1></label>
</div>
</td>
</tr>
<tr>
<td>History of CHF</td>
<td class='center'>
<div class="gfhirAssist" data-component="gCHFAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gCHF" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText">No</span><span class="btnIncrement">0</span></span><input class="btn btn-outline-secondary" type="radio" name="gCHF" value=0></label>
<label for="gCHF" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">Yes</span><span class="btnIncrement">+1</span></span><input type="radio" name="gCHF" value=1></label>
</div>
</td>
</tr>
<tr>
<td>History of HTN</td>
<td class='center'>
<div class="gfhirAssist" data-component="gHTNAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gHTN" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText">No</span><span class="btnIncrement">0</span></span><input class="btn btn-outline-secondary" type="radio" name="gHTN" value=0></label>
<label for="gHTN" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">Yes</span><span class="btnIncrement">+1</span></span><input type="radio" name="gHTN" value=1></label>
</div>
</td>
</tr>
<tr>
<td>History of Stroke, TIA, or Thromboembolic Disease</td>
<td class='center'>
<div class="gfhirAssist" data-component="gCVATIAPEDVTAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gCVATIAPEDVT" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText">No</span><span class="btnIncrement">0</span></span><input class="btn btn-outline-secondary" type="radio" name="gCVATIAPEDVT" value=0></label>
<label for="gCVATIAPEDVT" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">Yes</span><span class="btnIncrement">+2</span></span><input type="radio" name="gCVATIAPEDVT" value=2></label>
</div>
</td>
</tr>
<tr>
<td>History of Vascular Disease (PAD, ACS)</td>
<td class='center'>
<div class="gfhirAssist" data-component="gVASCDZAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gVASCDZ" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText">No</span><span class="btnIncrement">0</span></span><input class="btn btn-outline-secondary" type="radio" name="gVASCDZ" value=0></label>
<label for="gVASCDZ" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">Yes</span><span class="btnIncrement">+1</span></span><input type="radio" name="gVASCDZ" value=1></label>
</div>
</td>
</tr>
<tr>
<td>History of Diabetes</td>
<td class='center'>
<div class="gfhirAssist" data-component="gDMAssist">
</div>
</td>
<td class='center'>
<div class="btn-group" data-toggle="buttons">
<label for="gDM" data-state="0" class="btn btn-outline-secondary"><span><span class="btnText">No</span><span class="btnIncrement">0</span></span><input class="btn btn-outline-secondary" type="radio" name="gDM" value=0></label>
<label for="gDM" data-state="1" class="btn btn-outline-secondary"><span><span class="btnText">Yes</span><span class="btnIncrement">+1</span></span><input type="radio" name="gDM" value=1></label>
</div>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td id="calculatedScore"></td>
</tr>
</tbody>
</table>
</div>
</td>
</table>
<div id="creditsModal" class="modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Credits & Disclaimer<img id="logo" src="mi2.png" alt=""></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<td><a href="https://www.ncbi.nlm.nih.gov/pubmed/19762550" target="_blank">CHA₂DS₂-VASc</td>
<td><a href="https://www.ncbi.nlm.nih.gov/pubmed/?term=Lip+GY%5BAuthor%5D" target="_blank">Dr. Gregory Lip</a></td>
</tr>
<tr>
<td>Other projects used</td>
<td>
<a href="https://github.com/smart-on-fhir/client-js">fhir-client.js</a>
<a href="https://getbootstrap.com/">bootstrap</a>
<a href="https://jquery.com/">jquery</a>
<a href="https://underscorejs.org">underscore.js</a>
<a href="https://momentjs.com/">moment.js</a>
<a href="https://popper.js.org/">popper.js</a>
</td>
</tr>
<tr>
<td>A project of</td>
<td><a href="http://mi2.medstarhealth.org/">The MedStar Institute for Innovation</a></td>
</tr>
<tr>
<td>Contribute at</td>
<td><a href="https://github.com/MI2-Labs" target="_blank">MI2's Github</a></td>
</tr>
<tr>
<td>License</td>
<td><a href="https://github.com/MI2-Labs/chadsvasc/License" target="_blank">MIT</a></td>
</tr>
<tr>
<td colspan=2>
A best effort is made to search through the EHR to find matches for different elements of this score. However, a negative search does not necessarily imply absence of that element. Please always check with patient, their family, and the medical record.
</td>
</tr>
<tr>
<td colspan=2>
This app is intended for educational purposes only. It cannot diagnose medical conditions or provide treatment recommendations. This information should not be used for the diagnosis or treatment of any health problem or disease. This information is not intended to replace clinical judgment or guide individual patient care in any manner. The system's authors, developers and distributors assume no responsibility for any erroneous results due to defects in the system. Access to and use of the system is provided without warranty of merchantability or fitness for any particular purpose or any other warranty, express or implied.
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
var myApp = {}
myApp.data = {}
myApp.data.smartPatient = {}
myApp.data.conditions = {}
myApp.data.observations = {}
myApp.deferred = {}
myApp.deferred.smartPatient = $.Deferred()
myApp.deferred.conditions = $.Deferred()
myApp.deferred.observations = $.Deferred()
$.when(myApp.deferred.smartPatient).then(function(){ getAllFHIR(); getObservation() })
$.when(myApp.deferred.conditions, myApp.deferred.observations).then(function(){ render(); $("#progress").html("") })
$(document).ready(function(){
getFHIR()
})
function getFHIR(){
FHIR.oauth2.ready(function (fhirClient) {
myApp.smart = fhirClient;
myApp.patient = fhirClient.patient;
$.when( myApp.patient.read() )
.done(function (data) {
myApp.data.smartPatient = data
myApp.deferred.smartPatient.resolve()
}, function(error){
// alert(JSON.stringify(error))
})
})
}
function getAllFHIR(){
$.when(myApp.patient.api.fetchAll({
type: "Condition"
})
.done(function (data) {
myApp.data.conditions = data
myApp.deferred.conditions.resolve()
}), function(error){ alert(JSON.stringify(error)) });
}
function getObservation(){
$.when(myApp.patient.api.fetchAll({
type: "Observation",
query: {
status: "final",
date: {$gte: moment().subtract(72,"hours").format("YYYY-MM-DDTHH:mm:ssZ")}
}
})
.done(function (data) {
myApp.data.observations = data
myApp.deferred.observations.resolve()
}), function(error){ alert(JSON.stringify(error)) });
}
function render(){
///////////////////////////
var relevants = [
{resource: "conditions", name: "chf", displayForNegativeQuery: "No history of CHF found." },
{resource: "conditions", name: "dm", displayForNegativeQuery: "No history of DM found." },
{resource: "conditions", name: "htn", displayForNegativeQuery: "No history of HTN found." },
{resource: "conditions", name: "vascdz", displayForNegativeQuery: "No history of CVA found." },
{resource: "conditions", name: "cvatiapedvt", displayForNegativeQuery: "No history of CVA found." }
]
var resources = _.groupBy(relevants, function(val,index){ return val.resource })
_.each(resources, function(val,index){
var promiseArray = []
_.each(val, function(v,i){
promiseArray.push( renderUI(v) )
})
$.when.apply($, promiseArray).then(function(){
renderCard.apply(this, arguments);
})
})
function renderUI(incoming){
var dfd = $.Deferred();
if (incoming.resource === "observations"){
var q = fhirAtlasObservation(incoming.name, myApp.data.observations, incoming.typeOfLoinc, incoming.stringOrObj, incoming.firstLastAll, incoming.timeFrameInHours)
dfd.resolve({q:q, incoming:incoming});
}
if (incoming.resource === "conditions"){
var q = fhirAtlasCondition(incoming.name, myApp.data.conditions)
dfd.resolve({q:q, incoming:incoming});
}
return dfd.promise()
}
///////////////////////////
}
function renderCard(){
if (!arguments[0]){ return false; }
var card = arguments[0].incoming.card
var mainArguments = Array.prototype.slice.call(arguments);
var toInsert = ""
_.each(mainArguments, function(val,index){
console.log(val)
if (val.q.length === 0 ){
console.log('g'+_.upperCase(val.incoming.name))
$('label[for=g'+_.upperCase(val.incoming.name)+'][data-state=0]').trigger('click');
$('label[for=g'+_.upperCase(val.incoming.name)+']').addClass('btn-primary');
$('div[data-component=g'+_.upperCase(val.incoming.name)+'Assist]').html( "Not found" )
}else{
$('label[for=g'+_.upperCase(val.incoming.name)+'][data-state=1]').trigger('click');
$('label[for=g'+_.upperCase(val.incoming.name)+']').addClass('btn-primary');
$('div[data-component=g'+_.upperCase(val.incoming.name)+'Assist]').html( val.q.join(", ") )
}
})
//age
var age = moment().diff( moment(myApp.data.smartPatient.birthDate, "YYYY-MM-DD"), "year")
if (age < 65){
$('label[for=gAge][data-state=0]').trigger('click');
$('label[for=gAge]').addClass('btn-primary');
$('div[data-component=gAgeAssist]').html("Age: "+age)
}else if (age >= 65 && age < 75){
$('label[for=gAge][data-state=1]').trigger('click');
$('label[for=gAge]').addClass('btn-primary');
$('div[data-component=gAgeAssist]').html("Age: "+age)
}else if (age >= 75 ){
$('label[for=gAge][data-state=2]').trigger('click');
$('label[for=gAge]').addClass('btn-primary');
$('div[data-component=gAgeAssist]').html("Age: "+age)
}else{
alert("bad age")
}
if (myApp.data.smartPatient.gender === "male"){
$('label[for=gGender][data-state=0]').trigger('click');
$('label[for=gGender]').addClass('btn-primary');
$('div[data-component=gGenderAssist]').html(_.capitalize(myApp.data.smartPatient.gender))
}else if (myApp.data.smartPatient.gender === "female"){
$('label[for=gGender][data-state=1]').trigger('click');
$('label[for=gGender]').addClass('btn-primary');
$('div[data-component=gGenderAssist]').html(_.capitalize(myApp.data.smartPatient.gender))
}else{
alert("bad age")
}
}
$("body").on("change", ".gTable input", function(){ calculatedScore() })
function calculatedScore(){
var score = 0
var $inputs = $(".gTable input:checked")
//only checked
_.each($inputs, function(val,index){
score = score + parseInt( $(val).val() )
})
var $allInputs = $(".gTable input")
var allInputsLength = $allInputs.length
var checkedInputsLength = $inputs.length
var addPhrase = ""
if ((((allInputsLength-1)/2)-checkedInputsLength) !== 0){
addPhrase = "<span class='incomplete'>("+(((allInputsLength-1)/2)-checkedInputsLength)+" incomplete)</span>"
}
var recs = ""
/*
if (score === 0) { recs = "<br/><span>Say Something1</span>" }
else if (score > 0){ recs = "<br/><span>Say Something2</span>" }
else if (score > 1){ recs = "<br/><span>Say Something3</span>" }
*/
$("#calculatedScore").html("<span>Score: "+score+"</span>"+addPhrase+recs)
}
</script>
</body>
</html>