Prechádzať zdrojové kódy

Patients list updates, central accessible-patients method

Vijayakrishnan 4 rokov pred
rodič
commit
d002eb6cd3

+ 32 - 53
app/Http/Controllers/HomeController.php

@@ -188,39 +188,26 @@ class HomeController extends Controller
 
         $keyNumbers  = [];
 
-        $totalPatients = Client::where('mcp_pro_id', $performer->pro->id)->count();
-        $keyNumbers['totalPatients'] = $totalPatients;
-
-        $patientNotSeenYet = Client::where('mcp_pro_id', $performer->pro->id)
-            ->where(function ($query) {
-                $query->where('has_mcp_done_onboarding_visit', 'UNKNOWN')
-                    ->orWhere('has_mcp_done_onboarding_visit', 'NO');
+        $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
+
+        $keyNumbers['totalPatients'] = $queryClients->count();
+
+        // patientNotSeenYet
+        $patientNotSeenYet = $queryClients
+            ->where(function ($query) use ($performer) {     // own patient and primary OB visit pending
+                $query->where('mcp_pro_id', $performer->pro->id)
+                    ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
+            })
+            ->orWhere(function ($query) {   // mcp of any client program and program OB pending
+                $query->where(function ($_query) {
+                    $_query->select(DB::raw('COUNT(id)'))
+                        ->from('client_program')
+                        ->whereColumn('client_id', 'client.id')
+                        ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
+                }, '>=', 1);
             })->count();
         $keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
 
-        // patientsPendingProgramOB
-        $proID = $this->performer()->pro->id;
-        if ($this->performer()->pro->pro_type === 'ADMIN') {
-            $query = Client::where('id', '>', 0);
-        } else {
-            $query = 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 is_active AND pro_id = ?)', [$proID])
-                    ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE pro_id = ?)', [$proID]);
-            });
-        }
-        $query = $query->where(function ($_query) {
-            $_query->select(DB::raw('COUNT(id)'))
-                ->from('client_program')
-                ->whereColumn('client_id', 'client.id')
-                ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
-        }, '>=', 1);
-        $keyNumbers['patientsPendingProgramOB'] = $query->count();
-
-
         $pendingBillsToSign = Bill::where(function ($query) use ($performerProID) {
             $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
         })
@@ -337,32 +324,24 @@ class HomeController extends Controller
 
     public function patients(Request $request, $filter = '')
     {
-        $proID = $this->performer()->pro->id;
-        if ($this->performer()->pro->pro_type === 'ADMIN') {
-            $query = Client::where('id', '>', 0);
-        } else {
-            $query = 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 is_active AND pro_id = ?)', [$proID])
-                    ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE pro_id = ?)', [$proID]);
-            });
-        }
+        $performer = $this->performer();
+        $query = $performer->pro->getAccessibleClientsQuery();
 
         switch ($filter) {
             case 'not-yet-seen':
-                $query = $query->where('has_mcp_done_onboarding_visit', '<>', 'YES');
-                break;
-
-            case 'program-onboarding-pending':
-                $query = $query->where(function ($_query) {
-                    $_query->select(DB::raw('COUNT(id)'))
-                        ->from('client_program')
-                        ->whereColumn('client_id', 'client.id')
-                        ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
-                }, '>=', 1);
+                $query = $query
+                    ->where(function ($query) use ($performer) {     // own patient and primary OB visit pending
+                        $query->where('mcp_pro_id', $performer->pro->id)
+                            ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
+                    })
+                    ->orWhere(function ($query) {   // mcp of any client program and program OB pending
+                        $query->where(function ($_query) {
+                            $_query->select(DB::raw('COUNT(id)'))
+                                ->from('client_program')
+                                ->whereColumn('client_id', 'client.id')
+                                ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
+                        }, '>=', 1);
+                    });
                 break;
 
                 // more cases can be added as needed

+ 20 - 0
app/Models/Pro.php

@@ -6,6 +6,7 @@ namespace App\Models;
 
 use App\Helpers\TimeLine;
 use Exception;
+use Illuminate\Support\Facades\DB;
 
 class Pro extends Model
 {
@@ -301,6 +302,25 @@ class Pro extends Model
             ->get();
     }
 
+    public function getAccessibleClientsQuery() {
+        $proID = $this->id;
+        if ($this->pro_type === 'ADMIN') {
+            $query = Client::where('id', '>', 0);
+        } else {
+            $query = Client::where(function ($q) use ($proID) {
+                $q->where('mcp_pro_id', $proID + 1)
+                    ->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 appointment WHERE pro_id = ?)', [$proID])
+                    ->orWhereRaw('id IN (SELECT mcp_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)')
+                    ->orWhereRaw('id IN (SELECT manager_pro_id FROM client_program WHERE client_id = client.id AND is_active = TRUE)');
+            });
+        }
+        return $query;
+    }
+
     public function canAddCPMEntryForMeasurement(Measurement $measurement, Pro $pro)
     {
         // check if client has any programs where this measurement type is allowed

+ 0 - 4
resources/views/app/dashboard.blade.php

@@ -26,10 +26,6 @@
                                     <th class="px-2 text-center">{{$keyNumbers['patientsNotSeenYet']}}</th>
                                     <th class="pl-2"><a native target="_top" href="/patients/not-yet-seen">Patients I have not seen yet</a></th>
                                 </tr>
-                                <tr>
-                                    <th class="px-2 text-center">{{$keyNumbers['patientsPendingProgramOB']}}</th>
-                                    <th class="pl-2"><a native target="_top" href="/patients/program-onboarding-pending">Patients awaiting program OB</a></th>
-                                </tr>
                                 <tr>
                                     <th class="px-2 text-center">{{$keyNumbers['pendingBillsToSign']}}</th>
                                     <th class="pl-2"><a native target="_top" href="/practice-management/bills/not-yet-signed">Pending bills to sign</a></th>

+ 5 - 6
resources/views/app/patients.blade.php

@@ -13,7 +13,6 @@
             <select class="ml-auto max-width-300px form-control form-control-sm" onchange="fastLoad('/patients/' + this.value, true, false, false)">
                 <option value="" {{ $filter === '' ? 'selected' : '' }}>All patients</option>
                 <option value="not-yet-seen" {{ $filter === 'not-yet-seen' ? 'selected' : '' }}>Patients I have not seen yet</option>
-                <option value="program-onboarding-pending" {{ $filter === 'program-onboarding-pending' ? 'selected' : '' }}>Patients pending program onboarding</option>
             </select>
         </div>
         <div class="card-body p-0">
@@ -22,11 +21,9 @@
                 <tr>
                     <th></th>
                     <th class="px-3 border-0">#</th>
-                    <th class="border-0">Name</th>
+                    <th class="border-0">Patient</th>
                     <th class="border-0">Created At</th>
                     <th class="border-0">Program(s)</th>
-                    <th class="border-0">DOB</th>
-                    <th class="border-0">Sex</th>
                     <th class="border-0">MCN</th>
                     <th class="border-0">PCP</th>
                     {{--<th class="border-0">RMM</th>--}}
@@ -47,6 +44,7 @@
                             @if($patient->has_mcp_done_onboarding_visit !== 'YES')
                             <span title="MCP Onboarding Visit Pending"><i class="fa fa-exclamation-triangle"></i></span>
                             @endif
+                            <div>{{ friendly_date_time($patient->dob, false) }}{{ $patient->sex === 'M' ? ', Male' : ($patient->sex === ', F' ? 'Female' : '') }}</div>
                         </td>
                         <td>{{friendly_date_time_short_with_tz($patient->created_at, true, 'EASTERN')}}</td>
                         <td>
@@ -65,9 +63,10 @@
                                     @endif
                                 </div>
                             @endforeach
+                            @if(!count($patient->clientPrograms))
+                                -
+                            @endif
                         </td>
-                        <td>{{ friendly_date_time($patient->dob, false) }}</td>
-                        <td>{{ $patient->sex === 'M' ? 'Male' : ($patient->sex === 'F' ? 'Female' : '-') }}</td>
                         <td>
                             @if($patient->was_medicare_validation_successful && $patient->is_part_b_primary == 'YES')
                             Covered <span style="color:green"><i class="fa fa-check-circle"></i></span>