Samson Mutunga 1 жил өмнө
parent
commit
dbf1883100

+ 2 - 3
app/Http/Controllers/DnaController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 namespace App\Http\Controllers;
 
 
 use App\Models\Appointment;
 use App\Models\Appointment;
+use App\Models\AppointmentView;
 use App\Models\BDTDevice;
 use App\Models\BDTDevice;
 use App\Models\Bill;
 use App\Models\Bill;
 use App\Models\CareMonth;
 use App\Models\CareMonth;
@@ -113,9 +114,7 @@ class DnaController extends Controller
     public function appointments(Request $request)
     public function appointments(Request $request)
     {
     {
         $filters = $request->all();
         $filters = $request->all();
-        $appointments = Appointment::select('appointment.*')
-                        ->join('client', 'client.id', '=', 'appointment.client_id')
-                        ->where('client.default_na_pro_id', $this->performer->pro->id);
+        $appointments = AppointmentView::where('client_default_na_pro_id', $this->performer->pro->id);
         $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
         $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
         $this->filterSimpleQuery($request, $appointments, 'status', 'status');
         $this->filterSimpleQuery($request, $appointments, 'status', 'status');
         $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);
         $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);

+ 60 - 0
app/Models/AppointmentView.php

@@ -10,4 +10,64 @@ class AppointmentView extends Model
 {
 {
     protected $table = 'appointment_view';
     protected $table = 'appointment_view';
 
 
+    public function clientCoverage(){
+        $coverageDetails = json_decode($this->client_primary_coverage);
+        $coverage = @$coverageDetails[0];
+        return $coverage;
+    }
+    public function getClientPrimaryCoverageStatus() {
+        $coverage = $this->clientCoverage();
+        $status = 'NO';
+
+        // if medicare, check is_partbprimary
+        if($coverage->plan_type === 'MEDICARE') {
+            $status = $coverage->is_partbprimary;
+        }
+        else {
+            if(!$coverage->is_manually_determined) {
+                // AUTO determination of non-medicare not yet supported
+                $status = 'NO';
+            }
+            else {
+                switch($coverage->manual_determination_category) {
+                    case 'COVERED':
+                        $status = 'YES';
+                        break;
+                    case 'NOT_COVERED':
+                    case 'INVALID':
+                        $status = 'NO';
+                        break;
+                    default:
+                        $status = $coverage->manual_determination_category;
+                        break;
+                }
+            }
+        }
+
+        return $status;
+    }
+
+    public function insuranceDisplayName(){
+        $coverageName = $this->insuranceNameToString();
+        if(stripos($coverageName, 'medicare') !== false) return 'Medicare';
+        if(stripos($coverageName, 'medicaid') !== false) return 'Medicaid';
+        if(stripos($coverageName, 'commercial') !== false) return 'Commercial';
+        return null;
+
+    }
+    public function insuranceNameToString() {
+        $coverage = $this->clientCoverage();
+        $parts = [];
+        $parts[] = $coverage->plan_type;
+        if($coverage->plan_type === 'MEDICARE') {
+            if($coverage->is_partbprimary === 'YES') {
+                $parts[] = 'Part B';
+            }
+        }
+        else {
+            if(@$coverage->plan_name) $parts[] = ' / ' . $coverage->plan_name;
+            if(@$coverage->plan_identifier) $parts[] = ' / ' . $coverage->plan_identifier;
+        }
+        return implode(" ", $parts);
+    }
 }
 }

+ 12 - 13
resources/views/app/dna/appointments.blade.php

@@ -33,20 +33,20 @@
                     @foreach($appointments as $appointment)
                     @foreach($appointments as $appointment)
                     <tr>
                     <tr>
                         <td class="text-nowrap">
                         <td class="text-nowrap">
-                            <a native target="_blank" href="{{route('patients.view.dashboard', $appointment->client)}}">
-                                {{$appointment->client->chart_number}}
+                            <a native target="_blank" href="{{route('patients.view.dashboard', $appointment->client_uid)}}">
+                                {{$appointment->client_chart_number}}
                             </a>
                             </a>
                         </td>
                         </td>
                         <td class="text-nowrap">
                         <td class="text-nowrap">
-                            <a native target="_blank" href="{{route('patients.view.dashboard', $appointment->client)}}">
-                                {{$appointment->client->displayName()}}
+                            <a native target="_blank" href="{{route('patients.view.dashboard', $appointment->client_uid)}}">
+                                {{$appointment->client_display_name}}
                             </a>
                             </a>
                         </td>
                         </td>
-                        <td class="text-nowrap">{{ friendly_date_time($appointment->client->dob, false) }}</td>
-                        <td>{{ $appointment->client->age_in_years ?  $appointment->client->age_in_years : '-' }}</td>
-                        <td>{{ $appointment->client->sex }}</td>
+                        <td class="text-nowrap">{{ friendly_date_time($appointment->client_dob, false) }}</td>
+                        <td>{{ $appointment->client_age_in_years ?  $appointment->client_age_in_years : '-' }}</td>
+                        <td>{{ $appointment->client_sex }}</td>
                         <td>
                         <td>
-                            <?php $coverageStatus = $appointment->client->getPrimaryCoverageStatus(); ?>
+                            <?php $coverageStatus = $appointment->getClientPrimaryCoverageStatus(); ?>
                             <div class="text-nowrap">
                             <div class="text-nowrap">
                                 @if($coverageStatus === 'YES')
                                 @if($coverageStatus === 'YES')
                                 <i class="fa fa-check-circle text-success" data-toggle="tooltip" data-placement="bottom" title="Covered"></i>
                                 <i class="fa fa-check-circle text-success" data-toggle="tooltip" data-placement="bottom" title="Covered"></i>
@@ -55,15 +55,14 @@
                                 @else
                                 @else
                                 <i class="fa fa-exclamation-triangle text-warning-mellow" data-toggle="tooltip" data-placement="bottom" title="Unknown"></i>
                                 <i class="fa fa-exclamation-triangle text-warning-mellow" data-toggle="tooltip" data-placement="bottom" title="Unknown"></i>
                                 @endif
                                 @endif
-                                <?php $coverage = $appointment->client->getPrimaryCoverage(); ?>
-                                @if($coverage)
-                                {{$coverage->insuranceDisplayName()}}
+                                @if($appointment->clientCoverage())
+                                {{$appointment->insuranceNameToString()}}
                                 @endif
                                 @endif
                             </div>
                             </div>
                         </td>
                         </td>
-                        <td>{{ $appointment->pro->displayName() }}</td>
+                        <td>{{ $appointment->pro_display_name }}</td>
                         <td>
                         <td>
-                            <a href="/patients/view/{{$appointment->client->uid}}/calendar/{{$appointment->uid}}" class="text-nowrap">
+                            <a href="/patients/view/{{$appointment->client_uid}}/calendar/{{$appointment->uid}}" class="text-nowrap">
                                 {{friendly_date($appointment->raw_date) . ' ' . friendly_time($appointment->raw_start_time)}}
                                 {{friendly_date($appointment->raw_date) . ' ' . friendly_time($appointment->raw_start_time)}}
                             </a>
                             </a>
                         </td>
                         </td>