forked from dr01d3r/redcap-em-orca-specimen-tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrcaSpecimenTracking.php
174 lines (166 loc) · 6.31 KB
/
OrcaSpecimenTracking.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
<?php
// Set the namespace defined in your config file
namespace ORCA\OrcaSpecimenTracking;
// The next 2 lines should always be included and be the same in every module
use ExternalModules\AbstractExternalModule;
use ExternalModules\ExternalModules;
use Exception;
require_once 'traits/ModuleUtils.php';
require_once 'traits/PlateUtils.php';
require_once 'traits/SpecimenUtils.php';
require_once 'traits/ShipmentUtils.php';
require_once 'traits/ReportUtils.php';
require_once 'traits/REDCapUtils.php';
require_once 'traits/RequestHandlers.php';
/**
* Class OrcaSpecimenTracking
* @package ORCA\OrcaSpecimenTracking
*/
class OrcaSpecimenTracking extends AbstractExternalModule {
use ModuleUtils;
use PlateUtils;
use SpecimenUtils;
use ShipmentUtils;
use ReportUtils;
use REDCapUtils;
use RequestHandlers;
public $_config = [
// TODO fields required to exist in each project
"fields" => [
"box" => [
"record_id",
"box_name",
"box_status",
"box_type",
"sample_type",
"shipment_record_id"
],
"aliquot" => [
"record_id",
"name",
"box_record_id"
],
"shipment" => [
"record_id",
"shipment_name",
"shipment_status"
]
],
"plate_size_map" => [
"9x9" => [
"row" => 9,
"col" => 9
],
"10x10" => [
"row" => 10,
"col" => 10
],
"8x12" => [
"row" => 8,
"col" => 12
]
],
"sample_type_units" => [
"bD" => "# of Tube(s)",
"sD" => "# of Vial(s)",
"bl" => "Volume (mL)",
"bs" => "# of Slide(s)",
"cb" => "Concentration (x10(6) cells)",
"il" => "Volume (mL)",
"mx" => "Volume",
"np" => "Volume (mL)",
"ns" => "Volume (mL)",
"pb" => "Concentration (x10(6) cells)",
"pf" => "Volume (mL)",
"pl" => "Volume (mL)",
"px" => "# of Tube(s)",
"sa" => "Volume (mL)",
"sr" => "Volume (mL)",
"st" => "# of Vial(s)",
"ur" => "Volume (mL)",
// TODO don't have a key for Blood Spot
]
];
public function redcap_module_link_check_display($project_id, $link) {
return true;
}
function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance) {
if ($project_id === null) return;
try {
$config = $this->getConfiguration($project_id);
// handle fatal errors and stop processing
if (!empty($config["errors"])) {
$config_errors = $config["errors"];
// TODO do something with the errors?
} else {
switch ($project_id) {
case $config["plate_project_id"]:
// load script for doing the secondary unique field copy
$scriptUrl = $this->getUrl("hooks/box_project/redcap_data_entry_form.js");
echo "<script src='$scriptUrl'></script>";
break;
}
}
} catch (Exception $ex) {
// TODO do something with the error?
}
}
function redcap_every_page_top($project_id) {
if ($project_id === null) return;
try {
// only process this page request if it is the page and context we care about
if (PAGE === "DataEntry/record_home.php" && !isset($_GET["auto"])) {
$config = $this->getConfiguration($project_id);
// handle fatal errors and stop processing
if (!empty($config["errors"])) {
$config_errors = $config["errors"];
// TODO do something with the errors?
} else {
$url = null;
$link_text = "";
switch ($project_id) {
case $config["plate_project_id"]:
$url = $this->getUrl("views/index.php");
$link_text = "Box Dashboard";
if (isset($_GET["id"])) {
$url .= "&" . http_build_query([
"id" => $_GET["id"]
]);
}
break;
case $config["shipment_project_id"]:
$url = $this->getUrl("views/shipment.php");
$link_text = "Shipment Dashboard";
if (isset($_GET["id"])) {
$url .= "&" . http_build_query([
"id" => $_GET["id"]
]);
}
break;
}
// stop processing if url is empty
if (empty($url)) return;
// if this is after a new record, auto-navigate back to dashboard
// otherwise, just inject a link into record_home
if (isset($_GET["msg"]) && $_GET["msg"] === "add") {
// be sure to always call exitAfterHook!
$this->exitAfterHook();
header("Location: $url");
} else {
?><script type="text/javascript">
$(function() {
let html = `<span> | </span><a href="<?=$url?>" class="text-primary ml-1"><i class="fas fa-share"></i> <?=$link_text?></a>`;
let target = $(".projhdr:first");
if (target.length) {
target.append(html);
}
});
</script><?php
}
}
}
} catch (Exception $ex) {
// TODO do something with the error?
}
}
}