|
@@ -981,50 +981,9 @@ class PracticeManagementController extends Controller
|
|
$careMonthStart = date($ym . '-01');
|
|
$careMonthStart = date($ym . '-01');
|
|
|
|
|
|
$rc = $request->input('rc') ?: 1;
|
|
$rc = $request->input('rc') ?: 1;
|
|
- $rc2 = $request->input('rc2') ?: 1;
|
|
|
|
- $conditions = [];
|
|
|
|
|
|
+ $rc2 = $request->input('rc2') ?: 2;
|
|
|
|
|
|
- $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_lastVisitWithin90Days = "DATE_PART('day', client.most_recent_completed_mcp_note_date::timestamp - care_month.start_date::timestamp) <= 90";
|
|
|
|
- $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)";
|
|
|
|
-
|
|
|
|
- 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, $c_lastVisitWithin90Days];
|
|
|
|
- break;
|
|
|
|
- case 5:
|
|
|
|
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $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 8:
|
|
|
|
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
|
|
|
|
- break;
|
|
|
|
- case 9:
|
|
|
|
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_deviceUsed];
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ $conditions = $this->rpmConditions($performer, $rc, $rc2);
|
|
|
|
|
|
$patients = DB::select(
|
|
$patients = DB::select(
|
|
DB::raw(
|
|
DB::raw(
|
|
@@ -1081,12 +1040,34 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
|
|
|
|
|
|
$rc = $request->input('rc') ?: 1;
|
|
$rc = $request->input('rc') ?: 1;
|
|
$rc2 = $request->input('rc2') ?: 1;
|
|
$rc2 = $request->input('rc2') ?: 1;
|
|
|
|
+
|
|
|
|
+ $conditions = $this->rpmConditions($performer, $rc, $rc2);
|
|
|
|
+
|
|
|
|
+ $count = DB::select(
|
|
|
|
+ DB::raw(
|
|
|
|
+ "
|
|
|
|
+SELECT count(client.id)
|
|
|
|
+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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function rpmConditions($performer, $rc, $rc2) {
|
|
$conditions = [];
|
|
$conditions = [];
|
|
|
|
|
|
$c_isMCP = "client.mcp_pro_id = {$performer->pro->id}";
|
|
$c_isMCP = "client.mcp_pro_id = {$performer->pro->id}";
|
|
$c_enrolledInRPM = "client.is_enrolled_in_rm = 'YES'";
|
|
$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_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_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_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_hasUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp > 0";
|
|
$c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
|
|
$c_hasNoUnstamped = "care_month.rm_num_measurements_not_stamped_by_mcp = 0";
|
|
@@ -1094,6 +1075,8 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
|
|
$c_gte16MeasurementDays = "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_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_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) {
|
|
switch ($rc) {
|
|
case 1:
|
|
case 1:
|
|
@@ -1106,10 +1089,10 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice];
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice];
|
|
break;
|
|
break;
|
|
case 4:
|
|
case 4:
|
|
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days];
|
|
|
|
|
|
+ $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, ($rc2 == 1 ? $c_lastVisitBefore90Days : $c_lastVisitWithin90Days)];
|
|
break;
|
|
break;
|
|
case 5:
|
|
case 5:
|
|
- $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth];
|
|
|
|
|
|
+ $conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, ($rc2 == 1 ? $c_notSpokenToThisMonth : $c_spokenToThisMonth)];
|
|
break;
|
|
break;
|
|
case 6:
|
|
case 6:
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_hasUnstamped : $c_hasNoUnstamped)];
|
|
@@ -1117,6 +1100,9 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
|
|
case 7:
|
|
case 7:
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_hasDevice, $c_lastVisitWithin90Days, $c_spokenToThisMonth, ($rc2 == 1 ? $c_lt16MeasurementDays : $c_gte16MeasurementDays)];
|
|
break;
|
|
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:
|
|
case 8:
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
|
|
$conditions = [$c_isMCP, $c_enrolledInRPM, $c_subscribedToSMS];
|
|
break;
|
|
break;
|
|
@@ -1125,20 +1111,7 @@ ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, cli
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- $count = DB::select(
|
|
|
|
- DB::raw(
|
|
|
|
- "
|
|
|
|
-SELECT count(client.id)
|
|
|
|
-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;
|
|
|
|
|
|
+ return $conditions;
|
|
}
|
|
}
|
|
|
|
|
|
public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
|
|
public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
|