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");
14 foreach ($_POST as $k => $var) {
15 if (! is_array($var)) $_POST[$k] = mysql_escape_string($var);
19 $conn = $GLOBALS['adodb']['db'];
21 // $date = $_POST["year"]."-".$_POST["month"]."-".$_POST["day"];
22 // $onset_date = $_POST["onset_year"]."-".$_POST["onset_month"]."-".$_POST["onset_day"];
24 $date = $_POST['form_date'];
25 $onset_date = $_POST['form_onset_date'];
26 $sensitivity = $_POST['form_sensitivity'];
27 $pc_catid = $_POST['pc_catid'];
28 $facility_id = $_POST['facility_id'];
29 $reason = $_POST['reason'];
30 $mode = $_POST['mode'];
31 $referral_source = $_POST['form_referral_source'];
33 $facilityresult = sqlQuery("select name FROM facility WHERE id = $facility_id");
34 $facility = $facilityresult['name'];
36 if ($GLOBALS['concurrent_layout'])
37 $normalurl = "patient_file/encounter/encounter_top.php";
39 $normalurl = "$rootdir/patient_file/encounter/patient_encounter.php";
41 $nexturl = $normalurl;
45 $provider_id = $userauthorized ?
$_SESSION['authUserID'] : 0;
46 $encounter = $conn->GenID("sequences");
47 addForm($encounter, "New Patient Encounter",
48 sqlInsert("INSERT INTO form_encounter SET " .
50 "onset_date = '$onset_date', " .
51 "reason = '$reason', " .
52 "facility = '$facility', " .
53 "pc_catid = '$pc_catid', " .
54 "facility_id = '$facility_id', " .
55 "sensitivity = '$sensitivity', " .
56 "referral_source = '$referral_source', " .
58 "encounter = '$encounter', " .
59 "provider_id = '$provider_id'"),
60 "newpatient", $pid, $userauthorized, $date);
62 else if ($mode == 'update')
65 $result = sqlQuery("SELECT encounter, sensitivity FROM form_encounter WHERE id = '$id'");
66 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
67 die("You are not authorized to see this encounter.");
69 $encounter = $result['encounter'];
70 // See view.php to allow or disallow updates of the encounter date.
71 // $datepart = $_POST["day"] ? "date = '$date', " : "";
72 $datepart = acl_check('encounters', 'date_a') ?
"date = '$date', " : "";
73 sqlStatement("UPDATE form_encounter SET " .
75 "onset_date = '$onset_date', " .
76 "reason = '$reason', " .
77 "facility = '$facility', " .
78 "pc_catid = '$pc_catid', " .
79 "facility_id = '$facility_id', " .
80 "sensitivity = '$sensitivity', " .
81 "referral_source = '$referral_source' " .
85 die("Unknown mode '$mode'");
88 setencounter($encounter);
90 // Update the list of issues associated with this encounter.
91 sqlStatement("DELETE FROM issue_encounter WHERE " .
92 "pid = '$pid' AND encounter = '$encounter'");
93 if (is_array($_POST['issues'])) {
94 foreach ($_POST['issues'] as $issue) {
95 $query = "INSERT INTO issue_encounter ( " .
96 "pid, list_id, encounter " .
98 "'$pid', '$issue', '$encounter'" .
100 sqlStatement($query);
104 // Custom for Chelsea FC.
106 if ($mode == 'new' && $GLOBALS['default_new_encounter_form'] == 'football_injury_audit') {
108 // If there are any "football injury" issues (medical problems without
109 // "illness" in the title) linked to this encounter, but no encounter linked
110 // to such an issue has the injury form in it, then present that form.
112 $lres = sqlStatement("SELECT list_id " .
113 "FROM issue_encounter, lists WHERE " .
114 "issue_encounter.pid = '$pid' AND " .
115 "issue_encounter.encounter = '$encounter' AND " .
116 "lists.id = issue_encounter.list_id AND " .
117 "lists.type = 'medical_problem' AND " .
118 "lists.title NOT LIKE '%Illness%'");
120 if (mysql_num_rows($lres)) {
121 $nexturl = "patient_file/encounter/load_form.php?formname=" .
122 $GLOBALS['default_new_encounter_form'];
123 while ($lrow = sqlFetchArray($lres)) {
124 $frow = sqlQuery("SELECT count(*) AS count " .
125 "FROM issue_encounter, forms WHERE " .
126 "issue_encounter.list_id = '" . $lrow['list_id'] . "' AND " .
127 "forms.pid = issue_encounter.pid AND " .
128 "forms.encounter = issue_encounter.encounter AND " .
129 "forms.formdir = '" . $GLOBALS['default_new_encounter_form'] . "'");
130 if ($frow['count']) $nexturl = $normalurl;
134 $result4 = sqlStatement("SELECT fe.encounter,fe.date,openemr_postcalendar_categories.pc_catname FROM form_encounter AS fe ".
135 " left join openemr_postcalendar_categories on fe.pc_catid=openemr_postcalendar_categories.pc_catid WHERE fe.pid = '$pid' order by fe.date desc");
139 <script language
='JavaScript'>
140 <?php
if ($GLOBALS['concurrent_layout'])
141 {//Encounter details are stored to javacript as array.
143 EncounterDateArray
=new Array;
144 CalendarCategoryArray
=new Array;
145 EncounterIdArray
=new Array;
148 if(sqlNumRows($result4)>0)
149 while($rowresult4 = sqlFetchArray($result4))
152 EncounterIdArray
[Count
]='<?php echo htmlspecialchars($rowresult4['encounter
'], ENT_QUOTES); ?>';
153 EncounterDateArray
[Count
]='<?php echo htmlspecialchars(oeFormatShortDate(date("Y-m-d", strtotime($rowresult4['date
']))), ENT_QUOTES); ?>';
154 CalendarCategoryArray
[Count
]='<?php echo htmlspecialchars( xl_appt_category($rowresult4['pc_catname
']), ENT_QUOTES); ?>';
159 top
.window
.parent
.left_nav
.setPatientEncounter(EncounterIdArray
,EncounterDateArray
,CalendarCategoryArray
);
161 top
.restoreSession();
162 <?php
if ($GLOBALS['concurrent_layout']) { ?
>
163 <?php
if ($mode == 'new') { ?
>
164 parent
.left_nav
.setEncounter(<?php
echo "'" . oeFormatShortDate($date) . "', $encounter, window.name"; ?
>);
165 parent
.left_nav
.setRadio(window
.name
, 'enc');
166 <?php
} // end if new encounter ?>
167 parent
.left_nav
.loadFrame('enc2', window
.name
, '<?php echo $nexturl; ?>');
168 <?php
} else { // end if concurrent layout ?>
169 window
.location
="<?php echo $nexturl; ?>";
170 <?php
} // end not concurrent layout ?>