2 //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='$directory'");
10 $lines = @file($GLOBALS['srcdir']."/../interface/forms/$directory/info.txt");
17 return sqlInsert("insert into registry set
20 directory='".add_escape_custom($directory)."',
22 unpackaged='$unpackaged',
30 function updateRegistered($id, $mod)
32 return sqlInsert("update registry set
40 function getRegistered($state = "1", $limit = "unlimited", $offset = "0")
42 $sql = "select * from registry where state like \"$state\" order by priority, name";
43 if ($limit != "unlimited") {
44 $sql .= " limit $limit, $offset";
47 $res = sqlStatement($sql);
49 for ($iter=0; $row=sqlFetchArray($res); $iter++) {
59 function getRegistryEntry($id, $cols = "*")
61 $sql = "select $cols from registry where id='$id'";
62 return sqlQuery($sql);
65 function getRegistryEntryByDirectory($directory, $cols = "*")
67 $sql = "select $cols from registry where directory = ?";
68 return sqlQuery($sql, $directory);
71 function installSQL($dir)
73 $sqltext = $dir."/table.sql";
74 if ($sqlarray = @file($sqltext)) {
75 $sql = implode("", $sqlarray);
76 //echo "<br>$sql<br><br>";
77 $sqla = explode(";", $sql);
78 foreach ($sqla as $sqlq) {
79 if (strlen($sqlq) > 5) {
80 sqlStatement(rtrim("$sqlq"));
92 * is a form registered
93 * (optional - and active)
96 * NOTE - sometimes the Name of a form has a line-break at the end, thus this function might be better
98 * INPUT = directory => form directory
99 * state => 0=inactive / 1=active
100 * OUTPUT = true or false
102 function isRegistered($directory, $state = 1)
104 $sql = "select id from registry where ".
105 "directory='".$directory.
106 "' and state=".$state;
107 $result = sqlQuery($sql);
108 if ($result['id'] != '') {
115 function getTherapyGroupCategories()
121 // This gets an array including both standard and LBF visit form types,
122 // one row per form type, sorted by category, priority, is lbf, name.
124 function getFormsByCategory($state = '1', $lbfonly = false)
128 // First get the traditional form types from the registry table.
129 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
130 "unpackaged, date, priority, aco_spec FROM registry WHERE " .
131 "state LIKE ? ORDER BY category, priority, name";
132 $res = sqlStatement($sql, array($state));
134 while ($row = sqlFetchArray($res)) {
135 // Skip fee_sheet from list of registered forms.
136 if ($row['directory'] != 'fee_sheet') {
137 // Flag this entry as not LBF
145 // Merge LBF form types into the registry array of form types.
146 // Note that the mapping value is used as the category name.
147 $lres = sqlStatement("SELECT * FROM layout_group_properties " .
148 "WHERE grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
149 "ORDER BY grp_mapping, grp_seq, grp_title");
150 while ($lrow = sqlFetchArray($lres)) {
152 $rrow['category'] = $lrow['grp_mapping'] ? $lrow['grp_mapping'] : 'Clinical';
153 $rrow['name'] = $lrow['grp_title'];
154 $rrow['nickname'] = $lrow['grp_title'];
155 $rrow['directory'] = $lrow['grp_form_id']; // should start with LBF
156 $rrow['priority'] = $lrow['grp_seq'];
157 $rrow['aco_spec'] = $lrow['grp_aco_spec'];
158 $rrow['LBF'] = true; // Flag this form as LBF
162 // Sort by category, priority, is lbf, name.
163 usort($all, function ($a, $b) {
164 // Anonymous functions supported as of PHP 5.3. Yay!
165 if ($a['category'] == $b['category']) {
166 if ($a['priority'] == $b['priority']) {
167 if ($a['LBF'] == $b['LBF']) {
168 $name1 = $a['nickname'] ? $a['nickname'] : $a['name'];
169 $name2 = $b['nickname'] ? $b['nickname'] : $b['name'];
170 if ($name1 == $name2) {
173 return $name1 < $name2 ? -1 : 1;
175 // Sort LBF with the same priority after standard forms
176 return $b['LBF'] ? -1 : 1;
179 return $a['priority'] < $b['priority'] ? -1 : 1;
181 return $a['category'] < $b['category'] ? -1 : 1;