AppointmentController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Appointment;
  4. use App\Models\BDTDevice;
  5. use App\Models\CareMonth;
  6. use App\Models\Client;
  7. use App\Models\ClientInfoLine;
  8. use App\Models\Facility;
  9. use App\Models\NoteTemplate;
  10. use App\Models\Pro;
  11. use App\Models\SectionTemplate;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\File;
  14. class AppointmentController extends Controller
  15. {
  16. public function events(Request $request)
  17. {
  18. $proIds = $request->get('proIds');
  19. $start = $request->get('start');
  20. $end = $request->get('end');
  21. $timeZone = $request->get('timeZone');
  22. $appointments = Appointment
  23. ::whereIn('pro_id', explode(',', $proIds))
  24. ->where('status', '!=', 'COMPLETED')
  25. ->where('status', '!=', 'CANCELLED')
  26. ->where('start_time', '>=', $start)
  27. ->where('start_time', '<=', $end)
  28. ->get();
  29. $events = [];
  30. foreach ($appointments as $appointment) {
  31. $events[] = [
  32. "title" => '(' . $appointment->pro->initials() . ') ' . $appointment->client->displayName(),
  33. "_title" => $appointment->title,
  34. "description" => $appointment->description,
  35. "clientName" => $appointment->client->displayName(),
  36. "appointmentUid" => $appointment->uid,
  37. "clientUid" => $appointment->client->uid,
  38. "proUid" => $appointment->pro->uid,
  39. "start" => $this->convertToTimezone($appointment->start_time, $timeZone),
  40. "end" => $this->convertToTimezone($appointment->end_time, $timeZone),
  41. "editable" => true
  42. ];
  43. }
  44. return json_encode($events);
  45. }
  46. private function convertToTimezone($_dateTime, $_targetTimezone) {
  47. if(!$_dateTime) return $_dateTime;
  48. $timezone = 'US/Eastern';
  49. switch($_targetTimezone) {
  50. case 'ALASKA':
  51. $timezone = "US/Alaska";
  52. break;
  53. case 'CENTRAL':
  54. $timezone = "US/Central";
  55. break;
  56. case 'HAWAII':
  57. $timezone = "US/Hawaii";
  58. break;
  59. case 'MOUNTAIN':
  60. $timezone = "US/Mountain";
  61. break;
  62. case 'PACIFIC':
  63. $timezone = "US/Pacific";
  64. break;
  65. case 'PUERTO_RICO':
  66. $timezone = "America/Puerto_Rico";
  67. break;
  68. default:
  69. $timezone = "US/Eastern";
  70. break;
  71. }
  72. $date = new \DateTime($_dateTime, new \DateTimeZone("UTC"));
  73. $date->setTimezone(new \DateTimeZone($timezone));
  74. return $date->format('Y-m-d H:i:s');
  75. }
  76. }