12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?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 = explode(',', $request->get('proIds'));
- $start = $request->get('start');
- $end = $request->get('end');
- $clientId = $request->get('clientId');
- $timeZone = $request->get('timeZone');
- $appointments = Appointment
- ::where('status', '!=', 'COMPLETED')
- ->where('status', '!=', 'CANCELLED')
- ->where('start_time', '>=', $start)
- ->where('start_time', '<=', $end)
- ->where(function ($query) use ($proIds, $clientId) {
- $query
- ->whereIn('pro_id', $proIds)
- ->orWhere('client_id', '=', $clientId);
- })
- ->get();
- $events = [];
- foreach ($appointments as $appointment) {
- $events[] = [
- "title" => '(' . $appointment->pro->initials() . ') ' . $appointment->client->displayName(),
- "_title" => $appointment->title,
- "description" => $appointment->description,
- "clientName" => $appointment->client->displayName(),
- "appointmentUid" => $appointment->uid,
- "clientUid" => $appointment->client->uid,
- "proId" => $appointment->pro->id,
- "proUid" => $appointment->pro->uid,
- "start" => $this->convertToTimezone($appointment->start_time, $timeZone),
- "end" => $this->convertToTimezone($appointment->end_time, $timeZone),
- "clientOnly" => !in_array($appointment->pro->id, $proIds),
- "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');
- }
- }
|