|
@@ -438,51 +438,60 @@ class McpController extends Controller
|
|
|
$ym = ($request->input('y') ?: 'Y') . '-' . ($request->input('m') ?: 'm');
|
|
|
$careMonthStart = date($ym . '-01');
|
|
|
|
|
|
- $query = "
|
|
|
-SELECT client.name_first, client.name_last,
|
|
|
- (client.name_first || ' ' || client.name_last) as client_name,
|
|
|
- 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,
|
|
|
- GREATEST(client.most_recent_cellular_bp_measurement_at, client.most_recent_cellular_weight_measurement_at) as latest_measurement_at
|
|
|
-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())') . "
|
|
|
- AND care_month.rm_num_measurements_not_stamped_by_mcp > 0
|
|
|
- ORDER BY latest_measurement_at DESC
|
|
|
- LIMIT 1
|
|
|
-";
|
|
|
-
|
|
|
$patient = null;
|
|
|
$careMonth = null;
|
|
|
- $patients = DB::select($query);
|
|
|
|
|
|
- if(count($patients)) {
|
|
|
- $patient = Client::where('uid', $patients[0]->client_uid)->first();
|
|
|
- $careMonth = CareMonth::where('uid', $patients[0]->care_month_uid)->first();
|
|
|
+ if($request->input('patientUid') && $request->input('careMonthUid')) {
|
|
|
+ $patient = Client::where('uid', $request->input('patientUid'))->first();
|
|
|
+ $careMonth = CareMonth::where('uid', $request->input('careMonthUid'))->first();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$patient && !$careMonth) {
|
|
|
+
|
|
|
+ $query = "
|
|
|
+ SELECT client.name_first, client.name_last,
|
|
|
+ (client.name_first || ' ' || client.name_last) as client_name,
|
|
|
+ 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,
|
|
|
+ GREATEST(client.most_recent_cellular_bp_measurement_at, client.most_recent_cellular_weight_measurement_at) as latest_measurement_at
|
|
|
+ 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())') . "
|
|
|
+ AND care_month.rm_num_measurements_not_stamped_by_mcp > 0
|
|
|
+ ORDER BY latest_measurement_at DESC
|
|
|
+ LIMIT 1
|
|
|
+ ";
|
|
|
+
|
|
|
+ $patients = DB::select($query);
|
|
|
+
|
|
|
+ if (count($patients)) {
|
|
|
+ $patient = Client::where('uid', $patients[0]->client_uid)->first();
|
|
|
+ $careMonth = CareMonth::where('uid', $patients[0]->care_month_uid)->first();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return view('app.mcp.rpm_work_matrix', compact('patient', 'careMonth'));
|