acknowledgments update
[openemr.git] / interface / forms / newpatient / save.php
blob69be40f8aa2e34b4a109c339293ac50795cf6bfc
1 <?php
2 /**
3 * Encounter form save script.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Brady Miller <brady@sparmy.com>
18 * @link http://www.open-emr.org
21 $fake_register_globals=false;
22 $sanitize_all_escapes=true;
24 require_once("../../globals.php");
25 require_once("$srcdir/forms.inc");
26 require_once("$srcdir/sql.inc");
27 require_once("$srcdir/encounter.inc");
28 require_once("$srcdir/acl.inc");
29 require_once("$srcdir/formatting.inc.php");
30 require_once("$srcdir/formdata.inc.php");
32 $date = (isset($_POST['form_date'])) ? $_POST['form_date'] : '';
33 $onset_date = (isset($_POST['form_onset_date'])) ? $_POST['form_onset_date'] : '';
34 $sensitivity = (isset($_POST['form_sensitivity'])) ? $_POST['form_sensitivity'] : '';
35 $pc_catid = (isset($_POST['pc_catid'])) ? $_POST['pc_catid'] : '';
36 $facility_id = (isset($_POST['facility_id'])) ? $_POST['facility_id'] : '';
37 $billing_facility = (isset($_POST['billing_facility'])) ? $_POST['billing_facility'] : '';
38 $reason = (isset($_POST['reason'])) ? $_POST['reason'] : '';
39 $mode = (isset($_POST['mode'])) ? $_POST['mode'] : '';
40 $referral_source = (isset($_POST['form_referral_source'])) ? $_POST['form_referral_source'] : '';
42 $facilityresult = sqlQuery("select name FROM facility WHERE id = ?", array($facility_id));
43 $facility = $facilityresult['name'];
45 if ($GLOBALS['concurrent_layout'])
46 $normalurl = "patient_file/encounter/encounter_top.php";
47 else
48 $normalurl = "$rootdir/patient_file/encounter/patient_encounter.php";
50 $nexturl = $normalurl;
52 if ($mode == 'new')
54 $provider_id = $userauthorized ? $_SESSION['authUserID'] : 0;
55 $encounter = generate_id();
56 addForm($encounter, "New Patient Encounter",
57 sqlInsert("INSERT INTO form_encounter SET " .
58 "date = '" . add_escape_custom($date) . "', " .
59 "onset_date = '" . add_escape_custom($onset_date) . "', " .
60 "reason = '" . add_escape_custom($reason) . "', " .
61 "facility = '" . add_escape_custom($facility) . "', " .
62 "pc_catid = '" . add_escape_custom($pc_catid) . "', " .
63 "facility_id = '" . add_escape_custom($facility_id) . "', " .
64 "billing_facility = '" . add_escape_custom($billing_facility) . "', " .
65 "sensitivity = '" . add_escape_custom($sensitivity) . "', " .
66 "referral_source = '" . add_escape_custom($referral_source) . "', " .
67 "pid = '" . add_escape_custom($pid) . "', " .
68 "encounter = '" . add_escape_custom($encounter) . "', " .
69 "provider_id = '" . add_escape_custom($provider_id) . "'"),
70 "newpatient", $pid, $userauthorized, $date);
72 else if ($mode == 'update')
74 $id = $_POST["id"];
75 $result = sqlQuery("SELECT encounter, sensitivity FROM form_encounter WHERE id = ?", array($id));
76 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
77 die(xlt("You are not authorized to see this encounter."));
79 $encounter = $result['encounter'];
80 // See view.php to allow or disallow updates of the encounter date.
81 $datepart = acl_check('encounters', 'date_a') ? "date = '" . add_escape_custom($date) . "', " : "";
82 sqlStatement("UPDATE form_encounter SET " .
83 $datepart .
84 "onset_date = '" . add_escape_custom($onset_date) . "', " .
85 "reason = '" . add_escape_custom($reason) . "', " .
86 "facility = '" . add_escape_custom($facility) . "', " .
87 "pc_catid = '" . add_escape_custom($pc_catid) . "', " .
88 "facility_id = '" . add_escape_custom($facility_id) . "', " .
89 "billing_facility = '" . add_escape_custom($billing_facility) . "', " .
90 "sensitivity = '" . add_escape_custom($sensitivity) . "', " .
91 "referral_source = '" . add_escape_custom($referral_source) . "' " .
92 "WHERE id = '" . add_escape_custom($id) . "'");
94 else {
95 die("Unknown mode '" . text($mode) . "'");
98 setencounter($encounter);
100 // Update the list of issues associated with this encounter.
101 sqlStatement("DELETE FROM issue_encounter WHERE " .
102 "pid = ? AND encounter = ?", array($pid,$encounter) );
103 if (is_array($_POST['issues'])) {
104 foreach ($_POST['issues'] as $issue) {
105 $query = "INSERT INTO issue_encounter ( pid, list_id, encounter ) VALUES (?,?,?)";
106 sqlStatement($query, array($pid,$issue,$encounter));
110 // Custom for Chelsea FC.
112 if ($mode == 'new' && $GLOBALS['default_new_encounter_form'] == 'football_injury_audit') {
114 // If there are any "football injury" issues (medical problems without
115 // "illness" in the title) linked to this encounter, but no encounter linked
116 // to such an issue has the injury form in it, then present that form.
118 $lres = sqlStatement("SELECT list_id " .
119 "FROM issue_encounter, lists WHERE " .
120 "issue_encounter.pid = ? AND " .
121 "issue_encounter.encounter = ? AND " .
122 "lists.id = issue_encounter.list_id AND " .
123 "lists.type = 'medical_problem' AND " .
124 "lists.title NOT LIKE '%Illness%'", array($pid,$encounter));
126 if (sqlNumRows($lres) > 0) {
127 $nexturl = "patient_file/encounter/load_form.php?formname=" .
128 $GLOBALS['default_new_encounter_form'];
129 while ($lrow = sqlFetchArray($lres)) {
130 $frow = sqlQuery("SELECT count(*) AS count " .
131 "FROM issue_encounter, forms WHERE " .
132 "issue_encounter.list_id = ? AND " .
133 "forms.pid = issue_encounter.pid AND " .
134 "forms.encounter = issue_encounter.encounter AND " .
135 "forms.formdir = ?", array($lrow['list_id'],$GLOBALS['default_new_encounter_form']));
136 if ($frow['count']) $nexturl = $normalurl;
140 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
141 " left join openemr_postcalendar_categories on fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = ? order by fe.date desc", array($pid));
143 <html>
144 <body>
145 <script language='JavaScript'>
146 <?php if ($GLOBALS['concurrent_layout'])
147 {//Encounter details are stored to javacript as array.
149 EncounterDateArray=new Array;
150 CalendarCategoryArray=new Array;
151 EncounterIdArray=new Array;
152 Count=0;
153 <?php
154 if(sqlNumRows($result4)>0)
155 while($rowresult4 = sqlFetchArray($result4))
158 EncounterIdArray[Count]='<?php echo attr($rowresult4['encounter']); ?>';
159 EncounterDateArray[Count]='<?php echo attr(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date'])))); ?>';
160 CalendarCategoryArray[Count]='<?php echo attr(xl_appt_category($rowresult4['pc_catname'])); ?>';
161 Count++;
162 <?php
165 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray,EncounterDateArray,CalendarCategoryArray);
166 <?php } ?>
167 top.restoreSession();
168 <?php if ($GLOBALS['concurrent_layout']) { ?>
169 <?php if ($mode == 'new') { ?>
170 parent.left_nav.setEncounter(<?php echo "'" . oeFormatShortDate($date) . "', " . attr($encounter) . ", window.name"; ?>);
171 parent.left_nav.setRadio(window.name, 'enc');
172 <?php } // end if new encounter ?>
173 parent.left_nav.loadFrame('enc2', window.name, '<?php echo $nexturl; ?>');
174 <?php } else { // end if concurrent layout ?>
175 window.location="<?php echo $nexturl; ?>";
176 <?php } // end not concurrent layout ?>
177 </script>
179 </body>
180 </html>