-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
16900 lines (14932 loc) · 696 KB
/
main.js
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var umami;
var complex_mode = 0;
var paedi_mode = 0;
var PMA;
var ageunit = "y";
var active_drug_set_index = 0;
var alt_drug_set_index = 1;
var vc;
var d = null; //to store date object
var mass;
var ABW; //for eleveld
var lbm, height, gender;
var conc1;
var conc2;
var conc3;
var drug_sets = new Array();
var drug_name = "Propofol";
var conc_units = "mcg";
var infused_units = "mg";
var k10;
var k12;
var k21;
var k13;
var k31;
var k41;
var l1, l2, l3, l4;
var bolus;
var time = 0; //time in ms
var time_in_s = 0;
var r = new Array();
var lambda = new Array();
var refresh_interval = 1000; //interval for drug infusions
var inf_rate_mls;
//var inf_rate_mgperkg; //deprecated
var inf_rate_permass;
var inf_rate_permass_factor = 1; //1 for propofol
var inf_rate_permass_unit = "mg/kg/h";
var inf_rate_permass_dp = 100; //100 means 2 dp, if need zero dp, set this to 1
var inf_rate_amt;
var infusate_concentration=10;
var delta_volume_infused;
var delta_amount_infused;
var infuse_time;
var prior_infuse_time = -1;
var interval;
var volume_infused = 0;
var pump_rate_in_amt = 0;
var p_coef = new Array();
var e_coef = new Array();
var p_udf = new Array();
var e_udf = new Array();
var delta_seconds = 1; // for p_udf
var p_state = new Array();
var e_state = new Array();
var p_state2 = new Array();
var e_state2 = new Array();
var p_state3 = new Array();
var e_state3 = new Array();
var timeadjust = 0;
var loop1;
var loop2;
var firstrun = -1;
var result = 0;
var result_e = 0;
var alt_result = 0;
var alt_result_e = 0;
var simspeed =1;
var corX=0; //for chartjs
var corY=0; //for chartjs
var historytext = ""; //for history writing
var modeltext = " "; //for modeldescription
var myChart;
var desired;
var cpt_threshold_auto =1;
var cpt_threshold=0.08;
var cpt_avgfactor=0.667;
var cpt_active = 0;
var cet_active = 0;
var IB_active = 0;
var IB_last_dose = 0;
var IB_last_time = 0;
var IB_next_dose = 0;
var IB_next_time = 0;
var manualmode_active = 0;
var running = 0;
var trial_result = 0;
var trial_result_e = 0;
var cpt_bolus = 0;
var cet_bolus = 0;
var cpt_rates = new Array();
var cpt_rates_real = new Array();
var cpt_times = new Array();
var cpt_cp = new Array();
var cpt_ce = new Array();
var volinf = new Array();
//fentanyl shibutani weight adjusted
//var fentanyl_weightadjusted_factor = 1;
//var fentanyl_weightadjusted_flag = 0;
//var fentanyl_weightadjusted_target_uncorrected = 0;
var cpt_rates_real_PP = new Array();
var cpt_cp_PP = new Array();
var cpt_ce_PP = new Array();
var cpt_interval = 120;//cpt interval
//for ce targeting
var peak_time, prior_peak_time;
var temp_peak, current, next_time;
var cet_lockdowntime = 0; //this will allow any cet_bolus to exert its full effect before going to new scheme of new target
var cet_priordesired = 0;
var historyarray = new Array();
// this is for current scheme
var historyarrays = new Array();
/* history arrays structure: this is for record keeping of all schemes entered
[a0,a1,a2,a3,a4,a5]
where
a0 = 0:manual, 1:cpt, 2:cet
a1 = 0:target, 1:bolus, 2:infusion arrays, 3:cetpause, 4:intermittent bolus arrays
a2 = time in s
a3 = content
added a5, a6 below to determine IB mode
a4 = IB mode active
a5 = IB swing
structure end */
var historydivs = new Array();
var prior = 0; //this is for update -->display-->highlight current inf rate
var next = 999; //this is for update -->display highlighting function when next is near
var preview_bolus;
var preview_rate;
var preview_downtrend;
var previewtimeout;
var user_hide=0; // for warning prompt - NOT hide by default
var timeout2 = null; // for delay display cpt prompt
var optionsarray = new Array();
var optionsarray_infusionunit = new Array();
var PD_mode = 0 ; //PD effect estimtation: 0 is off, 1 is BIS, 2 is PTOL, 3 is NSRI
var alert_vibrate_on = 0;
var alert_sound_on = 0;
var alertinterval_vibrate = null; //for alert api use - it is a setinterval function
var alertinterval_sound = null; //for alert api use - it is a setinterval function
var alert_sound_object = new sound("beep.mp3");
var alert_sound_object2 = new sound("beep-2.mp3");
var historytexts = new Array();
var chartprofile = 0;
var arrPOINTERS = new Array();
var arrTEMP = new Array();
var IB_swing = 0.05; //this is intermittent bolus swing
var PP_mode;
var PP_tickertime;
var PP_interval=180;
var PP_start = 0;
var PP_next = PP_interval;
var PP_temp_bolus_store = 0;
var PP_temp_bolustime_store = 0;
var ticker_active = 0;
var notificationallowed = 0;
var notificationactive = 0;
var UI_borderon = 0;
var UI_infrateon = 0;
var manageFileListState = 0;
var modal = undefined;
var prior_half_minute_clock = 0;
var time_of_stop = -1;
window.ptolcouplesarray = []; //ptol couples over time
//var ptol0overtime = new Array(); //ptol chart data for 0 over time, series based on chart data
//var ptol1overtime = new Array(); //ptol chart data for 1 over time
var loop6 = null; //this is setinterval function
var loop7 = null;
window.BIS_array = [];
window.eventArray = [];
const arrBodyIcons = [
["baby","<i class='fas fa-baby fa-fw tooltip bodyicon'><span class='tooltiptext'>BMI-for-age reference range from WHO</span></i>"],
["child","<i class='fas fa-child fa-fw tooltip bodyicon'><span class='tooltiptext'>BMI-for-age & weight-for-age reference range from WHO</span></i>"],
["male","<i class='fas fa-male fa-fw tooltip bodyicon'><span class='tooltiptext'>BMI reference range from WHO</span></i>"],
["female","<i class='fas fa-female fa-fw tooltip bodyicon'><span class='tooltiptext'>BMI reference range from WHO</span></i>"]
]
// variables for loading and saving
var uid;
//for local storage: data structure
//UID + "DATA" - target data
//UID + "PATIENT" - demographic and model
//UID + "TIME" - frequently changing time variable
var selected_uid;
var texttimeout = null;
// start service worker code
var parseloading = 0; //suppress function calls during parseobject loading when equals 1
var popupon = false;
var isDark = false;
var timeoutptol = null;
var chartviewarray = [0,30,10];
var ringbell2active = 0;
var ringbell2timeout = null;
var alert_sound_2 = null;
var alert_vibrate_2 = null;
var updateBIS = null;
var timeoutVal = null;
var ringtimeout = null;
var ringactive = 0;
var inputname = "";
var importDataArray = new Array();
var canvasUpdateInterval = null;
var textheight = 0;
var newCanvas = document.createElement('canvas');
var newCanvasReady = 0;
var popupchart;
var boxesArray = new Array();
var suitableForBoxes = false;
var isFullscreen = false;
var popupUpdateInterval;
var numpadValue = 0;
var numpadOrig;
var collapsibles = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < collapsibles.length; i++) {
collapsibles[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
if (collapsibles[i].classList.contains("active")) {
collapsibles[i].nextElementSibling.style.display = "block";
}
}
var collapsiblecards = document.getElementsByClassName("collapsiblecard");
for (i=0; i<collapsiblecards.length; i++) {
collapsiblecards[i].nextElementSibling.style.display = "none";
collapsiblecards[i].nextElementSibling.classList.add("collapsed");
collapsiblecards[i].addEventListener("click", function() {
toggleCard(this);
});
}
function toggleCard(x) {
var content = x.nextElementSibling;
x.classList.toggle("active");
if (content.style.display === "block") {
content.style.display = "none";
//content.classList.add("collapsed");
content.classList.remove("animate");
} else {
content.style.display = "block";
content.classList.add("animate");
}
}
var tops = document.getElementsByClassName("top_title_box");
for (topscounter=0; topscounter<tops.length; topscounter++) {
tops[topscounter].addEventListener("click", function() {
window.scrollTo(0,0);
})
}
//global colors / charting script initiation
//band colors from column 200 of material design 1-10 hues, for myChart2
var bandColor0 = 'rgb(239,154,154,0.2)';//red
var bandColor1 = 'rgb(244,143,177,0.2)';//pink
var bandColor2 = 'rgb(206,147,216,0.2)';//purple
var bandColor3 = 'rgb(179,157,219,0.2)';
var bandColor4 = 'rgb(159,168,218,0.2)';
var bandColor5 = 'rgb(144,202,249,0.2)';
var bandColor6 = 'rgb(129,212,250,0.2)';
var bandColor7 = 'rgb(128,222,234,0.2)';
var bandColor8 = 'rgb(128,203,196,0.2)';
var bandColor9 = 'rgb(165,214,167,0.2)';
var bandColor10 = 'rgb(197,225,165,0.2)';
var bandColor11 = 'rgb(230,238,156,0.2)';//lime
var bandColor12 = 'rgb(255,245,157,0.2)';//yellow
var bandColor13 = 'rgb(255,224,130,0.2)';//amber
var bandColor14= 'rgb(255,204,128,0.2)'//orange
var dotColor0 = 'rgb(158,158,158,1)';
var dotColor1 = 'rgb(117,117,117,1)';
var dotColor2 = 'rgb(97,97,97,1)';
var dotColor3 = 'rgb(66,66,66,1)';
var dotColor4 = 'rgb(33,33,33,1)';
var dotColor5 = 'rgb(66,66,66,1)';
var dotColor6 = 'rgb(97,97,97,1)';
var dotColor7 = 'rgb(117,117,117,1)';
var dotColor8 = 'rgb(158,158,158,1)';
var dotColor0dark = 'rgb(185,185,185,0.7)';
var dotColor1dark = 'rgb(200,200,200,0.8)';
var dotColor2dark = 'rgb(215,215,215,0.8)';
var dotColor3dark = 'rgb(230,230,230,0.8)';
var dotColor4dark = 'rgb(245,245,245,1)';
var dotColor5dark = 'rgb(230,230,230,0.8)';
var dotColor6dark = 'rgb(215,215,215,0.8)';
var dotColor7dark = 'rgb(200,200,200,0.8)';
var dotColor8dark = 'rgb(185,185,185,0.7)';
/*
const dotColor0 = 'rgb(0,96,100,1)'//cyan
const dotColor1 = 'rgb(1,87,155,1)'; // lightblue
const dotColor2 = 'rgb(26,35,126,1)'; //indigo
const dotColor3 = 'rgb(74,20,140,1)'; //purple
const dotColor4 = 'rgb(183,28,28,1)';//red
const dotColor5 = 'rgb(230,81,0,1)';//orange
const dotColor6 = 'rgb(245,127,23,1)';//yellow
const dotColor7 = 'rgb(51,105,30,1)';//lightgreen
const dotColor8 = 'rgb(0,77,64,1)';//teal
*/
//line colors from blue-grey row
var lineColor0 = 'rgba(84,110,122,0.75)';
var lineColor1 = 'rgba(120,144,156,1)';
var lineColor1dark = 'rgba(210,235,250,1)';
var yellowPri = 'rgba(251,192,45,1)';
var yellowPri50 = 'rgba(251,192,45,0.58)';
var yellowPri10 = 'rgba(251,192,45,0.1)';
var yellowPri70 = 'rgba(251,192,45,0.7)';
var yellowPri30 = 'rgba(251,192,45,0.3)';
var yellowLight = 'rgba(255,242,99,1)';
var yellowLight10 = 'rgba(255,242,99,0.1)';
var yellowLight70 = 'rgba(255,242,99,0.7)';
var yellowDark = 'rgba(196,144,0,1)';
var yellowSec = 'rgba(255,202,40,1)';
var yellowSec10 = 'rgba(255,202,40,0.11)';
var yellowSecLight = 'rgba(255,253,97,1)';
var yellowSecDark = 'rgba(199,154,0,1)';
var orangeShadeLight = 'rgba(255,204,128,0.2)';
var orangeShadeDark = 'rgba(255,152,0,0.2)';
var bluePri = 'rgba(21,101,192,1)';
var bluePri50 = 'rgba(21,101,192,0.5)';
var blueLight = 'rgba(94,146,243,1)';
var blueLight10 = 'rgba(94,146,243,0.1)';
var blueLight70 = 'rgba(94,146,243,0.7)';
var blueLight50 = 'rgba(94,146,243,0.58)';
var blueDark = 'rgba(0,60,143,1)';
var blueSec = 'rgba(3,169,244,1)';
var blueSec10 = 'rgba(3,169,244,0.11)';
var blueSecLight = 'rgba(103,218,255,1)';
var blueSecDark = 'rgba(0,122,193,1)';
var blueShadeDark = 'rgba(3,169,244,0.2)';
var greenShade = 'rgba(102, 177, 105, 0.25)';
var greenShadeDark = 'rgba(102, 177, 105, 0.35)';
function getGradientRed(ctx, chartArea, scales) {
const gradientBgRed = ctx.createLinearGradient(chartArea.left, 0, chartArea.right, 0);
var position = (scales.x.getPixelForValue(time_in_s/60) - scales.x.getPixelForValue(scales.x.min)) / chartArea.width;
if (position<=0) position = 0;
if (position>=1) position = 1;
gradientBgRed.addColorStop(0, 'rgba(231,50,39,0.4)');
gradientBgRed.addColorStop(position, 'rgba(231,50,39,0.4)');
gradientBgRed.addColorStop(position, 'rgba(231,50,39,0.1');
gradientBgRed.addColorStop(1, 'rgba(231,50,39,0.1)');
return gradientBgRed;
}
function getGradientYellow(ctx, chartArea, scales) {
const gradientBgYellow = ctx.createLinearGradient(chartArea.left, 0, chartArea.right, 0);
var position = (scales.x.getPixelForValue(time_in_s/60) - scales.x.getPixelForValue(scales.x.min)) / chartArea.width;
if (position<=0) position = 0;
if (position>=1) position = 1;
gradientBgYellow.addColorStop(0, 'rgba(251,192,45,0.58)');
gradientBgYellow.addColorStop(position, 'rgba(251,192,45,0.58)');
gradientBgYellow.addColorStop(position, 'rgba(255,202,40,0.11)');
gradientBgYellow.addColorStop(1, 'rgba(255,202,40,0.11)');
return gradientBgYellow;
}
function getGradientBlue(ctx, chartArea, scales) {
const gradientBgBlue = ctx.createLinearGradient(chartArea.left, 0, chartArea.right, 0);
var position = (scales.x.getPixelForValue(time_in_s/60) - scales.x.getPixelForValue(scales.x.min)) / chartArea.width;
if (position<=0) position = 0;
if (position>=1) position = 1;
gradientBgBlue.addColorStop(0, 'rgba(94,146,243,0.58)');
gradientBgBlue.addColorStop(position, 'rgba(94,146,243,0.58)');
gradientBgBlue.addColorStop(position, 'rgba(3,169,244,0.11)');
gradientBgBlue.addColorStop(1, 'rgba(3,169,244,0.11)');
return gradientBgBlue;
}
function getGradientGreen(ctx, chartArea, scales) {
const gradientBgGreen = ctx.createLinearGradient(chartArea.left, 0, chartArea.right, 0);
var position = (scales.x.getPixelForValue(time_in_s/60) - scales.x.getPixelForValue(scales.x.min)) / chartArea.width;
if (position<=0) position = 0;
if (position>=1) position = 1;
gradientBgGreen.addColorStop(0, 'rgba(9,203,93,0.7)');
gradientBgGreen.addColorStop(position, 'rgba(9,203,93,0.7)');
gradientBgGreen.addColorStop(position, 'rgba(9,203,93,0.1');
gradientBgGreen.addColorStop(1, 'rgba(9,203,93,0.1)');
return gradientBgGreen;
}
const chartInfRateLayer = {
id: 'chartInfRateLayer',
afterDraw(chart, args, options) {
if (suitableForBoxes && boxesArray.length>0) {
const {ctx, chartArea: {top, right, bottom, left, width, height }, scales} = chart;
//load history array
//define corr_factor for y scale as % of cp scale
if (drug_sets[active_drug_set_index].drug_name == "Fentanyl") {
ymax = 3;
} else if (drug_sets[active_drug_set_index].drug_name == "Alfentanil") {
ymax = 90;
} else {
ymax = 5;
}
corr_factor = 1 * 3600 / drug_sets[active_drug_set_index].infusate_concentration / 200 * ymax;
xmargin = scales.x.getPixelForValue(scales.x.min);
//determine text size
textsize = 16 * (width / popupchart.width);
/*
x0 = scales.x.getPixelForValue(0);
x1 = scales.x.getPixelForValue(5) - x0;
y0 = scales.y.getPixelForValue(3);
y1 = scales.y.getPixelForValue(0) - y0;
console.log("***");
console.log(scales.x.getPixelForValue(scales.x.max));
console.log(scales.x.getPixelForValue(scales.x.min));
console.log(scales.x.getPixelForValue(5));
console.log(scales.x.getPixelForValue(10));
console.log(scales.x.getPixelForValue(15));
console.log(scales.x.getPixelForValue(20));
console.log("###");
console.log(scales.y.getPixelForValue(scales.y.max));
console.log(scales.y.getPixelForValue(scales.y.min));
*/
ctx.save();
for (icount = 0; icount < boxesArray.length; icount++) {
if (boxesArray[icount][1] > 0) {
ctx.fillStyle = 'rgba(128,128,128,0.5)';
x0 = scales.x.getPixelForValue(boxesArray[icount][0] / 60) + 2;
y0 = scales.y.getPixelForValue(boxesArray[icount][1] * corr_factor);
x1 = scales.x.getPixelForValue(boxesArray[icount][2] / 60) - x0 - 2;
y1 = scales.y.getPixelForValue(scales.y.min) - y0;
ctx.fillRect(x0,y0,x1,y1);
if (!isDark) {
ctx.fillStyle = "black";
} else {
ctx.fillStyle = "white";
}
ctx.font = "bold " + textsize + "px SourceSans";
ctx.fillText(Math.round(boxesArray[icount][1]*3600/drug_sets[active_drug_set_index].infusate_concentration*10)/10 + "ml/h", x0, y0 - textsize/3);
}
}
// bolus
bolustext = "";
bolustime = -1;
bolusArray = new Array();
textheight = 0;
if ((drug_sets[active_drug_set_index].manualmode_active > 0) || (drug_sets[active_drug_set_index].cpt_active > 0) || ((drug_sets[active_drug_set_index].cet_active > 0) && (drug_sets[active_drug_set_index].IB_active == 0))) {
for (icount = 0; icount<drug_sets[active_drug_set_index].historyarrays.length; icount++) {
if (drug_sets[active_drug_set_index].historyarrays[icount][1] == 1) {
bolustime = drug_sets[active_drug_set_index].historyarrays[icount][2];
if (drug_sets[active_drug_set_index].historyarrays[icount][3]>0) {
if (drug_sets[active_drug_set_index].historyarrays[icount].length > 4) {
bolustext = drug_sets[active_drug_set_index].historyarrays[icount][3] + drug_sets[active_drug_set_index].infused_units + " over " + drug_sets[active_drug_set_index].historyarrays[icount][5] + "s";
} else {
bolustext = drug_sets[active_drug_set_index].historyarrays[icount][3] + drug_sets[active_drug_set_index].infused_units;
}
} else {
bolustext = "";
}
if (bolustext != "") {
bolusArray.push(bolustime);
x0 = scales.x.getPixelForValue(bolustime/60);
ctx.font = "bold " + textsize + "px SourceSans";
if (!isDark) {
ctx.fillStyle = "black";
} else {
ctx.fillStyle = "white";
}
if (bolusArray.length>1) {
//if this is 10mins close to previous
if (bolusArray[bolusArray.length-1] - bolusArray[bolusArray.length-2] < 600) {
if (textheight < textsize * 6) {
textheight = textheight + textsize * 1.33;
ctx.fillText(bolustext, x0+10, 50+textheight);
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50+textheight);
} else {
textheight = 0;
ctx.fillText(bolustext, x0+10, 50);
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50);
}
} else {
ctx.fillText(bolustext, x0+10, 50);
textheight = 0;
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50);
}
} else {
ctx.fillText(bolustext, x0+10, 50);
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50);
}
}
} else {
bolustext = "";
}
} // end for loop
} // end if manual/cpt/cet block
//end "suitableForBoxes" check
} else {
if ((drug_sets[active_drug_set_index].cet_active > 0) && (drug_sets[active_drug_set_index].IB_active == 1)) {
//load chart context
const {ctx, chartArea: {width}, scales} = chart;
//determine text size
textsize = 14 * (width / popupchart.width);
ctx.save();
// bolus
bolustext = "";
bolustime = -1;
bolusArray = new Array();
textheight = 0;
for (icount = 0; icount<drug_sets[active_drug_set_index].historyarray.length; icount++) {
bolustime = drug_sets[active_drug_set_index].historyarray[icount][0];
if (drug_sets[active_drug_set_index].historyarray[icount][2]>0) {
bolustext = drug_sets[active_drug_set_index].historyarray[icount][2] + drug_sets[active_drug_set_index].infused_units;
} else {
bolustext = "";
}
if (bolustext != "") {
bolusArray.push(bolustime);
x0 = scales.x.getPixelForValue(bolustime/60);
ctx.font = "bold " + textsize + "px SourceSans";
if (!isDark) {
ctx.fillStyle = "rgba(0,0,0,0.7)";
} else {
ctx.fillStyle = "rgba(255,255,255,0.7)";
}
if (bolusArray.length>1) {
//if this is 10mins close to previous
if (bolusArray[bolusArray.length-1] - bolusArray[bolusArray.length-2] < 660) {
if (textheight < textsize * 7) {
textheight = textheight + textsize * 1.33;
ctx.fillText(bolustext, x0+10, 50+textheight);
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50+textheight);
} else {
textheight = 0;
ctx.fillText(bolustext, x0+10, 50);
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50);
}
} else {
ctx.fillText(bolustext, x0+10, 50);
textheight = 0;
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50);
}
} else {
ctx.fillText(bolustext, x0+10, 50);
ctx.font = 'normal 900 ' + textsize + 'px "Font Awesome 5 Free"';
ctx.fillText("\uf063", x0-5, 50);
}
}
} // end for loop
} // end if IB block
}
}
};
//charting scripts
setTimeout(
function() {
var ctx = document.getElementById('myChart').getContext('2d');
var y = document.getElementById('chartwrapper').offsetHeight*0.6;
myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Cp_', //obsolete
data: [{x: 0, y: 0}],
borderWidth:7,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: 'rgb(231, 50, 39,0.7)',
backgroundColor: 'rgb(231, 50, 39,0.4)',
pointBorderColor: 'rgb(231, 50, 39,0.8)',
pointBackgroundColor: 'rgb(231, 50, 39,0.8)',
fill: true,
parsing: false
},{
label: 'Ce_', //obsolete
data: [{x:0, y:0}],
borderWidth:7,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: 'rgb(9, 203, 93,0.7)',
backgroundColor: 'rgb(9, 203, 93,0.4)',
pointBorderColor: 'rgb(9, 203, 93,0.8)',
pointBackgroundColor: 'rgb(9, 203, 93,0.8)',
fill: true,
parsing: false
},{
label: 'Cp-Prop',
data: [{x: 0, y: 0}],
borderWidth:3,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: 'rgb(231, 50, 39,0.5)',
//borderDash: [2,2],
//borderColor: yellowSec,
//backgroundColor: gradientRed,//'rgb(100, 90, 90,0.1)',
backgroundColor: context => {
const chart = context.chart;
const { ctx, chartArea, scales } = chart;
if (!chartArea) {
return null ;
}
return getGradientRed(ctx, chartArea, scales);
},
//backgroundColor: 'rgb(0,0,0,0)',
segment: {
borderColor: ctx => behindPosition(ctx, 'rgb(231,50,39,0.7)'),
borderWidth: ctx => behindPosition2(ctx, 8)
},
fill: true,
hidden: false,
parsing: false
},{
label: 'Ce-Prop',
data: [{x:0, y:0}],
borderWidth:3,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: 'rgb(9, 203, 93,0.5)',
//borderColor: yellowPri50,
//backgroundColor: gradientGreen,//'rgb(90, 100, 90,0.1)',
backgroundColor: context => {
const chart = context.chart;
const { ctx, chartArea, scales } = chart;
if (!chartArea) {
return null ;
}
return getGradientGreen(ctx, chartArea, scales);
},
//backgroundColor: 'rgb(0,0,0,0)',
segment: {
borderColor: ctx => behindPosition(ctx, 'rgb(9,203,93,0.7)'),
borderWidth: ctx => behindPosition2(ctx, 8)
},
fill: true,
hidden: true, //this is for vetsimtiva
parsing: false
},{
label: 'Cp-Remi',
data: [{x: 0, y: 0}],
borderWidth:3,
pointRadius:0,
borderJoinStyle: 'round',
//borderDash: [2,2],
borderColor: bluePri,
//backgroundColor: gradientRed,//'rgb(100, 90, 90,0.1)',
/*
backgroundColor: context => {
const chart = context.chart;
const { ctx, chartArea, scales } = chart;
if (!chartArea) {
return null ;
}
return getGradientRed(ctx, chartArea, scales);
},
*/
//backgroundColor: 'rgb(0,0,0,0)',
segment: {
borderColor: ctx => behindPosition(ctx, blueLight),
borderWidth: ctx => behindPosition2(ctx, 8)
},
fill: false,
hidden: true,
parsing: false
},{
label: 'Ce-Remi',
data: [{x:0, y:0}],
borderWidth:3,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: blueLight,
//backgroundColor: gradientGreen,//'rgb(90, 100, 90,0.1)',
backgroundColor: context => {
const chart = context.chart;
const { ctx, chartArea, scales } = chart;
if (!chartArea) {
return null ;
}
return getGradientBlue(ctx, chartArea, scales);
},
segment: {
borderColor: ctx => behindPosition(ctx, blueSec),
borderWidth: ctx => behindPosition2(ctx, 8)
},
fill: true,
hidden: true,
parsing: false
},{ //index = 6 for propofol margins
label: 'P(upper)',
data: [{x:0, y:0}],
borderWidth:1,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: greenShadeDark,
backgroundColor: greenShade,
fill: '+1',
parsing: false
},{
label: 'P(lower)',
data: [{x:0, y:0}],
borderWidth:1,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: greenShadeDark,
fill: false,
parsing: false
},{ //index = 8 for remi margins
label: 'P(upper)',
data: [{x:0, y:0}],
borderWidth:1,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: greenShadeDark,
backgroundColor: greenShade,
fill: '+1',
parsing: false
},{
label: 'P(lower)',
data: [{x:0, y:0}],
borderWidth:1,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: greenShadeDark,
fill: false,
parsing: false
},{ //index = 10 for BIS margins
label: 'P(upper)',
data: [{x:0, y:0}],
borderWidth:1,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: greenShadeDark,
backgroundColor: greenShade,
fill: '+1',
parsing: false
},{
label: 'P(lower)',
data: [{x:0, y:0}],
borderWidth:1,
pointRadius:0,
borderJoinStyle: 'round',
borderColor: greenShadeDark,
fill: false,
parsing: false
}]
}, //end data
options: {
maintainAspectRatio: false,
interaction: {
},
scales: {
y: {
display: true,
min: 0,
max: 5,
title: {
display: true,
text:'Concentration'
}
},
x: {
type: 'linear',
display: true,
position:'bottom',
min:0,
max:20,
title: {
display: true,
text:'Time (minutes)'
}
}
},
animation: {
duration: 200
},
transitions: {
active: {
animation: {
duration: 200
}
}
},
plugins: { //start plugins
//shadingArea,
legend: {
onClick: null,
labels: {
boxWidth: 20,
filter: function(item, chart) { //this is for vetsimtiva
if (item.datasetIndex == 2) {
return true;
} else {
return false;
}
/*
var index = item.datasetIndex;
if ((index <= 1) || (index >= drug_sets.length*2+2)) {
return false;
} else {
return true;
}
*/
}
}
},
tooltip: {
mode: 'index',
intersect: false,
footerFont: {
weight: 'normal',
size: 10
},
filter: function(tooltipItem, data) { //this is for vetsimtiva
if (tooltipItem.datasetIndex == 2) {
return true;
} else {
return false;
}
/*
var index = tooltipItem.datasetIndex;
if ((index >= 2) && (index <=5)) {
return true;
} else {
return false;
}
*/
},
position: 'nearest',
caretSize: 0,
backgroundColor: 'rgba(0,0,0,0.5)',
callbacks: {
title: function(context) {
var title = context[0].parsed.x || "";
if (title) {
title = title*60; //to s
return converttime(title);
}
},
label: function(context) {
var label = context.dataset.label || '';
if (label) {
if ((label == "Cp-Prop") || (label == "Cp-Remi") || (label == "Cp-Fen") || (label == "Cp-Alfen")) label = "Cp:";
if ((label == "Ce-Prop") || (label == "Ce-Remi") || (label == "Ce-Fen") || (label == "Ce-Alfen")) label = "Ce:";
label += Math.round(context.parsed.y * 100) / 100;
return label;
}
},
footer: function(tooltipItems) {
var infrate = "Inf rate: ";
var vitext = "VI: ";
var parsedx = tooltipItems[0].parsed.x;
infrate = infrate + getinfusionrate(parsedx * 60,active_drug_set_index) + "ml/h";
vitext = vitext + Math.round(drug_sets[active_drug_set_index].volinf[Math.round(parsedx*60)]*10)/10 + "ml";
if ((PD_mode == 1) && (active_drug_set_index == 0)) {
PD_text = "eBIS: " + BIS_array[Math.round(parsedx*60)];
return [infrate, vitext, PD_text];
} else if ((PD_mode == 2) && (ptolcouplesarray.length>0)) {
temp_ptol_elem = ptolcouplesarray[Math.round(parsedx*2)];
if (temp_ptol_elem == undefined) {
PD_text = "";
} else {
PD_text = "PTOL: " + Math.round(temp_ptol_elem.meta_ptol * 100);
}
return [infrate, vitext, PD_text];
} else {
return [infrate, vitext];
}
}
}
},
crosshair: {
line: {
color: '#66F',
width: 1,
//dashPattern: [20,5]
},
sync: {
enabled: true, // enable trace line syncing with other charts
group: 1, // chart group
suppressTooltips: false // suppress tooltips when showing a synced tracer
},
zoom: {
enabled: false,
}
},
/*
annotation: {
annotations: {
line0: {
type: 'line',
drawTime: 'beforeDatasetsDraw',
xMin: getEventLine(0),
xMax: getEventLine(0),
borderColor: 'rgba(255,0,0,0.2)',
borderWidth: 2,
label: {
content: getEventLabel(0),