Jelajahi Sumber

Update appointment Pro

Samson Mutunga 3 tahun lalu
induk
melakukan
3799c0fc26

+ 5 - 1
app/Http/Controllers/HomeController.php

@@ -1870,7 +1870,11 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
 
         // for calendar select2
         if($request->input('json')) {
-            $jsonPros = $suggestedPros->map(function($_pro) {
+            $onlyProsThatCanAccessClientUid = $request->get('canAccessClientUid');
+            $jsonPros = $suggestedPros->map(function($_pro) use($onlyProsThatCanAccessClientUid) {
+                if($onlyProsThatCanAccessClientUid){
+                    if(!$_pro->canAccess($onlyProsThatCanAccessClientUid)) return false;
+                }
                 return [
                     "uid" => $_pro->uid,
                     "id" => $_pro->id,

+ 50 - 7
resources/views/app/patient/appointment-calendar.blade.php

@@ -316,7 +316,7 @@
                                class="form-control form-control-sm"
                                :value="editAppointment.proName" readonly> -->
                         <!-- -- -->
-                        <select id="updateApptPro" name="proUid" {{$pro->pro_type !== 'ADMIN' ? '' : 'provider-search'}}
+                        <select id="updateApptPro" name="proUid" {{$pro->pro_type !== 'ADMIN' ? '' : 'pros-can-access-client-search'}}
                                 v-model="editAppointment.proUid"
                                 :data-pro-uid="editAppointment.proUid"
                                 no-auto-pro-suggest-init
@@ -327,6 +327,8 @@
                                         {{$iPro->displayName()}}
                                     </option>
                                 @endforeach
+                            @else
+                                <option :value="editAppointment.proUid" selected>@{{ editAppointment.proName }}</option>
                             @endif
                         </select>
                     </div>
@@ -740,6 +742,7 @@
                         nextPaletteIndex: 0,
                         palette: {!! json_encode($palette) !!},
                         proMeta: {},
+                        updateProUid:false,
                     },
                     methods: {
                         // init
@@ -822,8 +825,14 @@
                             $('#addApptPro').on('change', function() {
                                 self.newAppointment.proUid = $(this).val();
                             });
-                            $('#editApptPro, #updateApptPro').on('change', function() {
+                            $('#editApptPro').on('change', function() {
+                                self.editAppointment.proUid = $(this).val();
+                            });
+                            $('#updateApptPro').on('change', function() {
                                 self.editAppointment.proUid = $(this).val();
+                                if(!self.updateProUid){
+                                    self.updateProUid = true;
+                                }
                             });
                         },
                         initCalendar: function () {
@@ -1128,6 +1137,7 @@
                                 });
                         },
                         showEditAppointmentModal: function() {
+                            var self = this;
                             // setup model data
                             this.inProgress = false;
                             this.editAppointment.uid = this.selectedEvent.extendedProps.appointmentUid;
@@ -1159,11 +1169,8 @@
                             this.editAppointment.status = this.selectedEvent.extendedProps.status;
                             this.editAppointment.isTrainingEvent = this.selectedEvent.extendedProps.isTrainingEvent;
                             Vue.nextTick(function() {
-                                $('#updateApptPro').find('option').prop('selected', false);
-                                $('#updateApptPro').trigger('change');
                                 showStagPopup('client-edit-appointment', true);
-                                $('#updateApptPro').removeAttr('no-auto-pro-suggest-init').removeAttr('pro-suggest-initialized');
-                                initProSuggest();
+                                self.initAutoSuggestAppointmentProsAllowedToAccessClients();
 
                             });
 
@@ -1329,13 +1336,19 @@
                                 form[0].reportValidity();
                                 return false;
                             }
+                            
+                            var url = form.attr('action');
+                            if(this.updateProUid){
+                                url = '/api/appointment/updateProDateAndTime';
+                            }
 
                             this.inProgress = true;
                             let self = this;
                             showMask();
-                            $.post(form.attr('action'), form.serialize(), function(_data) {
+                            $.post(url, form.serialize(), function(_data) {
                                 if(_data) {
                                     if(_data.success) {
+                                        self.updateProUid = false;
                                         self.refreshEvents();
                                         closeStagPopup();
                                     }
@@ -1377,6 +1390,36 @@
                                 hideMask();
                             }, 'json');
                         },
+                        initAutoSuggestAppointmentProsAllowedToAccessClients: function(){
+                            var select2 = $("[pros-can-access-client-search]").select2({
+                            placeholder: "Search Pro",
+                            minimumInputLength: 2,
+                            ajax: {
+                                url: '/pro-suggest',
+                                dataType: 'json',
+                                type: "GET",
+                                quietMillis: 50,
+                                data: function (params) {
+                                    return {
+                                        term: params.term,
+                                        json: true,
+                                        canAccessClientUid: "{{ $patient->uid }}"
+                                    };
+                                },
+                                processResults: function (data) {
+                                    data = data.results || [];
+                                    return {
+                                        results: $.map(data, function (item) {
+                                            return {
+                                                text: item.text,
+                                                id: item.uid
+                                            }
+                                        })
+                                    };
+                                }
+                            }
+                        });
+                        },
                     },
                     mounted: function() {
                         this.init();