-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-unit-shift.php
1424 lines (1202 loc) · 54.1 KB
/
add-unit-shift.php
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
<?php
include 'includes/pre-head.php';
if (!isset($_SESSION['user'])) {
header("Location: index.php");
}
//use the CRUD object to access the database and to build option lists of the staff categories
$form_select_rn = $crud->getRnStaff();
$form_select_na = $crud->getNaStaff();
$form_select_uc = $crud->getUcStaff();
$form_select_assignment = $crud->getAllAssignments();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Header include -->
<?php include 'includes/head.php';?>
<!-- END Header include -->
</head>
<body>
<!-- NAV bar include -->
<?php include 'includes/navbar.php'; ?>
<!-- END NAV bar include -->
<!-- Alert include -->
<?php include 'includes/alert-header.php' ?>
<!-- END Alert include -->
<div class="container-fluid">
<div class="col-12">
<!-- NAV include -->
<?php include 'includes/nav-menu.php' ?>
<!-- END NAV include -->
</div>
<div class="col-10">
<h3>Add Shifts for the Unit</h3>
</div>
</div>
<div class="container-fluid">
<div class="row justify-content-center">
<!-- Alert Feedback -->
<div id="shift-form-feedback" class="col-8 form-control-feedback hidden">
</div>
</div>
<div class="row justify-content-center">
<div id="msf-container" class="col-sm-12">
<!-- Multi-step form goes here -->
<form id="unit-shift-form" class="unit-shift-form">
<div class="form-navigation m-1 text-center">
<button type="button" id="btn-prev" class="previous btn btn-secondary">< Previous</button>
<button type="button" id="btn-next" class="next btn btn-secondary">Next ></button>
<button type="submit" id="btn-submit" class="btn btn-secondary">Submit</button>
</div>
<div id="section-date-select" class="form-section form-inline mt-4 mb-4">
<!-- DATE SELECT -->
<div class="form-group">
<label class="control-label requiredField mr-1" for="date">Date: </label>
<div class="input-group mt-1">
<div class="input-group-addon"><i class="fa fa-calendar"></i></div>
<input class="form-control"
id="date"
name="date"
placeholder="YYYY/MM/DD"
value="<?= date('Y-m-d') ?>"
type="<?= (($detect->isMobile()) ? 'date' : 'text'); ?>"
<?= (($detect->isMobile()) ? ('max="'.date('Y-m-d').'" ') : ''); ?>
required>
</div>
<!-- DAY / NIGHT SELECT -->
<div class="btn-group requiredField ml-sm-1 mt-1" data-toggle="buttons">
<label class="btn btn-outline-primary active">
<input id="day-or-night-day" type="radio" name="day-or-night" value="D" autocomplete="off" checked required>
Day
</label>
<label class="btn btn-outline-primary">
<input id="day-or-night-night" type="radio" name="day-or-night" value="N" autocomplete="off">
Night
</label>
</div>
</div>
</div>
<!-- Select Clinician/Charge -->
<div id="section-nc-cn-select" class="form-section mt-4 mb-4">
<!-- RN Clinician SELECT -->
<div class="form-group">
<label class="control-label requiredField" for="nc-select">
Who is the Clinician for the shift?<span class="asteriskField">*</span>
</label>
<div id="nc-select-errors"></div>
<div id="nc-select" class="staff-select-group p-0 m-0" data-populate-with-staff-group="RN" data-populate-type="radio" data-populate-prefix="nc" data-populate-required="true">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
<!-- RN CHARGE SELECT -->
<div id="cn-select-group" class="form-group">
<label class="control-label requiredField" for="cn-select">
Who is the Charge for the shift?<span class="asteriskField">*</span>
</label>
<div id="cn-select-errors"></div>
<div id="cn-select" class="staff-select-group p-0 m-0" data-populate-with-staff-group="RN" data-populate-type="radio" data-populate-prefix="cn" data-populate-required="true">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<div id="section-nc-cn-pod-select" class="form-section mt-4 mb-4">
<!-- assign pods to the clinician/charge -->
<div class="form-group">
<label class="control-label requiredField" for="select">
Which pod was the Nurse Clinician in?<span class="asteriskField">*</span>
</label>
<div id="nc-pod-select-errors"></div>
<div id="nc-pod-select" class="staff-select-group p-0 m-0">
<?php
//Build Pod Select List
$i = true;
foreach ($form_select_assignment as $k => $v):
if ( (strpos($v, "B") === false) || (strlen($v) == 1) ) {
continue;
}
?>
<div class="inner-item list-group-item-action">
<label class="custom-control custom-radio m-1">
<input id="nc-pod-<?= $k ?>"
name="nc-pod-select"
type="radio"
value="<?= $k ?>"
<?= ($i === true)? ' required data-parsley-errors-container="#nc-pod-select-errors"':'' ?>
data-pod-name="<?= $v ?>"
class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description"><?= $v ?></span>
</label>
</div>
<?php
$i = false;
endforeach;
//END Build Pod Select List
?>
</div>
</div>
<div class="form-group">
<label class="control-label requiredField" for="cn-pod">
Which pod was the Charge Nurse in?<span class="asteriskField">*</span>
</label>
<div id="cn-pod-select-errors"></div>
<div id="cn-pod-select" class="staff-select-group p-0 m-0">
<?php
//Build Pod Select List
$i = true;
foreach ($form_select_assignment as $k => $v):
if ( (strlen($v) > 1) || ($v === "B") ) {
continue;
}
?>
<div class="inner-item list-group-item-action">
<label class="custom-control custom-radio m-1">
<input id="cn-pod-<?= $k ?>"
name="cn-pod-select"
type="radio"
value="<?= $k ?>"
<?= ($i === true)? ' required data-parsley-errors-container="#cn-pod-select-errors"':'' ?>
data-pod-name="<?= $v ?>"
class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description"><?= $v ?></span>
</label>
</div>
<?php
$i = false;
endforeach;
//END Build Pod Select List
?>
</div>
</div>
</div>
<!-- Floating nurse -->
<div id="section-float-rn-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="float-rn-check">
Was there a float nurse?
</label>
<div id="float-rn-check-errors"></div>
<div id="float-rn-check" class="staff-select-group p-0 m-0">
<div class="inner-item list-group-item-action">
<label class="custom-control custom-radio m-1">
<input id="float-rn-check-yes"
name="float-rn-check"
type="radio"
value="Yes"
required
data-parsley-errors-container="#float-rn-check-errors"
class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Yes</span>
</label>
</div>
<div class="inner-item list-group-item-action">
<label class="custom-control custom-radio m-1">
<input id="float-rn-check-no"
name="float-rn-check"
type="radio"
value="No"
checked
class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">No</span>
</label>
</div>
</div>
</div>
<div id="float-rn-select-group" class="form-group">
<label class="control-label" for="float-rn-select">
Who floated?
</label>
<div id="float-rn-select-errors"></div>
<div id="float-rn-select" class="staff-select-group p-0 m-0" data-populate-with-staff-group="RN" data-populate-type="checkbox" data-populate-prefix="float-rn" data-populate-required="false">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<div id="section-apod-rn-select" class="form-section mt-4 mb-4">
<!-- Select Bedside Nurses for A -->
<div class="form-group">
<label class="control-label requiredField" for="select">
Select the nurses for Pod A<span class="asteriskField">*</span>
</label>
<div id="apod-rn-select-errors"></div>
<div id="apod-rn-select" class="staff-select-group p-0 m-0" data-populate-with-staff-group="RN" data-populate-type="checkbox" data-populate-prefix="apod-rn" data-populate-required="true">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<div id="section-bpod-rn-select" class="form-section mt-4 mb-4">
<!-- Select Bedside Nurses for B -->
<div class="form-group">
<label class="control-label requiredField" for="select">
Select the nurses for Pod B<span class="asteriskField">*</span>
</label>
<div id="bpod-rn-select-errors"></div>
<div id="bpod-rn-select" class="staff-select-group p-0 m-0" data-populate-with-staff-group="RN" data-populate-type="checkbox" data-populate-prefix="bpod-rn" data-populate-required="true">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<div id="section-cpod-rn-select" class="form-section mt-4 mb-4">
<!-- Select Bedside Nurses for C -->
<div class="form-group">
<label class="control-label requiredField" for="select">
Select the nurses for Pod C<span class="asteriskField">*</span>
</label>
<div id="cpod-rn-select-errors"></div>
<div id="cpod-rn-select" class="staff-select-group p-0 m-0" data-populate-with-staff-group="RN" data-populate-type="checkbox" data-populate-prefix="cpod-rn" data-populate-required="true">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<!-- Who had non-vent -->
<div id="section-non-vent-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses had only non-ventilated patients?
</label>
<div id="non-vent-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who had double -->
<div id="section-double-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses were doubled?
</label>
<div id="double-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who admitted -->
<div id="section-admit-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses admitted patients?
</label>
<div id="admit-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who had very sick -->
<div id="section-very-sick-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses had a very sick patient <small>(3 gtt's or more)</small>?
</label>
<div id="very-sick-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who had code pager -->
<div id="section-code-pager-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses had the code pager?
</label>
<div id="code-pager-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who had crrt -->
<div id="section-crrt-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses had crrt?
</label>
<div id="crrt-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who had evd -->
<div id="section-evd-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses had an EVD?
</label>
<div id="evd-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<!-- Who who had burn -->
<div id="section-burn-mod-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label" for="div">
Which nurses had a burn patient?
</label>
<div id="burn-mod-select" class="staff-select-group p-0 m-0">
<!-- Add handlebars template here -->
</div>
</div>
</div>
<div id="section-na-select" class="form-section mt-4 mb-4">
<!-- Select NA's -->
<div class="form-group">
<label class="control-label requiredField" for="select">
Select the NA's<span class="asteriskField">*</span>
</label>
<div id="na-select-errors"></div>
<div id="na-select" class="staff-select-group p-0 m-0"
data-populate-with-staff-group="NA,LPN"
data-populate-type="checkbox"
data-populate-prefix="na"
data-populate-required="false">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<!-- assign pods to the na's -->
<div id="section-na-pod-select" class="form-section mt-4 mb-4 skip-section">
<!-- dynamic pod select template generated here -->
</div>
<div id="section-uc-select" class="form-section mt-4 mb-4">
<!-- Select UC's -->
<div class="form-group">
<label class="control-label requiredField" for="select">
Select the UC's<span class="asteriskField">*</span>
</label>
<div id="uc-select-errors"></div>
<div id="uc-select" class="staff-select-group p-0 m-0"
data-populate-with-staff-group="UC"
data-populate-type="checkbox"
data-populate-prefix="uc"
data-populate-required="false">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<!-- assign pods to the uc's -->
<div id="section-uc-pod-select" class="form-section mt-4 mb-4 skip-section">
<!-- dynamic pod select template generated here -->
</div>
<!-- Select Outreach RN -->
<div id="section-outreach-rn-select" class="form-section mt-4 mb-4">
<div class="form-group">
<label class="control-label requiredField" for="outrach-rn">
Who was on outreach?<span class="asteriskField">*</span>
</label>
<div id="outreach-rn-select-errors"></div>
<div id="outreach-rn-select" class="staff-select-group p-0 m-0"
data-populate-with-staff-group="RN"
data-populate-type="radio"
data-populate-prefix="outreach-rn"
data-populate-required="true">
<!-- dynamic staff select built here -->
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
<div class="form-navigation m-1 text-center">
<button type="button" id="btn-prev" class="previous btn btn-secondary">< Previous</button>
<button type="button" id="btn-next" class="next btn btn-secondary">Next ></button>
<button type="submit" id="btn-submit" class="btn btn-secondary">Submit</button>
</div>
</form>
</div>
</div>
<div class="row justify-content-center">
<div class="col-8">
<!-- Progess bar -->
<div class="progress">
<div id="step-progress" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<!-- <p id="step-x-of-y" class="text-center"></p> -->
</div>
</div>
</div>
<!-- Spacer for the bottom -->
<div class="container">
<br />
<br />
<br />
</div>
<!-- Spacer for the bottom -->
<!-- Bootstrap Modal -->
<div id="submission-modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<!-- submission modal content -->
<div class="modal-content" id="shift-detail-modal-content">
<div class="modal-header">
<h5 class="modal-title">Submission Details:</h5>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body" id="submission-modal-body"></div>
<div class="modal-footer">
<button id="modal-close" type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.submission modal content -->
</div>
</div>
<!-- Prefooter Include -->
<?php include 'includes/script-include.php'; ?>
<!-- END Prefooter Include -->
<!-- Handlebars templates -->
<script id="hbt-shift-modifier-checkbox" type="text/x-handlebars-template">
<?php include 'includes/templates/UnitShiftShiftModCheckbox.handlebars'; ?>
</script>
<script id="hbt-staff-pod-select" type="text/x-handlebars-template">
<?php include 'includes/templates/StaffPodSelect.handlebars'; ?>
</script>
<!-- END Handlebars templates -->
<!-- Aux Scripts -->
<script>
//Global scope variables
var debug = true; // debug flag
var shiftModifierCheckboxTemplate = null;
var staffPodSelectTemplate = null;
var lastDate = null;
var $disabledPrn = null;
var staffList = {}; //Object of all the staff not previously selected for the date to be added
var bedsideRnStaffList = [];
var assignmentList = JSON.parse('<?= json_encode($crud->getAllAssignmentObj()) ?>');
var roleList = JSON.parse('<?= json_encode($crud->getAllRoleObj()) ?>');
var $sections = null;
var dateChangeTimer; //variable to prevent ajax request for staff to not update too often
var dateChangeTimerInterval = 1500;
//TODO Bind to the window, so that if user tries to back out while form is dirty, then prompts to ask
$(function() {
<?php if (!$detect->isMobile()): ?>
$('#date').datepicker({
format: "yyyy-mm-dd",
orientation: "bottom auto",
autoclose: true,
endDate: "0d"
});
<?php endif; ?>
/**
* Event listener for change of date to populate the staff list
* Prevents ajax from being called too often
*/
$('#date').on('change', function(){
if (debug) console.log("Date change event occured.");
//clear out the old timer
clearTimeout(dateChangeTimer);
//get the value of the current date selected
let d = $(this).val();
//make a new timer
dateChangeTimer = setTimeout( function(){
if (debug) console.log("Change timeout elapsed, calling function.");
getStaffFilteredByDate(d);
}, dateChangeTimerInterval);
})
//get the initial list of staff based on default date
getStaffFilteredByDate($('#date').val());
/********************************************************
* FORM PAGINATION - CREDIT TO Parsely.js DOCUMENTATION *
********************************************************/
$sections = $('.form-section'); // list all all the form-section elements
/**
* navigateTo - shows/hides the appropriate form section based on the index
* @var integer index Numeric index of the element in the $sections array of DOM elements
*/
var oldIndex = -1; //reference to be able to know if traverseing forward or backward
function navigateTo(index) {
// Mark the current section with the class 'current'
var $temp = $sections.removeClass('current')
.eq(index);
updateFormSection($temp);
//check if section should be skipped
while ( $temp.hasClass('skip-section') ) { //loop until section found which shouldnt be skipped
if ( oldIndex > index ) { //if moving backwards
$temp = $sections.eq(--index); //look back one more section
} else if ( oldIndex < index ) { //if moving forwards
$temp = $sections.eq(++index); //look ahead one more section
}
updateFormSection($temp);
}
$temp.addClass('current');
// Show only the navigation buttons that make sense for the current section:
$('.form-navigation .previous').attr("disabled", !(index > 0))
.toggleClass("btn-primary", (index > 0))
.toggleClass("btn-secondary", !(index > 0));
var atTheEnd = index >= $sections.length - 1;
$('.form-navigation .next').attr("disabled", (atTheEnd))
.toggleClass("btn-primary", (!atTheEnd))
.toggleClass("btn-secondary", (atTheEnd));
$('.form-navigation [type=submit]').attr("disabled", (!atTheEnd))
.toggleClass("btn-primary", (atTheEnd))
.toggleClass("btn-secondary", (!atTheEnd));
//update progress bar
var progress = (index + 1)/$sections.length*100;
$('#step-progress').attr('aria-valuenow', progress).css("width",(progress+"%"));
//$('#step-x-of-y').html(`Step ${index + 1} of ${$sections.length}`);
//update reference index
oldIndex = index;
}
/**
* Control logic to update each form based on the previous sections of the form completed.
* @param DOMelement $section reference to the div which has the 'sec'
* @return [type] [description]
*/
function updateFormSection($section) {
let sectionId = $section.prop('id'); //get the current section's name
if (debug) console.log(`Updating form section: '${sectionId}'`);
//each block allows it to update itself based on previously completed form sections
if ( sectionId == 'section-nc-cn-select' ) {
//getStaffFilteredByDate($('#date').val());
} else if ( sectionId == 'section-float-rn-select' ) {
hideAlreadyPicked('#float-rn-select', ['nc-select', 'cn-select']);
} else if ( sectionId == 'section-apod-rn-select' ) {
hideAlreadyPicked('#apod-rn-select', ['nc-select', 'cn-select', 'float-rn-select']);
} else if ( sectionId == 'section-bpod-rn-select' ) {
hideAlreadyPicked('#bpod-rn-select', ['nc-select', 'cn-select', 'float-rn-select', 'apod-rn-select']);
} else if ( sectionId == 'section-cpod-rn-select' ) {
hideAlreadyPicked('#cpod-rn-select', ['nc-select', 'cn-select', 'float-rn-select', 'apod-rn-select', 'bpod-rn-select']);
} else if ( sectionId == 'section-outreach-rn-select' ) {
hideAlreadyPicked('#outreach-rn-select', ['nc-select', 'cn-select', 'float-rn-select', 'apod-rn-select', 'bpod-rn-select', 'cpod-rn-select']);
} else if ( sectionId == 'section-non-vent-mod-select' ) {
bedsideRnStaffList = getStaffFromCheckboxes(['apod-rn-select', 'bpod-rn-select', 'cpod-rn-select']);
popStaffShiftModifierList('#non-vent-mod-select', 'non-vent-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-double-mod-select' ) {
popStaffShiftModifierList('#double-mod-select', 'double-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-admit-mod-select' ) {
popStaffShiftModifierList('#admit-mod-select', 'admit-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-very-sick-mod-select' ) {
popStaffShiftModifierList('#very-sick-mod-select', 'very-sick-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-code-pager-mod-select' ) {
popStaffShiftModifierList('#code-pager-mod-select', 'code-pager-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-crrt-mod-select' ) {
popStaffShiftModifierList('#crrt-mod-select', 'crrt-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-evd-mod-select' ) {
popStaffShiftModifierList('#evd-mod-select', 'evd-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-burn-mod-select' ) {
popStaffShiftModifierList('#burn-mod-select', 'burn-mod-select', bedsideRnStaffList);
} else if ( sectionId == 'section-na-pod-select' ) {
popPodSelectList('#section-na-pod-select', 'na-pod-select', getStaffFromCheckboxes(['na-select']), assignmentList);
setParsleyJsGroup('#section-na-pod-select', $('#section-na-pod-select').data('blockIndex'));
} else if ( sectionId == 'section-uc-pod-select' ) {
popPodSelectList('#section-uc-pod-select', 'uc-pod-select', getStaffFromCheckboxes(['uc-select']), assignmentList);
setParsleyJsGroup('#section-uc-pod-select', $('#section-uc-pod-select').data('blockIndex'));
}
}
// Return the current index by looking at which section has the class 'current'
function curIndex() {
return $sections.index($sections.filter('.current'));
}
// Previous button is easy, just go back
$('.form-navigation .previous').click(function() {
navigateTo(curIndex() - 1);
});
// Next button goes forward iff current block validates
$('.form-navigation .next').click(function() {
$('.unit-shift-form').parsley().whenValidate({
group: 'block-' + curIndex()
}).done(function() {
navigateTo(curIndex() + 1);
});
});
// Prepare sections by setting the `data-parsley-group` attribute to 'block-0', 'block-1', etc.
$sections.each(function(index, section) {
$(this).data('blockIndex', index);
setParsleyJsGroup(section, index);
});
navigateTo(0); // Start at the beginning
//catch the on-submit event, collect/format data from the form, submit via ajax
$('#unit-shift-form').parsley().on('form:submit', function () {
submitUnitShiftForm();
return false; //return false to prevent HTML form submission
});
/***************************************
* END -- FORM PAGINATION / VALIDATION *
***************************************/
//call the function to set listeners on the div's that contain the checkboxes to make more accessible
setClickAreaListeners("div.staff-select-group");
//hide the option for the nc to select pod 'A/B/C' when the day shift button is preselected (default state)
hideFormInnerItem($(`#nc-pod-8`));
/**
* listener to change behavior of form if float nurse is to be selected
* @var [type]
*/
$(`#float-rn-check-yes`).closest('div').click(function() {
$(`#float-rn-select-group`).toggle(true); //show float nurse select
$(`input[name='float-rn-select']`).first().prop("required", true); // add the required property to the float-rn-select select
});
/**
* listener to change behavior of form if no float nurse is to be added
* @var [type]
*/
$(`#float-rn-check-no`).closest('div').click(function() {
$(`#float-rn-select-group`).toggle(false); //show float nurse select
$(`input[name='float-rn-select']`).first().prop("required", false); // add the required property to the float-rn-select select
let $frnElem = $(`input[type='checkbox'][name='float-rn-select']:checked`); //unselect any selected float-rn-select value
if ($frnElem !== null) { $frnElem.prop("checked", false); }
});
/**
* listener to change behavior of form if day shift is selected for input
* @var [type]
*/
$(`#day-or-night-day`).closest('label').click(function() {
$(`#cn-select-group`).toggle(true); // show charge nurse select
$(`#section-nc-cn-pod-select`).toggleClass('skip-section', false); // show section for pod selection for nc/cn
$(`input[name='cn-select']`).first().prop("required", true); // add the required property to the first cn-select
$(`#cn-pod-select input`).first().prop("required", true); // add the required property to the first cn-pod-select
hideFormInnerItem($(`#nc-pod-8`));
});
/**
* listener to change behavior of form if night shift is selected for input
* @var [type]
*/
$(`#day-or-night-night`).closest('label').click(function() {
$(`#cn-select-group`).toggle(false); // hide charge nurse select
$(`#section-nc-cn-pod-select`).toggleClass('skip-section', true); // hide section for pod selection for nc/cn
$(`input[name='cn-select'][required]`).prop("required", false); // remove the required property from the cn-select select
$(`input[name='cn-pod-select'][required]`).prop("required", false); // remove the required property from the cn-select select
showFormInnerItem($(`#nc-pod-8`)); //auto-select pod A/B/C for the nc
$(`#nc-pod-8`).prop("checked", true);
let $cnElem = $(`input[type='radio'][name='cn-select']:checked`); //unselect any selected cn-select value
if ($cnElem !== null) { $cnElem.prop("checked", false); }
let $cnPodElem = $(`input[type='radio'][name='cn-pod-select']:checked`); //unselect any selected cn-select value
if ($cnPodElem !== null) { $cnPodElem.prop("checked", false); }
});
/**
* when the nc's assigned pod is clicked, the charge nurse's pod changes to the appropriate selection
* @var [type]
*/
$(`#nc-pod-select div.inner-item`).click(function() {
let clickedPodName = $(this).find('input').data('podName').replace(/[\/B]/g, ''); //which main pod was chosen, get rid of the B-pod
$(`input[type='radio'][name='cn-pod-select']`)
.filter(function() {
//find the non-matching main pod assignment -- eg: if pod A was chosen by nc, choose pod C for cn
return (!($(this).closest('div').hasClass('st-none'))) && ($(this).data('podName').indexOf(clickedPodName) < 0);
})
.prop("checked", true); //select it
return true;
});
/**
* when the cn's assigned pod is clicked, the nc's pod changes to the appropriate selection
* @var [type]
*/
$(`#cn-pod-select div.inner-item`).click(function() {
let clickedPodName = $(this).find('input').data('podName'); //which main pod was chosen
$(`input[type='radio'][name='nc-pod-select']`)
.filter(function() {
//find the non-matching main pod assignment -- eg: if pod A was chosen by cn, choose pod C for nc
return (!($(this).closest('div').hasClass('st-none'))) && ($(this).data('podName').indexOf(clickedPodName) < 0);
})
.prop("checked", true); // select it
return true;
});
//compile the shift modifier checkbox template with Handlebars
shiftModifierCheckboxTemplate = Handlebars.compile($("#hbt-shift-modifier-checkbox").html());
staffPodSelectTemplate = Handlebars.compile($("#hbt-staff-pod-select").html());
}); //End on document ready function
function setParsleyJsGroup(section, index) {
return $(section).find(':input').attr('data-parsley-group', 'block-' + index);
}
/**
* [setClickAreaListeners description]
* @param [type] target [description]
*/
function setClickAreaListeners(target) {
//listener for click in the div to increase radio/checkbox active area
$(target).find(`div.inner-item`).each(function(){
$(this).click(function() {
let $elem = $(this).find("input[type='checkbox'], input[type='radio']"); // find checkbox associated
if (!$elem.prop("disabled")) {
$elem.prop("checked", !($elem.prop("checked"))); // toggle checked state
}
let parentId = $(this).parent().prop('id');
if (parentId == "nc-select") {
if ($disabledPrn !== null) {
enableFormInnerItem($disabledPrn);
}
let $ncChoice = $(this).find("input[type='radio']");
let $elem = $(`input[type='radio'][name='cn-select'][value='${$ncChoice.val()}']`);
if ($elem !== null) {
disableFormInnerItem($elem);
$disabledPrn = $elem;
}
} else if (parentId == "na-select") {
if ($(`input[name='na-select']:checked`).length) {
$(`#section-na-pod-select`).removeClass('skip-section');
} else {
$(`#section-na-pod-select`).addClass('skip-section');
}
} else if (parentId == "uc-select") {
if ($(`input[name='uc-select']:checked`).length) {
$(`#section-uc-pod-select`).removeClass('skip-section');
} else {
$(`#section-uc-pod-select`).addClass('skip-section');
}
}
return false; // return false to stop click propigation
});
});
}
function getStaffFromCheckboxes(names) {
names = names || [];
let jquerySelector = '';
//iterate through the array of checkbox names to check for selected staff, building the query selector string
names.forEach(function (name) {
jquerySelector += `input[name='${name}'][type='checkbox']:checked, `;
});
//get rid of the last comma and space (', ')
jquerySelector = jquerySelector.slice(0, -2);
//find the selected staff, map the results into an array of object literals
return $(jquerySelector).map(function () {
return {id: $(this).val(), name: $(this).data("staffName")};
})
.get()
.sort(function(a, b){
if (a.name < b.name) {
return -1;
} else if (a.name > b.name) {
return 1;
}
return 0;
});
}
/**
* [popStaffShiftModifierList description]
* @return [type] [description]
*/
function popStaffShiftModifierList(target, shiftModName, staffList) {
$(target).html(shiftModifierCheckboxTemplate({modifier: shiftModName, staff: staffList}));
setClickAreaListeners(`${target}`);
}
/**
* [popNaPodSelectList description]
* @return [type] [description]
*/
function popPodSelectList(target, sectionName, staffList, podList) {
let x = {section: sectionName, pod: podList, staff: staffList};
$(target).html(staffPodSelectTemplate(x));
}
/**
* This hides staff choices in a target div element based on an array of specified divs
* @param string targetId the id of the target div
* @param string[] hideBasedOn the id('s) of the divs to base the hiding on
* @return void
*/
function hideAlreadyPicked(targetId, hideBasedOn) {
//reset all hidden
$(`${targetId} div.st-none`).each(function() {
showFormInnerItem($(this).find('input'));
});
//foreach radio/checkbox name specified
hideBasedOn.forEach(function(s) {
//select any checked staff
$(`input[name='${s}']:checked`).each(function() {
//get the staff id (set as value)
let val = $(this).val();
//hide the staff choice from the current target
hideFormInnerItem($(`${targetId} input[value='${val}']`));
});
});
}
/**
* Shows the inner inner-item
* @param [type] $elem [description]
* @return [type] [description]
*/
function showFormInnerItem($elem) {
try {
$elem.closest("div").removeClass('st-none').toggle(true);
enableFormInnerItem($elem);
return true;
} catch (e) {
return false;
}
}
/**
* [hideFormInnerItem description]
* @param [type] $elem [description]
* @return [type] [description]
*/
function hideFormInnerItem($elem) {
try {
$elem.closest("div").addClass('st-none').toggle(false);
disableFormInnerItem($elem);
return true;
} catch (e) {
return false;
}
}
/**
* [enableFormInnerItem description]
* @param [type] $elem [description]
* @return [type] [description]
*/
function enableFormInnerItem($elem) {
try {
$elem.prop("disabled", false);
$elem.closest("div").toggleClass("list-group-item-action");