Browse Source

Merge branch 'master' into dev-vj

Vijayakrishnan 3 năm trước cách đây
mục cha
commit
7f49b80637

+ 63 - 1
app/Http/Controllers/AdminController.php

@@ -421,6 +421,68 @@ class AdminController extends Controller
         $templateContent = file_get_contents($path);
         return $this->pass($templateContent);
     }
+    
+    public function bdtDevices(Request $request)
+    {
+        $filters = $request->all();
+        $bdtDevices = BDTDevice::query();
+
+        $imei = $request->input('imei');
+        if($imei){
+            $bdtDevices = $bdtDevices->where('imei', '=', $imei);
+        }
+        $client = $request->input('client');
+
+        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');
+            }
+        }
+
+        $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');
+            }
+        }
 
+        $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->paginate(20);
+        
+       
+        return view('app.admin.bdt_devices', compact('bdtDevices', 'filters'));
+    }
 
-}
+} 

+ 4 - 0
app/Models/BDTDevice.php

@@ -6,4 +6,8 @@ class BDTDevice extends Model
 {
     protected $table = 'bdt_device';
 
+    public function clientBDTDevice() {
+        return $this->hasOne(ClientBDTDevice::class, 'device_id', 'id');
+    }
+
 }

+ 4 - 0
app/Models/ClientBDTDevice.php

@@ -14,6 +14,10 @@ class ClientBDTDevice extends Model
         return $this->hasOne(Client::class, 'id', 'client_id');
     }
 
+    public function supplyOrders(){
+        return $this->hasMany(SupplyOrder::class, 'client_bdt_device_id', 'id');
+    }
+
     public function mostRecentMeasurement() {
         return $this->hasOne(ClientBDTMeasurement::class, 'id', 'most_recent_client_bdt_measurement_id');
     }

+ 20 - 0
resources/views/app/admin/bdt_devices.blade.php

@@ -0,0 +1,20 @@
+@extends ('layouts/template')
+
+@section('content')
+    <div class="p-3 mcp-theme-1" id="patients-list">
+        <div class="card">
+
+            <div class="card-header px-3 py-2 d-flex align-items-center">
+                <strong class="mr-4">
+                    <i class="fas fa-user"></i>
+                    BDT Devices
+                </strong>
+            </div>
+                <div class="p-3">
+                    @include('app.admin.bdt_devices_filters')
+                </div>
+                @include('app.admin.bdt_devices_table')
+            </div>
+        </div>
+    </div>
+@endsection

+ 118 - 0
resources/views/app/admin/bdt_devices_filters.blade.php

@@ -0,0 +1,118 @@
+<style>
+	#bdt-devices-filters label {
+		font-weight: bold;
+	}
+
+	#bdt-devices-filters .mw-100px {
+		min-width: 100px;
+	}
+	.filter-container{
+		display: flex;
+		align-items: flex-start;
+		flex-wrap: wrap;
+	}
+	.filter-container >div {
+		width: 165px;
+	}
+	.filter-container >div:not(:last-child) {
+		margin-right: 10px;
+	}
+	.sm-section {
+		width: 125px !important;
+	}
+</style>
+
+<form id="bdt-devices-filters" method="GET" action="{{ route('admin.bdt_devices') }}" class="filter-container" v-cloak>
+	
+	<div class="sm-section">
+		<div class="">
+			<label>IMEI:</label>
+			<input name="imei" class="form-control input-sm" v-model="filters.imei">
+		</div>
+	</div>
+
+	<div class="sm-section">
+		<div class="">
+			<label>Client:</label>
+			<input name="client" class="form-control input-sm" v-model="filters.client">
+		</div>
+	</div>
+
+	<div class="sm-section">
+		<div class="">
+			<label>Issued?</label>
+			<select name="is_issued" class="form-control input-sm" v-model="filters.is_issued">
+				<option value="">All</option>
+				<option value="YES">Yes</option>
+				<option value="NO">No</option>
+			</select>
+		</div>
+	</div>
+
+	<div class="sm-section">
+		<div class="">
+			<label>MCP:</label>
+			<select name="mcp" class="form-control min-width-unset" v-model="filters.mcp">
+				<option value="">--select--</option>
+				<?php $mcpPros = \App\Models\Pro::where('is_active', true)->where('is_enrolled_as_mcp', true)->orderBy('name_display')->get(); ?>
+				@foreach($mcpPros as $mcpPro)
+					<option value="{{$mcpPro->uid}}">{{$mcpPro->name_display}}</option>
+				@endforeach
+			</select>
+		</div>
+	</div>
+
+	<div>
+		<div class="">
+			<label>&nbsp;</label>
+			<div class=" d-flex">
+				<button type="button" v-on:click.prevent="doSubmit()" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
+				<a href="#" v-on:click.prevent="fastLoad('{{route('admin.bdt_devices')}}')" class="btn btn-link btn-sm text-danger">Clear</a>
+			</div>
+		</div>
+	</div>
+</form>
+
+<?php
+$loadedFilters = $filters;
+$allFilterKeys = [
+	'imei',
+	'mcp',
+	'client',
+	'is_issued'
+];
+for ($i=0; $i < count($allFilterKeys); $i++) {
+	if (!isset($loadedFilters[$allFilterKeys[$i]]) || !$loadedFilters[$allFilterKeys[$i]]) {
+		$loadedFilters[$allFilterKeys[$i]] = '';
+	}
+}
+?>
+<script>
+	(function() {
+		function init() {
+			new Vue({
+				el: '#bdt-devices-filters',
+				delimiters: ['@{{', '}}'],
+				data: {
+					filters: <?= json_encode($loadedFilters) ?>
+				},
+				methods: {
+					init: function() {
+
+					},
+					doSubmit: function() {
+						fastLoad('{{ route('admin.bdt_devices') }}?' + $('#bdt-devices-filters').serialize());
+						return false;
+					}
+				},
+				mounted: function() {
+					console.log(this.filters);
+					this.init();
+				},
+			});
+
+
+		}
+		addMCInitializer('bdt-devices-filters', init, '#bdt-devices-filters');
+	})();
+</script>

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

@@ -0,0 +1,96 @@
+	<table class="table table-striped p-0 m-0 table-sm border-top border-bottom text-nowrap">
+		<thead class="bg-light">
+			<tr>
+				<th class="border-0">IMEI</th>
+				<th class="border-0">Issued Yet?</th>
+				<th class="border-0">Client</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>
+			</tr>
+		</thead>
+		<tbody>
+			@foreach($bdtDevices as $bdtDevice)
+			<tr>
+				<td>{{$bdtDevice->imei}}</td>
+				<td>{{$bdtDevice->clientBDTDevice ? 'Yes': 'No'}}</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice)
+					<a native target="_blank" href="{{route('patients.view.dashboard',$bdtDevice->clientBDTDevice->client)}}">
+						{{$bdtDevice->clientBDTDevice->client->displayName()}}
+					</a>
+					@else 
+						-
+					@endif 
+				</td>
+				<td>
+					@if($bdtDevice->clientBDTDevice && $bdtDevice->clientBDTDevice->client && $bdtDevice->clientBDTDevice->client->mcp)
+						{{$bdtDevice->clientBDTDevice->client->mcp->name_first}} {{$bdtDevice->clientBDTDevice->client->mcp->name_last}}
+					@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>
+			</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>

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

@@ -185,6 +185,7 @@
                             <a class="dropdown-item" href="{{ route('practice-management.segmentTemplates') }}">Segment Templates</a>
                             <a class="dropdown-item" href="{{ route('practice-management.visitTemplates') }}">Visit Templates</a>
                             <a class="dropdown-item" href="{{ route('admin.part_b_patients') }}">Part B Patients</a>
+                            <a class="dropdown-item" href="{{ route('admin.bdt_devices') }}">BDT Devices</a>
                         @elseif($pro->is_enrolled_as_mcp && $pro->is_considered_for_mcp_assignment)
 
                             <a class="dropdown-item" href="{{ route('practice-management.financialTransactions') }}">Financial Transactions</a>

+ 1 - 0
routes/web.php

@@ -200,6 +200,7 @@ Route::middleware('pro.auth')->group(function () {
 
         Route::get('patients', 'AdminController@patients')->name('patients');
         Route::get('part_b_patients', 'AdminController@partBPatients')->name('part_b_patients');
+        Route::get('bdt_devices', 'AdminController@bdtDevices')->name('bdt_devices');
         Route::get('notes', 'AdminController@notes')->name('notes');
         Route::get('notes-pending-summary-suggestion', 'AdminController@notes_pending_summary_suggestion')->name('notes_pending_summary_suggestion');
         Route::get('notes-rejected-summary-suggestion', 'AdminController@notes_rejected_summary_suggestion')->name('notes_rejected_summary_suggestion');