adding ubuntu cvs development package scripts with other pieces
[openemr.git] / custom / LBF / LBFgcac.plugin.php
blob5a0c4be211fd0e38a60a47eb8d917232c0dfe258
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 // This provides enhancement functions for the LBFgcac visit form.
10 // It is invoked by interface/forms/LBF/new.php.
12 // Private function. Constructs a query to find a given lbf_data field's
13 // values from visits within the past 2 weeks.
15 function _LBFgcac_query_recent($more) {
16 global $pid, $encounter, $formname, $formid;
18 // Get the date of this visit.
19 $encrow = sqlQuery("SELECT date FROM form_encounter WHERE " .
20 "pid = '$pid' AND encounter = '$encounter'");
21 $encdate = $encrow['date'];
23 // Query complications from the two weeks prior to this visit.
24 $query = "SELECT d.field_value " .
25 "FROM forms AS f, form_encounter AS fe, lbf_data AS d " .
26 "WHERE f.pid = '$pid' AND " .
27 "f.formdir = '$formname' AND " .
28 "f.deleted = 0 AND " .
29 "fe.pid = f.pid AND fe.encounter = f.encounter AND " .
30 "fe.date <= '$encdate' AND " .
31 "DATE_ADD(fe.date, INTERVAL 14 DAY) > '$encdate' AND " .
32 "d.form_id = f.form_id AND $more";
34 return $query;
37 // Private function. Given a field name, gets its value from the most
38 // recent instance of this form type that is not more than 2 weeks old.
40 function _LBFgcac_recent_default($name) {
41 global $formid;
43 // This logic only makes sense for a new form.
44 if ($formid) return '';
46 $query = _LBFgcac_query_recent(
47 "d.field_id = '$name' " .
48 "ORDER BY f.form_id DESC LIMIT 1");
49 $row = sqlQuery($query);
51 if (empty($row['field_value'])) return '';
52 return $row['field_value'];
55 // The purpose of this function is to create JavaScript for the <head>
56 // section of the page. This in turn defines desired javaScript
57 // functions.
59 function LBFgcac_javascript() {
60 global $formid;
62 // Query complications from the two weeks prior to this visit.
63 $res = sqlStatement(_LBFgcac_query_recent(
64 "f.form_id != '$formid' AND " .
65 "d.field_id = 'complications'"));
67 // This JavaScript function is to enable items in the "Main complications"
68 // list that have been selected, and to disable all others.
69 // Option.disabled seems to work for Firefox 3 and IE8 but not IE6.
70 echo "// Enable recent complications and disable all others.
71 function set_main_compl_list() {
72 var f = document.forms[0];
73 var sel = f.form_main_compl;
74 var n = '';
76 // We use the checkbox object values as a scratch area to note which
77 // complications were already selected from other forms.
78 while ($row = sqlFetchArray($res)) {
79 $a = explode('|', $row['field_value']);
80 foreach ($a as $complid) {
81 if (empty($complid)) continue;
82 echo " n = 'form_complications[$complid]'; if (f[n]) f[n].value = 2;\n";
85 echo " // Scan the list items and set their disabled flags.
86 for (var i = 1; i < sel.options.length; ++i) {
87 n = 'form_complications[' + sel.options[i].value + ']';
88 sel.options[i].disabled = (f[n] && (f[n].checked || f[n].value == '2')) ? false : true;
92 echo "
93 // Disable most form fields if refusing abortion.
94 function client_status_changed() {
95 var f = document.forms[0];
96 var sel = f.form_client_status;
97 var dis = sel.selectedIndex >= 0 && sel.options[sel.selectedIndex].value == 'mara';
98 for (var i = 0; i < f.elements.length; ++i) {
99 var e = f.elements[i];
100 if (
101 e.name.substring(0,18) == 'form_complications' ||
102 e.name.substring(0,15) == 'form_contrameth' ||
103 e.name == 'form_ab_location' ||
104 e.name == 'form_in_ab_proc' ||
105 e.name == 'form_main_compl'
107 e.disabled = dis;
115 // The purpose of this function is to create JavaScript that is run
116 // once when the page is loaded.
118 function LBFgcac_javascript_onload() {
119 echo "
120 set_main_compl_list();
121 client_status_changed();
122 var f = document.forms[0];
123 for (var i = 0; i < f.elements.length; ++i) {
124 var e = f.elements[i];
125 if (e.name.substring(0,18) == 'form_complications')
126 e.onclick = function () { set_main_compl_list(); };
128 f.form_client_status.onchange = function () { client_status_changed(); };
132 // Generate default for client status.
134 function LBFgcac_default_client_status() {
135 return _LBFgcac_recent_default('client_status');
138 // Generate default for visit type. If there are no recent prior visits,
139 // then default to new procedure.
141 function LBFgcac_default_ab_location() {
142 global $formid;
143 if ($formid) return '';
144 $vt = _LBFgcac_recent_default('ab_location');
145 if (empty($vt)) return 'proc';
146 return $vt;
149 // Generate default for the induced procedure type.
151 function LBFgcac_default_in_ab_proc() {
152 return _LBFgcac_recent_default('in_ab_proc');
155 // Generate default for the main complication.
157 function LBFgcac_default_main_compl() {
158 return _LBFgcac_recent_default('main_compl');