Selaa lähdekoodia

Merge branch 'cleanup' of https://rav.triplestart.com/tigerphp/stagfe2 into cleanup

Peter Muturi 1 vuosi sitten
vanhempi
commit
cf9633ae0d
32 muutettua tiedostoa jossa 1392 lisäystä ja 586 poistoa
  1. BIN
      .env.swp
  2. 14 13
      app/Http/Controllers/AdminController.php
  3. 92 0
      app/Http/Controllers/CREATE OR REPLACE VIEW dna_patient_list .sql
  4. 1 1
      app/Http/Controllers/Controller.php
  5. 3 4
      app/Http/Controllers/DnaController.php
  6. 3 5
      app/Http/Controllers/McpController.php
  7. 30 2
      app/Http/Controllers/PatientController.php
  8. 92 0
      app/Models/AdminPatient.php
  9. 92 0
      app/Models/DnaPatient.php
  10. 92 0
      app/Models/McpPatient.php
  11. 532 0
      resources/views/app/admin/patients-table-extended-depricated.blade.php
  12. 39 304
      resources/views/app/admin/patients-table-extended.blade.php
  13. 17 17
      resources/views/app/dna/patients-table.blade.php
  14. 101 0
      resources/views/app/mcp/patients-table-depricated.blade.php
  15. 9 16
      resources/views/app/mcp/patients-table.blade.php
  16. 6 6
      resources/views/app/patient/care-month/dashboard.blade.php
  17. 2 2
      resources/views/app/patient/care-months.blade.php
  18. 54 0
      resources/views/app/patient/coverage_column_fast_renderer.blade.php
  19. 3 179
      resources/views/app/patient/dashboard.blade.php
  20. 1 1
      resources/views/app/patient/measurements.blade.php
  21. 1 1
      resources/views/app/patient/memos.blade.php
  22. 2 2
      resources/views/app/patient/note/partials/flag-note-by-supervisor.blade.php
  23. 2 2
      resources/views/app/patient/note/segment/suggestions_and_updates.blade.php
  24. 169 0
      resources/views/app/patient/partials/client-memos.blade.php
  25. 2 2
      resources/views/app/patient/partials/measurements.blade.php
  26. 1 1
      resources/views/app/patient/partials/quick-actions-buttons.blade.php
  27. 3 3
      resources/views/app/patient/primary-coverage-view.blade.php
  28. 5 5
      resources/views/app/patient/review-requests/list.blade.php
  29. 2 2
      resources/views/app/patient/settings.blade.php
  30. 2 2
      resources/views/app/patient/sms.blade.php
  31. 10 9
      resources/views/layouts/patient-header.blade.php
  32. 10 7
      resources/views/layouts/patient.blade.php

BIN
.env.swp


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

@@ -33,6 +33,7 @@ use App\Models\Point;
 use Illuminate\Support\Facades\Http;
 use PDF;
 use Illuminate\Support\Facades\Schema;
+use App\Models\AdminPatient;
 
 class AdminController extends Controller
 {
@@ -40,7 +41,7 @@ class AdminController extends Controller
     public function patients(Request $request)
     {
         $filters = $request->all();
-        $patients = Client::whereNull('shadow_pro_id');
+        $patients = AdminPatient::whereNull('shadow_pro_id');
 
 
         if ($request->input('name')) {
@@ -131,10 +132,10 @@ class AdminController extends Controller
         $fVal = $request->input('has_account');
         if($fVal) {
             if($fVal === 'YES') {
-                $patients = $patients->whereRaw("((SELECT COUNT(ac.id) FROM account_client ac WHERE ac.client_id = client.id) > 0)");
+                $patients = $patients->whereRaw("((SELECT COUNT(ac.id) FROM account_client ac WHERE ac.client_id = admin_patient_list.id) > 0)");
             }
             else {
-                $patients = $patients->whereRaw("((SELECT COUNT(ac.id) FROM account_client ac WHERE ac.client_id = client.id) = 0)");
+                $patients = $patients->whereRaw("((SELECT COUNT(ac.id) FROM account_client ac WHERE ac.client_id = admin_patient_list.id) = 0)");
             }
         }
 
@@ -173,12 +174,12 @@ class AdminController extends Controller
             if($fVal === 'YES') {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 1 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) > 0)");
+                    "WHERE so.product_id = 1 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
             }
             else {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 1 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) = 0)");
+                    "WHERE so.product_id = 1 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
             }
         }
 
@@ -187,12 +188,12 @@ class AdminController extends Controller
             if($fVal === 'YES') {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 2 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) > 0)");
+                    "WHERE so.product_id = 2 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
             }
             else {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 2 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) = 0)");
+                    "WHERE so.product_id = 2 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
             }
         }
 
@@ -201,12 +202,12 @@ class AdminController extends Controller
             if($fVal === 'YES') {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 3 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) > 0)");
+                    "WHERE so.product_id = 3 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
             }
             else {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 3 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) = 0)");
+                    "WHERE so.product_id = 3 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
             }
         }
 
@@ -215,24 +216,24 @@ class AdminController extends Controller
             if($fVal === 'YES') {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 4 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) > 0)");
+                    "WHERE so.product_id = 4 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) > 0)");
             }
             else {
                 $patients = $patients->whereRaw("((SELECT count(sh.id) " .
                     "FROM shipment sh LEFT JOIN supply_order so ON so.shipment_id = sh.id " .
-                    "WHERE so.product_id = 4 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = client.id) = 0)");
+                    "WHERE so.product_id = 4 AND sh.status IN ('DELIVERED', 'DISPATCHED') AND so.client_id = admin_patient_list.id) = 0)");
             }
         }
 
         $fVal = $request->input('imei');
         if($fVal) {
             $patients = $patients->whereRaw("((SELECT count(cbd.id) FROM client_bdt_device cbd
-            WHERE cbd.client_id = client.id AND cbd.device_id IN (SELECT bd.id FROM bdt_device bd WHERE bd.imei LIKE '%$fVal%' AND bd.is_active IS TRUE)) > 0)");
+            WHERE cbd.client_id = admin_patient_list.id AND cbd.device_id IN (SELECT bd.id FROM bdt_device bd WHERE bd.imei LIKE '%$fVal%' AND bd.is_active IS TRUE)) > 0)");
         }
 
         if($request->input('number_of_measurements')){
             $keyName = $request->input('number_of_measurements');
-            $measurementCountQuery = '(SELECT COUNT(*) FROM measurement WHERE measurement.client_id = client.id AND is_active IS TRUE AND is_cellular IS TRUE AND is_cellular_zero IS NOT TRUE)';
+            $measurementCountQuery = '(SELECT COUNT(*) FROM measurement WHERE measurement.client_id = admin_patient_list.id AND is_active IS TRUE AND is_cellular IS TRUE AND is_cellular_zero IS NOT TRUE)';
             switch($keyName) {
                 case 'EXACTLY':
                     if($request->input('number_of_measurements_value_1')) {

+ 92 - 0
app/Http/Controllers/CREATE OR REPLACE VIEW dna_patient_list .sql

@@ -0,0 +1,92 @@
+CREATE OR REPLACE VIEW dna_patient_list AS
+select
+    c.id,
+    c.uid,
+    c.shadow_pro_id,
+    c.client_engagement_status_category,
+    c.chart_number,
+    c.name_first,
+    c.name_last,
+    (c.name_first ||' '||c.name_last) as display_name,
+    c.dob,
+
+    c.mcp_pro_id,
+    c.default_na_pro_id,
+    (mcp_pro.name_first||' '||mcp_pro.name_last) as mcp_pro_display_name,
+
+    c.mailing_address_state,
+    c.mpb_remaining,
+    c.has_mcp_done_onboarding_visit,
+    c.next_mcp_appointment_id,
+
+    c.latest_client_primary_coverage_id,
+    cpc.manual_determination_category,
+    cpc.auto_medicare_is_match_found,
+    cpc.auto_medicaid_is_match_found,
+    cpc.auto_commercial_is_match_found,
+    cpc.deductible_amount,
+    cpc.carrier_free_text,
+
+    mcdp.name as mcd_payer_name,
+    commp.name as commercial_payer_name,
+    
+
+    cpc.is_partbprimary,
+    cpc.plan_type,
+    cpc.is_manually_determined,
+
+    c.age_in_years,
+    c.sex,
+    c.usual_bmi_max,
+    c.most_recent_weight_at,
+    c.most_recent_bp_at,
+    c.created_at,
+    c.most_recent_completed_mcp_note_id,
+    c.most_recent_completed_mcp_note_date,
+    c.email_address,
+    c.default_mcp_company_pro_id,
+    c.default_mcp_company_pro_payer_id,
+    c.default_mcp_company_location_id,
+    c.initiative,
+    c.effective_client_primary_coverage_id,
+
+    c.most_recent_cellular_bp_sbp_mm_hg,
+    c.most_recent_cellular_bp_dbp_mm_hg,
+    c.most_recent_cellular_bp_value_irregular,
+    c.most_recent_cellular_bp_value_pulse,
+    c.most_recent_cellular_weight_value,
+    c.next_mcp_appointment_date,
+
+    nmcpa.status as next_mcp_appointment_status,
+    nmcpa.raw_date as next_mcp_appointment_raw_date,
+    nmcpa.raw_start_time as next_mcp_appointment_start_time,
+
+    mrcn.uid as most_recent_completed_mcp_note_uid,
+    mrcn.effective_dateest as most_recent_completed_mcp_note_effective_dateest,
+
+    mrcn.follow_up_not_needed_memo as most_recent_completed_note_followup_memo,
+
+    mrbpm.created_at as most_recent_cellular_bp_measurement_at,
+    mrwm.created_at as most_recent_cellular_weight_measurement_at,
+
+    c.created_at as client_created_at,
+
+    (dna.name_first|| ' '||dna.name_last ) as dna_display_name,
+
+    (select value from measurement where client_id = c.id AND bdt_measurement_id IS NOT NULL AND ts IS NOT NULL AND is_cellular_zero IS FALSE AND is_active IS TRUE AND label = 'Wt. (lbs.)' order by ts desc LIMIT 1) as last_measurement_of_type_weight,
+    (select value from measurement where client_id = c.id AND bdt_measurement_id IS NOT NULL AND ts IS NOT NULL AND is_cellular_zero IS FALSE AND is_active IS TRUE AND label = 'BP' order by ts desc LIMIT 1) as last_measurement_of_type_bp,
+
+    c.is_assigned_cellular_bp_device as has_bp_device,
+    c.is_assigned_cellular_weight_scale_device has_weight_scale_device
+from client c
+         left join pro mcp_pro on mcp_pro.id = c.mcp_pro_id
+         left join client_primary_coverage cpc on cpc.id = c.latest_client_primary_coverage_id
+         left join payer mcdp on mcdp.id = cpc.mcd_payer_id
+         left join payer commp on commp.id = cpc.commercial_payer_id
+         left join note lmcpa on lmcpa.id = c.previous_mcp_appointment_id
+         left join pro lmcpa_pro on lmcpa_pro.id = lmcpa.hcp_pro_id
+         left join appointment nmcpa on nmcpa.id = c.next_mcp_appointment_id
+         left join note mrcn  on mrcn.id = c.most_recent_completed_mcp_note_id
+         left join measurement mrwm on mrwm.id = c.most_recent_weight_measurement_id
+         left join measurement mrbpm on mrbpm.id = c.most_recent_bp_measurement_id
+         left join pro dna on dna.id = c.default_na_pro_id;

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

@@ -31,7 +31,7 @@ class Controller extends BaseController
         $this->performer = get_current_session();
         if($this->performer && $this->performer->pro) {
             $this->pro = $this->performer->pro;
-            view()->share('pro', $this->performer->pro);
+            view()->share('pro', $this->pro);
         }
         view()->share('performer', $this->performer);
 

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

@@ -33,14 +33,14 @@ use Illuminate\Support\Facades\File;
 
 use Illuminate\Support\Facades\Http;
 use PDF;
-
+use App\Models\DnaPatient;
 class DnaController extends Controller
 {
 
     public function patients(Request $request)
     {
         $filters = $request->all();
-        $patients = Client::whereNull('shadow_pro_id')->where('default_na_pro_id', $this->performer->pro->id);
+        $patients = DnaPatient::whereNull('shadow_pro_id')->where('default_na_pro_id', $this->performer->pro->id);
 
         //Also include the ones given access to:
         $proAccessClientIDs = ClientProAccess::where('pro_id', $this->performer->pro->id)->pluck('client_id')->toArray();
@@ -51,8 +51,7 @@ class DnaController extends Controller
             $name = trim($request->input('name'));
             if ($name) {
                 $patients = $patients->where(function ($q) use ($name) {
-                    $q->where('name_first', 'ILIKE', '%' . $name . '%')
-                        ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
+                    return $q->where('display_name', 'ILIKE', '%' . $name . '%');
                 });
             }
         }

+ 3 - 5
app/Http/Controllers/McpController.php

@@ -34,6 +34,7 @@ use App\Models\ClientMemo;
 use App\Models\ClientProAccess;
 use Illuminate\Support\Facades\Http;
 use PDF;
+use App\Models\McpPatient;
 
 class McpController extends Controller
 {
@@ -42,7 +43,7 @@ class McpController extends Controller
     {
         $pro = $this->performer->pro;
         $filters = $request->all();
-        $patients = Client::whereNull('shadow_pro_id');
+        $patients = McpPatient::whereNull('shadow_pro_id');
         
         //TODO: implement in admin controller 
         if($pro->pro_type != 'ADMIN'){
@@ -81,10 +82,7 @@ class McpController extends Controller
         if ($request->input('name')) {
             $name = trim($request->input('name'));
             if ($name) {
-                $patients = $patients->where(function ($q) use ($name) {
-                    $q->where('name_first', 'ILIKE', '%' . $name . '%')
-                        ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
-                });
+                $patients = $patients->where('display_name', 'ILIKE', '%' . $name . '%');
             }
         }
 

+ 30 - 2
app/Http/Controllers/PatientController.php

@@ -35,7 +35,7 @@ use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\File;
 use App\Models\Measurement;
 use App\Models\ClientReviewRequest;
-
+use App\Models\Point;
 use Illuminate\Support\Facades\Http;
 use PDF;
 
@@ -101,13 +101,41 @@ class PatientController extends Controller
         $assignedDeviceIDs = null;
         unset($assignedDeviceIDs);
 
+        $availableDevices = count($devices);
+            $patientDeviceIDs = ClientBDTDevice::select('id')->where('client_id', $patient->id)->where('is_active', true)->get()->toArray();
+            $patientDeviceIDs = array_map(function ($_x) {
+                return $_x["id"];
+            }, $patientDeviceIDs);
+
         $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
             ->where('category', 'dx')
             ->where('is_removed', false)
             ->orderBy('content_text', 'asc')
             ->get();
+        $clientMemos = $patient->memos;
+
+        $shortCutsObject = [];
+        foreach ($this->pro->allShortcuts() as $shortcut) {
+            // %replaceables%
+            $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
+            $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
+            $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);
+
+            $shortCutsObject[] = [
+                "name" => $shortcut->shortcut,
+                "value" => $shortcut->text
+            ];
+        }
+        
+        $recentMeasurements = $patient->recentMeasurements;
+
+        $latestVitals = Point::where('client_id', $patient->id)->where('category', 'VITALS')->orderBy('id', 'DESC')->first();
+
+        $nonCoreVisitNotes = $patient->nonCoreVisitNotes;
+        $disallowPointEdits = $nonCoreVisitNotes && count($nonCoreVisitNotes);
+
         return view('app.patient.dashboard',
-            compact('patient', 'facilities', 'devices', 'dxInfoLines'));
+            compact('patient', 'facilities', 'devices', 'dxInfoLines', 'clientMemos', 'shortCutsObject', 'availableDevices', 'patientDeviceIDs', 'recentMeasurements', 'latestVitals', 'disallowPointEdits'));
     }
 
     public function canvasMigrate(Request $request, Client $patient )

+ 92 - 0
app/Models/AdminPatient.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class AdminPatient extends Model
+{
+    protected $table = 'admin_patient_list';
+
+    public function nextMcpAppointment()
+    {
+        return $this->hasOne(Appointment::class, 'id', 'next_mcp_appointment_id');
+    }
+
+    public function effectiveClientPrimaryCoverage(){
+        return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'effective_client_primary_coverage_id');
+    }
+
+    public function companyClients()
+    {
+        return $this->hasMany(CompanyClient::class, 'client_id', 'id')
+            ->where('is_active', true)
+            ->orderBy('created_at', 'asc');
+    }
+
+    public function getCoverageStatus() {
+        $status = 'NO';
+
+        // if medicare, check is_partbprimary
+        if($this->plan_type === 'MEDICARE') {
+            $status = $this->is_partbprimary;
+        }
+        else {
+            if(!$this->is_manually_determined) {
+                // AUTO determination of non-medicare not yet supported
+                $status = 'NO';
+            }
+            else {
+                switch($this->manual_determination_category) {
+                    case 'COVERED':
+                        $status = 'YES';
+                        break;
+                    case 'NOT_COVERED':
+                    case 'INVALID':
+                        $status = 'NO';
+                        break;
+                    default:
+                        $status = $this->manual_determination_category;
+                        break;
+                }
+            }
+        }
+
+        return $status;
+    }
+
+    public function insuranceDisplayName(){
+        $coverageName = $this->coverageToString();
+        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 insuranceDisplayPayerName(){
+        if($this->plan_type === 'MEDICAID'){
+            if($this->mcd_payer_name) return $this->mcd_payer_name;
+        } 
+        if($this->plan_type === 'COMMERCIAL'){
+            if($this->commercial_payer_name) return $this->commercial_payer_name; else $this->carrier_free_text ?: '-';
+        } 
+        return $this->insuranceDisplayName();
+    }
+
+    public function coverageToString() {
+        $parts = [];
+        $parts[] = $this->plan_type;
+        if($this->plan_type === 'MEDICARE') {
+            if($this->is_partbprimary === 'YES') {
+                $parts[] = 'Part B';
+            }
+        }
+        else {
+            if(@$this->plan_name) $parts[] = ' / ' . $this->plan_name;
+            if(@$this->plan_identifier) $parts[] = ' / ' . $this->plan_identifier;
+        }
+        return implode(" ", $parts);
+    }
+
+}

+ 92 - 0
app/Models/DnaPatient.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class DnaPatient extends Model
+{
+    protected $table = 'dna_patient_list';
+
+    public function nextMcpAppointment()
+    {
+        return $this->hasOne(Appointment::class, 'id', 'next_mcp_appointment_id');
+    }
+
+    public function effectiveClientPrimaryCoverage(){
+        return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'effective_client_primary_coverage_id');
+    }
+
+    public function companyClients()
+    {
+        return $this->hasMany(CompanyClient::class, 'client_id', 'id')
+            ->where('is_active', true)
+            ->orderBy('created_at', 'asc');
+    }
+
+    public function getCoverageStatus() {
+        $status = 'NO';
+
+        // if medicare, check is_partbprimary
+        if($this->plan_type === 'MEDICARE') {
+            $status = $this->is_partbprimary;
+        }
+        else {
+            if(!$this->is_manually_determined) {
+                // AUTO determination of non-medicare not yet supported
+                $status = 'NO';
+            }
+            else {
+                switch($this->manual_determination_category) {
+                    case 'COVERED':
+                        $status = 'YES';
+                        break;
+                    case 'NOT_COVERED':
+                    case 'INVALID':
+                        $status = 'NO';
+                        break;
+                    default:
+                        $status = $this->manual_determination_category;
+                        break;
+                }
+            }
+        }
+
+        return $status;
+    }
+
+    public function insuranceDisplayName(){
+        $coverageName = $this->coverageToString();
+        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 insuranceDisplayPayerName(){
+        if($this->plan_type === 'MEDICAID'){
+            if($this->mcd_payer_name) return $this->mcd_payer_name;
+        } 
+        if($this->plan_type === 'COMMERCIAL'){
+            if($this->commercial_payer_name) return $this->commercial_payer_name; else $this->carrier_free_text ?: '-';
+        } 
+        return $this->insuranceDisplayName();
+    }
+
+    public function coverageToString() {
+        $parts = [];
+        $parts[] = $this->plan_type;
+        if($this->plan_type === 'MEDICARE') {
+            if($this->is_partbprimary === 'YES') {
+                $parts[] = 'Part B';
+            }
+        }
+        else {
+            if(@$this->plan_name) $parts[] = ' / ' . $this->plan_name;
+            if(@$this->plan_identifier) $parts[] = ' / ' . $this->plan_identifier;
+        }
+        return implode(" ", $parts);
+    }
+
+}

+ 92 - 0
app/Models/McpPatient.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class McpPatient extends Model
+{
+    protected $table = 'mcp_patient_list';
+
+    public function nextMcpAppointment()
+    {
+        return $this->hasOne(Appointment::class, 'id', 'next_mcp_appointment_id');
+    }
+
+    public function effectiveClientPrimaryCoverage(){
+        return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'effective_client_primary_coverage_id');
+    }
+
+    public function companyClients()
+    {
+        return $this->hasMany(CompanyClient::class, 'client_id', 'id')
+            ->where('is_active', true)
+            ->orderBy('created_at', 'asc');
+    }
+
+    public function getCoverageStatus() {
+        $status = 'NO';
+
+        // if medicare, check is_partbprimary
+        if($this->plan_type === 'MEDICARE') {
+            $status = $this->is_partbprimary;
+        }
+        else {
+            if(!$this->is_manually_determined) {
+                // AUTO determination of non-medicare not yet supported
+                $status = 'NO';
+            }
+            else {
+                switch($this->manual_determination_category) {
+                    case 'COVERED':
+                        $status = 'YES';
+                        break;
+                    case 'NOT_COVERED':
+                    case 'INVALID':
+                        $status = 'NO';
+                        break;
+                    default:
+                        $status = $this->manual_determination_category;
+                        break;
+                }
+            }
+        }
+
+        return $status;
+    }
+
+    public function insuranceDisplayName(){
+        $coverageName = $this->coverageToString();
+        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 insuranceDisplayPayerName(){
+        if($this->plan_type === 'MEDICAID'){
+            if($this->mcd_payer_name) return $this->mcd_payer_name;
+        } 
+        if($this->plan_type === 'COMMERCIAL'){
+            if($this->commercial_payer_name) return $this->commercial_payer_name; else $this->carrier_free_text ?: '-';
+        } 
+        return $this->insuranceDisplayName();
+    }
+
+    public function coverageToString() {
+        $parts = [];
+        $parts[] = $this->plan_type;
+        if($this->plan_type === 'MEDICARE') {
+            if($this->is_partbprimary === 'YES') {
+                $parts[] = 'Part B';
+            }
+        }
+        else {
+            if(@$this->plan_name) $parts[] = ' / ' . $this->plan_name;
+            if(@$this->plan_identifier) $parts[] = ' / ' . $this->plan_identifier;
+        }
+        return implode(" ", $parts);
+    }
+
+}

+ 532 - 0
resources/views/app/admin/patients-table-extended-depricated.blade.php

@@ -0,0 +1,532 @@
+<?php
+$patientEngagementColorCodes = @Config::get('constants.client_engagement_status_color_codes');
+?>
+<div>
+    @include('app.admin.patients-results-view-options')
+</div>
+<div class="table-responsive border-top" style="height: calc(100vh - 280px)" id="admin-patients-list-extended">
+    <table class="table p-0 m-0 table-sm table-striped table-bordered border-bottom text-nowrap">
+        <thead class="bg-light">
+            <tr>
+                <th class="border-0">@include('app.practice-management._sort_header', [
+                    'route' => route('admin.patients'),
+                    'label' => 'Status',
+                    'key' => 'client_engagement_status_category',
+                ])</th>
+                <th class="border-0 width-90px text-secondary">#</th>
+                <th class="border-0">@include('app.practice-management._sort_header', [
+                    'route' => route('admin.patients'),
+                    'label' => 'Name',
+                    'key' => 'name_first',
+                ])</th>
+                @if ($pro->pro_type == 'ADMIN')
+                    <th class="border-0 text-secondary">MCP</th>
+                    {{-- <th class="border-0">NA</th> --}}
+                    {{-- <th class="border-0">Initiative</th> --}}
+                    {{-- <th class="border-9">Status</th> --}}
+                    {{-- <th class="border-0">Source</th> --}}
+                @endif
+                <th class="border-0 text-secondary">State</th>
+                <th class="border-0 text-secondary">Insurance</th>
+                @if ($performer->pro->pro_type == 'ADMIN')
+                    <th class="border-0 text-secondary">Ded.</th>
+                @endif
+                <th class="border-0 text-secondary">Age</th>
+                <th class="border-0">@include('app.practice-management._sort_header', [
+                    'route' => route('admin.patients'),
+                    'label' => 'Last Visit',
+                    'key' => 'most_recent_completed_mcp_note_date',
+                ])</th>
+                <th class="border-0 text-secondary"></th>
+                <th class="border-0 text-secondary">Last Memo</th>
+                <th class="border-0 text-secondary">Notes</th>
+                <th class="border-0 text-secondary">Next Appt.</th>
+                <th class="border-0">@include('app.practice-management._sort_header', [
+                    'route' => route('admin.patients'),
+                    'label' => 'BP/Pulse Timestamp',
+                    'key' => 'most_recent_cellular_bp_measurement_at',
+                ])</th>
+                <th class="border-0">@include('app.practice-management._sort_header', [
+                    'route' => route('admin.patients'),
+                    'label' => 'Weight Timestamp',
+                    'key' => 'most_recent_cellular_weight_measurement_at',
+                ])</th>
+                <th class="border-0">@include('app.practice-management._sort_header', [
+                    'route' => route('admin.patients'),
+                    'label' => 'Created',
+                    'key' => 'created_at',
+                ])</th>
+                <th class="border-0 text-secondary">Assigned On</th>
+                <th class="border-0 text-secondary">NA</th>
+
+                <th class="border-0 text-secondary">Temp. Gun</th>
+                <th class="border-0 text-secondary">Pulse Ox.</th>
+                <th class="border-0 text-secondary">Cell. Bp</th>
+                <th class="border-0 text-secondary">Wt. Scale</th>
+                <th class="border-0 text-secondary">Companies</th>
+
+
+                {{-- <th class="border-0">DOB</th> --}}
+                {{-- <th class="border-0">Age</th> --}}
+                {{-- <th class="border-0">Sex</th> --}}
+                {{-- <th class="border-0">BMI</th> --}}
+                {{-- <th class="border-0">BP</th> --}}
+                {{-- <th class="border-0"><i class="fa fa-heartbeat"></i></th> --}}
+                {{-- <th class="border-0">Pulse</th> --}}
+                {{-- <th class="border-0">Weight</th> --}}
+                {{-- <th class="border-0"># Cellular Measurements</th> --}}
+                {{-- <th>Scale <i class="fa fa-battery"></i></th> --}}
+                {{-- <th class="border-0">RPM</th> --}}
+                {{-- <th class="border-0 d-none">Last Weight-In</th> --}}
+                {{-- <th class="border-0 d-none">Last BP</th> --}}
+                {{-- <th class="border-0">Email Address</th> --}}
+            </tr>
+        </thead>
+        <tbody>
+            @foreach ($patients as $patient)
+                <tr>
+                    <td
+                        style="background-color:<?= @$patientEngagementColorCodes[$patient->client_engagement_status_category] ?: '' ?>;">
+                        {{ $patient->client_engagement_status_category == 'DUMMY' ? 'Test Record' : $patient->client_engagement_status_category }}
+                    </td>
+                    <td>
+                        <a native target="_blank" href="{{ route('patients.view.dashboard', $patient) }}">
+                            {{ $patient->chart_number }}
+                        </a>
+                    </td>
+                    <td>
+                        <div class="d-flex align-items-baseline flex-nowrap">
+                            <span>{{ $patient->displayName() }}</span>
+                            <?php $latestMemo = $patient->latestMemo(); ?>
+                            <div class="on-hover-show d-inline-block on-hover-opaque ml-auto mr-1">
+                                <i class="fa fa-info-circle ml-1 {{ $latestMemo ? '' : 'opacity-35' }}"></i>
+                                <div class="on-hover-content py-2 pl-3 text-nowrap text-dark"
+                                    style="left:0;right:auto;">
+                                    @if ($latestMemo)
+                                        <p class="mb-1 font-weight-bold text-secondary">Last Memo:
+                                            {{ $latestMemo->category }}</p>
+                                        <div class="text-wrap mb-1">{{ $latestMemo->content }}</div>
+                                        <div class="text-secondary text-sm mb-1">
+                                            {{ friendly_date_time($latestMemo->created_at) }}</div>
+                                        @if ($latestMemo->createdBy && $latestMemo->createdBy->pro)
+                                            <div class="text-secondary text-sm">By
+                                                {{ $latestMemo->createdBy->pro->displayName() }}</div>
+                                        @endif
+                                    @else
+                                        <div class="text-secondary">No client memos.</div>
+                                    @endif
+                                </div>
+                            </div>
+                        </div>
+                    </td>
+                    @if ($pro->pro_type == 'ADMIN')
+                        <td>
+                        @if(@$patient->mcp)
+                            {{ $patient->mcp->displayName() }}
+                            @if(!$patient->mcp->is_hcp)
+                                <small class="text-danger font-weight-bold"><i class="fas fa-exclamation-triangle fa-fw"></i> {{ $patient->mcp->name_first }} is no longer HCP.</small>
+                            @endif
+                        @else
+                            --
+                        @endif
+                        </td>
+                        {{-- <td>{{@$patient->defaultNaPro ? $patient->defaultNaPro->displayName() : '--'}}</td> --}}
+                        {{-- <td>{{$patient->initiative}}</td> --}}
+                        {{-- <td>{{$patient->client_engagement_status_category == 'DUMMY'? 'Test Record': $patient->client_engagement_status_category}}</td> --}}
+                        {{-- <td>{{$patient->source}}</td> --}}
+                    @endif
+                    <td>{{ $patient->mailing_address_state }}</td>
+                    <td class="{{ $patient->mpb_remaining === 0 ? 'deductible-zero' : '' }}">
+                        @include('app.patient.coverage_column_renderer', ['patient' => $patient])
+
+                    </td>
+                    @if ($performer->pro->pro_type == 'ADMIN')
+                        <td>
+                            <small class="d-block text-sm text-muted">
+                                <span class="font-weight-bold">{{ format_number(@$patient->mpb_remaining) }}</span>
+                            </small>
+                        </td>
+                        <td>{{ $patient->age_in_years }}</td>
+                    @endif
+                    <td>
+                        {{ friendly_date($patient->most_recent_completed_mcp_note_date) }}
+                    </td>
+                    <td>
+                        @if ($patient->lastMcpAppointment)
+                            <small class="text-muted">{{ $patient->lastMcpAppointment->pro->displayName() }}</small>
+                        @endif
+                    </td>
+                    <td>
+                        <?php $lastMemo = $patient->lastMemo(); ?>
+                        @if ($lastMemo)
+                            {{ friendly_date($lastMemo->created_at) }}
+                            <?php
+                        $daysAgo = date_diff(date_create($lastMemo->created_at), date_create('now'))->days;
+                        if ($daysAgo > 0) {
+                            ?>
+                            <span class="text-sm text-secondary">({{ $daysAgo }} day{{ $daysAgo > 1 ? 's' : '' }}
+                                ago)</span>
+                            <?php
+                        }
+                        ?>
+                        @else
+                            -
+                        @endif
+                    </td>
+                    <td class="p-0 pb-1">
+                        <div if-details-view>
+                            @if (count($patient->activeNotes))
+                                <?php $noteIndex = 0; ?>
+                                @foreach ($patient->activeNotes as $note)
+                                    <?php $noteIndex++; ?>
+                                    <div class="mt-1 bg-white border p-2">
+                                        <div class="d-flex align-items-baseline">
+                                            <span
+                                                class="mr-2 font-weight-bold text-secondary">{{ $noteIndex }}.</span>
+                                            <a native target="_blank"
+                                                href="/patients/view/{{ $patient->uid }}/notes/view/{{ $note->uid }}">
+                                                <b>{{ friendly_date_time($note->effective_dateest, false) }}</b>
+                                            </a>
+                                            <span class="mx-2 text-sm">/</span>
+                                            <span>{{ $note->new_or_fu_or_na === 'NEW' ? 'New' : 'Follow-up' }}</span>
+                                            <span class="mx-2 text-sm">/</span>
+                                            <span>{{ $note->hcpPro ? $note->hcpPro->name_display : '-' }}</span>
+                                            <span class="mx-2 text-sm">/</span>
+                                            <span>{{ noteMethodDisplay($note->method) }}</span>
+                                            @if ($note->hcpPro && $note->is_signed_by_hcp)
+                                                <span class="mx-2 text-sm">/</span>
+                                                <span class="text-success">Signed</span>
+                                            @endif
+                                        </div>
+                                        <?php
+                                        $bills = \App\Models\Bill::where('note_id', $note->id)
+                                            ->where('bill_service_type', '<>', 'GENERIC')
+                                            ->where('is_cancelled', false)
+                                            ->orderBy('id', 'desc')
+                                            ->get();
+                                        ?>
+                                        @if (count($bills))
+                                            <hr class="my-2">
+                                            <div class="d-flex align-items-start text-sm">
+                                                <b class="text-secondary width-60px">Bills:</b>
+                                                <div class="ml-2 flex-grow-1">
+                                                    @foreach ($bills as $bill)
+                                                        <div class="border border-info bg-aliceblue p-1 mb-1">
+                                                            <div class="d-flex align-items-baseline">
+                                                                <span>{{ $bill->code }}</span>
+                                                                <span class="mx-2 text-sm">/</span>
+                                                                <span>
+                                                                    @if (strpos(strtolower($bill->code), 'treatment services') !== false)
+                                                                        <?php
+                                                                        $totalSeconds = $bill->number_of_units * 3600;
+                                                                        $remainder = $totalSeconds % 60;
+                                                                        if ($remainder !== 0) {
+                                                                            if ($remainder < 30) {
+                                                                                $totalSeconds = $totalSeconds - $remainder;
+                                                                            } else {
+                                                                                $totalSeconds = $totalSeconds + (60 - $remainder);
+                                                                            }
+                                                                        }
+                                                                        ?>
+                                                                        {{ time_in_hrminsec($totalSeconds) }}
+                                                                    @else
+                                                                        @if (!!$bill->number_of_units)
+                                                                            {{ $bill->number_of_units }} unit(s)
+                                                                        @else
+                                                                            -
+                                                                        @endif
+                                                                    @endif
+                                                                </span>
+                                                                @if ($bill->is_signed_by_hcp)
+                                                                    <span class="mx-2 text-sm">/</span>
+                                                                    <span class="d-block text-nowrap">
+                                                                        <i class="fa fa-check"></i>
+                                                                        Signed
+                                                                    </span>
+                                                                @endif
+                                                                @if ($bill->is_verified)
+                                                                    <span class="mx-2 text-sm">/</span>
+                                                                    <span class="d-block text-nowrap">
+                                                                        <i class="fa fa-check"></i>
+                                                                        Verified
+                                                                    </span>
+                                                                @endif
+                                                                @if (!$bill->has_hcp_been_paid)
+                                                                    <span class="mx-2 text-sm">/</span>
+                                                                    <div class="text-nowrap mt-1 screen-only">
+                                                                        <span class="">Expected: </span>
+                                                                        <span
+                                                                            class="font-weight-bold">${{ $bill->hcp_expected_payment_amount }}</span>
+                                                                    </div>
+                                                                @else
+                                                                    <span class="mx-2 text-sm">/</span>
+                                                                    <div class="text-nowrap mt-1 screen-only">
+                                                                        <span class="">Paid: </span>
+                                                                        <span
+                                                                            class="font-weight-bold">${{ $bill->hcp_payment_amount }}</span>
+                                                                    </div>
+                                                                @endif
+                                                            </div>
+                                                        </div>
+                                                    @endforeach
+                                                </div>
+                                            </div>
+                                        @endif
+                                        <?php
+                                        $claims = \App\Models\Claim::where('note_id', $note->id)
+                                            ->where('is_cancelled', false)
+                                            ->orderBy('id', 'desc')
+                                            ->get();
+                                        ?>
+                                        @if (count($claims))
+                                            <hr class="my-2">
+                                            <div class="d-flex align-items-start text-sm">
+                                                <b class="text-secondary width-60px">Claims:</b>
+                                                <div class="ml-2 flex-grow-1 border border-success">
+                                                    <table class="table table-sm tabe-striped mb-0 border-0">
+                                                        <tbody>
+                                                            @foreach ($claims as $claim)
+                                                                @if ($claim->status !== 'CANCELLED' || request('claims-filter') === 'all')
+                                                                    <tr
+                                                                        class="{{ $claim->status === 'CANCELLED' ? 'text-secondary bg-light on-hover-opaque' : '' }}">
+                                                                        <td class="p-0 border-left border-right">
+                                                                            @if ($claim->lines->count())
+                                                                                <table
+                                                                                    class="table table-sm table-condensed border-0 mb-0">
+                                                                                    <thead>
+                                                                                        <tr class="bg-light">
+                                                                                            <th class="border-0">CPT
+                                                                                            </th>
+                                                                                            <th class="border-0">DOS
+                                                                                            </th>
+                                                                                            <th class="border-0">ICDs
+                                                                                            </th>
+                                                                                        </tr>
+                                                                                    </thead>
+                                                                                    <tbody class="">
+                                                                                        @foreach ($claim->lines as $line)
+                                                                                            <tr class="claim-line">
+                                                                                                <td>{{ $line->cpt }}
+                                                                                                    <div>Units:
+                                                                                                        <b>{{ !@$line->units ? 1 : $line->units }}</b>
+                                                                                                    </div>
+                                                                                                </td>
+                                                                                                <td class="text-nowrap">
+                                                                                                    {{ friendlier_date($line->date_of_service) }}
+                                                                                                </td>
+                                                                                                <td>
+                                                                                                    @if (count($line->claimLineIcds))
+                                                                                                        @foreach ($line->claimLineIcds as $icd)
+                                                                                                            <div>
+                                                                                                                <b class="c-pointer border-secondary border-bottom"
+                                                                                                                    title="{{ $icd->description }}">{{ $icd->code }}</b>
+                                                                                                            </div>
+                                                                                                        @endforeach
+                                                                                                    @else
+                                                                                                        <p>No ICDs set
+                                                                                                        </p>
+                                                                                                    @endif
+                                                                                                </td>
+                                                                                            </tr>
+                                                                                        @endforeach
+                                                                                    </tbody>
+                                                                                </table>
+                                                                            @else
+                                                                                <p>No lines for this claim</p>
+                                                                            @endif
+                                                                        </td>
+                                                                        <td class="border-right p-0">
+
+                                                                            <!-- payer, company, location -->
+                                                                            <div class="p-1">
+                                                                                <div class="mt-1">
+                                                                                    <div>
+                                                                                        <b>{{ $claim->primaryPayer ? $claim->primaryPayer->name : '-' }}</b>
+                                                                                        /
+                                                                                        {{ $claim->status ? $claim->status : 'Status not set' }}
+                                                                                    </div>
+                                                                                </div>
+
+                                                                                <div class="mt-1">
+                                                                                    {{ $claim->companyPro && $claim->companyPro->company ? $claim->companyPro->company->name : '-' }}
+                                                                                </div>
+
+                                                                                <div class="mt-1">
+                                                                                    {{ $claim->companyLocation ? $claim->companyLocation->line1 . ', ' . $claim->companyLocation->city : '-' }}
+                                                                                </div>
+                                                                            </div>
+                                                                        </td>
+                                                                    </tr>
+                                                                @endif
+                                                            @endforeach
+                                                        </tbody>
+                                                    </table>
+                                                </div>
+                                            </div>
+                                        @endif
+                                    </div>
+                                @endforeach
+                            @endif
+                        </div>
+                        <div if-grid-view class="p-1">
+                            {{ count($patient->activeNotes) }}
+                        </div>
+                    </td>
+                    <td>{{ $patient->nextMcpAppointment ? friendly_date_time($patient->nextMcpAppointment->raw_date . ' ' . $patient->nextMcpAppointment->raw_start_time) : '' }}
+                        <span if-grid-view>
+                            @if ($patient->nextMcpAppointment)
+                                {{-- {{$patient->nextMcpAppointment->status}} --}}
+                            @elseif($patient->mostRecentCompletedMcpNote && $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo)
+                                <div class="w-100 text-nowrap overflow-hidden text-ellipsis max-width-170px"
+                                    title="{{ $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo }}">
+                                    <b>No</b>
+                                    {{ $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo }}
+                                </div>
+                            @endif
+                        </span>
+                        <div if-details-view>
+                            @if ($patient->nextMcpAppointment)
+                                {{ $patient->nextMcpAppointment->status }}
+                            @elseif($patient->mostRecentCompletedMcpNote && $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo)
+                                <b>No</b>
+                                {{ $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo }}
+                            @endif
+                        </div>
+                    </td>
+                    <td>{{ friendlier_date_time($patient->most_recent_cellular_bp_measurement_at) }}</td>
+                    <td>{{ friendlier_date_time($patient->most_recent_cellular_weight_measurement_at) }}</td>
+                    <td>
+                        <div title="{{ friendly_date_time($patient->created_at) }}">
+                            {{ friendly_date_time($patient->created_at, false) }}</div>
+                        <div class="mt-1" if-details-view>
+                            By <span>{{ $patient->creator ? $patient->creator->displayName() : '-' }}</span>
+                        </div>
+                    </td>
+                    <td>{{ $patient->getMcpAssignedOn() }}</td>
+                    <td>{{ $patient->defaultNaPro ? $patient->defaultNaPro->displayName() : '-' }}</td>
+
+                    <td>{{ $patient->temparatureGunDeliveryStatus() }}</td>
+                    <td>{{ $patient->pulseOximeterDeliveryStatus() }}</td>
+                    <td>{{ $patient->hasBPDevice() ? 'DELIVERED' : '' }}</td>
+                    <td>{{ $patient->hasWeightScaleDevice() ? 'DELIVERED' : '' }}</td>
+
+                    {{-- <td>{{ friendly_date_time($patient->dob, false) }}</td> --}}
+                    {{-- <td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td> --}}
+                    {{-- <td>{{ $patient->sex }}</td> --}}
+                    {{-- <td>
+                    <div class="d-none d-dflex flex-column">
+                        @if ($patient->usual_bmi_min && $patient->usual_bmi_max)
+                            <small class="text-muted">BMI (Usual):
+                                <b>{{ $patient->usual_bmi_min }}</b> {{ $patient->usual_bmi_min_category }} to
+                                <b>{{ $patient->usual_bmi_max }}</b> {{ $patient->usual_bmi_max_category }}</small>
+                        @endif
+                        @if ($patient->ideal_bmi)
+                            <small class="text-muted">BMI (Ideal)
+                                <b>{{ $patient->ideal_bmi }}</b> {{ $patient->ideal_bmi_category }}</small>
+                        @endif
+                    </div>
+                </td> --}}
+                    {{-- <td>
+                    @if ($patient->most_recent_cellular_bp_measurement_at)
+                        {{ $patient->most_recent_cellular_bp_sbp_mm_hg }}
+                        / {{ $patient->most_recent_cellular_bp_dbp_mm_hg }}
+                    @endif
+                </td> --}}
+                    {{-- <td><?= $patient->most_recent_cellular_bp_value_irregular ? '<i class="fa fa-heartbeat"></i>' : '' ?></td> --}}
+                    {{-- <td>{{ $patient->most_recent_cellular_bp_value_pulse }}</td> --}}
+                    {{-- <td>{{ $patient->most_recent_cellular_weight_value ? round($patient->most_recent_cellular_weight_value, 2) : '--' }}</td> --}}
+                    {{-- <td class="d-none text-nowrap">
+                    <?php $m = $patient->lastMeasurementOfType('Wt. (lbs.)'); ?>
+                    {{$m && $m->value ? round($m->value, 2) : '-'}}
+                </td> --}}
+                    {{-- <td class="d-none text-nowrap">
+                    <?php $m = $patient->lastMeasurementOfType('BP'); ?>
+                    {{$m && $m->value ? $m->value : '-'}}
+                </td> --}}
+                    {{-- <td>{{count($patient->cellularMeasurements)}}</td> --}}
+                    {{-- <td>{{$patient->email_address}}</td> --}}
+
+                    <td>
+                        <div class="d-flex flex-column">
+                            @foreach ($patient->companyClients as $companyClient)
+                            <span>{{ $companyClient->company->name }}</span>
+                            @endforeach
+                        </div>
+                    </td>
+                </tr>
+            @endforeach
+
+            @if (count($patients) === 0)
+                <tr>
+                    <td colspan="24">No records found!</td>
+                </tr>
+            @endif
+        </tbody>
+    </table>
+</div>
+<div class="px-3 pt-3 d-flex align-items-center">
+    {{ $patients->withQueryString()->links() }}
+    <div class="ml-4 mb-3">Showing <b>{{ $patients->firstItem() }}</b> to <b>{{ $patients->lastItem() }}</b> (page
+        {{ $patients->currentPage() }}) of <b>{{ $patients->total() }}</b> patients</div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            let panning = false,
+                prevX = false,
+                prevY = false;
+            $('#admin-patients-list-extended')
+                .off('mousedown.pan')
+                .on('mousedown.pan', function(_e) {
+                    if (panning && panning.length) return false;
+                    if (_e.ctrlKey) {
+                        prevX = _e.screenX;
+                        prevY = _e.screenY;
+                        panning = $(this);
+                        return false;
+                    }
+                });
+            $(document)
+                .off('mousemove.pan')
+                .on('mousemove.pan', function(_e) {
+                    if (!panning || !panning.length) return;
+                    let deltaX = _e.screenX - prevX,
+                        deltaY = _e.screenY - prevY;
+                    panning.scrollTop(panning.scrollTop() - deltaY);
+                    panning.scrollLeft(panning.scrollLeft() - deltaX);
+                    prevX = _e.screenX;
+                    prevY = _e.screenY;
+                });
+            $(document)
+                .off('mouseup.pan')
+                .on('mouseup.pan', function(_e) {
+                    panning = false;
+                });
+
+            $(document)
+                .off('click.enable-grid', '.enable-grid')
+                .on('click.enable-grid', '.enable-grid', function() {
+                    $('#admin-patients-list-extended>table').addClass('stag-compact-grid');
+                    localStorage.adminPatientsTableFormat = 'grid';
+                    return false;
+                });
+
+            $(document)
+                .off('click.disable-grid', '.disable-grid')
+                .on('click.disable-grid', '.disable-grid', function() {
+                    $('#admin-patients-list-extended>table').removeClass('stag-compact-grid');
+                    localStorage.adminPatientsTableFormat = 'regular';
+                    return false;
+                });
+
+            if (localStorage.adminPatientsTableFormat !== 'regular') {
+                $('#admin-patients-list-extended>table').addClass('stag-compact-grid');
+            } else {
+                $('#admin-patients-list-extended>table').removeClass('stag-compact-grid');
+            }
+        }
+
+        addMCInitializer('admin-patients-list-extended', init, '#admin-patients-list-extended');
+    }).call(window);
+</script>

+ 39 - 304
resources/views/app/admin/patients-table-extended.blade.php

@@ -21,10 +21,6 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                 ])</th>
                 @if ($pro->pro_type == 'ADMIN')
                     <th class="border-0 text-secondary">MCP</th>
-                    {{-- <th class="border-0">NA</th> --}}
-                    {{-- <th class="border-0">Initiative</th> --}}
-                    {{-- <th class="border-9">Status</th> --}}
-                    {{-- <th class="border-0">Source</th> --}}
                 @endif
                 <th class="border-0 text-secondary">State</th>
                 <th class="border-0 text-secondary">Insurance</th>
@@ -63,23 +59,6 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                 <th class="border-0 text-secondary">Pulse Ox.</th>
                 <th class="border-0 text-secondary">Cell. Bp</th>
                 <th class="border-0 text-secondary">Wt. Scale</th>
-                <th class="border-0 text-secondary">Companies</th>
-
-
-                {{-- <th class="border-0">DOB</th> --}}
-                {{-- <th class="border-0">Age</th> --}}
-                {{-- <th class="border-0">Sex</th> --}}
-                {{-- <th class="border-0">BMI</th> --}}
-                {{-- <th class="border-0">BP</th> --}}
-                {{-- <th class="border-0"><i class="fa fa-heartbeat"></i></th> --}}
-                {{-- <th class="border-0">Pulse</th> --}}
-                {{-- <th class="border-0">Weight</th> --}}
-                {{-- <th class="border-0"># Cellular Measurements</th> --}}
-                {{-- <th>Scale <i class="fa fa-battery"></i></th> --}}
-                {{-- <th class="border-0">RPM</th> --}}
-                {{-- <th class="border-0 d-none">Last Weight-In</th> --}}
-                {{-- <th class="border-0 d-none">Last BP</th> --}}
-                {{-- <th class="border-0">Email Address</th> --}}
             </tr>
         </thead>
         <tbody>
@@ -90,27 +69,26 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                         {{ $patient->client_engagement_status_category == 'DUMMY' ? 'Test Record' : $patient->client_engagement_status_category }}
                     </td>
                     <td>
-                        <a native target="_blank" href="{{ route('patients.view.dashboard', $patient) }}">
+                        <a native target="_blank" href="{{ route('patients.view.dashboard', $patient->uid) }}">
                             {{ $patient->chart_number }}
                         </a>
                     </td>
                     <td>
                         <div class="d-flex align-items-baseline flex-nowrap">
-                            <span>{{ $patient->displayName() }}</span>
-                            <?php $latestMemo = $patient->latestMemo(); ?>
+                            <span>{{ $patient->display_name }}</span>
                             <div class="on-hover-show d-inline-block on-hover-opaque ml-auto mr-1">
-                                <i class="fa fa-info-circle ml-1 {{ $latestMemo ? '' : 'opacity-35' }}"></i>
+                                <i class="fa fa-info-circle ml-1 {{ $patient->last_memo_created_at ? '' : 'opacity-35' }}"></i>
                                 <div class="on-hover-content py-2 pl-3 text-nowrap text-dark"
                                     style="left:0;right:auto;">
-                                    @if ($latestMemo)
+                                    @if ($patient->last_memo_created_at)
                                         <p class="mb-1 font-weight-bold text-secondary">Last Memo:
-                                            {{ $latestMemo->category }}</p>
-                                        <div class="text-wrap mb-1">{{ $latestMemo->content }}</div>
+                                            {{ $patient->last_memo_category }}</p>
+                                        <div class="text-wrap mb-1">{{ $patient->last_memo_content }}</div>
                                         <div class="text-secondary text-sm mb-1">
-                                            {{ friendly_date_time($latestMemo->created_at) }}</div>
-                                        @if ($latestMemo->createdBy && $latestMemo->createdBy->pro)
+                                            {{ friendly_date_time($patient->last_memo_created_at) }}</div>
+                                        @if ($patient->last_memo_created_by_pro_display_name)
                                             <div class="text-secondary text-sm">By
-                                                {{ $latestMemo->createdBy->pro->displayName() }}</div>
+                                                {{ $patient->last_memo_created_by_pro_display_name }}</div>
                                         @endif
                                     @else
                                         <div class="text-secondary">No client memos.</div>
@@ -121,23 +99,19 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                     </td>
                     @if ($pro->pro_type == 'ADMIN')
                         <td>
-                        @if(@$patient->mcp)
-                            {{ $patient->mcp->displayName() }}
-                            @if(!$patient->mcp->is_hcp)
-                                <small class="text-danger font-weight-bold"><i class="fas fa-exclamation-triangle fa-fw"></i> {{ $patient->mcp->name_first }} is no longer HCP.</small>
+                        @if(@$patient->mcp_pro_display_name)
+                            {{ $patient->mcp_pro_display_name }}
+                            @if(!$patient->mcp_is_hcp)
+                                <small class="text-danger font-weight-bold"><i class="fas fa-exclamation-triangle fa-fw"></i> {{ $patient->mcp_pro_display_name }} is no longer HCP.</small>
                             @endif
                         @else
                             --
                         @endif
                         </td>
-                        {{-- <td>{{@$patient->defaultNaPro ? $patient->defaultNaPro->displayName() : '--'}}</td> --}}
-                        {{-- <td>{{$patient->initiative}}</td> --}}
-                        {{-- <td>{{$patient->client_engagement_status_category == 'DUMMY'? 'Test Record': $patient->client_engagement_status_category}}</td> --}}
-                        {{-- <td>{{$patient->source}}</td> --}}
                     @endif
                     <td>{{ $patient->mailing_address_state }}</td>
                     <td class="{{ $patient->mpb_remaining === 0 ? 'deductible-zero' : '' }}">
-                        @include('app.patient.coverage_column_renderer', ['patient' => $patient])
+                        @include('app.patient.coverage_column_fast_renderer', ['patient' => $patient])
 
                     </td>
                     @if ($performer->pro->pro_type == 'ADMIN')
@@ -152,16 +126,15 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                         {{ friendly_date($patient->most_recent_completed_mcp_note_date) }}
                     </td>
                     <td>
-                        @if ($patient->lastMcpAppointment)
-                            <small class="text-muted">{{ $patient->lastMcpAppointment->pro->displayName() }}</small>
+                        @if ($patient->last_mcp_appointment_display_name)
+                            <small class="text-muted">{{ $patient->last_mcp_appointment_display_name }}</small>
                         @endif
                     </td>
                     <td>
-                        <?php $lastMemo = $patient->lastMemo(); ?>
-                        @if ($lastMemo)
-                            {{ friendly_date($lastMemo->created_at) }}
+                        @if ($patient->last_memo_created_at)
+                            {{ friendly_date($patient->last_memo_created_at) }}
                             <?php
-                        $daysAgo = date_diff(date_create($lastMemo->created_at), date_create('now'))->days;
+                        $daysAgo = date_diff(date_create($patient->last_memo_created_at), date_create('now'))->days;
                         if ($daysAgo > 0) {
                             ?>
                             <span class="text-sm text-secondary">({{ $daysAgo }} day{{ $daysAgo > 1 ? 's' : '' }}
@@ -174,222 +147,28 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                         @endif
                     </td>
                     <td class="p-0 pb-1">
-                        <div if-details-view>
-                            @if (count($patient->activeNotes))
-                                <?php $noteIndex = 0; ?>
-                                @foreach ($patient->activeNotes as $note)
-                                    <?php $noteIndex++; ?>
-                                    <div class="mt-1 bg-white border p-2">
-                                        <div class="d-flex align-items-baseline">
-                                            <span
-                                                class="mr-2 font-weight-bold text-secondary">{{ $noteIndex }}.</span>
-                                            <a native target="_blank"
-                                                href="/patients/view/{{ $patient->uid }}/notes/view/{{ $note->uid }}">
-                                                <b>{{ friendly_date_time($note->effective_dateest, false) }}</b>
-                                            </a>
-                                            <span class="mx-2 text-sm">/</span>
-                                            <span>{{ $note->new_or_fu_or_na === 'NEW' ? 'New' : 'Follow-up' }}</span>
-                                            <span class="mx-2 text-sm">/</span>
-                                            <span>{{ $note->hcpPro ? $note->hcpPro->name_display : '-' }}</span>
-                                            <span class="mx-2 text-sm">/</span>
-                                            <span>{{ noteMethodDisplay($note->method) }}</span>
-                                            @if ($note->hcpPro && $note->is_signed_by_hcp)
-                                                <span class="mx-2 text-sm">/</span>
-                                                <span class="text-success">Signed</span>
-                                            @endif
-                                        </div>
-                                        <?php
-                                        $bills = \App\Models\Bill::where('note_id', $note->id)
-                                            ->where('bill_service_type', '<>', 'GENERIC')
-                                            ->where('is_cancelled', false)
-                                            ->orderBy('id', 'desc')
-                                            ->get();
-                                        ?>
-                                        @if (count($bills))
-                                            <hr class="my-2">
-                                            <div class="d-flex align-items-start text-sm">
-                                                <b class="text-secondary width-60px">Bills:</b>
-                                                <div class="ml-2 flex-grow-1">
-                                                    @foreach ($bills as $bill)
-                                                        <div class="border border-info bg-aliceblue p-1 mb-1">
-                                                            <div class="d-flex align-items-baseline">
-                                                                <span>{{ $bill->code }}</span>
-                                                                <span class="mx-2 text-sm">/</span>
-                                                                <span>
-                                                                    @if (strpos(strtolower($bill->code), 'treatment services') !== false)
-                                                                        <?php
-                                                                        $totalSeconds = $bill->number_of_units * 3600;
-                                                                        $remainder = $totalSeconds % 60;
-                                                                        if ($remainder !== 0) {
-                                                                            if ($remainder < 30) {
-                                                                                $totalSeconds = $totalSeconds - $remainder;
-                                                                            } else {
-                                                                                $totalSeconds = $totalSeconds + (60 - $remainder);
-                                                                            }
-                                                                        }
-                                                                        ?>
-                                                                        {{ time_in_hrminsec($totalSeconds) }}
-                                                                    @else
-                                                                        @if (!!$bill->number_of_units)
-                                                                            {{ $bill->number_of_units }} unit(s)
-                                                                        @else
-                                                                            -
-                                                                        @endif
-                                                                    @endif
-                                                                </span>
-                                                                @if ($bill->is_signed_by_hcp)
-                                                                    <span class="mx-2 text-sm">/</span>
-                                                                    <span class="d-block text-nowrap">
-                                                                        <i class="fa fa-check"></i>
-                                                                        Signed
-                                                                    </span>
-                                                                @endif
-                                                                @if ($bill->is_verified)
-                                                                    <span class="mx-2 text-sm">/</span>
-                                                                    <span class="d-block text-nowrap">
-                                                                        <i class="fa fa-check"></i>
-                                                                        Verified
-                                                                    </span>
-                                                                @endif
-                                                                @if (!$bill->has_hcp_been_paid)
-                                                                    <span class="mx-2 text-sm">/</span>
-                                                                    <div class="text-nowrap mt-1 screen-only">
-                                                                        <span class="">Expected: </span>
-                                                                        <span
-                                                                            class="font-weight-bold">${{ $bill->hcp_expected_payment_amount }}</span>
-                                                                    </div>
-                                                                @else
-                                                                    <span class="mx-2 text-sm">/</span>
-                                                                    <div class="text-nowrap mt-1 screen-only">
-                                                                        <span class="">Paid: </span>
-                                                                        <span
-                                                                            class="font-weight-bold">${{ $bill->hcp_payment_amount }}</span>
-                                                                    </div>
-                                                                @endif
-                                                            </div>
-                                                        </div>
-                                                    @endforeach
-                                                </div>
-                                            </div>
-                                        @endif
-                                        <?php
-                                        $claims = \App\Models\Claim::where('note_id', $note->id)
-                                            ->where('is_cancelled', false)
-                                            ->orderBy('id', 'desc')
-                                            ->get();
-                                        ?>
-                                        @if (count($claims))
-                                            <hr class="my-2">
-                                            <div class="d-flex align-items-start text-sm">
-                                                <b class="text-secondary width-60px">Claims:</b>
-                                                <div class="ml-2 flex-grow-1 border border-success">
-                                                    <table class="table table-sm tabe-striped mb-0 border-0">
-                                                        <tbody>
-                                                            @foreach ($claims as $claim)
-                                                                @if ($claim->status !== 'CANCELLED' || request('claims-filter') === 'all')
-                                                                    <tr
-                                                                        class="{{ $claim->status === 'CANCELLED' ? 'text-secondary bg-light on-hover-opaque' : '' }}">
-                                                                        <td class="p-0 border-left border-right">
-                                                                            @if ($claim->lines->count())
-                                                                                <table
-                                                                                    class="table table-sm table-condensed border-0 mb-0">
-                                                                                    <thead>
-                                                                                        <tr class="bg-light">
-                                                                                            <th class="border-0">CPT
-                                                                                            </th>
-                                                                                            <th class="border-0">DOS
-                                                                                            </th>
-                                                                                            <th class="border-0">ICDs
-                                                                                            </th>
-                                                                                        </tr>
-                                                                                    </thead>
-                                                                                    <tbody class="">
-                                                                                        @foreach ($claim->lines as $line)
-                                                                                            <tr class="claim-line">
-                                                                                                <td>{{ $line->cpt }}
-                                                                                                    <div>Units:
-                                                                                                        <b>{{ !@$line->units ? 1 : $line->units }}</b>
-                                                                                                    </div>
-                                                                                                </td>
-                                                                                                <td class="text-nowrap">
-                                                                                                    {{ friendlier_date($line->date_of_service) }}
-                                                                                                </td>
-                                                                                                <td>
-                                                                                                    @if (count($line->claimLineIcds))
-                                                                                                        @foreach ($line->claimLineIcds as $icd)
-                                                                                                            <div>
-                                                                                                                <b class="c-pointer border-secondary border-bottom"
-                                                                                                                    title="{{ $icd->description }}">{{ $icd->code }}</b>
-                                                                                                            </div>
-                                                                                                        @endforeach
-                                                                                                    @else
-                                                                                                        <p>No ICDs set
-                                                                                                        </p>
-                                                                                                    @endif
-                                                                                                </td>
-                                                                                            </tr>
-                                                                                        @endforeach
-                                                                                    </tbody>
-                                                                                </table>
-                                                                            @else
-                                                                                <p>No lines for this claim</p>
-                                                                            @endif
-                                                                        </td>
-                                                                        <td class="border-right p-0">
-
-                                                                            <!-- payer, company, location -->
-                                                                            <div class="p-1">
-                                                                                <div class="mt-1">
-                                                                                    <div>
-                                                                                        <b>{{ $claim->primaryPayer ? $claim->primaryPayer->name : '-' }}</b>
-                                                                                        /
-                                                                                        {{ $claim->status ? $claim->status : 'Status not set' }}
-                                                                                    </div>
-                                                                                </div>
-
-                                                                                <div class="mt-1">
-                                                                                    {{ $claim->companyPro && $claim->companyPro->company ? $claim->companyPro->company->name : '-' }}
-                                                                                </div>
-
-                                                                                <div class="mt-1">
-                                                                                    {{ $claim->companyLocation ? $claim->companyLocation->line1 . ', ' . $claim->companyLocation->city : '-' }}
-                                                                                </div>
-                                                                            </div>
-                                                                        </td>
-                                                                    </tr>
-                                                                @endif
-                                                            @endforeach
-                                                        </tbody>
-                                                    </table>
-                                                </div>
-                                            </div>
-                                        @endif
-                                    </div>
-                                @endforeach
-                            @endif
-                        </div>
-                        <div if-grid-view class="p-1">
-                            {{ count($patient->activeNotes) }}
+                        <div class="p-1">
+                            {{ $patient->active_notes_count }}
                         </div>
                     </td>
-                    <td>{{ $patient->nextMcpAppointment ? friendly_date_time($patient->nextMcpAppointment->raw_date . ' ' . $patient->nextMcpAppointment->raw_start_time) : '' }}
+                    <td>{{ $patient->next_mcp_appointment_raw_date ? friendly_date_time($patient->next_mcp_appointment_raw_date . ' ' . $patient->next_mcp_appointment_start_time) : '' }}
                         <span if-grid-view>
-                            @if ($patient->nextMcpAppointment)
-                                {{-- {{$patient->nextMcpAppointment->status}} --}}
-                            @elseif($patient->mostRecentCompletedMcpNote && $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo)
+                            @if ($patient->next_mcp_appointment_raw_date)
+                                {{-- {{$patient->next_mcp_appointment_status}} --}}
+                            @elseif($patient->most_recent_completed_mcp_note_date)
                                 <div class="w-100 text-nowrap overflow-hidden text-ellipsis max-width-170px"
-                                    title="{{ $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo }}">
+                                    title="{{ $patient->most_recent_completed_note_followup_memo }}">
                                     <b>No</b>
-                                    {{ $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo }}
+                                    {{ $patient->most_recent_completed_note_followup_memo }}
                                 </div>
                             @endif
                         </span>
                         <div if-details-view>
-                            @if ($patient->nextMcpAppointment)
-                                {{ $patient->nextMcpAppointment->status }}
-                            @elseif($patient->mostRecentCompletedMcpNote && $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo)
+                            @if ($patient->next_mcp_appointment_raw_date)
+                                {{ $patient->next_mcp_appointment_status }}
+                            @elseif($patient->most_recent_completed_mcp_note_date)
                                 <b>No</b>
-                                {{ $patient->mostRecentCompletedMcpNote->follow_up_not_needed_memo }}
+                                {{ $patient->most_recent_completed_note_followup_memo }}
                             @endif
                         </div>
                     </td>
@@ -399,66 +178,22 @@ $patientEngagementColorCodes = @Config::get('constants.client_engagement_status_
                         <div title="{{ friendly_date_time($patient->created_at) }}">
                             {{ friendly_date_time($patient->created_at, false) }}</div>
                         <div class="mt-1" if-details-view>
-                            By <span>{{ $patient->creator ? $patient->creator->displayName() : '-' }}</span>
+                            By <span>{{ $patient->creator_display_name ? $patient->creator_display_name : '-' }}</span>
                         </div>
                     </td>
-                    <td>{{ $patient->getMcpAssignedOn() }}</td>
-                    <td>{{ $patient->defaultNaPro ? $patient->defaultNaPro->displayName() : '-' }}</td>
-
-                    <td>{{ $patient->temparatureGunDeliveryStatus() }}</td>
-                    <td>{{ $patient->pulseOximeterDeliveryStatus() }}</td>
-                    <td>{{ $patient->hasBPDevice() ? 'DELIVERED' : '' }}</td>
-                    <td>{{ $patient->hasWeightScaleDevice() ? 'DELIVERED' : '' }}</td>
+                    <td>{{ friendly_date($patient->mcp_assigned_on) }}</td>
+                    <td>{{ $patient->dna_display_name ? $patient->dna_display_name : '-' }}</td>
 
-                    {{-- <td>{{ friendly_date_time($patient->dob, false) }}</td> --}}
-                    {{-- <td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td> --}}
-                    {{-- <td>{{ $patient->sex }}</td> --}}
-                    {{-- <td>
-                    <div class="d-none d-dflex flex-column">
-                        @if ($patient->usual_bmi_min && $patient->usual_bmi_max)
-                            <small class="text-muted">BMI (Usual):
-                                <b>{{ $patient->usual_bmi_min }}</b> {{ $patient->usual_bmi_min_category }} to
-                                <b>{{ $patient->usual_bmi_max }}</b> {{ $patient->usual_bmi_max_category }}</small>
-                        @endif
-                        @if ($patient->ideal_bmi)
-                            <small class="text-muted">BMI (Ideal)
-                                <b>{{ $patient->ideal_bmi }}</b> {{ $patient->ideal_bmi_category }}</small>
-                        @endif
-                    </div>
-                </td> --}}
-                    {{-- <td>
-                    @if ($patient->most_recent_cellular_bp_measurement_at)
-                        {{ $patient->most_recent_cellular_bp_sbp_mm_hg }}
-                        / {{ $patient->most_recent_cellular_bp_dbp_mm_hg }}
-                    @endif
-                </td> --}}
-                    {{-- <td><?= $patient->most_recent_cellular_bp_value_irregular ? '<i class="fa fa-heartbeat"></i>' : '' ?></td> --}}
-                    {{-- <td>{{ $patient->most_recent_cellular_bp_value_pulse }}</td> --}}
-                    {{-- <td>{{ $patient->most_recent_cellular_weight_value ? round($patient->most_recent_cellular_weight_value, 2) : '--' }}</td> --}}
-                    {{-- <td class="d-none text-nowrap">
-                    <?php $m = $patient->lastMeasurementOfType('Wt. (lbs.)'); ?>
-                    {{$m && $m->value ? round($m->value, 2) : '-'}}
-                </td> --}}
-                    {{-- <td class="d-none text-nowrap">
-                    <?php $m = $patient->lastMeasurementOfType('BP'); ?>
-                    {{$m && $m->value ? $m->value : '-'}}
-                </td> --}}
-                    {{-- <td>{{count($patient->cellularMeasurements)}}</td> --}}
-                    {{-- <td>{{$patient->email_address}}</td> --}}
-
-                    <td>
-                        <div class="d-flex flex-column">
-                            @foreach ($patient->companyClients as $companyClient)
-                            <span>{{ $companyClient->company->name }}</span>
-                            @endforeach
-                        </div>
-                    </td>
+                    <td>{{ $patient->temparature_gun_delivery_status }}</td>
+                    <td>{{ $patient->oximeter_delivery_status }}</td>
+                    <td>{{ $patient->has_bp_device ? 'DELIVERED' : '' }}</td>
+                    <td>{{ $patient->has_weight_scale_device ? 'DELIVERED' : '' }}</td>
                 </tr>
             @endforeach
 
             @if (count($patients) === 0)
                 <tr>
-                    <td colspan="24">No records found!</td>
+                    <td colspan="23">No records found!</td>
                 </tr>
             @endif
         </tbody>

+ 17 - 17
resources/views/app/dna/patients-table.blade.php

@@ -20,12 +20,12 @@
 		?>
 		<tr>
 			<td>
-				<a native target="_blank" href="{{route('patients.view.dashboard', $patient)}}">
+				<a native target="_blank" href="{{route('patients.view.dashboard', $patient->uid)}}">
 					{{$patient->chart_number}}
 				</a>
 			</td>
 			<td>
-				{{$patient->displayName()}}
+				{{$patient->display_name}}
 			</td>
 			<td class="text-nowrap">{{ friendly_date_time($patient->dob, false) }}</td>
 			<td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td>
@@ -41,11 +41,11 @@
 				</div>
 			</td>
 			<td>
-				@include('app.patient.coverage_column_renderer', ['patient'=>$patient])
+				@include('app.patient.coverage_column_fast_renderer', ['patient'=>$patient])
 			</td>
 			<td>
 				<div class="d-flex flex-column">
-					<span>{{ $patient->mcp ? $patient->mcp->displayName() :'' }}</span>	
+					<span>{{ $patient->mcp_pro_display_name ? $patient->mcp_pro_display_name :'' }}</span>	
 					<span>Status: 
 						@if($patient->has_mcp_done_onboarding_visit === 'YES')
 						<i class="fas fa-check-circle text-success" data-toggle="tooltip" data-placement="bottom" title="YES"></i>
@@ -55,21 +55,21 @@
 							<i class="fas fa-question-circle text-secondary" data-toggle="tooltip" data-placement="bottom" title="UNKNOWN"></i>
 						@endif
 					</span>				
-					@if($patient->mostRecentCompletedMcpNote)
+					@if($patient->most_recent_completed_mcp_note_id)
 						<span>Last Encounter:  
-						<a href="/patients/view/{{ $patient->mostRecentCompletedMcpNote->client->uid }}/notes/view/{{ $patient->mostRecentCompletedMcpNote->uid }}" class="font-weight-bold">
-                                {{ friendly_date_time($patient->mostRecentCompletedMcpNote->effective_dateest, false) }}
+						<a href="/patients/view/{{ $patient->uid }}/notes/view/{{ $patient->most_recent_completed_mcp_note_uid }}" class="font-weight-bold">
+                                {{ friendly_date_time($patient->most_recent_completed_mcp_note_effective_dateest, false) }}
                             </a>
 						</span>
 					@endif
 					@if($patient->next_mcp_appointment_date)
 						<span class="text-muted">Next Appt. <b>{{ friendly_date_time($patient->next_mcp_appointment_date) }}</b></span>
 					@endif
-					<?php $recentNote = $patient->mostRecentCompletedMcpNote; ?>
-					@if($recentNote)
+					
+					@if($patient->most_recent_completed_mcp_note_uid)
 					<div>
-						Note: <a href="/patients/view/{{ $patient->uid }}/notes/view/{{ $recentNote->uid }}" class="font-weight-bold">
-                        {{ friendly_date_time($recentNote->effective_dateest, false) }}
+						Note: <a href="/patients/view/{{ $patient->uid }}/notes/view/{{ $patient->most_recent_completed_mcp_note_uid }}" class="font-weight-bold">
+                        {{ friendly_date_time($patient->most_recent_completed_mcp_note_effective_dateest, false) }}
                     </a>
 					</div>
 					@endif
@@ -107,13 +107,13 @@
 							<span>{{ $patient->why_not_eligible_for_rm_memo }}</span>
 						</div>
 				   </div>
-				<?php $m = $patient->lastMeasurementOfType('Wt. (lbs.)');?>
-				@if($m)
-				<span class="d-block mt-1">Wt. (lbs.) {{$m && $m->value ? round($m->value, 2) : '-'}}</span>
+				   
+				@if($patient->last_measurement_of_type_weight)
+				<span class="d-block mt-1">Wt. (lbs.) {{$patient->last_measurement_of_type_weight ? round($patient->last_measurement_of_type_weight, 2) : '-'}}</span>
 				@endif
-				<?php $bp = $patient->lastMeasurementOfType('BP'); ?>
-				@if($bp)
-				<span class="d-block mt-1">BP. {{$bp && $bp->value ? $bp->value : '-'}}</span>
+				
+				@if($patient->last_measurement_of_type_bp)
+				<span class="d-block mt-1">BP. {{$patient->last_measurement_of_type_bp ? $patient->last_measurement_of_type_bp : '-'}}</span>
 				@endif
 			   </div>
 			</td>

+ 101 - 0
resources/views/app/mcp/patients-table-depricated.blade.php

@@ -0,0 +1,101 @@
+<div class="table-responsive">
+	<table class="table table-striped p-0 m-0 table-sm border-top border-bottom text-nowrap table-bordered">
+		<thead class="bg-light">
+			<tr>
+				<th class="border-0 text-secondary">#</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Name', 'key' => 'name_first'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'DOB', 'key' => 'dob'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Age', 'key' => 'age_in_years'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Sex', 'key' => 'sex'])</th>
+				<th class="border-0 text-secondary">Insurance</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Last Visit', 'key' => 'most_recent_completed_mcp_note_date'])</th>
+				<th class="border-0 text-secondary">Next Appt.</th>
+				<th class="border-0 text-secondary">Status</th>
+
+				<th class="border-0 text-secondary">BP</th>
+				<th class="border-0 text-nowrap">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => '<i class="fa fa-heartbeat text-secondary"></i>', 'key' => 'most_recent_cellular_bp_value_irregular'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Pulse', 'key' => 'most_recent_cellular_bp_value_pulse'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'BP/Pulse Timestamp', 'key' => 'most_recent_cellular_bp_measurement_at'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Weight', 'key' => 'most_recent_cellular_weight_value'])</th>
+				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Weight Timestamp', 'key' => 'most_recent_cellular_weight_measurement_at'])</th>
+
+				{{-- <th>Scale <i class="fa fa-battery"></i></th>--}}
+				{{-- <th class="border-0">RPM</th>--}}
+				{{-- <th class="border-0 d-none">Last Weight-In</th>--}}
+				{{-- <th class="border-0 d-none">Last BP</th>--}}
+				<th class="border-0 text-secondary">Assigned On</th>
+
+				@if($pro->pro_type == 'ADMIN')
+				<th class="border-0 text-secondary">MCP</th>
+				<th class="border-0 text-secondary">Initiative</th>
+				@endif
+			</tr>
+		</thead>
+		<tbody>
+			@foreach($patients as $patient)
+			<tr>
+				<td>
+					<a native target="_blank" href="{{route('patients.view.dashboard', $patient)}}">
+						{{$patient->chart_number}}
+					</a>
+				</td>
+				<td>
+					{{$patient->displayName()}}
+				</td>
+				<td>{{ friendly_date_time($patient->dob, false) }}</td>
+				<td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td>
+				<td>{{ $patient->sex }}</td>
+				<td>
+					@include('app.patient.coverage_column_renderer', ['patient'=>$patient])
+				</td>
+				<td>
+					{{ friendly_date($patient->most_recent_completed_mcp_note_date) }}
+					{{-- {{$patient->lastMcpAppointment ? friendly_date_time($patient->lastMcpAppointment->raw_date.' '.$patient->lastMcpAppointment->raw_start_time) : '-'}}--}}
+				</td>
+				<td>{{$patient->nextMcpAppointment ? friendly_date_time($patient->nextMcpAppointment->raw_date.' '.$patient->nextMcpAppointment->raw_start_time) : '-'}}</td>
+				<td>{{$patient->nextMcpAppointment ? $patient->nextMcpAppointment->status : '-'}}</td>
+
+				<td>
+					@if($patient->most_recent_cellular_bp_measurement_at)
+					{{ $patient->most_recent_cellular_bp_sbp_mm_hg }} / {{ $patient->most_recent_cellular_bp_dbp_mm_hg }}
+					@endif
+				</td>
+
+				<td><?= $patient->most_recent_cellular_bp_value_irregular ? '<i class="fa fa-heartbeat"></i>' : '' ?></td>
+
+				<td>{{ $patient->most_recent_cellular_bp_value_pulse }}</td>
+
+				<td>{{ friendlier_date_time($patient->most_recent_cellular_bp_measurement_at, false) }}</td>
+
+				<td>{{ $patient->most_recent_cellular_weight_value ? round($patient->most_recent_cellular_weight_value, 2) : '--' }}</td>
+
+				<td>{{ friendlier_date_time($patient->most_recent_cellular_weight_measurement_at, false) }}</td>
+
+				<td class="d-none text-nowrap">
+					<?php $m = $patient->lastMeasurementOfType('Wt. (lbs.)'); ?>
+					{{$m && $m->value ? round($m->value, 2) : '-'}}
+				</td>
+				<td class="d-none text-nowrap">
+					<?php $m = $patient->lastMeasurementOfType('BP'); ?>
+					{{$m && $m->value ? $m->value : '-'}}
+				</td>
+				<td>{{$patient->getMcpAssignedOn()}}</td>
+				@if($pro->pro_type == 'ADMIN')
+				<td>{{$patient->mcp->display_name ?? '--'}}</td>
+				<td>{{$patient->initiative}}</td>
+				@endif
+			</tr>
+			@endforeach
+
+			@if(count($patients) === 0)
+			<tr>
+				<td colspan="24">No records found!</td>
+			</tr>
+			@endif
+		</tbody>
+
+	</table>
+</div>
+<div class="p-3">
+	{{$patients->withQueryString()->links()}}
+</div>

+ 9 - 16
resources/views/app/mcp/patients-table.blade.php

@@ -19,10 +19,6 @@
 				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Weight', 'key' => 'most_recent_cellular_weight_value'])</th>
 				<th class="border-0">@include('app.practice-management._sort_header', ['route' => route("mcp.patients"), 'label' => 'Weight Timestamp', 'key' => 'most_recent_cellular_weight_measurement_at'])</th>
 
-				{{-- <th>Scale <i class="fa fa-battery"></i></th>--}}
-				{{-- <th class="border-0">RPM</th>--}}
-				{{-- <th class="border-0 d-none">Last Weight-In</th>--}}
-				{{-- <th class="border-0 d-none">Last BP</th>--}}
 				<th class="border-0 text-secondary">Assigned On</th>
 
 				@if($pro->pro_type == 'ADMIN')
@@ -35,25 +31,24 @@
 			@foreach($patients as $patient)
 			<tr>
 				<td>
-					<a native target="_blank" href="{{route('patients.view.dashboard', $patient)}}">
+					<a native target="_blank" href="{{route('patients.view.dashboard', $patient->uid)}}">
 						{{$patient->chart_number}}
 					</a>
 				</td>
 				<td>
-					{{$patient->displayName()}}
+					{{$patient->display_name}}
 				</td>
 				<td>{{ friendly_date_time($patient->dob, false) }}</td>
 				<td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td>
 				<td>{{ $patient->sex }}</td>
 				<td>
-					@include('app.patient.coverage_column_renderer', ['patient'=>$patient])
+					@include('app.patient.coverage_column_fast_renderer', ['patient'=>$patient])
 				</td>
 				<td>
 					{{ friendly_date($patient->most_recent_completed_mcp_note_date) }}
-					{{-- {{$patient->lastMcpAppointment ? friendly_date_time($patient->lastMcpAppointment->raw_date.' '.$patient->lastMcpAppointment->raw_start_time) : '-'}}--}}
 				</td>
-				<td>{{$patient->nextMcpAppointment ? friendly_date_time($patient->nextMcpAppointment->raw_date.' '.$patient->nextMcpAppointment->raw_start_time) : '-'}}</td>
-				<td>{{$patient->nextMcpAppointment ? $patient->nextMcpAppointment->status : '-'}}</td>
+				<td>{{$patient->next_mcp_appointment_raw_date ? friendly_date_time($patient->next_mcp_appointment_raw_date.' '.$patient->next_mcp_appointment_start_time) : '-'}}</td>
+				<td>{{$patient->next_mcp_appointment_status ? $patient->next_mcp_appointment_status : '-'}}</td>
 
 				<td>
 					@if($patient->most_recent_cellular_bp_measurement_at)
@@ -72,16 +67,14 @@
 				<td>{{ friendlier_date_time($patient->most_recent_cellular_weight_measurement_at, false) }}</td>
 
 				<td class="d-none text-nowrap">
-					<?php $m = $patient->lastMeasurementOfType('Wt. (lbs.)'); ?>
-					{{$m && $m->value ? round($m->value, 2) : '-'}}
+					{{$patient->last_measurement_of_type_weight ? round($patient->last_measurement_of_type_weight, 2) : '-'}}
 				</td>
 				<td class="d-none text-nowrap">
-					<?php $m = $patient->lastMeasurementOfType('BP'); ?>
-					{{$m && $m->value ? $m->value : '-'}}
+					{{$patient->last_measurement_of_type_bp ? $patient->last_measurement_of_type_bp : '-'}}
 				</td>
-				<td>{{$patient->getMcpAssignedOn()}}</td>
+				<td>{{friendly_date($patient->mcp_assigned_on)}}</td>
 				@if($pro->pro_type == 'ADMIN')
-				<td>{{$patient->mcp->display_name ?? '--'}}</td>
+				<td>{{$patient->mcp_pro_display_name ?? '--'}}</td>
 				<td>{{$patient->initiative}}</td>
 				@endif
 			</tr>

+ 6 - 6
resources/views/app/patient/care-month/dashboard.blade.php

@@ -309,9 +309,9 @@
                                 </div>
 
                                 {{-- mcp billing --}}
-                                @if($performer->pro->pro_type == 'ADMIN' || $careMonth->mcp && $pro->id === $careMonth->mcp->id)
+                                @if($pro->pro_type == 'ADMIN' || $careMonth->mcp && $pro->id === $careMonth->mcp->id)
                                     <div class="mt-2 d-flex align-items-baseline">
-                                        @if($performer->pro->pro_type == 'ADMIN')
+                                        @if($pro->pro_type == 'ADMIN')
                                             <span class="font-weight-bold text-secondary mr-1">Billing (MCP):</span>
                                         @else
                                             <span class="font-weight-bold text-secondary mr-1">Billing:</span>
@@ -373,9 +373,9 @@
                                 @endif
 
                                 {{-- rmm billing --}}
-                                @if($performer->pro->pro_type == 'ADMIN' || $careMonth->rmmPro && $pro->id === $careMonth->rmmPro->id)
+                                @if($pro->pro_type == 'ADMIN' || $careMonth->rmmPro && $pro->id === $careMonth->rmmPro->id)
                                     <div class="mt-2 d-flex align-items-baseline">
-                                        @if($performer->pro->pro_type == 'ADMIN')
+                                        @if($pro->pro_type == 'ADMIN')
                                             <span class="font-weight-bold text-secondary mr-1">Billing (RMM):</span>
                                         @else
                                             <span class="font-weight-bold text-secondary mr-1">Billing:</span>
@@ -458,7 +458,7 @@
                                 <div class="d-flex align-items-baseline mb-3" tab-links>
                                     <a class="tab-link-active" href="#" tab-link="measurements-graph">Graph</a>
                                     <a class="" href="#" tab-link="measurements-calendar">Calendar</a>
-                                    @if($performer->pro->pro_type == 'ADMIN')
+                                    @if($pro->pro_type == 'ADMIN')
                                         <a class="" href="#" tab-link="measurements-admin">Admin</a>
                                     @endif
                                 </div>
@@ -473,7 +473,7 @@
                                     </div>
                                 </div>
 
-                                @if($performer->pro->pro_type == 'ADMIN')
+                                @if($pro->pro_type == 'ADMIN')
                                     <div class="cm-tab border p-3 d-none" tab-key="measurements-admin">
                                         <div>
                                             <div class="my-1 font-weight-bold text-secondary">Has Anyone Interacted With Client About RM: {{$careMonth->has_anyone_interacted_with_client_about_rm? 'Yes': 'No'}}</div>

+ 2 - 2
resources/views/app/patient/care-months.blade.php

@@ -110,7 +110,7 @@
                 <th class="text-secondary border-bottom-0">RMM</th>
                 <th class="text-secondary border-bottom-0">RME</th>
                 <th class="text-secondary border-bottom-0">ICDs</th>
-                @if($performer->pro->pro_type === 'ADMIN')
+                @if($pro->pro_type === 'ADMIN')
                     <th class="text-secondary border-bottom-0">Claims</th>
                 @endif
                 <th class="text-secondary border-bottom-0">Matrix</th>
@@ -150,7 +150,7 @@
                             {{ implode(', ', $careMonthRmReasonCodes) }}
                         </div>
                     </td>
-                    @if($performer->pro->pro_type === 'ADMIN')
+                    @if($pro->pro_type === 'ADMIN')
                     <td>
                         @foreach($careMonth->claims as $claim)
                             <?php

+ 54 - 0
resources/views/app/patient/coverage_column_fast_renderer.blade.php

@@ -0,0 +1,54 @@
+<div class="d-flex align-items-baseline">
+    <?php
+    $coverageStatus = $patient->getCoverageStatus();
+    ?>
+
+    @if($coverageStatus === 'YES')
+        <i class="fa fa-check-circle text-success"></i>
+    @elseif($coverageStatus === 'NO')
+        @if(!$patient->manual_determination_category)
+            <i class="fas fa-hourglass-half text-warning" title="Pending Validation"></i>
+        @else
+            <i class="fa fa-times text-danger"></i>
+        @endif
+    @else
+        @if($patient->plan_type == 'MEDICARE' && !$patient->auto_medicare_is_match_found)
+            <i class="fa fa-times text-danger"></i>
+        @elseif($patient->plan_type == 'MEDICAID' && !$patient->auto_medicaid_is_match_found)
+            <i class="fa fa-times text-danger"></i>
+        @elseif($patient->plan_type == 'COMMERCIAL' && !$patient->auto_commercial_is_match_found)
+            <i class="fa fa-times text-danger"></i>
+        @else
+            <i class="fa fa-exclamation-triangle text-warning-mellow"></i>
+        @endif
+    @endif
+
+    <div class="ml-2 d-inline-flex align-items-baseline">
+        @if($patient->latest_client_primary_coverage_id)
+            @if($patient->plan_type === 'MEDICAID' && $patient->mcd_payer_name)
+                <span class="{{ @$truncateName ? 'coverage-payer-name':'' }}"
+                      title="{{$patient->mcd_payer_name}}">{{$patient->mcd_payer_name}}</span>
+            @elseif($patient->plan_type === 'COMMERCIAL' && $patient->commercial_payer_name)
+                <span class="{{ @$truncateName ? 'coverage-payer-name':'' }}"
+                      title="{{$patient->commercial_payer_name}}">{{$patient->commercial_payer_name}}</span>
+            @else
+                <span class="{{ @$truncateName ? 'coverage-payer-name':'' }}"
+                      title="{{$patient->insuranceDisplayName()}}">{{$patient->insuranceDisplayName()}}</span>
+            @endif
+        @else
+            <small class="ml-2 text-muted">(No insurance)</small>
+        @endif
+        <div class="">
+            @if($patient->plan_type === 'MEDICARE')
+                @if(@$patient->mpb_remaining)
+                    <span class="text-muted d-block text-sm ml-1">(Ded: {{format_number(@$patient->mpb_remaining)}})</span>
+                @endif
+            @endif
+            @if($patient->plan_type === 'COMMERCIAL')
+                @if(@$patient->deductible_amount && !!+@$patient->deductible_amount)
+                    <span class="text-muted d-block text-sm ml-1">(Ded: {{format_number(@$patient->deductible_amount)}})</span>
+                @endif
+            @endif
+        </div>
+    </div>
+</div>

+ 3 - 179
resources/views/app/patient/dashboard.blade.php

@@ -1,21 +1,7 @@
 @extends ('layouts.patient')
 
 @section('inner-content')
-<?php
-$shortCutsObject = [];
-foreach ($pro->allShortcuts() as $shortcut) {
-
-    // %replaceables%
-    $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
-    $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
-    $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);
-
-    $shortCutsObject[] = [
-        "name" => $shortcut->shortcut,
-        "value" => $shortcut->text
-    ];
-}
-?>
+
 <script>
     window.userShortcuts = <?= json_encode($shortCutsObject); ?>;
 </script>
@@ -29,13 +15,10 @@ foreach ($pro->allShortcuts() as $shortcut) {
     <?php $vitalLabels = ['Ht. (in.)', 'Wt. (lbs.)', 'Temp. (F)', 'Pulse', 'Resp.', 'Pulse Ox.', 'SBP', 'DBP', 'Smoking Status', 'BMI']; ?>
     <?php $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_create($patient->created_at))->invert === 1); ?>
 
-    <?php $nonCoreVisitNotes = $patient->nonCoreVisitNotes; ?>
-    <?php $disallowPointEdits = $nonCoreVisitNotes && count($nonCoreVisitNotes); ?>
-
     <div class="row client-single-dashboard">
         <div class="col-6">
             <?php
-            $myCurrentClientReviewRequest = $performer->pro->currentMonthClientReviewRequest($patient->id);
+            $myCurrentClientReviewRequest = $pro->currentMonthClientReviewRequest($patient->id);
             ?>
             @if($myCurrentClientReviewRequest)
             <div class="pt-2 mt-2">
@@ -126,13 +109,6 @@ foreach ($pro->allShortcuts() as $shortcut) {
             @include('app.patient.point-based-partials.rx')
 
             {{-- devices --}}
-            <?php
-            $availableDevices = count($devices);
-            $patientDeviceIDs = \App\Models\ClientBDTDevice::select('id')->where('client_id', $patient->id)->where('is_active', true)->get()->toArray();
-            $patientDeviceIDs = array_map(function ($_x) {
-                return $_x["id"];
-            }, $patientDeviceIDs);
-            ?>
             <div class="mt-2 pb-1" id="patient-dashboard-devices">
                 <div class="d-flex align-items-center mb-2 py-2 border-top border-bottom">
                     <h6 class="my-0 font-weight-bold">Devices</h6>
@@ -254,7 +230,6 @@ foreach ($pro->allShortcuts() as $shortcut) {
             @endif
 
             <!-- vitals - point -->
-            <?php $latestVitals = \App\Models\Point::where('client_id', $patient->id)->where('category', 'VITALS')->orderBy('id', 'DESC')->first(); ?>
             <div class="pt-2 mt-2">
                 <div class="d-flex align-items-center pb-2">
                     <h6 class="my-0 font-weight-bold">Vitals
@@ -395,158 +370,7 @@ foreach ($pro->allShortcuts() as $shortcut) {
     <div class="row my-3">
         <div class="col-md-12">
             {{-- memos --}}
-            <div class="mb-2 pt-3 pb-2 border-top">
-                <div class="">
-                    <div class="d-flex align-items-start pb-2">
-                        <h6 class="my-0 font-weight-bold">Client Memos</h6>
-                    </div>
-                    <div moe class="w-100 p-2 border mb-3">
-                        <form url="/api/clientMemo/create" show>
-                            <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
-                            <label class="text-secondary font-weight-bold">+ New Memo</label>
-                            <div class="mb-2">
-                                <select class="form-control form-control-sm" name="category" required>
-                                    <option value="">-- select --</option>
-                                    <option value="Incoming Call">Incoming Call</option>
-                                    <option value="Outgoing Call">Outgoing Call</option>
-                                    <option value="Call Unspecified">Call Unspecified</option>
-                                    <option value="Other">Other</option>
-                                </select>
-                            </div>
-                            <div class="mb-2">
-                                <textarea class="form-control form-control-sm" rows="5" name="content" placeholder="Content"></textarea>
-                            </div>
-                            @if($performer->pro->pro_type === 'ADMIN')
-                            <div class="mb-2">
-                                <label for="" class="checkbox">
-                                    <input type="checkbox" name="isAdminOnly">
-                                    Admins only
-                                </label>
-                            </div>
-                            @endif
-                            <div class="d-flex align-items-center">
-                                <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
-                            </div>
-                        </form>
-                    </div>
-                    <table class="table table-striped table-sm table-bordered mb-0">
-                        @if($patient->memos && count($patient->memos))
-                        <thead class="bg-light">
-                            <tr class="text-nowrap">
-                                <th class="border-0 text-secondary">Category</th>
-                                <th class="border-0 text-secondary w-50">Summary</th>
-                                <th class="border-0 text-secondary">Created</th>
-                                @if($performer->pro->pro_type === 'ADMIN')
-                                <th class="border-0 text-secondary">Admins Only</th>
-                                @endif
-                                <th class="border-0 text-secondary">Ack. by MCP</th>
-                                <th class="border-0 text-secondary delete-column">&nbsp;</th>
-                            </tr>
-                        </thead>
-                        <tbody>
-                            @foreach($patient->memos as $memo)
-                            @if(!$memo->is_admin_only || ($memo->is_admin_only && $performer->pro->pro_type === 'ADMIN') )
-                            <tr>
-                                <td class="text-nowrap">{{ $memo->category }}</td>
-                                <td class="px-2">
-                                    <pre class="m-0 break-spaces">{{ $memo->content }}</pre>
-                                </td>
-                                <td class="text-nowrap">
-                                    <strong>{{$memo->createdBy->pro->name_first}} {{$memo->createdBy->pro->name_last}}</strong><br />
-                                    {{ friendly_date_time($memo->created_at) }}
-                                </td>
-                                @if($performer->pro->pro_type === 'ADMIN' )
-                                <td class="text-secondary">
-                                    @if($memo->is_admin_only)
-                                    <span class="text-success"><i class="fas fa-lock"></i> YES</span>
-                                    @else
-                                    <span><i class="fas fa-unlock"></i> NO</span>
-                                    @endif
-                                </td>
-                                @endif
-                                <td>
-                                    @if($memo->mcp_stamp_id)
-                                    <span class="text-success">YES <i class="fas fa-info-circle c-pointer" data-toggle="tooltip" data-placement="bottom" title="{{ friendly_date_time($memo->stamp->created_at) }}"></i></span>
-                                    @else
-                                    <span class="text-secondary">NO</span>
-                                    @endif
-                                </td>
-                                <td class="text-center delete-column">
-                                    @if($performer->pro->pro_type == 'ADMIN')
-                                    <div moe relative bottom class="mr-2">
-                                        <a start show><i class="fa fa-history"></i></a>
-                                        <div action="" url right bottom>
-                                            <table class="table table-condensed table-striped table-sm">
-                                                <thead>
-                                                    <th>Category</th>
-                                                    <th>Summary</th>
-                                                    <th>Created</th>
-
-                                                </thead>
-                                                <tbody>
-                                                    @foreach($memo->updates as $update)
-                                                    <tr>
-                                                        <td>{{$update->category}}</td>
-                                                        <td>{{$update->content}}</td>
-                                                        <td><strong>{{$update->createdBy->proname_first}} {{$update->createdBy->pro->name_last}}</strong><br />{{ friendly_date_time($update->created_at) }}</td>
-
-                                                    </tr>
-                                                    @endforeach
-                                                </tbody>
-                                            </table>
-                                        </div>
-                                    </div>
-                                    @endif
-                                    <div moe wide relative class="mr-2">
-                                        <a class="on-hover-opaque" start show title="Edit">
-                                            <i class="font-size-11 fa fa-edit"></i>
-                                        </a>
-                                        <form url="/api/clientMemo/update" right>
-                                            <input type="hidden" name="uid" value="{{ $memo->uid }}">
-                                            <div class="mb-2">
-                                                <select class="form-control form-control-sm" name="category" required>
-                                                    <option value="">-- select --</option>
-                                                    <option {{ $memo->category === "Incoming Call" ? "selected" : "" }} value="Incoming Call">Incoming Call</option>
-                                                    <option {{ $memo->category === "Outgoing Call" ? "selected" : "" }} value="Outgoing Call">Outgoing Call</option>
-                                                    <option {{ $memo->category === "Call Unspecified" ? "selected" : "" }} value="Call Unspecified">Call Unspecified</option>
-                                                    <option {{ $memo->category === "Other" ? "selected" : "" }} value="Other">Other</option>
-                                                </select>
-                                            </div>
-                                            <div class="mb-2">
-                                                <textarea class="form-control form-control-sm" name="content" rows="5" placeholder="Content"><?= $memo->content ?></textarea>
-                                            </div>
-                                            <div class="d-flex align-items-center">
-                                                <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
-                                                <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
-                                            </div>
-                                        </form>
-                                    </div>
-                                    <div moe relative>
-                                        <a start show class="on-hover-opaque"><i class="fa fa-trash-alt text-danger"></i></a>
-                                        <form url="/api/clientMemo/cancel" right>
-                                            <input type="hidden" name="uid" value="{{ $memo->uid }}">
-                                            <p class="small">Are you sure you want to cancel this memo?</p>
-                                            <div class="d-flex align-items-center">
-                                                <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
-                                                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
-                                            </div>
-                                        </form>
-                                    </div>
-                                </td>
-                            </tr>
-                            @endif
-                            @endforeach
-                        </tbody>
-                        @else
-                        <tbody>
-                            <tr>
-                                <td class="text-secondary p-3">No memos have been created for this patient</td>
-                            </tr>
-                        </tbody>
-                        @endif
-                    </table>
-                </div>
-            </div>
+            @include('app.patient.partials.client-memos')
         </div>
     </div>
 

+ 1 - 1
resources/views/app/patient/measurements.blade.php

@@ -49,7 +49,7 @@
                     </form>
                 </div>
                 --}}
-{{--                @if($performer->pro->pro_type == 'ADMIN')--}}
+{{--                @if($pro->pro_type == 'ADMIN')--}}
 {{--                <span class="mx-2 text-secondary">|</span>--}}
 {{--                <div moe>--}}
 {{--                    <a start show class="py-0 font-weight-normal">Process Client BDT Measurements Report</a>--}}

+ 1 - 1
resources/views/app/patient/memos.blade.php

@@ -37,7 +37,7 @@
                 </thead>
                 <tbody>
                 @foreach($patient->memos as $memo)
-                    @if(!$memo->is_admin_only || ($memo->is_admin_only && $performer->pro->pro_type === 'ADMIN') )
+                    @if(!$memo->is_admin_only || ($memo->is_admin_only && $pro->pro_type === 'ADMIN') )
                     <tr>
                         <td>{{ $memo->category }}</td>
                         <td><pre class="m-0 break-spaces">{{ $memo->content }}</pre></td>

+ 2 - 2
resources/views/app/patient/note/partials/flag-note-by-supervisor.blade.php

@@ -23,7 +23,7 @@
         </div>        
     @else
         @if($note->is_flagged_for_supervising_physician_review)
-            @if($performer->pro->pro_type === 'ADMIN')
+            @if($pro->pro_type === 'ADMIN')
                 <div class="d-flex align-items-center">
                     <span class="text-danger mr-2"><i class="fas fa-flag text-danger"></i> Flagged for Review</span>
                     <span class="mr-2">by <b>{{ $note->flaggedForSupervisingPhysicianReviewBySession->pro->displayName() }}</b> at {{ friendlier_date($note->flagged_for_supervising_physician_review_at) }}</span>            
@@ -60,7 +60,7 @@
                 </div>
             @endif
         @else
-            @if($performer->pro->pro_type === 'ADMIN')
+            @if($pro->pro_type === 'ADMIN')
             <div moe class="mr-2">
                 <a href="#" start show><i class="fas fa-flag text-danger"></i> Flag Note for Review</a>
                 <form url="/api/note/markAsFlaggedForSupervisingPhysicianReview">

+ 2 - 2
resources/views/app/patient/note/segment/suggestions_and_updates.blade.php

@@ -55,7 +55,7 @@
         <div class="alert alert-info">Your suggestion has been rejected.</div>
         @endif
         <div class="d-flex">
-            @if(($note->hcp_pro_id == $performer->pro_id || $performer->pro->pro_type === 'ADMIN') && $segment->proposedSegmentSummarySuggestion->status == 'PENDING')
+            @if(($note->hcp_pro_id == $performer->pro_id || $pro->pro_type === 'ADMIN') && $segment->proposedSegmentSummarySuggestion->status == 'PENDING')
             <div class="d-block mt-1 mr-2" moe>
                 <form url="/api/segment/acceptProposedSegmentSummarySuggestion" show>
                     <input type="hidden" name="uid" value="{{$segment->uid}}">
@@ -115,7 +115,7 @@
                         {!! 1 ? $segment->getRecalculatedHtml($performer, $performer->session_key, true)['summaryHtml'] : '' !!}
                     @endif 
                 </textarea>
-                @if($performer->pro->pro_type == 'ADMIN')
+                @if($pro->pro_type == 'ADMIN')
                 <div class="checkbox mt-1">
                     <input type="checkbox" name="autoAccept">
                     <label for="" class="checkbox-label">Auto-accept</label>

+ 169 - 0
resources/views/app/patient/partials/client-memos.blade.php

@@ -0,0 +1,169 @@
+<?php
+    $isProTypeAdmin = $pro->pro_type === 'ADMIN';
+?>
+<div class="mb-2 pt-3 pb-2 border-top">
+    <div class="">
+        <div class="d-flex align-items-start pb-2">
+            <h6 class="my-0 font-weight-bold">Client Memos</h6>
+        </div>
+        <div moe class="w-100 p-2 border mb-3">
+            <form url="/api/clientMemo/create" show>
+                <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
+                <label class="text-secondary font-weight-bold">+ New Memo</label>
+                <div class="mb-2">
+                    <select class="form-control form-control-sm" name="category" required>
+                        <option value="">-- select --</option>
+                        <option value="Incoming Call">Incoming Call</option>
+                        <option value="Outgoing Call">Outgoing Call</option>
+                        <option value="Call Unspecified">Call Unspecified</option>
+                        <option value="Other">Other</option>
+                    </select>
+                </div>
+                <div class="mb-2">
+                    <textarea class="form-control form-control-sm" rows="5" name="content" placeholder="Content"></textarea>
+                </div>
+                @if ($isProTypeAdmin)
+                    <div class="mb-2">
+                        <label for="" class="checkbox">
+                            <input type="checkbox" name="isAdminOnly">
+                            Admins only
+                        </label>
+                    </div>
+                @endif
+                <div class="d-flex align-items-center">
+                    <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
+                </div>
+            </form>
+        </div>
+        <table class="table table-striped table-sm table-bordered mb-0">
+            @if ($clientMemos && count($clientMemos))
+                <thead class="bg-light">
+                    <tr class="text-nowrap">
+                        <th class="border-0 text-secondary">Category</th>
+                        <th class="border-0 text-secondary w-50">Summary</th>
+                        <th class="border-0 text-secondary">Created</th>
+                        @if ($isProTypeAdmin)
+                            <th class="border-0 text-secondary">Admins Only</th>
+                        @endif
+                        <th class="border-0 text-secondary">Ack. by MCP</th>
+                        <th class="border-0 text-secondary delete-column">&nbsp;</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    @foreach ($clientMemos as $memo)
+                        <?php $memoCreatedBy = $memo->createdBy->pro; ?>
+                        @if (!$memo->is_admin_only || ($memo->is_admin_only && $isProTypeAdmin))
+                            <tr>
+                                <td class="text-nowrap">{{ $memo->category }}</td>
+                                <td class="px-2">
+                                    <pre class="m-0 break-spaces">{{ $memo->content }}</pre>
+                                </td>
+                                <td class="text-nowrap">
+                                    <strong>{{ $memoCreatedBy->displayName() }}</strong><br />
+                                    {{ friendly_date_time($memo->created_at) }}
+                                </td>
+                                @if ($isProTypeAdmin)
+                                    <td class="text-secondary">
+                                        @if ($memo->is_admin_only)
+                                            <span class="text-success"><i class="fas fa-lock"></i> YES</span>
+                                        @else
+                                            <span><i class="fas fa-unlock"></i> NO</span>
+                                        @endif
+                                    </td>
+                                @endif
+                                <td>
+                                    @if ($memo->mcp_stamp_id)
+                                        <span class="text-success">YES <i class="fas fa-info-circle c-pointer"
+                                                data-toggle="tooltip" data-placement="bottom"
+                                                title="{{ friendly_date_time($memo->stamp->created_at) }}"></i></span>
+                                    @else
+                                        <span class="text-secondary">NO</span>
+                                    @endif
+                                </td>
+                                <td class="text-center delete-column">
+                                    @if ($isProTypeAdmin)
+                                        <div moe relative bottom class="mr-2">
+                                            <a start show><i class="fa fa-history"></i></a>
+                                            <div action="" url right bottom>
+                                                <table class="table table-condensed table-striped table-sm">
+                                                    <thead>
+                                                        <th>Category</th>
+                                                        <th>Summary</th>
+                                                        <th>Created</th>
+
+                                                    </thead>
+                                                    <tbody>
+                                                        @foreach ($memo->updates as $update)
+                                                            <tr>
+                                                                <td>{{ $update->category }}</td>
+                                                                <td>{{ $update->content }}</td>
+                                                                <td><strong>{{ $update->createdBy->proname_first }}
+                                                                        {{ $update->createdBy->pro->name_last }}</strong><br />{{ friendly_date_time($update->created_at) }}
+                                                                </td>
+
+                                                            </tr>
+                                                        @endforeach
+                                                    </tbody>
+                                                </table>
+                                            </div>
+                                        </div>
+                                    @endif
+                                    <div moe wide relative class="mr-2">
+                                        <a class="on-hover-opaque" start show title="Edit">
+                                            <i class="font-size-11 fa fa-edit"></i>
+                                        </a>
+                                        <form url="/api/clientMemo/update" right>
+                                            <input type="hidden" name="uid" value="{{ $memo->uid }}">
+                                            <div class="mb-2">
+                                                <select class="form-control form-control-sm" name="category" required>
+                                                    <option value="">-- select --</option>
+                                                    <option {{ $memo->category === 'Incoming Call' ? 'selected' : '' }}
+                                                        value="Incoming Call">Incoming Call</option>
+                                                    <option {{ $memo->category === 'Outgoing Call' ? 'selected' : '' }}
+                                                        value="Outgoing Call">Outgoing Call</option>
+                                                    <option
+                                                        {{ $memo->category === 'Call Unspecified' ? 'selected' : '' }}
+                                                        value="Call Unspecified">Call Unspecified</option>
+                                                    <option {{ $memo->category === 'Other' ? 'selected' : '' }}
+                                                        value="Other">Other</option>
+                                                </select>
+                                            </div>
+                                            <div class="mb-2">
+                                                <textarea class="form-control form-control-sm" name="content" rows="5" placeholder="Content"><?= $memo->content ?></textarea>
+                                            </div>
+                                            <div class="d-flex align-items-center">
+                                                <button class="btn btn-sm btn-primary mr-2" type="button"
+                                                    submit>Save</button>
+                                                <button class="btn btn-sm btn-default mr-2 border" type="button"
+                                                    cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                    <div moe relative>
+                                        <a start show class="on-hover-opaque"><i
+                                                class="fa fa-trash-alt text-danger"></i></a>
+                                        <form url="/api/clientMemo/cancel" right>
+                                            <input type="hidden" name="uid" value="{{ $memo->uid }}">
+                                            <p class="small">Are you sure you want to cancel this memo?</p>
+                                            <div class="d-flex align-items-center">
+                                                <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
+                                                <button class="btn btn-sm btn-default mr-2 border"
+                                                    cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                </td>
+                            </tr>
+                        @endif
+                    @endforeach
+                </tbody>
+            @else
+                <tbody>
+                    <tr>
+                        <td class="text-secondary p-3">No memos have been created for this patient</td>
+                    </tr>
+                </tbody>
+            @endif
+        </table>
+    </div>
+</div>

+ 2 - 2
resources/views/app/patient/partials/measurements.blade.php

@@ -9,7 +9,7 @@
     </div>
     <table class="table table-sm border-0 m-0">
         <tbody>
-        @foreach($patient->recentMeasurements as $measurement)
+        @foreach($recentMeasurements as $measurement)
             @if(1 || !empty($measurement->label) && !in_array($measurement->label, $vitalLabels))
                 @if(!in_array($measurement->label, ["SBP", "DBP"]))
                     @if(!empty($measurement->client_bdt_measurement_id))
@@ -44,7 +44,7 @@
                 @endif
             @endif
         @endforeach
-        @if(!$patient->measurements || !count($patient->measurements))
+        @if(!$recentMeasurements || !count($recentMeasurements))
             <tr>
                 <td class="text-secondary p-0 border-0 pl-2">
                     No items to show

+ 1 - 1
resources/views/app/patient/partials/quick-actions-buttons.blade.php

@@ -43,7 +43,7 @@
 			</form>
 		</span>
 	</div>
-	@if($performer->pro->pro_type == 'ADMIN')
+	@if($pro->pro_type == 'ADMIN')
 	<div>
 		<a href="#" start class="ml-2 d-block" show onclick="return openInRHS('/pro/check-video/{{ $patient->uid }}')"><i class="fa fa-eye mr-1"></i></a>
 	</div>

+ 3 - 3
resources/views/app/patient/primary-coverage-view.blade.php

@@ -57,7 +57,7 @@
 							<tr v-if="cpc.plan_type == 'COMMERCIAL'">
 								<td>Patient Member Identifier</td>
 								<td>
-									@if($performer->pro->pro_type === 'ADMIN')
+									@if($pro->pro_type === 'ADMIN')
 										{{$cpc->commercial_member_identifier ?? '-'}}
 									@else
 										{{$cpc->commercial_member_identifier ? mask_string($cpc->commercial_member_identifier, '*', 4) : '-'}}
@@ -120,7 +120,7 @@
 							<tr v-if="cpc.plan_type == 'MEDICAID' || (cpc.plan_type == 'COMMERCIAL' && cpc.mcd_number)">
 								<td>Medicaid Number</td>
 								<td class="text-uppercase">
-									@if($performer->pro->pro_type === 'ADMIN')
+									@if($pro->pro_type === 'ADMIN')
 										{{$cpc->mcd_number ?? '-'}}
 									@else
 										{{$cpc->mcd_number ? mask_string($cpc->mcd_number, '*', 4) : '-'}}
@@ -130,7 +130,7 @@
 							<tr v-if="cpc.plan_type == 'MEDICARE' || (cpc.plan_type == 'COMMERCIAL' && cpc.mcr_number)">
 								<td>Medicare Number</td>
 								<td class="text-uppercase">
-									@if($performer->pro->pro_type === 'ADMIN')
+									@if($pro->pro_type === 'ADMIN')
 										{{$cpc->mcr_number ?? '-'}}
 									@else
 										{{$cpc->mcr_number ? mask_string($cpc->mcr_number, '*', 4) : '-'}}

+ 5 - 5
resources/views/app/patient/review-requests/list.blade.php

@@ -3,7 +3,7 @@
 <div class="">
     <div class="d-flex align-items-center pb-2">
         <h4 class="font-weight-bold mb-0 mr-3">Review Requests</h4>
-        @if($performer->pro->pro_type === 'ADMIN')
+        @if($pro->pro_type === 'ADMIN')
             @include('app.patient.review-requests.partials.create')
         @endif
     </div>
@@ -37,7 +37,7 @@
                                 <i class="fas fa-info-circle text-muted" title="{{ $rr->reactivation_memo }}"></i>
                             @endif
                         </span>
-                        @if($performer->pro->pro_type === 'ADMIN')
+                        @if($pro->pro_type === 'ADMIN')
                             @include('app.patient.review-requests.partials.deactivate')
                         @endif
                     @else
@@ -46,7 +46,7 @@
                                 <i class="fas fa-info-circle text-muted" title="{{ $rr->deactivation_memo }}"></i>
                             @endif
                         </span>
-                        @if($performer->pro->pro_type === 'ADMIN')
+                        @if($pro->pro_type === 'ADMIN')
                             @include('app.patient.review-requests.partials.activate')
                         @endif
                     @endif
@@ -57,12 +57,12 @@
                             <i class="fas fa-info-circle text-muted" title="{{ $rr->status_memo }}"></i>
                         @endif
                     </span>
-                    @if($performer->pro->pro_type === 'ADMIN')
+                    @if($pro->pro_type === 'ADMIN')
                         @include('app.patient.review-requests.partials.update-status')
                     @endif
                 </td>
                 <td>
-                    @if($performer->pro->pro_type === 'ADMIN')
+                    @if($pro->pro_type === 'ADMIN')
                         @include('app.patient.review-requests.partials.edit')
                     @endif
                 </td>

+ 2 - 2
resources/views/app/patient/settings.blade.php

@@ -706,7 +706,7 @@ $patientName = implode(', ', array_filter([$patient->name_last, $patient->name_f
                 </div>
                 @endif
 
-                @if($performer->pro->pro_type === 'ADMIN')
+                @if($pro->pro_type === 'ADMIN')
                 <hr class="m-negator-3 my-3">
                 <div>
                     <h3>Admin Engagement Assessment Status</h3>
@@ -840,7 +840,7 @@ $patientName = implode(', ', array_filter([$patient->name_last, $patient->name_f
                 </div>
                 @endif
 
-                @if($performer->pro->pro_type == 'ADMIN')
+                @if($pro->pro_type == 'ADMIN')
                 <hr class="m-negator-3 my-3">
                 <div>
                     <h3>Client Engagement Assessment Status</h3>

+ 2 - 2
resources/views/app/patient/sms.blade.php

@@ -32,7 +32,7 @@
                 <th class="border-0 text-secondary w-25">To</th>
                 <th class="border-0 text-secondary w-50">Content</th>
                 <th></th>
-                @if($performer->pro->pro_type == 'ADMIN')
+                @if($pro->pro_type == 'ADMIN')
                     <th></th>
                 @endif
             </tr>
@@ -65,7 +65,7 @@
                             </div>
                         @endif
                     </td>
-                    @if($performer->pro->pro_type == 'ADMIN')
+                    @if($pro->pro_type == 'ADMIN')
                         <td class="text-nowrap">
                             <div moe relative>
                                 <a start show class="">Update Is Reply Needed</a>

+ 10 - 9
resources/views/layouts/patient-header.blade.php

@@ -1,4 +1,5 @@
 <?php
+$patientMcp = $patient->mcp;
 $thumbnail = $patient->profile_picture_base64;
 $initials = !$thumbnail ? substr($patient->name_first, 0, 1) . substr($patient->name_last, 0, 1) : '';
 $online = $patient->is_online ? 'online' : '';
@@ -12,7 +13,7 @@ $confirmedEmail = empty($patient->email_address) ? '-' : $patient->email_address
 $location = implode(', ', array_filter([$patient->home_address_city, $patient->home_address_state]));
 $location = empty($location) ? '-' : $location;
 
-$mcpName = $patient->mcp ? implode(', ', array_filter([$patient->mcp->name_last, $patient->mcp->name_first])) : null;
+$mcpName = $patientMcp ? implode(', ', array_filter([$patientMcp->name_last, $patientMcp->name_first])) : null;
 $cmName = $patient->cm ? implode(', ', array_filter([$patient->cm->name_last, $patient->cm->name_first])) : null;
 
 $memberSince = date_diff(date_create($patient->created_at), date_create('now'))->days;
@@ -234,7 +235,7 @@ $addressParts .= implode(", ", $addressPart2);
             <div class="position-relative ml-2">
                 <div class="screen-only">
                     <div>
-                        <label class="{{ $patient->mcp && $patient->mcp->is_hcp ? '':'text-danger' }}">MCP:</label> <span class="{{ $patient->mcp && $patient->mcp->is_hcp ? '':'text-danger' }}">{{$mcpName}}</span>
+                        <label class="{{ $patientMcp && $patientMcp->is_hcp ? '':'text-danger' }}">MCP:</label> <span class="{{ $patientMcp && $patientMcp->is_hcp ? '':'text-danger' }}">{{$mcpName}}</span>
                         @if($patient->has_mcp_done_onboarding_visit === 'YES')
                             <i class="fa fa-check text-sm" title="MCP Onboarding Visit Completed"></i>
                         @endif
@@ -243,7 +244,7 @@ $addressParts .= implode(", ", $addressPart2);
                                 <a start show><i class="fa fa-edit on-hover-opaque"></i></a>
                                 @include('app.patient.partials.put-mcp-form')
                             </div>
-                            @if($patient->mcp)
+                            @if($patientMcp)
                                 <div moe class="ml-2 hide-inside-popup">
                                     <a start show><i class="fa fa-times on-hover-opaque"></i></a>
                                     <form url="/api/client/removeMcp" class="mcp-theme-1">
@@ -263,15 +264,15 @@ $addressParts .= implode(", ", $addressPart2);
                                 </div>
                             @endif
                         @endif
-                        @if($patient->mcp && $pro->pro_type === 'ADMIN' && $pro->uid !== $patient->mcp->uid)
-                            <form action="{{route('process-log-in-as')}}?redir={{request()->url()}}" onsubmit="window.top.localStorage.currentProUid = '{{$patient->mcp->uid}}';" method="POST" target="_top" class="d-inline-block">
+                        @if($patientMcp && $pro->pro_type === 'ADMIN' && $pro->uid !== $patientMcp->uid)
+                            <form action="{{route('process-log-in-as')}}?redir={{request()->url()}}" onsubmit="window.top.localStorage.currentProUid = '{{$patientMcp->uid}}';" method="POST" target="_top" class="d-inline-block">
                                 @csrf
-                                <input type="hidden" name="proUid" value="{{$patient->mcp->uid}}">
+                                <input type="hidden" name="proUid" value="{{$patientMcp->uid}}">
                                 <button class="bg-transparent text-primary border-0 text-sm"><i class="fa fa-user on-hover-opaque"></i></button>
                             </form>
                         @endif
-                        @if($patient->mcp && !$patient->mcp->is_hcp)
-                            <small class="text-danger font-weight-bold"><i class="fas fa-exclamation-triangle fa-fw"></i> {{ $patient->mcp->name_first }} is no longer HCP. Reassign.</small>
+                        @if($patientMcp && !$patientMcp->is_hcp)
+                            <small class="text-danger font-weight-bold"><i class="fas fa-exclamation-triangle fa-fw"></i> {{ $patientMcp->name_first }} is no longer HCP. Reassign.</small>
                         @endif
                     </div>
                     <div>
@@ -441,7 +442,7 @@ $addressParts .= implode(", ", $addressPart2);
             </div>
         @endif
         <div class="bg-light p-2 border d-none">
-            @if($patient->mcp && $patient->mcp->id === $pro->id || $pro->pro_type == 'ADMIN')
+            @if($patientMcp && $patientMcp->id === $pro->id || $pro->pro_type == 'ADMIN')
                 <div>
                     <label>Status (mcp):</label>
                     <span>{!! $patient->mcpEngagementAssessmentStatus && $patient->mcpEngagementAssessmentStatus->status_category ? ucwords(strtolower(str_replace('_', ' ', $patient->mcpEngagementAssessmentStatus->status_category))) : '<span class="text-danger">Not

+ 10 - 7
resources/views/layouts/patient.blade.php

@@ -1,12 +1,15 @@
 @extends(request()->input('popupmode') ? 'layouts.empty' : 'layouts.template')
 <?php
-/** @var \App\Models\Client $patient */
+	/** @var \App\Models\Client $patient **/
 ?>
 <?php
 $trimLayout = true;
 $routeName = request()->route()->getName();
 $leanLeftNav = ($routeName === 'patients.view.notes.view.dashboard' && @$note && !!$note->visitTemplate) || ($routeName === 'patients.view.sleep-study');
 $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_create($patient->created_at))->invert === 1);
+
+$patientMcp = $patient->mcp;
+$patientCompanyClients = $patient->companyClients;
 ?>
 <style media="screen">
 	.pt-name {
@@ -33,7 +36,7 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 							<li class="nav-item">
 								<a class="nav-link {{ strpos($routeName, 'patients.view.primary-coverage') === 0 ? 'active' : '' }}" href="{{ route('patients.view.primary-coverage', $patient) }}">Primary Coverage</a>
 							</li>
-							@if($performer->pro->pro_type == 'ADMIN' || $performer->pro->id == $patient->default_na_pro_id)
+							@if($pro->pro_type == 'ADMIN' || $pro->id == $patient->default_na_pro_id)
 							<li class="nav-item">
 								<a class="nav-link {{ strpos($routeName, 'patients.view.insurance-coverage') === 0 ? 'active' : '' }}" href="{{ route('patients.view.insurance-coverage-history', $patient) }}">Insurance Coverage History</a>
 							</li>
@@ -44,8 +47,8 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 						<h6 class="nav-link font-weight-bold m-0">Appointments</h6>
 						<ul class="m-0 p-0 nav-child-list">
 							<li class="nav-item">
-								@if($pro->pro_type === 'ADMIN' && $patient->mcp)
-									<a class="nav-link {{ strpos($routeName, 'patients.view.calendar') === 0 ? 'active' : '' }}" href="{{ route('patients.view.calendar', ['patient' => $patient]) }}?opUid={{$patient->mcp->uid}}">Calendar</a>
+								@if($pro->pro_type === 'ADMIN' && $patientMcp)
+									<a class="nav-link {{ strpos($routeName, 'patients.view.calendar') === 0 ? 'active' : '' }}" href="{{ route('patients.view.calendar', ['patient' => $patient]) }}?opUid={{$patientMcp->uid}}">Calendar</a>
 								@else
 									<a class="nav-link {{ strpos($routeName, 'patients.view.calendar') === 0 ? 'active' : '' }}" href="{{ route('patients.view.calendar', ['patient' => $patient]) }}">Calendar</a>
 								@endif
@@ -247,7 +250,7 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 			@if(!request()->input('popupmode'))
 				@include('app.patient.partials.cpt-alert')
 			@endif
-			@if($pro->is_enrolled_as_mcp && !$patient->mcp)
+			@if($pro->is_enrolled_as_mcp && !$patientMcp)
 			<div class="d-flex align-items-center alert alert-info bg-white mcp-theme-1 p-1 hide-inside-ticket-popup m-1">
 				<div class="font-size-16 mr-3">
 					<i class="fa fa-exclamation-triangle text-warning-mellow"></i>
@@ -345,9 +348,9 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 					</div>
 					<div class="ml-3">
 						<div class="d-flex align-items-center">
-							<b class="mr-2">Partners ({{ count($patient->companyClients)  }}):</b>
+							<b class="mr-2">Partners ({{ count($patientCompanyClients)  }}):</b>
 							<div class="d-flex align-items-center mr-2">
-								@foreach($patient->companyClients as $companyClient)
+								@foreach($patientCompanyClients as $companyClient)
 									<span class="mr-2">
 										{{$companyClient->company->name}}
 										<div moe class="d-inline-block">