fixed display of non-calendar providers in the Billing Report page
[openemr.git] / interface / forms / LBF / new.php
blobe54c4d9f8b1bbe3be50df7b1e198739e4b8427f7
1 <?php
2 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../../globals.php");
10 require_once("$srcdir/api.inc");
11 require_once("$srcdir/forms.inc");
12 require_once("$srcdir/options.inc.php");
13 require_once("$srcdir/patient.inc");
14 require_once("$srcdir/formdata.inc.php");
16 $CPR = 4; // cells per row
18 $pprow = array();
20 if (! $encounter) { // comes from globals.php
21 die("Internal error: we do not seem to be in an encounter!");
24 function end_cell() {
25 global $item_count, $cell_count;
26 if ($item_count > 0) {
27 echo "</td>";
28 $item_count = 0;
32 function end_row() {
33 global $cell_count, $CPR;
34 end_cell();
35 if ($cell_count > 0) {
36 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
37 echo "</tr>\n";
38 $cell_count = 0;
42 function end_group() {
43 global $last_group;
44 if (strlen($last_group) > 0) {
45 end_row();
46 echo " </table>\n";
47 echo "</div>\n";
51 $formname = formData('formname', 'G');
52 $formid = 0 + formData('id', 'G');
54 $tmp = sqlQuery("SELECT title FROM list_options WHERE " .
55 "list_id = 'lbfnames' AND option_id = '$formname'");
56 $formtitle = $tmp['title'];
58 $newid = 0;
60 // If Save was clicked, save the info.
62 if ($_POST['bn_save']) {
63 $sets = "";
64 $fres = sqlStatement("SELECT * FROM layout_options " .
65 "WHERE form_id = '$formname' AND uor > 0 AND field_id != '' AND " .
66 "edit_options != 'H' " .
67 "ORDER BY group_name, seq");
68 while ($frow = sqlFetchArray($fres)) {
69 $field_id = $frow['field_id'];
70 $value = get_layout_form_value($frow);
71 if ($formid) { // existing form
72 if ($value === '') {
73 $query = "DELETE FROM lbf_data WHERE " .
74 "form_id = '$formid' AND field_id = '$field_id'";
76 else {
77 $query = "REPLACE INTO lbf_data SET field_value = '$value', " .
78 "form_id = '$formid', field_id = '$field_id'";
80 sqlStatement($query);
82 else { // new form
83 if ($value !== '') {
84 if ($newid) {
85 sqlStatement("INSERT INTO lbf_data " .
86 "( form_id, field_id, field_value ) " .
87 " VALUES ( '$newid', '$field_id', '$value' )");
89 else {
90 $newid = sqlInsert("INSERT INTO lbf_data " .
91 "( field_id, field_value ) " .
92 " VALUES ( '$field_id', '$value' )");
95 // Note that a completely empty form will not be created at all!
99 if (!$formid && $newid) {
100 addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
103 formHeader("Redirecting....");
104 formJump();
105 formFooter();
106 exit;
109 $fname = "../../../custom/LBF/$formname.plugin.php";
110 if (file_exists($fname)) include_once($fname);
112 $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date FROM " .
113 "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
114 "p.pid = '$pid' AND f.pid = '$pid' AND f.encounter = '$encounter' AND " .
115 "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
116 "fe.id = f.form_id LIMIT 1");
118 <html>
119 <head>
120 <?php html_header_show();?>
121 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
122 <style>
124 td, input, select, textarea {
125 font-family: Arial, Helvetica, sans-serif;
126 font-size: 10pt;
129 div.section {
130 border: solid;
131 border-width: 1px;
132 border-color: #0000ff;
133 margin: 0 0 0 10pt;
134 padding: 5pt;
137 </style>
139 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
141 <script type="text/javascript" src="../../../library/dialog.js"></script>
142 <script type="text/javascript" src="../../../library/textformat.js"></script>
143 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
144 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
145 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
146 <script type="text/javascript" src="../../../library/js/jquery.js"></script>
148 <script language="JavaScript">
150 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
152 // Supports customizable forms.
153 function divclick(cb, divid) {
154 var divstyle = document.getElementById(divid).style;
155 if (cb.checked) {
156 divstyle.display = 'block';
157 } else {
158 divstyle.display = 'none';
160 return true;
163 // This is for callback by the find-code popup.
164 // Appends to or erases the current list of related codes.
165 function set_related(codetype, code, selector, codedesc) {
166 var frc = document.getElementById('form_related_code');
167 var s = frc.value;
168 if (code) {
169 if (s.length > 0) s += ';';
170 s += codetype + ':' + code;
171 } else {
172 s = '';
174 frc.value = s;
177 // This invokes the find-code popup.
178 function sel_related() {
179 dlgopen('<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
182 <?php if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?>
184 </script>
185 </head>
187 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
188 <form method="post" action="<?php echo $rootdir ?>/forms/LBF/new.php?formname=<?php echo $formname ?>&id=<?php echo $formid ?>"
189 onsubmit="return top.restoreSession()">
191 <p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>
192 <?php
193 echo "$formtitle " . xl('for') . ' ';
194 echo $enrow['fname'] . ' ' . $enrow['mname'] . ' ' . $enrow['lname'];
195 echo ' ' . xl('on') . ' ' . substr($enrow['date'], 0, 10);
197 </p>
199 <?php
200 $shrow = getHistoryData($pid);
202 $fres = sqlStatement("SELECT * FROM layout_options " .
203 "WHERE form_id = '$formname' AND uor > 0 " .
204 "ORDER BY group_name, seq");
205 $last_group = '';
206 $cell_count = 0;
207 $item_count = 0;
208 $display_style = 'block';
210 while ($frow = sqlFetchArray($fres)) {
211 $this_group = $frow['group_name'];
212 $titlecols = $frow['titlecols'];
213 $datacols = $frow['datacols'];
214 $data_type = $frow['data_type'];
215 $field_id = $frow['field_id'];
216 $list_id = $frow['list_id'];
218 $currvalue = '';
220 if ($frow['edit_options'] == 'H') {
221 // This data comes from static history
222 if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
223 } else {
224 if ($formid) {
225 $pprow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
226 "form_id = '$formid' AND field_id = '$field_id'");
227 if (!empty($pprow)) $currvalue = $pprow['field_value'];
229 else {
230 // New form, see if there is a custom default from a plugin.
231 $fname = $formname . '_default_' . $field_id;
232 if (function_exists($fname)) {
233 $currvalue = call_user_func($fname);
238 // Handle a data category (group) change.
239 if (strcmp($this_group, $last_group) != 0) {
240 end_group();
241 $group_seq = 'lbf' . substr($this_group, 0, 1);
242 $group_name = substr($this_group, 1);
243 $last_group = $this_group;
244 echo "<br /><span class='bold'><input type='checkbox' name='form_cb_$group_seq' value='1' " .
245 "onclick='return divclick(this,\"div_$group_seq\");'";
246 if ($display_style == 'block') echo " checked";
247 echo " /><b>" . xl_layout_label($group_name) . "</b></span>\n";
248 echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
249 echo " <table border='0' cellpadding='0' width='100%'>\n";
250 $display_style = 'none';
253 // Handle starting of a new row.
254 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
255 end_row();
256 echo " <tr>";
259 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
261 // Handle starting of a new label cell.
262 if ($titlecols > 0) {
263 end_cell();
264 echo "<td valign='top' colspan='$titlecols' width='1%' nowrap";
265 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
266 if ($cell_count == 2) echo " style='padding-left:10pt'";
267 echo ">";
268 $cell_count += $titlecols;
270 ++$item_count;
272 echo "<b>";
273 if ($frow['title']) echo (xl_layout_label($frow['title']) . ":"); else echo "&nbsp;";
274 echo "</b>";
276 // Handle starting of a new data cell.
277 if ($datacols > 0) {
278 end_cell();
279 echo "<td valign='top' colspan='$datacols' class='text'";
280 if ($cell_count > 0) echo " style='padding-left:5pt'";
281 echo ">";
282 $cell_count += $datacols;
285 ++$item_count;
287 if ($frow['edit_options'] == 'H')
288 echo generate_display_field($frow, $currvalue);
289 else
290 generate_form_field($frow, $currvalue);
293 end_group();
296 <p style='text-align:center'>
297 <input type='submit' name='bn_save' value='Save' />
298 &nbsp;
299 <input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
300 &nbsp;
301 </p>
303 </form>
305 <!-- include support for the list-add selectbox feature -->
306 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
308 <script language="JavaScript">
309 <?php echo $date_init; ?>
310 <?php
311 if (function_exists($formname . '_javascript_onload')) {
312 call_user_func($formname . '_javascript_onload');
314 // TBD: If $alertmsg, display it with a JavaScript alert().
316 </script>
318 </body>
319 </html>