Browse Source

Multisearch pro on HCP note activity

Samson Mutunga 3 years ago
parent
commit
6b4c137748

+ 7 - 3
app/Http/Controllers/PracticeManagementController.php

@@ -805,8 +805,6 @@ class PracticeManagementController extends Controller
 
         $filters = $request->all();
 
-        $name = $request->get('name');
-        $wildCardedName = '%'.$name.'%';
         $from_date = $request->get('from_date');
         if(!$from_date) {
             $from_date = '2010-01-01';
@@ -831,7 +829,13 @@ class PracticeManagementController extends Controller
             (SELECT note.created_at FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false ORDER BY note.created_at DESC LIMIT 1) as last_note_created_at,
             (SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at >= '${startOfCurrentMonth}'::DATE AND created_at <= '${endOfCurrentMonth}'::DATE ) AS notes_this_month,
             (SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at >= '${from_date}'::DATE AND created_at <= '${to_date}'::DATE  ) AS notes_this_period");
-        $rows = $rows->where('name_first', 'ilike', $wildCardedName)->orWhere('name_last', 'ilike', $wildCardedName);
+
+        $prosIDs = $request->get('pros_ids');
+        if($prosIDs){
+            $pros = 
+            $rows = $rows->whereIn('pro.id', $prosIDs);
+        }
+
         $rows = $rows->orderBy('name_first');
         $rows = $rows->paginate(50);
 

+ 42 - 7
resources/views/app/practice-management/hcp-note-activity.blade.php

@@ -1,7 +1,8 @@
 @extends ('layouts/template')
 
 @section('content')
-
+<link href="/select2/select2.min.css" rel="stylesheet" />
+<script src="/select2/select2.min.js"></script>
 <style>
     #hcp-note-activity-filters label {
         font-weight: bold;
@@ -42,11 +43,17 @@
         <div class="card-body p-0 border-0 table-responsive">
             <div class="m-2">
             
-            <form id="hcp-note-activity-filters" method="GET" action="{{ route('practice-management.hcp-note-activity') }}" class="filter-container" v-cloak>
-                <div class="sm-section">
+            <form id="hcp-note-activity-filters" method="GET" action="{{ route('practice-management.hcp-note-activity') }}" class="filter-container" v-cloak>                
+                <div class="sm-section" style="width: 250px !important;">
                     <div class="form-group">
-                        <label>Name:</label>
-                        <input name="name" class="form-control input-sm" v-model="filters.name">
+                        <label>Pros:</label>
+                        <select multiple name="pros_ids[]" class="form-control input-sm" v-model="filters.pros_ids">
+                            @if(@$filters['pros_ids'])
+                                @foreach($rows as $p)
+                                    <option value="{{ $p->id }}" selected>{{$p->name_first}} {{$p->name_last}}</option>
+                                @endforeach
+                            @endif
+                        </select>
                     </div>
                 </div>
                
@@ -111,7 +118,7 @@
 <?php
 $loadedFilters = $filters;
 $allFilterKeys = [
-	'name',
+	'pros_ids',
 	'from_date',
 	'to_date'
 ];
@@ -131,8 +138,36 @@ for ($i = 0; $i < count($allFilterKeys); $i++) {
 					filters: <?= json_encode($loadedFilters) ?>
 				},
 				methods: {
+                    initSelect2: function(){
+                        var select2 = $("select[multiple]").select2({
+                            minimumInputLength: 2,
+                            ajax: {
+                                url: '/pro-suggest',
+                                dataType: 'json',
+                                type: "GET",
+                                quietMillis: 50,
+                                data: function (params) {
+                                    return {
+                                        term: params.term,
+                                        json: true
+                                    };
+                                },
+                                results: function (data) {
+                                    return {
+                                        results: $.map(data, function (item) {
+                                            return {
+                                                text: item.completeName,
+                                                slug: item.slug,
+                                                id: item.id
+                                            }
+                                        })
+                                    };
+                                }
+                            }
+                        });
+                    },
 					init: function() {
-
+                        this.initSelect2();
 					},
 					doSubmit: function() {
 						fastLoad('{{ route("practice-management.hcp-note-activity") }}?' + $('#hcp-note-activity-filters').serialize());