Skip to content

Commit

Permalink
separating facility from user maintenance, improved support for multi…
Browse files Browse the repository at this point in the history
…ple facilities from Bill Himmelstoss, and a bit of cleanup
  • Loading branch information
sunsetsystems committed Jul 14, 2009
1 parent cbdd0d6 commit ef6a8b5
Show file tree
Hide file tree
Showing 25 changed files with 560 additions and 265 deletions.
4 changes: 4 additions & 0 deletions interface/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@
// Everyone should want this, but for now it's optional.
$GLOBALS['full_new_patient_form'] = true;

// Restrict non-authorized users to the "Schedule Facilities" (aka user_facilities table)
// set in User admin.
$GLOBALS['restrict_user_facility'] = false;

// If you want Hylafax support then uncomment and customize the following
// statements, and also customize custom/faxcover.txt:
//
Expand Down
74 changes: 71 additions & 3 deletions interface/main/calendar/add_edit_event.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ function InsertEvent($args) {
FROM openemr_postcalendar_events
LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
WHERE pc_eid = $eid");
if ( !$facility['pc_facility'] ) {
// if ( !$facility['pc_facility'] ) {
if ( is_array($facility) && !$facility['pc_facility'] ) {
$qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
$min = $qmin['minId'];
$min_name = $qmin['facility'];
Expand All @@ -161,8 +162,13 @@ function InsertEvent($args) {
$e2f = $min;
$e2f_name = $min_name;
} else {
// not edit event
if (!$facility['pc_facility'] && ($_SESSION['pc_facility'] || $_COOKIE['pc_facility'])) {
$e2f = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $_COOKIE['pc_facility'];
} else {
$e2f = $facility['pc_facility'];
$e2f_name = $facility['name'];
}
}
}
// EOS E2F
Expand Down Expand Up @@ -640,7 +646,9 @@ function InsertEvent($args) {
$_POST['form_provider'] . "'");
$username = $tmprow['username'];
$facility = $tmprow['facility'];
$facility_id = $tmprow['facility_id'];
// $facility_id = $tmprow['facility_id'];
// use the session facility if it is set, otherwise the one from the provider.
$facility_id = $_SESSION['pc_facility'] ? $_SESSION['pc_facility'] : $tmprow['facility_id'];
$conn = $GLOBALS['adodb']['db'];
$encounter = $conn->GenID("sequences");
addForm($encounter, "New Patient Encounter",
Expand All @@ -649,7 +657,8 @@ function InsertEvent($args) {
"onset_date = '$event_date', " .
"reason = '" . $_POST['form_comments'] . "', " .
"facility = '$facility', " .
"facility_id = '$facility_id', " .
// "facility_id = '$facility_id', " .
"facility_id = '" . (int)$_POST['facility'] . "', " .
"pid = '" . $_POST['form_pid'] . "', " .
"encounter = '$encounter'"
),
Expand Down Expand Up @@ -828,7 +837,28 @@ function InsertEvent($args) {
//(CHEMED)
//Set default facility for a new event based on the given 'userid'
if ($userid) {
/*************************************************************
$pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
*************************************************************/
if ($_SESSION['pc_facility']) {
$pref_facility = sqlFetchArray(sqlStatement(sprintf("
SELECT f.id as facility_id,
f.name as facility
FROM facility f
WHERE f.id = %d
",
$_SESSION['pc_facility']
)));
} else {
$pref_facility = sqlFetchArray(sqlStatement("
SELECT u.facility_id,
f.name as facility
FROM users u
LEFT JOIN facility f on (u.facility_id = f.id)
WHERE u.id = $userid
"));
}
/************************************************************/
$e2f = $pref_facility['facility_id'];
$e2f_name = $pref_facility['facility'];
}
Expand Down Expand Up @@ -1053,6 +1083,7 @@ function find_available() {
var c = document.forms[0].form_category;
var formDate = document.forms[0].form_date;
dlgopen('find_appt_popup.php?providerid=' + s +
'&facility=' + f.options[f.selectedIndex].value +
'&catid=' + c.options[c.selectedIndex].value +
'&startdate=' + formDate.value, '_blank', 500, 400);
//END (CHEMED) modifications
Expand Down Expand Up @@ -1279,10 +1310,22 @@ function verify_selecteerbaar (a) {
// EVENTS TO FACILITIES
//(CHEMED) added service_location WHERE clause
// get the facilities
/***************************************************************
$qsql = sqlStatement("SELECT * FROM facility WHERE service_location != 0");
***************************************************************/
$facils = getUserFacilities($_SESSION['authId']);
$qsql = sqlStatement("SELECT id, name FROM facility WHERE service_location != 0");
/**************************************************************/
while ($facrow = sqlFetchArray($qsql)) {
/*************************************************************
$selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
*************************************************************/
if ($_SESSION['authorizedUser'] || in_array($facrow, $facils)) {
$selected = ( $facrow['id'] == $e2f ) ? 'selected="selected"' : '' ;
echo "<option value={$facrow['id']} $selected>{$facrow['name']}</option>";
}
/************************************************************/
}
// EOS E2F
// ===========================
Expand Down Expand Up @@ -1368,6 +1411,7 @@ function verify_selecteerbaar (a) {
}
else {
// this is a new event so smartly choose a default provider
/*****************************************************************
if ($userid) {
// Provider already given to us as a GET parameter.
$defaultProvider = $userid;
Expand Down Expand Up @@ -1395,6 +1439,30 @@ function verify_selecteerbaar (a) {
echo "</option>\n";
}
echo "</select>";
*****************************************************************/
// default to the currently logged-in user
$defaultProvider = $_SESSION['authUserID'];
// or, if we have chosen a provider in the calendar, default to them
// choose the first one if multiple have been selected
if (count($_SESSION['pc_username']) >= 1) {
// get the numeric ID of the first provider in the array
$pc_username = $_SESSION['pc_username'];
$firstProvider = sqlFetchArray(sqlStatement("select id from users where username='".$pc_username[0]."'"));
$defaultProvider = $firstProvider['id'];
}
// if we clicked on a provider's schedule to add the event, use THAT.
if ($userid) $defaultProvider = $userid;
}
echo "<select name='form_provider' style='width:100%' />";
while ($urow = sqlFetchArray($ures)) {
echo " <option value='" . $urow['id'] . "'";
if ($urow['id'] == $defaultProvider) echo " selected";
echo ">" . $urow['lname'];
if ($urow['fname']) echo ", " . $urow['fname'];
echo "</option>\n";
}
echo "</select>";
/****************************************************************/
}

?>
Expand Down
6 changes: 6 additions & 0 deletions interface/main/calendar/find_appt_popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ function doOneDay($catid, $udate, $starttime, $duration, $prefcatid) {
"WHERE pc_aid = '$providerid' AND " .
"((pc_endDate >= '$sdate' AND pc_eventDate < '$edate') OR " .
"(pc_endDate = '0000-00-00' AND pc_eventDate >= '$sdate' AND pc_eventDate < '$edate'))";
// phyaura whimmel facility filtering
if ($_REQUEST['facility'] > 0 ) {
$facility = $_REQUEST['facility'];
$query .= " AND pc_facility = $facility";
}
// end facility filtering whimmel 29apr08
$res = sqlStatement($query);

while ($row = sqlFetchArray($res)) {
Expand Down
19 changes: 19 additions & 0 deletions interface/main/calendar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,27 @@

// FACILITY FILTERING (lemonsoftware) (CHEMED)
$_SESSION['pc_facility'] = 0;

/*********************************************************************
if ($_POST['pc_facility']) $_SESSION['pc_facility'] = $_POST['pc_facility'];
*********************************************************************/
if (isset($_COOKIE['pc_facility'])) $_SESSION['pc_facility'] = $_COOKIE['pc_facility'];
// override the cookie if the user doesn't have access to that facility any more
if ($_SESSION['userauthorized'] != 1 && $GLOBALS['restrict_user_facility']) {
$facilities = getUserFacilities($_SESSION['authId']);
// use the first facility the user has access to, unless...
$_SESSION['pc_facility'] = $facilities[0]['id'];
// if the cookie is in the users' facilities, use that.
foreach ($facilities as $facrow) {
if ($facrow['id'] == $_COOKIE['pc_facility'])
$_SESSION['pc_facility'] = $_COOKIE['pc_facility'];
}
}
if (isset($_POST['pc_facility'])) $_SESSION['pc_facility'] = $_POST['pc_facility'];
/********************************************************************/

if ($_GET['pc_facility']) $_SESSION['pc_facility'] = $_GET['pc_facility'];
setcookie("pc_facility", $_SESSION['pc_facility'], time() + (3600 * 365));

// allow tracking of current viewtype -- JRM
if ($_GET['viewtype']) $_SESSION['viewtype'] = $_GET['viewtype'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,19 @@

$MULTIDAY = count($A_EVENTS) > 1;

//==================================
//FACILITY FILTERING (CHEMED)
if ( $_SESSION['pc_facility'] ) {
$provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
} else {
$provinfo = getProviderInfo();
}
//EOS FACILITY FILTERING (CHEMED)
//==================================
//==================================
//FACILITY FILTERING (CHEMED)
$facilities = getUserFacilities($_SESSION['authId']); // from users_facility
if (count($facilities) == 1 || !$_SESSION['pc_facility']) {
$_SESSION['pc_facility'] = $facilities[0]['id'];
}
if ( $_SESSION['pc_facility'] ) {
$provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
} else {
$provinfo = getProviderInfo();
}
//EOS FACILITY FILTERING (CHEMED)
//==================================

[-/php-]

Expand Down Expand Up @@ -290,11 +294,22 @@
[-php-]
// ==============================
// FACILITY FILTERING (lemonsoftware)
/*********************************************************************
$facilities = getFacilities();
*********************************************************************/
if ($_SESSION['authorizeduser'] == 1) {
$facilities = getFacilities();
} else {
$facilities = getUserFacilities($_SESSION['authId']); // from users_facility
if (count($facilities) == 1)
$_SESSION['pc_facility'] = key($facilities);
}
/********************************************************************/
if (count($facilities) > 1) {
echo " <select name='pc_facility' id='pc_facility'>\n";
if ( !$_SESSION['pc_facility'] ) $selected = "selected='selected'";
echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
// echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
if (!$GLOBALS['restrict_user_facility']) echo " <option value='0' $selected>" . xl('All Facilities') . "</option>\n";
foreach ($facilities as $fa) {
$selected = ( $_SESSION['pc_facility'] == $fa['id']) ? "selected='selected'" : "" ;
echo " <option value='" .$fa['id']. "' $selected>" .$fa['name']. "</option>\n";
Expand Down Expand Up @@ -345,13 +360,19 @@

echo "<tr><td class='timeslot'>";

/*****************************************************************
$providerid = 0;
if (count($providers) == 1) {
$providerid = $providers[0]['id'];
}
echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$Date,$providerid,0)' title='New Appointment' alt='New Appointment'>";
*****************************************************************/
// can't have a link to new appts since we may have multiple providers displayed
//echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$defaultDate,$providerid,$in_cat_id)' title='New Appointment' alt='New Appointment'>";
/****************************************************************/

echo "$disptimeh:$starttimem";
echo "</a>";
// echo "</a>";

echo "</td></tr>\n";
}
Expand Down Expand Up @@ -598,7 +619,8 @@
$content .= "<span class='appointment'>";
$content .= $dispstarth . ':' . $startm;
if ($event['recurrtype'] == 1) $content .= "<img src='$TPL_IMAGE_PATH/repeating8.png' border='0' style='margin:0px 2px 0px 2px;' title='Repeating event' alt='Repeating event'>";
$content .= htmlspecialchars($event['apptstatus']);
// $content .= htmlspecialchars($event['apptstatus']);
$content .= '&nbsp;'.htmlspecialchars($event['apptstatus']);
if ($patientid) {
$link_title = "Age: ".$patient_age."\nDOB: ".$patient_dob."\n";
$link_title .= "(Click to view)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,17 @@

$MULTIDAY = count($A_EVENTS) > 1;

$provinfo = getProviderInfo();

echo "<form name='theform' action='index.php?module=PostCalendar&func=view" .
$facilities = getUserFacilities($_SESSION['authId']); // from users_facility
if (count($facilities) == 1 || !$_SESSION['pc_facility']) {
$_SESSION['pc_facility'] = $facilities[0]['id'];
}
if ( $_SESSION['pc_facility'] ) {
$provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
} else {
$provinfo = getProviderInfo();
}
// echo "<form name='theform' action='index.php?module=PostCalendar&func=view" .
echo "<form id='theform' name='theform' action='index.php?module=PostCalendar&func=view" .
"&tplview=default&pc_category=&pc_topic=' " .
"method='post' onsubmit='return top.restoreSession()'>\n";
echo "<center>\n";
Expand All @@ -182,6 +190,7 @@
}
echo " </select>\n";

/*********************************************************************
// ==============================
// FACILITY FILTERING (lemonsoftware)
$facilities = getFacilities();
Expand All @@ -193,6 +202,28 @@
echo " <option value='" .$fa['id']. "' $selected>" .$fa['name']. "</option>\n";
}
echo " </select>\n";
*********************************************************************/
// ==============================
// FACILITY FILTERING (lemonsoftware)
if ($_SESSION['authorizeduser'] == 1) {
$facilities = getFacilities();
} else {
$facilities = getUserFacilities($_SESSION['authId']); // from users_facility
if (count($facilities) == 1)
$_SESSION['pc_facility'] = ($facilities[0]['id']);
}
if (count($facilities) > 1) {
echo " <select name='pc_facility' id='pc_facility' onChange='document.getElementById(\"theform\").submit();'>\n";
if ( !$_SESSION['pc_facility'] ) $selected = "selected='selected'";
if ( !$GLOBALS['restrict_user_facility']) echo " <option value='0' $selected>" . xl('All Facilities') . "</option>\n";
foreach ($facilities as $fa) {
$selected = ( $_SESSION['pc_facility'] == $fa['id']) ? "selected='selected'" : "" ;
echo " <option value='" . $fa['id'] . "' $selected>" . $fa['name'] . "</option>\n";
}
echo " </select>\n";
}
/********************************************************************/

// EOS FF
// ==============================

Expand Down Expand Up @@ -494,7 +525,8 @@
}
else { // some sort of patient appointment
$content .= "<a href='javascript:oldEvt($eventdate,$eventid)' title='$catname'>";
$content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . "</a>";
// $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . "</a>";
$content .= $starth . ':' . $startm . '&nbsp;' . htmlspecialchars($event['apptstatus']) . "&nbsp;</a>";
$content .= "<a href='javascript:goPid($patientid)' title='$title'>";
if ($catid == 1) $content .= "<strike>";
$content .= $lname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@

//==================================
//FACILITY FILTERING (CHEMED)
$facilities = getUserFacilities($_SESSION['authId']); // from users_facility
if (count($facilities) == 1 || !$_SESSION['pc_facility']) {
$_SESSION['pc_facility'] = $facilities[0]['id'];
}
if ( $_SESSION['pc_facility'] ) {
$provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']);
} else {
Expand Down Expand Up @@ -270,11 +274,20 @@
[-php-]
// ==============================
// FACILITY FILTERING (lemonsoftware)
$facilities = getFacilities();
// $facilities = getFacilities();
if ($_SESSION['authorizeduser'] == 1) {
$facilities = getFacilities();
} else {
$facilities = getUserFacilities($_SESSION['authId']); // from users_facility
if (count($facilities) == 1)
$_SESSION['pc_facility'] = key($facilities);
}
if (count($facilities) > 1) {
echo " <select name='pc_facility' id='pc_facility'>\n";
if ( !$_SESSION['pc_facility'] ) $selected = "selected='selected'";
echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
// echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
if (!$GLOBALS['restrict_user_facility']) echo " <option value='0' $selected>" . xl('All Facilities') . "</option>\n";

foreach ($facilities as $fa) {
$selected = ( $_SESSION['pc_facility'] == $fa['id']) ? "selected='selected'" : "" ;
echo " <option value='" .$fa['id']. "' $selected>" .$fa['name']. "</option>\n";
Expand Down
Loading

0 comments on commit ef6a8b5

Please sign in to comment.