瀏覽代碼

Client > Pros listing page

Vijayakrishnan 4 年之前
父節點
當前提交
1a8c7de6c7

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

@@ -248,6 +248,11 @@ class PatientController extends Controller
         return view('app.patient.settings', compact('patient'));
     }
 
+    public function pros(Request $request, Client $patient )
+    {
+        return view('app.patient.pros', compact('patient'));
+    }
+
     public function account(Request $request, Client $patient )
     {
         return view('app.patient.account', compact('patient'));

+ 45 - 0
app/Models/Client.php

@@ -177,4 +177,49 @@ class Client extends Model
             ->orderBy('created_at', 'desc');
     }
 
+    public function prosWithAccess() {
+
+        $pros = [];
+
+        // directly associated pros
+        $pro = $this->mcp;
+        if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'MCP'];
+        $pro = $this->pcp;
+        if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'PCP'];
+        $pro = $this->cm;
+        if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'CM'];
+        $pro = $this->rmm;
+        if ($pro && $pro->id) $pros[] = ["pro" => $pro->displayName(), "association" => 'RMM'];
+
+        // via client pro access
+        $cpAccesses = ClientProAccess::where('client_id', $this->id)->where('is_active', true)->get();
+        foreach ($cpAccesses as $cpAccess) {
+            if(!$cpAccess->pro) continue;
+            $pros[] = ["pro" => $cpAccess->pro->displayName(), "association" => 'Via Client-Pro Access'];
+        }
+
+        // via appointments
+        $appointments = Appointment::where('client_id', $this->id)->get();
+        foreach ($appointments as $appointment) {
+            if(!$appointment->pro) continue;
+            $pros[] = ["pro" => $appointment->pro->displayName(), "association" => 'Via Appointment: ' . $appointment->raw_date];
+        }
+
+        // via client program
+        $clientPrograms = ClientProgram::where('client_id', $this->id)->where('is_active', true)->get();
+        foreach ($clientPrograms as $clientProgram) {
+            if($clientProgram->mcp)
+                $pros[] = ["pro" => $clientProgram->mcp->displayName(), "association" => 'Program MCP: ' . $clientProgram->title];
+            if($clientProgram->manager)
+                $pros[] = ["pro" => $clientProgram->manager->displayName(), "association" => 'Program Manager: ' . $clientProgram->title];
+        }
+
+        // sort by pro name
+        $name  = array_column($pros, 'pro');
+        array_multisort($name, SORT_ASC, $pros);
+
+        return $pros;
+
+    }
+
 }

+ 5 - 1
app/Models/ClientProAccess.php

@@ -6,6 +6,10 @@ namespace App\Models;
 
 class ClientProAccess extends Model
 {
-    
+
     protected $table = 'client_pro_access';
+
+    public function pro() {
+        return $this->hasOne(Pro::class, 'id', 'pro_id');
+    }
 }

+ 1 - 1
app/Models/Pro.php

@@ -308,7 +308,7 @@ class Pro extends Model
             $query = Client::where('id', '>', 0);
         } else {
             $query = Client::where(function ($q) use ($proID) {
-                $q->where('mcp_pro_id', $proID + 1)
+                $q->where('mcp_pro_id', $proID)
                     ->orWhere('cm_pro_id', $proID)
                     ->orWhere('rmm_pro_id', $proID)
                     ->orWhere('rme_pro_id', $proID)

+ 35 - 0
resources/views/app/patient/pros.blade.php

@@ -0,0 +1,35 @@
+@extends ('layouts.patient')
+@section('inner-content')
+    <div class="">
+        <div class="d-flex align-items-start pb-2">
+            <h4 class="font-weight-bold m-0">Pros With Access</h4>
+        </div>
+        <table class="table table-striped table-sm table-bordered mb-0">
+            @php $prosWithAccess = $patient->prosWithAccess(); @endphp
+            @if($prosWithAccess && count($prosWithAccess))
+                <thead>
+                <tr>
+                    <th class="px-2 text-secondary">Pro</th>
+                    <th class="px-2 text-secondary w-75">Association</th>
+                </tr>
+                </thead>
+                <tbody>
+                @php $prevPro = ''; @endphp
+                @foreach($prosWithAccess as $aPro)
+                    <tr>
+                        <td class="px-2">{{ $aPro['pro'] !== $prevPro ? $aPro['pro'] : '' }}</td>
+                        <td class="px-2">{{ $aPro['association'] }}</td>
+                        @php $prevPro = $aPro['pro']; @endphp
+                    </tr>
+                @endforeach
+                </tbody>
+            @else
+                <tbody>
+                    <tr>
+                        <td class="text-secondary p-3">No pros (other than admin pros) have access to this patient</td>
+                    </tr>
+                </tbody>
+            @endif
+        </table>
+    </div>
+@endsection

+ 4 - 0
resources/views/layouts/patient.blade.php

@@ -116,6 +116,10 @@
                             <a class="nav-link {{ strpos($routeName, 'patients.view.settings') === 0 ? 'active' : '' }}"
                                href="{{ route('patients.view.settings', ['patient' => $patient]) }}">Settings</a>
                         </li>
+                        <li class="nav-item">
+                            <a class="nav-link {{ strpos($routeName, 'patients.view.pros') === 0 ? 'active' : '' }}"
+                               href="{{ route('patients.view.pros', ['patient' => $patient]) }}">Pros</a>
+                        </li>
                         {{--<li class="nav-item">
                             <a class="nav-link" href="/patients/view/{{ $patient->uid }}/intake">Intake</a>
                         </li>--}}

+ 1 - 0
routes/web.php

@@ -120,6 +120,7 @@ Route::middleware('pro.auth')->group(function () {
         Route::get('handouts', 'PatientController@handouts')->name('handouts');
         Route::get('flowsheets', 'PatientController@flowSheets')->name('flowsheets');
         Route::get('settings', 'PatientController@settings')->name('settings');
+        Route::get('pros', 'PatientController@pros')->name('pros');
         Route::get('account', 'PatientController@account')->name('account');
         Route::get('care-checklist', 'PatientController@careChecklist')->name('care-checklist');
         Route::get('documents', 'PatientController@documents')->name('documents');