fix: Update patient_tracker.php (#6595)
[openemr.git] / library / registry.inc.php
blobb31cd4cc034763729165b8729fc8cf542142790e
1 <?php
3 //these are the functions used to access the forms registry database
4 //
6 function registerForm($directory, $sql_run = 0, $unpackaged = 1, $state = 0)
8 $check = sqlQuery("select state from registry where directory=?", array($directory));
9 if ($check == false) {
10 $lines = @file($GLOBALS['srcdir'] . "/../interface/forms/$directory/info.txt");
11 if ($lines) {
12 $name = $lines[0];
13 $category = $category ?? ($lines[1] ?? 'Miscellaneous');
14 } else {
15 $name = $directory;
16 $category = "Miscellaneous";
19 return sqlInsert("insert into registry set
20 name=?,
21 state=?,
22 directory=?,
23 sql_run=?,
24 unpackaged=?,
25 category=?,
26 date=NOW()
27 ", array($name, $state, $directory, $sql_run, $unpackaged, $category));
30 return false;
33 function updateRegistered($id, $mod)
35 return sqlInsert("update registry set $mod, date=NOW() where id=?", array($id));
38 /**
39 * @param string $state
40 * @param string $limit
41 * @param string $offset
42 * @param string $encounterType all|patient|therapy_group
44 function getRegistered($state = "1", $limit = "unlimited", $offset = "0", $encounterType = 'all')
46 $sql = "select * from registry where state like ? ";
47 if ($encounterType !== 'all') {
48 switch ($encounterType) {
49 case 'patient':
50 $sql .= 'AND patient_encounter = 1 ';
51 break;
52 case 'therapy_group':
53 $sql .= 'AND therapy_group_encounter = 1 ';
54 break;
57 $sql .= "order by priority, name ";
58 if ($limit != "unlimited") {
59 $sql .= " limit " . escape_limit($limit) . ", " . escape_limit($offset);
62 $res = sqlStatement($sql, array($state));
63 if ($res) {
64 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
65 $all[$iter] = $row;
67 } else {
68 return false;
71 return $all;
74 function getRegistryEntry($id, $cols = "*")
76 $sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('registry')) . " from registry where id=?";
77 return sqlQuery($sql, array($id));
80 function getRegistryEntryByDirectory($directory, $cols = "*")
82 $sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('registry')) . " from registry where directory = ?";
83 return sqlQuery($sql, $directory);
86 function installSQL($dir)
88 $sqltext = $dir . "/table.sql";
89 if ($sqlarray = @file($sqltext)) {
90 $sql = implode("", $sqlarray);
91 //echo "<br />$sql<br /><br />";
92 $sqla = explode(";", $sql);
93 foreach ($sqla as $sqlq) {
94 if (strlen($sqlq) > 5) {
95 sqlStatement(rtrim("$sqlq"));
99 return true;
100 } else {
101 return false;
107 * is a form registered
108 * (optional - and active)
109 * in the database?
111 * NOTE - sometimes the Name of a form has a line-break at the end, thus this function might be better
113 * INPUT = directory => form directory
114 * state => 0=inactive / 1=active
115 * OUTPUT = true or false
117 function isRegistered($directory, $state = 1)
119 $sql = "select id from registry where directory=? and state=?";
120 $result = sqlQuery($sql, array($directory, $state));
121 if (!empty($result['id'])) {
122 return true;
125 return false;
128 function getTherapyGroupCategories()
130 return array('');
133 // This gets an array including both standard and LBF visit form types,
134 // one row per form type, sorted by category, priority, is lbf, name.
136 function getFormsByCategory($state = '1', $lbfonly = false)
138 global $attendant_type;
139 $all = array();
140 if (!$lbfonly) {
141 // First get the traditional form types from the registry table.
142 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
143 "unpackaged, date, priority, aco_spec FROM registry WHERE ";
144 if (($attendant_type ?? 'pid') == 'pid') {
145 $sql .= "patient_encounter = 1 AND ";
146 } else {
147 $sql .= "therapy_group_encounter = 1 AND ";
149 $sql .= "state LIKE ? ORDER BY category, priority, name";
150 $res = sqlStatement($sql, array($state));
151 if ($res) {
152 while ($row = sqlFetchArray($res)) {
153 // Flag this entry as not LBF
154 $row['LBF'] = false;
155 $all[] = $row;
160 // Merge LBF form types into the registry array of form types.
161 // Note that the mapping value is used as the category name.
162 $lres = sqlStatement(
163 "SELECT * FROM layout_group_properties " .
164 "WHERE grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
165 "ORDER BY grp_mapping, grp_seq, grp_title"
167 while ($lrow = sqlFetchArray($lres)) {
168 $rrow = array();
169 $rrow['category'] = $lrow['grp_mapping'] ? $lrow['grp_mapping'] : 'Clinical';
170 $rrow['name'] = $lrow['grp_title'];
171 $rrow['nickname'] = $lrow['grp_title'];
172 $rrow['directory'] = $lrow['grp_form_id']; // should start with LBF
173 $rrow['priority'] = $lrow['grp_seq'];
174 $rrow['aco_spec'] = $lrow['grp_aco_spec'];
175 $rrow['LBF'] = true; // Flag this form as LBF
176 $all[] = $rrow;
179 // Sort by category, priority, is lbf, name.
180 usort($all, function ($a, $b) {
181 // Anonymous functions supported as of PHP 5.3. Yay!
182 if ($a['category'] == $b['category']) {
183 if ($a['priority'] == $b['priority']) {
184 if ($a['LBF'] == $b['LBF']) {
185 $name1 = $a['nickname'] ? $a['nickname'] : $a['name'];
186 $name2 = $b['nickname'] ? $b['nickname'] : $b['name'];
187 if ($name1 == $name2) {
188 return 0;
190 return $name1 < $name2 ? -1 : 1;
191 } else {
192 // Sort LBF with the same priority after standard forms
193 return $b['LBF'] ? -1 : 1;
196 return $a['priority'] < $b['priority'] ? -1 : 1;
198 return $a['category'] < $b['category'] ? -1 : 1;
200 return $all;