Browse Source

Dont show devices already mapped to clients in device > add

Vijayakrishnan 4 years ago
parent
commit
251c145c7b

+ 9 - 0
app/Http/Controllers/PatientController.php

@@ -6,6 +6,7 @@ use App\Models\Appointment;
 use App\Models\BDTDevice;
 use App\Models\CareMonth;
 use App\Models\Client;
+use App\Models\ClientBDTDevice;
 use App\Models\ClientInfoLine;
 use App\Models\Facility;
 use App\Models\NoteTemplate;
@@ -21,6 +22,10 @@ class PatientController extends Controller
         $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
         $facilities = Facility::where('is_active', true)->get();
         $devices = BDTDevice::where('is_active', true)->orderBy('imei', 'asc')->get();
+        $devices = $devices->filter(function ($record) {
+            $matching = ClientBDTDevice::where('device_id', $record->id)->get();
+            return count($matching) === 0;
+        });
         $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
             ->where('category', 'dx')
             ->where('is_removed', false)
@@ -82,6 +87,10 @@ class PatientController extends Controller
     public function devices(Request $request, Client $patient )
     {
         $devices = BDTDevice::where('is_active', true)->get();
+        $devices = $devices->filter(function ($record) {
+            $matching = ClientBDTDevice::where('device_id', $record->id)->get();
+            return count($matching) === 0;
+        });
         return view('app.patient.devices', compact('patient', 'devices'));
     }
 

+ 4 - 2
resources/views/app/patient/devices.blade.php

@@ -2,7 +2,8 @@
 @section('inner-content')
     <div class="">
         <div class="d-flex align-items-start pb-2">
-            <h4 class="font-weight-bold m-0">Devices</h4>
+            <div class="font-weight-bold m-0">Devices</div>
+            @if(count($devices))
             <span class="mx-2 text-secondary">|</span>
             <div moe>
                 <a start show>Add</a>
@@ -14,7 +15,7 @@
                             <option value=""> --select-- </option>
                             @foreach($devices as $device)
                                 <option value="{{$device->uid}}">
-                                {$device->imei}} ({{$device->category}}) 
+                                {{$device->imei}} ({{$device->category}})
                                 </option>
                             @endforeach
                         </select>
@@ -41,6 +42,7 @@
                     </div>
                 </form>
             </div>
+            @endif
         </div>
         <table class="table table-striped table-sm table-bordered mb-0">
             @if($patient->devices && count($patient->devices))