minor improvement to the fee sheet search code drop down
[openemr.git] / interface / forms / newpatient / save.php
blob8446d50d0e797b2752628a4044a464fff80d7a25
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once("../../globals.php");
8 require_once("$srcdir/forms.inc");
9 require_once("$srcdir/sql.inc");
10 require_once("$srcdir/encounter.inc");
11 require_once("$srcdir/acl.inc");
12 require_once("$srcdir/formatting.inc.php");
13 require_once("$srcdir/formdata.inc.php");
15 $conn = $GLOBALS['adodb']['db'];
17 $date = formData('form_date');
18 $onset_date = formData('form_onset_date');
19 $sensitivity = formData('form_sensitivity');
20 $pc_catid = formData('pc_catid');
21 $facility_id = formData('facility_id');
22 $billing_facility = formData('billing_facility');
23 $reason = formData('reason');
24 $mode = formData('mode');
25 $referral_source = formData('form_referral_source');
27 $facilityresult = sqlQuery("select name FROM facility WHERE id = $facility_id");
28 $facility = $facilityresult['name'];
30 if ($GLOBALS['concurrent_layout'])
31 $normalurl = "patient_file/encounter/encounter_top.php";
32 else
33 $normalurl = "$rootdir/patient_file/encounter/patient_encounter.php";
35 $nexturl = $normalurl;
37 if ($mode == 'new')
39 $provider_id = $userauthorized ? $_SESSION['authUserID'] : 0;
40 $encounter = $conn->GenID("sequences");
41 addForm($encounter, "New Patient Encounter",
42 sqlInsert("INSERT INTO form_encounter SET " .
43 "date = '$date', " .
44 "onset_date = '$onset_date', " .
45 "reason = '$reason', " .
46 "facility = '" . add_escape_custom($facility) . "', " .
47 "pc_catid = '$pc_catid', " .
48 "facility_id = '$facility_id', " .
49 "billing_facility = '$billing_facility', " .
50 "sensitivity = '$sensitivity', " .
51 "referral_source = '$referral_source', " .
52 "pid = '$pid', " .
53 "encounter = '$encounter', " .
54 "provider_id = '$provider_id'"),
55 "newpatient", $pid, $userauthorized, $date);
57 else if ($mode == 'update')
59 $id = $_POST["id"];
60 $result = sqlQuery("SELECT encounter, sensitivity FROM form_encounter WHERE id = '$id'");
61 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
62 die("You are not authorized to see this encounter.");
64 $encounter = $result['encounter'];
65 // See view.php to allow or disallow updates of the encounter date.
66 $datepart = acl_check('encounters', 'date_a') ? "date = '$date', " : "";
67 sqlStatement("UPDATE form_encounter SET " .
68 $datepart .
69 "onset_date = '$onset_date', " .
70 "reason = '$reason', " .
71 "facility = '$facility', " .
72 "pc_catid = '$pc_catid', " .
73 "facility_id = '$facility_id', " .
74 "billing_facility = '$billing_facility', " .
75 "sensitivity = '$sensitivity', " .
76 "referral_source = '$referral_source' " .
77 "WHERE id = '$id'");
79 else {
80 die("Unknown mode '$mode'");
83 setencounter($encounter);
85 // Update the list of issues associated with this encounter.
86 sqlStatement("DELETE FROM issue_encounter WHERE " .
87 "pid = '$pid' AND encounter = '$encounter'");
88 if (is_array($_POST['issues'])) {
89 foreach ($_POST['issues'] as $issue) {
90 $query = "INSERT INTO issue_encounter ( " .
91 "pid, list_id, encounter " .
92 ") VALUES ( " .
93 "'$pid', '$issue', '$encounter'" .
94 ")";
95 sqlStatement($query);
99 // Custom for Chelsea FC.
101 if ($mode == 'new' && $GLOBALS['default_new_encounter_form'] == 'football_injury_audit') {
103 // If there are any "football injury" issues (medical problems without
104 // "illness" in the title) linked to this encounter, but no encounter linked
105 // to such an issue has the injury form in it, then present that form.
107 $lres = sqlStatement("SELECT list_id " .
108 "FROM issue_encounter, lists WHERE " .
109 "issue_encounter.pid = '$pid' AND " .
110 "issue_encounter.encounter = '$encounter' AND " .
111 "lists.id = issue_encounter.list_id AND " .
112 "lists.type = 'medical_problem' AND " .
113 "lists.title NOT LIKE '%Illness%'");
115 if (mysql_num_rows($lres)) {
116 $nexturl = "patient_file/encounter/load_form.php?formname=" .
117 $GLOBALS['default_new_encounter_form'];
118 while ($lrow = sqlFetchArray($lres)) {
119 $frow = sqlQuery("SELECT count(*) AS count " .
120 "FROM issue_encounter, forms WHERE " .
121 "issue_encounter.list_id = '" . $lrow['list_id'] . "' AND " .
122 "forms.pid = issue_encounter.pid AND " .
123 "forms.encounter = issue_encounter.encounter AND " .
124 "forms.formdir = '" . $GLOBALS['default_new_encounter_form'] . "'");
125 if ($frow['count']) $nexturl = $normalurl;
129 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
130 " left join openemr_postcalendar_categories on fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = '$pid' order by fe.date desc");
132 <html>
133 <body>
134 <script language='JavaScript'>
135 <?php if ($GLOBALS['concurrent_layout'])
136 {//Encounter details are stored to javacript as array.
138 EncounterDateArray=new Array;
139 CalendarCategoryArray=new Array;
140 EncounterIdArray=new Array;
141 Count=0;
142 <?php
143 if(sqlNumRows($result4)>0)
144 while($rowresult4 = sqlFetchArray($result4))
147 EncounterIdArray[Count]='<?php echo htmlspecialchars($rowresult4['encounter'], ENT_QUOTES); ?>';
148 EncounterDateArray[Count]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date']))), ENT_QUOTES); ?>';
149 CalendarCategoryArray[Count]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname']), ENT_QUOTES); ?>';
150 Count++;
151 <?php
154 top.window.parent.left_nav.setPatientEncounter(EncounterIdArray,EncounterDateArray,CalendarCategoryArray);
155 <?php } ?>
156 top.restoreSession();
157 <?php if ($GLOBALS['concurrent_layout']) { ?>
158 <?php if ($mode == 'new') { ?>
159 parent.left_nav.setEncounter(<?php echo "'" . oeFormatShortDate($date) . "', $encounter, window.name"; ?>);
160 parent.left_nav.setRadio(window.name, 'enc');
161 <?php } // end if new encounter ?>
162 parent.left_nav.loadFrame('enc2', window.name, '<?php echo $nexturl; ?>');
163 <?php } else { // end if concurrent layout ?>
164 window.location="<?php echo $nexturl; ?>";
165 <?php } // end not concurrent layout ?>
166 </script>
168 </body>
169 </html>