Skip to content

Instantly share code, notes, and snippets.

@iaditya
Created April 15, 2017 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaditya/4915fb6f65818a6b454c8d1b7b465239 to your computer and use it in GitHub Desktop.
Save iaditya/4915fb6f65818a6b454c8d1b7b465239 to your computer and use it in GitHub Desktop.
// 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]]])
;
foreach ($providerSlots as $providerSlot): {
if ($providerSlot->alldays == 1) {
$dow = [0,1,2,3,4,5,6];
} else {
$dow = [$providerSlot->day];
}
$data[] = array(
'id' => 'sunday_slots',
'start' => $providerSlot->start->format('H:i'),
'end' => $providerSlot->end->format('H:i'),
'dow' => $dow,
// 'constraint' => 'sunday_slots',
'allowed' => true,
'resourceId' => $providerSlot->facility_id,
'color' => $providerSlot->color,
'slot_type' => $providerSlot->slot_type,
'textColor' => 'black',
'rendering' => 'background'
);
}
endforeach;
$start = Time::now()->subMonths(1)->toDateString();
$end = Time::now()->addMonths(2)->toDateString();
$Event = TableRegistry::get('events');
$events = $Event->find("all")
->contain(['Zoommeetings', 'Providers', 'Facilities', 'Patients' => ['Users']])
->where(['provider_id' => $provider_id])
->andWhere(['events.status' => 'Confirmed']) // changes by aditya - requires only confirmed events on Calendar
->andWhere(['events.start BETWEEN :now AND :then'])
->bind(':now', $start, 'time')
->bind(':then', $end, 'time');
Log::debug("start: ".$start);
Log::debug("start: ".$end);
Log::debug("events".$events);
foreach ($events as $event): {
$teleurl = null;
$color = "voilet";
if (isset($event->zoommeeting)) {
$color = "blue";
$teleurl = $event->zoommeeting->start_url;
} else {
if ($event->status == "Confirmed")
$color = "purple";
}
$encounter_url = "/encounters/add?event_id=" . $event->id;
$facility_id = null;
$facility = null;
if (isset($event->facility)) {
$facility = $event->facility->name;
$facility_id = $event->facility->id;
}
$patient_uuid = null;
$patient = null;
if (isset($event->patient)) {
$patient_uuid = ! $event->patient->external_patient_id ? $event->patient->patient_uuid : $event->patient->external_patient_id;
$patient = $event->patient->user->first_name;
}
$last_visit_date = $this->lastVisitDate($event->patient->id, $event->facility->id) ? (" | " . (new Time($this->lastVisitDate($event->patient->id, $event->facility->id)))->timeAgoInWords()): "";
$age = !($event->patient->age == "Not Defined") ? (" | ". $event->patient->age . " years old ") : "";
$data[] = array(
'id' => $event->id,
'start' => $event->start,
'end' => $event->end,
'title' => $patient . " | " . $event->patient->sex . $age . $last_visit_date,
'patient_uuid' => $patient_uuid,
'patient' => $patient,
'facility' => $facility,
'url' => '/events/edit/' . $event->id,
'teleurl' => $teleurl,
'description' => $event->details,
'encounterUrl' => $encounter_url,
'resourceId' => $event->facility_id,
'status' => $event->status,
'color' => $color
);
}
endforeach;
// $data = current($data);
$this->set(array(
'data' => $data,
'_serialize' => 'data'
));
// $this->set("data", $data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment