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=?", array($directory));
10 $lines = @file($GLOBALS['srcdir']."/../interface/forms/$directory/info.txt");
17 return sqlInsert("insert into registry set
24 ", array($name, $state, $directory, $sql_run, $unpackaged));
30 function updateRegistered($id, $mod)
32 return sqlInsert("update registry set $mod, date=NOW() where id=?", array($id));
36 * @param string $state
37 * @param string $limit
38 * @param string $offset
39 * @param string $encounterType all|patient|therapy_group
41 function getRegistered($state = "1", $limit = "unlimited", $offset = "0", $encounterType = 'all')
43 $sql = "select * from registry where state like ? ";
44 if ($encounterType !== 'all') {
45 switch ($encounterType) {
47 $sql .= 'AND patient_encounter = 1 ';
50 $sql .= 'AND therapy_group_encounter = 1 ';
54 $sql .= "order by priority, name ";
55 if ($limit != "unlimited") {
56 $sql .= " limit " . escape_limit($limit) . ", " . escape_limit($offset);
59 $res = sqlStatement($sql, array($state));
61 for ($iter=0; $row=sqlFetchArray($res); $iter++) {
71 function getRegistryEntry($id, $cols = "*")
73 $sql = "select $cols from registry where id=?";
74 return sqlQuery($sql, array($id));
77 function getRegistryEntryByDirectory($directory, $cols = "*")
79 $sql = "select $cols from registry where directory = ?";
80 return sqlQuery($sql, $directory);
83 function installSQL($dir)
85 $sqltext = $dir."/table.sql";
86 if ($sqlarray = @file($sqltext)) {
87 $sql = implode("", $sqlarray);
88 //echo "<br>$sql<br><br>";
89 $sqla = explode(";", $sql);
90 foreach ($sqla as $sqlq) {
91 if (strlen($sqlq) > 5) {
92 sqlStatement(rtrim("$sqlq"));
104 * is a form registered
105 * (optional - and active)
108 * NOTE - sometimes the Name of a form has a line-break at the end, thus this function might be better
110 * INPUT = directory => form directory
111 * state => 0=inactive / 1=active
112 * OUTPUT = true or false
114 function isRegistered($directory, $state = 1)
116 $sql = "select id from registry where directory=? and state=?";
117 $result = sqlQuery($sql, array($directory, $state));
118 if ($result['id'] != '') {
125 function getTherapyGroupCategories()
131 // This gets an array including both standard and LBF visit form types,
132 // one row per form type, sorted by category, priority, is lbf, name.
134 function getFormsByCategory($state = '1', $lbfonly = false)
138 // First get the traditional form types from the registry table.
139 $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
140 "unpackaged, date, priority, aco_spec FROM registry WHERE " .
141 "state LIKE ? ORDER BY category, priority, name";
142 $res = sqlStatement($sql, array($state));
144 while ($row = sqlFetchArray($res)) {
145 // Skip fee_sheet from list of registered forms.
146 if ($row['directory'] != 'fee_sheet') {
147 // Flag this entry as not LBF
155 // Merge LBF form types into the registry array of form types.
156 // Note that the mapping value is used as the category name.
157 $lres = sqlStatement("SELECT * FROM layout_group_properties " .
158 "WHERE grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 " .
159 "ORDER BY grp_mapping, grp_seq, grp_title");
160 while ($lrow = sqlFetchArray($lres)) {
162 $rrow['category'] = $lrow['grp_mapping'] ? $lrow['grp_mapping'] : 'Clinical';
163 $rrow['name'] = $lrow['grp_title'];
164 $rrow['nickname'] = $lrow['grp_title'];
165 $rrow['directory'] = $lrow['grp_form_id']; // should start with LBF
166 $rrow['priority'] = $lrow['grp_seq'];
167 $rrow['aco_spec'] = $lrow['grp_aco_spec'];
168 $rrow['LBF'] = true; // Flag this form as LBF
172 // Sort by category, priority, is lbf, name.
173 usort($all, function ($a, $b) {
174 // Anonymous functions supported as of PHP 5.3. Yay!
175 if ($a['category'] == $b['category']) {
176 if ($a['priority'] == $b['priority']) {
177 if ($a['LBF'] == $b['LBF']) {
178 $name1 = $a['nickname'] ? $a['nickname'] : $a['name'];
179 $name2 = $b['nickname'] ? $b['nickname'] : $b['name'];
180 if ($name1 == $name2) {
183 return $name1 < $name2 ? -1 : 1;
185 // Sort LBF with the same priority after standard forms
186 return $b['LBF'] ? -1 : 1;
189 return $a['priority'] < $b['priority'] ? -1 : 1;
191 return $a['category'] < $b['category'] ? -1 : 1;