forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.inc.php
201 lines (182 loc) · 6.15 KB
/
registry.inc.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
<?php
//these are the functions used to access the forms registry database
//
function registerForm($directory, $sql_run = 0, $unpackaged = 1, $state = 0)
{
$check = sqlQuery("select state from registry where directory=?", array($directory));
if ($check == false) {
$lines = @file($GLOBALS['srcdir'] . "/../interface/forms/$directory/info.txt");
if ($lines) {
$name = $lines[0];
$category = $category ?? ($lines[1] ?? 'Miscellaneous');
} else {
$name = $directory;
$category = "Miscellaneous";
}
return sqlInsert("insert into registry set
name=?,
state=?,
directory=?,
sql_run=?,
unpackaged=?,
category=?,
date=NOW()
", array($name, $state, $directory, $sql_run, $unpackaged, $category));
}
return false;
}
function updateRegistered($id, $mod)
{
return sqlInsert("update registry set $mod, date=NOW() where id=?", array($id));
}
/**
* @param string $state
* @param string $limit
* @param string $offset
* @param string $encounterType all|patient|therapy_group
*/
function getRegistered($state = "1", $limit = "unlimited", $offset = "0", $encounterType = 'all')
{
$sql = "select * from registry where state like ? ";
if ($encounterType !== 'all') {
switch ($encounterType) {
case 'patient':
$sql .= 'AND patient_encounter = 1 ';
break;
case 'therapy_group':
$sql .= 'AND therapy_group_encounter = 1 ';
break;
}
}
$sql .= "order by priority, name ";
if ($limit != "unlimited") {
$sql .= " limit " . escape_limit($limit) . ", " . escape_limit($offset);
}
$res = sqlStatement($sql, array($state));
if ($res) {
for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
$all[$iter] = $row;
}
} else {
return false;
}
return $all;
}
function getRegistryEntry($id, $cols = "*")
{
$sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('registry')) . " from registry where id=?";
return sqlQuery($sql, array($id));
}
function getRegistryEntryByDirectory($directory, $cols = "*")
{
$sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('registry')) . " from registry where directory = ?";
return sqlQuery($sql, $directory);
}
function installSQL($dir)
{
$sqltext = $dir . "/table.sql";
if ($sqlarray = @file($sqltext)) {
$sql = implode("", $sqlarray);
//echo "<br />$sql<br /><br />";
$sqla = explode(";", $sql);
foreach ($sqla as $sqlq) {
if (strlen($sqlq) > 5) {
sqlStatement(rtrim("$sqlq"));
}
}
return true;
} else {
return false;
}
}
/*
* is a form registered
* (optional - and active)
* in the database?
*
* NOTE - sometimes the Name of a form has a line-break at the end, thus this function might be better
*
* INPUT = directory => form directory
* state => 0=inactive / 1=active
* OUTPUT = true or false
*/
function isRegistered($directory, $state = 1)
{
$sql = "select id from registry where directory=? and state=?";
$result = sqlQuery($sql, array($directory, $state));
if (!empty($result['id'])) {
return true;
}
return false;
}
function getTherapyGroupCategories()
{
return array('');
}
// This gets an array including both standard and LBF visit form types,
// one row per form type, sorted by category, priority, is lbf, name.
//
function getFormsByCategory($state = '1', $lbfonly = false)
{
global $attendant_type;
$all = array();
if (!$lbfonly) {
// First get the traditional form types from the registry table.
$sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
"unpackaged, date, priority, aco_spec FROM registry WHERE ";
if (($attendant_type ?? 'pid') == 'pid') {
$sql .= "patient_encounter = 1 AND ";
} else {
$sql .= "therapy_group_encounter = 1 AND ";
}
$sql .= "state LIKE ? ORDER BY category, priority, name";
$res = sqlStatement($sql, array($state));
if ($res) {
while ($row = sqlFetchArray($res)) {
// Flag this entry as not LBF
$row['LBF'] = false;
$all[] = $row;
}
}
}
// Merge LBF form types into the registry array of form types.
// Note that the mapping value is used as the category name.
$lres = sqlStatement(
"SELECT * FROM layout_group_properties " .
"WHERE grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
"ORDER BY grp_mapping, grp_seq, grp_title"
);
while ($lrow = sqlFetchArray($lres)) {
$rrow = array();
$rrow['category'] = $lrow['grp_mapping'] ? $lrow['grp_mapping'] : 'Clinical';
$rrow['name'] = $lrow['grp_title'];
$rrow['nickname'] = $lrow['grp_title'];
$rrow['directory'] = $lrow['grp_form_id']; // should start with LBF
$rrow['priority'] = $lrow['grp_seq'];
$rrow['aco_spec'] = $lrow['grp_aco_spec'];
$rrow['LBF'] = true; // Flag this form as LBF
$all[] = $rrow;
}
// Sort by category, priority, is lbf, name.
usort($all, function ($a, $b) {
// Anonymous functions supported as of PHP 5.3. Yay!
if ($a['category'] == $b['category']) {
if ($a['priority'] == $b['priority']) {
if ($a['LBF'] == $b['LBF']) {
$name1 = $a['nickname'] ? $a['nickname'] : $a['name'];
$name2 = $b['nickname'] ? $b['nickname'] : $b['name'];
if ($name1 == $name2) {
return 0;
}
return $name1 < $name2 ? -1 : 1;
} else {
// Sort LBF with the same priority after standard forms
return $b['LBF'] ? -1 : 1;
}
}
return $a['priority'] < $b['priority'] ? -1 : 1;
}
return $a['category'] < $b['category'] ? -1 : 1;
});
return $all;
}