View EventsCtrl
public function lastVisitDate($patient_id, $facility_id) {
$start = Time::now()->toDateString(); // today
$events = $this->Events->find()
->where(['patient_id' => $patient_id])
->andWhere(['facility_id' => $facility_id])
->andWhere(['Events.start < :now']) // returns the past appointments (not check today)
->bind(':now', $start, 'time');
if($events->count() > 1) {
$event_date = $events->limit(2)->orderDesc('id')->first()->start;
View EventsCtrl
$patient_uuid = !$event->patient->external_patient_id ? $event->patient->patient_uuid : $event->patient->external_patient_id;
// aditya changes -
$last_visit_date = $this->lastVisitDate($event->patient->id, $event->facility->id);
// For last_vist date , please check for null then appply below date function, whereever you call
$last_visit_date = ($last_visit_date != null) ? (new Date($last_visit_date))->timeAgoInWords() : null;
$age = !($event->patient->age == "Not Defined") ? (" | ". $event->patient->age . " years old ") : "";
/*
* 'title' => $patient . " | " . $event->patient->sex . $age . $last_visit_date,
View primary_caegiver
// primary caregiver
if($patient->dirty('primary_contact_email') || $patient->dirty('primary_contact_phone1')) {
if ($new_caregiver_id1) {
// Found Existing user
// send notification
// create mapper Entity
if($caregiver1) {
$caregiver1->caregiver_patient_id = $new_caregiver_id1;
$this->Patients->Caregivers->save($caregiver1);
} else {
View getSlotsForProvider
// using for EventCalendar/provider_cal.ctp
public function getSlotsForProvider($provider_id=null) {
Log::debug("getSlotsForProvider".$provider_id);
$providerSlots = $this->ProviderSlots->find("all")
->where(['provider_id' => $provider_id])
// ->where(['OR' => [['alldays' => 1], ['day' => 0]]])
;
View lastVisitDate
public function lastVisitDate($patient_id, $facility_id) {
$Events = TableRegistry::get('events');
$start = Time::now()->toDateString(); // today
$events = $Events->find()
->where(['patient_id' => $patient_id])
->andWhere(['facility_id' => $facility_id])
->andWhere(['events.start < :now']) // returns the past appointments (not includes today)
->bind(':now', $start, 'time')
->contain(['Encounters' => ['Prescriptions']]);
View notify
$_data = [
'users' => [],
'recipientLists' => [],
'template' => 'default',
'vars' => [],
'tracking_id' => $this->getTrackingId()
];
foreach ($data['vars'] as $key => $value) {
if (($key != 'new_email') && ($key != 'hyperlink')) {
$data['vars'][$key] = substr($value, 0, 18);
View EventsCtrl
// this function is using on calendar slot -appointment - aditya
public function lastVisitDate($patient_id, $facility_id) {
$last_visit_date = " ";
$Prescriptions = TableRegistry::get('prescriptions');
$prescription = $Prescriptions->find()
->where(['patient_id' => $patient_id])
->andWhere(['facility_id' => $facility_id]);
if($prescription->last()) {
//debug("pres-hh");
$last_visit_date = $prescription->last()->created;
View patientDashboardApi
//using on patientDashboard - from today
public function nextAppointment($patient_id) {
$start = Time::now()->toDateString(); // today
$event = $this->Events->findByPatientId($patient_id)
->contain(['Facilities', 'Providers' => ['Users']])
->where(['Events.start >= :now'])
->bind(':now', $start, 'time')->first();
$this->set(compact('event'));
View EncountersCtrl
public function bmiGraphApi($patient_id) {
if(!empty($patient_id)) {
$query = $this->Encounters->find()
->join(['Patients']);
$time = $query->func()->date_format([
'Encounters.visitdate' => 'identifier',
"'%m-%d-%y'" => 'literal'
]);
$data = $query->select([ 'visitdate' => $time, 'bmi' => 'Patients.bmi'])
View auto_sort_object
success: function (response) {
if (response) {
var eventData = response.events;
var arr = [], i;
for (i in eventData) arr.push([i, eventData[i]].join('$$'));
var reverseData = arr.reverse();
var append_text = "";