Skip to content

Commit

Permalink
Merge pull request #24 from palladiumkenya/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
Murithijoshua authored Apr 2, 2024
2 parents 2b84568 + a46958e commit 7a94bff
Show file tree
Hide file tree
Showing 10 changed files with 645 additions and 6 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use App\Models\DirectoryLog;

class DirectoryController extends Controller
{
Expand All @@ -25,4 +26,17 @@ public function directory(Request $request, $facility)
return response()->json(['error' => 'API request failed'], $response->status());
}
}
public function directoryLog(Request $request)
{
$searchTerm = $request->input('search_term');
$resultCount = $request->input('result_count');

// Save the log
DirectoryLog::create([
'search_term' => $searchTerm,
'result_count' => $resultCount,
]);

return response()->json(['status' => 'success']);
}
}
82 changes: 82 additions & 0 deletions app/Http/Controllers/NishauriController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Illuminate\Support\Facades\Auth;
use DB;
use Carbon\Carbon;
use App\Models\NishauriDrugDelivery;
use App\Models\NishauriDrugOrder;


class NishauriController extends Controller
Expand Down Expand Up @@ -843,4 +845,84 @@ public function filter_nishauri_uptake(Request $request)
return $data;
}
}

public function drug_delivery_list()
{
if (Auth::user()->access_level == 'Facility') {

$drug_delivery = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id')
->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id')
->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier')
->where('tbl_client.mfl_code', Auth::user()->facility_id)
->where('tbl_nishauri_drug_order.status', '=', 'Pending')
->get();
$drug_dispatch = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id')
->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id')
->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier')
->where('tbl_client.mfl_code', Auth::user()->facility_id)
->where('tbl_nishauri_drug_order.status', '=', 'Approved')
->get();

$drug_fullfilled = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id')
->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id')
->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier')
->where('tbl_client.mfl_code', Auth::user()->facility_id)
->where('tbl_nishauri_drug_order.status', '=', 'Fullfilled')
->get();

return view('nishauri.drug_delivery', compact('drug_delivery', 'drug_dispatch', 'drug_fullfilled'));
}
}

public function delivery_approval(Request $request)
{
try {
$client = NishauriDrugDelivery::where('appointment_id', $request->appointment_id)
->update([
'status' => 'Approved',
'updated_at' => date('Y-m-d H:i:s')
]);

// dd( $client);
if ($client) {
NishauriDrugOrder::create([
'order_id' => $request->order_id,
'initiated_by' => Auth::user()->id,
]);
Alert::success('Success', 'Delivery Successfully Approved');
return redirect('delivery/list');
} else {
Alert::error('Failed', 'Could not approve please try again later.');
return back();
}
} catch (Exception $e) {
}
}

public function delivery_dispatch(Request $request)
{
try {
$client = NishauriDrugDelivery::where('appointment_id', $request->appointment_id)
->update([
'status' => 'Dispatched',
'updated_at' => date('Y-m-d H:i:s')
]);

// dd( $client);
if ($client) {
NishauriDrugOrder::where('order_id', $request->order_id)
->update([
'initiated_by' => Auth::user()->id,
'dispatch_notes' => $request->dispatch_notes,
'updated_at' => date('Y-m-d H:i:s')
]);
Alert::success('Success', 'Delivery Successfully Dispatched');
return redirect('delivery/list');
} else {
Alert::error('Failed', 'Could not dispatch please try again later.');
return back();
}
} catch (Exception $e) {
}
}
}
17 changes: 17 additions & 0 deletions app/Models/DirectoryLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class DirectoryLog extends Model
{
use HasFactory;

public $table = 'tbl_directory_search_logs';
public $timestamps = true;
public $incrementing = false;

protected $fillable = ['search_term', 'result_count'];
}
18 changes: 18 additions & 0 deletions app/Models/NishauriDrugDelivery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class NishauriDrugDelivery extends Model
{
use HasFactory;

public $table = 'tbl_nishauri_drug_order';
public $timestamps = false;
public $incrementing = false;

protected $fillable = [];

}
17 changes: 17 additions & 0 deletions app/Models/NishauriDrugOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class NishauriDrugOrder extends Model
{
use HasFactory;

public $table = 'tbl_nishauri_drug_delivery';
public $timestamps = true;
public $incrementing = false;

protected $fillable = ['order_id', 'initiated_by'];
}
62 changes: 59 additions & 3 deletions resources/views/directory/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" type="image/jpeg" sizes="16x16" href="{{ asset('assets/images/ushauri.jpeg') }}">
Expand Down Expand Up @@ -30,9 +31,14 @@
.logo {
max-height: 50px;
/* Set the max height of your logo */
}
</style>
<script type="text/javascript">
function setMaxLength(input) {
var isDigit = /^\d+$/.test(input.value);
input.maxLength = isDigit ? 5 : 1000;
}
</script>
</head>

<body>
Expand All @@ -57,8 +63,9 @@
<div class="row justify-content-center">
<div class="col-md-6 mb-3">
<label for="searchInput" class="form-label">Search Facility:</label>
<input type="text" class="form-control" id="searchInput" placeholder="Enter Facility Name">
<input type="text" class="form-control" id="searchInput" placeholder="Enter Facility Name or MFL Code" oninput="setMaxLength(this)">
<button class="btn btn-primary mt-2" id="searchButton">Search</button>
<div id="error-message" class="text-danger mt-2" style="display: none;">Invalid MFL Code.</div>
</div>
</div>

Expand All @@ -70,6 +77,7 @@
<th scope="col">Facility Name</th>
<th scope="col">MFL Code</th>
<th scope="col">Contact</th>
<th scope="col">County</th>
<th scope="col">Facility Type</th>
<th scope="col">More</th>
</tr>
Expand Down Expand Up @@ -139,6 +147,9 @@
{
data: 'Contact'
},
{
data: 'County'
},
{
data: 'Facility Type'
},
Expand All @@ -153,13 +164,33 @@
$('#searchButton').on('click', function() {
var facility = $('#searchInput').val();
if (!facility.trim()) {
Swal.fire({
icon: 'warning',
title: 'Empty Search',
text: 'Please Enter Facility Name or MFL Code.',
});
return;
}
Swal.fire({
title: "loading results......",
showConfirmButton: false,
allowOutsideClick: false
});
var apiUrl = "{{ env('ART_URL') }}directory/" + mfl + '/' + facility;
// var apiUrl = "{{ env('ART_URL') }}directory/" + mfl + '/' + facility;
var isCode = /^\d{5}$/.test(facility);
var apiUrl;
if (isCode) {
apiUrl = "{{ env('ART_URL') }}facility/directory?code=" + facility;
} else {
apiUrl = "{{ env('ART_URL') }}facility/directory?name=" + facility;
}
// Hide error message
$('#error-message').hide();
$.ajax({
url: apiUrl,
method: 'GET',
Expand All @@ -180,6 +211,7 @@
'Facility Name': facility.name,
'MFL Code': facility.code,
'Contact': facility.telephone,
'County': facility.county,
'Facility Type': facility.facility_type,
'More': moreLink
});
Expand All @@ -193,6 +225,7 @@
// Show the result table section
$('#resultTableSection').show();
saveSearchLog(facility, facilities.length);
},
error: function(error) {
console.log(error);
Expand All @@ -204,6 +237,29 @@
}
});
});
function saveSearchLog(searchTerm, resultCount) {
// search log
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: "{{ route('directory_log') }}",
method: 'POST',
data: {
search_term: searchTerm,
result_count: resultCount
},
success: function(response) {
// console.log(response);
},
error: function(error) {
console.log(error);
}
});
}
});
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/landing/page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
</a>
</div>
<div class="col-md-4 mb-4">
<a href="{{ url('directory') }}" class="card">
<img src="{{ asset('assets/images/login/moh.png') }}" class="pl-3" alt="ART Directory Logo" height="90">
<a href="{{ url('directory') }}" class="card" style="align-items:center">
<img src="{{ asset('assets/images/login/moh.png') }}" class="pl-3" alt="ART Directory Logo" height="90" width="200">
<div class="card-body text-center">
<h5 class="card-title">Facility Directory</h5>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@
@if (env('INSTANCE') === 'UshauriPublic')
@if (Auth::user()->access_level == 'Facility')
<!-- Full screen toggle -->
<div class="reschedule-nishauri" style="position: relative;">
<div class="reschedule-nishauri" style="position: relative; margin-right: 15px;">
<span id="reschedule" class="badge rounded-pill badge-notification bg-danger" style="position: absolute; top: -10px; right: -10px; color: white;" title="Appointment Reschedule Requests"></span>
<a href="{{route('reschedule_list')}}"><i class="fas fa-envelope fa-2x"></i></a>
</div>

<div class="reschedule-nishauri" style="position: relative;">
<span id="reschedule" class="badge rounded-pill badge-notification bg-danger" style="position: absolute; top: -10px; right: -10px; color: white;" title="Drug Delivery Requests"></span>
<a href="{{route('drug_delivery_list')}}"><i class="fas fa-prescription-bottle-alt fa-2x"></i></a>
</div>

@endif
@endif

Expand Down
Loading

0 comments on commit 7a94bff

Please sign in to comment.