3 //these are the functions used to access the forms registry database
7 function registerForm($directory, $sql_run = 0, $unpackaged = 1, $state = 0)
9 $check = sqlQuery("select state from registry where directory=?", array($directory));
10 if ($check == false) {
11 $lines = @file($GLOBALS['srcdir'] . "/../interface/forms/$directory/info.txt");
14 $category = $category ?? ($lines[1] ?? 'Miscellaneous');
17 $category = "Miscellaneous";
20 return sqlInsert("insert into registry set
28 ", array($name, $state, $directory, $sql_run, $unpackaged, $category));
34 function updateRegistered($id, $mod)
36 return sqlInsert("update registry set $mod, date=NOW() where id=?", array($id));
40 * @param string $state
41 * @param string $limit
42 * @param string $offset
43 * @param string $encounterType all|patient|therapy_group
45 function getRegistered($state = "1", $limit = "unlimited", $offset = "0", $encounterType = 'all')
47 $sql = "select * from registry where state like ? ";
48 if ($encounterType !== 'all') {
49 switch ($encounterType) {
51 $sql .= 'AND patient_encounter = 1 ';
54 $sql .= 'AND therapy_group_encounter = 1 ';
58 $sql .= "order by priority, name ";
59 if ($limit != "unlimited") {
60 $sql .= " limit " . escape_limit($limit) . ", " . escape_limit($offset);
63 $res = sqlStatement($sql, array($state));
65 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
75 function getRegistryEntry($id, $cols = "*")
77 $sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('registry')) . " from registry where id=?";
78 return sqlQuery($sql, array($id));
81 function getRegistryEntryByDirectory($directory, $cols = "*")
83 $sql = "select " . escape_sql_column_name(process_cols_escape($cols), array('registry')) . " from registry where directory = ?";
84 return sqlQuery($sql, $directory);
87 function installSQL($dir)
89 $sqltext = $dir . "/table.sql";
90 if ($sqlarray = @file($sqltext)) {
91 $sql = implode("", $sqlarray);
92 //echo "<br />$sql<br /><br />";
93 $sqla = explode(";", $sql);
94 foreach ($sqla as $sqlq) {
95 if (strlen($sqlq) > 5) {
96 sqlStatement(rtrim("$sqlq"));
108 * is a form registered
109 * (optional - and active)
112 * NOTE - sometimes the Name of a form has a line-break at the end, thus this function might be better
114 * INPUT = directory => form directory
115 * state => 0=inactive / 1=active
116 * OUTPUT = true or false
118 function isRegistered($directory, $state = 1)
120 $sql = "select id from registry where directory=? and state=?";
121 $result = sqlQuery($sql, array($directory, $state));
122 if (!empty($result['id'])) {
129 function getTherapyGroupCategories()
134 // This gets an array including both standard and LBF visit form types,
135 // one row per form type, sorted by category, priority, is lbf, name.
137 function getFormsByCategory($state = '1', $lbfonly = false)
139 global $attendant_type;
142 // First get the traditional form types from the registry table.
143 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
144 "unpackaged, date, priority, aco_spec FROM registry WHERE ";
145 if (($attendant_type ?? 'pid') == 'pid') {
146 $sql .= "patient_encounter = 1 AND ";
148 $sql .= "therapy_group_encounter = 1 AND ";
150 $sql .= "state LIKE ? ORDER BY category, priority, name";
151 $res = sqlStatement($sql, array($state));
153 while ($row = sqlFetchArray($res)) {
154 // Flag this entry as not LBF
161 // Merge LBF form types into the registry array of form types.
162 // Note that the mapping value is used as the category name.
163 $lres = sqlStatement(
164 "SELECT * FROM layout_group_properties " .
165 "WHERE grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
166 "ORDER BY grp_mapping, grp_seq, grp_title"
168 while ($lrow = sqlFetchArray($lres)) {
170 $rrow['category'] = $lrow['grp_mapping'] ? $lrow['grp_mapping'] : 'Clinical';
171 $rrow['name'] = $lrow['grp_title'];
172 $rrow['nickname'] = $lrow['grp_title'];
173 $rrow['directory'] = $lrow['grp_form_id']; // should start with LBF
174 $rrow['priority'] = $lrow['grp_seq'];
175 $rrow['aco_spec'] = $lrow['grp_aco_spec'];
176 $rrow['LBF'] = true; // Flag this form as LBF
180 // Sort by category, priority, is lbf, name.
181 usort($all, function ($a, $b) {
182 // Anonymous functions supported as of PHP 5.3. Yay!
183 if ($a['category'] == $b['category']) {
184 if ($a['priority'] == $b['priority']) {
185 if ($a['LBF'] == $b['LBF']) {
186 $name1 = $a['nickname'] ? $a['nickname'] : $a['name'];
187 $name2 = $b['nickname'] ? $b['nickname'] : $b['name'];
188 if ($name1 == $name2) {
191 return $name1 < $name2 ? -1 : 1;
193 // Sort LBF with the same priority after standard forms
194 return $b['LBF'] ? -1 : 1;
197 return $a['priority'] < $b['priority'] ? -1 : 1;
199 return $a['category'] < $b['category'] ? -1 : 1;