Pārlūkot izejas kodu

merged with dev-josh

Josh 4 gadi atpakaļ
vecāks
revīzija
a25d6cfaea

+ 19 - 9
app/Http/Controllers/HomeController.php

@@ -259,15 +259,27 @@ class HomeController extends Controller
         $totalExpectedAmount =  $expectedForHcp + $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
         $reimbursement['nextPaymentAmount'] =  $totalExpectedAmount;
 
+        $milliseconds = strtotime(date('Y-m-d')) . '000';
+
+        return view('app/dashboard', compact('keyNumbers', 'reimbursement', 'milliseconds'));
+    }
+
+    public function dashboardAppointments(Request $request, $from, $to) {
+
+        $performer = $this->performer();
+        $performerProID = $performer->pro->id;
+        $isAdmin = ($performer->pro->pro_type === 'ADMIN');
+
+        $appointments = Appointment::where("start_time", '>=', $from)->where("start_time", '<=', $to);
+
         if(!$isAdmin) {
-            $appointments = Appointment::where("pro_id", $performerProID)
-                ->orderBy('start_time', 'asc')
-                ->get();
-        }
-        else {
-            $appointments = Appointment::orderBy('start_time', 'asc')->get();
+            $appointments = $appointments->where("pro_id", $performerProID);
         }
 
+        $appointments = $appointments
+            ->orderBy('start_time', 'asc')
+            ->get();
+
         foreach ($appointments as $appointment) {
             $date = explode(" ", $appointment->start_time)[0];
             $appointment->milliseconds = strtotime($date) . '000';
@@ -297,9 +309,7 @@ class HomeController extends Controller
             $appointment->proName = $appointment->pro->displayName();
         }
 
-        $milliseconds = strtotime(date('Y-m-d')) . '000';
-
-        return view('app/dashboard', compact('keyNumbers', 'reimbursement', 'appointments', 'milliseconds'));
+        return json_encode($appointments);
     }
 
     public function patients(Request $request, $filter = '')

+ 8 - 6
public/js/mc.js

@@ -150,10 +150,12 @@ function onFastLoaded(_data, _href, _history) {
     _data = '<div>' + _data + '</div>';
     var content = $(_data).find('.stag-content');
     if (content && content.length) {
-        content = content.html();
-        content += '<script src="/js/yemi.js?_=7"></script>';
-        targetParent.html(content);
-        window.setTimeout(function () {
+
+        targetParent.html(content.html());
+        hideMask();
+        hideMoeFormMask();
+        targetParent.append('<script src="/js/yemi.js?_=7"></script>');
+        window.setTimeout(function() {
             initCreateNote();
             initQuillEdit();
             initFastLoad(targetParent);
@@ -172,9 +174,9 @@ function onFastLoaded(_data, _href, _history) {
         // fallback
         console.warn('MC: Target page failed: ' + _href);
         targetParent.html('<p class="text-danger p-3 small">Target page not found or returned error: <b>' + _href + '</b></p>');
+        hideMask();
+        hideMoeFormMask();
     }
-    hideMask();
-    hideMoeFormMask();
     $('html, body').removeClass('no-scroll');
 }
 function fastLoad(_href, _history = true, _useCache = true, _replaceState = false) {

+ 56 - 13
resources/views/app/dashboard.blade.php

@@ -109,7 +109,7 @@
                         <div>
                             Status: <b class="text-secondary">@{{ event.status }}</b>
                             &nbsp;/&nbsp;
-                            <a target="_top" :href="'/patients/view/' + event.clientUid + '/manage-appointment/' + event.uid">
+                            <a target="_top" :href="'/patients/view/' + event.clientUid + '/calendar/' + event.uid">
                                 <i class="fa fa-edit"></i>
                                 Edit Appointment
                             </a>
@@ -201,21 +201,42 @@
             data: {
                 selectedDate: '{{ date('Y-m-d') }}',
                 selectedStatus: 'CREATED',
-                events: {!! json_encode($appointments) !!},
+                events: [],
                 numEventsForDate: 0,
                 filterStatus: '',
+                calendarElem: null,
+                currentMonth: null,
+                currentYear: null,
             },
             methods: {
+                formatDate: function (date) {
+                    let d = new Date(date),
+                        month = '' + (d.getMonth() + 1),
+                        day = '' + d.getDate(),
+                        year = d.getFullYear();
+
+                    if (month.length < 2)
+                        month = '0' + month;
+                    if (day.length < 2)
+                        day = '0' + day;
+
+                    return [year, month, day].join('-');
+                },
                 onDateChange: function (_newDate) {
-                    this.highlightDatesWithEvents();
-                    this.selectedDate = _newDate;
-                    this.updateNumEventsForDate();
+                    // this.loadEvents();
+
+                    let self = this;
+                    self.selectedDate = _newDate;
+                    this.loadEvents(function() {
+                        self.highlightDatesWithEvents();
+                        self.updateNumEventsForDate();
+                    });
                 },
                 selectToday: function () {
                     $('.pro-dashboard-inline-calendar table td[data-date]').removeClass('active');
                     $('.pro-dashboard-inline-calendar table td[data-date="{{ $milliseconds }}"]')
                         .addClass('active');
-                    this.onDateChange('{{ date('Y-m-d') }}');
+                    // this.onDateChange('{{ date('Y-m-d') }}');
                 },
                 highlightDatesWithEvents: function () {
                     $('.pro-dashboard-inline-calendar table td[data-date]').removeAttr('has-events');
@@ -285,18 +306,40 @@
                     hideMoeFormMask();
                     form.hide();
                 },
+                loadEvents: function(_callback) {
+                    let today = this.calendarElem.datepicker('getDate'),
+                        firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1),
+                        lastOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0),
+                        self = this;
+                    if(this.currentMonth === today.getMonth() && this.currentYear === today.getFullYear()) {
+                        _callback.call(self);
+                    }
+                    else {
+                        $.get('/pro-dashboard-events/' +
+                            this.formatDate(firstOfMonth) + '/' +
+                            this.formatDate(lastOfMonth), function(_data) {
+                            self.events = _data;
+                            self.currentMonth = firstOfMonth.getMonth();
+                            self.currentYear = firstOfMonth.getFullYear();
+                            _callback.call(self);
+                        }, 'json');
+                    }
+                }
             },
             mounted: function () {
-                var calendarElem = $('.pro-dashboard-inline-calendar'), self = this;
-                calendarElem.datepicker({
+                let self = this;
+                this.calendarElem = $('.pro-dashboard-inline-calendar');
+                this.calendarElem.datepicker({
                     format: 'yyyy-mm-dd'
                 });
-                calendarElem.on('changeDate', function () {
-                    self.onDateChange(calendarElem.datepicker('getFormattedDate'));
+                this.calendarElem.on('changeDate', function () {
+                    self.onDateChange(self.calendarElem.datepicker('getFormattedDate'));
                 });
-                self.selectToday();
-                self.updateNumEventsForDate();
-                console.log(this.events)
+                this.selectToday();
+                this.updateNumEventsForDate();
+
+                // this.loadEvents();
+                $('.datepicker-days .day.active').trigger('click');
             }
         });
     });

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

@@ -11,7 +11,7 @@
     </div>
     <table class="table table-sm border-0 m-0">
         <tbody>
-        @foreach($patient->appointments as $appointment)
+        @foreach($patient->upcomingAppointments as $appointment)
             <tr>
                 <td class="text-black p-0 border-0 pb-1">
                     <div class="pb-0 d-flex align-items-center flex-wrap">

+ 4 - 0
routes/web.php

@@ -118,8 +118,12 @@ Route::middleware('pro.auth')->group(function () {
 
         // appointment calendar
         Route::get('calendar/{currentAppointment?}', 'PatientController@calendar')->name('calendar');
+
     });
 
+    // pro dashboard events (ajax)
+    Route::get('pro-dashboard-events/{from}/{to}', 'HomeController@dashboardAppointments')->name('pro-dashboard-events');
+
     // events for fc
     Route::get('/appointment/getAllAppointmentsForPros', 'AppointmentController@events')->name('events');