-
Notifications
You must be signed in to change notification settings - Fork 1
/
dashboard_cache.php
896 lines (839 loc) · 53.5 KB
/
dashboard_cache.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
<?php
namespace Vanderbilt\DashboardAnalysisPlatformExternalModule;
require_once (dirname(__FILE__)."/classes/ProjectData.php");
require_once (dirname(__FILE__)."/classes/GraphData.php");
require_once (dirname(__FILE__)."/classes/Crons.php");
$project_id = (int)$_GET['pid'];
$report = htmlentities($_GET['report'],ENT_QUOTES);
$banner = $module->getProjectSetting('banner',$project_id);
$display_graph_by_site = $module->getProjectSetting('display-graph-by-site',$project_id);
include_once "reports.php";
if(($_SESSION[$project_id . "_startDate"] == "" || $_SESSION[$project_id . "_startDate"] == "") || (empty($_GET['dash']) || !empty($_GET['dash'])) && !ProjectData::startTest($_GET['dash'], '', '', $_SESSION[$project_id."_dash_timestamp"])){
if($_SESSION[$project_id . "_question"] == "" || $_SESSION[$project_id . "_study"] == "" || empty($_GET['dash'])){
$_SESSION[$project_id . "_question"] = "1";
$_SESSION[$project_id . "_study"] = ProjectData::NOFILTER_ARRAY_KEY;
}
}
$array_questions = ProjectData::getFilterQuestionsArray();
$array_study = ProjectData::getStudyArray();
$custom_filters = $module->getProjectSetting('custom-filter',$project_id);
$array_colors_graphs = array(0=>"337ab7",1=>"F8BD7F",2=>"EF3054",3=>"43AA8B",4=>"BD93D8",5=>"3F386B",6=>"A23F47",7=>"DE7CBC",8=>"CA3C25",9=>"B3DEE2");
?>
<script>
$( document ).ready(function() {
$('.forme').width($('table.dal thead tr .question:first-of-type').width());
var maxWidthth = Math.max.apply(null, $('.dal>thead th.dal_task>div').map(function() {
return $(this).outerWidth(true);
}).get());
$('.dal>thead th.dal_task>div').width(maxWidthth+30);
$('.dal').css('margin-top', maxWidthth * .75);
function RGBToHSL(rgb) {
//If grey do not convert
if(rgb != "196,196,196") {
var rgb = rgb.split(",");
r = rgb[0];
g = rgb[1];
b = rgb[2];
r /= 255;
g /= 255;
b /= 255;
let cmin = Math.min(r, g, b),
cmax = Math.max(r, g, b),
delta = cmax - cmin,
h = 0,
s = 0,
l = 0;
if (delta == 0)
h = 0;
// Red is max
else if (cmax == r)
h = ((g - b) / delta) % 6;
// Green is max
else if (cmax == g)
h = (b - r) / delta + 2;
// Blue is max
else
h = (r - g) / delta + 4;
h = Math.round(h * 60);
// Make negative hues positive behind 360°
if (h < 0)
h += 360;
l = (cmax + cmin) / 2;
// Calculate saturation
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
// Multiply l and s by 100
s = +(s * 100).toFixed(1);
l = +(l * 100).toFixed(1);
return "hsl(" + h + ",70%," + (l + 13) + "%)";
}
}
$('tr td:nth-of-type(1) ~ td').each(function(index, value) {
clr = $(this).css("background-color");
clr = clr.replace(/ /g, '', clr);
clr = clr.replace(')', '', clr);
if (clr != 'rgba(0,0,0,0') {
$(this).css('background-color', RGBToHSL(clr.replace('rgb(', '', clr)));
}
$(this).addClass('perc');
});
$('[data-toggle="popover"]').popover({
container: 'body'
})
});
</script>
<div class="optionSelect" style="margin-bottom: 0px;">
<div class="alert alert-danger fade in col-md-12" id="errMsgContainerModal" style="display:none"></div>
</div>
<?php
if(!empty($_GET['dash']) && ProjectData::startTest($_GET['dash'], '', '', $_SESSION[$project_id."_dash_timestamp"]) || ($_SESSION[$project_id . "_study"] == ProjectData::NOFILTER_ARRAY_KEY && $_SESSION[$project_id . "_question"] == "1")) {
$question = $_SESSION[$project_id . "_question"];
$study = $_SESSION[$project_id . "_study"];
$row_questions = ProjectData::getRowQuestions();
$row_questions_1 = ProjectData::getRowQuestionsParticipantPerception();
$row_questions_2 = ProjectData::getRowQuestionsResponseRate();
$study_options = ProjectData::getChoiceLabelsArray($module, $study, $project_id);
if(!empty($study_options))
ksort($study_options);
$multipleRecords = \REDCap::getData($project_id, 'json-array');
$institutions = ProjectData::getAllInstitutions($multipleRecords);
$graph = array();
if($question == 2){
$array_study = ProjectData::getArrayStudyQuestion_2();
}
if(ProjectData::isEthnicityVar($study)){
array_push($study_options,ProjectData::getExtraColumTitle());
}
if($_SESSION[$project_id . "_startDate"] != ""){
$startDate = date("Y-m-d",strtotime($_SESSION[$project_id . "_startDate"]));
}else{
$startDate = "";
}
if($_SESSION[$project_id . "_endDate"] != ""){
$endDate = date("Y-m-d",strtotime($_SESSION[$project_id . "_endDate"]));
}else{
$endDate = "";
}
$conditionDate = "";
if($endDate != "" && $startDate != ""){
$conditionDate = " AND [survey_datetime] >= '".$startDate. "' AND [survey_datetime] <= '".$endDate."'";
}
$score_title = "% Responding Very or Somewhat Important";
$top_box_popover_info = '';
if ($question == 1) {
$score_title = "Top Box Score";
$top_box_popover_content = "<div style='padding-bottom: 20px'><strong>Definitions:</strong> “Top box” scores are created by calculating the percentage of survey respondents who chose the most positive score for a given item response scale. A variation, the 'Top 2 box' score is the total of the top two categories in a table. For example, the overall Rating question is scores using a Top 2 Box score; participants reply using a numeric scale from “0 (Worst)” to “10 (Best)”. The Top 2 Box scores based on the combination of the responses “9” and “10”.</div>
<div><strong>Top-Box versus mean scores:</strong> Top Box scores are easy to understand because they clearly identify the respondents who fall into a given category, usually the optimal category from a marketing or customer experience perspective. However, taken alone, Top Box scores leave out important information about how many respondents were close to, or far from the top category. In contrast, mean scores provide a summary measure that includes all the data, including lower and lowest scores, but it may be harder to interpret the significance of a 0.1 or 1 or 5 point difference between two mean scores, especially if the sample size is large. The frequency distribution of all of the response data provides the richest data about the range and number of responses, but lacks the simplicity of summary scores. It can be most valuable to use summary scores like Top Box or Means to follow overall trends, and frequency distributions to understand the details when designing interventions for change. When assessing change in a score, it is important to compare measures of the same type.</div>";
$top_box_popover_info = ' <a tabindex="0" role="button" data-container="body" data-toggle="popover" data-trigger="hover" data-html="true" data-placement="right" data-content="'.$top_box_popover_content.'"><i class="fas fa-info-circle fa-fw infoIcon" aria-hidden="true"></i></a>';
}else if($question == 2){
$score_title = "Percent Responding (% Responding)";
$top_box_popover_content = "<div style='padding-bottom: 20px'><strong>Percent Responding or response rate</strong> is a measure of the portion of surveys returned compared to those sent out, according to pre-specified criteria. The fraction of responses/total sent is multiple by 100 to calculate a response “rate”.</div>
<div style='padding-bottom: 20px'><strong>Calculating Response Rates:</strong> The numerator for the response rate calculation is the total number of responses meeting criteria for a given response category. The denominator consists of the total number of individuals to whom surveys were sent, regardless of whether they responded. The calculation does not distinguish undeliverable surveys and other reasons for non-response.</div>
<div style='padding-bottom: 20px'><strong>Defining a response:</strong> A “response” is defined by the return of a survey with a response (not null) for at least one of the questions considered key to the validity of the survey. The criteria for whether a response is considered “complete” or “partial” or a “break-off” or “any” are defined below based (“i” icon). A survey returned completely blank is not considered a response. Reference: <a href='https://www.aapor.org/AAPOR_Main/media/MainSiteFiles/Standard-Definitions2015' target='_blank'>https://www.aapor.org/AAPOR_Main/media/MainSiteFiles/Standard-Definitions2015</a></div>
<div style='padding-bottom: 20px'><strong>Key questions:</strong> For the RPPS response rate calculations, 18 questions were selected as key to a meaningful response. The key questions include the 15 questions in the Perception and rating questions drop down menu on the Dashboard, and three questions that characterize the study in terms of intensity, interventional nature, and mode of consent (filter menu).</div>
<div style='padding-bottom: 20px'><strong>Response rates can be calculated for datasets filtered by individual or study characteristics</strong> (e.g., age, race, ethnicity, sex, gender) for which there are data from the EMR or CTMS to inform the denominator (including characteristics of non-responders). All respondents with a given characteristic in their RPPS data are included in the numerator for that characteristic, and all potential recipients with the same characteristic to whom the survey was sent are included in the denominator regardless of whether they returned a response.</div>
<div>When values for characteristics are available from RPPS data, RPPS values are used. When RPPS values are missing, or there is no RPPS data (non-response) available, values from the EMR/CTMS are used. When the RPPS data and site source data are in conflict, RPPS data inform both the numerator and the denominator for response rate calculations.</div>
";
$top_box_popover_info = ' <a tabindex="0" role="button" data-container="body" data-toggle="popover" data-trigger="hover" data-html="true" data-placement="right" data-content="'.$top_box_popover_content.'"><i class="fas fa-info-circle fa-fw infoIcon" aria-hidden="true"></i></a>';
}
$logout = $module->getUrl('index.php?pid='.$project_id.'&sout');
$table = "";
if($banner != ""){
$table .= "<div style='margin-top: 20px;'>
<div class='alert alert-info'>".$banner."</div>
</div>";
}
$table .= "<div class='optionSelect' id='loadTable'>
<div style='width: 621px;' class='forme'>
<img src='".$module->getUrl('epv-2colorhorizontal1300__1_.jpg')."' width='300px'>
<div style='float: right;padding-top: 23px;'>
<div style='width: 100%'>
<a href='#' style='float: right' onclick='destroy_session(\"".$logout."\")'> Logout</a>
</div>
<a class='btn btn-default' target='_blank' href='".$module->getUrl('index.php')."&NOAUTH&option=sac"."'>Stats & Charts</a>
</div>
<h3 class='header'></h3>
<div>
<select class='form-control' id='question' onchange='isItResponseRates(this.value,".json_encode($module->getUrl("response_rates_selector_ajax.php")).")'>
<option value=''>Question type</option>
";
foreach ($array_questions as $index => $squestion){
$selected = "";
if($index == $_SESSION[$project_id . "_question"]){
$selected = "selected";
}
$table .= '<option value="'.$index.'" '.$selected.'>'.$squestion.'</option>';
}
$table .= ' </select>
<select class="form-control" id="study">';
if($study == ProjectData::NOFILTER_ARRAY_KEY) {
$table .= '<option value="'.ProjectData::NOFILTER_ARRAY_KEY.'" selected>No filter</option>
<option value="'.ProjectData::BYSITE_ARRAY_KEY.'">By site</option>';
}else if($study == ProjectData::BYSITE_ARRAY_KEY) {
$table .= '<option value="'.ProjectData::NOFILTER_ARRAY_KEY.'">No filter</option>
<option value="'.ProjectData::BYSITE_ARRAY_KEY.'" selected>By site</option>';
}else{
$table .= '<option value="'.ProjectData::NOFILTER_ARRAY_KEY.'">No filter</option>
<option value="'.ProjectData::BYSITE_ARRAY_KEY.'">By site</option>';
}
foreach ($array_study as $index => $sstudy){
if(strpos($index, 'header') !== false){
$number_header = explode('header', strtolower($index));
if($number_header == "0"){
$table .= '</optgroup><optgroup label="'.$sstudy.'">';
}else{
$table .= '<optgroup label="'.$sstudy.'">';
}
}else {
$selected = "";
if ($index === $_SESSION[$project_id . "_study"]) {
$selected = "selected";
}
$table .= '<option value="' . $index . '" ' . $selected . '>' . $sstudy . '</option>';
}
}
$table .='</optgroup>';
if($question != 2) {
if (isset($custom_filters)) {
$table .= '<optgroup label="Custom site filters:">';
}
$customf_counter = 1;
foreach ($custom_filters as $index => $sstudy) {
$selected = "";
if ($sstudy === $_SESSION[$project_id . "_study"]) {
$selected = "selected";
}
if($customf_counter < ProjectData::MAX_CUSTOM_FILTERS) {
$table .= '<option value="' . $sstudy . '" ' . $selected . '>' . $sstudy . '</option>';
}
$customf_counter++;
$array_study[$sstudy] = $sstudy;
}
}
$table .='</optgroup>';
$table .='</select>
<button onclick=\'loadTable('.json_encode($module->getUrl("loadTable.php")."&NOAUTH").');\' class="btn btn-primary" id="loadTablebtn">Load Table</button>
</div>
</div>
<table class="table dal table-bordered pull-left" id="table_archive">
<thead>
<tr>
<th class="question"><span style="position: relative; top:23px"><strong>'.$score_title.$top_box_popover_info.'</strong></span></th>'.
'<th class="dal_task"><div style="width: 197.719px;"><span>TOTAL</span></div></th>';
if($study != ProjectData::NOFILTER_ARRAY_KEY) {
if (ProjectData::isEthnicityVar($study)) {
foreach ($study_options as $indexstudy => $col_title) {
$class = "";
$attribute = "";
if ($indexstudy != 1 && (ProjectData::isEthnicityVar($study) && $indexstudy < count($study_options))) {
$class = "hide";
$attribute = "etnicity='1'";
}
$table .= '<th class="dal_task ' . $class . '" ' . $attribute . '><div style="width: 197.719px;"><span>' . $col_title . '</span></div></th>';
}
}else if ($study == ProjectData::BYSITE_ARRAY_KEY) {
foreach ($institutions as $institution => $institutionRecords){
$table .= '<th class="dal_task"><div style="width: 197.719px;"><span>'.$institution.'</span></div></th>';
}
} else {
foreach ($study_options as $indexstudy => $col_title) {
$table .= '<th class="dal_task"><div style="width: 197.719px;"><span>' . $col_title . '</span></div></th>';
}
}
if($study != ProjectData::BYSITE_ARRAY_KEY) {
$table .= '<th class="dal_task"><div style="width: 197.719px;"><span>NO ' . strtoupper($array_study[$study]) . ' REPORTED</span></div></th>';
}
if ($study == "rpps_s_q61" || $study == "race") {
$table .= '<th class="dal_task"><div style="width: 197.719px;"><span>MULTIPLE</span></div></th>';
}
}
$table .= '</tr>';
$table .= '<tr>';
$table .= '<td class="question"></td>';
$table .= '<td></td>';
foreach ($study_options as $indexstudy => $col_title) {
if(ProjectData::isEthnicityVar($study)) {
$table .="<style>.dal_task>div>span {
display: block;
margin-left: 38px;
color: #5592c6;
}</style>";
if (ProjectData::isEthnicityVar($study) && $indexstudy == count($study_options)) {
$table .= '<td><i class="fas fa-plus-circle fa-fw" id="etnicityPlus" aria-hidden="true" onclick="etnicity_change_icon(this.id)" symbol="0"></i></td>';
} else if ($indexstudy != 1) {
$table .= '<td class="hide" etnicity="1"></td>';
} else if ($indexstudy == 1) {
$table .= '<td></td>';
}
}else{
$table .="<style>.dal_task>div>span {
display: block;
margin-left: 20px;
color: #5592c6;
}</style>";
$table .= '<td> </td>';
}
}
$table .= '<td></td>';
$table .= '</tr>';
$table .= '</thead>';
#LOAD THE FILE
$dash_array = ProjectData::getFileData($module, $project_id, "dashboard_cache_file_", $report);
$showLegendNoFilter = false;
if($dash_array != "" && is_array($dash_array)){
$max = 100;
if ($question == 1) {
if($dash_array['data'][$question][$study] != "" || $study == ProjectData::BYSITE_ARRAY_KEY){
if($study == "rpps_s_q61") {
$extras = 3;
}
foreach ($row_questions_1 as $indexQuestion => $question_1) {
$show_graph = '';
if(($study == ProjectData::BYSITE_ARRAY_KEY && $display_graph_by_site) || $study != ProjectData::BYSITE_ARRAY_KEY){
$show_graph = ' <i class="fas fa-chart-bar infoChart" id="DashChart_'.$question_1.'" indexQuestion="'.$indexQuestion.'"></i>';
}
#PRINT RESULTS
$question_popover_content = returnTopScoresLabels($question_1,$module->getChoiceLabels($question_1, $project_id));
$question_popover_info = ' <a tabindex="0" role="button" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="top" title="Field: ['.$question_1.']" data-content="'.$question_popover_content.'"><i class="fas fa-info-circle fa-fw infoIcon" aria-hidden="true"></i></a>';
$table .= '<tr><td class="question">'.$module->getFieldLabel($question_1).$question_popover_info.$show_graph.'</td>';
$study_aux = $study;
if($study == ProjectData::BYSITE_ARRAY_KEY) {
$study_aux = ProjectData::NOFILTER_ARRAY_KEY;
}
if(!empty($dash_array['data'][$question][$study_aux][$question_1][$indexQuestion]))
ksort($dash_array['data'][$question][$study_aux][$question_1][$indexQuestion]);
if(!empty($dash_array['tooltip'][$question][$study_aux][$question_1][$indexQuestion]))
ksort($dash_array['tooltip'][$question][$study_aux][$question_1][$indexQuestion]);
if($study == ProjectData::NOFILTER_ARRAY_KEY || $study == ProjectData::BYSITE_ARRAY_KEY){
if (($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] == "-" || $dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] == "x") && $dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] != "0") {
$color = "#c4c4c4";
$showLegendNoFilter = true;
} else {
if (strpos($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0], '*')) {
$showLegendNoFilter = true;
}
$percent = ($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] / ($max)) * 100;
$color = GetColorFromRedYellowGreenGradient($percent);
}
$extraSpace100 = '';
if ($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] == "100 *") {
$extraSpace100 = " extraSpace100";
}
$table .= '<td style="background-color:' . $color . '" class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel' . $extraSpace100 . '" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] . '">' . $dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_1][$indexQuestion][0] . '</div></td>';
if($study == ProjectData::BYSITE_ARRAY_KEY) {
#INSTITUTIONS
foreach ($institutions as $institution => $institutionRecords) {
if (($dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution] == "-" || $dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution] == "x") && $dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution] != "0") {
$color = "#c4c4c4";
$showLegendNoFilter = true;
} else {
if (strpos($dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution], '*')) {
$showLegendNoFilter = true;
}
$percent = ($dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution] / ($max)) * 100;
$color = GetColorFromRedYellowGreenGradient($percent);
}
$extraSpace100 = '';
if ($dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution] == "100 *") {
$extraSpace100 = " extraSpace100";
}
$table .= '<td style="background-color:' . $color . '" class="' . $class . '" ' . $attribute . '><div class="extraInfoLabel' . $extraSpace100 . '" style="cursor:default !important">' . $dash_array['data'][$question][ProjectData::INSTITUTIONS_ARRAY_KEY][$question_1][$indexQuestion][0][$institution] . '</div></td>';
}
}
$table .= '</tr>';
}else{
foreach ($dash_array['data'][$question][$study][$question_1][$indexQuestion] as $i => $value){
if(($value == "-" || $value == "x") && $value != "0"){
$color = "#c4c4c4";
}else{
$percent = ($value/($max))*100;
$color = GetColorFromRedYellowGreenGradient($percent);
}
$class = "";
$attribute = "";
if(ProjectData::isEthnicityVar($study) && $i > 1 && $i < count($study_options)){
$class = "hide";
$attribute = "etnicity = '1'";
}
$extraSpace100 = '';
if($value == "100 *"){
$extraSpace100 = " extraSpace100";
}
if($study != ProjectData::NOFILTER_ARRAY_KEY || ($study == ProjectData::NOFILTER_ARRAY_KEY && $i == "0")) {
$table .= '<td style="background-color:' . $color . '" class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel'.$extraSpace100.'" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question][$study][$question_1][$indexQuestion][$i] . '">' . $value . '</div></td>';
}
}
$table .= '</tr>';
}
}
}else{
$found = false;
foreach ($custom_filters as $index => $sstudy) {
if($sstudy == $study){
$found = true;
break;
}
}
if($found){
$url = $module->getUrl("callCron.php");
echo "<div class='optionSelect messageCache' style='margin-top: 20px;'>
<div class='alert alert-warning fade in col-md-12' id='errMsgContainerModal'>
The selected custom filter has not been added to the Dashboard Cache file. This file will be automatically generated every day at 23:50pm.<br/>
To create the file now <a href='javascript:loadCache(".json_encode($project_id).",".json_encode($url).");'>click here</a>. Have in mind that this will take several minutes.</div>
</div>";
}
}
}else if ($question == 2) {
$row_questions_2_info = ProjectData::getRowQuestionsResponseRateInfo();
foreach ($row_questions_2 as $indexQuestion => $question_2) {
$question_popover_content = $row_questions_2_info[$indexQuestion];
$question_popover_info = ' <a tabindex="0" role="button" data-container="body" data-toggle="popover" data-trigger="hover" data-placement="right" title="'.ucfirst($question_2).' Response" data-content="'.$question_popover_content.'"><i class="fas fa-info-circle fa-fw infoIcon" aria-hidden="true"></i></a>';
$table .= '<tr><td class="question">'.ucfirst($question_2)." response ".$question_popover_info.' <i class="fas fa-chart-bar infoChart" id="DashChart_'.$question_2.'" indexQuestion="'.$indexQuestion.'"></i></td>';
if($study == ProjectData::NOFILTER_ARRAY_KEY || $study == ProjectData::BYSITE_ARRAY_KEY){
if($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_2][0] == "100 *"){
$extraSpace100 = " extraSpace100";
}
if(strpos($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_2][0], '*')){
$showLegendNoFilter = true;
}
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel'.$extraSpace100.'" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_2][0] . '">' . $dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY][$question_2][0] . '</div></td>';
if($study == ProjectData::BYSITE_ARRAY_KEY) {
#INSTITUTIONS
foreach ($institutions as $institution => $institutionRecords) {
if ($dash_array['data'][$question]['institutions'][$question_2][$institution][0] == "100 *") {
$extraSpace100 = " extraSpace100";
}
if (strpos($dash_array['data'][$question]['institutions'][$question_2][$institution][0], '*')) {
$showLegendNoFilter = true;
}
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="extraInfoLabel' . $extraSpace100 . '" style="cursor:default !important">' . $dash_array['data'][$question]['institutions'][$question_2][$institution][0] . '</div></td>';
}
}
$table .= '</tr>';
}else{
if(!empty($dash_array['data'][$question][$study][$question_2][$indexQuestion]))
ksort($dash_array['data'][$question][$study][$question_2]);
if(!empty($dash_array['tooltip'][$question][$study][$question_2][$indexQuestion]))
ksort($dash_array['tooltip'][$question][$study][$question_2]);
$array = $dash_array['data'][$question][$study][$question_2];
if(!empty($array))
end($array); // move the internal pointer to the end of the array
$last_index = "";
if(!empty($array))
$last_index = key($array);
foreach ($dash_array['data'][$question][$study][$question_2] as $i => $value){
$class = "";
$attribute = "";
if(ProjectData::isEthnicityVar($study) && $i > 1 && $i < count($study_options)){
$class = "hide";
$attribute = "etnicity = '1'";
}
$extraSpace100 = "";
if($value == "100 *"){
$extraSpace100 = " extraSpace100";
}
if($last_index == $i && $study == "race") {
#MULTIPLE
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel'.$extraSpace100.'" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question][$study][$question_2][$i] . '">' . $value . '</div></td>';
}else{
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel'.$extraSpace100.'" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question][$study][$question_2][$i] . '">' . $value . '</div></td>';
}
}
$table .= '</tr>';
}
}
}else{
if($dash_array['data'][$question][$study] != "") {
$option = explode("-", $row_questions[$question]);
$index = 0;
for ($i = $option[0]; $i < $option[1]; $i++) {
$table .= '<tr><td class="question">' . $module->getFieldLabel("rpps_s_q" . $i) . '</td>';
if ($study == ProjectData::NOFILTER_ARRAY_KEY) {
$extraSpace100 = "";
if($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY]["rpps_s_q" . $i][$index][0] == "100 *"){
$extraSpace100 = " extraSpace100";
}
if(strpos($dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY]["rpps_s_q" . $i][$index][0], '*')){
$showLegendNoFilter = true;
}
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel'.$extraSpace100.'" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question]['institutions']["rpps_s_q" . $i][$index][0] . '">' . $dash_array['data'][$question][ProjectData::NOFILTER_ARRAY_KEY]["rpps_s_q" . $i][$index][0] . '</div></td>';
#INSTITUTIONS
foreach ($institutions as $institution => $institutionRecords) {
if($dash_array['data'][$question]['institutions']["rpps_s_q" . $i][$index][0][0][$institution] == "100 *"){
$extraSpace100 = " extraSpace100";
}
if(strpos($dash_array['data'][$question]['institutions']["rpps_s_q" . $i][$index][0][0][$institution], '*')){
$showLegendNoFilter = true;
}
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="extraInfoLabel'.$extraSpace100.'" style="cursor:default !important">' . $dash_array['data'][$question]['institutions']["rpps_s_q" . $i][$index][0][0][$institution] . '</div></td>';
}
$table .= '</tr>';
} else {
foreach ($dash_array['data'][$question][$study]["rpps_s_q" . $i] as $singleDataIndex => $singleData) {
if(!empty($dash_array['data'][$question][$study]["rpps_s_q" . $i][$singleDataIndex]))
ksort($dash_array['data'][$question][$study]["rpps_s_q" . $i][$singleDataIndex]);
if(!empty($dash_array['tooltip'][$question][$study]["rpps_s_q" . $i][$singleDataIndex]))
ksort($dash_array['tooltip'][$question][$study]["rpps_s_q" . $i][$singleDataIndex]);
foreach ($dash_array['data'][$question][$study]["rpps_s_q" . $i][$singleDataIndex] as $arrayIndex => $value) {
$class = "";
$attribute = "";
if (ProjectData::isEthnicityVar($study) && $arrayIndex > 1 && $arrayIndex < count($study_options)) {
$class = "hide";
$attribute = "etnicity = '1'";
}
if($value == '-' || $value == "*" || $value == 'x'){
$showLegendNoFilter = true;
}
$extraSpace100 = "";
if($value == " *"){
$extraSpace100 = " extraSpace100";
}
$table .= '<td class="' . $class . '" ' . $attribute . '><div class="red-tooltip extraInfoLabel'.$extraSpace100.'" data-toggle="tooltip" data-html="true" title="' . $dash_array['tooltip'][$question][$study]["rpps_s_q" . $i][$singleDataIndex][$arrayIndex] . '">' . $value . '</div></td>';
}
}
}
$index++;
}
$table .= '</tr>';
}else{
$found = false;
foreach ($custom_filters as $index => $sstudy) {
if($sstudy == $study){
$found = true;
break;
}
}
if($found){
$url = $module->getUrl("callCron.php");
echo "<div class='optionSelect messageCache' style='margin-top: 20px;'>
<div class='alert alert-warning fade in col-md-12' id='errMsgContainerModal'>
The selected custom filter has not been added to the Dashboard Cache file. This file will be automatically generated every day at 23:50pm.<br/>
To create the file now <a href='javascript:loadCache(".json_encode($project_id).",".json_encode($url).");'>click here</a>. Have in mind that this will take several minutes.</div>
</div>";
}
}
}
}else if(!empty($report)){
$q = $module->query("SELECT report_id FROM redcap_reports
WHERE project_id = ? AND unique_report_name=?",
[$project_id,$report]);
$row = $q->fetch_assoc();
$report_records = \REDCap::getReport($row['report_id']);
if(empty($report_records)) {
echo "<div class='optionSelect messageCache' style='margin-top: 20px;'>
<div class='alert alert-danger fade in col-md-12' id='errMsgContainerModal'>
The Dashboard Cache file has not been generated.<br/>
No record IDs found in report.</div>
</div>";
}else{
$url = $module->getUrl("callCron.php")."&report=".$report;
echo "<div class='optionSelect messageCache' style='margin-top: 20px;'>
<div class='alert alert-warning fade in col-md-12' id='errMsgContainerModal'>
The Dashboard Cache file has not been generated. This file will be automatically generated every day at 23:50pm.<br/>
To create the file now <a href='javascript:loadCache(".json_encode($project_id).",".json_encode($url).");'>click here</a>. Have in mind that this will take several minutes.</div>
</div>";
echo '<div class="optionSelect" style="margin-top: 20px;display: none" id="spinner">
<div class="alert alert-success">
<em class="fa fa-spinner fa-spin"></em> Updating... Please wait until the process finishes.
</div></div>';
}
}else{
$url = $module->getUrl("callCron.php");
echo "<div class='optionSelect messageCache' style='margin-top: 20px;'>
<div class='alert alert-warning fade in col-md-12' id='errMsgContainerModal'>
The Dashboard Cache file has not been generated. This file will be automatically generated every day at 23:50pm.<br/>
To create the file now <a href='javascript:loadCache(".json_encode($project_id).",".json_encode($url).");'>click here</a>. Have in mind that this will take several minutes.</div>
</div>";
echo '<div class="optionSelect" style="margin-top: 20px;display: none" id="spinner">
<div class="alert alert-success">
<em class="fa fa-spinner fa-spin"></em> Updating... Please wait until the process finishes.
</div></div>';
}
$table .= '</table>';
if($dash_array['legend'][$question][$study] || $showLegendNoFilter){
$table .= "<i style='padding-bottom: 20px'>X = fewer than 5 responses <span style='padding-left: 10px'>- = no responses</span><span style='padding-left: 10px'>* = fewer than 20 responses</span></i>";
}
$table .= '</div>';
echo $table;
?>
<script>
$(function () {
var datagraph;
var graph_url = <?=json_encode($module->getUrl("graph_ajax.php"))?>;
var study_options = <?=json_encode($study_options)?>;
var question = <?=json_encode($question)?>;
var conditionDate = <?=json_encode($conditionDate)?>;
var studyOption = <?=json_encode($study)?>;
var report = <?=json_encode($report)?>;
var nofilter = <?=json_encode(ProjectData::NOFILTER_ARRAY_KEY)?>;
var config_dash = {
type: 'line',
data: {
labels: [""],
datasets: []
},
options: {
elements: {
line: {
tension: 0, // disables bezier curves
}
},
tooltips: {
mode: 'index',
intersect: false
},
scales : {
yAxes : [{
ticks: {
stepSize: 10,
beginAtZero:true,
max: 100
},
scaleLabel: {
display: true,
labelString: 'Top Box Score'
}
}]
}
}
}
dash_chart_big = new Chart($("#modal-big-graph-body"), config_dash);
$('[data-toggle="tooltip"]').tooltip();
$(".category").change(function(){
var question_1 = $("#question_num").val();
var study = $(this).val();
var timeline = $("#options td").closest(".selected").attr("id");
var color = "#"+$(this).attr("color");
var ds1 = {
label: $(this).attr("text"),
fill: false,
spanGaps: true,
id: study,
borderColor: color,
backgroundColor: color,
data: datagraph["results"][timeline][question_1][study]
};
if($(this).is(":checked")){
dash_chart_big.data.datasets.push(ds1);
}else{
dash_chart_big.data.datasets.find((dataset, index) => {
if (dataset.id === study) {
dash_chart_big.data.datasets.splice(index, 1);
return true; // stop searching
}
});
}
dash_chart_big.update();
updateTooltipLabels(dash_chart_big, datagraph, timeline, question_1, study);
});
$(".infoChart").click(function(){
var question_1 = $(this).attr('id').split("DashChart_")[1];
var question_text = $(this).parent("td").text();
$("#category").val("total");
$("#question_num").val(question_1);
$('#modal-big-graph-title').text(question_text);
$('#modal-spinner').modal('show');
if((studyOption == nofilter) && datagraph != "" && datagraph != undefined){
dash_chart_big.data.datasets.find((dataset, index) => {
if (dataset.id === "total") {
dash_chart_big.data.datasets.splice(index, 1);
return true; // stop searching
}
});
}else {
//Clean checkboxes & data in graph
$(".category:checked").each(function () {
if ($(this).attr("text") != "Total") {
$(this).prop("checked", false);
}
dash_chart_big.data.datasets.find((dataset, index) => {
if (dataset.id === $(this).val()) {
dash_chart_big.data.datasets.splice(index, 1);
return true; // stop searching
}
});
});
}
dash_chart_big.update();
$.ajax({
url: graph_url,
data: "&studyOption="+studyOption+"&question="+question+"&question_1="+question_1+"&study="+studyOption+"&study_options="+JSON.stringify(study_options)+"&conditionDate="+conditionDate+"&report="+report,
type: 'POST',
success: function(returnData) {
var data = JSON.parse(returnData);
$('#modal-spinner').modal('hide');
if (data.status == 'success') {
datagraph = JSON.parse(data.chartgraph);
dash_chart_big.data.labels = datagraph["labels"]["month"][question_1]["total"];
var ds1 = {
label: "Total",
borderColor: '#337ab7',
backgroundColor: '#337ab7',
fill: false,
spanGaps: true,
id: "total",
data: datagraph["results"]["month"][question_1]["total"]
};
dash_chart_big.data.datasets.push(ds1);
dash_chart_big.update();
updateTooltipLabels(dash_chart_big, datagraph, "month", question_1, "total");
$('#quarter').removeClass('selected');
$('#year').removeClass('selected');
$('#month').addClass('selected');
$('#modal-big-graph').modal('show');
}
}
});
});
$("#options td").click(function(){
var question_1 = $("#question_num").val();
var timeline = $(this).attr('id');
if($(this).attr('id') == "month"){
$('#quarter').removeClass('selected');
$('#year').removeClass('selected');
}else if($(this).attr('id') == "quarter"){
$('#month').removeClass('selected');
$('#year').removeClass('selected');
}else if($(this).attr('id') == "year"){
$('#quarter').removeClass('selected');
$('#month').removeClass('selected');
}
if(studyOption == nofilter || studyOption == "bysite"){
study = "total";
dash_chart_big.data.labels = datagraph["labels"][timeline][question_1][study];
dash_chart_big.data.datasets[0].data = datagraph["results"][timeline][question_1][study];
}else{
$(".category:checked").each(function () {
var study = $(this).val();
var indexdataset = 0;
dash_chart_big.data.datasets.find((dataset, index) => {
if (dataset.id === study) {
indexdataset = index;
}
});
dash_chart_big.data.labels = datagraph["labels"][timeline][question_1][study];
dash_chart_big.data.datasets[indexdataset].data = datagraph["results"][timeline][question_1][study];
});
}
$('#'+timeline).addClass('selected');
dash_chart_big.update();
updateTooltipLabels(dash_chart_big, datagraph, timeline, question_1, study);
});
});
function updateTooltipLabels(dash_chart_big, datagraph, type, question_1, study){
//Update labels adding ", n=value" on tooltip hover
var datasetIndex = (dash_chart_big.data.datasets.length-1);
var newTooltipConfig = {
intersect: false,
callbacks: {
label: function(tooltipItem, data) {
var datasetLabel = data.datasets[tooltipItem.datasetIndex].label;
var text_label = datasetLabel.toLowerCase();
for (var index = 0; index < dash_chart_big.data.datasets.length; index++) {
if(data.datasets[index].label == datasetLabel){
if(text_label.startsWith('no') && text_label.endsWith('reported')){
responsesIndex = "no";
}else if(text_label != "total"){
responsesIndex = data.datasets[index].id;
}else{
responsesIndex = "total";
}
datasetIndex = index;
break;
}
}
var responses_na_array = Array.from(datagraph["responses_na"][type][question_1][responsesIndex]);
var responses_na = responses_na_array[tooltipItem.index];
if(responses_na == null || responses_na == ""){
responses_na = "n=0";
}
var label = tooltipItem.yLabel + ", " + responses_na;
return datasetLabel + ': ' + label;
}
}
}
dash_chart_big.options.tooltips = newTooltipConfig;
dash_chart_big.update();
}
</script>
<!-- MODAL GRAPH-->
<div class="modal fade" id="modal-big-graph" tabindex="-1" role="dialog" aria-labelledby="Codes">
<div class="modal-dialog" role="document" style="width:900px !important;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close closeCustomModal" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="modal-big-graph-title"></h4>
<input type="hidden" id="question_num" value=""/>
</div>
<div class="modal-body">
<canvas id="modal-big-graph-body" class="infoChartBig pull-left"></canvas>
<div style="padding-left: 20px;float: left;width: 180px;">
<table class='table table-bordered' id='options' style="width: 100%;">
<tr>
<td class='selected' id='month'>Month</td>
</tr>
<tr>
<td id='quarter'>Quarter</td>
</tr>
<tr>
<td id='year'>Year</td>
</tr>
</table>
<?php if(!empty($study_options) && $study != ProjectData::NOFILTER_ARRAY_KEY && $study != ProjectData::BYSITE_ARRAY_KEY){ ?>
<div class='table table-bordered'>
<div><input type="checkbox" value="total" class="category" text="Total" color="<?=$array_colors_graphs[0]?>" checked> Total</div>
<?php
$i = 1;
foreach ($study_options as $indexstudy => $col_title) {
echo "<div><input type='checkbox' value='".$indexstudy."' class='category' text='".$col_title."' color='".$array_colors_graphs[$i]."'> ".$col_title."</div>";
$i++;
}
?>
<div><input type="checkbox" value="no" class="category" text="NO <?=strtoupper($array_study[$study])?> REPORTED" color="<?=$array_colors_graphs[$i]?>"> NO <?=strtoupper($array_study[$study])?> REPORTED</div>
<?php
if($study == "rpps_s_q61"){
$i++;
echo "<div><input type='checkbox' value='multiple' class='category' text='MULTIPLE' color='".$array_colors_graphs[$i]."'> MULTIPLE</div>";
}
?>
</div>
<?php } else if($study == ProjectData::BYSITE_ARRAY_KEY){
echo "<div><input type='checkbox' value='total' class='category' text='Total' color='".$array_colors_graphs[0]."' checked> Total</div>";
#INSTITUTIONS
$i = 1;
foreach ($institutions as $institution => $institutionRecords) {
echo "<div><input type='checkbox' value='".$institution."' class='category' text='".$institution."' color='".$array_colors_graphs[$i]."'> ".$institution."</div>";
$i++;
}
?>
<?php } ?>
</div>
</div>
<div class="modal-footer" style="padding-top: 30px">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- MODAL SPINNER-->
<div class="modal fade" id="modal-spinner" tabindex="-1" role="dialog" aria-labelledby="Codes">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close closeCustomModal" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Graph in progress</h4>
</div>
<div class="modal-body">
<div style="padding-top: 20px">
<div class="alert alert-success">
<em class="fa fa-spinner fa-spin"></em> Processing... Please wait until the process finishes.
</div>
</div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<?php
}
?>