Browse Source

Patient > appointments listing page

Vijayakrishnan 4 năm trước cách đây
mục cha
commit
d2a4b593df

+ 12 - 0
app/Http/Controllers/PatientController.php

@@ -343,6 +343,18 @@ class PatientController extends Controller
         return view('app.patient.tickets', compact('patient', 'pros', 'allPros'));
     }
 
+    public function appointments(Request $request, Client $patient, $forPro = 'all', $status = 'all') {
+        $pros = $this->pros;
+        $appointments = $patient->appointmentsForProByStatus('all', 'ALL');
+        $appointmentProIDs = $appointments->map(function($_item) {
+            return $_item->pro_id;
+        });
+        $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
+        $appointments = $patient->appointmentsForProByStatus($forPro, strtoupper($status));
+        return view('app.patient.appointments',
+            compact('patient', 'pros', 'appointments', 'appointmentPros', 'forPro', 'status'));
+    }
+
     public function getTicket(Request $request, Ticket $ticket) {
         $ticket->data = json_decode($ticket->data);
 //        $ticket->created_at = friendly_date_time($ticket->created_at);

+ 14 - 0
app/Models/Client.php

@@ -197,6 +197,20 @@ class Client extends Model
             ->orderBy('start_time', 'desc');
     }
 
+    public function appointmentsForProByStatus($forPro = 'all', $status = 'all')
+    {
+        $appointments = Appointment::where('client_id', $this->id);
+        if($forPro !== 'all') {
+            $forPro = Pro::where('uid', $forPro)->first();
+            $appointments = $appointments->where('pro_id', $forPro->id);
+        }
+        if($status !== 'ALL') {
+            $appointments = $appointments->where('status', $status);
+        }
+        $appointments = $appointments->orderBy('start_time', 'desc');
+        return $appointments->get();
+    }
+
     public function upcomingAppointments()
     {
         return $this->hasMany(Appointment::class, 'client_id', 'id')

+ 61 - 0
resources/views/app/patient/appointments.blade.php

@@ -0,0 +1,61 @@
+@extends ('layouts.patient')
+@section('inner-content')
+    <div class="">
+        <div class="d-flex align-items-end pb-3">
+            <h4 class="font-weight-bold m-0 font-size-16">Appointments</h4>
+            <span class="mx-2 text-secondary">|</span>
+            <a href="/patients/view/{{$patient->uid}}/calendar">Calendar</a>
+            <select class="ml-auto max-width-200px form-control form-control-sm"
+                    onchange="fastLoad('/patients/view/{{$patient->uid}}/appointments/' + this.value + '/{{$status}}', true, false, false)">
+                <option value="all" {{ $forPro === 'all' ? 'selected' : '' }}>All Pros</option>
+                @foreach($appointmentPros as $appointmentPro)
+                    <option value="{{$appointmentPro->uid}}" {{ $forPro === $appointmentPro->uid ? 'selected' : '' }}>{{$appointmentPro->displayName()}}</option>
+                @endforeach
+            </select>
+            <select class="ml-2 max-width-200px form-control form-control-sm"
+                    onchange="fastLoad('/patients/view/{{$patient->uid}}/appointments/{{$forPro}}/' + this.value, true, false, false)">
+                <option value="all" {{ $status === 'all' ? 'selected' : '' }}>All Appointments</option>
+                <option value="created" {{ $status === 'created' ? 'selected' : '' }}>New Appointments</option>
+                <option value="confirmed" {{ $status === 'confirmed' ? 'selected' : '' }}>Confirmed Appointments</option>
+                <option value="cancelled" {{ $status === 'cancelled' ? 'selected' : '' }}>Cancelled Appointments</option>
+                <option value="completed" {{ $status === 'completed' ? 'selected' : '' }}>Completed Appointments</option>
+                <option value="abandoned" {{ $status === 'abandoned' ? 'selected' : '' }}>Abandoned Appointments</option>
+                <option value="rejected" {{ $status === 'rejected' ? 'selected' : '' }}>Rejected Appointments</option>
+            </select>
+        </div>
+        <table class="table table-striped table-sm table-bordered mb-0">
+            @if($appointments && count($appointments))
+                <thead>
+                <tr>
+                    <th class="px-2 text-secondary border-bottom-0">Date & Time</th>
+                    <th class="px-2 text-secondary border-bottom-0">Pro</th>
+                    <th class="px-2 text-secondary border-bottom-0">Title</th>
+                    <th class="px-2 text-secondary border-bottom-0">Description</th>
+                    <th class="px-2 text-secondary border-bottom-0">Status</th>
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($appointments as $appointment)
+                    <tr>
+                        <td class="px-2">
+                            <a href="/patients/view/{{$patient->uid}}/calendar/{{$appointment->uid}}" class="font-weight-bold">
+                                {{ $appointment->raw_date }}&nbsp;&nbsp;{{ $appointment->raw_start_time }}
+                            </a>
+                        </td>
+                        <td class="px-2">{{ $appointment->pro->displayName() }}</pre></td>
+                        <td class="px-2">{{ $appointment->title }}</td>
+                        <td class="px-2">{{ $appointment->description }}</td>
+                        <td class="px-2">{{ $appointment->status }}</td>
+                    </tr>
+                @endforeach
+                </tbody>
+            @else
+                <tbody>
+                    <tr>
+                        <td class="text-secondary p-3">No appointments</td>
+                    </tr>
+                </tbody>
+            @endif
+        </table>
+    </div>
+@endsection

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

@@ -74,6 +74,11 @@
                 </td>
             </tr>
         @endif
+        <tr>
+            <td class="text-secondary pt-2 px-0 border-0">
+                <a href="/patients/view/{{$patient->uid}}/appointments/all/all">See all appointments</a>
+            </td>
+        </tr>
         </tbody>
     </table>
 </div>

+ 3 - 0
routes/web.php

@@ -157,6 +157,9 @@ Route::middleware('pro.auth')->group(function () {
 
         // tickets
         Route::get('tickets', 'PatientController@tickets')->name('patient-tickets');
+
+        // appointments
+        Route::get('appointments/{forPro}/{status}', 'PatientController@appointments')->name('appointments');
     });
 
     // pro dashboard events (ajax)