Переглянути джерело

Main dashboard - measurements tab - optimize queries

Vijayakrishnan 4 роки тому
батько
коміт
7922fc61e8

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

@@ -304,7 +304,49 @@ class HomeController extends Controller
 
         $milliseconds = strtotime(date('Y-m-d')) . '000';
 
-        $measurements = $performer->pro->getMeasurements();
+        // $measurements = $performer->pro->getMeasurements();
+
+        $myClientIDs = [];
+        if ($performer->pro->pro_type != 'ADMIN') {
+            $myClientIDs = $this->getMyClientIds();
+        }
+
+        $measurements = DB::select(
+            DB::raw(
+"
+SELECT measurement.uid as uid,
+       care_month.uid as care_month_uid,
+       measurement.label,
+       measurement.value,
+       measurement.sbp_mm_hg,
+       measurement.dbp_mm_hg,
+       measurement.numeric_value,
+       measurement.ts,
+       client.uid as client_uid,
+       client.name_last,
+       client.name_first,
+       care_month.rm_total_time_in_seconds
+FROM measurement
+         join client on measurement.client_id = client.id
+         join care_month on client.id = care_month.client_id
+WHERE measurement.label NOT IN ('SBP', 'DBP')
+  AND (measurement.is_cellular_zero = FALSE or measurement.is_cellular_zero IS NULL)
+  AND measurement.is_removed IS FALSE
+  AND measurement.ts IS NOT NULL
+  AND measurement.client_bdt_measurement_id IS NOT NULL
+  AND (measurement.status IS NULL OR (measurement.status <> 'ACK' AND measurement.status <> 'INVALID_ACK'))
+  AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
+  AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
+" .
+                (
+                    $performer->pro->pro_type != 'ADMIN' && count($myClientIDs) ?
+                        ' AND WHERE client.id IN (' . implode(", ", $myClientIDs) . ')' :
+                        ''
+                )
+            ) .
+" ORDER BY measurement.ts DESC LIMIT 12"
+
+        );
 
         // bills & claims
         $businessNumbers = [];

+ 137 - 0
resources/views/app/dashboard/measurements-eloquent.blade.php

@@ -0,0 +1,137 @@
+<div class="d-flex align-items-end mb-3">
+    <b class="large">Measurements in {{friendly_month(date('Y-m-d'))}}</b>
+</div>
+<table class="table table-striped table-sm table-bordered mb-0">
+    <thead>
+        <tr>
+            <th class="border-0 px-2 text-secondary">Patient</th>
+            <th class="border-0 px-2 text-secondary">Category</th>
+            <th class="border-0 px-2 text-secondary">Value</th>
+            <th class="border-0 px-2 text-secondary">Timestamp</th>
+            <th class="border-0 px-2 text-secondary">Mins this month</th>
+            <th class="border-0 px-2 text-secondary text-center">Stamp</th>
+            <th class="border-0 px-2 text-secondary text-center">Entry</th>
+        </tr>
+    </thead>
+    <tbody>
+        @if(count($measurements))
+            <?php foreach($measurements as $measurement): ?>
+                <?php if(in_array($measurement->label, ['SBP', 'DBP']) ) continue; ?>
+                <tr>
+                    <td class="px-2">
+                        <a href="/patients/view/{{$measurement->client->uid}}" class="font-weight-bold">
+                            {{ $measurement->client->name_first }} {{ $measurement->client->name_last }}
+                        </a>
+                    </td>
+                    <td class="px-2">{{ $measurement->label }}</td>
+                    <td class="px-2">
+                        @if($measurement->is_cellular_zero)
+                            <i class="font-size-11 fa fa-rss"></i>
+                        @elseif($measurement->label === 'BP')
+                            {{ $measurement->sbp_mm_hg }}/{{ $measurement->dbp_mm_hg }} mmHg
+                        @elseif($measurement->label === 'Wt. (lbs.)')
+                            {{ round(floatval($measurement->numeric_value), 2) }} lbs
+                        @else
+                            {{ $measurement->value }}
+                        @endif
+                    </td>
+                    <td>
+                        {{ friendly_date_time_short_with_tz_from_timestamp_divide1000($measurement->ts, 'EASTERN') }}
+                        EST
+                    </td>
+                    <td class="px-2">
+                        @if($measurement->careMonth)
+                        {{ floor($measurement->careMonth->rm_total_time_in_seconds/60) }}
+                        @endif
+                    </td>
+                    <td colspan="px-2">
+                        @if($measurement->clientBdtMeasurement)
+                        <span moe large relative>
+                            <a start show class="py-0 mb-3 font-weight-bold">Update status</a>
+                            <form url="/api/measurement/updateStatus" right>
+                                <input type="hidden" name="uid" value="{{$measurement->uid}}">
+                                <select name="status" id="" class="form-control input-sm">
+                                    <option value="">--select--</option>
+                                    <option value="ACK">Ok</option>
+                                    <option value="INVALID_ACK">Invalid</option>
+                                </select>
+                                <div class="d-flex align-items-center mt-2">
+                                    <button class="btn btn-sm btn-success mr-2" submit>Submit</button>
+                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </span>
+                        <div v-else class="text-center">-</div>
+                        @endif
+                    </td>
+                    <td colspan="px-2">
+                        @if($measurement->clientBdtMeasurement)
+                        <div class="text-center">
+                            <span moe large relative>
+                                <a start show class="py-0 mb-3 font-weight-bold">Add</a>
+                                <form url="/api/careMonthEntry/createForRm" right>
+                                    <p class="mb-2 d-block text-left"><b>Add RM Entry</b></p>
+                                    <input type="hidden" name="careMonthUid" value="{{$measurement->careMonth->uid}}">
+                                    <input type="hidden" name="proUid" value="{{$pro->uid}}">
+                                    <input type="hidden" name="effectiveDate" value="{{date('Y-m-d')}}">
+                                    <div class="bg-light border rounded p-2 mb-2">
+                                        <div class="mb-1 d-flex align-items-center">
+                                            <span class="width-50px text-left text-secondary">Type</span>
+                                            <div><b>{{ $measurement->label }} </b></div>
+                                        </div>
+                                        <div class="d-flex align-items-center">
+                                            <span class="width-50px text-left text-secondary">Value</span>
+                                            @if(!$measurement->clientBDTMeasurement)
+                                                <div><b>{{ $measurement->value }}</b></div>
+                                            @else
+                                                <div>
+                                                    @if($measurement->label == 'BP')
+                                                    <div>
+                                                        <b>{{ $measurement->clientBdtMeasurement->measurement->systolic_bp_in_mm_hg }}</b>/<b>{{ $measurement->clientBdtMeasurement->measurement->diastolic_bp_in_mm_hg }}</b> mmHg
+                                                    </div>
+                                                    @endif
+                                                    @if($measurement->label == 'Wt. (lbs.)')
+                                                    <div>
+                                                        <b>{{ floor($measurement->clientBdtMeasurement->measurement->weight_in_pounds)}}</b> lbs
+                                                    </div>
+                                                    @endif
+                                                </div>
+                                            @endif
+                                        </div>
+                                    </div>
+                                    <div class="mb-2">
+                                        <div class="row">
+                                            <div class="col-6 d-flex align-items-center">
+                                                <label class="text-secondary text-sm my-0 mr-3 text-nowrap">Time (mins)</label>
+                                                <input type="number" min="0" max="5400" class="form-control form-control-sm w-100 cm-time-value" name="timeInMinutes" value="" placeholder="Time (mins.)" required>
+                                            </div>
+                                        </div>
+                                    </div>
+                                    <div class="mb-2">
+                                        <div class="row">
+                                            <div class="col-12 text-left">
+                                                <label class="text-secondary text-sm mb-1">Details</label>
+                                                <textarea class="form-control form-control-sm" rows="4" name="contentText">{{ 'Reviewed ' . $measurement->label . ' measurement' }}</textarea>
+                                            </div>
+                                        </div>
+                                    </div>
+                                    <div class="d-flex align-items-center">
+                                        <button class="btn btn-sm btn-success mr-2" submit>Submit</button>
+                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </span>
+                        </div>
+                        @endif
+                    </td>
+                </tr>
+            <?php endforeach ?>
+        @else
+            <tr>
+                <td class="text-secondary p-0 p-3" colspan="7">
+                    No items to show
+                </td>
+            </tr>
+        @endif
+    </tbody>
+</table>

+ 18 - 28
resources/views/app/dashboard/measurements.blade.php

@@ -16,18 +16,15 @@
     <tbody>
         @if(count($measurements))
             <?php foreach($measurements as $measurement): ?>
-                <?php if(in_array($measurement->label, ['SBP', 'DBP']) ) continue; ?>
                 <tr>
                     <td class="px-2">
-                        <a href="/patients/view/{{$measurement->client->uid}}" class="font-weight-bold">
-                            {{ $measurement->client->name_first }} {{ $measurement->client->name_last }}
+                        <a href="/patients/view/{{$measurement->client_uid}}" class="font-weight-bold">
+                            {{ $measurement->name_first }} {{ $measurement->name_last }}
                         </a>
                     </td>
                     <td class="px-2">{{ $measurement->label }}</td>
                     <td class="px-2">
-                        @if($measurement->is_cellular_zero)
-                            <i class="font-size-11 fa fa-rss"></i>
-                        @elseif($measurement->label === 'BP')
+                        @if($measurement->label === 'BP')
                             {{ $measurement->sbp_mm_hg }}/{{ $measurement->dbp_mm_hg }} mmHg
                         @elseif($measurement->label === 'Wt. (lbs.)')
                             {{ round(floatval($measurement->numeric_value), 2) }} lbs
@@ -40,12 +37,13 @@
                         EST
                     </td>
                     <td class="px-2">
-                        @if($measurement->careMonth)
-                        {{ floor($measurement->careMonth->rm_total_time_in_seconds/60) }}
+                        @if($measurement->rm_total_time_in_seconds)
+                            {{ floor($measurement->rm_total_time_in_seconds/60) }}
+                        @else
+                            0
                         @endif
                     </td>
                     <td colspan="px-2">
-                        @if($measurement->clientBdtMeasurement)
                         <span moe large relative>
                             <a start show class="py-0 mb-3 font-weight-bold">Update status</a>
                             <form url="/api/measurement/updateStatus" right>
@@ -61,17 +59,14 @@
                                 </div>
                             </form>
                         </span>
-                        <div v-else class="text-center">-</div>
-                        @endif
                     </td>
                     <td colspan="px-2">
-                        @if($measurement->clientBdtMeasurement)
                         <div class="text-center">
                             <span moe large relative>
                                 <a start show class="py-0 mb-3 font-weight-bold">Add</a>
                                 <form url="/api/careMonthEntry/createForRm" right>
                                     <p class="mb-2 d-block text-left"><b>Add RM Entry</b></p>
-                                    <input type="hidden" name="careMonthUid" value="{{$measurement->careMonth->uid}}">
+                                    <input type="hidden" name="careMonthUid" value="{{$measurement->care_month_uid}}">
                                     <input type="hidden" name="proUid" value="{{$pro->uid}}">
                                     <input type="hidden" name="effectiveDate" value="{{date('Y-m-d')}}">
                                     <div class="bg-light border rounded p-2 mb-2">
@@ -81,22 +76,18 @@
                                         </div>
                                         <div class="d-flex align-items-center">
                                             <span class="width-50px text-left text-secondary">Value</span>
-                                            @if(!$measurement->clientBDTMeasurement)
-                                                <div><b>{{ $measurement->value }}</b></div>
-                                            @else
+                                            <div>
+                                                @if($measurement->label == 'BP')
+                                                <div>
+                                                    <b>{{ $measurement->sbp_mm_hg }}/{{ $measurement->dbp_mm_hg }} mmHg</b>
+                                                </div>
+                                                @endif
+                                                @if($measurement->label == 'Wt. (lbs.)')
                                                 <div>
-                                                    @if($measurement->label == 'BP')
-                                                    <div>
-                                                        <b>{{ $measurement->clientBdtMeasurement->measurement->systolic_bp_in_mm_hg }}</b>/<b>{{ $measurement->clientBdtMeasurement->measurement->diastolic_bp_in_mm_hg }}</b> mmHg
-                                                    </div>
-                                                    @endif
-                                                    @if($measurement->label == 'Wt. (lbs.)')
-                                                    <div>
-                                                        <b>{{ floor($measurement->clientBdtMeasurement->measurement->weight_in_pounds)}}</b> lbs
-                                                    </div>
-                                                    @endif
+                                                    <b>{{ round(floatval($measurement->numeric_value), 2) }}</b> lbs
                                                 </div>
-                                            @endif
+                                                @endif
+                                            </div>
                                         </div>
                                     </div>
                                     <div class="mb-2">
@@ -122,7 +113,6 @@
                                 </form>
                             </span>
                         </div>
-                        @endif
                     </td>
                 </tr>
             <?php endforeach ?>