|
@@ -1046,7 +1046,7 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
|
|
$count = DB::select(
|
|
$count = DB::select(
|
|
DB::raw(
|
|
DB::raw(
|
|
"
|
|
"
|
|
-SELECT count(client.id)
|
|
|
|
|
|
+SELECT count(*)
|
|
FROM care_month join client on care_month.client_id = client.id
|
|
FROM care_month join client on care_month.client_id = client.id
|
|
WHERE
|
|
WHERE
|
|
client.mcp_pro_id = {$performer->pro->id}
|
|
client.mcp_pro_id = {$performer->pro->id}
|
|
@@ -1059,6 +1059,88 @@ WHERE
|
|
return $count[0]->count;
|
|
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) {
|
|
private function rpmConditions($performer, $rc, $rc2) {
|
|
$conditions = [];
|
|
$conditions = [];
|
|
|
|
|
|
@@ -1114,6 +1196,57 @@ WHERE
|
|
return $conditions;
|
|
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', client.most_recent_completed_mcp_note_date::timestamp - care_month.start_date::timestamp) > 90";
|
|
|
|
+ $c_lastVisitWithin90Days = "DATE_PART('day', client.most_recent_completed_mcp_note_date::timestamp - care_month.start_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) {
|
|
public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
|
|
|
|
|
|
$performer = $this->performer();
|
|
$performer = $this->performer();
|