Kaynağa Gözat

RM dashboard stats + filter fix

Vijayakrishnan 3 yıl önce
ebeveyn
işleme
dc02879208

+ 59 - 3
app/Http/Controllers/HomeController.php

@@ -260,9 +260,6 @@ class HomeController extends Controller
             })
             ->count();
 
-        // num measurements that need stamping
-        $keyNumbers['measurementsToBeStamped'] = $this->performer()->pro->getUnstampedMeasurements(true, null, null);
-
         // unacknowledged cancelled bills for authed pro
         $keyNumbers['unacknowledgedCancelledBills'] = Bill::where('hcp_pro_id', $performerProID)
             ->where('is_cancelled', true)
@@ -441,6 +438,65 @@ WHERE
             })
             ->count();
 
+        $count = DB::select(
+            DB::raw(
+                "
+SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
+WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
+          OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_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())') . "
+  AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL)
+"
+            )
+        );
+        $keyNumbers['rmPatientsWithLT16MD'] = $count[0]->cnt;
+
+        $count = DB::select(
+            DB::raw(
+                "
+SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
+WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
+          OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_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())') . "
+  AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL)
+"
+            )
+        );
+        $keyNumbers['rmPatientsWithGTE16MD'] = $count[0]->cnt;
+
+        $count = DB::select(
+            DB::raw(
+                "
+SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
+WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
+          OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_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())') . "
+  AND care_month.has_non_hcp_communicated_to_patient_about_rm = TRUE
+"
+            )
+        );
+        $keyNumbers['rmPatientsWithWhomCommDone'] = $count[0]->cnt;
+
+        $count = DB::select(
+            DB::raw(
+                "
+SELECT count(client.id) as cnt FROM client join care_month on care_month.client_id = client.id
+WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$performer->pro->id})
+          OR (client.rme_pro_id = {$performer->pro->id}) OR (client.default_na_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())') . "
+  AND care_month.has_non_hcp_communicated_to_patient_about_rm = FALSE
+"
+            )
+        );
+        $keyNumbers['rmPatientsWithWhomCommNotDone'] = $count[0]->cnt;
+
+        // num measurements that need stamping
+        $keyNumbers['measurementsToBeStamped'] = $this->performer()->pro->getUnstampedMeasurementsFromCurrentMonth(true, null, null);
+
         return view('app/dashboard', compact('keyNumbers', 'reimbursement', 'milliseconds',
             'businessNumbers',
             'incomingReports', 'tickets', 'supplyOrders',

+ 2 - 2
app/Http/Controllers/PracticeManagementController.php

@@ -707,10 +707,10 @@ class PracticeManagementController extends Controller
         if($fmd && $fmd !== 'all') {
             switch($fmd) {
                 case 'lt16':
-                    $filters .= ' AND care_month.number_of_days_with_remote_measurements < 16 ';
+                    $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 ';
+                    $filters .= ' AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL) ';
                     break;
             }
         }

+ 11 - 1
app/Models/Pro.php

@@ -370,13 +370,23 @@ class Pro extends Model
         return $allowed ? $clientPrograms : FALSE;
     }
 
-    public function getUnstampedMeasurements($_countOnly, $skip, $limit)
+    public function getUnstampedMeasurementsFromCurrentMonth($_countOnly, $skip, $limit)
     {
+
+        date_default_timezone_set('US/Eastern');
+
+        $start = strtotime(date('Y-m-01'));
+        $end = date_add(date_create(date('Y-m-01')), date_interval_create_from_date_string("1 month"))->getTimestamp();
+        $start *= 1000;
+        $end *= 1000;
+
         $measurementsQuery = Measurement::where('is_removed', false)
             ->join('client', 'client.id', '=', 'measurement.client_id')
             ->whereNotNull('measurement.client_bdt_measurement_id')
             ->whereNotNull('measurement.ts')
             ->where('measurement.is_cellular_zero', false)
+            ->where('measurement.ts', '>=', $start)
+            ->where('measurement.ts', '<', $end)
             ->whereIn('measurement.client_id', $this->getMyClientIds())
             ->where(function ($q) {
                 $q

+ 11 - 9
resources/views/app/dashboard.blade.php

@@ -100,33 +100,35 @@
                         <table class="table mb-0 dashboard-stats-table">
                             <tbody>
                             <tr>
-                                <th class="px-2 text-center">0</th>
+                                <th class="px-2 text-center">{{$keyNumbers['rmPatientsWithLT16MD']}}</th>
                                 <th class="pl-2">
-                                    <a native target="_top" href="#">Patients with < 16 meas. days</a>
+                                    <b>Patients with < 16 meas. days</b>
                                 </th>
                             </tr>
                             <tr>
-                                <th class="px-2 text-center">0</th>
+                                <th class="px-2 text-center">{{$keyNumbers['rmPatientsWithGTE16MD']}}</th>
                                 <th class="pl-2">
-                                    <a native target="_top" href="#">Patients with >= 16 meas. days</a>
+                                    <b>Patients with >= 16 meas. days</b>
                                 </th>
                             </tr>
+                            @if(!$pro->is_hcp)
                             <tr>
-                                <th class="px-2 text-center">0</th>
+                                <th class="px-2 text-center">{{$keyNumbers['rmPatientsWithWhomCommDone']}}</th>
                                 <th class="pl-2">
-                                    <a native target="_top" href="#">Patients with whom comm. not done</a>
+                                    <b>Patients with whom comm. not done</b>
                                 </th>
                             </tr>
                             <tr>
-                                <th class="px-2 text-center">0</th>
+                                <th class="px-2 text-center">{{$keyNumbers['rmPatientsWithWhomCommNotDone']}}</th>
                                 <th class="pl-2">
-                                    <a native target="_top" href="#">Patients with whom comm. done</a>
+                                    <b>Patients with whom comm. done</b>
                                 </th>
                             </tr>
+                            @endif
                             <tr>
                                 <th class="px-2 text-center">{{$keyNumbers['measurementsToBeStamped']}}</th>
                                 <th class="pl-2">
-                                    <a native target="_top" href="#" v-on:click.prevent="tab='measurements'">Unstamped Measurements</a>
+                                    <a href="{{route('practice-management.remote-monitoring')}}">Unstamped Measurements</a>
                                 </th>
                             </tr>
                             </tbody>