|
@@ -0,0 +1,77 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers;
|
|
|
+
|
|
|
+use App\Models\Appointment;
|
|
|
+use App\Models\BDTDevice;
|
|
|
+use App\Models\CareMonth;
|
|
|
+use App\Models\Client;
|
|
|
+use App\Models\ClientInfoLine;
|
|
|
+use App\Models\Facility;
|
|
|
+use App\Models\NoteTemplate;
|
|
|
+use App\Models\Pro;
|
|
|
+use App\Models\SectionTemplate;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\File;
|
|
|
+
|
|
|
+class AppointmentController extends Controller
|
|
|
+{
|
|
|
+ public function events(Request $request)
|
|
|
+ {
|
|
|
+ $proIds = $request->get('proIds');
|
|
|
+ $start = $request->get('start');
|
|
|
+ $end = $request->get('end');
|
|
|
+ $timeZone = $request->get('timeZone');
|
|
|
+ $appointments = Appointment
|
|
|
+ ::whereIn('pro_id', explode(',', $proIds))
|
|
|
+ ->where('status', '!=', 'COMPLETED')
|
|
|
+ ->where('status', '!=', 'CANCELLED')
|
|
|
+ ->where('start_time', '>=', $start)
|
|
|
+ ->where('start_time', '<=', $end)
|
|
|
+ ->get();
|
|
|
+ $events = [];
|
|
|
+ foreach ($appointments as $appointment) {
|
|
|
+ $events[] = [
|
|
|
+ "title" => '[' . $appointment->pro->initials() . '] ' . $appointment->client->displayName(),
|
|
|
+ "appointmentUid" => $appointment->uid,
|
|
|
+ "clientUid" => $appointment->client->uid,
|
|
|
+ "proUid" => $appointment->pro->uid,
|
|
|
+ "start" => $this->convertToTimezone($appointment->start_time, $timeZone), // TODO: convert to $timeZone
|
|
|
+ "end" => $this->convertToTimezone($appointment->end_time, $timeZone), // TODO: convert to $timeZone
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return json_encode($events);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function convertToTimezone($_dateTime, $_targetTimezone) {
|
|
|
+ if(!$_dateTime) return $_dateTime;
|
|
|
+ $timezone = 'US/Eastern';
|
|
|
+ switch($_targetTimezone) {
|
|
|
+ case 'ALASKA':
|
|
|
+ $timezone = "US/Alaska";
|
|
|
+ break;
|
|
|
+ case 'CENTRAL':
|
|
|
+ $timezone = "US/Central";
|
|
|
+ break;
|
|
|
+ case 'HAWAII':
|
|
|
+ $timezone = "US/Hawaii";
|
|
|
+ break;
|
|
|
+ case 'MOUNTAIN':
|
|
|
+ $timezone = "US/Mountain";
|
|
|
+ break;
|
|
|
+ case 'PACIFIC':
|
|
|
+ $timezone = "US/Pacific";
|
|
|
+ break;
|
|
|
+ case 'PUERTO_RICO':
|
|
|
+ $timezone = "America/Puerto_Rico";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $timezone = "US/Eastern";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $date = new \DateTime($_dateTime, new \DateTimeZone("UTC"));
|
|
|
+ $date->setTimezone(new \DateTimeZone($timezone));
|
|
|
+ return $date->format('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
+}
|