Browse Source

Remote monitoring matrix (wip)

Vijayakrishnan 3 years ago
parent
commit
ec9bd1adad

+ 51 - 33
app/Http/Controllers/PracticeManagementController.php

@@ -980,42 +980,54 @@ class PracticeManagementController extends Controller
         $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
         $careMonthStart = date($ym . '-01');
 
-        // filters
-        $filters = '';
-        $fmd = $request->input('fmd');
-        if($fmd && $fmd !== 'all') {
-            switch($fmd) {
-                case 'lt16':
-                    $filters .= ' AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL) ';
-                    break;
-                case 'gte16':
-                    $filters .= ' AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL) ';
-                    break;
-            }
-        }
-        $fcomm = $request->input('fcomm');
-        if($fcomm && $fcomm !== 'all') {
-            switch($fcomm) {
-                case 'not-done':
-                    $filters .= ' AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE OR care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL) ';
-                    break;
-                case 'done':
-                    $filters .= ' AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE AND care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NOT NULL) ';
-                    break;
-            }
-        }
-        $c = $request->input('c');
-        if($c) {
-            $filters .= ' AND client.uid = \'' . $request->input('c') . '\' ';
+        $rc = $request->input('rc') ?: 1;
+        $conditions = [];
+
+        $c_isMCP = "client.mcp_pro_id = {$performer->pro->id}";
+        $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
+        $c_hasDevice = "";
+        $c_lastVisitWithin90Days = "DATE_PART('day', client.most_recent_completed_mcp_note_date::timestamp - care_month.start_date::timestamp) <= 90";
+        $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
+        $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
+        $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)";
+
+        switch ($rc) {
+            case 1:
+                $conditions = [$c_isMCP];
+                break;
+            case 2:
+                $conditions = [$c_isMCP, $c_enrolledInRPM];
+                break;
+            case 3:
+                $conditions = [$c_isMCP, $c_enrolledInRPM]; // todo
+                break;
+            case 4:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_lastVisitWithin90Days];
+                break;
+            case 5:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_lastVisitWithin90Days, $c_spokenToThisMonth];
+                break;
+            case 8:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
+                break;
+            case 9:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_deviceUsed];
+                break;
         }
 
         $patients = DB::select(
             DB::raw(
                 "
-SELECT client.name_first, client.name_last, client.uid as client_uid,
+SELECT client.name_first, 
+       client.name_last, 
+       client.uid as client_uid, 
+       client.dob,
+       client.is_enrolled_in_rm,
+       client.most_recent_completed_mcp_note_date,
        care_month.uid as care_month_uid,
        care_month.id as care_month_id,
        care_month.start_date,
+       care_month.rm_total_time_in_seconds_by_mcp,
        care_month.number_of_days_with_remote_measurements,
        care_month.has_anyone_interacted_with_client_about_rm_outside_note,
        care_month.rm_num_measurements_not_stamped_by_mcp,
@@ -1026,13 +1038,19 @@ SELECT client.name_first, client.name_last, client.uid as client_uid,
        client.default_na_pro_id,
        client.rmm_pro_id,
        client.rme_pro_id,
-       client.cell_number
+       client.cell_number,
+       client.most_recent_cellular_bp_dbp_mm_hg,
+       client.most_recent_cellular_bp_sbp_mm_hg,
+       client.most_recent_cellular_bp_measurement_at,      
+       client.most_recent_cellular_weight_value,
+       client.most_recent_cellular_weight_measurement_at
 FROM care_month join client on care_month.client_id = client.id
 WHERE
-      EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
-  AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
-  {$filters}
-ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first ASC, client.name_last ASC
+      client.mcp_pro_id = {$performer->pro->id}
+      AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
+      AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
+      " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
+ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first, client.name_last
 "
             )
         );

+ 15 - 0
app/Models/Client.php

@@ -868,4 +868,19 @@ ORDER BY m.ts DESC
     public function mostRecentWeightMeasurement(){        
         return $this->hasOne(Measurement::class, 'id', 'most_recent_weight_measurement_id');
     }
+
+    public function hasBPDevice() {
+        $cbds = ClientBDTDevice::where('client_id', $this->id)->get();
+        foreach ($cbds as $cbd) {
+            if($cbd->is_active && !!$cbd->device && $cbd->device->is_active && $cbd->device->category === 'BP') return true;
+        }
+        return false;
+    }
+    public function hasWeightScaleDevice() {
+        $cbds = ClientBDTDevice::where('client_id', $this->id)->get();
+        foreach ($cbds as $cbd) {
+            if($cbd->is_active && !!$cbd->device && $cbd->device->is_active && $cbd->device->category === 'WEIGHT') return true;
+        }
+        return false;
+    }
 }

+ 10 - 0
public/css/style.css

@@ -2629,3 +2629,13 @@ body.stag-scrollbar-scrolling .stag-scrollbar[stag-h-scrollbar] .stag-scrollbar-
     border: 0;
     padding: 0;
 }
+.conditions-tree {
+    /*padding: 0.5rem;*/
+}
+.conditions-tree .condition>a {
+    display: block;
+    padding: 3px 5px;
+}
+.conditions-tree .condition-children {
+    padding-left: 1rem;
+}

+ 115 - 90
resources/views/app/practice-management/remote-monitoring.blade.php

@@ -12,99 +12,124 @@
                     <i class="fas fa-arrow-right text-sm mx-1"></i>
                     <b class="font-size-14">{{friendly_month(date((request()->input('y') ?: 'Y') . '-' . (request()->input('m') ?: 'm') . '-d'))}}</b>
                 </span>
-                <?php
-                $dateInput = [];
-                if(request()->input('m')) $dateInput[] = 'm=' . request()->input('m');
-                if(request()->input('y')) $dateInput[] = 'y=' . request()->input('y');
-                $dateInput = '&' . implode('&', $dateInput);
-                ?>
-                <select class="ml-auto max-width-200px form-control form-control-sm"
-                        onchange="fastLoad('/practice-management/remote-monitoring?fmd=' + this.value + '&fcomm={{request()->input('fcomm')}}{{$dateInput}}', true, false, false)">
-                    <option value="all" {{ !request()->input('fmd') || request()->input('fmd') === 'all' ? 'selected' : '' }}>All</option>
-                    <option value="lt16" {{ request()->input('fmd') === 'lt16' ? 'selected' : '' }}>Patients with &lt; 16 meas. days</option>
-                    <option value="gte16" {{ request()->input('fmd') === 'gte16' ? 'selected' : '' }}>Patients with &ge; 16 meas. days</option>
-                </select>
-                <select class="ml-3 max-width-200px form-control form-control-sm"
-                        onchange="fastLoad('/practice-management/remote-monitoring?fmd={{request()->input('fmd')}}&fcomm=' + this.value + '{{$dateInput}}', true, false, false)">
-                    <option value="all" {{ !request()->input('fcomm') || request()->input('fcomm') === 'all' ? 'selected' : '' }}>All</option>
-                    <option value="not-done" {{ request()->input('fcomm') === 'not-done' ? 'selected' : '' }}>Patients with whom comm. not done</option>
-                    <option value="done" {{ request()->input('fcomm') === 'done' ? 'selected' : '' }}>Patients with whom comm. done</option>
-                </select>
             </div>
+
+            <?php $rc = request()->input('rc') ? request()->input('rc') : 1; ?>
+
             <div class="card-body p-0">
-                <table class="table table-sm table-striped table-hover p-0 m-0">
-                    <thead class="bg-light">
-                    <tr>
-                        <th class="border-0">Patient</th>
-                        <th class="border-0">Relation</th>
-                        <th class="border-0">Measurement Days</th>
-                        <th class="border-0">Unstamped Measurements</th>
-                        
-                        <th class="border-0">Phone</th>
-                    </tr>
-                    </thead>
-                    <tbody>
-                    @foreach ($patients as $iPatient)
-                        <tr>
-                            <td class="">
-                                <a href="/patients/view/{{ $iPatient->client_uid }}">{{ $iPatient->name_first }} {{ $iPatient->name_last }}</a>
-                            </td>
-                            <td class="">
-                                @if($iPatient->mcp_pro_id === $pro->id)
-                                    <div>MCP</div>
-                                @endif
-                                @if($iPatient->default_na_pro_id === $pro->id)
-                                    <div>Care Coordinator</div>
-                                @endif
-                                @if($iPatient->rmm_pro_id === $pro->id)
-                                    <div>RMM</div>
-                                @endif
-                                @if($iPatient->rme_pro_id === $pro->id)
-                                    <div>RME</div>
-                                @endif
-                            </td>
-                            <td class="">
-                                <span class="d-inline-block width-30px">{{$iPatient->number_of_days_with_remote_measurements ?: '0'}}</span>
-                                <span class="">
-                                <?php $moreMDNeeded = 16 - $iPatient->number_of_days_with_remote_measurements; ?>
-                                @if($iPatient->number_of_days_with_remote_measurements >= 16)
-                                    <i class="fa fa-check text-success" title="16 measurement days reached"></i>
-                                @elseif($daysRemaining >= $moreMDNeeded)
-                                    <i class="fa fa-exclamation-triangle text-warning-mellow" title="{{$moreMDNeeded}} more measurement day{{$moreMDNeeded > 1 ? 's' : ''}} needed"></i>
-                                @elseif($daysRemaining < $moreMDNeeded)
-                                    <i class="fa fa-exclamation-triangle text-secondary opacity-60" title="Can no longer reach 16 measurement days this month"></i>
-                                @endif
-                                </span>
-                            </td>
-                            <td class="">
-                                <?php $numUS = 0; ?>
-                                @if($iPatient->mcp_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_mcp; ?>
-                                @elseif($iPatient->default_na_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_non_hcp; ?>
-                                @elseif($iPatient->rmm_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_rmm; ?>
-                                @elseif($iPatient->rme_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_rme; ?>
-                                @endif
-                                <span class="d-inline-block width-30px">{{$numUS ?: '-'}}</span>
-                                @if($numUS || true)
-                                    <a native target="_blank"
-                                       open-in-stag-popup
-                                       update-parent
-                                       mc-initer="remote-monitoring-measurements-{{$iPatient->care_month_id}}"
-                                       title="{{ $iPatient->name_first }} {{ $iPatient->name_last }} / Unstamped Measurements / {{ friendly_month($careMonthStart) }}"
-                                       href="/remote-monitoring-measurements/{{$iPatient->care_month_uid}}">View</a>
-                                @endif
-                            </td>
+                <div class="row m-0">
+                    <div class="col-3 p-0">
+                        <div class="conditions-tree">
+                            <div class="condition">
+                                <a href="{{route('practice-management.remote-monitoring')}}?rc=1" {!! $rc == 1 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Who am I the MCP for?</a>
+                                <div class="condition-children">
+                                    <div class="condition">
+                                        <a href="{{route('practice-management.remote-monitoring')}}?rc=2" {!! $rc == 2 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Which of them is enrolled in RPM?</a>
+                                        <div class="condition-children">
+                                            <div class="condition">
+                                                <a href="{{route('practice-management.remote-monitoring')}}?rc=3" {!! $rc == 3 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Which of them has been given a cellular device?</a>
+                                                <div class="condition-children">
+                                                    <div class="condition">
+                                                        <a href="{{route('practice-management.remote-monitoring')}}?rc=4" {!! $rc == 4 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Which of them have I seen w/in 90 days?</a>
+                                                        <div class="condition-children">
+                                                            <div class="condition">
+                                                                <a href="{{route('practice-management.remote-monitoring')}}?rc=5" {!! $rc == 5 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Which of them have I spoken to this month?</a>
+                                                                <div class="condition-children">
+                                                                    <div class="condition">
+                                                                        <a href="{{route('practice-management.remote-monitoring')}}?rc=6" {!! $rc == 6 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How am I doing regarding their stamping?</a>
+                                                                    </div>
+                                                                    <div class="condition">
+                                                                        <a href="{{route('practice-management.remote-monitoring')}}?rc=7" {!! $rc == 7 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How are they doing regarding hitting 16 days?</a>
+                                                                    </div>
+                                                                </div>
+                                                            </div>
+                                                        </div>
+                                                    </div>
+                                                    <div class="condition">
+                                                        <a href="{{route('practice-management.remote-monitoring')}}?rc=8" {!! $rc == 8 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Which of them has subscribed to SMS confirmation texts?</a>
+                                                    </div>
+                                                    <div class="condition">
+                                                        <a href="{{route('practice-management.remote-monitoring')}}?rc=9" {!! $rc == 9 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Which of them has used the device?</a>
+                                                    </div>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-9 border-left p-0">
+                        <table class="table table-sm table-striped table-hover p-0 m-0">
+                            <thead class="bg-light">
+                            <tr>
+                                <th class="border-0">Name</th>
+                                <!--<th class="border-0">Relation</th>-->
+
+                                <th class="border-0">DOB</th>
+                                <th class="border-0">Enrolled in RPM?</th>
+                                <th class="border-0">Cellular BP?</th>
+                                <th class="border-0">Cellular Scale?</th>
+                                <th class="border-0">Latest BP</th>
+                                <th class="border-0">Latest Weight</th>
+                                <th class="border-0">Latest Visit</th>
+                                <th class="border-0">RPM Interaction This Month?</th>
+                                <th class="border-0">Measurements Pending Stamp</th>
+                                <th class="border-0"># Meas. Days This Month</th>
+                                <th class="border-0"># RPM Minutes</th>
+
+                            </tr>
+                            </thead>
+                            <tbody>
+                            @foreach ($patients as $iPatient)
+                                <?php $oPatient = \App\Models\Client::where('uid', $iPatient->client_uid)->first(); ?>
+                                <tr>
+                                    <td class="">
+                                        <a href="/patients/view/{{ $iPatient->client_uid }}">{{ $iPatient->name_first }} {{ $iPatient->name_last }}</a>
+                                    </td>
+                                    <!--<td class="">
+                                        @if($iPatient->mcp_pro_id === $pro->id)
+                                            <div>MCP</div>
+                                        @endif
+                                        @if($iPatient->default_na_pro_id === $pro->id)
+                                            <div>Care Coordinator</div>
+                                        @endif
+                                        @if($iPatient->rmm_pro_id === $pro->id)
+                                            <div>RMM</div>
+                                        @endif
+                                        @if($iPatient->rme_pro_id === $pro->id)
+                                            <div>RME</div>
+                                        @endif
+                                    </td>-->
+
+                                    <td>{{friendly_date($iPatient->dob)}}</td>
+                                    <td>{{ucwords(strtolower($iPatient->is_enrolled_in_rm ?: ''))}}</td>
+                                    <td>{{$oPatient->hasBPDevice() ? 'Yes' : 'No'}}</td>
+                                    <td>{{$oPatient->hasBPDevice() ? 'Yes' : 'No'}}</td>
+                                    <td>
+                                        {{$iPatient->most_recent_cellular_bp_sbp_mm_hg ?: '-'}}/{{$iPatient->most_recent_cellular_bp_dbp_mm_hg ?: '-'}}
+                                        @if($iPatient->most_recent_cellular_bp_measurement_at)
+                                            <div class="text-sm text-secondary text-nowrap">{{friendly_date_time($iPatient->most_recent_cellular_bp_measurement_at)}}</div>
+                                        @endif
+                                    </td>
+                                    <td>
+                                        {{$iPatient->most_recent_cellular_weight_value ?: '-'}}
+                                        @if($iPatient->most_recent_cellular_weight_measurement_at)
+                                            <div class="text-sm text-secondary text-nowrap">{{friendly_date_time($iPatient->most_recent_cellular_weight_measurement_at)}}</div>
+                                        @endif
+                                    </td>
+                                    <td>{{$iPatient->most_recent_completed_mcp_note_date ? friendly_date($iPatient->most_recent_completed_mcp_note_date) : '-'}}</td>
+                                    <td>{{$iPatient->has_anyone_interacted_with_client_about_rm_outside_note ? 'Yes' : 'No'}}</td>
+                                    <td>{{$iPatient->rm_num_measurements_not_stamped_by_mcp}}</td>
+                                    <td>{{$iPatient->number_of_days_with_remote_measurements ?: 0}}</td>
+                                    <td>{{floor($iPatient->rm_total_time_in_seconds_by_mcp / 60)}}</td>
 
-                            <td class="">
-                                {{$iPatient->cell_number}}
-                            </td>
-                        </tr>
-                    @endforeach
-                    </tbody>
-                </table>
+                                </tr>
+                            @endforeach
+                            </tbody>
+                        </table>
+                    </div>
+                </div>
             </div>
         </div>
     </div>

+ 1 - 1
resources/views/layouts/template.blade.php

@@ -123,6 +123,7 @@
                         <i class="mr-1 fas fa-tasks"></i> Practice
                     </a>
                     <div class="dropdown-menu mcp-theme-1 no-overflow-menu p-0" aria-labelledby="practice-management">
+                        <a class="dropdown-item" href="{{ route('practice-management.remote-monitoring') }}">Remote Monitoring</a>
                         @if($pro->pro_type == 'ADMIN')
                             <a class="dropdown-item" href="{{ route('practice-management.rpmMatrix') }}">RPM Matrix</a>
                             {{--<a class="dropdown-item" href="{{ route('practice-management.previousBills') }}">Previous Bills</a>--}}
@@ -130,7 +131,6 @@
                             <a class="dropdown-item" href="/practice-management/bills/not-yet-signed">Pending Bills to Sign</a>
                             <a class="dropdown-item" href="/practice-management/notes/not-yet-signed">Pending Notes to Sign</a>
                             <a class="dropdown-item" href="/practice-management/notes/not-yet-signed-but-ally-signed">Pending Notes to Sign (Ally Signed)</a>
-                            <a class="dropdown-item" href="{{ route('practice-management.remote-monitoring') }}">Remote Monitoring</a>
                             <a class="dropdown-item" href="{{ route('pro-care-month-report') }}">Care Month Report</a>
                             <a class="dropdown-item" href="{{ route('practice-management.rm-bills-to-sign') }}">RM Bills to Sign</a>
                             <a class="dropdown-item" href="{{ route('unmapped-sms') }}">Unmapped SMS</a>