From 0a698dfeca1122a3d1394fc7b5e3a88a9e833c7c Mon Sep 17 00:00:00 2001 From: sunsetsystems Date: Tue, 5 Dec 2006 22:32:07 +0000 Subject: [PATCH] added auto-create of new encounter when patient arrives --- interface/globals.php | 4 ++++ interface/main/calendar/add_edit_event.php | 34 ++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/interface/globals.php b/interface/globals.php index 572ff7904..43d0e3548 100644 --- a/interface/globals.php +++ b/interface/globals.php @@ -167,6 +167,10 @@ $GLOBALS['default_chief_complaint'] = ''; // have other applications. $GLOBALS['default_new_encounter_form'] = ''; +// If you want a new encounter to be automatically created when appointment +// status is set to "@" (arrived), then make this true. +$GLOBALS['auto_create_new_encounters'] = true; + // If you want Hylafax support then uncomment and customize the following // statements, and also customize custom/faxcover.txt: // diff --git a/interface/main/calendar/add_edit_event.php b/interface/main/calendar/add_edit_event.php index d9f389b0c..9e9ee9c2d 100644 --- a/interface/main/calendar/add_edit_event.php +++ b/interface/main/calendar/add_edit_event.php @@ -22,6 +22,7 @@ include_once("../../globals.php"); include_once("$srcdir/patient.inc"); + include_once("$srcdir/forms.inc"); // Things that might be passed by our opener. // @@ -56,6 +57,8 @@ // if ($_POST['form_save']) { + $event_date = fixDate($_POST['form_date']); + // Compute start and end time strings to be saved. if ($_POST['form_allday']) { $tmph = 0; @@ -107,7 +110,7 @@ "pc_time = NOW(), " . "pc_hometext = '" . $_POST['form_comments'] . "', " . "pc_informant = '" . $_SESSION['authUserID'] . "', " . - "pc_eventDate = '" . fixDate($_POST['form_date']) . "', " . + "pc_eventDate = '" . $event_date . "', " . "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " . "pc_duration = '" . ($duration * 60) . "', " . "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " . @@ -132,7 +135,7 @@ "NOW(), " . "'" . $_POST['form_comments'] . "', " . "'" . $_SESSION['authUserID'] . "', " . - "'" . fixDate($_POST['form_date']) . "', " . + "'" . $event_date . "', " . "'" . fixDate($_POST['form_enddate']) . "', " . "'" . ($duration * 60) . "', " . "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " . @@ -154,6 +157,33 @@ "pid = '" . $_POST['form_pid'] . "'"); } + // Auto-create a new encounter if appropriate. + // + if ($GLOBALS['auto_create_new_encounters'] && + $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d')) + { + $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . + "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'"); + if ($tmprow['count'] == 0) { + $tmprow = sqlQuery("SELECT facility FROM users WHERE username = '" . + $_SESSION['authUser'] . "'"); + $facility = $tmprow['facility']; + $conn = $GLOBALS['adodb']['db']; + $encounter = $conn->GenID("sequences"); + addForm($encounter, "New Patient Encounter", + sqlInsert("INSERT INTO form_encounter SET " . + "date = '$event_date', " . + "onset_date = '$event_date', " . + "reason = '" . $_POST['form_comments'] . "', " . + "facility = '$facility', " . + "pid = '" . $_POST['form_pid'] . "', " . + "encounter = '$encounter'"), + "newpatient", $_POST['form_pid'], $userauthorized + ); + $info_msg .= "New encounter $encounter was created. "; + } + } + } else if ($_POST['form_delete']) { sqlStatement("DELETE FROM openemr_postcalendar_events WHERE " . -- 2.11.4.GIT