change eligibility batch from ssn to policy number, minor fix to filename with extra...
[openemr.git] / library / ajax / left_nav_encounter_ajax.php
blob17f267b86e9214bc2dde8707f76f326921224fac
1 <?php
2 // Copyright (C) 2011-2012 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 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.
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)) {
31 die("Error fetching issue $issue");
34 if ($createvisit) {
35 // Create a new encounter and give it a title of the issue title.
36 $thisenc = todaysEncounter($thispid, $irow['title']);
38 // If the encounter is not already linked to the specified issue, link it.
39 $tmp = sqlQuery(
40 "SELECT count(*) AS count FROM issue_encounter WHERE " .
41 "pid = ? AND list_id = ? AND encounter = ?",
42 array($thispid, $issue, $thisenc)
44 if (empty($tmp['count'])) {
45 sqlStatement(
46 "INSERT INTO issue_encounter " .
47 "( pid, list_id, encounter ) VALUES ( ?, ?, ? )",
48 array($thispid, $issue, $thisenc)
53 // alert('pid = <?php echo $pid; ?> thispid = <?php echo $thispid; ?>'); // debugging
55 top.restoreSession();
56 var enc = <?php echo $thisenc; ?>;
57 <?php
58 // If there is a followup function to call, call it.
59 $followup = $_REQUEST['followup'];
60 if (!empty($followup)) {
61 echo "$followup($thisenc)\n";
62 exit;
64 } // end if $createvisit
66 // If this is a new pid, switch to it. Cloned from demographics.php.
67 // Currently this will only happen from players_report.php, but we try to be general.
68 if ($pid != $thispid) {
69 include_once("$srcdir/pid.inc");
70 setpid($thispid);
71 $prow = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
73 // The JavaScript part of switching to the new pid. Cloned from demographics.php.
74 top.left_nav.setPatient(<?php echo "'" . addslashes(($prow['fname']) . " " . ($prow['lname'])) .
75 "'," . addslashes($pid) . ",'" . addslashes($prow['pubpid']) .
76 "','', ' " . xls('DOB') . ": " . addslashes(oeFormatShortDate($prow['DOB_YMD'])) . " " .
77 xls('Age') . ": " . addslashes(getPatientAge($prow['DOB_YMD'])) . "'"; ?>);
78 // TBD: ForceDual? Maybe load demographics.php into the top frame?
79 <?php
80 } // End of pid switch logic.
82 if ($createvisit) {
83 // Write JavaScript to open the selected encounter as the active encounter.
84 // Logic cloned from encounters.php.
86 top.left_nav.setEncounter('<?php echo $today; ?>', enc, 'RBot');
87 top.left_nav.loadFrame2('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc);
88 <?php
89 } else { // if not $createvisit
91 top.left_nav.loadFrame2('nen1','RBot','forms/newpatient/new.php?autoloaded=1&calenc=&issue=<?php echo $issue; ?>');
92 <?php
93 } // end not $createvisit