2 // Copyright (C) 2011-2012 Rod Roark <rod@sunsetsystems.com>
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 is an AJAX handler used either to open the New Encounter form or to
10 // create a new encounter dynamically. In either case an issue is linked to
11 // the new encounter. It is given an issue ID from which also serves to
12 // identify the patient, and if that patient is not the current patient then
13 // the current patient is switched to the new one.
15 $sanitize_all_escapes = true;
16 $fake_register_globals = false;
18 require_once("../../interface/globals.php");
19 require_once("$srcdir/forms.inc");
20 require_once("$srcdir/patient.inc");
21 require_once("$srcdir/encounter_events.inc.php");
23 $issue = $_GET['issue'];
24 $createvisit = !empty($_GET['createvisit']);
25 $today = date('Y-m-d');
27 $irow = sqlQuery("SELECT title, pid FROM lists WHERE id = ?", array($issue));
29 $thispid = $irow['pid'];
30 if (empty($thispid)) die("Error fetching issue $issue");
33 // Create a new encounter and give it a title of the issue title.
34 $thisenc = todaysEncounter($thispid, $irow['title']);
36 // If the encounter is not already linked to the specified issue, link it.
37 $tmp = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
38 "pid = ? AND list_id = ? AND encounter = ?",
39 array($thispid, $issue, $thisenc));
40 if (empty($tmp['count'])) {
41 sqlStatement("INSERT INTO issue_encounter " .
42 "( pid, list_id, encounter ) VALUES ( ?, ?, ? )",
43 array($thispid, $issue, $thisenc));
47 // alert('pid = <?php echo $pid; ?> thispid = <?php echo $thispid; ?>'); // debugging
50 var enc
= <?php
echo $thisenc; ?
>;
52 // If there is a followup function to call, call it.
53 $followup = $_REQUEST['followup'];
54 if (!empty($followup)) {
55 echo "$followup($thisenc)\n";
58 } // end if $createvisit
60 // If this is a new pid, switch to it. Cloned from demographics.php.
61 // Currently this will only happen from players_report.php, but we try to be general.
62 if ($pid != $thispid) {
63 include_once("$srcdir/pid.inc");
65 $prow = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
67 // The JavaScript part of switching to the new pid. Cloned from demographics.php.
68 top
.left_nav
.setPatient(<?php
echo "'" . addslashes(($prow['fname']) . " " . ($prow['lname'])) .
69 "'," . addslashes($pid) . ",'" . addslashes($prow['pubpid']) .
70 "','', ' " . xls('DOB') . ": " . addslashes(oeFormatShortDate($prow['DOB_YMD'])) . " " .
71 xls('Age') . ": " . addslashes(getPatientAge($prow['DOB_YMD'])) . "'"; ?
>);
72 // TBD: ForceDual? Maybe load demographics.php into the top frame?
74 } // End of pid switch logic.
77 // Write JavaScript to open the selected encounter as the active encounter.
78 // Logic cloned from encounters.php.
80 top
.left_nav
.setEncounter('<?php echo $today; ?>', enc
, 'RBot');
81 top
.left_nav
.loadFrame2('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc
);
84 else { // if not $createvisit
86 top
.left_nav
.loadFrame2('nen1','RBot','forms/newpatient/new.php?autoloaded=1&calenc=&issue=<?php echo $issue; ?>');
88 } // end not $createvisit