-
Notifications
You must be signed in to change notification settings - Fork 1
/
boot.php
233 lines (197 loc) · 5.19 KB
/
boot.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
<?php
/**
* (c) 2018 OpenTHC, Inc.
*
* This file is part of OpenTHC Lab Portal released under GPL-3.0 License
* SPDX-License-Identifier: GPL-3.0-only
*
* OpenTHC Lab Application Bootstrap
*
* OpenTHC Laboratory Portal is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* OpenTHC Laboratory Portal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenTHC Laboratory Portal. If not, see <https://www.gnu.org/licenses/>.
*/
use OpenTHC\Sodium;
define('APP_ROOT', __DIR__);
define('APP_SALT', sha1('$PUT_YOUR_SECRET_VALUE_HERE'));
define('APP_BUILD', '420.24.268');
define('APP_VERSION', '420.24.268');
openlog('openthc-lab', LOG_ODELAY|LOG_PID, LOG_LOCAL0);
error_reporting(E_ALL & ~ E_NOTICE & ~ E_WARNING);
require_once(APP_ROOT . '/vendor/autoload.php');
if ( ! \OpenTHC\Config::init(APP_ROOT) ) {
_exit_html_fail('<h1>Invalid Application Configuration [ALB-035]</h1>', 500);
}
define('OPENTHC_SERVICE_ID', \OpenTHC\Config::get('openthc/lab/id'));
define('OPENTHC_SERVICE_ORIGIN', \OpenTHC\Config::get('openthc/lab/origin'));
_error_handler_init();
/**
* Database Connection Getter
*/
function _dbc($dsn=null)
{
static $dbc_list = [];
if (empty($dsn)) {
throw new \Exception('Invalid Data Source Name [ABS-045]');
}
$dbc = $dbc_list[$dsn];
if ( ! empty($dbc)) {
return $dbc;
}
switch ($dsn) {
case 'auth':
case 'base':
case 'cic':
case 'corp':
case 'main':
case 'root':
case 'ops':
// @v2 URL Based Connection
$cfg = \OpenTHC\Config::get(sprintf('database/%s', $dsn));
if (empty($cfg['database'])) {
_exit_text('Invalid Database Configuration [AFD-052]', 500);
}
$c = sprintf('pgsql:host=%s;dbname=%s', $cfg['hostname'], $cfg['database']);
$dbc_list[$dsn] = new \Edoceo\Radix\DB\SQL($c, $cfg['username'], $cfg['password']);
return $dbc_list[$dsn];
break;
default:
$ret = new \Edoceo\Radix\DB\SQL($dsn);
return $ret;
}
}
/**
* Make a Nicer Looking ID
*/
function _nice_id($x0, $x1=null)
{
$r = $x0;
if (!empty($x1)) {
$r = $x1;
$r = preg_replace('/\w+:\/\//', '', $r);
}
return $r;
}
/**
*
*/
function _draw_metric($lm)
{
$uom = $lm['metric']['uom'] ?: $lm['metric']['meta']['uom'] ?: $lm['meta']['uom'];
?>
<div class="lab-metric-item">
<div class="input-group">
<div class="input-group-text"><?= __h($lm['name']) ?></div>
<input
autocomplete="off"
class="form-control r lab-metric-qom"
data-auto-sum="1"
id="<?= sprintf('lab-metric-%s', $lm['id']) ?>"
name="<?= sprintf('lab-metric-%s', $lm['id']) ?>"
placeholder="<?= __h($lm['name']) ?>"
value="<?= $lm['metric']['qom'] ?>">
<select
class="form-control lab-metric-uom"
name="<?= sprintf('lab-metric-%s-uom', $lm['id']) ?>"
style="flex: 0 1 5em; width: 5em;"
tabindex="-1">
<?php
foreach (\OpenTHC\Lab\UOM::$uom_list as $v => $n) {
$sel = ($v == $uom ? ' selected' : null);
printf('<option%s value="%s">%s</option>', $sel, $v, $n);
}
?>
</select>
</div>
</div>
<?php
}
/**
*
*/
function _draw_metric_select_pass_fail($lm)
{
// $sel = == 1 ? 'pass' : 'fail';
$sel = $lm['metric']['qom'];
?>
<div class="lab-metric-item">
<div class="input-group">
<div class="input-group-text"><?= __h($lm['name']) ?></div>
<select class="form-control" name="<?= sprintf('lab-metric-%s', $lm['id']) ?>">
<option>-empty-</option>
<option <?= ($sel == '-1' ? 'selected' : null) ?> value="-1">n/a</option>
<option <?= ($sel == '0' ? 'selected' : null) ?> value="0">Fail</option>
<option <?= ($sel == '1' ? 'selected' : null) ?> value="1">Pass</option>
</select>
</div>
</div>
<?php
}
/**
* Draw Status Picker
*/
function _draw_stat_pick()
{
$html = <<<HTML
<div class="input-group">
<div class="input-group-text">Result:</div>
<select class="form-control lab-metric-qom-bulk">
<option value="OK">OK</option>
<option value="N/A">N/A</option>
<option value="N/D">N/D</option>
<option value="N/T">N/T</option>
</select>
</div>
HTML;
return $html;
}
/**
* Draw UOM Picker
*/
function _draw_unit_pick()
{
$html = [];
$html[] = '<div class="input-group">';
$html[] = '<div class="input-group-text">UOM:</div>';
$html[] = '<select class="form-control lab-metric-uom-bulk">';
foreach (\OpenTHC\Lab\UOM::$uom_list as $k => $v) {
$html[] = sprintf('<option data-uom="%s" value="%s">%s</option>'
, $k
, $k
, $v
);
}
$html[] = '</select>';
$html[] = '</div>';
return implode('', $html);
}
/**
*
*/
function _lab_result_status_nice($x)
{
switch ($x) {
case 0:
case 100:
return 'In Progress';
break;
case 1: // @todo update all stat=1 lab_result to stat=200
case 200:
return '<span class="text-success">Passed</span>';
break;
case 400:
return '<span class="text-danger">Failed</span>';
break;
default:
return sprintf('<span class="text-warning" title="Status: %s">-unknown-</span>', $x);
break;
}
}