123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?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),
- "end" => $this->convertToTimezone($appointment->end_time, $timeZone),
- "editable" => true
- ];
- }
- 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');
- }
- }
|