|
@@ -186,14 +186,21 @@ class PatientController extends Controller
|
|
|
|
|
|
public function devices(Request $request, Client $patient )
|
|
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)
|
|
|
|
- ->where('is_active', true)
|
|
|
|
- ->get();
|
|
|
|
- return count($matching) === 0;
|
|
|
|
- });
|
|
|
|
|
|
+ // get assigned devices
|
|
|
|
+ $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
|
|
|
|
+ $assignedDeviceIDs = array_map(function($_x) {
|
|
|
|
+ return $_x->device_id;
|
|
|
|
+ }, $assignedDeviceIDs);
|
|
|
|
+
|
|
|
|
+ // get all except assigned ones
|
|
|
|
+ $devices = BDTDevice::where('is_active', true)
|
|
|
|
+ ->whereNotIn('id', $assignedDeviceIDs)
|
|
|
|
+ ->orderBy('imei', 'asc')
|
|
|
|
+ ->get();
|
|
|
|
+
|
|
|
|
+ $assignedDeviceIDs = null;
|
|
|
|
+ unset($assignedDeviceIDs);
|
|
|
|
+
|
|
return view('app.patient.devices', compact('patient', 'devices'));
|
|
return view('app.patient.devices', compact('patient', 'devices'));
|
|
}
|
|
}
|
|
|
|
|