Explorar el Código

Patients list: Show only patients the pro has access to

Vijayakrishnan Krishnan hace 5 años
padre
commit
1563a78d09
Se han modificado 1 ficheros con 11 adiciones y 3 borrados
  1. 11 3
      app/Http/Controllers/HomeController.php

+ 11 - 3
app/Http/Controllers/HomeController.php

@@ -2,13 +2,11 @@
 
 namespace App\Http\Controllers;
 
-use App\Models\AppSession;
 use App\Models\Client;
 use App\Models\Bill;
 use App\Models\Note;
 use App\Models\ProTransaction;
 use Illuminate\Http\Request;
-use Illuminate\Support\Facades\DB;
 
 class HomeController extends Controller
 {
@@ -71,7 +69,17 @@ class HomeController extends Controller
 
     public function patients(Request $request)
     {
-        $patients = Client::orderBy('name_last', 'asc')->orderBy('name_first', 'asc')->get();
+        $proID = $this->performer()->pro->id;
+        $patients = Client::where(function ($q) use($proID) {
+                $q->where('mcp_pro_id', $proID)
+                    ->orWhere('cm_pro_id', $proID)
+                    ->orWhere('rmm_pro_id', $proID)
+                    ->orWhere('rme_pro_id', $proID)
+                    ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE pro_id = ?)', [$proID]);
+            })
+            ->orderBy('name_last', 'asc')
+            ->orderBy('name_first', 'asc')
+            ->get();
         return view('app/patients', ['patients' => $patients]);
     }