Samson Mutunga 3 年 前
コミット
feaf673b36

+ 13 - 13
app/Http/Controllers/AdminController.php

@@ -174,11 +174,11 @@ class AdminController extends Controller
         $insurance = $request->get('insurance');
         if($insurance){
             if($insurance === 'MEDICARE'){
-                $patients = $patients->whereHas('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('is_partbprimary', '=', 'YES');
                 });
             }else{
-                $patients = $patients->whereDoesntHave('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereDoesntHave('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('is_partbprimary', '=', 'YES');
                 });
             }
@@ -265,33 +265,33 @@ class AdminController extends Controller
 
             switch($keyName) {
                 case 'EXACTLY':
-                        $patients = $patients->whereHas('latestClientPrimaryCoverage', function($q) use ($request){
+                        $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
                             return $q->where('auto_medicare_mpb_deductible', '=', $request->input('deductible_value_1'));
                         });
                     break;
                 case 'LESS_THAN':
                     if($request->input('deductible_value_1')) {
-                        $patients = $patients->whereHas('latestClientPrimaryCoverage', function($q) use ($request){
+                        $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
                             return $q->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_1'));
                         });
                     }
                     break;
                 case 'GREATER_THAN':
                     if($request->input('deductible_value_1')) {
-                        $patients = $patients->whereHas('latestClientPrimaryCoverage', function($q) use ($request){
+                        $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
                             return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'));
                         });
                     }
                     break;
                 case 'BETWEEN':
-                    $patients = $patients->whereHas('latestClientPrimaryCoverage', function($q) use ($request){
+                    $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
                         return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'))
                         ->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_2'));
                     });
                     break;
                 case 'NOT_BETWEEN':
                     if($request->input('deductible_value_1') && $request->input('deductible_value_2')) {
-                        $patients = $patients->whereHas('latestClientPrimaryCoverage', function($q) use ($request){
+                        $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
 
                             return $q->where(function($qq) use ($request){
                                 return $qq->where('auto_medicare_mpb_deductible', '<', $request->input('deductible_value_1'))
@@ -339,7 +339,7 @@ class AdminController extends Controller
             });
         }
 
-        $patients = $patients->whereHas('latestClientPrimaryCoverage', function($cpcQuery){
+        $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
             return $cpcQuery->where('is_partbprimary', '=', 'YES');
         });
 
@@ -527,24 +527,24 @@ class AdminController extends Controller
         $insurance = $request->get('insurance');
         if($insurance){
             if($insurance === 'MEDICARE'){
-                $patients = $patients->whereHas('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('is_partbprimary', '=', 'YES');
                 });
             }elseif($insurance === 'MEDICARE_PENDING'){
-                $patients = $patients->whereHas('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('plan_type', 'MEDICARE')->where('is_covered', '!=', 'YES');
                 });
             }elseif($insurance === 'NOT_COVERED'){
-                $patients = $patients->whereHas('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('is_covered', '!=', 'YES');
                 });
             }elseif($insurance === 'PENDING'){
-                $patients = $patients->whereHas('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('is_covered', '=', 'UNKNOWN');
                 });
             }
             else{
-                $patients = $patients->whereDoesntHave('latestClientPrimaryCoverage', function($cpcQuery){
+                $patients = $patients->whereDoesntHave('effectiveClientPrimaryCoverage', function($cpcQuery){
                     return $cpcQuery->where('is_partbprimary', '=', 'YES');
                 });
             }

+ 3 - 3
app/Http/Controllers/PatientController.php

@@ -608,13 +608,13 @@ class PatientController extends Controller
     }
 
     public function primaryCoverageManualDeterminationModal(Request $request, Client $patient) {
-        if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICARE'){
+        if($patient->effectiveClientPrimaryCoverage->plan_type === 'MEDICARE'){
             return view('app.patient.primary-coverage-manual-determination-medicare-modal', compact('patient'));
         }
-        if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICAID'){
+        if($patient->effectiveClientPrimaryCoverage->plan_type === 'MEDICAID'){
             return view('app.patient.primary-coverage-manual-determination-medicaid-modal', compact('patient'));
         }
-        if($patient->latestClientPrimaryCoverage->plan_type === 'COMMERCIAL'){
+        if($patient->effectiveClientPrimaryCoverage->plan_type === 'COMMERCIAL'){
             return view('app.patient.primary-coverage-manual-determination-commercial-modal', compact('patient'));
         }
 

+ 1 - 1
app/Http/Controllers/PracticeManagementController.php

@@ -167,7 +167,7 @@ SELECT effective_date, count(*), sum(number_of_units) as units FROM bill WHERE c
         if($zero_deductible){
             $rows = $rows->whereHas('client', function($clientQuery){
                 return $clientQuery->where('client_engagement_status_category','<>' ,'DUMMY')
-                ->whereHas('latestClientPrimaryCoverage', function($lcpcQuery){
+                ->whereHas('effectiveClientPrimaryCoverage', function($lcpcQuery){
                     return $lcpcQuery->where('auto_medicare_mpb_deductible', 0);
                 });
             });

+ 5 - 21
app/Models/Client.php

@@ -20,6 +20,10 @@ class Client extends Model
             ->orderBy('created_at', 'desc');
     }
 
+    
+    public function effectiveClientPrimaryCoverage(){
+        return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'effective_client_primary_coverage_id');
+    }
     public function latestClientPrimaryCoverage(){
         return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'latest_client_primary_coverage_id');
     }
@@ -889,27 +893,7 @@ ORDER BY m.ts DESC
 
     public function getPrimaryCoverage()
     {
-        $coverage = $this->latestManualClientPrimaryCoverage;
-        if ($coverage) {
-            return  $coverage;
-        }
-
-        $latestAutoRefreshCoverage = $this->latestAutoRefreshClientPrimaryCoverage;
-        $latestNewCoverage = $this->latestNewClientPrimaryCoverage;
-
-        if($latestAutoRefreshCoverage && $latestNewCoverage){
-            if($latestAutoRefreshCoverage->created_at > $latestNewCoverage->created_at){
-                return $latestAutoRefreshCoverage;
-            }else {
-                return $latestNewCoverage;
-            }
-        }else if($latestAutoRefreshCoverage) {
-            return $latestAutoRefreshCoverage;
-        }else if( $latestNewCoverage){
-            return  $latestNewCoverage;
-        }
-        
-        return null;
+        return $this->effectiveClientPrimaryCoverage;
     }
 
     // return value will be YES, NO or UNKNOWN

+ 10 - 9
resources/views/app/patient/primary-coverage.blade.php

@@ -13,28 +13,29 @@
         </a>
     </div>
 </div>
+<?php $clientPrimaryCoverage = $patient->getPrimaryCoverage(); ?>
 <div class="page-tabs coverage-tabs-display mt-3">
         <div class="links">
             @if($patient->latestNewClientPrimaryCoverage)
-                <a class="c-pointer {{ $patient->getPrimaryCoverage()->id == $patient->latestNewClientPrimaryCoverage->id ? 'active':'' }}" data-link="latest_new_client_primary_coverage">
+                <a class="c-pointer {{ $clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestNewClientPrimaryCoverage->id ? 'active':'' }}" data-link="latest_new_client_primary_coverage">
                     Latest New Client Primary Coverage
-                    @if($patient->getPrimaryCoverage()->id == $patient->latestNewClientPrimaryCoverage->id)
+                    @if($clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestNewClientPrimaryCoverage->id)
                         <i class="fas fa-star ml-2"></i>
                     @endif
                 </a>
             @endif
             @if($patient->latestAutoRefreshClientPrimaryCoverage)
-                <a class="c-pointer {{ $patient->getPrimaryCoverage()->id == $patient->latestAutoRefreshClientPrimaryCoverage->id ? 'active':'' }}" data-link="latest_auto_refresh_client_primary_coverage">
+                <a class="c-pointer {{ $clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestAutoRefreshClientPrimaryCoverage->id ? 'active':'' }}" data-link="latest_auto_refresh_client_primary_coverage">
                     Latest Auto Refresh Client Primary Coverage
-                    @if($patient->getPrimaryCoverage()->id == $patient->latestAutoRefreshClientPrimaryCoverage->id)
+                    @if($clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestAutoRefreshClientPrimaryCoverage->id)
                         <i class="fas fa-star ml-2"></i>
                     @endif
                 </a>
             @endif
             @if($patient->latestManualClientPrimaryCoverage)
-                <a class="c-pointer {{ $patient->getPrimaryCoverage()->id == $patient->latestManualClientPrimaryCoverage->id ? 'active':'' }}" data-link="latest_manual_client_primary_coverage">
+                <a class="c-pointer {{ $clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestManualClientPrimaryCoverage->id ? 'active':'' }}" data-link="latest_manual_client_primary_coverage">
                     Latest Manual Client Primary Coverage
-                    @if($patient->getPrimaryCoverage()->id == $patient->latestManualClientPrimaryCoverage->id)
+                    @if($clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestManualClientPrimaryCoverage->id)
                         <i class="fas fa-star ml-2"></i>
                     @endif
                 </a>   
@@ -42,17 +43,17 @@
         </div>
         <div class="page-tab">
             @if($patient->latestNewClientPrimaryCoverage)
-            <div tab id="latest_new_client_primary_coverage" class="{{ $patient->getPrimaryCoverage()->id == $patient->latestNewClientPrimaryCoverage->id ? '':'d-none' }}">
+            <div tab id="latest_new_client_primary_coverage" class="{{ $clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestNewClientPrimaryCoverage->id ? '':'d-none' }}">
                 @include('app.patient.partials.coverage-information', ['coverage' => $patient->latestNewClientPrimaryCoverage])
             </div>
             @endif
             @if($patient->latestAutoRefreshClientPrimaryCoverage)
-            <div tab id="latest_auto_refresh_client_primary_coverage" class="{{ $patient->getPrimaryCoverage()->id == $patient->latestAutoRefreshClientPrimaryCoverage->id ? '':'d-none' }}">
+            <div tab id="latest_auto_refresh_client_primary_coverage" class="{{ $clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestAutoRefreshClientPrimaryCoverage->id ? '':'d-none' }}">
                 @include('app.patient.partials.coverage-information', ['coverage' => $patient->latestAutoRefreshClientPrimaryCoverage])
             </div>
             @endif
             @if($patient->latestManualClientPrimaryCoverage)
-            <div tab id="latest_manual_client_primary_coverage" class="{{ $patient->getPrimaryCoverage()->id == $patient->latestManualClientPrimaryCoverage->id ? '':'d-none' }}">
+            <div tab id="latest_manual_client_primary_coverage" class="{{ $clientPrimaryCoverage && $clientPrimaryCoverage->id == $patient->latestManualClientPrimaryCoverage->id ? '':'d-none' }}">
                 @include('app.patient.partials.coverage-information', ['coverage' => $patient->latestManualClientPrimaryCoverage])
             </div>
             @endif