Repository navigation
Expand file tree
/
Copy pathHideCodebookRandonisationNumbers.php
More file actions
78 lines (67 loc) · 3.91 KB
/
Copy pathHideCodebookRandonisationNumbers.php
File metadata and controls
78 lines (67 loc) · 3.91 KB
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
<?php
/**
* REDCap External Module: Hide Codebook Randomisation Numbers
* Hides randomisation allocation groups on Codebook page.
* Useful when the randomisation allocation field is set up with numbers rather than groups.
* @author Luke Stevens, Murdoch Children's Research Institute
*/
namespace MCRI\HideCodebookRandonisationNumbers;
use ExternalModules\AbstractExternalModule;
use Randomization;
class HideCodebookRandonisationNumbers extends AbstractExternalModule
{
const DEFAULT_THRESHOLD = 10;
const DEFAULT_MESSAGE = "Randomization numbers hidden";
public function redcap_module_system_enable($version) {
$this->setSystemSetting('system-threshold', ''.self::DEFAULT_THRESHOLD);
$this->setSystemSetting('system-message', self::DEFAULT_MESSAGE);
}
public function redcap_every_page_top($project_id) {
if (isset($project_id) && intval($project_id)>0 && PAGE==='Design/data_dictionary_codebook.php') {
// hide long randomisation list info in codebook because is very long and
// may even show group allocatiion sequence (when not blinded)
global $Proj, $randomization;
if ($randomization) {
$randomizationAttributes = Randomization::getRandomizationAttributes();
if ($randomizationAttributes !== false) {
$targetField = $randomizationAttributes['targetField'];
$randlistOptions = parseEnum($Proj->metadata[$targetField]['element_enum']);
$threshold = $this->getThreshold();
$message = $this->getMessage();
if (count($randlistOptions) > intval($threshold)) {
?>
<script type='text/javascript'>
(function(document, $) {
$(document).ready(function() {
// find the target field in the var names column - ensure
$('#codebook-table tr[data-field=<?=$targetField?>]')
.find('table.ReportTableWithBorder')
.replaceWith('<div style="margin-top:5px;"><mark><?php echo $message;?></mark></div>');
});
})(document, jQuery);
</script>
<?php
}
}
}
}
}
protected function getThreshold() {
return $this->getSetting('threshold');
}
protected function getMessage() {
return $this->getSetting('message');
}
protected function getSetting($setting) {
$s = $this->getProjectSetting("project-$setting");
if (is_null($s) || empty($s)) {
$s = $this->getSystemSetting("system-$setting");
}
if (is_null($s) || empty($s)) {
$s = '';
if ($setting==='threshold') { $s = self::DEFAULT_THRESHOLD; }
if ($setting==='message') { $s = self::DEFAULT_MESSAGE; }
}
return \REDCap::escapeHtml($s);
}
}