Browse Source

Merge branch 'dev' of https://rav.triplestart.com/jmudaka/stagfe2 into dev

Peter Muturi 3 years ago
parent
commit
7ab59a1f96
37 changed files with 1186 additions and 365 deletions
  1. 1 0
      app/Helpers/helpers.php
  2. 10 1
      app/Http/Controllers/AdminController.php
  3. 1 1
      app/Http/Controllers/DnaController.php
  4. 0 1
      app/Http/Controllers/HomeController.php
  5. 1 1
      app/Http/Controllers/McpController.php
  6. 254 42
      app/Http/Controllers/PracticeManagementController.php
  7. 18 18
      app/Http/Controllers/StatTreeLineController.php
  8. 15 0
      app/Models/Client.php
  9. 1 1
      config/app.php
  10. 57 0
      public/css/style.css
  11. BIN
      public/img/node.png
  12. 11 0
      resources/views/app/admin/patients_filters.blade.php
  13. 21 0
      resources/views/app/dashboard-admin.blade.php
  14. 13 1
      resources/views/app/dashboard-mcp.blade.php
  15. 1 1
      resources/views/app/dna/DnaController.php
  16. 5 3
      resources/views/app/generic-bills/inline.blade.php
  17. 1 1
      resources/views/app/mcp/notes.blade.php
  18. 1 1
      resources/views/app/patient/appointment-calendar.blade.php
  19. 38 35
      resources/views/app/patient/care-month/dashboard.blade.php
  20. 1 4
      resources/views/app/patient/notes.blade.php
  21. 5 3
      resources/views/app/patient/segment-templates/covid_intake/edit.blade.php
  22. 4 3
      resources/views/app/patient/segment-templates/covid_intake/summary.blade.php
  23. 39 35
      resources/views/app/patient/settings.blade.php
  24. 9 0
      resources/views/app/practice-management/_sort_header.blade.php
  25. 1 1
      resources/views/app/practice-management/calendar.blade.php
  26. 60 89
      resources/views/app/practice-management/hcp-note-activity.blade.php
  27. 42 7
      resources/views/app/practice-management/pro-availability.blade.php
  28. 89 0
      resources/views/app/practice-management/remote-monitoring-admin-tree.blade.php
  29. 143 0
      resources/views/app/practice-management/remote-monitoring-admin.blade.php
  30. 97 0
      resources/views/app/practice-management/remote-monitoring-tree.blade.php
  31. 135 92
      resources/views/app/practice-management/remote-monitoring.blade.php
  32. 1 1
      resources/views/layouts/confirm-hours-of-availability-notification.blade.php
  33. 5 4
      resources/views/layouts/patient.blade.php
  34. 5 1
      resources/views/layouts/template.blade.php
  35. 6 1
      routes/web.php
  36. 75 0
      spec/sample_rm_stat_tree.txt
  37. 20 17
      spec/stat-tree-report-builder-spec.txt

+ 1 - 0
app/Helpers/helpers.php

@@ -81,6 +81,7 @@ if(!function_exists('queryLineExcept')) {
         $final = [];
         foreach ($params as $k => $v) {
             if(in_array($k, $except) === FALSE) {
+                if(is_array($v)) $v = implode(',', $v);
                 $final[] = "$k=" . urlencode($v);
             }
         }

+ 10 - 1
app/Http/Controllers/AdminController.php

@@ -38,7 +38,7 @@ class AdminController extends Controller
     public function patients(Request $request)
     {
         $filters = $request->all();
-        $patients = Client::whereNull('shadow_pro_id')->where('client_engagement_status_category', '!=', 'NO_LONGER_INTERESTED');
+        $patients = Client::whereNull('shadow_pro_id');
 
         // filters
         /*
@@ -106,6 +106,15 @@ class AdminController extends Controller
             });
         }
 
+        $insurance = $request->get('insurance');
+        if($insurance){
+            if($insurance === 'MEDICARE'){
+                $patients = $patients->where('is_part_b_primary', 'YES');
+            }else{
+                $patients = $patients->where('is_part_b_primary', '!=', 'YES');
+            }
+        }
+
         $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
         return view('app.admin.patients', compact('patients', 'filters'));
     }

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

@@ -39,7 +39,7 @@ 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)->where('client_engagement_status_category', '!=', 'NO_LONGER_INTERESTED');
+        $patients = Client::whereNull('shadow_pro_id')->where('default_na_pro_id', $this->performer->pro->id);
 
         if ($request->input('name')) {
             $name = trim($request->input('name'));

+ 0 - 1
app/Http/Controllers/HomeController.php

@@ -1707,7 +1707,6 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
         }
 
         $clientQuery= Client::whereNull('shadow_pro_id')
-            ->where('client_engagement_status_category', '!=', 'NO_LONGER_INTERESTED')
             ->where(function ($q) use ($term, $phoneNumberTerm) {
                 $q->where('name_first', 'ILIKE', '%' . $term . '%')
                     ->orWhere('name_last', 'ILIKE', '%' . $term . '%')

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

@@ -39,7 +39,7 @@ class McpController extends Controller
     public function patients(Request $request)
     {
         $filters = $request->all();
-        $patients = Client::whereNull('shadow_pro_id')->where('client_engagement_status_category', '!=', 'NO_LONGER_INTERESTED');
+        $patients = Client::whereNull('shadow_pro_id');
         
         //TODO: implement in admin controller 
         if($this->performer->pro->pro_type != 'ADMIN'){

+ 254 - 42
app/Http/Controllers/PracticeManagementController.php

@@ -806,13 +806,13 @@ class PracticeManagementController extends Controller
         $filters = $request->all();
 
         $from_date = $request->get('from_date');
-        if(!$from_date) {
-            $from_date = '2010-01-01';
-        }
+//        if(!$from_date) {
+//            $from_date = '2010-01-01';
+//        }
         $to_date = $request->get('to_date');
-        if(!$to_date){
-            $to_date = '2900-12-31';
-        }
+//        if(!$to_date){
+//            $to_date = '2900-12-31';
+//        }
         
 
         //TODO sanitize inputs
@@ -830,7 +830,9 @@ class PracticeManagementController extends Controller
             (SELECT id FROM note WHERE note.hcp_pro_id = pro.id AND is_cancelled = false ORDER BY created_at DESC LIMIT 1) as last_note_id, 
             (SELECT note.created_at FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false ORDER BY note.created_at DESC LIMIT 1) as last_note_created_at,
             (SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at::DATE >= '${startOfCurrentMonth}'::DATE AND created_at::DATE <= '${endOfCurrentMonth}'::DATE ) AS notes_this_month,
-            (SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at >= '${from_date}'::DATE AND created_at <= '${to_date}'::DATE  ) AS notes_this_period");
+            (SELECT COUNT(*) FROM client WHERE client.mcp_pro_id = pro.id AND client.client_engagement_status_category <> 'DUMMY' AND client.client_engagement_status_category <> 'DUPLICATE') as total_client_count,
+            (SELECT COUNT(*) FROM client WHERE client.mcp_pro_id = pro.id AND client.client_engagement_status_category <> 'DUMMY' AND client.client_engagement_status_category <> 'DUPLICATE' AND client.most_recent_completed_mcp_note_date >= (NOW() - interval '60 days')::DATE) as active_client_count
+            " . (!!$from_date && !!$to_date ? ",(SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at::DATE >= '${from_date}'::DATE AND created_at::DATE <= '${to_date}'::DATE  ) AS notes_this_period" : ""));
 
         $prosIDs = $request->get('pros_ids');
         if($prosIDs){
@@ -838,7 +840,11 @@ class PracticeManagementController extends Controller
             $rows = $rows->whereIn('pro.id', $prosIDs);
         }
 
-        $rows = $rows->orderBy('name_first');
+        $sortBy = $request->input('sort_by') ?: 'name_first';
+        $sortDir = $request->input('sort_dir') ?: 'ASC';
+
+        $rows = $rows->orderByRaw("$sortBy $sortDir NULLS LAST");
+
         $rows = $rows->paginate(50);
 
 
@@ -977,45 +983,29 @@ class PracticeManagementController extends Controller
 
         $performer = $this->performer();
 
+        abort_if($performer->pro->pro_type !== 'ADMIN' && !$performer->pro->can_view_rm_matrix, 403);
+
         $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
         $careMonthStart = date($ym . '-01');
 
-        // filters
-        $filters = '';
-        $fmd = $request->input('fmd');
-        if($fmd && $fmd !== 'all') {
-            switch($fmd) {
-                case 'lt16':
-                    $filters .= ' AND (care_month.number_of_days_with_remote_measurements < 16 OR care_month.number_of_days_with_remote_measurements IS NULL) ';
-                    break;
-                case 'gte16':
-                    $filters .= ' AND (care_month.number_of_days_with_remote_measurements >= 16 AND care_month.number_of_days_with_remote_measurements IS NOT NULL) ';
-                    break;
-            }
-        }
-        $fcomm = $request->input('fcomm');
-        if($fcomm && $fcomm !== 'all') {
-            switch($fcomm) {
-                case 'not-done':
-                    $filters .= ' AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE OR care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL) ';
-                    break;
-                case 'done':
-                    $filters .= ' AND (care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE AND care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NOT NULL) ';
-                    break;
-            }
-        }
-        $c = $request->input('c');
-        if($c) {
-            $filters .= ' AND client.uid = \'' . $request->input('c') . '\' ';
-        }
+        $rc = $request->input('rc') ?: 1;
+        $rc2 = $request->input('rc2') ?: 2;
+
+        $conditions = $this->rpmConditions($performer, $rc, $rc2);
 
         $patients = DB::select(
             DB::raw(
                 "
-SELECT client.name_first, client.name_last, client.uid as client_uid,
+SELECT client.name_first, 
+       client.name_last, 
+       client.uid as client_uid, 
+       client.dob,
+       client.is_enrolled_in_rm,
+       client.most_recent_completed_mcp_note_date,
        care_month.uid as care_month_uid,
        care_month.id as care_month_id,
        care_month.start_date,
+       care_month.rm_total_time_in_seconds_by_mcp,
        care_month.number_of_days_with_remote_measurements,
        care_month.has_anyone_interacted_with_client_about_rm_outside_note,
        care_month.rm_num_measurements_not_stamped_by_mcp,
@@ -1026,13 +1016,19 @@ SELECT client.name_first, client.name_last, client.uid as client_uid,
        client.default_na_pro_id,
        client.rmm_pro_id,
        client.rme_pro_id,
-       client.cell_number
+       client.cell_number,
+       client.most_recent_cellular_bp_dbp_mm_hg,
+       client.most_recent_cellular_bp_sbp_mm_hg,
+       client.most_recent_cellular_bp_measurement_at,      
+       client.most_recent_cellular_weight_value,
+       client.most_recent_cellular_weight_measurement_at
 FROM care_month join client on care_month.client_id = client.id
 WHERE
-      EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
-  AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
-  {$filters}
-ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first ASC, client.name_last ASC
+      client.mcp_pro_id = {$performer->pro->id}
+      AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
+      AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
+      " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
+ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first, client.name_last
 "
             )
         );
@@ -1043,6 +1039,222 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
         return view('app.practice-management.remote-monitoring', compact('patients', 'daysRemaining', 'careMonthStart'));
     }
 
+    public function remoteMonitoringCount(Request $request) {
+
+        $performer = $this->performer();
+
+        $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
+        $careMonthStart = date($ym . '-01');
+
+        $rc = $request->input('rc') ?: 1;
+        $rc2 = $request->input('rc2') ?: 2;
+
+        $conditions = $this->rpmConditions($performer, $rc, $rc2);
+
+        $count = DB::select(
+            DB::raw(
+                "
+SELECT count(*)
+FROM care_month join client on care_month.client_id = client.id
+WHERE
+      client.mcp_pro_id = {$performer->pro->id}
+      AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
+      AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
+      " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '')
+            )
+        );
+
+        return $count[0]->count;
+    }
+
+    public function remoteMonitoringAdmin(Request $request) {
+
+        $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
+        $careMonthStart = date($ym . '-01');
+
+        $rc = $request->input('rc') ?: 1;
+        $rc2 = $request->input('rc2') ?: 2;
+
+        $conditions = $this->rpmConditionsAdmin($this->performer(), $rc, $rc2);
+
+        $patients = DB::select(
+            DB::raw(
+                "
+SELECT client.name_first, 
+       client.name_last, 
+       client.uid as client_uid, 
+       client.dob,
+       client.is_enrolled_in_rm,
+       client.most_recent_completed_mcp_note_date,
+       care_month.uid as care_month_uid,
+       care_month.id as care_month_id,
+       care_month.start_date,
+       care_month.rm_total_time_in_seconds_by_mcp,
+       care_month.number_of_days_with_remote_measurements,
+       care_month.has_anyone_interacted_with_client_about_rm_outside_note,
+       care_month.rm_num_measurements_not_stamped_by_mcp,
+       care_month.rm_num_measurements_not_stamped_by_non_hcp,
+       care_month.rm_num_measurements_not_stamped_by_rmm,
+       care_month.rm_num_measurements_not_stamped_by_rme,
+       client.mcp_pro_id,
+       client.default_na_pro_id,
+       client.rmm_pro_id,
+       client.rme_pro_id,
+       client.cell_number,
+       client.most_recent_cellular_bp_dbp_mm_hg,
+       client.most_recent_cellular_bp_sbp_mm_hg,
+       client.most_recent_cellular_bp_measurement_at,      
+       client.most_recent_cellular_weight_value,
+       client.most_recent_cellular_weight_measurement_at
+FROM care_month join client on care_month.client_id = client.id
+WHERE
+      client.shadow_pro_id is null AND client.is_enrolled_in_rm = 'YES'
+      AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
+      AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
+      " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
+ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, client.name_first, client.name_last
+"
+            )
+        );
+
+        $timestamp = strtotime(date('Y-m-d'));
+        $daysRemaining = (int)date('t', $timestamp) - (int)date('j', $timestamp);
+
+        return view('app.practice-management.remote-monitoring-admin', compact('patients', 'daysRemaining', 'careMonthStart'));
+    }
+
+    public function remoteMonitoringAdminCount(Request $request) {
+
+        $ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
+        $careMonthStart = date($ym . '-01');
+
+        $rc = $request->input('rc') ?: 1;
+        $rc2 = $request->input('rc2') ?: 2;
+
+        $conditions = $this->rpmConditionsAdmin($this->performer(), $rc, $rc2);
+
+        $count = DB::select(
+            DB::raw(
+                "
+SELECT count(*)
+FROM care_month join client on care_month.client_id = client.id
+WHERE
+      client.shadow_pro_id is null AND client.is_enrolled_in_rm = 'YES'
+      AND EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
+      AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
+      " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '')
+            )
+        );
+
+        return $count[0]->count;
+    }
+
+    private function rpmConditions($performer, $rc, $rc2) {
+        $conditions = [];
+
+        $c_isMCP = "client.mcp_pro_id = {$performer->pro->id}";
+        $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
+        $c_hasDevice = "(SELECT COUNT(client_bdt_device.id) FROM client_bdt_device JOIN bdt_device bd on client_bdt_device.device_id = bd.id WHERE client_bdt_device.client_id = client.id) > 0";
+        $c_lastVisitBefore90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) > 90";
+        $c_lastVisitWithin90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) <= 90";
+        $c_notSpokenToThisMonth = "(care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL OR care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE)";
+        $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
+        $c_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
+        $c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
+        $c_lt16MeasurementDays = "care_month.number_of_days_with_remote_measurements < 16";
+        $c_gte16MeasurementDays = "care_month.number_of_days_with_remote_measurements >= 16";
+        $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
+        $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)";
+        $c_lt20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp < 1200";
+        $c_gte20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp >= 1200";
+
+        switch ($rc) {
+            case 1:
+                $conditions = [$c_isMCP];
+                break;
+            case 2:
+                $conditions = [$c_isMCP, $c_enrolledInRPM];
+                break;
+            case 3:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice];
+                break;
+            case 4:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
+                break;
+            case 5:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
+                break;
+            case 6:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
+                break;
+            case 7:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
+                break;
+            case 10:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, $c_gte16MeasurementDays, ($rc2 == 1 ? $c_lt20BillingMinutes : $c_gte20BillingMinutes)];
+                break;
+            case 8:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
+                break;
+            case 9:
+                $conditions = [$c_isMCP, $c_enrolledInRPM, $c_deviceUsed];
+                break;
+        }
+
+        return $conditions;
+    }
+
+    private function rpmConditionsAdmin($performer, $rc, $rc2) {
+        $conditions = [];
+
+        $c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
+        $c_hasDevice = "(SELECT COUNT(client_bdt_device.id) FROM client_bdt_device JOIN bdt_device bd on client_bdt_device.device_id = bd.id WHERE client_bdt_device.client_id = client.id) > 0";
+        $c_lastVisitBefore90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) > 90";
+        $c_lastVisitWithin90Days = "DATE_PART('day', care_month.start_date::timestamp - client.most_recent_completed_mcp_note_date::timestamp) <= 90";
+        $c_notSpokenToThisMonth = "(care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL OR care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE)";
+        $c_spokenToThisMonth = "care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE";
+        $c_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
+        $c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
+        $c_lt16MeasurementDays = "care_month.number_of_days_with_remote_measurements < 16";
+        $c_gte16MeasurementDays = "care_month.number_of_days_with_remote_measurements >= 16";
+        $c_subscribedToSMS = "client.send_sms_on_bdt_measurement = TRUE";
+        $c_deviceUsed = "(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)";
+        $c_lt20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp < 1200";
+        $c_gte20BillingMinutes = "care_month.rm_total_time_in_seconds_by_mcp >= 1200";
+
+        switch ($rc) {
+            case 2:
+                $conditions = [$c_enrolledInRPM];
+                break;
+            case 3:
+                $conditions = [$c_enrolledInRPM, $c_hasDevice];
+                break;
+            case 4:
+                $conditions = [$c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
+                break;
+            case 5:
+                $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
+                break;
+            case 6:
+                $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
+                break;
+            case 7:
+                $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
+                break;
+            case 10:
+                $conditions = [$c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, $c_gte16MeasurementDays, ($rc2 == 1 ? $c_lt20BillingMinutes : $c_gte20BillingMinutes)];
+                break;
+            case 8:
+                $conditions = [$c_enrolledInRPM, $c_subscribedToSMS];
+                break;
+            case 9:
+                $conditions = [$c_enrolledInRPM, $c_deviceUsed];
+                break;
+        }
+
+        return $conditions;
+    }
+
     public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
 
         $performer = $this->performer();

+ 18 - 18
app/Http/Controllers/StatTreeLineController.php

@@ -8,6 +8,7 @@ use App\Models\StatTree;
 use App\Models\StatTreeLine;
 use App\Models\Client;
 use App\Models\Pro;
+use Illuminate\Support\Facades\DB;
 
 class StatTreeLineController extends Controller
 {
@@ -43,7 +44,7 @@ class StatTreeLineController extends Controller
         foreach ($lines as $line) {
             $query = $this->applyStatTreeLineQueryClauses($line);
             if ($query) {
-                $line->last_refresh_count = $query->count();
+                $line->last_refresh_count = $query[0]->count;
                 $line->save();
             }
         }
@@ -58,10 +59,9 @@ class StatTreeLineController extends Controller
 
         $statTreeLine = StatTreeLine::where('id', $statTreeLineID)->first();
         if (!$statTreeLine) return $this->fail('Invalid stat tree line!');
-
-        $query = $this->applyStatTreeLineQueryClauses($statTreeLine);        
+        $query = $this->applyStatTreeLineQueryClauses($statTreeLine);  
         if ($query) {
-            $statTreeLine->last_refresh_count = $query->count();
+            $statTreeLine->last_refresh_count = $query[0]->count;
             $statTreeLine->save();
             return $this->pass($statTreeLine->last_refresh_count);
         }else{
@@ -73,14 +73,17 @@ class StatTreeLineController extends Controller
     {
 
         $model = $statTreeLine->statTree->model;
-        $query = null;
-        if (strcasecmp($model, 'client') == 0) {
-            $query = Client::query();
-        }
-        if (strcasecmp($model, 'pro') == 0) {
-            $query = Pro::query();
-        }
-        if (!$query) return null;
+        // $query = null;
+        // if (strcasecmp($model, 'client') == 0) {
+        //     $query = Client::query();
+        // }
+        // if (strcasecmp($model, 'pro') == 0) {
+        //     $query = Pro::query();
+        // }
+        // if (!$query) return null;
+
+
+
 
         $clauses = [];
         foreach ($statTreeLine->lineClauses as $lineClause) {
@@ -91,12 +94,9 @@ class StatTreeLineController extends Controller
             }
         }
 
-        foreach ($clauses as $clause) {
-            $clauseQuery = $clause;
-            $query = $query->whereRaw($clauseQuery);
-        }
-
-        return $query;
+        $query = 'SELECT COUNT(*) FROM '.$model.' WHERE '. implode(" AND ", $clauses);
+        
+        return DB::select($query);
     }
 
     protected function cleanupClause($clauseText)

+ 15 - 0
app/Models/Client.php

@@ -868,4 +868,19 @@ ORDER BY m.ts DESC
     public function mostRecentWeightMeasurement(){        
         return $this->hasOne(Measurement::class, 'id', 'most_recent_weight_measurement_id');
     }
+
+    public function hasBPDevice() {
+        $cbds = ClientBDTDevice::where('client_id', $this->id)->get();
+        foreach ($cbds as $cbd) {
+            if($cbd->is_active && !!$cbd->device && $cbd->device->is_active && $cbd->device->category === 'BP') return true;
+        }
+        return false;
+    }
+    public function hasWeightScaleDevice() {
+        $cbds = ClientBDTDevice::where('client_id', $this->id)->get();
+        foreach ($cbds as $cbd) {
+            if($cbd->is_active && !!$cbd->device && $cbd->device->is_active && $cbd->device->category === 'WEIGHT') return true;
+        }
+        return false;
+    }
 }

+ 1 - 1
config/app.php

@@ -65,7 +65,7 @@ return [
 
     'hrm2_url' => env('HRM2_URL'),
 
-    'asset_version' => 38,
+    'asset_version' => 39,
 
     'temp_dir' => env('TEMP_DIR'),
 

+ 57 - 0
public/css/style.css

@@ -2629,3 +2629,60 @@ body.stag-scrollbar-scrolling .stag-scrollbar[stag-h-scrollbar] .stag-scrollbar-
     border: 0;
     padding: 0;
 }
+.conditions-tree {
+    /*padding: 0.5rem;*/
+}
+.conditions-tree .condition>a {
+    display: block;
+    padding: 3px 5px;
+}
+.conditions-tree .condition-children {
+    padding-left: 22px;
+    margin-left: -4px;
+    margin-top: -10px;
+    padding-top: 10px;
+}
+
+/* tree lines CSS */
+.conditions-tree {
+    margin-left: 10px;
+}
+.conditions-tree .condition {
+    position: relative;
+}
+.conditions-tree .condition>a {
+    position: relative;
+    display: block;
+    padding-left: 9px;
+    white-space: nowrap;
+    text-overflow: ellipsis;
+}
+.conditions-tree .condition>a:before {
+    position: absolute;
+    content: '';
+    left: -7px;
+    background: url(/img/node.png);
+    width: 8px;
+    height: 7px;
+    background-size: 100% 100%;
+    top: calc(50% - 4px);
+}
+.conditions-tree .condition-children .condition>a:after {
+    position: absolute;
+    content: '';
+    left: -92px;
+    border-top: 1px solid #aaa;
+    width: 90px;
+    top: calc(50% - 1px);
+}
+.conditions-tree .condition-children .condition>a>.rm-count:after {
+    position: absolute;
+    content: '';
+    left: -22px;
+    border-left: 1px solid #aaa;
+    height: 200px;
+    bottom: 50%;
+}
+.conditions-tree .condition-children {
+    overflow: hidden;
+}

BIN
public/img/node.png


+ 11 - 0
resources/views/app/admin/patients_filters.blade.php

@@ -150,6 +150,16 @@
 			<input type="text" name="initiative" class="form-control input-sm" v-model="filters.initiative">
 		</div>
 	</div>
+	<div class="sm-section">
+		<div class="">
+			<label>Insurance:</label>
+			<select class="form-control"  name="insurance" v-model="filters.insurance">
+				<option value=""></option>
+				<option value="MEDICARE">Medicare (Part B)</option>
+				<option value="OTHER">Other</option>
+			</select>
+		</div>
+	</div>
 	@endif
 
 	@if($performer->pro->pro_type == 'ADMIN')
@@ -245,6 +255,7 @@ $allFilterKeys = [
 	'sex',
 	'status',
 	'initiative',
+	'insurance',
 	'include_test_records',
 ];
 for ($i=0; $i < count($allFilterKeys); $i++) {

+ 21 - 0
resources/views/app/dashboard-admin.blade.php

@@ -195,6 +195,13 @@
                                 Appointments
                             </a>
                         </li>
+                        <li class="nav-item">
+                            <a native data-tab="rpm" class="nav-link"
+                               :class="tab == 'rpm' ? 'active' : ''" href="#"
+                               v-on:click.prevent="tab='rpm';">
+                                RPM
+                            </a>
+                        </li>
                         <li class="nav-item">
                             <a native data-tab="measurements" class="nav-link"
                                :class="tab == 'measurements' ? 'active' : ''" href="#"
@@ -333,6 +340,20 @@
                                 Please select a date from the calendar on the left
                             </div>
                         </div>
+                        <div v-show="tab==='rpm'">
+                            <div id="rpm-tab">
+                                <div class="card mb-4">
+                                    <div class="card-header pl-2">
+                                        <strong>
+                                            Remote Monitoring: {{friendly_month(date('Y-m-d'))}}
+                                        </strong>
+                                    </div>
+                                    <div class="card-body p-1">
+                                        @include('app.practice-management.remote-monitoring-admin-tree')
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
                         <div v-show="tab==='measurements'">
                             <div id="measurements-tab">Loading...</div>
                         </div>

+ 13 - 1
resources/views/app/dashboard-mcp.blade.php

@@ -202,7 +202,7 @@
                             </table>
                         </div>
                     </div>
-                    <div class="card mb-4" stag-collapsible-card="mcp-rm">
+                    <div class="card mb-4 d-none" stag-collapsible-card="mcp-rm">
                         <div class="card-header pl-2">
                             <strong>
                                 Remote Monitoring: {{friendly_month(date('Y-m-d'))}}
@@ -302,6 +302,18 @@
                             <div id="mcp-dashboard-appointments" class="mb-4">
 
                             </div>
+                            @if($performer->pro->can_view_rm_matrix || $performer->pro->pro_type=='ADMIN')
+                            <div class="card mb-4">
+                                <div class="card-header pl-2">
+                                    <strong>
+                                        Remote Monitoring: {{friendly_month(date('Y-m-d'))}}
+                                    </strong>
+                                </div>
+                                <div class="card-body p-1">
+                                    @include('app.practice-management.remote-monitoring-tree')
+                                </div>
+                            </div>
+                            @endif
                             <div class="card mb-4">
                                 <div class="card-header pl-2">
                                     <strong>

+ 1 - 1
resources/views/app/dna/DnaController.php

@@ -36,7 +36,7 @@ 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)->where('client_engagement_status_category', '!=', 'NO_LONGER_INTERESTED');
+        $patients = Client::whereNull('shadow_pro_id')->where('default_na_pro_id', $this->performer->pro->id);
 
         if ($request->input('name')) {
             $name = trim($request->input('name'));

+ 5 - 3
resources/views/app/generic-bills/inline.blade.php

@@ -17,14 +17,16 @@ $genericBills = genericBills($pro, @$patient, @$entityType, @$entityUid);
 @if(!count($genericBills))
     <div class="{{@$class ? $class : ''}} d-flex align-items-center">
         <p class="font-weight-bold mb-0">No {{@$label ? $label : 'Admin.'}} Bills</p>
-        <span class="mx-2 text-secondary">|</span>
-        @include('app.generic-bills.create_generic-bill')
+        @if($pro->is_arbitrary_generic_bill_enabled)
+            <span class="mx-2 text-secondary">|</span>
+            @include('app.generic-bills.create_generic-bill')
+        @endif
     </div>
 @else
     <div class="{{@$class ? $class : ''}}">
         <div class="d-flex align-items-center mb-2">
             <p class="font-weight-bold m-0">{{@$label ? $label : 'Admin.'}} Bills</p>
-            @if(!@$noCreate)
+            @if(!@$noCreate && $pro->is_arbitrary_generic_bill_enabled)
                 <span class="mx-2 text-secondary">|</span>
                 @include('app.generic-bills.create_generic-bill')
             @endif

+ 1 - 1
resources/views/app/mcp/notes.blade.php

@@ -60,7 +60,7 @@
                                 <i class="fa fa-info-circle"></i>
                                 <div class="position-absolute bg-white border rounded p-2 stag-tooltip-content">
                                     <div class="text-nowrap small text-left pb-1">Created on <b>{{ friendly_date_time($note->created_at, true) }}</b></div>
-                                    <div class="text-nowrap small text-left">Created by <b>{{ $note->createdSession->pro->displayName() }}</b></div>
+                                    <div class="text-nowrap small text-left">Created by <b>{{ $note->createdSession && $note->createdSession->pro ? $note->createdSession->pro->displayName() : '-'}}</b></div>
                                 </div>
                             </div>
                         </td>

+ 1 - 1
resources/views/app/patient/appointment-calendar.blade.php

@@ -767,7 +767,7 @@
                                         }
                                     },
 
-                                    closeOnSelect: false,
+                                    closeOnSelect: true,
 
                                     // dropdown options
                                     templateResult: function(_state) {

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

@@ -569,6 +569,7 @@
                                     @endif
                                 </div>
 
+                                @if($careMonth->mcp && $pro->id === $careMonth->mcp->id)
                                 <div class="mt-2">
                                     <?php
                                     $minsBilled = 0;
@@ -593,6 +594,7 @@
                                         @endif
                                         <span class="ml-1 text-secondary text-sm font-weight-normal">(20 needed)</span>
                                     </b>
+                                    @if($careMonth->number_of_days_with_remote_measurements >= 16)
                                     <div moe relative class="ml-2">
                                         <a href="#" start show class="text-sm">+ Entry</a>
                                         <form url="/api/careMonthEntry/createForRm" right>
@@ -621,7 +623,9 @@
                                             </div>
                                         </form>
                                     </div>
+                                    @endif
                                 </div>
+                                @endif
 
                                 @if(($daysDiff !== -1 && $daysDiff <= 90) &&
                                     $careMonth->number_of_days_with_remote_measurements >= 16 &&
@@ -2474,12 +2478,13 @@
             @endif
 
         @endif
+        @if($pro->pro_type === 'ADMIN')
         <hr class="m-negator mt-4 mb-3">
-            <div>
-                Is RM interaction waived: {{$careMonth->is_rm_interaction_waived? 'Yes': 'No'}}
-                <div moe class="text-left mt-1" title="Cancel Claim">
-                    <a class="" href="" show start>Set Is RM Interaction Waived To False</a>
-                    @if($careMonth->is_rm_interaction_waived)
+        <div>
+            Is RM interaction waived: <b>{{$careMonth->is_rm_interaction_waived? 'Yes': 'No'}}</b>
+            <div moe class="text-left ml-2 mb-2">
+                <a class="" href="" show start>Toggle</a>
+                @if($careMonth->is_rm_interaction_waived)
                     <form url="/api/careMonth/setIsRmInteractionWaivedToFalse">
                         <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                         <p>Set is RM interaction waived to false?</p>
@@ -2488,24 +2493,23 @@
                             <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                         </div>
                     </form>
-                    @else
-                        <form url="/api/careMonth/setIsRmInteractionWaivedToTrue">
-                            <input type="hidden" name="uid" value="{{$careMonth->uid}}">
-                            <p>Set is RM interaction waived to true?</p>
-                            <div class="mb-0">
-                                <button class="btn btn-primary btn-sm" submit>Submit</button>
-                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
-                            </div>
-                        </form>
-                    @endif
-                </div>
+                @else
+                    <form url="/api/careMonth/setIsRmInteractionWaivedToTrue">
+                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
+                        <p>Set is RM interaction waived to true?</p>
+                        <div class="mb-0">
+                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                        </div>
+                    </form>
+                @endif
             </div>
-
-            <div>
-                Is RM interaction waived: {{$careMonth->is_rm_time_waived? 'Yes': 'No'}}
-                <div moe class="text-left mt-1" title="Cancel Claim">
-                    <a class="" href="" show start>Set Is RM Time Waived To False</a>
-                    @if($careMonth->is_rm_time_waived)
+        </div>
+        <div>
+            Is RM time waived: <b>{{$careMonth->is_rm_time_waived? 'Yes': 'No'}}</b>
+            <div moe class="text-left ml-2">
+                <a class="" href="" show start>Toggle</a>
+                @if($careMonth->is_rm_time_waived)
                     <form url="/api/careMonth/setIsRmTimeWaivedToFalse">
                         <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                         <p>Set is RM Time waived to false?</p>
@@ -2514,18 +2518,19 @@
                             <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                         </div>
                     </form>
-                    @else
-                        <form url="/api/careMonth/setIsRmTimeWaivedToTrue">
-                            <input type="hidden" name="uid" value="{{$careMonth->uid}}">
-                            <p>Set is RM time waived to true?</p>
-                            <div class="mb-0">
-                                <button class="btn btn-primary btn-sm" submit>Submit</button>
-                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
-                            </div>
-                        </form>
-                    @endif
-                </div>
+                @else
+                    <form url="/api/careMonth/setIsRmTimeWaivedToTrue">
+                        <input type="hidden" name="uid" value="{{$careMonth->uid}}">
+                        <p>Set is RM time waived to true?</p>
+                        <div class="mb-0">
+                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                        </div>
+                    </form>
+                @endif
             </div>
+        </div>
+        @endif
 
         <hr class="m-negator my-3">
 
@@ -2582,7 +2587,6 @@
                 });
 
                 // init calendar view
-                @if(count($plottableMeasurements))
                 $('#caremonth-measurements-calendar-{{$calendarID}}').closest('.d-none').removeClass('d-none');
                 let measurementsCalendar = new FullCalendar.Calendar($('#caremonth-measurements-calendar-{{$calendarID}}')[0], {
                     allDaySlot: false,
@@ -2616,7 +2620,6 @@
 
                 window.setTimeout(() => { measurementsCalendar.render();}, 10);
 
-                @endif
             }
 
             addMCInitializer('care-month-dashboard-{{$patient->uid}}', init, '#care-month-container-{{$patient->uid}}');

+ 1 - 4
resources/views/app/patient/notes.blade.php

@@ -220,10 +220,7 @@
                 <td class="max-width-200px">
                     @if(count($note->reasons))
                         @foreach ($note->reasons as $reason)
-                            <div class="mb-1">
-                                <span>{{ $reason->code }}</span>
-                                <span class="text-secondary text-sm">{{ $reason->description}}</span>
-                            </div>
+                            <span class="d-inline-block mr-2" title="{{ $reason->description}}">{{ $reason->code }}</span>
                         @endforeach
                     @else
                         -

+ 5 - 3
resources/views/app/patient/segment-templates/covid_intake/edit.blade.php

@@ -3,9 +3,9 @@
 use App\Models\Point;
 
 $category = 'COVID_INTAKE';
-$endPoint = 'upsertNoteSingleton';
+$endPoint = 'upsertGlobalSingleton';
 
-$point = Point::where('added_in_segment_id', $segment->id)->where('category', $category)->orderBy('id', 'DESC')->first();
+$point = Point::getGlobalSingletonOfCategory($patient, 'COVID_INTAKE', true);
 $contentData = [
     "ans_how_are_you" => '',
     "ans_is_address_correct" => null, // yes/no
@@ -127,9 +127,11 @@ $contentData = [
     "ans_edu_provided_cdc_guidelines" => null, // checkbox
 
 ];
+
 if (!!@$point->data) {
-    $contentData = json_decode($point->data, true);
+    $contentData = $point->data;
 }
+
 ?>
 <div visit-moe close-on-save close-on-cancel class="d-block p-3">
     <form show url="/api/visitPoint/<?= $endPoint ?>" class="mcp-theme-1">

+ 4 - 3
resources/views/app/patient/segment-templates/covid_intake/summary.blade.php

@@ -3,9 +3,10 @@
 use App\Models\Point;
 
 $category = 'COVID_INTAKE';
-$endPoint = 'upsertNoteSingleton';
+$endPoint = 'upsertGlobalSingleton';
+
+$point = Point::getGlobalSingletonOfCategory($patient, 'COVID_INTAKE', true);
 
-$point = Point::where('added_in_segment_id', $segment->id)->where('category', $category)->orderBy('id', 'DESC')->first();
 $contentData = [
     "ans_how_are_you" => '',
     "ans_is_address_correct" => null, // yes/no
@@ -114,7 +115,7 @@ $contentData = [
 
 ];
 if (!!@$point->data) {
-    $contentData = json_decode($point->data, true);
+    $contentData = $point->data;
 }
 ?>
 <div class="events-none form-read-mode">

+ 39 - 35
resources/views/app/patient/settings.blade.php

@@ -1382,44 +1382,49 @@
                         @endif
                     @endif
 
+                
+                @endif
+
                 <hr class="m-negator-3 mt-3">
                 <div>
                     <div class="d-flex mb-2 align-items-center">
                         <b class="d-block">MCN Query Response</b>
-                        <span class="text-secondary mx-2">|</span>
-                        @if(!$patient->is_coverage_manually_verified)
-                            <div moe wide>
-                                <a start show><i class="fa fa-edit"></i> <b>Set Part B to Manually Verified</b></a>
-                                <form url="/api/client/markCoverageAsManuallyVerified" class="mcp-theme-1">
-                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
-                                    <div class="mb-2">
-                                        <label class="mb-1 text-secondary text-sm">Manual Verification Memo</label>
-                                        <textarea rows="4" type="text" class="form-control form-control-sm" name="memo"
-                                              placeholder="Memo">{{ $patient->coverage_manual_verification_memo }}</textarea>
-                                    </div>
-                                    <div>
-                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
-                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
-                                    </div>
-                                </form>
-                            </div>
-                        @else
-                            <span class="text-info font-weight-bold"><i class="fa fa-check"></i>&nbsp;Part B Manually Verified</span>
-                            <div moe wide class="ml-3">
-                                <a start show><i class="fa fa-edit"></i> Undo</a>
-                                <form url="/api/client/undoMarkCoverageAsManuallyVerified" class="mcp-theme-1">
-                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
-                                    <div class="mb-2">
-                                        <label class="mb-1 text-secondary text-sm">Undo Manual Verification Memo</label>
-                                        <textarea rows="4" type="text" class="form-control form-control-sm" name="memo"
-                                                  placeholder="Memo">{{ $patient->coverage_manual_verification_memo }}</textarea>
-                                    </div>
-                                    <div>
-                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
-                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
-                                    </div>
-                                </form>
-                            </div>
+                        @if($pro->pro_type == 'ADMIN')
+                            <span class="text-secondary mx-2">|</span>
+                            @if(!$patient->is_coverage_manually_verified)
+                                <div moe wide>
+                                    <a start show><i class="fa fa-edit"></i> <b>Set Part B to Manually Verified</b></a>
+                                    <form url="/api/client/markCoverageAsManuallyVerified" class="mcp-theme-1">
+                                        <input type="hidden" name="uid" value="{{$patient->uid}}">
+                                        <div class="mb-2">
+                                            <label class="mb-1 text-secondary text-sm">Manual Verification Memo</label>
+                                            <textarea rows="4" type="text" class="form-control form-control-sm" name="memo"
+                                                placeholder="Memo">{{ $patient->coverage_manual_verification_memo }}</textarea>
+                                        </div>
+                                        <div>
+                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @else
+                                <span class="text-info font-weight-bold"><i class="fa fa-check"></i>&nbsp;Part B Manually Verified</span>
+                                <div moe wide class="ml-3">
+                                    <a start show><i class="fa fa-edit"></i> Undo</a>
+                                    <form url="/api/client/undoMarkCoverageAsManuallyVerified" class="mcp-theme-1">
+                                        <input type="hidden" name="uid" value="{{$patient->uid}}">
+                                        <div class="mb-2">
+                                            <label class="mb-1 text-secondary text-sm">Undo Manual Verification Memo</label>
+                                            <textarea rows="4" type="text" class="form-control form-control-sm" name="memo"
+                                                    placeholder="Memo">{{ $patient->coverage_manual_verification_memo }}</textarea>
+                                        </div>
+                                        <div>
+                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
                         @endif
                     </div>
                     <div class="bg-light border p-2">
@@ -1461,7 +1466,6 @@
                     {!! implode("", $output) !!}
                     </div>
                 </div>
-                @endif
 
             </div>
         </div>

+ 9 - 0
resources/views/app/practice-management/_sort_header.blade.php

@@ -0,0 +1,9 @@
+<b class="{{request()->input('sort_by') === $key ? 'text-primary' : 'text-secondary'}}">{{$label}}</b>
+<span class="ml-2 d-inline-flex align-items-baseline">
+    <a href="{{ route("practice-management.hcp-note-activity") }}?{{queryLineExcept(['sort_by', 'sort_dir'])}}&sort_by={{$key}}&sort_dir=DESC" class="ml-1">
+        <i class="fa fa-arrow-up {{request()->input('sort_by') === $key && request()->input('sort_dir') === 'DESC' ? '' : 'on-hover-opaque text-secondary'}}"></i>
+    </a>
+    <a href="{{ route("practice-management.hcp-note-activity") }}?{{queryLineExcept(['sort_by', 'sort_dir'])}}&sort_by={{$key}}&sort_dir=ASC" class="ml-1">
+        <i class="fa fa-arrow-down {{request()->input('sort_by') === $key && request()->input('sort_dir') === 'ASC' ? '' : 'on-hover-opaque text-secondary'}}"></i>
+    </a>
+</span>

+ 1 - 1
resources/views/app/practice-management/calendar.blade.php

@@ -425,7 +425,7 @@
                                     },
                                     minimumInputLength: 3,
 
-                                    closeOnSelect: false,
+                                    closeOnSelect: true,
 
                                     // dropdown options
                                     templateResult: function(_state) {

+ 60 - 89
resources/views/app/practice-management/hcp-note-activity.blade.php

@@ -34,20 +34,20 @@
 <div id="hcp-note-activity" class="p-3 mcp-theme-1">
     <div class="card">
 
-        <div class="card-header px-2 py-1 d-flex align-items-center">
+        <div class="card-header p-2 d-flex align-items-center">
             <strong class="mr-4">
                 <i class="fas fa-user"></i>
                 HCP Note Activity
             </strong>
         </div>
         <div class="card-body p-0 border-0 table-responsive">
-            <div class="m-2">
+            <div class="p-3">
             
-            <form id="hcp-note-activity-filters" method="GET" action="{{ route('practice-management.hcp-note-activity') }}" class="filter-container" v-cloak>                
+            <form id="hcp-note-activity-filters" method="GET" action="{{ route('practice-management.hcp-note-activity') }}" class="filter-container">
                 <div class="sm-section" style="width: 250px !important;">
-                    <div class="form-group">
-                        <label>Pros:</label>
-                        <select id="searchForProInput" multiple name="pros_ids[]" class="form-control input-sm" v-model="filters.pros_ids">
+                    <div class="">
+                        <label class="mb-1 text-secondary">Pros:</label>
+                        <select id="searchForProInput" multiple name="pros_ids[]" class="form-control input-sm">
                             @if(@$filters['pros_ids'])
                                 @foreach($rows as $p)
                                     <option value="{{ $p->id }}" selected>{{$p->name_first}} {{$p->name_last}}</option>
@@ -58,25 +58,25 @@
                 </div>
                
                 <div class="sm-section">
-                    <div class="form-group">
-                        <label>From Date:</label>
-                        <input type="date" name="from_date" class="form-control input-sm" v-model="filters.from_date">
+                    <div class="">
+                        <label class="mb-1 text-secondary">From Date:</label>
+                        <input type="date" name="from_date" class="form-control input-sm" value="{{request()->input('from_date')}}">
                     </div>
                 </div>
 
                 <div class="sm-section">
-                    <div class="form-group">
-                        <label>To Date:</label>
-                        <input type="date" name="to_date" class="form-control input-sm" v-model="filters.to_date">
+                    <div class="">
+                        <label class="mb-1 text-secondary">To Date:</label>
+                        <input type="date" name="to_date" class="form-control input-sm" value="{{request()->input('to_date')}}">
                     </div>
                 </div>
 
                 <div>
-                    <div class="form-group">
+                    <div class="">
                         <label>&nbsp;</label>
                         <div class=" d-flex">
-                            <button type="button" v-on:click.prevent="doSubmit()" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
-                            <a href="#" v-on:click.prevent="fastLoad('{{route('practice-management.hcp-note-activity')}}')" class="btn btn-link btn-sm text-danger">Clear Filters</a>
+                            <button type="button" onclick="return fastLoad('{{ route("practice-management.hcp-note-activity") }}?' + $('#hcp-note-activity-filters').serialize());" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
+                            <a href="#" onclick="return fastLoad('{{ route("practice-management.hcp-note-activity") }}');" class="btn btn-link btn-sm text-danger">Clear Filters</a>
                         </div>
                     </div>
                 </div>
@@ -85,11 +85,15 @@
             <table class="table table-sm table-striped border-0 p-0 m-0 text-nowrap">
                 <thead class="bg-light">
                     <tr>
-                        <th>First Name</th>
-                        <th>Last Name</th>
-                        <th>Last Note Created At</th>
-                        <th># Notes This Month</th>
-                        <th># Notes In the Period</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => 'First Name', 'key' => 'name_first'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => 'Last Name', 'key' => 'name_last'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => 'Last Note Created At', 'key' => 'last_note_created_at'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => '# Notes This Month', 'key' => 'notes_this_month'])</th>
+                        @if(request()->input('from_date') && request()->input('from_date'))
+                            <th>@include('app.practice-management._sort_header', ['label' => '# Notes In the Period', 'key' => 'notes_this_period'])</th>
+                        @endif
+                        <th>@include('app.practice-management._sort_header', ['label' => '# Clients', 'key' => 'total_client_count'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => '# Active Clients', 'key' => 'active_client_count'])</th>
                     </tr>
                 </thead>
                 <tbody>
@@ -101,7 +105,11 @@
                         <td>{{$row->name_last}}</td>
                         <td>{{friendly_date_time($row->last_note_created_at)}}</td>
                         <td>{{$row->notes_this_month}}</td>
-                        <td>{{$row->notes_this_period}}</td>
+                        @if(request()->input('from_date') && request()->input('from_date'))
+                            <td>{{$row->notes_this_period}}</td>
+                        @endif
+                        <td>{{$row->total_client_count}}</td>
+                        <td>{{$row->active_client_count}}</td>
                     </tr>
                     @endforeach
                 </tbody>
@@ -115,75 +123,38 @@
 
 </div>
 
-<?php
-$loadedFilters = $filters;
-$allFilterKeys = [
-	'pros_ids',
-	'from_date',
-	'to_date'
-];
-for ($i = 0; $i < count($allFilterKeys); $i++) {
-	if (!isset($loadedFilters[$allFilterKeys[$i]]) || !$loadedFilters[$allFilterKeys[$i]]) {
-		$loadedFilters[$allFilterKeys[$i]] = '';
-	}
-}
-?>
 <script>
-	(function() {
-		function init() {
-			new Vue({
-				el: '#hcp-note-activity',
-				delimiters: ['@{{', '}}'],
-				data: {
-					filters: <?= json_encode($loadedFilters) ?>
-				},
-				methods: {
-                    initSelect2: function(){
-                        var select2 = $("#searchForProInput").select2({
-                            placeholder: "Search Pro(s) by Name",
-                            minimumInputLength: 2,
-                            ajax: {
-                                url: '/pro-suggest',
-                                dataType: 'json',
-                                type: "GET",
-                                quietMillis: 50,
-                                data: function (params) {
-                                    return {
-                                        term: params.term,
-                                        json: true
-                                    };
-                                },
-                                results: function (data) {
-                                    return {
-                                        results: $.map(data, function (item) {
-                                            return {
-                                                text: item.completeName,
-                                                slug: item.slug,
-                                                id: item.id
-                                            }
-                                        })
-                                    };
-                                }
-                            }
-                        });
+    (function() {
+        function init() {
+            var select2 = $("#searchForProInput").select2({
+                placeholder: "Search Pro(s) by Name",
+                minimumInputLength: 2,
+                ajax: {
+                    url: '/pro-suggest',
+                    dataType: 'json',
+                    type: "GET",
+                    quietMillis: 50,
+                    data: function (params) {
+                        return {
+                            term: params.term,
+                            json: true
+                        };
                     },
-					init: function() {
-                        this.initSelect2();
-					},
-					doSubmit: function() {
-						fastLoad('{{ route("practice-management.hcp-note-activity") }}?' + $('#hcp-note-activity-filters').serialize());
-						return false;
-					}
-				},
-				mounted: function() {
-					console.log(this.filters);
-					this.init();
-				},
-			});
-
-
-		}
-		addMCInitializer('hcp-note-activity', init, '#hcp-note-activity');
-	})();
+                    results: function (data) {
+                        return {
+                            results: $.map(data, function (item) {
+                                return {
+                                    text: item.completeName,
+                                    slug: item.slug,
+                                    id: item.id
+                                }
+                            })
+                        };
+                    }
+                }
+            });
+        }
+        addMCInitializer('hcp-note-activity', init, '#hcp-note-activity');
+    }).call(window);
 </script>
 @endsection

+ 42 - 7
resources/views/app/practice-management/pro-availability.blade.php

@@ -588,6 +588,41 @@
             @if($pro->is_enrolled_as_mcp && $pro->is_considered_for_mcp_assignment)
                 @include('layouts.confirm-hours-of-availability-notification')
             @endif
+            @if($pro->is_enrolled_as_mcp && $pro->is_considered_for_mcp_assignment)
+                <div class="my-3 border p-3 rounded bg-light d-flex align-items-baseline">
+                    <i class="fa fa-globe-americas"></i>
+                    <div class="flex-grow-1 ml-2">
+                        <div class="d-flex align-items-baseline">
+                            <span class="">Display Timezone:</span><b class="ml-2">{{$pro->display_timezone ?: '(not set)'}}</b>
+                            <div moe class="ml-3">
+                                <a href="#" start show class="font-weight-bold">Edit</a>
+                                <form url="/api/pro/putDisplayTimezone">
+                                    <input type="hidden" name="uid" value="{{$pro->uid}}">
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Display Timezone:</label>
+                                        <select name="timezone" class="form-control form-control-sm width-200px">
+                                            <option value="EASTERN" {{$pro->display_timezone === 'EASTERN' ? 'selected' : ''}}>Eastern</option>
+                                            <option value="CENTRAL" {{$pro->display_timezone === 'CENTRAL' ? 'selected' : ''}}>Central</option>
+                                            <option value="MOUNTAIN" {{$pro->display_timezone === 'MOUNTAIN' ? 'selected' : ''}}>Mountain</option>
+                                            <option value="PACIFIC" {{$pro->display_timezone === 'PACIFIC' ? 'selected' : ''}}>Pacific</option>
+                                            <option value="ALASKA" {{$pro->display_timezone === 'ALASKA' ? 'selected' : ''}}>Alaska</option>
+                                            <option value="HAWAII" {{$pro->display_timezone === 'HAWAII' ? 'selected' : ''}}>Hawaii</option>
+                                            <option value="PUERTO_RICO" {{$pro->display_timezone === 'PUERTO_RICO' ? 'selected' : ''}}>Puerto Rico</option>
+                                        </select>
+                                    </div>
+                                    <div class="form-group m-0">
+                                        <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
+                                        <button cancel class="btn btn-default border btn-sm mr-2">Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        </div>
+                        <div class="text-sm text-secondary mt-1">
+                            Your patients will see your availability in this timezone (if set) while booking appointments.
+                        </div>
+                    </div>
+                </div>
+            @endif
             <div class="card">
                 <div class="card-header px-3 py-1 d-flex align-items-center">
                     <strong class="">
@@ -597,13 +632,13 @@
                     <div class="ml-auto d-inline-flex align-items-center">
                         <span class="font-weight-bold text-secondary mr-2">Timezone:</span>
                         <select id="calendar-timezone" class="form-control form-control-sm ml-auto width-200px">
-                            <option value="EASTERN" selected>Eastern</option>
-                            <option value="CENTRAL">Central</option>
-                            <option value="MOUNTAIN">Mountain</option>
-                            <option value="PACIFIC">Pacific</option>
-                            <option value="ALASKA">Alaska</option>
-                            <option value="HAWAII">Hawaii</option>
-                            <option value="PUERTO_RICO">Puerto Rico</option>
+                            <option value="EASTERN" {{!$pro->display_timezone || $pro->display_timezone === 'EASTERN' ? 'selected' : ''}}>Eastern</option>
+                            <option value="CENTRAL" {{$pro->display_timezone === 'CENTRAL' ? 'selected' : ''}}>Central</option>
+                            <option value="MOUNTAIN" {{$pro->display_timezone === 'MOUNTAIN' ? 'selected' : ''}}>Mountain</option>
+                            <option value="PACIFIC" {{$pro->display_timezone === 'PACIFIC' ? 'selected' : ''}}>Pacific</option>
+                            <option value="ALASKA" {{$pro->display_timezone === 'ALASKA' ? 'selected' : ''}}>Alaska</option>
+                            <option value="HAWAII" {{$pro->display_timezone === 'HAWAII' ? 'selected' : ''}}>Hawaii</option>
+                            <option value="PUERTO_RICO" {{$pro->display_timezone === 'PUERTO_RICO' ? 'selected' : ''}}>Puerto Rico</option>
                         </select>
                     </div>
                 </div>

+ 89 - 0
resources/views/app/practice-management/remote-monitoring-admin-tree.blade.php

@@ -0,0 +1,89 @@
+<?php
+if(!@$rc) {
+    $rc = 0;
+}
+?>
+<div class="conditions-tree" id="remote-monitoring-tree">
+    <div class="condition">
+        <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=2"
+                {!! $rc == 2 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many are enrolled in RPM?
+            <span class="rm-count ml-1" data-rc="2">(0)</span>
+        </a>
+        <div class="condition-children">
+            <div class="condition">
+                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=3"
+                        {!! $rc == 3 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many given a cellular device?
+                    <span class="rm-count ml-1" data-rc="3">(0)</span>
+                </a>
+                <div class="condition-children">
+                    <div class="condition">
+                        <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=4"
+                                {!! $rc == 4 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many seen w/in 90 days?
+                            <span class="rm-count ml-1" data-rc="4">(0)</span>
+                        </a>
+                        <div class="condition-children">
+                            <div class="condition">
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=5"
+                                        {!! $rc == 5 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many spoken to this month?
+                                    <span class="rm-count ml-1" data-rc="5">(0)</span>
+                                </a>
+                                <div class="condition-children">
+                                    <div class="condition">
+                                        <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=6"
+                                                {!! $rc == 6 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many with no unstamped meas.?
+                                            <span class="rm-count ml-1" data-rc="6">(0)</span>
+                                        </a>
+                                    </div>
+                                    <div class="condition">
+                                        <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=7"
+                                                {!! $rc == 7 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many with 16 or more meas. days?
+                                            <span class="rm-count ml-1" data-rc="7">(0)</span>
+                                        </a>
+                                        <div class="condition-children">
+                                            <div class="condition">
+                                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=10"
+                                                        {!! $rc == 10 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many with 20 or more billing mins.?
+                                                    <span class="rm-count ml-1" data-rc="10">(0)</span>
+                                                </a>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="condition">
+                        <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=8"
+                                {!! $rc == 8 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Home many have subscribed to SMS?
+                            <span class="rm-count ml-1" data-rc="8">(0)</span>
+                        </a>
+                    </div>
+                    <div class="condition">
+                        <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=9"
+                                {!! $rc == 9 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many have used the device?
+                            <span class="rm-count ml-1" data-rc="9">(0)</span>
+                        </a>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    (function() {
+        function init() {
+            window.setTimeout(() => {
+                $('#remote-monitoring-tree .rm-count').each(function() {
+                    let params = '?rc=' + $(this).attr('data-rc');
+                    if($(this).is('[data-rc2]')) params += '&rc2=' + $(this).attr('data-rc2');
+                    @if(request()->input('m')) params += '&m={{request()->input('m')}}'; @endif
+                    @if(request()->input('y')) params += '&y={{request()->input('y')}}'; @endif
+                    $.get('{{route('practice-management.remote-monitoring-admin-count')}}' + params, _data => {
+                        $(this).text('(' + _data + ')');
+                    });
+                });
+            }, 250);
+        }
+        addMCInitializer('remote-monitoring-tree', init, '#remote-monitoring-tree')
+    }).call(window);
+</script>

+ 143 - 0
resources/views/app/practice-management/remote-monitoring-admin.blade.php

@@ -0,0 +1,143 @@
+@extends ('layouts/template')
+
+@section('content')
+
+    <div class="p-3 mcp-theme-1" id="practice-remote-monitoring">
+
+        <div class="card">
+
+            <div class="card-header px-2 py-2 d-flex align-items-center">
+                <span class="mr-4">
+                    <span class="font-size-14">Remote Monitoring</span>
+                    <i class="fas fa-arrow-right text-sm mx-1"></i>
+                    <b class="font-size-14">{{friendly_month(date((request()->input('y') ?: 'Y') . '-' . (request()->input('m') ?: 'm') . '-d'))}}</b>
+                </span>
+                <form class="ml-auto d-inline-flex flex-nowrap align-items-center" action="" method="GET">
+
+                    <span class="mr-2">Month</span>
+                    <select class="form-control form-control-sm min-width-unset width-100px mr-3" name="m"
+                            onchange="fastLoad('{{route('practice-management.remote-monitoring-admin')}}?' + $(this).closest('form').serialize())">
+                        <option value="01" {{request()->input('m') === '01' ? 'selected' : ''}}>Jan</option>
+                        <option value="02" {{request()->input('m') === '02' ? 'selected' : ''}}>Feb</option>
+                        <option value="03" {{request()->input('m') === '03' ? 'selected' : ''}}>Mar</option>
+                        <option value="04" {{request()->input('m') === '04' ? 'selected' : ''}}>Apr</option>
+                        <option value="05" {{request()->input('m') === '05' ? 'selected' : ''}}>May</option>
+                        <option value="06" {{request()->input('m') === '06' ? 'selected' : ''}}>Jun</option>
+                        <option value="07" {{request()->input('m') === '07' ? 'selected' : ''}}>Jul</option>
+                        <option value="08" {{request()->input('m') === '08' ? 'selected' : ''}}>Aug</option>
+                        <option value="09" {{request()->input('m') === '09' ? 'selected' : ''}}>Sep</option>
+                        <option value="10" {{request()->input('m') === '10' ? 'selected' : ''}}>Oct</option>
+                        <option value="11" {{request()->input('m') === '11' ? 'selected' : ''}}>Nov</option>
+                        <option value="12" {{request()->input('m') === '12' ? 'selected' : ''}}>Dec</option>
+                    </select>
+                    <span class="mr-2">Year</span>
+                    <select class="form-control form-control-sm min-width-unset width-100px" name="y"
+                            onchange="fastLoad('{{route('practice-management.remote-monitoring-admin')}}?' + $(this).closest('form').serialize())">
+                        <option value="2020" {{request()->input('y') === '2020' ? 'selected' : ''}}>2020</option>
+                        <option value="2021" {{request()->input('y') === '2021' ? 'selected' : ''}}>2021</option>
+                        <option value="2022" {{request()->input('y') === '2022' ? 'selected' : ''}}>2022</option>
+                    </select>
+                </form>
+            </div>
+
+            <?php $rc = request()->input('rc') ? request()->input('rc') : 1; ?>
+
+            <div class="card-body p-0">
+                <div class="d-flex align-items-start m-0">
+                    <div class="p-0">
+                        @include('app.practice-management.remote-monitoring-admin-tree')
+                    </div>
+                    <div class="flex-grow-1 border-left p-0">
+                        @if($rc == 4)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=4&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients not seen in over 90 days</a>
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=4&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients seen w/in last 90 days</a>
+                            </div>
+                        @elseif($rc == 5)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=5&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients not spoken to this month</a>
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=5&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients spoken to this month</a>
+                            </div>
+                        @elseif($rc == 6)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=6&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Unstamped Measurements > 0</a>
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=6&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >All Measurements Stamped</a>
+                            </div>
+                        @elseif($rc == 7)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=7&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Measurement Days < 16</a>
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=7&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Measurement Days >= 16</a>
+                            </div>
+                        @elseif($rc == 10)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=10&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Billing Minutes < 20</a>
+                                <a href="{{route('practice-management.remote-monitoring-admin')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=10&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Billing Minutes >= 20</a>
+                            </div>
+                        @endif
+                        <table class="table table-sm table-striped table-hover p-0 m-0 foo-bar-t">
+                            <thead class="bg-light">
+                            <tr>
+                                <th class="border-0">Patient</th>
+                                <th class="border-0">MCP</th>
+                                <th class="border-0">DOB</th>
+                                <th class="border-0">Enrolled in RPM?</th>
+                                <th class="border-0">Cellular BP?</th>
+                                <th class="border-0">Cellular Scale?</th>
+                                <th class="border-0">Latest BP</th>
+                                <th class="border-0">Latest Weight</th>
+                                <th class="border-0">Latest Visit</th>
+                                <th class="border-0">RPM Interaction This Month?</th>
+                                <th class="border-0">Measurements Pending Stamp</th>
+                                <th class="border-0"># Meas. Days This Month</th>
+                                <th class="border-0"># RPM Minutes</th>
+
+                            </tr>
+                            </thead>
+                            <tbody>
+                            @foreach ($patients as $iPatient)
+                                <?php $oPatient = \App\Models\Client::where('uid', $iPatient->client_uid)->first(); ?>
+                                <tr>
+                                    <td class="">
+                                        <a href="/patients/view/{{ $iPatient->client_uid }}" class="text-nowrap">{{ $oPatient->displayName() }}</a>
+                                    </td>
+                                    <td class="">
+                                        {{$oPatient->mcp ? $oPatient->mcp->displayName() : '-'}}
+                                    </td>
+
+                                    <td>{{friendly_date($iPatient->dob)}}</td>
+                                    <td>{{ucwords(strtolower($iPatient->is_enrolled_in_rm ?: ''))}}</td>
+                                    <td>{{$oPatient->hasBPDevice() ? 'Yes' : 'No'}}</td>
+                                    <td>{{$oPatient->hasBPDevice() ? 'Yes' : 'No'}}</td>
+                                    <td>
+                                        {{$iPatient->most_recent_cellular_bp_sbp_mm_hg ?: '-'}}/{{$iPatient->most_recent_cellular_bp_dbp_mm_hg ?: '-'}}
+                                        @if($iPatient->most_recent_cellular_bp_measurement_at)
+                                            <div class="text-sm text-secondary text-nowrap">{{friendly_date_time($iPatient->most_recent_cellular_bp_measurement_at)}}</div>
+                                        @endif
+                                    </td>
+                                    <td>
+                                        {{$iPatient->most_recent_cellular_weight_value ? round($iPatient->most_recent_cellular_weight_value, 1) : '-'}}
+                                        @if($iPatient->most_recent_cellular_weight_measurement_at)
+                                            <div class="text-sm text-secondary text-nowrap">{{friendly_date_time($iPatient->most_recent_cellular_weight_measurement_at)}}</div>
+                                        @endif
+                                    </td>
+                                    <td>{{$iPatient->most_recent_completed_mcp_note_date ? friendly_date($iPatient->most_recent_completed_mcp_note_date) : '-'}}</td>
+                                    <td>{{$iPatient->has_anyone_interacted_with_client_about_rm_outside_note ? 'Yes' : 'No'}}</td>
+                                    <td>{{$iPatient->rm_num_measurements_not_stamped_by_mcp}}</td>
+                                    <td>{{$iPatient->number_of_days_with_remote_measurements ?: 0}}</td>
+                                    <td>{{floor($iPatient->rm_total_time_in_seconds_by_mcp / 60)}}</td>
+
+                                </tr>
+                            @endforeach
+                            </tbody>
+                        </table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+@endsection

+ 97 - 0
resources/views/app/practice-management/remote-monitoring-tree.blade.php

@@ -0,0 +1,97 @@
+<?php
+if(!@$rc) {
+    $rc = 0;
+}
+?>
+<div class="conditions-tree" id="remote-monitoring-tree">
+    <div class="condition">
+        <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=1"
+                {!! $rc == 1 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Who am I the MCP for?
+            <span class="rm-count ml-1" data-rc="1">(0)</span>
+        </a>
+        <div class="condition-children">
+            <div class="condition">
+                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=2"
+                        {!! $rc == 2 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many are enrolled in RPM?
+                    <span class="rm-count ml-1" data-rc="2">(0)</span>
+                </a>
+                <div class="condition-children">
+                    <div class="condition">
+                        <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=3"
+                                {!! $rc == 3 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many given a cellular device?
+                            <span class="rm-count ml-1" data-rc="3">(0)</span>
+                        </a>
+                        <div class="condition-children">
+                            <div class="condition">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=4"
+                                        {!! $rc == 4 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many have I seen w/in 90 days?
+                                    <span class="rm-count ml-1" data-rc="4">(0)</span>
+                                </a>
+                                <div class="condition-children">
+                                    <div class="condition">
+                                        <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=5"
+                                                {!! $rc == 5 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many have I spoken to this month?
+                                            <span class="rm-count ml-1" data-rc="5">(0)</span>
+                                        </a>
+                                        <div class="condition-children">
+                                            <div class="condition">
+                                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=6"
+                                                        {!! $rc == 6 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many with no unstamped meas.?
+                                                    <span class="rm-count ml-1" data-rc="6">(0)</span>
+                                                </a>
+                                            </div>
+                                            <div class="condition">
+                                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=7"
+                                                        {!! $rc == 7 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many with 16 or more meas. days?
+                                                    <span class="rm-count ml-1" data-rc="7">(0)</span>
+                                                </a>
+                                                <div class="condition-children">
+                                                    <div class="condition">
+                                                        <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=10"
+                                                                {!! $rc == 10 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many with 20 or more billing mins.?
+                                                            <span class="rm-count ml-1" data-rc="10">(0)</span>
+                                                        </a>
+                                                    </div>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                            <div class="condition">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=8"
+                                        {!! $rc == 8 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>Home many have subscribed to SMS?
+                                    <span class="rm-count ml-1" data-rc="8">(0)</span>
+                                </a>
+                            </div>
+                            <div class="condition">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=9"
+                                        {!! $rc == 9 ? 'class="bg-aliceblue font-weight-bold"' : ''!!}>How many have used the device?
+                                    <span class="rm-count ml-1" data-rc="9">(0)</span>
+                                </a>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    (function() {
+        function init() {
+            window.setTimeout(() => {
+                $('#remote-monitoring-tree .rm-count').each(function() {
+                    let params = '?rc=' + $(this).attr('data-rc');
+                    if($(this).is('[data-rc2]')) params += '&rc2=' + $(this).attr('data-rc2');
+                    @if(request()->input('m')) params += '&m={{request()->input('m')}}'; @endif
+                    @if(request()->input('y')) params += '&y={{request()->input('y')}}'; @endif
+                    $.get('{{route('practice-management.remote-monitoring-count')}}' + params, _data => {
+                        $(this).text('(' + _data + ')');
+                    });
+                });
+            }, 250);
+        }
+        addMCInitializer('remote-monitoring-tree', init, '#remote-monitoring-tree')
+    }).call(window);
+</script>

+ 135 - 92
resources/views/app/practice-management/remote-monitoring.blade.php

@@ -2,109 +2,152 @@
 
 @section('content')
 
-    <div class="p-3 mcp-theme-1" id="practice-billing-manager">
+    <div class="p-3 mcp-theme-1" id="practice-remote-monitoring">
 
         <div class="card">
 
-            <div class="card-header px-2 py-1 d-flex align-items-center">
+            <div class="card-header px-2 py-2 d-flex align-items-center">
                 <span class="mr-4">
                     <span class="font-size-14">Remote Monitoring</span>
                     <i class="fas fa-arrow-right text-sm mx-1"></i>
                     <b class="font-size-14">{{friendly_month(date((request()->input('y') ?: 'Y') . '-' . (request()->input('m') ?: 'm') . '-d'))}}</b>
                 </span>
-                <?php
-                $dateInput = [];
-                if(request()->input('m')) $dateInput[] = 'm=' . request()->input('m');
-                if(request()->input('y')) $dateInput[] = 'y=' . request()->input('y');
-                $dateInput = '&' . implode('&', $dateInput);
-                ?>
-                <select class="ml-auto max-width-200px form-control form-control-sm"
-                        onchange="fastLoad('/practice-management/remote-monitoring?fmd=' + this.value + '&fcomm={{request()->input('fcomm')}}{{$dateInput}}', true, false, false)">
-                    <option value="all" {{ !request()->input('fmd') || request()->input('fmd') === 'all' ? 'selected' : '' }}>All</option>
-                    <option value="lt16" {{ request()->input('fmd') === 'lt16' ? 'selected' : '' }}>Patients with &lt; 16 meas. days</option>
-                    <option value="gte16" {{ request()->input('fmd') === 'gte16' ? 'selected' : '' }}>Patients with &ge; 16 meas. days</option>
-                </select>
-                <select class="ml-3 max-width-200px form-control form-control-sm"
-                        onchange="fastLoad('/practice-management/remote-monitoring?fmd={{request()->input('fmd')}}&fcomm=' + this.value + '{{$dateInput}}', true, false, false)">
-                    <option value="all" {{ !request()->input('fcomm') || request()->input('fcomm') === 'all' ? 'selected' : '' }}>All</option>
-                    <option value="not-done" {{ request()->input('fcomm') === 'not-done' ? 'selected' : '' }}>Patients with whom comm. not done</option>
-                    <option value="done" {{ request()->input('fcomm') === 'done' ? 'selected' : '' }}>Patients with whom comm. done</option>
-                </select>
+                <form class="ml-auto d-inline-flex flex-nowrap align-items-center" action="" method="GET">
+                    <span class="mr-2">Month</span>
+                    <select class="form-control form-control-sm min-width-unset width-100px mr-3" name="m"
+                            onchange="fastLoad('{{route('practice-management.remote-monitoring')}}?' + $(this).closest('form').serialize())">
+                        <option value="01" {{request()->input('m') === '01' ? 'selected' : ''}}>Jan</option>
+                        <option value="02" {{request()->input('m') === '02' ? 'selected' : ''}}>Feb</option>
+                        <option value="03" {{request()->input('m') === '03' ? 'selected' : ''}}>Mar</option>
+                        <option value="04" {{request()->input('m') === '04' ? 'selected' : ''}}>Apr</option>
+                        <option value="05" {{request()->input('m') === '05' ? 'selected' : ''}}>May</option>
+                        <option value="06" {{request()->input('m') === '06' ? 'selected' : ''}}>Jun</option>
+                        <option value="07" {{request()->input('m') === '07' ? 'selected' : ''}}>Jul</option>
+                        <option value="08" {{request()->input('m') === '08' ? 'selected' : ''}}>Aug</option>
+                        <option value="09" {{request()->input('m') === '09' ? 'selected' : ''}}>Sep</option>
+                        <option value="10" {{request()->input('m') === '10' ? 'selected' : ''}}>Oct</option>
+                        <option value="11" {{request()->input('m') === '11' ? 'selected' : ''}}>Nov</option>
+                        <option value="12" {{request()->input('m') === '12' ? 'selected' : ''}}>Dec</option>
+                    </select>
+                    <span class="mr-2">Year</span>
+                    <select class="form-control form-control-sm min-width-unset width-100px" name="y"
+                            onchange="fastLoad('{{route('practice-management.remote-monitoring')}}?' + $(this).closest('form').serialize())">
+                        <option value="2020" {{request()->input('y') === '2020' ? 'selected' : ''}}>2020</option>
+                        <option value="2021" {{request()->input('y') === '2021' ? 'selected' : ''}}>2021</option>
+                        <option value="2022" {{request()->input('y') === '2022' ? 'selected' : ''}}>2022</option>
+                    </select>
+                </form>
             </div>
+
+            <?php $rc = request()->input('rc') ? request()->input('rc') : 1; ?>
+
             <div class="card-body p-0">
-                <table class="table table-sm table-striped table-hover p-0 m-0">
-                    <thead class="bg-light">
-                    <tr>
-                        <th class="border-0">Patient</th>
-                        <th class="border-0">Relation</th>
-                        <th class="border-0">Measurement Days</th>
-                        <th class="border-0">Unstamped Measurements</th>
-                        
-                        <th class="border-0">Phone</th>
-                    </tr>
-                    </thead>
-                    <tbody>
-                    @foreach ($patients as $iPatient)
-                        <tr>
-                            <td class="">
-                                <a href="/patients/view/{{ $iPatient->client_uid }}">{{ $iPatient->name_first }} {{ $iPatient->name_last }}</a>
-                            </td>
-                            <td class="">
-                                @if($iPatient->mcp_pro_id === $pro->id)
-                                    <div>MCP</div>
-                                @endif
-                                @if($iPatient->default_na_pro_id === $pro->id)
-                                    <div>Care Coordinator</div>
-                                @endif
-                                @if($iPatient->rmm_pro_id === $pro->id)
-                                    <div>RMM</div>
-                                @endif
-                                @if($iPatient->rme_pro_id === $pro->id)
-                                    <div>RME</div>
-                                @endif
-                            </td>
-                            <td class="">
-                                <span class="d-inline-block width-30px">{{$iPatient->number_of_days_with_remote_measurements ?: '0'}}</span>
-                                <span class="">
-                                <?php $moreMDNeeded = 16 - $iPatient->number_of_days_with_remote_measurements; ?>
-                                @if($iPatient->number_of_days_with_remote_measurements >= 16)
-                                    <i class="fa fa-check text-success" title="16 measurement days reached"></i>
-                                @elseif($daysRemaining >= $moreMDNeeded)
-                                    <i class="fa fa-exclamation-triangle text-warning-mellow" title="{{$moreMDNeeded}} more measurement day{{$moreMDNeeded > 1 ? 's' : ''}} needed"></i>
-                                @elseif($daysRemaining < $moreMDNeeded)
-                                    <i class="fa fa-exclamation-triangle text-secondary opacity-60" title="Can no longer reach 16 measurement days this month"></i>
-                                @endif
-                                </span>
-                            </td>
-                            <td class="">
-                                <?php $numUS = 0; ?>
-                                @if($iPatient->mcp_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_mcp; ?>
-                                @elseif($iPatient->default_na_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_non_hcp; ?>
-                                @elseif($iPatient->rmm_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_rmm; ?>
-                                @elseif($iPatient->rme_pro_id === $pro->id)
-                                    <?php $numUS = $iPatient->rm_num_measurements_not_stamped_by_rme; ?>
-                                @endif
-                                <span class="d-inline-block width-30px">{{$numUS ?: '-'}}</span>
-                                @if($numUS || true)
-                                    <a native target="_blank"
-                                       open-in-stag-popup
-                                       update-parent
-                                       mc-initer="remote-monitoring-measurements-{{$iPatient->care_month_id}}"
-                                       title="{{ $iPatient->name_first }} {{ $iPatient->name_last }} / Unstamped Measurements / {{ friendly_month($careMonthStart) }}"
-                                       href="/remote-monitoring-measurements/{{$iPatient->care_month_uid}}">View</a>
-                                @endif
-                            </td>
+                <div class="d-flex align-items-start m-0">
+                    <div class="p-0">
+                        @include('app.practice-management.remote-monitoring-tree')
+                    </div>
+                    <div class="flex-grow-1 border-left p-0">
+                        @if($rc == 4)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=4&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients I have not seen in over 90 days</a>
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=4&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients I have seen w/in last 90 days</a>
+                            </div>
+                        @elseif($rc == 5)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=5&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients I have not spoken to this month</a>
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=5&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Patients I have spoken to this month</a>
+                            </div>
+                        @elseif($rc == 6)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=6&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Unstamped Measurements > 0</a>
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=6&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >All Measurements Stamped</a>
+                            </div>
+                        @elseif($rc == 7)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=7&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Measurement Days < 16</a>
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=7&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Measurement Days >= 16</a>
+                            </div>
+                        @elseif($rc == 10)
+                            <?php $rc2 = request()->input('rc2') ? request()->input('rc2') : 2; ?>
+                            <div class="d-flex align-items-baseline p-2 border-bottom">
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=10&rc2=1" class="border p-2 mr-2 {{$rc2 == 1 ? 'bg-aliceblue font-weight-bold' : ''}}" >Billing Minutes < 20</a>
+                                <a href="{{route('practice-management.remote-monitoring')}}?m={{request()->input('m')}}&y={{request()->input('y')}}&rc=10&rc2=2" class="border p-2 mr-2 {{$rc2 == 2 ? 'bg-aliceblue font-weight-bold' : ''}}" >Billing Minutes >= 20</a>
+                            </div>
+                        @endif
+                        <table class="table table-sm table-striped table-hover p-0 m-0">
+                            <thead class="bg-light">
+                            <tr>
+                                <th class="border-0">Name</th>
+                                <!--<th class="border-0">Relation</th>-->
+
+                                <th class="border-0">DOB</th>
+                                <th class="border-0">Enrolled in RPM?</th>
+                                <th class="border-0">Cellular BP?</th>
+                                <th class="border-0">Cellular Scale?</th>
+                                <th class="border-0">Latest BP</th>
+                                <th class="border-0">Latest Weight</th>
+                                <th class="border-0">Latest Visit</th>
+                                <th class="border-0">RPM Interaction This Month?</th>
+                                <th class="border-0">Measurements Pending Stamp</th>
+                                <th class="border-0"># Meas. Days This Month</th>
+                                <th class="border-0"># RPM Minutes</th>
+
+                            </tr>
+                            </thead>
+                            <tbody>
+                            @foreach ($patients as $iPatient)
+                                <?php $oPatient = \App\Models\Client::where('uid', $iPatient->client_uid)->first(); ?>
+                                <tr>
+                                    <td class="">
+                                        <a href="/patients/view/{{ $iPatient->client_uid }}" class="text-nowrap">{{ $oPatient->displayName() }}</a>
+                                    </td>
+                                    <!--<td class="">
+                                        @if($iPatient->mcp_pro_id === $pro->id)
+                                            <div>MCP</div>
+                                        @endif
+                                        @if($iPatient->default_na_pro_id === $pro->id)
+                                            <div>Care Coordinator</div>
+                                        @endif
+                                        @if($iPatient->rmm_pro_id === $pro->id)
+                                            <div>RMM</div>
+                                        @endif
+                                        @if($iPatient->rme_pro_id === $pro->id)
+                                            <div>RME</div>
+                                        @endif
+                                    </td>-->
+
+                                    <td>{{friendly_date($iPatient->dob)}}</td>
+                                    <td>{{ucwords(strtolower($iPatient->is_enrolled_in_rm ?: ''))}}</td>
+                                    <td>{{$oPatient->hasBPDevice() ? 'Yes' : 'No'}}</td>
+                                    <td>{{$oPatient->hasBPDevice() ? 'Yes' : 'No'}}</td>
+                                    <td>
+                                        {{$iPatient->most_recent_cellular_bp_sbp_mm_hg ?: '-'}}/{{$iPatient->most_recent_cellular_bp_dbp_mm_hg ?: '-'}}
+                                        @if($iPatient->most_recent_cellular_bp_measurement_at)
+                                            <div class="text-sm text-secondary text-nowrap">{{friendly_date_time($iPatient->most_recent_cellular_bp_measurement_at)}}</div>
+                                        @endif
+                                    </td>
+                                    <td>
+                                        {{$iPatient->most_recent_cellular_weight_value ? round($iPatient->most_recent_cellular_weight_value, 1) : '-'}}
+                                        @if($iPatient->most_recent_cellular_weight_measurement_at)
+                                            <div class="text-sm text-secondary text-nowrap">{{friendly_date_time($iPatient->most_recent_cellular_weight_measurement_at)}}</div>
+                                        @endif
+                                    </td>
+                                    <td>{{$iPatient->most_recent_completed_mcp_note_date ? friendly_date($iPatient->most_recent_completed_mcp_note_date) : '-'}}</td>
+                                    <td>{{$iPatient->has_anyone_interacted_with_client_about_rm_outside_note ? 'Yes' : 'No'}}</td>
+                                    <td>{{$iPatient->rm_num_measurements_not_stamped_by_mcp}}</td>
+                                    <td>{{$iPatient->number_of_days_with_remote_measurements ?: 0}}</td>
+                                    <td>{{floor($iPatient->rm_total_time_in_seconds_by_mcp / 60)}}</td>
 
-                            <td class="">
-                                {{$iPatient->cell_number}}
-                            </td>
-                        </tr>
-                    @endforeach
-                    </tbody>
-                </table>
+                                </tr>
+                            @endforeach
+                            </tbody>
+                        </table>
+                    </div>
+                </div>
             </div>
         </div>
     </div>

+ 1 - 1
resources/views/layouts/confirm-hours-of-availability-notification.blade.php

@@ -38,7 +38,7 @@
 		</div>
 		@else
 		<div>
-			<span>Hours of Avaliability last confirmed on <b><i class="fas fa-history"></i> {{ friendly_date($pro->hours_of_availability_confirmed_at) }}</b></span>
+			<span>Hours of Availability last confirmed on <b><i class="fas fa-history"></i> {{ friendly_date($pro->hours_of_availability_confirmed_at) }}</b></span>
 		</div>
 
 		<div>

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

@@ -246,6 +246,10 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 						<li class="nav-item">
 							<a class="nav-link" href="/patients/view/{{ $patient->uid }}/intake">Intake</a>
 						</li>
+						<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)
 						<li class="nav-item">
 							<a class="nav-link {{ strpos($routeName, 'patients.view.mcp-requests') === 0 ? 'active' : '' }}"
@@ -259,10 +263,7 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 							<a class="nav-link {{ strpos($routeName, 'patients.view.insurance-coverage') === 0 ? 'active' : '' }}"
 							   href="{{ route('patients.view.insurance-coverage', $patient) }}">Insurance Coverage</a>
 						</li>
-                        <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>
+                       
 						<li class="nav-item">
 							<a class="nav-link {{ strpos($routeName, 'patients.view.claims-resolver') === 0 ? 'active' : '' }}"
 							   href="{{ route('patients.view.claims-resolver', $patient) }}">Claims Resolver</a>

+ 5 - 1
resources/views/layouts/template.blade.php

@@ -123,6 +123,11 @@
                         <i class="mr-1 fas fa-tasks"></i> Practice
                     </a>
                     <div class="dropdown-menu mcp-theme-1 no-overflow-menu p-0" aria-labelledby="practice-management">
+                        @if($pro->pro_type !== 'ADMIN')
+                            <a class="dropdown-item" href="{{ route('practice-management.remote-monitoring') }}">Remote Monitoring</a>
+                        @else
+                            <a class="dropdown-item" href="{{ route('practice-management.remote-monitoring-admin') }}">Remote Monitoring (admin)</a>
+                        @endif
                         @if($pro->pro_type == 'ADMIN')
                             <a class="dropdown-item" href="{{ route('practice-management.rpmMatrix') }}">RPM Matrix</a>
                             {{--<a class="dropdown-item" href="{{ route('practice-management.previousBills') }}">Previous Bills</a>--}}
@@ -130,7 +135,6 @@
                             <a class="dropdown-item" href="/practice-management/bills/not-yet-signed">Pending Bills to Sign</a>
                             <a class="dropdown-item" href="/practice-management/notes/not-yet-signed">Pending Notes to Sign</a>
                             <a class="dropdown-item" href="/practice-management/notes/not-yet-signed-but-ally-signed">Pending Notes to Sign (Ally Signed)</a>
-                            <a class="dropdown-item" href="{{ route('practice-management.remote-monitoring') }}">Remote Monitoring</a>
                             <a class="dropdown-item" href="{{ route('pro-care-month-report') }}">Care Month Report</a>
                             <a class="dropdown-item" href="{{ route('practice-management.rm-bills-to-sign') }}">RM Bills to Sign</a>
                             <a class="dropdown-item" href="{{ route('unmapped-sms') }}">Unmapped SMS</a>

+ 6 - 1
routes/web.php

@@ -206,7 +206,6 @@ Route::middleware('pro.auth')->group(function () {
 
         Route::get('rpm-matrix', 'PracticeManagementController@rpmMatrix')->name('rpmMatrix');
 
-        Route::get('remote-monitoring-report', 'PracticeManagementController@remoteMonitoringReport')->name('remoteMonitoringReport');
         Route::get('rates/{selectedProUid?}', 'PracticeManagementController@rates')->name('rates');
         Route::get('dashboard', 'PracticeManagementController@dashboard')->name('dashboard');
         Route::get('previous-bills', 'PracticeManagementController@previousBills')->name('previousBills');
@@ -252,6 +251,8 @@ Route::middleware('pro.auth')->group(function () {
         Route::get('hcp-note-activity', 'PracticeManagementController@hcpNoteActivity')->name('hcp-note-activity');
 
         Route::middleware('pro.auth.admin')->group(function () {
+        	
+		Route::get('remote-monitoring-report', 'PracticeManagementController@remoteMonitoringReport')->name('remoteMonitoringReport');
 
             // BILLING REPORT
             Route::get('billing-report', 'PracticeManagementController@billingReport')->name('billing-report');
@@ -301,6 +302,10 @@ Route::middleware('pro.auth')->group(function () {
         Route::get('supply-orders/unsigned', 'PracticeManagementController@supplyOrdersUnsigned')->name('supply-orders-unsigned');
 
         Route::get('remote-monitoring', 'PracticeManagementController@remoteMonitoring')->name('remote-monitoring');
+        Route::get('remote-monitoring-count', 'PracticeManagementController@remoteMonitoringCount')->name('remote-monitoring-count');
+
+        Route::get('remote-monitoring-admin', 'PracticeManagementController@remoteMonitoringAdmin')->name('remote-monitoring-admin');
+        Route::get('remote-monitoring-admin-count', 'PracticeManagementController@remoteMonitoringAdminCount')->name('remote-monitoring-admin-count');
 
 
         //stat tree stuff

+ 75 - 0
spec/sample_rm_stat_tree.txt

@@ -0,0 +1,75 @@
+care_month join client on care_month.client_id = client.id	Start date? 2021-12-01	(care_month.start_date = '2021-12-01')
+care_month join client on care_month.client_id = client.id	Enrolled in RPM?	YES	(client.is_enrolled_in_rm = 'YES')
+care_month join client on care_month.client_id = client.id	Enrolled in RPM?	NO	(client.is_enrolled_in_rm = 'NO')
+care_month join client on care_month.client_id = client.id	Have cellular device?	YES	(SELECT COUNT(client_bdt_device.id) FROM client_bdt_device JOIN bdt_device bd on client_bdt_device.device_id = bd.id WHERE client_bdt_device.client_id = client.id) > 0		
+care_month join client on care_month.client_id = client.id	Have been seen w/in 90 days?	YES	(DATE_PART('day', client.most_recent_completed_mcp_note_date::timestamp - care_month.start_date::timestamp) <= 90)
+care_month join client on care_month.client_id = client.id	Have been seen w/in 90 days?	NO	(DATE_PART('day', client.most_recent_completed_mcp_note_date::timestamp - care_month.start_date::timestamp) > 90)
+care_month join client on care_month.client_id = client.id	Have been spoken to this month?	YES	(care_month.has_anyone_interacted_with_client_about_rm_outside_note = TRUE)
+care_month join client on care_month.client_id = client.id	Have been spoken to this month?	NO	(care_month.has_anyone_interacted_with_client_about_rm_outside_note IS NULL OR care_month.has_anyone_interacted_with_client_about_rm_outside_note = FALSE)
+care_month join client on care_month.client_id = client.id	Have no unstamped meas.?	YES	(care_month.rm_num_measurements_not_stamped_by_mcp = 0)
+care_month join client on care_month.client_id = client.id	Have no unstamped meas.?	NO	(care_month.rm_num_measurements_not_stamped_by_mcp > 0)
+care_month join client on care_month.client_id = client.id	Have 16 or more meas. days?	YES	(care_month.number_of_days_with_remote_measurements >= 16)
+care_month join client on care_month.client_id = client.id	Have 16 or more meas. days?	NO	(care_month.number_of_days_with_remote_measurements < 16)
+care_month join client on care_month.client_id = client.id	Have 20 or more billing mins.?	YES	(care_month.rm_total_time_in_seconds_by_mcp >= 1200)
+care_month join client on care_month.client_id = client.id	Have 20 or more billing mins.?	NO	(care_month.rm_total_time_in_seconds_by_mcp < 1200)
+care_month join client on care_month.client_id = client.id	Have subscribed to SMS?	YES	(client.send_sms_on_bdt_measurement = TRUE)
+care_month join client on care_month.client_id = client.id	Have used the device?	YES	(client.most_recent_cellular_bp_measurement_at IS NOT NULL OR most_recent_cellular_weight_measurement_at IS NOT NULL)
+
+
+
+ Enrolled in RPM? YES
+ Enrolled in RPM? NO
+ Have cellular device? YES
+ Have been seen w/in 90 days? YES
+ Have been seen w/in 90 days? NO
+ Have been spoken to this month? YES
+ Have been spoken to this month? NO
+ Have no unstamped meas.? YES
+ Have no unstamped meas.? NO
+ Have 16 or more meas. days? YES
+ Have 16 or more meas. days? NO
+ Have 20 or more billing mins.? YES
+ Have 20 or more billing mins.? NO
+ Have subscribed to SMS? YES
+ Have used the device? YES
+
+
+<<<<<<< HEAD
+Start date. 2021-12-01
+=======
+Start date? 2021-12-01
+>>>>>>> 9d1c97068d0d8befbe5b3deb4efabbbfcf325574
+    Enrolled in RPM? YES
+        Have cellular device? YES
+            Have been seen w/in 90 days? NO
+            Have been seen w/in 90 days? YES
+                Have been spoken to this month? YES
+                    Have 16 or more meas. days? YES
+                        Have 20 or more billing mins.? YES
+                        Have 20 or more billing mins.? NO
+                    Have 16 or more meas. days? NO
+            Have been spoken to this month? NO
+            Have no unstamped meas.? YES
+            Have no unstamped meas.? NO
+            Have subscribed to SMS? YES
+    Enrolled in RPM? NO
+
+<<<<<<< HEAD
+=======
+Enrolled in RPM? YES
+    Have cellular device? YES
+        Have been seen w/in 90 days? NO
+        Have been seen w/in 90 days? YES
+            Have been spoken to this month? YES
+                Have 16 or more meas. days? YES
+                    Have 20 or more billing mins.? YES
+                    Have 20 or more billing mins.? NO
+                Have 16 or more meas. days? NO
+        Have been spoken to this month? NO
+        Have no unstamped meas.? YES
+        Have no unstamped meas.? NO
+        Have subscribed to SMS? YES
+Enrolled in RPM? NO
+
+>>>>>>> 9d1c97068d0d8befbe5b3deb4efabbbfcf325574
+

+ 20 - 17
spec/stat-tree-report-builder-spec.txt

@@ -47,22 +47,8 @@ Pro	Is HCP?	NO	(is_hcp IS NOT TRUE)
 
 			EXAMPLE tsv_text_for_lines:
 			
-[QUESTION][SPACE][ANSWER]
-Active? YES
-	MCP assigned? YES
-		MCB Primary? NO
-			Has active RM device? YES
-	MCP assigned? NO
-		MCB Primary? YES
-Active? NO
-	MCB Primary? YES
-		Has active RM device? YES
-		Has active RM device? NO
-	MCB Primary? NO
-		Has active RM device? YES
-		Has active RM device? NO
-	Has active RM device? YES
-	Has active RM device? NO
+
+
 //Pros
 Active? YES
 	Is HCP? YES
@@ -258,4 +244,21 @@ Active? NO
 	Top level filters:
 		-(WHERE mcp_pro_id=2)
 
-	// render same thing as static stat-tree-line, but with this filter
+	// render same thing as static stat-tree-line, but with this filter
+
+
+
+client	Active?	YES	(is_active IS TRUE)
+client	Active?	NO	(is_active IS FALSE)
+client	MCP assigned?	YES	(mcp_pro_id IS NOT NULL)
+client	MCP assigned?	NO	(mcp_pro_id IS NULL)
+client	MCB Primary?	YES	(is_part_b_primary = 'YES')
+client	MCB Primary?	NO	(is_part_b_primary = 'NO')
+
+
+Active? YES
+	MCP assigned? YES
+		MCB Primary? YES
+		MCB Primary? NO
+	MCP assigned? NO
+Active? NO