From 289331fb1e3db8f3af5511a58d523a19230d20a0 Mon Sep 17 00:00:00 2001 From: Kevin Lanyo Date: Wed, 14 Aug 2024 15:47:10 +0300 Subject: [PATCH] Feat: facility directory search feedback --- app/Http/Controllers/DirectoryController.php | 27 ++ app/Http/Controllers/FacilityController.php | 42 +++ .../Controllers/NewDashboardController.php | 25 +- app/View/Components/Rating.php | 71 +++++ resources/views/components/rating.blade.php | 13 + resources/views/directory/search.blade.php | 216 +++++++++++++- .../facilities/facility_contact.blade.php | 272 ++++++++++++++++++ routes/web.php | 4 + 8 files changed, 663 insertions(+), 7 deletions(-) create mode 100644 app/View/Components/Rating.php create mode 100644 resources/views/components/rating.blade.php create mode 100644 resources/views/facilities/facility_contact.blade.php diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php index b1a2390..e684f39 100644 --- a/app/Http/Controllers/DirectoryController.php +++ b/app/Http/Controllers/DirectoryController.php @@ -39,4 +39,31 @@ public function directoryLog(Request $request) return response()->json(['status' => 'success']); } + + public function directoryRating(Request $request) + { + $mflcode = $request['FacilityCode']; + $rating = $request['Rating']; + $comment = $request['Comment']; + + //send this rating value to the facility directory + try { + $apiUrl = env('ART_URL')."facility/directory/rating"; + + $httpresponse = Http:: + withoutVerifying() + ->post("$apiUrl", [ + 'mflcode' => $mflcode, + 'rating' => $rating, + 'comment' => $comment, + ]); + + $body = json_decode($httpresponse->getBody(), true); + // return response()->json(['body'=>$body]); + } catch (\Exception $e) { + return response()->json(['status' => 'fail','error'=>$e]); + } + + return response()->json(['status' => 'success','mfl_code'=>$mflcode,'rating'=>$rating,'comment'=>$comment]); + } } diff --git a/app/Http/Controllers/FacilityController.php b/app/Http/Controllers/FacilityController.php index 46b9832..5e3e564 100644 --- a/app/Http/Controllers/FacilityController.php +++ b/app/Http/Controllers/FacilityController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Http; use App\Models\Facility; use App\Models\County; use App\Models\Partner; @@ -368,4 +369,45 @@ public function edit_facility(Request $request) return back(); } } + + public function update_contact(Request $request) + { + $validated = $request->validate([ + 'ccc_phone' => ['required', "regex:/^[0-9][0-9]{9,14}$/", 'max:12'], + 'pmtct_phone' => ['required', "regex:/^[0-9][0-9]{9,14}$/", 'max:12'], + ]); + + //get the facility details + $mflcode = $request->mflcode; + // $partner_name = $request->partner_name; + $ccc_phone = $request->ccc_phone; + $pmtct_phone = $request->pmtct_phone; + + //update the facility contact on ART directory + $apiUrl = env('ART_URL')."facility/directory/edit"; + $httpresponse = Http:: + withoutVerifying() + ->post("$apiUrl", [ + 'mflcode' => $mflcode, + 'ccc_phone' => $ccc_phone, + 'pmtct_phone' => $pmtct_phone, + ]); + + $body = json_decode( $httpresponse->getBody(), true); + + if (is_array($body) && array_key_exists('status', $body)) { + if ($body['status']) { + Alert::success('Success', 'Facility updated successfully!'); + return redirect('/admin/dashboard'); + } else { + Alert::error('Failed', 'An error has occurred please try again later.'); + return back(); + } + }else{ + Alert::error('Failed', 'An error has occurred please try again later.'); + return back(); + } + + + } } diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 08f5836..bd715f8 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Http\Request; - +use Illuminate\Support\Facades\Http; use App\Models\Client; use App\Models\Appointments; @@ -98,6 +98,29 @@ public function dashboard() // showing all the active clients, all appointments, missed appointments if (Auth::user()->access_level == 'Facility') { + + try { + //check if the facility has maintained a contact in the facility directory + $apiUrl = env('ART_URL')."facility/directory"; + + $httpresponse = Http:: + withoutVerifying() + ->get("$apiUrl", [ + 'code' => Auth::user()->facility_id, + ]); + + $body = json_decode($httpresponse->getBody(), true); + + if($body['message'] !== []) + { + $mflcode = Auth::user()->facility_id; + return view('facilities.facility_contact')->with('mflcode',$mflcode); + } + } catch (\Exception $e) { + // dd($e); + } + + $all_partners = Partner::where('status', '=', 'Active') ->remember($this->remember_period) ->pluck('name', 'id'); diff --git a/app/View/Components/Rating.php b/app/View/Components/Rating.php new file mode 100644 index 0000000..0a6ec84 --- /dev/null +++ b/app/View/Components/Rating.php @@ -0,0 +1,71 @@ +mflCode = $mflCode; + $this->searchRating = $searchRating; + $this->searchCounter = $searchRating > 0 ? $searchRating : 5; + // dd($mflCode); + } + + public function isSelected($option) + { + return $option == $this->searchRating; + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\Contracts\View\View|\Closure|string + */ + public function render() + { + return view('components.rating'); + } +} diff --git a/resources/views/components/rating.blade.php b/resources/views/components/rating.blade.php new file mode 100644 index 0000000..855cf7f --- /dev/null +++ b/resources/views/components/rating.blade.php @@ -0,0 +1,13 @@ +
+
+
+ + +
+ @for($i=1; $i<=$searchCounter; $i++) + + @endfor +
+
+
+
diff --git a/resources/views/directory/search.blade.php b/resources/views/directory/search.blade.php index 6fb6773..010f8a8 100644 --- a/resources/views/directory/search.blade.php +++ b/resources/views/directory/search.blade.php @@ -33,6 +33,97 @@ max-height: 50px; } + + - \ No newline at end of file + diff --git a/resources/views/facilities/facility_contact.blade.php b/resources/views/facilities/facility_contact.blade.php new file mode 100644 index 0000000..e98b044 --- /dev/null +++ b/resources/views/facilities/facility_contact.blade.php @@ -0,0 +1,272 @@ +@extends('layouts.master') +@section('before-css') + + +@endsection + +@section('main-content') +@include('sweetalert::alert') + +
+
+
+
+
Capture facility contacts
+
+ {{ csrf_field() }} +
+
+ +
+ +
+ + +
+
+
+
+ +
+ +
+ +
+
+
+
+   +
+
+ +
+
+
+
+
+
+
+ +@if ($errors->any()) +
+ +
+@endif + +@endsection +@section('page-js') + + + + +@endsection diff --git a/routes/web.php b/routes/web.php index e9825b2..78030b2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -75,6 +75,9 @@ // facility directory Route::post('/directory_log', ['uses' => 'App\Http\Controllers\DirectoryController@directoryLog', 'as' => 'directory_log']); + // facility directory rating + Route::post('/directory/rating', ['uses' => 'App\Http\Controllers\DirectoryController@directoryRating', 'as' => 'directory.rating']); + Route::post('/tet', ['uses' => 'App\Http\Controllers\NishauriController@tet', 'as' => 'tet']); Auth::routes(); @@ -145,6 +148,7 @@ Route::post('/approve_facility', ['uses' => 'App\Http\Controllers\FacilityController@approve_facility', 'as' => 'approve-facility']); Route::post('/add_facility', ['uses' => 'App\Http\Controllers\FacilityController@add_facility', 'as' => 'add_facility']); Route::post('/edit_facility', ['uses' => 'App\Http\Controllers\FacilityController@edit_facility', 'as' => 'edit_facility']); + Route::post('/facility/contact', ['uses' => 'App\Http\Controllers\FacilityController@update_contact', 'as' => 'facility-contact']); // Partner routes Route::get('/Reports/il/partners', ['uses' => 'App\Http\Controllers\ILUushauriController@partners_il', 'as' => 'Reports-il-partners']);