Răsfoiți Sursa

Poll and update patient presence without refresh

Vijayakrishnan Krishnan 4 ani în urmă
părinte
comite
38738e3ae4

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

@@ -139,4 +139,11 @@ class PatientController extends Controller
         $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
         return view('app.patient.care-months', compact('patient', 'careMonths'));
     }
+
+    public function presence(Request $request, Client $patient )
+    {
+        return json_encode([
+            "online" => $patient->is_online
+        ]);
+    }
 }

+ 25 - 0
public/js/mc.js

@@ -104,6 +104,7 @@ $(document).ready(function () {
     initQuillEdit();
     initFastLoad();
     initPrimaryForm();
+    initPatientPresenceIndicator();
     if(typeof initializeCalendar !== 'undefined') {
         initializeCalendar();
     }
@@ -215,6 +216,7 @@ function onFastLoaded(_data, _href, _history) {
             initQuillEdit();
             initFastLoad(targetParent);
             initPrimaryForm();
+            initPatientPresenceIndicator();
             $(window).scrollTop(0);
         }, 50);
         if(typeof initializeCalendar !== 'undefined') {
@@ -324,6 +326,7 @@ function initQuillEdit(_selector = '.note-content[auto-edit]') {
             $(this).attr('auto-edit', 1);
             initQuillEdit();
             initPrimaryForm();
+            initPatientPresenceIndicator();
         });
 
     if(!$(_selector).length) return;
@@ -354,4 +357,26 @@ function initQuillEdit(_selector = '.note-content[auto-edit]') {
     // });
 }
 
+function initPatientPresenceIndicator() {
+    var presenceTimer = false;
+    if(presenceTimer !== false) {
+        window.clearInterval(presenceTimer);
+        presenceTimer = false;
+    }
+    var elem = $('.patient-presence-indicator[data-patient-uid]');
+    if(elem.length) {
+        var patientUid = elem.attr('data-patient-uid');
+        presenceTimer = window.setInterval(function() {
+            $.get('/patients/' + patientUid + '/presence', function(_data) {
+                if(_data.online) {
+                    elem.addClass('online');
+                }
+                else {
+                    elem.removeClass('online');
+                }
+            }, 'json');
+        }, 2500);
+    }
+}
+
 

+ 6 - 2
resources/views/layouts/patient.blade.php

@@ -1,5 +1,7 @@
 @extends('layouts.template')
-
+<?php
+/** @var \App\Models\Client $patient */
+?>
 @section('content')
     <div class="container-fluid h-100">
         <div class="main-row h-100">
@@ -113,7 +115,9 @@
                                 </div>
                             @endif
                             <div class=hbox>
-                                <div class="thumbnail {{$online}}" style="background-image:<?=$thumbnail?>"><?=$initials?></div>
+                                <div class="patient-presence-indicator thumbnail {{$online}}"
+                                     data-patient-uid="{{$patient->uid}}"
+                                     style="background-image:<?=$thumbnail?>"><?=$initials?></div>
                                 <section>
                                     <div class=hbox>
                                         <h4>{{$patientName}}</h4>

+ 3 - 0
routes/web.php

@@ -77,6 +77,9 @@ Route::middleware('pro.auth')->group(function () {
         });
     });
 
+    // AJAX presence poll
+    Route::get('/patients/{patient}/presence', 'PatientController@presence');
+
     // 2-pane outer page housing lhs (practice management) and rhs (video call)
     Route::get('/mc/{fragment?}', 'HomeController@mc')
         ->where('fragment', '.*')