-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmar.html
More file actions
274 lines (246 loc) · 14.3 KB
/
mar.html
File metadata and controls
274 lines (246 loc) · 14.3 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.7, maximum-scale=0.7, user-scalable=0">
<title>MAR</title>
<script type="text/javascript">
function lookupGET(val) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === val) result = decodeURIComponent(tmp[1]);
}
return result;
}
/* parameters that should be changed */
var item_id_to_give = parseInt( lookupGET('item_id') ) || 0;
var mar_rows = [];
var row_number = 1;
while (true) {
if (lookupGET('row' + row_number + 'order')) {
var row = {};
row.order = lookupGET('row' + row_number + 'order') || '';
row.time = lookupGET('row' + row_number + 'time') || '';
row.dose = parseFloat( lookupGET('row' + row_number + 'dose') ) || 0;
row.item_id = parseInt( lookupGET('row' + row_number + 'item') ) || 0;
row.static = lookupGET('row' + row_number + 'static') === 'true';
mar_rows.push(row);
} else {
break;
}
row_number++;
}
var administer_mode = lookupGET('administer_mode') === 'true';
var name = lookupGET('name' ) || '';
var dob = lookupGET('dob' ) || '';
var weight = lookupGET('weight' ) || '';
var mr = lookupGET('mr' ) || '';
var provider = lookupGET('provider' ) || '';
var allergies = lookupGET('allergies') || '';
/* end of parameters */
var ARIS = {};
function float_equal(a, b) {
return Math.abs(a - b) < 0.0001;
}
function createHTMLNode(html) {
var div = document.createElement('div');
div.innerHTML = html;
return div;
}
function appReady() {
FastClick.attach(document.body);
var mar = document.getElementById('the-mar');
for (var i = 0; i < mar_rows.length; i++) {
var row = mar_rows[i];
var tr = document.createElement('tr');
tr.classList.add(i % 2 === 0 ? 'row-even' : 'row-odd');
var td1 = document.createElement('td');
td1.appendChild(createHTMLNode(row.order));
tr.appendChild(td1);
var td2 = document.createElement('td');
td2.appendChild(createHTMLNode(row.time));
tr.appendChild(td2);
if (administer_mode) {
var td3 = document.createElement('td');
td3.appendChild(createHTMLNode(row.dose));
tr.appendChild(td3);
var td4 = document.createElement('td');
if (!(row.static) && ARIS.cache.getPlayerItemCount(row.item_id) > 0) {
var input = document.createElement('input');
input.type = 'checkbox';
td4.appendChild(input);
}
tr.appendChild(td4);
} else {
var td3 = document.createElement('td');
if (row.static) {
td3.appendChild(createHTMLNode(row.dose));
} else {
var input = document.createElement('input');
input.type = 'text';
td3.appendChild(input);
}
tr.appendChild(td3);
}
mar.appendChild(tr);
}
if (!administer_mode) {
document.getElementById('the-administered-header').remove();
}
document.getElementById('the-name' ).textContent = name;
document.getElementById('the-dob' ).textContent = dob;
document.getElementById('the-weight' ).textContent = weight;
document.getElementById('the-mr' ).textContent = mr;
document.getElementById('the-provider' ).textContent = provider;
document.getElementById('the-allergies').textContent = allergies;
}
function check() {
var tracking_items = [];
for (var i = 0; i < mar_rows.length; i++) {
var row = mar_rows[i];
if (row.static) {
continue;
}
var dom_row = document.getElementsByTagName('tr')[i + 1];
var cell_dose = dom_row.children[2];
var cell_administered = dom_row.children[3];
if (administer_mode) {
if (cell_administered.children.length > 0) {
var administered = cell_administered.children[0].checked;
if (!administered) {
// they need to fill in the box
return false;
}
} else {
// no box to fill in
}
} else {
var entered_dose = cell_dose.children[0].value;
if (entered_dose.match(/\S/))
if (cell_dose.children[0].value.match(/\S/)) {
var dose = parseFloat( cell_dose.children[0].value );
if (!(float_equal(dose, mar_rows[i].dose))) {
// they entered the wrong value
return false;
}
// they entered the right value
tracking_items.push(row.item_id);
} else {
// they left the box blank, do nothing
}
}
}
return tracking_items;
}
function submit() {
var msg = document.getElementById('result-message');
var tracking_items_or_false = check();
if (tracking_items_or_false !== false) {
msg.textContent = 'You did it!';
ARIS.givePlayerItemCount(item_id_to_give, 1);
for (var i = 0; i < tracking_items_or_false.length; i++) {
ARIS.givePlayerItemCount(tracking_items_or_false[i], 1);
}
setTimeout(function(){
ARIS.exit();
}, 1500);
} else {
msg.textContent = 'Try again.';
}
}
// hack to wait for both aris and the dom
var locks = 2;
function unlock() {
locks--;
if (locks == 0) appReady();
}
ARIS.ready = unlock;
document.addEventListener('DOMContentLoaded', unlock);
// for debugging
/*
ARIS.givePlayerItemCount = function(id, count){
console.log('giving player ' + count + ' of item ' + id);
};
ARIS.exit = function(){ console.log('exiting aris'); };
ARIS.cache = {
getPlayerItemCount: function(item_id){
return 1;
},
}
ARIS.ready();
// */
</script>
<style type="text/css">
body {
font-family: sans-serif;
background-color: white;
}
table, td {
border: 1px solid black;
}
table {
background-color: #579dce;
color: white;
}
.row-even {
background-color: rgb(216,216,216);
color: black;
}
.row-odd {
background-color: rgb(242,242,242);
color: black;
}
input[type=text] {
width: 7em;
}
</style>
<script type="text/javascript">
/*
FastClick: polyfill to remove click delays on browsers with touch UIs.
@codingstandard ftlabs-jsv2
@copyright The Financial Times Limited [All Rights Reserved]
@license MIT License (see LICENSE.txt)
*/
(function(){function e(a,b){function c(a,b){return function(){return a.apply(b,arguments)}}var d;b=b||{};this.trackingClick=!1;this.trackingClickStart=0;this.targetElement=null;this.lastTouchIdentifier=this.touchStartY=this.touchStartX=0;this.touchBoundary=b.touchBoundary||10;this.layer=a;this.tapDelay=b.tapDelay||200;this.tapTimeout=b.tapTimeout||700;if(!e.notNeeded(a)){for(var f="onMouse onClick onTouchStart onTouchMove onTouchEnd onTouchCancel".split(" "),h=0,k=f.length;h<k;h++)this[f[h]]=c(this[f[h]],
this);g&&(a.addEventListener("mouseover",this.onMouse,!0),a.addEventListener("mousedown",this.onMouse,!0),a.addEventListener("mouseup",this.onMouse,!0));a.addEventListener("click",this.onClick,!0);a.addEventListener("touchstart",this.onTouchStart,!1);a.addEventListener("touchmove",this.onTouchMove,!1);a.addEventListener("touchend",this.onTouchEnd,!1);a.addEventListener("touchcancel",this.onTouchCancel,!1);Event.prototype.stopImmediatePropagation||(a.removeEventListener=function(b,c,d){var e=Node.prototype.removeEventListener;
"click"===b?e.call(a,b,c.hijacked||c,d):e.call(a,b,c,d)},a.addEventListener=function(b,c,d){var e=Node.prototype.addEventListener;"click"===b?e.call(a,b,c.hijacked||(c.hijacked=function(a){a.propagationStopped||c(a)}),d):e.call(a,b,c,d)});"function"===typeof a.onclick&&(d=a.onclick,a.addEventListener("click",function(a){d(a)},!1),a.onclick=null)}}var k=0<=navigator.userAgent.indexOf("Windows Phone"),g=0<navigator.userAgent.indexOf("Android")&&!k,f=/iP(ad|hone|od)/.test(navigator.userAgent)&&!k,l=
f&&/OS 4_\d(_\d)?/.test(navigator.userAgent),m=f&&/OS [6-7]_\d/.test(navigator.userAgent),n=0<navigator.userAgent.indexOf("BB10");e.prototype.needsClick=function(a){switch(a.nodeName.toLowerCase()){case "button":case "select":case "textarea":if(a.disabled)return!0;break;case "input":if(f&&"file"===a.type||a.disabled)return!0;break;case "label":case "iframe":case "video":return!0}return/\bneedsclick\b/.test(a.className)};e.prototype.needsFocus=function(a){switch(a.nodeName.toLowerCase()){case "textarea":return!0;
case "select":return!g;case "input":switch(a.type){case "button":case "checkbox":case "file":case "image":case "radio":case "submit":return!1}return!a.disabled&&!a.readOnly;default:return/\bneedsfocus\b/.test(a.className)}};e.prototype.sendClick=function(a,b){var c,d;document.activeElement&&document.activeElement!==a&&document.activeElement.blur();d=b.changedTouches[0];c=document.createEvent("MouseEvents");c.initMouseEvent(this.determineEventType(a),!0,!0,window,1,d.screenX,d.screenY,d.clientX,d.clientY,
!1,!1,!1,!1,0,null);c.forwardedTouchEvent=!0;a.dispatchEvent(c)};e.prototype.determineEventType=function(a){return g&&"select"===a.tagName.toLowerCase()?"mousedown":"click"};e.prototype.focus=function(a){var b;f&&a.setSelectionRange&&0!==a.type.indexOf("date")&&"time"!==a.type&&"month"!==a.type?(b=a.value.length,a.setSelectionRange(b,b)):a.focus()};e.prototype.updateScrollParent=function(a){var b,c;b=a.fastClickScrollParent;if(!b||!b.contains(a)){c=a;do{if(c.scrollHeight>c.offsetHeight){b=c;a.fastClickScrollParent=
c;break}c=c.parentElement}while(c)}b&&(b.fastClickLastScrollTop=b.scrollTop)};e.prototype.getTargetElementFromEventTarget=function(a){return a.nodeType===Node.TEXT_NODE?a.parentNode:a};e.prototype.onTouchStart=function(a){var b,c,d;if(1<a.targetTouches.length)return!0;b=this.getTargetElementFromEventTarget(a.target);c=a.targetTouches[0];if(f){d=window.getSelection();if(d.rangeCount&&!d.isCollapsed)return!0;if(!l){if(c.identifier&&c.identifier===this.lastTouchIdentifier)return a.preventDefault(),!1;
this.lastTouchIdentifier=c.identifier;this.updateScrollParent(b)}}this.trackingClick=!0;this.trackingClickStart=a.timeStamp;this.targetElement=b;this.touchStartX=c.pageX;this.touchStartY=c.pageY;a.timeStamp-this.lastClickTime<this.tapDelay&&a.preventDefault();return!0};e.prototype.touchHasMoved=function(a){a=a.changedTouches[0];var b=this.touchBoundary;return Math.abs(a.pageX-this.touchStartX)>b||Math.abs(a.pageY-this.touchStartY)>b?!0:!1};e.prototype.onTouchMove=function(a){if(!this.trackingClick)return!0;
if(this.targetElement!==this.getTargetElementFromEventTarget(a.target)||this.touchHasMoved(a))this.trackingClick=!1,this.targetElement=null;return!0};e.prototype.findControl=function(a){return void 0!==a.control?a.control:a.htmlFor?document.getElementById(a.htmlFor):a.querySelector("button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea")};e.prototype.onTouchEnd=function(a){var b,c,d=this.targetElement;if(!this.trackingClick)return!0;if(a.timeStamp-this.lastClickTime<
this.tapDelay)return this.cancelNextClick=!0;if(a.timeStamp-this.trackingClickStart>this.tapTimeout)return!0;this.cancelNextClick=!1;this.lastClickTime=a.timeStamp;b=this.trackingClickStart;this.trackingClick=!1;this.trackingClickStart=0;m&&(c=a.changedTouches[0],d=document.elementFromPoint(c.pageX-window.pageXOffset,c.pageY-window.pageYOffset)||d,d.fastClickScrollParent=this.targetElement.fastClickScrollParent);c=d.tagName.toLowerCase();if("label"===c){if(b=this.findControl(d)){this.focus(d);if(g)return!1;
d=b}}else if(this.needsFocus(d)){if(100<a.timeStamp-b||f&&window.top!==window&&"input"===c)return this.targetElement=null,!1;this.focus(d);this.sendClick(d,a);f&&"select"===c||(this.targetElement=null,a.preventDefault());return!1}if(f&&!l&&(b=d.fastClickScrollParent)&&b.fastClickLastScrollTop!==b.scrollTop)return!0;this.needsClick(d)||(a.preventDefault(),this.sendClick(d,a));return!1};e.prototype.onTouchCancel=function(){this.trackingClick=!1;this.targetElement=null};e.prototype.onMouse=function(a){return this.targetElement&&
!a.forwardedTouchEvent&&a.cancelable?!this.needsClick(this.targetElement)||this.cancelNextClick?(a.stopImmediatePropagation?a.stopImmediatePropagation():a.propagationStopped=!0,a.stopPropagation(),a.preventDefault(),!1):!0:!0};e.prototype.onClick=function(a){if(this.trackingClick)return this.targetElement=null,this.trackingClick=!1,!0;if("submit"===a.target.type&&0===a.detail)return!0;a=this.onMouse(a);a||(this.targetElement=null);return a};e.prototype.destroy=function(){var a=this.layer;g&&(a.removeEventListener("mouseover",
this.onMouse,!0),a.removeEventListener("mousedown",this.onMouse,!0),a.removeEventListener("mouseup",this.onMouse,!0));a.removeEventListener("click",this.onClick,!0);a.removeEventListener("touchstart",this.onTouchStart,!1);a.removeEventListener("touchmove",this.onTouchMove,!1);a.removeEventListener("touchend",this.onTouchEnd,!1);a.removeEventListener("touchcancel",this.onTouchCancel,!1)};e.notNeeded=function(a){var b,c;if("undefined"===typeof window.ontouchstart)return!0;if(c=+(/Chrome\/([0-9]+)/.exec(navigator.userAgent)||
[,0])[1])if(g){if((b=document.querySelector("meta[name=viewport]"))&&(-1!==b.content.indexOf("user-scalable=no")||31<c&&document.documentElement.scrollWidth<=window.outerWidth))return!0}else return!0;return n&&(b=navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/),10<=b[1]&&3<=b[2]&&(b=document.querySelector("meta[name=viewport]"))&&(-1!==b.content.indexOf("user-scalable=no")||document.documentElement.scrollWidth<=window.outerWidth))||"none"===a.style.msTouchAction||"manipulation"===a.style.touchAction||
27<=+(/Firefox\/([0-9]+)/.exec(navigator.userAgent)||[,0])[1]&&(b=document.querySelector("meta[name=viewport]"))&&(-1!==b.content.indexOf("user-scalable=no")||document.documentElement.scrollWidth<=window.outerWidth)?!0:"none"===a.style.touchAction||"manipulation"===a.style.touchAction?!0:!1};e.attach=function(a,b){return new e(a,b)};"function"===typeof define&&"object"===typeof define.amd&&define.amd?define(function(){return e}):"undefined"!==typeof module&&module.exports?(module.exports=e.attach,
module.exports.FastClick=e):window.FastClick=e})();
</script>
</head>
<body>
<p>
Patient Name: <span id="the-name"></span> <br />
DOB: <span id="the-dob"></span>
Weight (kg): <span id="the-weight"></span> <br />
MR#: <span id="the-mr"></span> <br />
Provider: <span id="the-provider"></span> <br />
Allergies: <span id="the-allergies"></span>
</p>
<table id="the-mar">
<tr>
<th>Order</th>
<th>Sch. Time</th>
<th>Dose</th>
<th id="the-administered-header">Given</th>
</tr>
</table>
<p><button type="button" onclick="submit();">Submit</button></p>
<p id="result-message"></p>
</body>
</html>