Some corrections specific to athletic teams concerning creation of new encounters.
[openemr.git] / library / ajax / left_nav_encounter_ajax.php
blob33b169b491e589cd91683fdfbf311ddd5f0621ee
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.
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/formatting.inc.php");
22 require_once("$srcdir/encounter_events.inc.php");
24 $issue = $_GET['issue'];
25 $createvisit = !empty($_GET['createvisit']);
26 $today = date('Y-m-d');
28 $irow = sqlQuery("SELECT title, pid FROM lists WHERE id = ?", array($issue));
30 $thispid = $irow['pid'];
31 if (empty($thispid)) die("Error fetching issue $issue");
33 if ($createvisit) {
34 // Create a new encounter and give it a title of the issue title.
35 $thisenc = todaysEncounter($thispid, $irow['title']);
37 // If the encounter is not already linked to the specified issue, link it.
38 $tmp = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " .
39 "pid = ? AND list_id = ? AND encounter = ?",
40 array($thispid, $issue, $thisenc));
41 if (empty($tmp['count'])) {
42 sqlStatement("INSERT INTO issue_encounter " .
43 "( pid, list_id, encounter ) VALUES ( ?, ?, ? )",
44 array($thispid, $issue, $thisenc));
48 // alert('pid = <?php echo $pid; ?> thispid = <?php echo $thispid; ?>'); // debugging
50 top.restoreSession();
51 var enc = <?php echo $thisenc; ?>;
52 <?php
53 // If there is a followup function to call, call it.
54 $followup = $_REQUEST['followup'];
55 if (!empty($followup)) {
56 echo "$followup($thisenc)\n";
57 exit;
59 } // end if $createvisit
61 // If this is a new pid, switch to it. Cloned from demographics.php.
62 // Currently this will only happen from players_report.php, but we try to be general.
63 if ($pid != $thispid) {
64 include_once("$srcdir/pid.inc");
65 setpid($thispid);
66 $prow = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
68 // The JavaScript part of switching to the new pid. Cloned from demographics.php.
69 top.left_nav.setPatient(<?php echo "'" . htmlspecialchars(($prow['fname']) . " " . ($prow['lname']),ENT_QUOTES) .
70 "'," . htmlspecialchars($pid,ENT_QUOTES) . ",'" . htmlspecialchars(($prow['pubpid']),ENT_QUOTES) .
71 "','', ' " . htmlspecialchars(xl('DOB') . ": " . oeFormatShortDate($prow['DOB_YMD']) . " " .
72 xl('Age') . ": " . getPatientAge($prow['DOB_YMD']), ENT_QUOTES) . "'"; ?>);
73 // TBD: ForceDual? Maybe load demographics.php into the top frame?
74 <?php
75 } // End of pid switch logic.
77 if ($createvisit) {
78 // Write JavaScript to open the selected encounter as the active encounter.
79 // Logic cloned from encounters.php.
80 if ($GLOBALS['concurrent_layout']) {
82 top.left_nav.setEncounter('<?php echo $today; ?>', enc, 'RBot');
83 top.left_nav.setRadio('RBot', 'enc');
84 top.left_nav.loadFrame2('enc2', 'RBot', 'patient_file/encounter/encounter_top.php?set_encounter=' + enc);
85 <?php
87 else {
89 top.Title.location.href = '../encounter/encounter_title.php?set_encounter=' + enc;
90 top.Main.location.href = '../encounter/patient_encounter.php?set_encounter=' + enc;
91 <?php
94 else { // if not $createvisit
95 if ($GLOBALS['concurrent_layout']) {
97 top.left_nav.loadFrame2('nen1','RBot','forms/newpatient/new.php?autoloaded=1&calenc=&issue=<?php echo $issue; ?>');
98 <?php
100 else {
102 // This case should not happen.
103 <?php
105 } // end not $createvisit