PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/interface/forms/LBF/new.php

https://github.com/md-tech/openemr
PHP | 449 lines | 343 code | 65 blank | 41 comment | 74 complexity | a599b3622c72870960154defa59bc5d0 MD5 | raw file
  1. <?php
  2. // Copyright (C) 2009-2011 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.
  8. require_once("../../globals.php");
  9. require_once("$srcdir/api.inc");
  10. require_once("$srcdir/forms.inc");
  11. require_once("$srcdir/options.inc.php");
  12. require_once("$srcdir/patient.inc");
  13. require_once("$srcdir/formdata.inc.php");
  14. $CPR = 4; // cells per row
  15. $pprow = array();
  16. // $is_lbf is defined in trend_form.php and indicates that we are being
  17. // invoked from there; in that case the current encounter is irrelevant.
  18. if (empty($is_lbf) && !$encounter) {
  19. die("Internal error: we do not seem to be in an encounter!");
  20. }
  21. function end_cell() {
  22. global $item_count, $cell_count, $historical_ids;
  23. if ($item_count > 0) {
  24. echo "</td>";
  25. foreach ($historical_ids as $key => $dummy) {
  26. $historical_ids[$key] .= "</td>";
  27. }
  28. $item_count = 0;
  29. }
  30. }
  31. function end_row() {
  32. global $cell_count, $CPR, $historical_ids;
  33. end_cell();
  34. if ($cell_count > 0) {
  35. for (; $cell_count < $CPR; ++$cell_count) {
  36. echo "<td></td>";
  37. foreach ($historical_ids as $key => $dummy) {
  38. $historical_ids[$key] .= "<td></td>";
  39. }
  40. }
  41. foreach ($historical_ids as $key => $dummy) {
  42. echo $historical_ids[$key];
  43. }
  44. echo "</tr>\n";
  45. $cell_count = 0;
  46. }
  47. }
  48. function end_group() {
  49. global $last_group;
  50. if (strlen($last_group) > 0) {
  51. end_row();
  52. echo " </table>\n";
  53. // No div for an empty group name.
  54. if (strlen($last_group) > 1) echo "</div>\n";
  55. }
  56. }
  57. $formname = formData('formname', 'G');
  58. $formid = 0 + formData('id', 'G');
  59. // Get title and number of history columns for this form.
  60. $tmp = sqlQuery("SELECT title, option_value FROM list_options WHERE " .
  61. "list_id = 'lbfnames' AND option_id = '$formname'");
  62. $formtitle = $tmp['title'];
  63. $formhistory = 0 + $tmp['option_value'];
  64. $newid = 0;
  65. // If Save was clicked, save the info.
  66. //
  67. if ($_POST['bn_save']) {
  68. $sets = "";
  69. $fres = sqlStatement("SELECT * FROM layout_options " .
  70. "WHERE form_id = '$formname' AND uor > 0 AND field_id != '' AND " .
  71. "edit_options != 'H' " .
  72. "ORDER BY group_name, seq");
  73. while ($frow = sqlFetchArray($fres)) {
  74. $field_id = $frow['field_id'];
  75. $value = get_layout_form_value($frow);
  76. if ($formid) { // existing form
  77. if ($value === '') {
  78. $query = "DELETE FROM lbf_data WHERE " .
  79. "form_id = '$formid' AND field_id = '$field_id'";
  80. }
  81. else {
  82. $query = "REPLACE INTO lbf_data SET field_value = '$value', " .
  83. "form_id = '$formid', field_id = '$field_id'";
  84. }
  85. sqlStatement($query);
  86. }
  87. else { // new form
  88. if ($value !== '') {
  89. if ($newid) {
  90. sqlStatement("INSERT INTO lbf_data " .
  91. "( form_id, field_id, field_value ) " .
  92. " VALUES ( '$newid', '$field_id', '$value' )");
  93. }
  94. else {
  95. $newid = sqlInsert("INSERT INTO lbf_data " .
  96. "( field_id, field_value ) " .
  97. " VALUES ( '$field_id', '$value' )");
  98. }
  99. }
  100. // Note that a completely empty form will not be created at all!
  101. }
  102. }
  103. if (!$formid && $newid) {
  104. addForm($encounter, $formtitle, $newid, $formname, $pid, $userauthorized);
  105. }
  106. formHeader("Redirecting....");
  107. formJump();
  108. formFooter();
  109. exit;
  110. }
  111. if (empty($is_lbf)) {
  112. $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$formname.plugin.php";
  113. if (file_exists($fname)) include_once($fname);
  114. }
  115. ?>
  116. <html>
  117. <head>
  118. <?php html_header_show();?>
  119. <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
  120. <style>
  121. td, input, select, textarea {
  122. font-family: Arial, Helvetica, sans-serif;
  123. font-size: 10pt;
  124. }
  125. div.section {
  126. border: solid;
  127. border-width: 1px;
  128. border-color: #0000ff;
  129. margin: 0 0 0 10pt;
  130. padding: 5pt;
  131. }
  132. </style>
  133. <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
  134. <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
  135. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
  136. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
  137. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
  138. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
  139. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui.js"></script>
  140. <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.easydrag.handler.beta2.js"></script>
  141. <script type="text/javascript" src="../../../library/textformat.js"></script>
  142. <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
  143. <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
  144. <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
  145. <script language="JavaScript">
  146. $(document).ready(function(){
  147. // fancy box
  148. if(window.enable_modals){
  149. enable_modals();
  150. }
  151. if(window.tabbify){
  152. tabbify();
  153. }
  154. // special size for
  155. $(".iframe_medium").fancybox( {
  156. 'overlayOpacity' : 0.0,
  157. 'showCloseButton' : true,
  158. 'frameHeight' : 580,
  159. 'frameWidth' : 900
  160. });
  161. $(function(){
  162. // add drag and drop functionality to fancybox
  163. $("#fancy_outer").easydrag();
  164. });
  165. });
  166. var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
  167. // Supports customizable forms.
  168. function divclick(cb, divid) {
  169. var divstyle = document.getElementById(divid).style;
  170. if (cb.checked) {
  171. divstyle.display = 'block';
  172. } else {
  173. divstyle.display = 'none';
  174. }
  175. return true;
  176. }
  177. // This is for callback by the find-code popup.
  178. // Appends to or erases the current list of related codes.
  179. function set_related(codetype, code, selector, codedesc) {
  180. var frc = document.getElementById('form_related_code');
  181. var s = frc.value;
  182. if (code) {
  183. if (s.length > 0) s += ';';
  184. s += codetype + ':' + code;
  185. } else {
  186. s = '';
  187. }
  188. frc.value = s;
  189. }
  190. // This invokes the find-code popup.
  191. function sel_related() {
  192. dlgopen('<?php echo $rootdir ?>/patient_file/encounter/find_code_popup.php', '_blank', 500, 400);
  193. }
  194. <?php if (function_exists($formname . '_javascript')) call_user_func($formname . '_javascript'); ?>
  195. </script>
  196. </head>
  197. <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
  198. <form method="post" action="<?php echo $rootdir ?>/forms/LBF/new.php?formname=<?php echo $formname ?>&id=<?php echo $formid ?>"
  199. onsubmit="return top.restoreSession()">
  200. <?php
  201. if (empty($is_lbf)) {
  202. $enrow = sqlQuery("SELECT p.fname, p.mname, p.lname, fe.date FROM " .
  203. "form_encounter AS fe, forms AS f, patient_data AS p WHERE " .
  204. "p.pid = '$pid' AND f.pid = '$pid' AND f.encounter = '$encounter' AND " .
  205. "f.formdir = 'newpatient' AND f.deleted = 0 AND " .
  206. "fe.id = f.form_id LIMIT 1");
  207. echo "<p class='title' style='margin-top:8px;margin-bottom:8px;text-align:center'>\n";
  208. echo "$formtitle " . xl('for') . ' ';
  209. echo $enrow['fname'] . ' ' . $enrow['mname'] . ' ' . $enrow['lname'];
  210. echo ' ' . htmlspecialchars(xl('on')) . ' ' . substr($enrow['date'], 0, 10);
  211. echo "</p>\n";
  212. }
  213. ?>
  214. <!-- This is where a chart might display. -->
  215. <div id="chart"></div>
  216. <?php
  217. $shrow = getHistoryData($pid);
  218. $fres = sqlStatement("SELECT * FROM layout_options " .
  219. "WHERE form_id = '$formname' AND uor > 0 " .
  220. "ORDER BY group_name, seq");
  221. $last_group = '';
  222. $cell_count = 0;
  223. $item_count = 0;
  224. $display_style = 'block';
  225. // This is an array keyed on forms.form_id for other occurrences of this
  226. // form type. The maximum number of such other occurrences to display is
  227. // in list_options.option_value for this form's list item. Values in this
  228. // array are work areas for building the ending HTML for each displayed row.
  229. //
  230. $historical_ids = array();
  231. // True if any data items in this form can be graphed.
  232. $form_is_graphable = false;
  233. while ($frow = sqlFetchArray($fres)) {
  234. $this_group = $frow['group_name'];
  235. $titlecols = $frow['titlecols'];
  236. $datacols = $frow['datacols'];
  237. $data_type = $frow['data_type'];
  238. $field_id = $frow['field_id'];
  239. $list_id = $frow['list_id'];
  240. $edit_options = $frow['edit_options'];
  241. $graphable = strpos($edit_options, 'G') !== FALSE;
  242. if ($graphable) $form_is_graphable = true;
  243. $currvalue = '';
  244. if ($frow['edit_options'] == 'H') {
  245. // This data comes from static history
  246. if (isset($shrow[$field_id])) $currvalue = $shrow[$field_id];
  247. } else {
  248. if ($formid) {
  249. $pprow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
  250. "form_id = '$formid' AND field_id = '$field_id'");
  251. if (!empty($pprow)) $currvalue = $pprow['field_value'];
  252. }
  253. else {
  254. // New form, see if there is a custom default from a plugin.
  255. $fname = $formname . '_default_' . $field_id;
  256. if (function_exists($fname)) {
  257. $currvalue = call_user_func($fname);
  258. }
  259. }
  260. }
  261. // Handle a data category (group) change.
  262. if (strcmp($this_group, $last_group) != 0) {
  263. end_group();
  264. $group_seq = 'lbf' . substr($this_group, 0, 1);
  265. $group_name = substr($this_group, 1);
  266. $last_group = $this_group;
  267. // If group name is blank, no checkbox or div.
  268. if (strlen($this_group) > 1) {
  269. echo "<br /><span class='bold'><input type='checkbox' name='form_cb_$group_seq' value='1' " .
  270. "onclick='return divclick(this,\"div_$group_seq\");'";
  271. if ($display_style == 'block') echo " checked";
  272. echo " /><b>" . htmlspecialchars(xl_layout_label($group_name)) . "</b></span>\n";
  273. echo "<div id='div_$group_seq' class='section' style='display:$display_style;'>\n";
  274. }
  275. // echo " <table border='0' cellpadding='0' width='100%'>\n";
  276. echo " <table border='0' cellpadding='0' width='100%'>\n";
  277. $display_style = 'none';
  278. // Initialize historical data array and write date headers.
  279. $historical_ids = array();
  280. if ($formhistory > 0) {
  281. echo " <tr>";
  282. echo "<td colspan='$CPR' align='right' class='bold'>";
  283. if (empty($is_lbf)) echo htmlspecialchars(xl('Current'));
  284. echo "</td>\n";
  285. $hres = sqlStatement("SELECT date, form_id FROM forms WHERE " .
  286. "pid = '$pid' AND formdir = '$formname' AND " .
  287. "form_id != '$formid' AND deleted = 0 " .
  288. "ORDER BY date DESC LIMIT $formhistory");
  289. while ($hrow = sqlFetchArray($hres)) {
  290. $historical_ids[$hrow['form_id']] = '';
  291. echo "<td colspan='$CPR' align='right' class='bold'>&nbsp;" . $hrow['date'] . "</td>\n";
  292. // TBD: Format date per globals.
  293. }
  294. echo " </tr>";
  295. }
  296. }
  297. // Handle starting of a new row.
  298. if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
  299. end_row();
  300. echo " <tr>";
  301. // Clear historical data string.
  302. foreach ($historical_ids as $key => $dummy) {
  303. $historical_ids[$key] = '';
  304. }
  305. }
  306. if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
  307. // Handle starting of a new label cell.
  308. if ($titlecols > 0) {
  309. end_cell();
  310. echo "<td valign='top' colspan='$titlecols' width='1%' nowrap";
  311. echo " class='";
  312. echo ($frow['uor'] == 2) ? "required" : "bold";
  313. if ($graphable) echo " graph";
  314. echo "'";
  315. if ($cell_count == 2) echo " style='padding-left:10pt'";
  316. if ($graphable) echo " id='$field_id'";
  317. echo ">";
  318. foreach ($historical_ids as $key => $dummy) {
  319. $historical_ids[$key] .= "<td valign='top' colspan='$titlecols' class='text' nowrap>";
  320. }
  321. $cell_count += $titlecols;
  322. }
  323. ++$item_count;
  324. echo "<b>";
  325. if ($frow['title']) echo htmlspecialchars(xl_layout_label($frow['title']) . ":"); else echo "&nbsp;";
  326. echo "</b>";
  327. // Note the labels are not repeated in the history columns.
  328. // Handle starting of a new data cell.
  329. if ($datacols > 0) {
  330. end_cell();
  331. echo "<td valign='top' colspan='$datacols' class='text'";
  332. if ($cell_count > 0) echo " style='padding-left:5pt'";
  333. echo ">";
  334. foreach ($historical_ids as $key => $dummy) {
  335. $historical_ids[$key] .= "<td valign='top' align='right' colspan='$datacols' class='text'>";
  336. }
  337. $cell_count += $datacols;
  338. }
  339. ++$item_count;
  340. // Skip current-value fields for the display-only case.
  341. if (empty($is_lbf)) {
  342. if ($frow['edit_options'] == 'H')
  343. echo generate_display_field($frow, $currvalue);
  344. else
  345. generate_form_field($frow, $currvalue);
  346. }
  347. // Append to historical data of other dates for this item.
  348. foreach ($historical_ids as $key => $dummy) {
  349. $hvrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " .
  350. "form_id = '$key' AND field_id = '$field_id'");
  351. $value = empty($hvrow) ? '' : $hvrow['field_value'];
  352. $historical_ids[$key] .= generate_display_field($frow, $value);
  353. }
  354. }
  355. end_group();
  356. ?>
  357. <p style='text-align:center'>
  358. <?php if (empty($is_lbf)) { ?>
  359. <input type='submit' name='bn_save' value='<?php echo htmlspecialchars(xl('Save')) ?>' />
  360. &nbsp;
  361. <input type='button' value='<?php echo htmlspecialchars(xl('Cancel')) ?>' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
  362. &nbsp;
  363. <?php if ($form_is_graphable) { ?>
  364. <input type='button' value='<?php echo htmlspecialchars(xl('Show Graph')) ?>' onclick="top.restoreSession();location='../../patient_file/encounter/trend_form.php?formname=<?php echo $formname; ?>'" />
  365. &nbsp;
  366. <?php } ?>
  367. <?php } else { ?>
  368. <input type='button' value='<?php echo htmlspecialchars(xl('Back')) ?>' onclick='window.back();' />
  369. <?php } ?>
  370. </p>
  371. </form>
  372. <!-- include support for the list-add selectbox feature -->
  373. <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
  374. <script language="JavaScript">
  375. <?php echo $date_init; ?>
  376. <?php
  377. if (function_exists($formname . '_javascript_onload')) {
  378. call_user_func($formname . '_javascript_onload');
  379. }
  380. // TBD: If $alertmsg, display it with a JavaScript alert().
  381. ?>
  382. </script>
  383. </body>
  384. </html>