فهرست منبع

Fix patient search (top right) issue

Vijayakrishnan 3 سال پیش
والد
کامیت
fdc24c15b7
2فایلهای تغییر یافته به همراه29 افزوده شده و 14 حذف شده
  1. 18 0
      app/Http/Controllers/HomeController.php
  2. 11 14
      resources/views/layouts/template.blade.php

+ 18 - 0
app/Http/Controllers/HomeController.php

@@ -770,6 +770,15 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
         $pro = $this->pro;
         $term = $request->input('term') ? trim($request->input('term')) : '';
         if (empty($term)) return '';
+
+        // if multiple words in query, check for all (max 2)
+        $term2 = '';
+        if(strpos($term, ' ') !== FALSE) {
+            $terms = explode(' ', $term);
+            $term = trim($terms[0]);
+            $term2 = trim($terms[1]);
+        }
+
         $clientQuery= Client::whereNull('shadow_pro_id')
             ->where(function ($q) use ($term) {
                 $q->where('name_first', 'ILIKE', '%' . $term . '%')
@@ -778,6 +787,15 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
                     ->orWhere('phone_home', 'ILIKE', '%' . $term . '%');
             });
 
+        if(!empty($term2)) {
+            $clientQuery = $clientQuery->where(function ($q) use ($term2) {
+                $q->where('name_first', 'ILIKE', '%' . $term2 . '%')
+                    ->orWhere('name_last', 'ILIKE', '%' . $term2 . '%')
+                    ->orWhere('cell_number', 'ILIKE', '%' . $term2 . '%')
+                    ->orWhere('phone_home', 'ILIKE', '%' . $term2 . '%');
+            });
+        }
+
         if(!($pro->pro_type === 'ADMIN' && $pro->can_see_any_client_via_search)) {
             $clientQuery->where(function ($q) use ($pro) {
                 $q->whereIn('id', $pro->getMyClientIds(true))

+ 11 - 14
resources/views/layouts/template.blade.php

@@ -251,11 +251,16 @@
             var lastTerm = '';
             var returnedFunction = debounce(function() {
                 var term = $.trim($('#patient-search').val());
-                if (!!term && lastTerm !== term) {
-                    $.get('/patients-suggest?term=' + term, function(_data) {
-                        $('.patient-search-results.suggestions-outer').html(_data).removeClass('d-none');
-                    });
-                    lastTerm = term;
+                if (!!term) {
+                    if(lastTerm !== term) {
+                        $('.patient-search-results.suggestions-outer')
+                            .html('<span class="d-block no-suggest-items">Searching...</span>')
+                            .removeClass('d-none');
+                        $.get('/patients-suggest?term=' + term, function(_data) {
+                            $('.patient-search-results.suggestions-outer').html(_data).removeClass('d-none');
+                        });
+                        lastTerm = term;
+                    }
                 } else {
                     $('.patient-search-results.suggestions-outer').addClass('d-none');
                 }
@@ -309,15 +314,7 @@
                 });
 
             function onQueryChange() {
-                var term = $.trim($('#patient-search').val());
-                if (!!term) {
-                    $('.patient-search-results.suggestions-outer')
-                        .html('<span class="d-block no-suggest-items">Searching...</span>')
-                        .removeClass('d-none');
-                    returnedFunction();
-                } else {
-                    $('.patient-search-results.suggestions-outer').addClass('d-none');
-                }
+                returnedFunction();
             }
             $(document).on('mousedown', '.suggest-item.patient-suggest[data-target-uid]', function() {
                 $('#patient-search').val('');