|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
+use App\Helpers\TimeLine;
|
|
|
use App\Models\Appointment;
|
|
|
use App\Models\BDTDevice;
|
|
|
use App\Models\CareMonth;
|
|
@@ -108,6 +109,7 @@ class AppointmentController extends Controller
|
|
|
$phpTZ = $this->appTZtoPHPTZ($timeZone);
|
|
|
$startDate = new \DateTime($start, new \DateTimeZone($phpTZ));
|
|
|
$endDate = new \DateTime($end, new \DateTimeZone($phpTZ));
|
|
|
+ $endDate->setTime(23,59,59);
|
|
|
$period = new \DatePeriod($startDate, \DateInterval::createFromDateString('1 day'), $endDate);
|
|
|
$days = [];
|
|
|
foreach ($period as $day) {
|
|
@@ -119,45 +121,83 @@ class AppointmentController extends Controller
|
|
|
|
|
|
foreach ($proIds as $proId) {
|
|
|
|
|
|
+ $proTimeLine = new TimeLine($startDate, $endDate);
|
|
|
+
|
|
|
$pro = Pro::where('id', $proId)->first();
|
|
|
|
|
|
$proGenAvail = $genAvail->filter(function ($record) use ($proId) {
|
|
|
return $record->pro_id == $proId;
|
|
|
});
|
|
|
|
|
|
+ $proSpecAvail = $specAvail->filter(function ($record) use ($proId) {
|
|
|
+ return $record->pro_id == $proId;
|
|
|
+ });
|
|
|
+
|
|
|
+ $proSpecUnavail = $specUnavail->filter(function ($record) use ($proId) {
|
|
|
+ return $record->pro_id == $proId;
|
|
|
+ });
|
|
|
+
|
|
|
+ // general availability
|
|
|
foreach ($days as $day) {
|
|
|
|
|
|
$proGenAvailForTheDay = $proGenAvail->filter(function ($record) use ($day) {
|
|
|
return $record->day_of_week === $day["day"];
|
|
|
});
|
|
|
+ foreach ($proGenAvailForTheDay as $ga) {
|
|
|
+
|
|
|
+ $gaStart = new \DateTime($day["date"], new \DateTimeZone($this->appTZtoPHPTZ($ga->timezone)));
|
|
|
+ $parts = explode(":", $ga->start_time);
|
|
|
+ $gaStart->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
|
+ $gaStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
|
|
|
- if(count($proGenAvailForTheDay)) {
|
|
|
- foreach ($proGenAvailForTheDay as $ga) {
|
|
|
-
|
|
|
- $gaStart = new \DateTime($day["date"], new \DateTimeZone($phpTZ));
|
|
|
- $parts = explode(":", $ga->start_time);
|
|
|
- $gaStart->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
|
-
|
|
|
- $gaEnd = new \DateTime($day["date"], new \DateTimeZone($phpTZ));
|
|
|
- $parts = explode(":", $ga->end_time);
|
|
|
- $gaEnd->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
|
-
|
|
|
- $events[] = [
|
|
|
- "type" => "availability",
|
|
|
- "title" => $pro->displayName(),
|
|
|
- "proId" => $pro->id,
|
|
|
- "proUid" => $pro->uid,
|
|
|
- "start" => $gaStart->format('Y-m-d H:i:s'),
|
|
|
- "end" => $gaEnd->format('Y-m-d H:i:s'),
|
|
|
- "editable" => false
|
|
|
- ];
|
|
|
- }
|
|
|
+ $gaEnd = new \DateTime($day["date"], new \DateTimeZone($this->appTZtoPHPTZ($ga->timezone)));
|
|
|
+ $parts = explode(":", $ga->end_time);
|
|
|
+ $gaEnd->setTime(intval($parts[0]), intval($parts[1]), intval($parts[2]));
|
|
|
+ $gaEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+
|
|
|
+ $proTimeLine->addAvailability($gaStart, $gaEnd);
|
|
|
}
|
|
|
|
|
|
- // TODO: add spec avail
|
|
|
- // TODO: subtract spec unavail
|
|
|
+ }
|
|
|
|
|
|
+ // specific availability
|
|
|
+ foreach ($proSpecAvail as $sa) {
|
|
|
+ $saStart = new \DateTime($sa->start_time, new \DateTimeZone($this->appTZtoPHPTZ($sa->timezone)));
|
|
|
+ $saStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+ $saEnd = new \DateTime($sa->end_time, new \DateTimeZone($this->appTZtoPHPTZ($sa->timezone)));
|
|
|
+ $saEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+ $proTimeLine->addAvailability($saStart, $saEnd);
|
|
|
}
|
|
|
+
|
|
|
+ // specific unavailability
|
|
|
+ foreach ($proSpecUnavail as $sua) {
|
|
|
+ $suaStart = new \DateTime($sua->start_time, new \DateTimeZone($this->appTZtoPHPTZ($sua->timezone)));
|
|
|
+ $suaStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+ $suaEnd = new \DateTime($sua->end_time, new \DateTimeZone($this->appTZtoPHPTZ($sua->timezone)));
|
|
|
+ $suaEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+ $proTimeLine->removeAvailability($suaStart, $suaEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($proTimeLine->available as $item) {
|
|
|
+
|
|
|
+ $eStart = new \DateTime('@' . $item->start);
|
|
|
+ $eStart->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+
|
|
|
+ $eEnd = new \DateTime('@' . $item->end);
|
|
|
+ $eEnd->setTimezone(new \DateTimeZone($phpTZ));
|
|
|
+
|
|
|
+ $events[] = [
|
|
|
+ "type" => "availability",
|
|
|
+ "title" => $pro->displayName(),
|
|
|
+ "proId" => $pro->id,
|
|
|
+ "proUid" => $pro->uid,
|
|
|
+ "start" => $eStart->format('Y-m-d H:i:s'),
|
|
|
+ "end" => $eEnd->format('Y-m-d H:i:s'),
|
|
|
+ "editable" => false
|
|
|
+ ];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return json_encode($events);
|