Ver Fonte

BDT devices refactor

Samson Mutunga há 1 ano atrás
pai
commit
8e805bc173

+ 9 - 30
app/Http/Controllers/AdminController.php

@@ -34,6 +34,7 @@ use Illuminate\Support\Facades\Http;
 use PDF;
 use Illuminate\Support\Facades\Schema;
 use App\Models\AdminPatient;
+use App\Models\BDTDeviceView;
 use App\Models\SupplyOrderView;
 
 class AdminController extends Controller
@@ -573,7 +574,7 @@ class AdminController extends Controller
     public function bdtDevices(Request $request)
     {
         $filters = $request->all();
-        $bdtDevices = BDTDevice::query();
+        $bdtDevices = BDTDeviceView::query();
 
         $imei = $request->input('imei');
         if($imei){
@@ -583,48 +584,26 @@ class AdminController extends Controller
 
         if($client){
             $client = '%'.$client.'%';
-            $bdtDevices = $bdtDevices->whereHas('clientBDTDevice', function($cbdtdQuery) use ($client) {
-                return $cbdtdQuery->whereHas('client', function($clientQuery) use ($client){
-                    return $clientQuery->where(function($q) use ($client){
-                        return $q->where('name_first', 'ilike', $client)
-                        ->orWhere('name_last', 'ilike', $client)
-                        ->orWhere('cell_number', 'ilike', $client)
-                        ->orWhereRaw("name_first||' '||name_last ILIKE "."'".$client."'");
-                    });
-                });
-            });
-        }
-
-        $is_issued = $request->input('is_issued');
-        if($is_issued){
-            if($is_issued == 'YES'){
-                $bdtDevices = $bdtDevices->whereHas('clientBDTDevice');
-            }
-
-            if($is_issued == 'NO'){
-                $bdtDevices = $bdtDevices->whereDoesntHave('clientBDTDevice');
-            }
+            $bdtDevices = $bdtDevices->where('client_name_first', 'ilike', $client)
+            ->orWhere('client_name_last', 'ilike', $client)
+            ->orWhere('client_cell_number', 'ilike', $client)
+            ->orWhereRaw("client_name_first||' '||client_name_last ILIKE "."'".$client."'");
         }
 
         $is_issued = $request->input('is_issued');
         if($is_issued){
             if($is_issued == 'YES'){
-                $bdtDevices = $bdtDevices->whereHas('clientBDTDevice');
+                $bdtDevices = $bdtDevices->whereRaw('client_id IS NOT NULL');
             }
 
             if($is_issued == 'NO'){
-                $bdtDevices = $bdtDevices->whereDoesntHave('clientBDTDevice');
+                $bdtDevices = $bdtDevices->whereRaw('client_id IS NULL');
             }
         }
 
         $mcp = $request->input('mcp');
         if($mcp){
-            $bdtDevices = $bdtDevices->whereHas('clientBDTDevice', function($cbdtdQuery) use ($mcp) {
-                return $cbdtdQuery->whereHas('client', function($clientQuery) use ($mcp){
-                    $mcpPro = Pro::where('uid', $mcp)->first();
-                    return $clientQuery->where('mcp_pro_id', $mcpPro->id);
-                });
-            });
+            $bdtDevices = $bdtDevices->where('client_mcp_pro_uid', $mcp);
         }
 
         $bdtDevices = $bdtDevices->paginate(20);

+ 9 - 0
app/Models/BDTDeviceView.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace App\Models;
+
+class BDTDeviceView extends Model
+{
+    protected $table = 'bdt_device_view';
+
+}

+ 120 - 0
resources/views/app/admin/bdt_devices_table.blade copy.php

@@ -0,0 +1,120 @@
+	<table class="table table-striped p-0 m-0 table-sm border-top border-bottom ">
+		<thead class="bg-light">
+			<tr>
+				<th class="border-0">Device Type</th>
+				<th class="border-0">IMEI</th>
+				<th class="border-0">Issued Yet?</th>
+				<th class="border-0">Client</th>
+				<th class="border-0">Used?</th>
+				<th class="border-0">MCP</th>
+				<th class="border-0">Issue Date</th>
+				<th class="border-0">Supply Order Status</th>
+				<th class="border-0">Last Meas. Date</th>
+				<th class="border-0">Last Meas. Days Ago</th>
+				<th class="border-0"># Days with Remote Meas. this Month</th>
+				<th class="border-0"># Days with Remote Meas. last Month</th>
+				<th class="border-0">Client Engagement Status Category</th>
+				<th class="border-0">Admin Engagement Assessment Status</th>
+				<th class="border-0">Mcp Engagement Assessment Status</th>
+				<th class="border-0">Default Na Engagement Assessment Status</th>
+			</tr>
+		</thead>
+		<tbody>
+			@foreach($bdtDevices as $bdtDevice)
+			<tr>
+				<td>{{$bdtDevice->category}}</td>
+				<td>{{$bdtDevice->imei}}</td>
+				<td>{{$bdtDevice->client_id ? 'Yes': 'No'}}</td>
+				<td>
+					@if($bdtDevice->client_id)
+					<a native target="_blank" href="{{route('patients.view.dashboard',$bdtDevice->client_uid)}}">
+						{{$bdtDevice->client_display_name}}
+					</a>
+					@else 
+						-
+					@endif 
+				</td>
+				<td>{{@$bdtDevice->most_recent_client_bdt_measurement_id ? 'Yes': 'No'}}</td>
+				<td>
+					@if($bdtDevice->client_id && $bdtDevice->client_mcp_pro_id)
+						{{$bdtDevice->mcp_pro_display_name}}
+					@else 
+						-
+					@endif 
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+						{{friendly_date_time($bdtDevice->clientBDTDevice->created_at)}}
+					@else 
+						-
+					@endif 
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+						@foreach($bdtDevice->clientBDTDevice->supplyOrders as $so)
+							<div class="card p-2 shadow m-2 border">
+								<div>Product: {{$so->product->title}}</div>
+								<div>Is signed by pro: {{$so->is_signed_by_pro ? 'Yes' : 'No'}}</div>
+								@if($so->is_signed_by_pro)
+									<div>Signed by: {{$so->signedPro->name_first}} {{$so->signedPro->name_last}}</div>
+								@endif
+								<div>
+									Has shippiment: {{$so->shipment? 'Yes': 'No'}}
+								</div>
+							</div>
+						@endforeach
+					@else 
+						-
+					@endif 	
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+						@if($bdtDevice->clientBDTDevice->mostRecentMeasurement)
+							{{friendly_date_time($bdtDevice->clientBDTDevice->mostRecentMeasurement->measurement->ts_date_time)}}
+						@else 
+							-
+						@endif
+					@else 
+						-
+					@endif 	
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+						@if($bdtDevice->clientBDTDevice->mostRecentMeasurement)
+							{{date_diff(date_create($bdtDevice->clientBDTDevice->mostRecentMeasurement->measurement->ts_date_time), date_create('now'))->days}}
+						@else 
+							-
+						@endif
+					@else 
+						-
+					@endif 	
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+						{{$bdtDevice->clientBDTDevice->client->currentCareMonth()->number_of_days_with_remote_measurements}}
+					@endif
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+						{{$bdtDevice->clientBDTDevice->client->previousCareMonth()->number_of_days_with_remote_measurements}}
+					@endif
+				</td>
+				<td>{{@$bdtDevice->clientBDTDevice->client->client_engagement_status_category}}
+				<td>{{@$bdtDevice->clientBDTDevice->client->adminEngagementAssessmentStatus->status_category}}
+				<td>{{@$bdtDevice->clientBDTDevice->client->mcpEngagementAssessmentStatus->status_category}}
+				<td>{{@$bdtDevice->clientBDTDevice->client->defaultNaEngagementAssessmentStatus->status_category}}
+			</tr>
+			@endforeach
+		
+			@if(count($bdtDevices) === 0)
+			<tr>
+				<td colspan="24">No records found!</td>
+			</tr>
+			@endif
+		</tbody>
+
+	</table>
+</div>
+<div class="p-3">
+	{{$bdtDevices->withQueryString()->links()}}
+</div>

+ 30 - 27
resources/views/app/admin/bdt_devices_table.blade.php

@@ -24,42 +24,45 @@
 			<tr>
 				<td>{{$bdtDevice->category}}</td>
 				<td>{{$bdtDevice->imei}}</td>
-				<td>{{$bdtDevice->clientBDTDevice ? 'Yes': 'No'}}</td>
+				<td>{{$bdtDevice->client_id ? 'Yes': 'No'}}</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice)
-					<a native target="_blank" href="{{route('patients.view.dashboard',$bdtDevice->clientBDTDevice->client)}}">
-						{{$bdtDevice->clientBDTDevice->client->displayName()}}
+					@if($bdtDevice->client_id)
+					<a native target="_blank" href="{{route('patients.view.dashboard',$bdtDevice->client_uid)}}">
+						{{$bdtDevice->client_display_name}}
 					</a>
 					@else 
 						-
 					@endif 
 				</td>
-				<td>{{@$bdtDevice->clientBDTDevice->mostRecentMeasurement ? 'Yes': 'No'}}</td>
+				<td>{{@$bdtDevice->most_recent_client_bdt_measurement_id ? 'Yes': 'No'}}</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice && $bdtDevice->clientBDTDevice->client && $bdtDevice->clientBDTDevice->client->mcp)
-						{{$bdtDevice->clientBDTDevice->client->mcp->name_first}} {{$bdtDevice->clientBDTDevice->client->mcp->name_last}}
+					@if($bdtDevice->client_id && $bdtDevice->client_mcp_pro_id)
+						{{$bdtDevice->mcp_pro_display_name}}
 					@else 
 						-
 					@endif 
 				</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice)
-						{{friendly_date_time($bdtDevice->clientBDTDevice->created_at)}}
+					@if($bdtDevice->client_id)
+						{{friendly_date_time($bdtDevice->client_bdt_created_at)}}
 					@else 
 						-
 					@endif 
 				</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice)
-						@foreach($bdtDevice->clientBDTDevice->supplyOrders as $so)
+					@if($bdtDevice->client_id)
+						<?php
+							$supplyOrders = json_decode($bdtDevice->supply_orders ?? '[]');
+						?>
+						@foreach($supplyOrders as $so)
 							<div class="card p-2 shadow m-2 border">
-								<div>Product: {{$so->product->title}}</div>
+								<div>Product: {{$so->product_title}}</div>
 								<div>Is signed by pro: {{$so->is_signed_by_pro ? 'Yes' : 'No'}}</div>
 								@if($so->is_signed_by_pro)
-									<div>Signed by: {{$so->signedPro->name_first}} {{$so->signedPro->name_last}}</div>
+									<div>Signed by: {{$so->signed_by_pro_name}}</div>
 								@endif
 								<div>
-									Has shippiment: {{$so->shipment? 'Yes': 'No'}}
+									Has shippiment: {{$so->shipment_id? 'Yes': 'No'}}
 								</div>
 							</div>
 						@endforeach
@@ -68,9 +71,9 @@
 					@endif 	
 				</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice)
-						@if($bdtDevice->clientBDTDevice->mostRecentMeasurement)
-							{{friendly_date_time($bdtDevice->clientBDTDevice->mostRecentMeasurement->measurement->ts_date_time)}}
+					@if($bdtDevice->client_id)
+						@if($bdtDevice->most_recent_client_bdt_measurement_id)
+							{{friendly_date_time($bdtDevice->most_recent_measurement_ts_date_time)}}
 						@else 
 							-
 						@endif
@@ -79,9 +82,9 @@
 					@endif 	
 				</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice)
-						@if($bdtDevice->clientBDTDevice->mostRecentMeasurement)
-							{{date_diff(date_create($bdtDevice->clientBDTDevice->mostRecentMeasurement->measurement->ts_date_time), date_create('now'))->days}}
+					@if($bdtDevice->client_id)
+						@if($bdtDevice->most_recent_client_bdt_measurement_id)
+							{{date_diff(date_create($bdtDevice->most_recent_measurement_ts_date_time), date_create('now'))->days}}
 						@else 
 							-
 						@endif
@@ -90,19 +93,19 @@
 					@endif 	
 				</td>
 				<td>
-					@if($bdtDevice->clientBDTDevice)
-						{{$bdtDevice->clientBDTDevice->client->currentCareMonth()->number_of_days_with_remote_measurements}}
+					@if($bdtDevice->client)
+						{{$bdtDevice->current_cm_number_of_days_with_remote_measurements}}
 					@endif
 				</td>
 				<td>
 					@if($bdtDevice->clientBDTDevice)
-						{{$bdtDevice->clientBDTDevice->client->previousCareMonth()->number_of_days_with_remote_measurements}}
+						{{$bdtDevice->prev_cm_number_of_days_with_remote_measurements}}
 					@endif
 				</td>
-				<td>{{@$bdtDevice->clientBDTDevice->client->client_engagement_status_category}}
-				<td>{{@$bdtDevice->clientBDTDevice->client->adminEngagementAssessmentStatus->status_category}}
-				<td>{{@$bdtDevice->clientBDTDevice->client->mcpEngagementAssessmentStatus->status_category}}
-				<td>{{@$bdtDevice->clientBDTDevice->client->defaultNaEngagementAssessmentStatus->status_category}}
+				<td>{{@$bdtDevice->client_engagement_status_category}}
+				<td>{{@$bdtDevice->admin_engagement_assessment_status}}
+				<td>{{@$bdtDevice->mcp_engagement_assessment_status}}
+				<td>{{@$bdtDevice->default_na_engagement_assessment_status}}
 			</tr>
 			@endforeach