Browse Source

HCP Note Activity UI & logic updates

Vijayakrishnan 3 years ago
parent
commit
a60834e25c

+ 1 - 0
app/Helpers/helpers.php

@@ -81,6 +81,7 @@ if(!function_exists('queryLineExcept')) {
         $final = [];
         foreach ($params as $k => $v) {
             if(in_array($k, $except) === FALSE) {
+                if(is_array($v)) $v = implode(',', $v);
                 $final[] = "$k=" . urlencode($v);
             }
         }

+ 13 - 9
app/Http/Controllers/PracticeManagementController.php

@@ -806,13 +806,13 @@ class PracticeManagementController extends Controller
         $filters = $request->all();
 
         $from_date = $request->get('from_date');
-        if(!$from_date) {
-            $from_date = '2010-01-01';
-        }
+//        if(!$from_date) {
+//            $from_date = '2010-01-01';
+//        }
         $to_date = $request->get('to_date');
-        if(!$to_date){
-            $to_date = '2900-12-31';
-        }
+//        if(!$to_date){
+//            $to_date = '2900-12-31';
+//        }
         
 
         //TODO sanitize inputs
@@ -829,8 +829,8 @@ class PracticeManagementController extends Controller
         ->selectRaw(" *,
             (SELECT id FROM note WHERE note.hcp_pro_id = pro.id AND is_cancelled = false ORDER BY created_at DESC LIMIT 1) as last_note_id, 
             (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::DATE >= '${startOfCurrentMonth}'::DATE AND created_at::DATE <= '${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");
+            (SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at::DATE >= '${startOfCurrentMonth}'::DATE AND created_at::DATE <= '${endOfCurrentMonth}'::DATE ) AS notes_this_month
+            " . (!!$from_date && !!$to_date ? ",(SELECT COUNT(*) FROM note WHERE note.hcp_pro_id = pro.id AND note.is_cancelled = false AND created_at::DATE >= '${from_date}'::DATE AND created_at::DATE <= '${to_date}'::DATE  ) AS notes_this_period" : ""));
 
         $prosIDs = $request->get('pros_ids');
         if($prosIDs){
@@ -838,7 +838,11 @@ class PracticeManagementController extends Controller
             $rows = $rows->whereIn('pro.id', $prosIDs);
         }
 
-        $rows = $rows->orderBy('name_first');
+        $sortBy = $request->input('sort_by') ?: 'name_first';
+        $sortDir = $request->input('sort_dir') ?: 'ASC';
+
+        $rows = $rows->orderByRaw("$sortBy $sortDir NULLS LAST");
+
         $rows = $rows->paginate(50);
 
 

+ 9 - 0
resources/views/app/practice-management/_sort_header.blade.php

@@ -0,0 +1,9 @@
+<b class="{{request()->input('sort_by') === $key ? 'text-primary' : 'text-secondary'}}">{{$label}}</b>
+<span class="ml-2 d-inline-flex align-items-baseline">
+    <a href="{{ route("practice-management.hcp-note-activity") }}?{{queryLineExcept(['sort_by', 'sort_dir'])}}&sort_by={{$key}}&sort_dir=DESC" class="ml-1">
+        <i class="fa fa-arrow-up {{request()->input('sort_by') === $key && request()->input('sort_dir') === 'DESC' ? '' : 'on-hover-opaque text-secondary'}}"></i>
+    </a>
+    <a href="{{ route("practice-management.hcp-note-activity") }}?{{queryLineExcept(['sort_by', 'sort_dir'])}}&sort_by={{$key}}&sort_dir=ASC" class="ml-1">
+        <i class="fa fa-arrow-down {{request()->input('sort_by') === $key && request()->input('sort_dir') === 'ASC' ? '' : 'on-hover-opaque text-secondary'}}"></i>
+    </a>
+</span>

+ 56 - 89
resources/views/app/practice-management/hcp-note-activity.blade.php

@@ -34,20 +34,20 @@
 <div id="hcp-note-activity" class="p-3 mcp-theme-1">
     <div class="card">
 
-        <div class="card-header px-2 py-1 d-flex align-items-center">
+        <div class="card-header p-2 d-flex align-items-center">
             <strong class="mr-4">
                 <i class="fas fa-user"></i>
                 HCP Note Activity
             </strong>
         </div>
         <div class="card-body p-0 border-0 table-responsive">
-            <div class="m-2">
+            <div class="p-3">
             
-            <form id="hcp-note-activity-filters" method="GET" action="{{ route('practice-management.hcp-note-activity') }}" class="filter-container" v-cloak>                
+            <form id="hcp-note-activity-filters" method="GET" action="{{ route('practice-management.hcp-note-activity') }}" class="filter-container">
                 <div class="sm-section" style="width: 250px !important;">
-                    <div class="form-group">
-                        <label>Pros:</label>
-                        <select id="searchForProInput" multiple name="pros_ids[]" class="form-control input-sm" v-model="filters.pros_ids">
+                    <div class="">
+                        <label class="mb-1 text-secondary">Pros:</label>
+                        <select id="searchForProInput" multiple name="pros_ids[]" class="form-control input-sm">
                             @if(@$filters['pros_ids'])
                                 @foreach($rows as $p)
                                     <option value="{{ $p->id }}" selected>{{$p->name_first}} {{$p->name_last}}</option>
@@ -58,25 +58,25 @@
                 </div>
                
                 <div class="sm-section">
-                    <div class="form-group">
-                        <label>From Date:</label>
-                        <input type="date" name="from_date" class="form-control input-sm" v-model="filters.from_date">
+                    <div class="">
+                        <label class="mb-1 text-secondary">From Date:</label>
+                        <input type="date" name="from_date" class="form-control input-sm" value="{{request()->input('from_date')}}">
                     </div>
                 </div>
 
                 <div class="sm-section">
-                    <div class="form-group">
-                        <label>To Date:</label>
-                        <input type="date" name="to_date" class="form-control input-sm" v-model="filters.to_date">
+                    <div class="">
+                        <label class="mb-1 text-secondary">To Date:</label>
+                        <input type="date" name="to_date" class="form-control input-sm" value="{{request()->input('to_date')}}">
                     </div>
                 </div>
 
                 <div>
-                    <div class="form-group">
+                    <div class="">
                         <label>&nbsp;</label>
                         <div class=" d-flex">
-                            <button type="button" v-on:click.prevent="doSubmit()" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
-                            <a href="#" v-on:click.prevent="fastLoad('{{route('practice-management.hcp-note-activity')}}')" class="btn btn-link btn-sm text-danger">Clear Filters</a>
+                            <button type="button" onclick="return fastLoad('{{ route("practice-management.hcp-note-activity") }}?' + $('#hcp-note-activity-filters').serialize());" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
+                            <a href="#" onclick="return fastLoad('{{ route("practice-management.hcp-note-activity") }}');" class="btn btn-link btn-sm text-danger">Clear Filters</a>
                         </div>
                     </div>
                 </div>
@@ -85,11 +85,13 @@
             <table class="table table-sm table-striped border-0 p-0 m-0 text-nowrap">
                 <thead class="bg-light">
                     <tr>
-                        <th>First Name</th>
-                        <th>Last Name</th>
-                        <th>Last Note Created At</th>
-                        <th># Notes This Month</th>
-                        <th># Notes In the Period</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => 'First Name', 'key' => 'name_first'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => 'Last Name', 'key' => 'name_last'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => 'Last Note Created At', 'key' => 'last_note_created_at'])</th>
+                        <th>@include('app.practice-management._sort_header', ['label' => '# Notes This Month', 'key' => 'notes_this_month'])</th>
+                        @if(request()->input('from_date') && request()->input('from_date'))
+                            <th>@include('app.practice-management._sort_header', ['label' => '# Notes In the Period', 'key' => 'notes_this_period'])</th>
+                        @endif
                     </tr>
                 </thead>
                 <tbody>
@@ -101,7 +103,9 @@
                         <td>{{$row->name_last}}</td>
                         <td>{{friendly_date_time($row->last_note_created_at)}}</td>
                         <td>{{$row->notes_this_month}}</td>
-                        <td>{{$row->notes_this_period}}</td>
+                        @if(request()->input('from_date') && request()->input('from_date'))
+                            <td>{{$row->notes_this_period}}</td>
+                        @endif
                     </tr>
                     @endforeach
                 </tbody>
@@ -115,75 +119,38 @@
 
 </div>
 
-<?php
-$loadedFilters = $filters;
-$allFilterKeys = [
-	'pros_ids',
-	'from_date',
-	'to_date'
-];
-for ($i = 0; $i < count($allFilterKeys); $i++) {
-	if (!isset($loadedFilters[$allFilterKeys[$i]]) || !$loadedFilters[$allFilterKeys[$i]]) {
-		$loadedFilters[$allFilterKeys[$i]] = '';
-	}
-}
-?>
 <script>
-	(function() {
-		function init() {
-			new Vue({
-				el: '#hcp-note-activity',
-				delimiters: ['@{{', '}}'],
-				data: {
-					filters: <?= json_encode($loadedFilters) ?>
-				},
-				methods: {
-                    initSelect2: function(){
-                        var select2 = $("#searchForProInput").select2({
-                            placeholder: "Search Pro(s) by Name",
-                            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
-                                            }
-                                        })
-                                    };
-                                }
-                            }
-                        });
+    (function() {
+        function init() {
+            var select2 = $("#searchForProInput").select2({
+                placeholder: "Search Pro(s) by Name",
+                minimumInputLength: 2,
+                ajax: {
+                    url: '/pro-suggest',
+                    dataType: 'json',
+                    type: "GET",
+                    quietMillis: 50,
+                    data: function (params) {
+                        return {
+                            term: params.term,
+                            json: true
+                        };
                     },
-					init: function() {
-                        this.initSelect2();
-					},
-					doSubmit: function() {
-						fastLoad('{{ route("practice-management.hcp-note-activity") }}?' + $('#hcp-note-activity-filters').serialize());
-						return false;
-					}
-				},
-				mounted: function() {
-					console.log(this.filters);
-					this.init();
-				},
-			});
-
-
-		}
-		addMCInitializer('hcp-note-activity', init, '#hcp-note-activity');
-	})();
+                    results: function (data) {
+                        return {
+                            results: $.map(data, function (item) {
+                                return {
+                                    text: item.completeName,
+                                    slug: item.slug,
+                                    id: item.id
+                                }
+                            })
+                        };
+                    }
+                }
+            });
+        }
+        addMCInitializer('hcp-note-activity', init, '#hcp-note-activity');
+    }).call(window);
 </script>
 @endsection