|
@@ -1072,6 +1072,75 @@ 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'));
|
|
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') ?: 1;
|
|
|
|
+ $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_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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $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;
|
|
|
|
+ }
|
|
|
|
+
|
|
public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
|
|
public function remoteMonitoringMeasurements(Request $request, CareMonth $careMonth) {
|
|
|
|
|
|
$performer = $this->performer();
|
|
$performer = $this->performer();
|