function fetchAppointments($from_date, $to_date, $patient_id = null, $provider_id = null, $facility_id = null) { $where = ""; if ($provider_id) { $where .= " AND e.pc_aid = '{$provider_id}'"; } if ($patient_id) { $where .= " AND e.pc_pid = '{$patient_id}'"; } else { $where .= " AND e.pc_pid != ''"; } $facility_filter = ''; if ($facility_id) { $event_facility_filter = " AND e.pc_facility = '{$facility_id}'"; $provider_facility_filter = " AND users.facility_id = '{$facility_id}'"; } $where .= $facility_filter; $appointments = fetchEvents($from_date, $to_date, $where); return $appointments; }
function fetchAppointments($from_date, $to_date, $patient_id = null, $provider_id = null, $facility_id = null, $pc_appstatus = null, $with_out_provider = null, $with_out_facility = null, $pc_catid = null) { $where = ""; if ($provider_id) { $where .= " AND e.pc_aid = '{$provider_id}'"; } if ($patient_id) { $where .= " AND e.pc_pid = '{$patient_id}'"; } else { $where .= " AND e.pc_pid != ''"; } $facility_filter = ''; if ($facility_id) { $event_facility_filter = " AND e.pc_facility = '" . add_escape_custom($facility_id) . "'"; // escape $facility_id $provider_facility_filter = " AND u.facility_id = '" . add_escape_custom($facility_id) . "'"; // escape $facility_id $facility_filter = $event_facility_filter . $provider_facility_filter; } $where .= $facility_filter; //Appointment Status Checking $filter_appstatus = ''; if ($pc_appstatus != '') { $filter_appstatus = " AND e.pc_apptstatus = '" . $pc_appstatus . "'"; } $where .= $filter_appstatus; if ($pc_catid != null) { $where .= " AND e.pc_catid=" . intval($pc_catid); // using intval to escape this parameter } //Without Provider checking $filter_woprovider = ''; if ($with_out_provider != '') { $filter_woprovider = " AND e.pc_aid = ''"; } $where .= $filter_woprovider; //Without Facility checking $filter_wofacility = ''; if ($with_out_facility != '') { $filter_wofacility = " AND e.pc_facility = 0"; } $where .= $filter_wofacility; $appointments = fetchEvents($from_date, $to_date, $where); return $appointments; }
function doSubs($s) { global $ptrow, $hisrow, $enrow, $nextLocation, $keyLocation, $keyLength; global $groupLevel, $groupCount, $itemSeparator, $pid, $encounter; $nextLocation = 0; $groupLevel = 0; $groupCount = 0; while (($keyLocation = strpos($s, '{', $nextLocation)) !== FALSE) { $nextLocation = $keyLocation + 1; if (keySearch($s, '{PatientName}')) { $tmp = $ptrow['fname']; if ($ptrow['mname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['mname']; } if ($ptrow['lname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['lname']; } $s = keyReplace($s, dataFixup($tmp, xl('Name'))); } else { if (keySearch($s, '{PatientID}')) { $s = keyReplace($s, dataFixup($ptrow['pubpid'], xl('Chart ID'))); } else { if (keySearch($s, '{Address}')) { $s = keyReplace($s, dataFixup($ptrow['street'], xl('Street'))); } else { if (keySearch($s, '{City}')) { $s = keyReplace($s, dataFixup($ptrow['city'], xl('City'))); } else { if (keySearch($s, '{State}')) { $s = keyReplace($s, dataFixup(getListItemTitle('state', $ptrow['state']), xl('State'))); } else { if (keySearch($s, '{Zip}')) { $s = keyReplace($s, dataFixup($ptrow['postal_code'], xl('Postal Code'))); } else { if (keySearch($s, '{PatientPhone}')) { $ptphone = $ptrow['phone_contact']; if (empty($ptphone)) { $ptphone = $ptrow['phone_home']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_cell']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_biz']; } if (preg_match("/([2-9]\\d\\d)\\D*(\\d\\d\\d)\\D*(\\d\\d\\d\\d)/", $ptphone, $tmp)) { $ptphone = '(' . $tmp[1] . ')' . $tmp[2] . '-' . $tmp[3]; } $s = keyReplace($s, dataFixup($ptphone, xl('Phone'))); } else { if (keySearch($s, '{PatientDOB}')) { $s = keyReplace($s, dataFixup(oeFormatShortDate($ptrow['DOB']), xl('Birth Date'))); } else { if (keySearch($s, '{PatientSex}')) { $s = keyReplace($s, dataFixup(getListItemTitle('sex', $ptrow['sex']), xl('Sex'))); } else { if (keySearch($s, '{DOS}')) { $s = keyReplace($s, dataFixup(oeFormatShortDate(substr($enrow['date'], 0, 10)), xl('Service Date'))); } else { if (keySearch($s, '{ChiefComplaint}')) { $cc = $enrow['reason']; $patientid = $ptrow['pid']; $DOS = substr($enrow['date'], 0, 10); // Prefer appointment comment if one is present. $evlist = fetchEvents($DOS, $DOS, " AND pc_pid = ? ", null, false, 0, array($patientid)); foreach ($evlist as $tmp) { if ($tmp['pc_pid'] == $pid && !empty($tmp['pc_hometext'])) { $cc = $tmp['pc_hometext']; } } $s = keyReplace($s, dataFixup($cc, xl('Chief Complaint'))); } else { if (keySearch($s, '{ReferringDOC}')) { $tmp = empty($ptrow['ur_fname']) ? '' : $ptrow['ur_fname']; if (!empty($ptrow['ur_mname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_mname']; } if (!empty($ptrow['ur_lname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_lname']; } $s = keyReplace($s, dataFixup($tmp, xl('Referer'))); } else { if (keySearch($s, '{Allergies}')) { $tmp = generate_plaintext_field(array('data_type' => '24', 'list_id' => ''), ''); $s = keyReplace($s, dataFixup($tmp, xl('Allergies'))); } else { if (keySearch($s, '{Medications}')) { $s = keyReplace($s, dataFixup(getIssues('medication'), xl('Medications'))); } else { if (keySearch($s, '{ProblemList}')) { $s = keyReplace($s, dataFixup(getIssues('medical_problem'), xl('Problem List'))); } else { if (keySearch($s, '{GRP}')) { ++$groupLevel; $groupCount = 0; $s = keyReplace($s, ''); } else { if (keySearch($s, '{/GRP}')) { if ($groupLevel > 0) { --$groupLevel; } $s = keyReplace($s, ''); } else { if (preg_match('/^\\{ITEMSEP\\}(.*?)\\{\\/ITEMSEP\\}/', substr($s, $keyLocation), $matches)) { $itemSeparator = $matches[1]; $keyLength = strlen($matches[0]); $s = keyReplace($s, ''); } else { if (preg_match('/^\\{(LBF\\w+):(\\w+)\\}/', substr($s, $keyLocation), $matches)) { $formname = $matches[1]; $fieldid = $matches[2]; $keyLength = 3 + strlen($formname) + strlen($fieldid); $data = ''; $currvalue = ''; $title = ''; $frow = sqlQuery("SELECT * FROM layout_options " . "WHERE form_id = ? AND field_id = ? LIMIT 1", array($formname, $fieldid)); if (!empty($frow)) { $ldrow = sqlQuery("SELECT ld.field_value " . "FROM lbf_data AS ld, forms AS f WHERE " . "f.pid = ? AND f.encounter = ? AND f.formdir = ? AND f.deleted = 0 AND " . "ld.form_id = f.form_id AND ld.field_id = ? " . "ORDER BY f.form_id DESC LIMIT 1", array($pid, $encounter, $formname, $fieldid)); if (!empty($ldrow)) { $currvalue = $ldrow['field_value']; $title = $frow['title']; } if ($currvalue !== '') { $data = generate_plaintext_field($frow, $currvalue); } } $s = keyReplace($s, dataFixup($data, $title)); } else { if (preg_match('/^\\{(DEM|HIS):(\\w+)\\}/', substr($s, $keyLocation), $matches)) { $formname = $matches[1]; $fieldid = $matches[2]; $keyLength = 3 + strlen($formname) + strlen($fieldid); $data = ''; $currvalue = ''; $title = ''; $frow = sqlQuery("SELECT * FROM layout_options " . "WHERE form_id = ? AND field_id = ? LIMIT 1", array($formname, $fieldid)); if (!empty($frow)) { $tmprow = $formname == 'DEM' ? $ptrow : $hisrow; if (isset($tmprow[$fieldid])) { $currvalue = $tmprow[$fieldid]; $title = $frow['title']; } if ($currvalue !== '') { $data = generate_plaintext_field($frow, $currvalue); } } $s = keyReplace($s, dataFixup($data, $title)); } } } } } } } } } } } } } } } } } } } } } // End if { character found. return $s; }
function fetchAppointments($from_date, $to_date, $patient_id = null, $provider_id = null, $facility_id = null, $pc_appstatus = null, $with_out_provider = null, $with_out_facility = null, $pc_catid = null, $tracker_board = false, $nextX = 0) { $sqlBindArray = array(); $where = ""; if ($provider_id) { $where .= " AND e.pc_aid = ?"; array_push($sqlBindArray, $provider_id); } if ($patient_id) { $where .= " AND e.pc_pid = ?"; array_push($sqlBindArray, $patient_id); } else { $where .= " AND e.pc_pid != ''"; } if ($facility_id) { $where .= " AND e.pc_facility = ?"; array_push($sqlBindArray, $facility_id); } //Appointment Status Checking if ($pc_appstatus != '') { $where .= " AND e.pc_apptstatus = ?"; array_push($sqlBindArray, $pc_appstatus); } if ($pc_catid != null) { $where .= " AND e.pc_catid = ?"; array_push($sqlBindArray, $pc_catid); } //Without Provider checking if ($with_out_provider != '') { $where .= " AND e.pc_aid = ''"; } //Without Facility checking if ($with_out_facility != '') { $where .= " AND e.pc_facility = 0"; } $appointments = fetchEvents($from_date, $to_date, $where, '', $tracker_board, $nextX, $sqlBindArray); return $appointments; }
// So, values may range from 0 to 7. // $slots = array_pad(array(), $slotcount, 0); $sqlBindArray = array(); // Note there is no need to sort the query results. $query = "SELECT pc_eventDate, pc_endDate, pc_startTime, pc_duration, " . "pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid, pc_prefcatid " . "FROM openemr_postcalendar_events " . "WHERE pc_aid = ? AND " . "pc_eid != ? AND " . "((pc_endDate >= ? AND pc_eventDate < ? ) OR " . "(pc_endDate = '0000-00-00' AND pc_eventDate >= ? AND pc_eventDate < ?))"; array_push($sqlBindArray, $providerid, $eid, $sdate, $edate, $sdate, $edate); // phyaura whimmel facility filtering if ($_REQUEST['facility'] > 0) { $facility = $_REQUEST['facility']; $query .= " AND pc_facility = ?"; array_push($sqlBindArray, $facility); } // end facility filtering whimmel 29apr08 ////// $events2 = fetchEvents($sdate, $edate, null, null, false, 0, $sqlBindArray, $query); foreach ($events2 as $row) { $thistime = strtotime($row['pc_eventDate'] . " 00:00:00"); doOneDay($row['pc_catid'], $thistime, $row['pc_startTime'], $row['pc_duration'], $row['pc_prefcatid']); } ////// // Mark all slots reserved where the provider is not in-office. // Actually we could do this in the display loop instead. $inoffice = false; for ($i = 0; $i < $slotcount; ++$i) { if ($i % $slotsperday == 0) { $inoffice = false; } if ($slots[$i] & 1) { $inoffice = true; }
if ($acl_allow) { $where = null; $provider_id = $userId; if ($facilities) { $where = " AND pc_facility IN ({$facilities})"; } if ($appstatus) { $where .= ' AND pc_apptstatus IN (' . $appstatus . ')'; } if ($appointment_type == 2) { $where .= " AND pc_aid = {$provider_id}"; } if ($time) { $where .= " AND pc_startTime = '{$time}'"; } $events = fetchEvents($from_date, $to_date, $where, $orderby_param = null); if ($events) { $xml_string .= "<status>0</status>\n"; $xml_string .= "<reason>Success processing patient appointments records</reason>\n"; $counter = 0; foreach ($events as $event) { $xml_string .= "<Appointment>\n"; foreach ($event as $fieldname => $fieldvalue) { $rowvalue = xmlsafestring($fieldvalue); $xml_string .= "<{$fieldname}>{$rowvalue}</{$fieldname}>\n"; } $strQuery = 'SELECT pc_apptstatus,p.sex as gender,p.pid as p_id, pce.pc_facility,pce.pc_billing_location,f1.name as facility_name,f2.name as billing_location_name FROM openemr_postcalendar_events as pce LEFT JOIN `facility` as f1 ON pce.pc_facility = f1.id LEFT JOIN `facility` as f2 ON pce.pc_billing_location = f2.id LEFT JOIN patient_data AS p ON p.pid = pce.pc_pid WHERE pc_eid = ?';
function doSubs($s) { global $ptrow, $enrow; // $loopcount avoids infinite looping if we screw up. // for ($loopcount = 0; $loopcount < 500; ++$loopcount) { if (keySearch($s, '{PatientName}')) { $tmp = $ptrow['fname']; if ($ptrow['mname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['mname']; } if ($ptrow['lname']) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['lname']; } $s = keyReplace($s, $tmp); } else { if (keySearch($s, '{PatientID}')) { $s = keyReplace($s, $ptrow['pubpid']); } else { if (keySearch($s, '{Address}')) { $s = keyReplace($s, $ptrow['street']); } else { if (keySearch($s, '{City}')) { $s = keyReplace($s, $ptrow['city']); } else { if (keySearch($s, '{State}')) { $s = keyReplace($s, getListItemTitle('state', $ptrow['state'])); } else { if (keySearch($s, '{Zip}')) { $s = keyReplace($s, $ptrow['postal_code']); } else { if (keySearch($s, '{PatientPhone}')) { $ptphone = $ptrow['phone_contact']; if (empty($ptphone)) { $ptphone = $ptrow['phone_home']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_cell']; } if (empty($ptphone)) { $ptphone = $ptrow['phone_biz']; } if (preg_match("/([2-9]\\d\\d)\\D*(\\d\\d\\d)\\D*(\\d\\d\\d\\d)/", $ptphone, $tmp)) { $ptphone = '(' . $tmp[1] . ')' . $tmp[2] . '-' . $tmp[3]; } $s = keyReplace($s, $ptphone); } else { if (keySearch($s, '{PatientDOB}')) { $s = keyReplace($s, oeFormatShortDate($ptrow['DOB'])); } else { if (keySearch($s, '{PatientSex}')) { $s = keyReplace($s, getListItemTitle('sex', $ptrow['sex'])); } else { if (keySearch($s, '{DOS}')) { $s = keyReplace($s, oeFormatShortDate(substr($enrow['date'], 0, 10))); } else { if (keySearch($s, '{ChiefComplaint}')) { $cc = $enrow['reason']; $patientid = $ptrow['pid']; $DOS = substr($enrow['date'], 0, 10); // Prefer appointment comment if one is present. $evlist = fetchEvents($DOS, $DOS, " AND pc_pid = '{$patientid}' "); foreach ($evlist as $tmp) { if ($tmp['pc_pid'] == $pid && !empty($tmp['pc_hometext'])) { $cc = $tmp['pc_hometext']; } } $s = keyReplace($s, $cc); } else { if (keySearch($s, '{ReferringDOC}')) { $tmp = empty($ptrow['ur_fname']) ? '' : $ptrow['ur_fname']; if (!empty($ptrow['ur_mname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_mname']; } if (!empty($ptrow['ur_lname'])) { if ($tmp) { $tmp .= ' '; } $tmp .= $ptrow['ur_lname']; } $s = keyReplace($s, $tmp); } else { if (keySearch($s, '{Allergies}')) { $tmp = generate_plaintext_field(array('data_type' => '24', 'list_id' => ''), ''); $s = keyReplace($s, $tmp); } else { if (keySearch($s, '{ProblemList}')) { $tmp = ''; $query = "SELECT title FROM lists WHERE " . "pid = ? AND type = 'medical_problem' AND enddate IS NULL " . "ORDER BY begdate"; $lres = sqlStatement($query, array($GLOBALS['pid'])); $count = 0; while ($lrow = sqlFetchArray($lres)) { if ($count++) { $tmp .= "; "; } $tmp .= $lrow['title']; } $s = keyReplace($s, $tmp); } else { break; } } } } } } } } } } } } } } } return $s; }