3 //these are the functions used to access the forms registry database
6 function registerForm($directory, $sql_run = 0, $unpackaged = 1, $state = 0)
8 $check = sqlQuery("select state from registry where directory=?", array($directory));
10 $lines = @file
($GLOBALS['srcdir'] . "/../interface/forms/$directory/info.txt");
13 $category = $category ??
($lines[1] ??
'Miscellaneous');
16 $category = "Miscellaneous";
19 return sqlInsert("insert into registry set
27 ", array($name, $state, $directory, $sql_run, $unpackaged, $category));
33 function updateRegistered($id, $mod)
35 return sqlInsert("update registry set $mod, date=NOW() where id=?", array($id));
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) {
50 $sql .= 'AND patient_encounter = 1 ';
53 $sql .= 'AND therapy_group_encounter = 1 ';
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));
64 for ($iter = 0; $row = sqlFetchArray($res); $iter++
) {
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"));
107 * is a form registered
108 * (optional - and active)
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'])) {
128 function getTherapyGroupCategories()
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;
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 ";
147 $sql .= "therapy_group_encounter = 1 AND ";
149 $sql .= "state LIKE ? ORDER BY category, priority, name";
150 $res = sqlStatement($sql, array($state));
152 while ($row = sqlFetchArray($res)) {
153 // Flag this entry as not LBF
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)) {
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
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) {
190 return $name1 < $name2 ?
-1 : 1;
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;