Quellcode durchsuchen

Merge branch 'dev' into dev-vj

Vijayakrishnan vor 4 Jahren
Ursprung
Commit
c505d4b282
3 geänderte Dateien mit 47 neuen und 4 gelöschten Zeilen
  1. 12 3
      app/Http/Controllers/HomeController.php
  2. 2 1
      app/Models/ClientProAccess.php
  3. 33 0
      app/Models/Pro.php

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

@@ -323,7 +323,8 @@ class HomeController extends Controller
                     ->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 is_active AND pro_id = ?)', [$proID]);
+                    ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
+                    ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE pro_id = ?)', [$proID]);
             });
         }
         switch ($filter) {
@@ -341,12 +342,20 @@ class HomeController extends Controller
 
     public function patientsSuggest(Request $request)
     {
+
+        $pro = $this->pro;
         $term = $request->input('term') ? trim($request->input('term')) : '';
         if (empty($term)) return '';
-        $clients = Client::where(function ($q) use ($term) {
+        $clientQuery= Client::where(function ($q) use ($term) {
             $q->where('name_first', 'ILIKE', '%' . $term . '%')
                 ->orWhere('name_last', 'ILIKE', '%' . $term . '%');
-        })->get();
+        });
+        
+        if($pro->pro_type != 'ADMIN'){
+            $clientQuery->whereIn('id', $pro->getMyClientIds());
+        }
+
+        $clients = $clientQuery->get();
         return view('app/patient-suggest', compact('clients'));
     }
 

+ 2 - 1
app/Models/ClientProAccess.php

@@ -6,5 +6,6 @@ namespace App\Models;
 
 class ClientProAccess extends Model
 {
-    //
+    
+    protected $table = 'client_pro_access';
 }

+ 33 - 0
app/Models/Pro.php

@@ -257,6 +257,39 @@ class Pro extends Model
 
         return $events;
 
+    }
+
+    public function getMyClientIds(){
+
+        $accessibleClientIds = [];
+        
+        $clientProAccesses = ClientProAccess::where('pro_id', $this->id)->get();
+        foreach($clientProAccesses as $cpa){
+            $accessibleClientIds[] = $cpa->client_id;
+        }
+
+        $appointmentClientIds = [];
+    
+        $appointments = Appointment::where('pro_id', $this->id)->get();
+        foreach($appointments as $appts){
+            $appointmentClientIds[] = $appts->client_id;
+        }
+
+        $clients = Client::where('mcp_pro_id', $this->id)
+            ->orWhere('cm_pro_id', $this->id)
+            ->orWhere('rmm_pro_id', $this->id)
+            ->orWhere('rme_pro_id', $this->id)
+            ->orWhere('rd_pro_id', $this->id)
+            ->orWhereIn('id', $accessibleClientIds)
+            ->orWhereIn('id', $appointmentClientIds)->get();
+
+        $clientIds = [];
 
+        foreach($clients as $client){
+            $clientIds[] = $client->id;
+        }
+        
+        return $clientIds;
     }
+
 }