|
@@ -1686,6 +1686,12 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
|
|
$originalTerm = $term;
|
|
$originalTerm = $term;
|
|
if (empty($term)) return '';
|
|
if (empty($term)) return '';
|
|
|
|
|
|
|
|
+ // replace comma with space
|
|
|
|
+ $term = str_replace(',', ' ', $term);
|
|
|
|
+
|
|
|
|
+ // special param for phone matching
|
|
|
|
+ $phoneTerm = preg_replace('/[^a-zA-Z0-9]/', '', $originalTerm);
|
|
|
|
+
|
|
// if multiple words in query, check for all (max 2)
|
|
// if multiple words in query, check for all (max 2)
|
|
$term2 = '';
|
|
$term2 = '';
|
|
if(strpos($term, ' ') !== FALSE) {
|
|
if(strpos($term, ' ') !== FALSE) {
|
|
@@ -1699,8 +1705,41 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
|
|
$phoneNumberTerm = $term;
|
|
$phoneNumberTerm = $term;
|
|
}
|
|
}
|
|
|
|
|
|
- $clientQuery= Client::whereNull('shadow_pro_id');
|
|
|
|
|
|
+ // $clientQuery= Client::whereNull('shadow_pro_id');
|
|
|
|
+
|
|
|
|
+ $columns = "c.id, c.uid, c.mcp_pro_id, c.name_display, c.name_first, c.name_last, c.cell_number, c.phone_home, c.client_engagement_status_category, c.dob";
|
|
|
|
+
|
|
|
|
+ $termWhere = "AND (
|
|
|
|
+ c.name_first ILIKE :term OR c.name_last ILIKE :term OR
|
|
|
|
+ " . (!empty($term2) ? "c.name_first ILIKE :term2 OR c.name_last ILIKE :term2 OR" : "") . "
|
|
|
|
+ c.cell_number ILIKE :phoneTerm OR
|
|
|
|
+ c.cell_number ILIKE :phoneTermRaw OR
|
|
|
|
+ c.phone_home ILIKE :phoneTerm OR
|
|
|
|
+ c.phone_home ILIKE :phoneTermRaw OR
|
|
|
|
+ c.dob::text ILIKE :phoneTermRaw
|
|
|
|
+ )";
|
|
|
|
+
|
|
|
|
+ $proWhere = "";
|
|
|
|
+ if(!($pro->pro_type === 'ADMIN' || $pro->can_see_any_client_via_search)) {
|
|
|
|
+ $myClientIds = $pro->getMyClientIds(true);
|
|
|
|
+ $myClientIds = implode(',', $myClientIds);
|
|
|
|
+ if($pro->pro_type === 'ADMIN' || $pro->is_enrolled_as_mcp) {
|
|
|
|
+ $proWhere = "AND (c.mcp_pro_id IS NULL OR c.id IN ($myClientIds))";
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $proWhere = "AND c.id IN ($myClientIds)";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $sql = "
|
|
|
|
+ SELECT $columns FROM client c
|
|
|
|
+ WHERE c.shadow_pro_id IS NULL
|
|
|
|
+ AND c.duplicate_of_client_id IS NULL
|
|
|
|
+ $termWhere
|
|
|
|
+ $proWhere
|
|
|
|
+ ";
|
|
|
|
|
|
|
|
+ /*
|
|
//Don't show duplicates
|
|
//Don't show duplicates
|
|
$clientQuery = $clientQuery->whereNull('duplicate_of_client_id');
|
|
$clientQuery = $clientQuery->whereNull('duplicate_of_client_id');
|
|
|
|
|
|
@@ -1732,6 +1771,18 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
|
|
}
|
|
}
|
|
|
|
|
|
$clients = $clientQuery->get();
|
|
$clients = $clientQuery->get();
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ $params = [
|
|
|
|
+ 'term' => '%' . $term . '%',
|
|
|
|
+ 'phoneTerm' => '%' . $phoneTerm . '%',
|
|
|
|
+ 'phoneTermRaw' => '%' . $originalTerm . '%',
|
|
|
|
+ ];
|
|
|
|
+ if(!empty($term2)) {
|
|
|
|
+ $params['term2'] = '%' . $term2 . '%';
|
|
|
|
+ }
|
|
|
|
+ $clients = DB::select($sql, $params);
|
|
|
|
+
|
|
return view('app/patient-suggest', compact('clients'));
|
|
return view('app/patient-suggest', compact('clients'));
|
|
}
|
|
}
|
|
|
|
|