-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.htm
768 lines (718 loc) · 16.1 KB
/
index.htm
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
<!DOCTYPE html>
<html>
<head>
<title>Sim Monitor</title>
<meta charset='utf-8'/>
<link rel='icon' href='res/ico.svg'/>
</head>
<body>
<div statusbar>
<img settingsToggle src='res/settings.svg'/>
<img src='res/x.svg'/> <b var-date></b><b var-time></b><img src='res/bat.svg'/><img src='res/net.svg'/><img src='res/snd.svg'/>
</div>
<aside settings>
<label>HR Waveform</label>
<select vital='hr' id='hrControl'></select>
<label>SpO<sub>2</sub> Waveform</label>
<select vital='spo2' id='o2Control'></select>
<label>RR Waveform</label>
<select vital='rr' id='rrControl'></select>
<label>ABP Waveform</label>
<select vital='bp' id='bpControl'></select>
</aside>
<div class='vitals-waveforms'>
<canvas wav='hr' width='3000' height='200'></canvas>
<canvas wav='o2' width='3000' height='200'></canvas>
<canvas wav='rr' width='3000' height='200'></canvas>
<canvas wav='bp' width='3000' height='200'></canvas>
</div>
<div class='vitals-numbers'>
<div vital='HR'><input value='90'></input></div>
<div vital='SpO2'><input value='98'></input></div>
<div vital='RR'><input value='16'></input></div>
<div vital='NIBP'><input value='120/80'></input></div>
<div sub vital='Temp'><input value='98.7'></input></div>
<div sub vital='Pulse'><input value='90'></input></div>
</div>
</body>
<script>
let l = console.log
let Waveforms = {}
Waveforms.Hr = {
sinus : {
amplitude: 1,
color: '#4f4',
cycle: {
length: 100, // use JS to convert this to segment in canvas
height: length*0.29
},
name: 'Sinus (Lead II)',
pathCoordinates: [
//StartPoints
[0,0],
//RelativeLineDrawing (Add x-px, Add y-px)
[23,0],
// Wave Peak #1
[6,16],
[6,-36],
// Wave Peak #2
[2, 120],
[2, -140],
// Wave balance
[6,40],
[9,0],
// Wave peak #3
[6, 20],
[6, -20],
// Wave Balance-end
[34,0]
]
},
avpaced : {
amplitude: 1,
color: '#4e4',
cycle: {
length: 100,
height: length*0.29
},
name: 'AVP',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[2,0],
[0,-75],
[1,75],
[1,8],
[1,-8],
[3,-80],
[2,80],
[1,30],
[8,-30],
[20,0],
[0,-75],
[1,80],
[1,-5],
[7,10],
[4,-10],
[8,0]
]
},
vfib : {
amplitude: 1,
color: '#4e4',
cycle: {
length: 50,
height: length*0.29
},
name: 'VFib',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[2,0],
[7,14],
[8,-26],
[4,12],
[4,0],
[1,-8],
[3,12],
[6,2],
[4,-6],
[1,0],
[14,20],
[3,0],
[5,-35],
[7,15],
[8,0]
]
},
afib: {
amplitude: 1,
color: '#4e4',
cycle: {
length: 50,
height: length*0.29,
span: 4,
},
name: 'AFib',
pathCoordinates: [
// StartPoints
[0,0],
// PathCoordidates
[7,0],
[2,10],
[4,-10],
[1,3],
[2,-3],
[1,8],
[2,-8],
[1,16],
[3,-16],
[10,0],
[1,16],
[3,-16],
[7,1],
[3,-6],
[3,5],
[6,16],
[10,-36],
[4, 120],
[16, -140],
[6,40],
[9,0],
[6, 20],
[6, -20],
[2, 40],
[1, -40],
[1,16],
[3,-16],
[10,0],
[1,16],
[3,-16],
[2,30],
[1,-50],
[4, 80],
[10, -100],
[8, 50],
[20, -50],
[6,40],
[9,0],
[8, 20],
[19, -20],
[7, 9],
[10, -9],
[5, 15],
[12, -15],
[7,0],
[1,8],
[2,-8],
[1,16],
[3,-16],
[2,10],
[4,-10],
[10,0],
[4, 120],
[16, -120],
]
},
}
Waveforms.O2 = {
normal: {
amplitude: 1,
color: '#4ee',
curve: {
smooth: 4,
smoothX: 2,
smoothY: 8,
},
cycle: {
length: 100,
height: length*0.29
},
name: 'Normal',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[23,0],
[8,90],
[3,-35],
[2,-5],
[5,-50],
[6,0],
]
},
small_and_weak: {
amplitude: 1,
color: '#4ee',
curve: {
smooth: 4,
smoothX: 2,
smoothY: 8,
},
cycle: {
length: 100,
height: length*0.29
},
name: 'Small and Weak',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[23,0],
[8,40],
[3,-15],
[1,5],
[2,-10],
[9,-20],
[6,0],
]
},
large_and_bounding: {
amplitude: 1,
color: '#4ee',
curve: {
smooth: 4,
smoothX: 2,
smoothY: 0,
},
cycle: {
length: 100,
height: length*0.29
},
name: 'Large and Bounding',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[23,0],
[8,90],
[10,-65],
[8,-10],
[16,-15],
[6,0],
]
},
pulsus_alternase: {
amplitude: 1,
color: '#4ee',
curve: {
smooth: 4,
smoothX: 2,
smoothY: 8,
},
cycle: {
length: 100,
height: length*0.29,
span: 2,
},
name: 'Pulsus Alternanse',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[13,0],
[8,90],
[3,-35],
[2,-5],
[5,-50],
[6,0],
// PathCoordidates
[13,0],
[8,70],
[3,-35],
[2,-5],
[5,-30],
[6,0],
]
},
no_dicrotic_notch: {
amplitude: 1,
color: '#4ee',
curve: {
smooth: 4,
smoothX: 2,
smoothY: 8,
},
cycle: {
length: 100,
height: length*0.29
},
name: 'No Dicrotic Notch',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[23,0],
[8,90],
[10,-90],
[6,0],
]
},
chaotic: {
amplitude: 1,
color: '#4ee',
curve: {
smooth: 4,
smoothX: 2,
smoothY: 8,
},
cycle: {
length: 100,
height: length*0.29
},
name: 'Chaotic',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[23,0],
[9,-20],
[8,40],
[3,-15],
[2,-10],
[1,5],
[6,0],
[9,-20],
[3,-15],
[6,0],
[2,-10],
[23,0],
[8,40],
[1,5],
]
},
}
Waveforms.Bp = {
normal: {
amplitude: 1,
color: '#e44',
curve: {
smooth: 0.5,
},
cycle: {
length: 100,
height: length*0.29
},
name: 'Normal Artline',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[2,95],
[2,-25],
[2,-45],
[2,15],
[8,-40],
]
},
}
Waveforms.Rr = {
basic: {
amplitude: 1,
color: '#eee',
cycle: {
length: 100,
height: length*0.29
},
name: 'Basic RR',
pathCoordinates: [
//StartPoints
[0,0],
// PathCoordidates
[2,95],
[2,0],
[2,-95],
[10,0]
]
},
}
</script>
<script>
let selectHr = document.querySelector('#hrControl')
let selectO2 = document.querySelector('#o2Control')
let selectRr = document.querySelector('#rrControl')
let selectBp = document.querySelector('#bpControl')
populateWaveformDropdown(selectHr, Waveforms.Hr, document.querySelector("[wav='hr']"))
populateWaveformDropdown(selectO2, Waveforms.O2, document.querySelector("[wav='o2']"))
populateWaveformDropdown(selectRr, Waveforms.Rr, document.querySelector("[wav='rr']"))
populateWaveformDropdown(selectBp, Waveforms.Bp, document.querySelector("[wav='bp']"))
//animateWaveformContext(Waveforms.Rr, document.querySelector("[wav='rr']"))
//animateWaveformContext(Waveforms.Bp, document.querySelector("[wav='bp']"))
// [{canvas, setIntervalHandleId}]
var waveformAnimationQueue = [];
/**
* Renders and animates a waveform in the given canvas for the provided ms, defaults to 20ms
**/
function animateWaveformContext(waveform, container, animationSpeed) {
if (!container.getContext) return
if (!animationSpeed) animationSpeed = 22
let c = container.getContext('2d')
let currentPositionX = 0
let intervalHandle = window.setInterval(()=>{
c.clearRect(0,0, c.canvas.width, c.canvas.height)
renderWaveInCanvas(waveform, container)
drawVerticalLineAt(currentPositionX, c)
currentPositionX += c.canvas.width * 0.003
if (currentPositionX >= c.canvas.width) {
currentPositionX = 0
c.moveTo(0,0)
}
}, animationSpeed)
if (waveformAnimationQueue) {
waveformAnimationQueue.push({canvas: container, intervalId: intervalHandle})
for (let queue_i = 0; queue_i<waveformAnimationQueue.length; queue_i++) {
let animationQueue = waveformAnimationQueue[queue_i]
if (animationQueue.canvas == container && animationQueue.intervalId != intervalHandle) {
window.clearInterval(animationQueue.intervalId)
waveformAnimationQueue.splice(queue_i, 1)
}
}
}
}
/**
* Draws a thick vertical line at a location for animation purposes
**/
function drawVerticalLineAt(xLocation, context, offset) {
if (!offset) offset = 0
let bgColor = window.getComputedStyle(document.body, null).getPropertyValue('background-color')
let c = context
let lineHeight = c.canvas.height
let lineWidth = 20 + offset
lineWidth = context.canvas.width * 0.015
let oldStrokeStyle = c.strokeStyle
//xLocation = xLocation / (context.canvas.width / 1.5) *5000
c.beginPath()
c.lineWidth = lineWidth
oldStrokeStyle = c.strokeStyle
c.strokeStyle = 'black'
if (bgColor) c.strokeStyle = bgColor
c.moveTo(xLocation, 0)
c.lineTo(xLocation, lineHeight)
c.stroke()
}
/**
* Plots the coordinate points to the context from the waveform.
* useExactCoordinates can be used to draw the coordinates as exact values instead of relative.
* Returns the relative, non-exact, coordinates for usage with looping.
**/
function drawWave(context, waveform, useExactCoordinates) {
let c = context
let coordinates = waveform.pathCoordinates
let xy_prev = coordinates[0]
let xy_last = xy_prev
for (let xy_i=1; xy_i<coordinates.length; xy_i++) {
let xy = coordinates[xy_i]
let x = xy[0]
let y = xy[1]*waveform.amplitude
let newX = xy_prev[0]+x
let newY = xy_prev[1]-y
// Will interpret values as EXACT PIXEL locations to draw and ignores assumed relative locations //
if (useExactCoordinates) {
newX = x
newY = y
}
// Calculate the exact point location in canvas from relative (percent-based) drawing coordinates //
let xper = (x, log)=> {
let val = waveform.cycle.length*(x/100)
if (waveform.cycle.span) val = val*waveform.cycle.span
if (log) l('x: '+x+' '+val)
return val
}
let yper = (y, log)=> {
let val = waveform.cycle.height*(y/100)
if (log) l('y: '+y+' '+val)
return y
}
// Placing the coordinates uses the exact values from the calculations //
c.moveTo(
xper(xy_prev[0]),
yper(xy_prev[1])
)
if (waveform.linear && waveform.linear == true) {
c.lineTo( xper(newX), yper(newY) )
}
else {
let curveStrength = [0,-2]
let xCurveStrength = curveStrength
let yCurveStrength = [0,0]
xCurveStrength = getCalculatedStrengthValues(waveform,'smoothX')
yCurveStrength = getCalculatedStrengthValues(waveform,'smoothY')
//ctrlPt1x, ctrlPt1y, cp2x, cp2y, x,y
c.bezierCurveTo(
// Control Points
xper(newX-xCurveStrength[0]), yper(newY-yCurveStrength[0]),
xper(newX-xCurveStrength[1]), yper(newY-yCurveStrength[1]),
// Coordinates
xper(newX),
yper(newY)
)
}
// Values stored do not use exact locations to ensure that waveform path data keeps consistent //
xy_prev = [newX,newY]
xy_last = [newX,newY]
}
return xy_last
}
let stopLoopNum = 0
function getCalculatedStrengthValues(waveform, curveTargetXY) {
let defaultStrength = [2,2]
let defaultCurveStrengthX = [0,-2]
let defaultCurveStrengthY = [0,0]
if (!waveform.curve) return defaultStrength
if (!curveTargetXY) curveTargetXY = 'smooth'
let validCurveStrengthFields = ['smooth', 'smoothX', 'smoothY']
for (let key in waveform.curve) {
let currentCurveField = waveform.curve[key]
if (!validCurveStrengthFields.includes(key)) {
continue
}
if (key == curveTargetXY || key == 'smooth') {
if (currentCurveField.length) {
defaultStrength = currentCurveField
continue
}
defaultStrength = [currentCurveField, currentCurveField]
}
}
return defaultStrength
}
/**
* Assigns select options from HR waveform with optional canvas to control
**/
function populateWaveformDropdown(select, waveforms, canvas) {
//function populateHrWaveformDropdown(select, canvas) {
if (!canvas) {
canvas = document.querySelector("[wav]")
}
let defaultOption = document.createElement('option')
defaultOption.innerHTML = '--'
defaultOption.value = null
select.innerHTML = ''
select.appendChild(defaultOption)
for (let waveform in waveforms) {
let option = document.createElement('option')
option.value = waveform
option.innerHTML = waveforms[waveform].name
select.appendChild(option)
}
select.onchange = ()=> {
setCanvasWaveToSelectValue(select, waveforms, canvas)
}
}
/**
* Renders the waveform to the context, repeated by the numberOfCycles.
**/
function renderWave(context, waveform, numberOfCycles) {
context.beginPath()
waveform.pathCoordinates[0] = [0,context._containerHeight/2]
for (let phaseNumber = 0; phaseNumber<=numberOfCycles-2; phaseNumber++) {
waveform.pathCoordinates[0] = drawWave(context, waveform)
}
drawWave(context, waveform)
context.stroke()
}
/**
* Draws the provided waveform in the given context.
**/
function renderWaveInCanvas(waveform, container) {
if (!container.getContext) return
let c = container.getContext('2d')
c._containerHeight = c.canvas.height
c._containerWidth = c.canvas.width
// TODO a- Remove need for numbers here and put idea into drawWave()
setWaveformWidth(waveform, c.canvas.width)
c.lineCap = 'round'
c.lineJoin = 'round'
let waveColor = '#44f'
let waveStrength = 3
if (waveform.color) waveColor = waveform.color
if (waveform.strength) waveStrength = waveform.strength
c.lineWidth = waveStrength * (container.offsetWidth / 800)
c.strokeStyle = waveColor
renderWave(c, waveform, 8)
return c
}
/**
* Sets the wave in a canvas based off of the select's value
**/
function setCanvasWaveToSelectValue(select, waveforms, canvas) {
for (let waveId in waveforms) {
if (select.value == waveId) {
animateWaveformContext(waveforms[waveId], canvas)
}
}
}
/**
* Adjusts waveform's total width to a given value
**/
function setWaveformWidth(waveform, value) {
let maxX= 0
for (let i=0; i<waveform.pathCoordinates.length; i++) {
maxX+= waveform.pathCoordinates[i][0]
}
waveform.cycle.length = (value/maxX)*100
}
setTimeout(()=> {
let select = document.querySelector('#hrControl')
select.selectedIndex = 1
setCanvasWaveToSelectValue(select, Waveforms.Hr, document.querySelector("[wav='hr']"))
}, 5)
setTimeout(()=>{
let selectO2 = document.querySelector('#o2Control')
selectO2.selectedIndex = 1
setCanvasWaveToSelectValue(selectO2, Waveforms.O2, document.querySelector("[wav='o2']"))
}, 10)
setTimeout(()=>{
selectRr.selectedIndex = 1
setCanvasWaveToSelectValue(selectRr, Waveforms.Rr, document.querySelector("[wav='rr']"))
}, 15)
setTimeout(()=>{
selectBp.selectedIndex = 1
setCanvasWaveToSelectValue(selectBp, Waveforms.Bp, document.querySelector("[wav='bp']"))
}, 20)
</script>
<script>
let varDate = document.querySelector('[var-date]')
let varTime = document.querySelector('[var-time]')
setInterval(()=>{
let now = new Date()
let h = now.getHours(), m = now.getMinutes(), s = now.getSeconds()
let mm = now.getMonth()+1, dd = now.getDate(), yy = now.getFullYear()
if (h < 10) h = `0${h}`
if (m < 10) m = `0${m}`
if (s < 10) s = `0${s}`
let date = `${mm}/${dd}/${yy}`
let time = `${h}:${m}:${s}`
varDate.innerHTML = date
varTime.innerHTML = time
}, 1000)
let vitalsDivs = document.querySelectorAll('[vital]')
for (let divs_i in vitalsDivs) {
if (isNaN(divs_i)) continue
let div = vitalsDivs[divs_i]
let b = document.createElement('b')
let vitalType = div.getAttribute('vital')
div.classList.add(vitalType.toLowerCase())
b.innerHTML = vitalType
b.onclick = ()=> {
if (div.classList.contains('disabled') == false) {
div.classList.add('disabled')
}
else {
div.classList.remove('disabled')
}
let input = div.querySelector('input')
if (input.value == '') {
input.value = input.getAttribute('value-last')
input.setAttribute('value-last', '')
}
else {
input.setAttribute('value-last', input.value)
input.value = ''
}
}
div.appendChild(b)
}
let settingsTogglers = document.querySelectorAll('[settingsToggle]')
for (let setTgl_i=0; setTgl_i<settingsTogglers.length; setTgl_i++) {
let settingsToggle = settingsTogglers[setTgl_i]
let settingsPanel = document.querySelector('[settings]')
settingsToggle.onclick = ()=>{
if (settingsPanel.classList.contains('hide')) {
settingsPanel.classList.remove('hide')
settingsToggle.src = 'res/settings-cancel.svg'
}
else {
settingsPanel.classList.add('hide')
settingsToggle.src = 'res/settings.svg'
}
}
settingsPanel.classList.add('hide')
}
</script>
<style>
@import 'basic.css';
</style>
</html>