Przeglądaj źródła

Patient dashboard - show only appts from last week and newer

Vijayakrishnan 4 lat temu
rodzic
commit
9e5e2151a2

+ 11 - 0
app/Models/Client.php

@@ -205,6 +205,17 @@ class Client extends Model
             ->orderBy('start_time', 'desc');
     }
 
+    public function appointmentsFromLastWeek()
+    {
+
+        $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("7 days"));
+        $dateLastWeek = date_format($dateLastWeek, "Y-m-d");
+        return $this->hasMany(Appointment::class, 'client_id', 'id')
+            ->where('raw_date', '>=', $dateLastWeek)
+            ->whereIn('status', ['CREATED', 'CONFIRMED'])
+            ->orderBy('start_time', 'desc');
+    }
+
     public function memos()
     {
         return $this->hasMany(ClientMemo::class, 'client_id', 'id')

+ 3 - 3
resources/views/app/patient/partials/appointments.blade.php

@@ -6,7 +6,7 @@
     </div>
     <table class="table table-sm border-0 m-0">
         <tbody>
-        @foreach($patient->upcomingAppointments as $appointment)
+        @foreach($patient->appointmentsFromLastWeek as $appointment)
             <tr>
                 <td class="text-black p-0 border-0 pb-1">
                     <div class="pb-0 d-flex align-items-center flex-wrap">
@@ -67,10 +67,10 @@
                 </td>
             </tr>
         @endforeach
-        @if(!$patient->appointments || count($patient->appointments) === 0)
+        @if(!$patient->appointmentsFromLastWeek || count($patient->appointmentsFromLastWeek) === 0)
             <tr>
                 <td class="text-secondary p-0 border-0">
-                    No appointments
+                    No recent appointments
                 </td>
             </tr>
         @endif