瀏覽代碼

Updates - bulk ack

Samson Mutunga 2 周之前
父節點
當前提交
6352705228

+ 30 - 0
app/Http/Controllers/AppointmentController.php

@@ -303,4 +303,34 @@ class AppointmentController extends Controller
         return view('app.patient.partials.appointment-confirmation-history', compact('appointment'));
     }
 
+    public function acknowledgeAsAppointmentPro(Request $request){
+        $action = $request->get('action');
+        $appointmentUids = $request->get('uids');
+        $failedUids = [];
+        $failedMessages = [];
+        foreach($appointmentUids as $uid){
+            $appointment = Appointment::where('uid', $uid)->first();
+            $data = [
+                'uid' => $uid,
+                'currentStatus' => $appointment->status,
+                'currentStatusMemo' => $appointment->status_memo,
+                'currentRawDate' => $appointment->raw_date,
+                'currentRawStartTime' => $appointment->raw_start_time,
+                'currentRawEndTime' => $appointment->raw_end_time,
+                'currentTimezone' => $appointment->timezone,
+            ];
+            $response = $this->callJavaApi('/appointment/'.$action, $data);
+    
+            if(!$response['success']){
+                array_push($failedUids, $uid);
+                array_push($failedMessages, $response['message']);
+            }
+            if(count($failedUids)){
+                return $this->fail('Some appointment(s) failed to acknowledge. ' . $failedMessages[0]);
+            }
+
+            return $this->pass();
+        }
+    }
+
 }

+ 84 - 8
resources/views/app/mcp/dashboard/notifications.blade.php

@@ -10,9 +10,12 @@ $apptsPending = [
 
     <div class="card mb-4">
         <div class="card-header pl-2">
-            <strong>
-                Appointment Status Changes
-            </strong>
+            <div class="d-flex justify-content-between">
+                <strong>
+                    Appointment Status Changes
+                </strong>
+                <button type="button" class="d-none btn btn-sm btn-primary" data-action="acknowledgeStatusAsAppointmentPro" submit-ack-appts>Ack. Selected (<span></span>)</button>
+            </div>            
         </div>
         <div class="card-body p-0">
             @if(!count($apptsPending['status']))
@@ -24,6 +27,7 @@ $apptsPending = [
                 <table class="table table-sm table-striped">
                     <thead>
                     <tr>
+                        <th><input type="checkbox" select-all-appts data-target="#apptsStatusChanges" /></th>
                         <th>Patient</th>
                         <th>Time</th>
                         <th>Memo</th>
@@ -31,9 +35,10 @@ $apptsPending = [
                         <th></th>
                     </tr>
                     </thead>
-                    <tbody>
+                    <tbody id="apptsStatusChanges">
                     @foreach($apptsPending['status'] as $appt)
                         <tr discardable-container>
+                            <td><input type="checkbox" name="uids[]" value="{{ $appt->uid }}" select-appt /></td>
                             <td>
                                 <a class="d-block"
                                    href="/patients/view/{{$appt->client->uid}}">{{$appt->client->displayName()}}</a>
@@ -76,9 +81,12 @@ $apptsPending = [
 
     <div class="card mb-4">
         <div class="card-header pl-2">
-            <strong>
-                Appointment Confirmation Changes
-            </strong>
+            <div class="d-flex justify-content-between">
+                <strong>
+                    Appointment Confirmation Changes
+                </strong>
+                <button type="button" class="d-none btn btn-sm btn-primary" data-action="acknowledgeDecisionAsAppointmentPro" submit-ack-appts>Ack. Selected (<span></span>)</button>
+            </div>
         </div>
         <div class="card-body p-0">
             @if(!count($apptsPending['decision']))
@@ -90,15 +98,17 @@ $apptsPending = [
                 <table class="table table-sm table-striped">
                     <thead>
                     <tr>
+                        <th><input type="checkbox" select-all-appts data-target="#apptsConfirmationChanges" /></th>
                         <th>Patient</th>
                         <th>Time</th>
                         <th>Status</th>
                         <th></th>
                     </tr>
                     </thead>
-                    <tbody>
+                    <tbody id="apptsConfirmationChanges">
                     @foreach($apptsPending['decision'] as $appt)
                         <tr discardable-container>
+                            <td><input type="checkbox" name="uids[]" value="{{ $appt->uid }}" select-appt /></td>
                             <td>
                                 <a class="d-block"
                                    href="/patients/view/{{$appt->client->uid}}">{{$appt->client->displayName()}}</a>
@@ -123,3 +133,69 @@ $apptsPending = [
     </div>
 
 </div>
+
+<script>
+    (function($){
+        const BulkAckAppointments = {
+            handleOnCheck: function(container){
+                const selectedAppts = container.find('input[type=checkbox]:checked');
+                    const button = $(container).closest('.card').find('.card-header').find('button');
+                    if(selectedAppts.length){
+                        button.find('span').text(selectedAppts.length);
+                        button.removeClass('d-none');
+                    }else{
+                        button.addClass('d-none');
+                    }
+            },
+            onCheck: function(){
+                var self = this;
+                $('[select-appt]').click(function(evt){
+                    const container = $(evt.currentTarget).closest('tbody');
+                    self.handleOnCheck(container);
+                });
+            },
+            onCheckAll: function(){
+                var self = this;
+                $('[select-all-appts]').click(function(evt){
+                    const isChecked = evt.currentTarget.checked ? true:false;
+
+                    const containerTargetRef = $(evt.currentTarget).data('target');
+                    const container = $(containerTargetRef);
+                    container.find('input[type=checkbox]').prop('checked', isChecked);
+                    self.handleOnCheck(container);
+                });
+            },
+            onSubmit: function(){
+                var self = this;
+                $('[submit-ack-appts]').click(function(evt){
+                    const action = $(evt.currentTarget).data('action');
+                    const container = $(evt.currentTarget).closest('.card').find('tbody');
+                    const checkedInputs = container.find('[select-appt]:checked');
+                    console.log({checkedInputs});
+                    const UIDS = [];
+                    $.each(checkedInputs, function(index, input){
+                        const value  = input.value;
+                        UIDS.push(value);
+                    });
+
+                    $.post('/acknowledge-as-appointment-pro', {uids: UIDS, action: action}, function(response){
+                        if(response.success){
+                            toastr.success();
+                            location.reload();
+                        }else{
+                            toastr.error(response.message);
+                            location.reload();
+                        }
+                    }, 'json');
+
+                });
+            },
+            init: function(){
+                this.onCheck();
+                this.onCheckAll();
+                this.onSubmit();
+            }
+        };
+        BulkAckAppointments.init();
+    })(jQuery);
+</script>

+ 2 - 0
routes/web.php

@@ -83,6 +83,8 @@ Route::middleware('pro.auth')->group(function () {
 
     Route::get('/can-access-patient/{uid}', 'HomeController@canAccessPatient')->name('can-access-patient');
 
+    Route::post('/acknowledge-as-appointment-pro', 'AppointmentController@acknowledgeAsAppointmentPro')->name('acknowledge-as-appointment-pro');
+
     Route::name('mcp.')->prefix('m')->middleware('pro.auth.mcp')->group(function () {
 
         Route::get('dashboard', 'HomeController@dashboard_MCP')->name('dashboard');