-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.html
1818 lines (1564 loc) · 66.8 KB
/
setup.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- The above meta tag must immediately follow the head element (no empty newlines) for IE7 to render in 'standards mode -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<!-- The title at the top of the page. -->
<title>Trialist Setup</title>
<!-- JSON because IE<8 -->
<script src="https://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.min.js">
</script>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- jQuery stuff -->
<script src="js/jquery-1.9.0.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<!-- Less stuff -->
<script src="js/less-1.3.3.min.js"></script>
<!-- Bootstrap stuff -->
<link href="https://fonts.googleapis.com/css?family=Limelight|Flamenco|Federo|Yesteryear|Josefin Sans|Spinnaker|Sansita One|Handlee|Droid Sans|Oswald:400,300,700" media="screen" rel="stylesheet" type="text/css" />
<link href="bootstrap/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="bootstrap/css/bootstrap-responsive.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="bootstrap/less/dropdowns.less" rel="stylesheet/less" />
<link href="bootstrap/less/sprites.less" rel="stylesheet/less" />
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DatePicker stuff -->
<link href="datepicker/css/datepicker.css" rel="stylesheet" type="text/css" />
<link href="datepicker/build/build.less" rel="stylesheet/less" />
<link href="datepicker/build/build_standalone.less" rel="stylesheet/less" />
<link href="datepicker/less/datepicker.less" rel="stylesheet/less" />
<script src="datepicker/js/bootstrap-datepicker.js"></script>
<!-- CSS Stuff -->
<link href="css/UserSetup.css" media="screen" rel="stylesheet" type="text/css" />
<!-- Wicked Good XPath -->
<script src="js/wgxpath.install.js"></script>
</head>
<body>
<!--
This JavaScript should be run before any of the page is rendered.
-->
<script type="text/javascript">
/**
* Retrieves a cookie's value.
*/
function getCookie(name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for(i = 0; i < ARRcookies.length; i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x == name)
{
return unescape(y);
}
}
}
/**
* Redirects the user to the login page.
*/
function redirectToLogin() {
<!--
$.cookie('trialist_redirect', '/trialist', {path: '/'});
document.location = "/web";
//-->
}
/**
* Retrieves the authentication token cookie or redirects the user to
* the login page.
*
* @return The user's authentication token or null if no authentication
* token exists.
*/
function getAuthToken() {
// Attempt to retrieve the authentication token.
var authToken = getCookie("auth_token");
// If the token is missing, redirect the user back to the login
// page.
if(
(authToken === null) ||
(typeof authToken === "undefined") ||
(authToken === ""))
{
// Set the authentication token to null;
authToken = null;
// Send the user to the login page.
redirectToLogin();
}
// Return whatever we have as the authentication token.
return authToken;
}
// Check for the authentication token before loading the page. If it
// doesn't exist, we will be redirected to the homepage before any of
// the UI elements are rendered.
getAuthToken();
// Install the Wicked Good XPath library.
wgxpath.install();
</script>
<script type="text/javascript">
// Expire the redirect cookie once a successful login occurs.
// This cannot happen in the above script tag because the browser
// can continue executing that JavaScript after the redirect to /
// has occurred.
$.cookie('trialist_redirect', '/trialist', { path: '/', expires: new Date() });
</script>
<div class="container">
<div style="box-shadow: 1px 0px 4px 0 #E0E0E0;">
<div style="box-shadow: -1px 0px 4px 0 #E0E0E0;">
<div id="alertModal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h3 id="alertHeader"></h3>
</div>
<div class="modal-body">
<div class="alertInfo"></div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span5"><h1>Trialist Participant Setup</h1></div>
<div class="span2"></div>
<div class="span5">
<div class="row-fluid">
<div class="btn-toolbar pull-right">
<div class="btn-group">
<button class="btn btn-inverse"
style="background: #738077; color: white;" id="help">Information
About Prescribing Opioids</button>
</div>
<div class="btn-group">
<button class="btn btn-inverse" id="logout">Logout</button>
</div>
</div>
</div>
<div class="row-fluid">
<div class="pull-right">
<small><i class="icon-question-sign" style="padding-left: 5px;"></i><a href="mailto:[email protected]">[email protected]</a></small>
</div>
</div>
</div>
</div>
</div>
<div id="helpArea" class="well">
<h3>General Principles when prescribing opioids for chronic
pain</h3>
<ul>
<li>Use the lowest possible effective dose when opioid
analgesics are considered for the management of pain.</li>
<li>When switching opioids, find an equivalent dose based on
the patient's current dosage and consider a reduction for
incomplete cross tolerance (see hyperlink below for opioid
equianalgesic dosages).</li>
<li>To assess for opioid misuse or addiction, consider using
targeted history or validated screening tools (see hyperlink
below for paper questionnaires).</li>
<li>Prescribers are advised to access a prescription
monitoring program (PMP) to ensure that patients are not involved
in doctor shopping (see hyperlink below for California’s
Prescription Drug Monitoring Program (CURES).</li>
<li>When feasible, avoid simultaneous prescribing of opioid
analgesics and benzodiazepines. This combination raises the risk
of inadvertent overdose.</li>
<li>Because of its added depressant effects, tramadol should
be prescribed with caution for those patients whose medical
condition requires the concomitant administration of sedatives,
tranquilizers, muscle relaxants, antidepressants, or other CNS
depressant drugs.</li>
<li>Provide information about opioid analgesics to patients
receiving a prescription, such as the risks of overdose and
dependence/ addiction, as well as safe storage and proper
disposal of unused medications (see hyperlink below for patient
instructions).</li>
</ul>
<h3>Online references for safe opioid prescribing</h3>
<table class="table table-bordered"
style="table-layout: fixed; width: 100%; word-wrap: break-word;">
<tr>
<th colspan="2">Opioid safety and risk management</th>
</tr>
<tr>
<td>Balancing Pain Management and Prescription Opioid Abuse</td>
<td><a
href="http://www.cdc.gov/primarycare/materials/opoidabuse/index.html">http://www.cdc.gov/primarycare/materials/opoidabuse/index.html</a></td>
</tr>
<tr>
<td>Preventing misuse and adverse events</td>
<td><a href="http://pain-topics.org/opioid_rx/safety.php">http://pain-topics.org/opioid_rx/safety.php</a></td>
</tr>
<tr>
<th>Opioid drug interactions</th>
<td><a
href="https://www.painedu.org/tools/drug_drug_interactions.asp">https://www.painedu.org/tools/drug_drug_interactions.asp</a></td>
</tr>
<tr>
<th>Opioid equianalgesic dosages</th>
<td><a href="http://www.globalrph.com/narcoticonv.htm">http://www.globalrph.com/narcoticonv.htm</a></td>
</tr>
<tr>
<th>Opioid side effects</th>
<td><a href="http://www.medscape.org/viewarticle/573016">http://www.medscape.org/viewarticle/573016</a></td>
</tr>
<tr>
<th colspan="2">Paper questionnaires for screening before
starting opioids</th>
</tr>
<tr>
<td>Screener and Opioid Assessment for Patients with Pain
(SOAPP)</td>
<td><a href="http://www.painedu.org/soapp.asp">http://www.painedu.org/soapp.asp</a></td>
</tr>
<tr>
<td>Opioid Risk Tool (ORT)</td>
<td><a
href="http://www.partnersagainstpain.com/printouts/Opioid_Risk_Tool.pdf">http://www.partnersagainstpain.com/printouts/Opioid_Risk_Tool.pdf</a>
</tr>
<tr>
<th colspan="2">Paper questionnaires for monitoring during
long-term opioid therapy</th>
</tr>
<tr>
<td>Pain Assessment and Documentation Tool (PADT)</td>
<td><a
href="http://www.ucdenver.edu/academics/colleges/PublicHealth/research/centers/maperc/online/Documents/Pain Assessment Documentation Tool %28PADT%29.pdf">http://www.ucdenver.edu/academics/colleges/PublicHealth/research/centers/maperc/online/Documents/Pain
Assessment Documentation Tool %28PADT%29.pdf</a></td>
</tr>
<tr>
<td>Current Opioid Misuse Measure (COMM)</td>
<td><a href="http://www.painedu.org/soapp.asp">http://www.painedu.org/soapp.asp</a></td>
</tr>
<tr>
<th colspan="2">Patient instructions</th>
</tr>
<tr>
<td>A Guide to Safe Use of Pain Medicine</td>
<td><a
href="http://www.fda.gov/downloads/ForConsumers/ConsumerUpdates/ucm095742.pdf">http://www.fda.gov/downloads/ForConsumers/ConsumerUpdates/ucm095742.pdf</a></td>
</tr>
<tr>
<td>Disposal of medications</td>
<td><a
href="http://www.fda.gov/drugs/resourcesforyou/consumers/buyingusingmedicinesafely/ensuringsafeuseofmedicine/safedisposalofmedicines/ucm186187.htm">http://www.fda.gov/drugs/resourcesforyou/consumers/buyingusingmedicinesafely/ensuringsafeuseofmedicine/safedisposalofmedicines/ucm186187.htm</a></td>
</tr>
<tr>
<th>Prescription Drug Monitoring Program</th>
<td><a href="https://pmp.doj.ca.gov/pdmp/index.do">https://pmp.doj.ca.gov/pdmp/index.do</a></td>
</tr>
<tr>
<th colspan="2">Urine drug testing</th>
</tr>
<tr>
<td>Urine Drug Testing: Current Recommendations and Best
Practices See Table 5 for immunoassay cross-reactions (false
positives)</td>
<td><a
href="http://www.painphysicianjournal.com/2012/july/2012;15;ES119-ES133.pdf">http://www.painphysicianjournal.com/2012/july/2012;15;ES119-ES133.pdf</a></td>
</tr>
</table>
</div>
<div class="light-grey row-fluid" style="margin-bottom: 0px;">
<form class="form-horizontal" action="#">
<h4 class="heading" style="padding-left: 10px; color: white;">
Patient Information</h4>
</form>
</div>
<div class="well" style="margin: 0px;">
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label">Patient's Login:</label>
<div class="controls">
<select id="selectUser">
</select>
</div>
</div>
</form>
</div>
<div class="light-grey row-fluid" style="margin-bottom: 0px;">
<form class="form-horizontal" action="#">
<h4 class="heading heading-shaddow" style="padding-left: 10px; color: white;">
Study Protocol
</h4>
</form>
</div>
<div class="well" style="margin: 0px;">
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label"><span class="dotted_underline" title="A treatment or treatments to be used in the personalized trial.">Regimen A:</span></label>
<div id="regimenA" class="controls"></div>
</div>
</form>
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label"><span class="dotted_underline" title="Treatment or treatments to be compared to the Regimen A selections.">Regimen B:</span></label>
<div id="regimenB" class="controls"></div>
</div>
</form>
<hr/>
<form class="form-horizontal" action="#">
<div class="control-group">
<div class="controls">
<span>Do you intend to prescribe or continue any pain treatments in addition to the ones selected above?</span>
<div>
<label class="radio inline">
<input type="radio" name="extraTreatmentRadios" id="extraTreatmentRadios1" value="yes">Yes
</label>
<label class="radio inline">
<input type="radio" name="extraTreatmentRadios" id="extraTreatmentRadios2" value="no">No
</label>
</div>
</div>
</div>
</form>
<hr/>
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label"><span class="dotted_underline" title="The day the personalized trial starts.">Study Start Date:</span></label>
<div class="controls">
<div class="input-append date datepicker" id="startDatePicker"
data-date-format="yyyy-mm-dd">
<input id="startDate" size="16" type="text" readonly><span
class="add-on"><i class="icon-th"></i></span>
</div>
</div>
</div>
</form>
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label"><span class="dotted_underline" title="The number of weeks to be spent on each Regimen. At the end of the period, a switch to the next Regimen occurs.">Period Length:</span></label>
<div class="controls">
<select id="regimenDuration">
<option value="1" data-value="7">7 days</option>
<option value="2" data-value="14">14 days</option>
</select>
</div>
</div>
</form>
<form class="form-horizontal" action="#">
<div class="control-group">
<label class="control-label"><span class="dotted_underline" title="The number of times for a full cycle to complete (one cycle is Regimen A followed by Regimen B, or Regimen B followed by Regimen A).">Number of Cycles:</span></label>
<div class="controls">
<select id="regimenCycles">
</select>
<span class="regimenCyclesEndDate" style="margin-left: 10px;"></span>
</div>
</div>
</form>
</div>
<div class="light-grey row-fluid" style="margin-bottom: 0px;">
<form class="form-horizontal" action="#">
<h4 class="heading" style="padding-left: 10px; color: white;">
Mandatory Outcomes
</h4>
</form>
</div>
<div class="well" style="margin: 0px;">
<span>These are outcomes that will be tracked by every participant in the study.</span>
<div class="container" style="padding: 20px 20px 0px 20px;">
<ul>
<li>A daily questionnaire about pain intensity and interference.</li>
<li>A daily question about how much fatigue you felt in the past day.</li>
<li>A daily question about how drowsy you felt during the current day.</li>
<li>A daily question about problems moving your bowels.</li>
<li>A daily question about the previous night's sleep.</li>
</ul>
</div>
<hr />
<div>
<form class="form-horizontal" action="#">
<span class="help-block" style="color: #000000;">
Pain medicines can sometimes affect our thinking or concentration. Please select one of the
following questions about your thinking or concentration to track every day.
</span>
<div style="padding: 20px;">
<select style="width: 80%" id="cognitiveFunction">
</select>
</div>
</form>
</div>
</div>
<div class="light-grey row-fluid" style="margin-bottom: 0px;">
<form class="form-horizontal" action="#">
<h4 class="heading" style="padding-left: 10px; color: white;">
Optional Neuropathic Pain Outcome
</h4>
</form>
</div>
<div class="well" style="padding: 10px;">
<form class="form-horizontal" action="#">
<div style="margin-left: 20px;">
<div><span>Does the patient have pain accompanied by burning, pins and needles,
itching, or a sensitive or unpleasant sensation on the skin?</span></div>
<div>
<label class="radio inline">
<input type="radio" name="neuropathicRadios" id="neuropathicRadios1" value="yes">Yes
</label>
<label class="radio inline">
<input type="radio" name="neuropathicRadios" id="neuropathicRadios2" value="no">No
</label>
</div>
<div class="row" style="margin: 10px;"><span class="neuropathicNotification"></span></div>
</div>
</form>
</div>
<div class="row-fluid">
<div class="span4"></div>
<div class="span4" style="padding: 20px;">
<button id="create" class="btn btn-large"
type="button" style="background: #B7E3E4;" onclick="create()">Create and Assign
Protocol</button>
</div>
</div>
<div class="row-fluid"
style="background: #808080; padding-bottom: 3px; margin: 0px;">
<div class="pull-right">
<img src="images/omh_logo-white.png" style="height: 91px; width: 225px;" alt="Open mHealth Logo" />
</div>
</div>
</div>
</div>
</div>
<!--
The page ends with all of the JavaScript which will speed up how
quickly the page is rendered and shouldn't even be run until after all
of the UI elements have been setup.
-->
<script type="text/javascript">
// Extend the Array prototype to contain an indexOf function.
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(needle) {
for ( var i = 0; i < this.length; i++) {
if (this[i] === needle) {
return i;
}
}
return -1;
};
}
$(document).ready(function () {
$("span").tooltip({
'selector': '',
'placement': 'top',
'trigger' : 'hover'
});
});
// The list of radio buttons refrencing the regimen.
var REGIMEN_RADIOS = [];
// The maximum random value allowed, which should be set when reading
// the campaign's contents.
var MAX_RANDOM;
// The list of required survey IDs.
var REQUIRED_PROMPT_IDS = [ 'currentRegimen', 'averagePainIntensity',
'enjoymentOfLife', 'generalActivity', 'fatiguePrompt',
'drowsinessPrompt', 'constipationPrompt', 'sleepDisturbancePrompt', 'notesAboutToday'];
var PROMPT_IDS_COGNITIVE_FUNCTION = [
'cognitiveFunctionFoggyThinkingPrompt',
'cognitiveFunctionWorkingHarderPrompt' ];
var PROMPT_IDS_NEUROPATHIC_PAIN = ['experiencePain',
'painSharpness', 'painHotness', 'painSensitivity'];
var SURVEY_ID_ADHERENCE = 'adherence';
var PROMPT_ID_ADHERENCE = 'adherencePrompt';
var SURVEY_ID_START = 'start';
var PROMPT_ID_START = 'startPrompt';
// The list of optional survey ID elements, which should be added when
// reading the campaign's contents.
var OPTIONAL_SURVEY_ID_ELEMENTS = [];
// Create a list of allowed regimen combinations. Each index in the
// list corresponds to the key for that choice. Each value is an array
// of allowed keys.
// 0 - No treatment
// 1 - Tylenol
// 2 - NSAID
// 3 - Codeine
// 4 - Tramadol
// 5 - Hydrocodone
// 6 - Oxycodone
// 7 - CAM
var ALLOWED_REGIMEN_COMBINATIONS = [
[ ],
[ "2", "4", "7" ],
[ "1", "2", "3", "4", "5", "6", "7" ],
[ "2", "7" ],
[ "1", "2", "7" ],
[ "2", "7" ],
[ "2", "7" ],
[ "1", "2", "3", "4", "5", "6" ] ];
// The Trialist class' unique identifier.
var CLASS_ID = "urn:class:trialist";
// The Trialist campaign's unique identifier.
var CAMPAIGN_ID = "urn:campaign:trialist";
// The ID of the survey that contains all of the setup prompts.
var SETUP_SURVEY_ID = "setup";
// The ID of the survey that contains the prompts in the main user survey
var MAIN_SURVEY_ID = "main";
// The prompt IDs from the setup survey.
var PROMPT_ID_REGIMEN_A = "regimenA";
var PROMPT_ID_REGIMEN_B = "regimenB";
var PROMPT_ID_START_DATE = "startDate";
var PROMPT_ID_REGIMEN_DURATION = "regimenDuration";
var PROMPT_ID_REGIMEN_CYCLES = "numberComparisonCycles";
var PROMPT_ID_RANDOM = "random";
var PROMPT_ID_RANDOM_AS_TEXT = "randomAsText";
var PROMPT_ID_COGNITIVE_FUNCTION = "cognitiveFunction";
var PROMPT_ID_NEUROPATHIC_PAIN_TAKEN = "neuropathicPainTaken";
var PROMPT_ID_USER_SELECTED = "userSelected";
var PROMPT_ID_EXTRA_TREATMENT = "extraTreatment";
// The list of checkboxes for each regimen.
var CHECKBOX_REGIMEN_A = [];
var CHECKBOX_REGIMEN_B = [];
// Treatments which trigger an opioid advisory popup
var OPIOID_TREATMENTS = [ "3", "4", "5", "6" ];
// Global array for the user list
var usernames = new Array();
// Variable to hold the end date value
// because it is calculated in an anonymous
// function
var endDateValue;
var endDateAsDate;
var startDateAsDate;
// Connect the help button with its functionality.
$("#help").click(function() {
var helpArea = $("#helpArea");
if (helpVisible) {
helpArea.fadeOut(200);
helpVisible = false;
} else {
helpArea.fadeIn(200);
helpVisible = true;
}
});
$("#helpArea").fadeOut(0);
var helpVisible = false;
// Connect the logout button with its functionality.
$("#logout").click(function() {
$.post("/app/user/logout", {
"client" : "Trialist"
}, function() {
window.location = "/";
});
});
// Setup the date picker.
$('#startDatePicker').datepicker();
$('#startDatePicker').change(updateCycles);
$('#regimenDuration').change(updateCycles);
$('#regimenCycles').change(updateCycles);
$('#neuropathicRadios1').change(showNeuropathicPainText);
$('#neuropathicRadios2').change(showNeuropathicPainText);
// Populate the page's UI elements.
try {
getUsers();
filterUsers();
getCampaignDefinition();
} catch (e) {
alertUser("Error", "An unknown error occurred: " + e);
}
function setDateValues(start, end) {
endDateAsDate = new Date(end);
startDateAsDate = new Date(start);
endDateValue = end.toString();
}
/**
* Converts an XML string into a DOM object.
*/
function convertXmlStringToDomObject(xml) {
var xmlDoc = null;
if(isIE()) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(xml);
}
else {
var parser = new DOMParser();
xmlDoc = parser.parseFromString(xml, "text/xml");
}
return xmlDoc;
}
/**
* Runs the document.evaluate() method based on the current browser.
*/
function evaluateXpath(root, node, expression) {
var result;
if(isIE()) {
result = node.selectNodes(expression);
}
else {
result = root.evaluate(expression, node, null,
XPathResult.ANY_TYPE, null);
}
return result;
}
/**
* Returns the next element from a list of elements.
*/
function nextElement(node) {
if(isIE()) {
return node.nextNode();
}
else {
return node.iterateNext();
}
}
/**
* Returns the text for the node.
*/
function elementValue(node) {
if(isIE()) {
return node.text;
}
else {
return node.textContent;
}
}
/**
* Because IE8 won't even bother with ISO 8601. Microsoft, what is your
* problem!?
*/
function parseISO8601(dateStringInRange) {
var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/, date = new Date(NaN), month, parts = isoExp.exec(dateStringInRange);
if (parts) {
month = +parts[2];
date.setFullYear(parts[1], month - 1, parts[3]);
if (month != date.getMonth() + 1) {
date.setTime(NaN);
}
}
return date;
}
/**
* Check for IE :(
*/
function isIE() {
return (window.DOMParser === undefined)
|| (navigator.userAgent.indexOf("MSIE 9") != -1)
|| (navigator.userAgent.indexOf("MSIE 10") != -1)
|| (navigator.userAgent.indexOf("Trident/7.0") != -1); // huge hack for IE 11;;
}
/**
* randomUUID.js - Version 1.0
*
* Copyright 2008, Robert Kieffer
*
* This software is made available under the terms of the Open Software License
* v3.0 (available here: http://www.opensource.org/licenses/osl-3.0.php )
*
* The latest version of this file can be found at:
* http://www.broofa.com/Tools/randomUUID.js
*
* For more information, or to comment on this, please go to:
* http://www.broofa.com/blog/?p=151
*
* Create and return a "version 4" RFC-4122 UUID string.
*/
function randomUUID() {
var s = [], itoh = '0123456789ABCDEF';
// Make array of random hex digits. The UUID only has 32 digits in it, but we
// allocate an extra items to make room for the '-'s we'll be inserting.
for ( var i = 0; i < 36; i++)
s[i] = Math.floor(Math.random() * 0x10);
// Conform to RFC-4122, section 4.4
s[14] = 4; // Set 4 high bits of time_high field to version
s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
// Convert to hex chars
for ( var i = 0; i < 36; i++)
s[i] = itoh.charAt(s[i]);
// Insert '-'s
s[8] = s[13] = s[18] = s[23] = '-';
return s.join('');
}
/**
* Uses some UI element to alert the user that something has happened.
*/
function alertUser(header, info, isHtml) {
$("#alertHeader").text(header);
if(isHtml !== undefined) {
$("div.alertInfo").html('<p>' + info + '</p>');
} else {
$("div.alertInfo").html(info);
}
$("#alertModal").modal('show');
}
/**
* Updates the number of cycles by adding dates to the values.
*/
function updateCycles() {
// Get the start date.
var startDateValue = $('#startDate').val();
// If it hasn't been selected, bail out.
if ((startDateValue === undefined) || (startDateValue === null) || (startDateValue === '')) {
return;
}
var startDate = parseISO8601(startDateValue);
// Get index of the duration select
// .text() will return the contents of the select
var durationIndex = $("#regimenDuration option:selected").val();
// If it hasn't been selected, bail out.
if ((durationIndex === undefined) || (durationIndex === null) || (durationIndex === '')) {
return;
}
// If nothing was selected, we will want to reset it after we
// update the options.
var regimenCyclesIndex = $("#regimenCycles option:selected").val();
var notSelected = (regimenCyclesIndex === undefined);
// Reset the choice if it was nothing.
if (notSelected) {
$("#regimenCycles").prop("selectedIndex", -1);
$("span.regimenCyclesEndDate").text("");
}
else {
// NOTE: if the XML values have changed for the duration
// or cycles, this code will need to be updated.
// FIXME using the <value> attribute for the property in the XML
var duration = -1;
var regimenCycles = -1;
// This is the duration for each 'leg' of an AB pair
// E.g., 14 days on A and 14 days on B
if(durationIndex == 0) {
duration = 2; // days
} else if(durationIndex == 1) {
duration = 7;
} else if(durationIndex == 2) {
duration = 14;
}
if(regimenCyclesIndex == 0) {
regimenCycles = 2;
} else if(regimenCyclesIndex == 1) {
regimenCycles = 3;
} else if(regimenCyclesIndex == 2) {
regimenCycles = 4;
}
var millis = duration * 2 * regimenCycles * 24 * 60 * 60 * 1000;
var endDateValue = new Date();
endDateValue.setTime(startDate.getTime() + millis + (startDate.getTimezoneOffset() * 60 * 1000));
$("span.regimenCyclesEndDate").html("<i class=\"icon-arrow-right\"></i> Your study will end on " + endDateValue.toDateString() + ".");
setDateValues(startDate, endDateValue);
}
}
function showNeuropathicPainText() {
if($("#neuropathicRadios1").is(":checked")) {
$("span.neuropathicNotification").html("<i class=\"icon-arrow-right\"></i> Your patient will receive daily questions about neuropathic pain.");
}
else {
$("span.neuropathicNotification").html("");
}
}
/**
* Retrieves the list of users visible to this user via their classes.
*
* @return A JSON array of the users.
*/
function getUsers() {
// Build the failure function.
var failure = function() {
alertUser("Error Retrieving Users",
"There was an error retrieving the list of users.");
}
// Build the success function.
var success = function(data) {
try {
// Check that we indicated success.
if (data['result'] === "success") {
// Iterate over all of the classes.
for ( var currClassId in data['data']) {
// We are only concerned with the Trialist class.
if (currClassId !== CLASS_ID) {
continue;
}
// Get the current class object.
var classObject = data['data'][currClassId];
// Iterate over all of the users in the current class.
for ( var user in classObject['users']) {
if(classObject['users'][user] === 'restricted') {
usernames.push(user);
}
}
usernames.sort();
}
} else {
var failureObject = data['errors'][0];
if (failureObject['code'] === "0200") {
redirectToLogin();
} else {
throw "Error reading the data: "
+ failureObject['text'];
}
}
} catch (e) {
alertUser("Error Loading Users",
"There was an error loading the list of users: "
+ e);
}
}
// Build the parameters and make the class read request.
var authToken = getAuthToken();
if (authToken != null) {
var parameters = {
"client" : "TrialistWeb",
"auth_token" : authToken,
"class_urn_list" : CLASS_ID
};
$.post("/app/class/read", parameters, success)
.fail(failure);
}
}
/**
* Filter out users based on previously submitted survey responses.
*/
function filterUsers() {
// Build the failure function.
var failure = function() {
alertUser("Server Communication Error",
"There was an error while communicating with the server.");
}
// Build the success function.
var success = function(data) {
try {
// Check that we indicated success.
if (data['result'] === "success") {
// Get the participants so users cannot be added to
// to the study twice.
var dataArray = data['data']; // an array of anonymous objects
var participants = new Array();
for(var i = 0; i < dataArray.length; i++) {
participants.push(dataArray[i]['responses']['userSelected']['prompt_response']);
}
var length = usernames.length;
// Connect to the list of users element in the HTML.
var userListElement = $("#selectUser");
for(var i = 0; i < length; i++) {
if(participants.indexOf(usernames[i]) == -1) {
userListElement
.append("<option value=\"" + usernames[i] + "\">"
+ usernames[i]
+ "</option>");
}
}
// Reset the selected index to -1, so that the user must explicitly
// choose an option.
userListElement.prop('selectedIndex', -1);
} else {
var failureObject = data['errors'][0];
if (failureObject['code'] === "0200") {
redirectToLogin();
} else {
throw "Error reading the data: "
+ failureObject['text'];
}
}
} catch (e) {
alertUser("Error Populating the Page",
"There was an error populating the page: "
+ e.toString());
}
}
// Build the parameters and make the request.
var authToken = getAuthToken();
if (authToken != null) {
var parameters = {
"client" : "TrialistWeb",
"auth_token" : authToken,
"campaign_urn" : CAMPAIGN_ID,
"output_format" : "json-rows",
"prompt_id_list" : "userSelected",
"user_list" : "urn:ohmage:special:all",
"column_list" : "urn:ohmage:prompt:response"
};
$.post("/app/survey_response/read", parameters, success,