resolved conflicts

This commit is contained in:
2025-03-31 03:46:05 +03:00
6454 changed files with 1520539 additions and 9 deletions
@@ -0,0 +1,13 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
@@ -0,0 +1,530 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Http\Request;
use Streamline\Models\Dental;
use Streamline\Models\DentalUsage;
use Streamline\Models\Requisition;
use Illuminate\Support\Facades\Auth;
use Streamline\Models\ChartOfAccount;
use Streamline\Models\HospitalInformation;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\QueryException;
class DentalController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('permission:dental-list', ['only' => ['index']]);
$this->middleware('permission:dental-create', ['only' => ['create', 'store']]);
$this->middleware('permission:dental-edit', ['only' => ['edit', 'update', 'edit_all', 'update_all']]);
$this->middleware('permission:dental-delete', ['only' => ['destroy', 'inactive', 'activate']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$dentals = Dental::orderBy('name', 'asc')->paginate(2000);
return view('investigations::dentals.index', compact('dentals'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ['' => '- select -'] + $payables_accounts;
return view('investigations::dentals.create', compact('cost_of_goods_accounts', 'expense_accounts', 'payables_accounts'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
request()->validate([
'name' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
$dental = new Dental;
$dental->name = $request->name;
$dental->expenses_account_id = $request->expenses_account_id;
$dental->payables_account_id = $request->payables_account_id;
$dental->cost_of_goods_account = $request->cost_of_goods_account;
$dental->created_by = $logged_in_user_id;
$dental->updated_by = $logged_in_user_id;
try {
$dental->save();
flash($request->name . " Dental has been saved")->success();
return redirect("/dentals/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$dental = Dental::where(['id' => $id])->first();
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ['' => '- select -'] + $payables_accounts;
if (!$dental) {
flash()->error("There is no such dental");
return redirect('/dentals/');
} else {
return view('investigations::dentals.edit', compact('dental', 'expense_accounts', 'payables_accounts'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
request()->validate([
'name' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
$dental = Dental::find($id);
$dental->name = $request->name;
$dental->expenses_account_id = $request->expenses_account_id;
$dental->payables_account_id = $request->payables_account_id;
$dental->updated_by = $logged_in_user_id;
try {
$dental->save();
flash($request->name . " dental has been updated")->success();
return redirect("/dentals/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$dental = Dental::find($id);
if ($dental->delete()) {
flash("dental has been deleted.")->success();
return redirect('/dentals/');
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Http\Response
*/
public function inactive()
{
$dentals = Dental::onlyTrashed()
->orderBy('name', 'asc')
->paginate(50);
if (count($dentals) < 1) {
flash()->error("There is no inactive dental item");
return redirect('/dentals/');
} else {
return view('investigations::dentals.inactive', compact('dentals'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function activate($id)
{
$dental = Dental::withTrashed()->find($id);
if ($dental->restore()) {
flash("dental has been activated.")->success();
return redirect('/dentals/inactive');
}
}
/**
* Search a resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function search(Request $request)
{
$query_name = $request->query_name;
$query_active = $request->query_active;
if ($query_name != "") {
$dentals = Dental::where([
['active', '=', $query_active],
['name', 'LIKE', '%' . $query_name . '%']
])
->orderBy('name', 'asc')
->paginate(10)
->setPath('');
$dentals->appends(array(
'query_name' => $query_name,
'query_active' => $query_active
));
if (count($dentals)) {
if ($query_active) {
return view('investigations::dentals.index', compact('dentals')) //;
->withDetails($dentals)
->withQuery($query_name, $query_active);
} else {
return view('investigations::dentals.inactive', compact('dentals')) //;
->withDetails($dentals)
->withQuery($query_name, $query_active);
}
}
}
flash()->error("No Details found. Try searching again!");
return redirect('/dentals/');
}
/**
* Display a listing of the active resources for bulk editing.
*
* @return \Illuminate\Http\Response
*/
public function edit_all()
{
$dentals = Dental::orderBy('name', 'asc')->paginate(2000);
if (count($dentals) < 1) {
flash()->error("There is no active dental");
return redirect('/dentals/');
} else {
return view('investigations::dentals.edit.all', compact('dentals'));
}
}
/**
* Update all the resources in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update_all(Request $request)
{
request()->validate([
'name' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
$id_array = $request->id;
$name_array = $request->name;
for ($x = 0; $x < count($id_array); $x++) {
$dental = Dental::find($id_array[$x]);
$dental->name = $name_array[$x];
$dental->updated_by = $logged_in_user_id;
try {
$dental->save();
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
flash("Dentals have been updated")->success();
return redirect("/dentals/");
}
public function get_dentals()
{
//code to be returned to view
$code = "<option> -- select -- </option>";
$dentals = Dental::orderBy('name', 'asc')->get();
foreach ($dentals as $dental) {
$code .= "<option value='" . $dental->id . "'>" . $dental->name . "</option>";
}
return $code;
}
public function dental_usage_report(Request $request)
{
$dentals = Dental::orderBy('name', 'asc')->get();
$hospital_information = HospitalInformation::first();
$dental_options = DB::table('dentals')->orderBy('name', 'asc')->pluck('name', 'id')->prepend('- All Dentals - ', 'all_dentals');
$search_by = $request->search_by;
$reg_date = $request->reg_date;
$start_date = $request->start_date;
$end_date = $request->end_date;
$filters = [];
$search_string = "";
if ($search_by == 0) {
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($filters, ['start_date', '>', $last_day]);
if ($request->dental_id != 'all_dentals') {
array_push($filters, ['dental_id', '=', $request->dental_id]);
}
$search_string = "<h4 class='label label-info'>Showing results of ".streamline_date($last_day)."</h4>";
} elseif ($search_by == 1) {
// custom date
if (is_null($request->reg_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$selected_date_filter = Carbon::createFromFormat('d/m/Y', $request->reg_date)->toDateString();
array_push($filters, ['start_date', $selected_date_filter]);
if ($request->dental_id != 'all_dentals') {
array_push($filters, ['dental_id', '=', $request->dental_id]);
}
$search_string = "<h4 class='label label-info'>Showing results of ".streamline_date($selected_date_filter)."</h4>";
} elseif ($search_by == 2) {
// custom date range
if (is_null($start_date) || is_null($end_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$start_date_search = Carbon::createFromFormat('d/m/Y', $start_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::createFromFormat('d/m/Y', $end_date)->endOfDay()->toDateTimeString();
array_push($filters, ['start_date', '>', $start_date_search]);
array_push($filters, ['end_date', '<', $end_date_search]);
if ($request->dental_id != 'all_dentals') {
array_push($filters, ['dental_id', '=', $request->dental_id]);
}
$search_string = "<h4 class='label label-info'>Showing between ".streamline_date($start_date_search). " and ".streamline_date($end_date_search)."</h4>";
}
$dental_usages = (!empty($search_by) && !empty($end_date) && !empty($start_date) && !empty($reg_date))? DentalUsage::where($filters)->orderBy('id','desc')->limit(500)->get(): DentalUsage::orderBy('id','desc')->limit(500)->get();
return view('investigations::dentals.dental_usage_report', compact('dentals', 'hospital_information', 'dental_usages', 'dental_options', 'search_string'));
}
public function dental_requisitions(Request $request)
{
$results = Dental::orderBy('name','asc')->get();
$names_array = Dental::orderBy('name')->distinct()->pluck('name');
$labs = Dental::orderBy('name')->pluck('name', 'id');
$date_filter = [];
if(isset($request->start_date) && isset($request->end_date)){
if (isset($request->quotation_type)) {
$item_type = $request->quotation_type;
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>', $start_date]);
array_push($date_filter, ['created_at', '<', $end_date]);
}
} else {
$date_from = Carbon::today()->subDays(30)->format('Y-m-d');
$date_to = Carbon::today()->addDays(1)->format('Y-m-d');
array_push($date_filter, ['created_at', '>', $date_from]);
array_push($date_filter, ['created_at', '<', $date_to]);
}
$previous_requisitions_results = DB::table('requisitions')->where('quotation_type_id', '=', 3)->where($date_filter)->orderBy('created_at','desc')->get();
return view('investigations::dentals.dental_requisition', compact('results', 'names_array', 'labs', 'previous_requisitions_results'));
}
public function dental_usage_listing()
{
$dentals = Dental::orderBy('name', 'asc')->get();
$hospital_information = HospitalInformation::first();
$dental_usages = DentalUsage::orderBy('id','desc')->limit(20)->get();
return view('investigations::dentals.dental_usage', compact('dentals', 'hospital_information', 'dental_usages'));
}
public function store_dental_usage(Request $request)
{
$dental_items_array = $request->labItem;
$available_qty_array = $request->availableQty;
$available_qty_unit_cost_array = $request->unitCost;
$usage_qty_array = $request->requiredQty;
$usage_qty_cost_array = $request->totalCost;
if($request->dates == 'today'){
$start = Carbon::now()->startOfDay()->toDateTimeString();
$end = Carbon::now()->endOfDay()->toDateTimeString();
}else{
$start = Carbon::parse($request->start_date)->endOfDay()->toDateTimeString();
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
}
for($i = 0; $i < count($dental_items_array); $i++){
if($dental_items_array[$i]){
$dental_usage = new DentalUsage;
$dental_usage->dental_id = $dental_items_array[$i];
$dental_usage->unit_cost_price = $unit_cost = $available_qty_unit_cost_array[$i];
$dental_usage->available_quantity = $available_qty_array[$i];
$dental_usage->available_quantity_cost = ((int)$unit_cost * $available_qty_array[$i]);
$dental_usage->usage_quantity = $usage_qty_array[$i];
$dental_usage->usage_quantity_cost = $usage_qty_cost_array[$i];
$dental_usage->remaining_quantity = $remaining_qty = ((int)$available_qty_array[$i] - (int)$usage_qty_array[$i]);
$dental_usage->remaining_quantity_cost = ($remaining_qty * $unit_cost);
$dental_usage->created_by = Auth::id();
$dental_usage->start_date = $start;
$dental_usage->end_date = $end;
if(!($remaining_qty < 0)){
$dental = Dental::find($dental_items_array[$i]);
$dental->pharmacy_stock = ($dental->pharmacy_stock - (int)$usage_qty_array[$i]);
$dental_usage->save();
$dental->save();
}else{
flash('Item\'s '.get_name($dental_items_array[$i], 'id', 'name', 'labs').' requested use quantity exceeds what is available.');
}
}
}
flash('Dentals to be used from '.streamline_date($start).' to '.streamline_date($end).' have saved successfully')->success();
return redirect()->route('dentals.usage_listing');
}
public function get_dental_quantity(Request $request){
$dental_item = Dental::where('id', $request->id)->first();
return $dental_item;
}
public function dentals_requisition_search(Request $request)
{
$item_type = $request->item_type;
$item_ids_array = $request->items_ids;
$results = null;
$filters = [];
$items = null;
$results = Dental::whereIn('id', $item_ids_array)->orderBy('name','asc')->get();
$labs = Dental::orderBy('name')->pluck('name', 'id');
$date_filter = [];
if(isset($request->start_date) && isset($request->end_date)){
if (isset($request->quotation_type)) {
$item_type = $request->quotation_type;
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>', $start_date]);
array_push($date_filter, ['created_at', '<', $end_date]);
}
} else {
$date_from = Carbon::today()->subDays(30)->format('Y-m-d');
$date_to = Carbon::today()->addDays(1)->format('Y-m-d');
array_push($date_filter, ['created_at', '>', $date_from]);
array_push($date_filter, ['created_at', '<', $date_to]);
}
$previous_requisitions_results = DB::table('requisitions')->where('quotation_type_id', '=', 5)->where($date_filter)->orderBy('created_at','desc')->get();
return view('investigations::dentals.dental_requisition',compact('items','item_type','labs','results','previous_requisitions_results'));
}
public function store_dental_requisitions(Request $request)
{
$drug_id_array = $request->drug_id;
$quantity_array = $request->quantity;
$item_type = $request->item_type;
$user_id = auth()->user()->id;
/* return back if no quantity has been filled */
if (array_sum($quantity_array) < 1) {
flash('Please insert some values!')->error();
return redirect()->back()->withInput();
}
if (isset($request->complete_request)) {
$filtered_drugs_array = [];
$filtered_quantities_array = [];
$associative_requested_drugs_array = [];
for ($i=0; $i < count($drug_id_array) ; $i++) {
if ($quantity_array[$i] != "") {
$associative_requested_drugs_array[$drug_id_array[$i]] = $quantity_array[$i];
$filtered_drugs_array[] = $drug_id_array[$i];
$filtered_quantities_array[] = $quantity_array[$i];
}
}
$new_requisition = new Requisition;
$new_requisition->quotation_type_id = $item_type;
$new_requisition->drug_id = implode(',', $filtered_drugs_array);
$new_requisition->quantity_requested = implode(',', $filtered_quantities_array);
$new_requisition->created_by = $user_id;
$new_requisition->save();
flash('Requisition number ' . $new_requisition->id . ' made successfully')->success();
return redirect('/dentals');
}
}
}
@@ -0,0 +1,179 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Http\Request;
use Streamline\Models\InvestigationCategory;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\QueryException;
use Streamline\Models\InvestigationSuperCategory;
class InvestigationCategoryController extends Controller {
public function __construct() {
$this->middleware('auth');
$this->middleware('permission:investigations-category-list', ['only' => ['index']]);
$this->middleware('permission:investigations-category-create', ['only' => ['create', 'store']]);
$this->middleware('permission:investigations-category-edit', ['only' => ['edit', 'update']]);
$this->middleware('permission:investigations-category-delete', ['only' => ['destroy', 'inactive', 'activate']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index() {
$investigation_categories = InvestigationCategory::orderBy('name', 'asc')
->paginate(50);
$super_categories = InvestigationSuperCategory::pluck('name', 'id');
return view('investigations::investigation_categories.index', compact('investigation_categories', 'super_categories'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create() {
$super_categories = InvestigationSuperCategory::pluck('name', 'id')->toArray();
$super_categories = ['' => '- select -'] + $super_categories;
return view('investigations::investigation_categories.create', compact('super_categories'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
request()->validate([
'name' => 'required'
]);
//validation passed
$investigation_category = new InvestigationCategory;
$logged_in_user_id = Auth::user()->id;
$investigation_category->name = $request->name;
$investigation_category->super_category_id = $request->super_category_id;
$investigation_category->created_by = $logged_in_user_id;
$investigation_category->updated_by = $logged_in_user_id;
try {
$investigation_category->save();
flash($request->name . " Investigation Category has been saved")->success();
return redirect("/investigation_categories/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function edit($id) {
$investigation_category = InvestigationCategory::where(['id' => $id])->first();
$super_categories = InvestigationSuperCategory::pluck('name', 'id')->toArray();
$super_categories = ['' => '- select -'] + $super_categories;
if (!$investigation_category) {
flash()->error("InvestigationCategory not found");
return redirect('/investigation_categories/');
} else {
return view('investigations::investigation_categories.edit', compact('investigation_category', 'super_categories'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
request()->validate([
'name' => 'required'
]);
//validation passed
$investigation_category = InvestigationCategory::find($id);
$investigation_category->name = $request->name;
$investigation_category->super_category_id = $request->super_category_id;
try {
$investigation_category->save();
flash($request->name . " Investigation Category has been updated")->success();
return redirect("/investigation_categories/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$investigation_category = InvestigationCategory::find($id);
if ($investigation_category->delete()):
flash("InvestigationCategory has been deleted.")->success();
return redirect('/investigation_categories/');
endif;
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Http\Response
*/
public function inactive() {
$investigation_categories = InvestigationCategory::onlyTrashed()
->orderBy('name', 'asc')
->paginate(50);
if (count($investigation_categories) < 1) {
flash()->error("There is no inactive investigation_category");
return redirect('/investigation_categories/');
} else {
return view('investigations::investigation_categories.inactive', compact('investigation_categories'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function activate($id) {
$investigation_category = InvestigationCategory::withTrashed()->find($id);
if ($investigation_category->restore()):
flash("InvestigationCategory has been activated.")->success();
return redirect('/investigation_categories/inactive');
endif;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,506 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Streamline\Models\Investigation;
use Streamline\Models\OrderedInvestigation;
use Streamline\Models\InvestigationResults;
use Streamline\Models\HospitalInformation;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
use Streamline\Models\Patient;
use Streamline\Models\ObstetricUltrasoundReports;
class InvestigationPrintController extends Controller {
public function __construct() {
$this->middleware('auth');
}
public function print_lab_result_details($id) {
$ordered_investigation = OrderedInvestigation::find($id);
$hospital_information = HospitalInformation::find(1);
$investigation_ids = [];
$patient = Patient::find($ordered_investigation->patient_id);
$results = [];
$investigation_results = InvestigationResults::where('order_id', '=', $id)->get();
foreach ($investigation_results as $result) {
$investigations = explode(",", $result->investigation_id);
$values = explode(",", $result->value);
$comments = explode(",", $result->comment);
$per_investigation = explode(",", $result->per_investigation);
$count_two = 0;
foreach ($investigations as $investigation) {
$investigation_ids[] = $investigation;
$results[$count_two]['name'] = get_name($investigation, 'id', 'name', 'investigations');
if(get_name($investigation, 'id', 'range_type', 'investigations') == 1) {
$results[$count_two]['range'] = get_dynamic_normal_range($investigation, get_patient_age_group($patient->id), get_name($patient->id, 'id', 'gender', 'patients'));
} else {
$results[$count_two]['range'] = get_name($investigation, 'id', 'normal_ranges', 'investigations');
}
//$results[$count_two]['range'] = get_name($investigation, 'id', 'normal_ranges', 'investigations');
$results[$count_two]['type'] = get_name($investigation, 'id', 'type', 'investigations');
$results[$count_two]['units'] = get_name($investigation, 'id', 'units', 'investigations');
$results[$count_two]['result'] = isset($values[$count_two]) ? $values[$count_two] : "";
$results[$count_two]['comment'] = isset($comments[$count_two]) ? $comments[$count_two] : "";
$results[$count_two]['authenticated'] = isset($per_investigation[$count_two]) ? $per_investigation[$count_two] : "";
$count_two++;
}
}
$data = [
'ordered_investigation' => $ordered_investigation,
'results' => $results,
'hospitalInfo' => $hospital_information,
'id' => $id,
'patient' => $patient,
'investigation_ids' => $investigation_ids,
];
$print_footer = (!is_null($hospital_information->print_footer)) ? '&nbsp&nbsp&nbsp&nbsp&nbsp<i>' . $hospital_information->print_footer . '</i>' : '';
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-lab-result-details", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>' . $print_footer);
return $pdf->inline('Investigation Details' . date(" d-m-y h:ia") . '.pdf');
}
public function print_historical_results_labs(Request $request) {
$patient_id = $request->patient_id;
$hospital_information = HospitalInformation::first();
//prepare the arrays
$dates = array();
$invs_array = array();
$values = array();
$patients = InvestigationResults::where('patient_id', '=', $patient_id)
->where('result_type', '=', 'Lab')
->where('all_authenticated', '=', 1)
->limit(7)
->get();
foreach ($patients as $patient) {
$dates[] = streamline_date($patient->created_at);
$investigations = explode(",", $patient->investigation_id);
foreach ($investigations as $investigation) {
if (!in_array($investigation, $invs_array)) {
$invs_array[] = $investigation;
}
}
}
//loop through the investigation ids to add values
for ($i = 0; $i < count($invs_array); $i++) {
//count for the returnInvestigations
$count = 0;
foreach ($patients as $patient) {
//get values from csv to array
$investigations = explode(",", $patient->investigation_id);
$return_values = explode(",", $patient->value);
$comments = explode(",", $patient->comment);
//check if current investigation is in array
if (in_array($invs_array[$i], $investigations)) {
//get key of that investigation which exists
$key = array_search($invs_array[$i], $investigations);
if ($patient->result_type == 'Ultrasound_Obstetric') {
//assign real$return_values value
$values[$i][$count] = array($return_values[$key], $patient->order_id, $patient_id, $patient->episode_id);
} elseif (get_name($invs_array[$i], 'id', 'type', 'investigations') == 1) {
// assign real value representing id
$values[$i][$count] = $return_values[$key] ?? "";
} else {
//assign real value
$values[$i][$count] = ($return_values[$key] ?? "") . " - (" . ($comments[$key] ?? "") . ")";
}
} else {
//assign N/A
$values[$i][$count] = "N/A";
}
$count++;
}
}
$patient = Patient::find($patient_id);
$data = [
'patient_id' => $patient_id,
'patient' => $patient,
'dates' => $dates,
'invs_array' => $invs_array,
'values' => $values,
'hospitalInfo' => $hospital_information
];
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-historical-results-labs", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>');
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . 'Historical Results' . date(" d-m-y h:ia") . '.pdf');
}
public function print_historical_results_imaging(Request $request) {
$patient_id = $request->patient_id;
$hospital_information = HospitalInformation::first();
//prepare the arrays
$dates = array();
$invs_array = array();
$values = array();
$patients = InvestigationResults::where('patient_id', '=', $patient_id)
->whereIn('investigation_results.result_type', ['Imaging', 'Ultrasound', 'Ultrasound_Obstetric'])
->where('all_authenticated', '=', 1)
->limit(7)
->get();
foreach ($patients as $patient) {
$dates[] = streamline_date($patient->created_at);
$investigations = explode(",", $patient->investigation_id);
foreach ($investigations as $investigation) {
if (!in_array($investigation, $invs_array)) {
$invs_array[] = $investigation;
}
}
}
//loop through the investigation ids to add values
for ($i = 0; $i < count($invs_array); $i++) {
//count for the returnInvestigations
$count = 0;
foreach ($patients as $patient) {
//get values from csv to array
$investigations = explode(",", $patient->investigation_id);
$return_values = explode(",", $patient->value);
$comments = explode(",", $patient->comment);
//check if current investigation is in array
if (in_array($invs_array[$i], $investigations)) {
//get key of that investigation which exists
$key = array_search($invs_array[$i], $investigations);
if ($patient->result_type == 'Ultrasound_Obstetric') {
//assign real$return_values value
$values[$i][$count] = array($return_values[$key], $patient->order_id, $patient_id, $patient->episode_id);
} elseif (get_name($invs_array[$i], 'id', 'type', 'investigations') == 1) {
// assign real value representing id
$values[$i][$count] = $return_values[$key] ?? "";
} else {
//assign real value
$values[$i][$count] = ($return_values[$key] ?? "") . " - (" . ($comments[$key] ?? "") . ")";
}
} else {
//assign N/A
$values[$i][$count] = "N/A";
}
$count++;
}
}
$patient = Patient::find($patient_id);
$data = [
'patient_id' => $patient_id,
'patient' => $patient,
'dates' => $dates,
'invs_array' => $invs_array,
'values' => $values,
'hospitalInfo' => $hospital_information
];
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-historical-results-labs", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>');
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . 'Historical Results' . date(" d-m-y h:ia") . '.pdf');
}
public function print_patient_investigation_results($result_id) {
$result = InvestigationResults::find($result_id);
$patient_id = $result->patient_id;
$hospital_information = HospitalInformation::first();
$patient = Patient::where(['id' => $patient_id])->first();
$inv = [];
$inv['episode_id'] = $result->episode_id;
$inv['date'] = streamline_date(get_name($result->episode_id, 'id', 'created_at', 'patient_episodes'));
$created_by = is_null($result->updated_by) ? $result->created_by : $result->updated_by;
$investigations = explode(",", $result->investigation_id);
$values = explode(",", $result->value);
$comments = explode(",", $result->comment);
$data = [];
$count = 0;
foreach ($investigations as $investigation) {
$investigation_details = Investigation::find($investigation);
if ($investigation_details) {
$data[$count]['name'] = $investigation_details->name;
$data[$count]['range'] = $investigation_details->normal_ranges;
$data[$count]['slug'] = $investigation_details->slug;
$data[$count]['result'] = $values[$count];
$data[$count]['comment'] = $comments[$count];
$data[$count]['type'] = $investigation_details->type;
$count++;
}
}
$inv['data'] = $data;
$data = [
'inv' => $inv,
'patient' => $patient,
'hospitalInfo' => $hospital_information,
'created_at' => $result->created_at,
'created_by' => $created_by,
'performed_at' => streamline_date_time($result->created_at),
'requested_at' => streamline_date_time(get_name($result->order_id, 'id', 'created_at', 'ordered_investigations'))
];
$pdf = SnappyPDF::loadView("investigations::investigations/print/print_patient_investigation_results", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>');
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . ' Investigation results' . date(" d-m-y h:ia") . '.pdf');
}
public function print_ultrasound_results_obstetric($obstetric_result_id) {
$report = ObstetricUltrasoundReports::where(['id' => $obstetric_result_id])->first();
// for old kisiizi records which use the order_id
if (!$report) {
$report = ObstetricUltrasoundReports::where(['order_id' => $obstetric_result_id])->first();
}
$invs_order = OrderedInvestigation::find($report->order_id);
if ($invs_order) {
$patient_id = $invs_order->patient_id;
$episode_id = $invs_order->episode_id;
$patient = Patient::find($patient_id);
$anc_details = DB::table('ante_natal_clinic_registrations')->where('episode_id', $episode_id)->first();
$data = [
'patient_id' => $patient_id,
'episode_id' => $episode_id,
'patient' => $patient,
'report' => $report,
'anc_details' => $anc_details,
'invs_order' => $invs_order
];
//dompdf
$pdf_obstetric = new DomPDF();
$html = view("investigations::investigations/print/print_ultrasound_results_obstetric", $data)->render();
$pdf_obstetric = DomPDF::loadHtml($html);
$pdf_obstetric->setPaper('A4', 'potrait');
$options = [
'isPhpEnabled' => true,
'isHtml5ParserEnabled' => true,
// Add more options
];
DomPDF::setOptions($options);
return $pdf_obstetric->stream($patient->first_name . ' ' . $patient->last_name . ' ' . 'Ultrasound Obstetric results' . date(" d-m-y h:ia") . '.pdf', array('Attachment' => false));
} else {
flash("Unable to find obstetric results")->error();
return redirect('/home');
}
}
public function print_selective_lab_result_details(Request $request) {
$invs_to_print = $request->invs_to_print;
if (is_null($invs_to_print)) {
flash("Please select investigations to print")->error();
return redirect('/home');
}
$id = $request->id;
$investigation_ids = [];
$ordered_investigation = OrderedInvestigation::find($id);
$hospital_information = HospitalInformation::find(1);
$patient = Patient::find($ordered_investigation->patient_id);
$results = [];
$investigation_results = InvestigationResults::where('order_id', '=', $id)->get();
foreach ($investigation_results as $result) {
$investigations = explode(",", $result->investigation_id);
$values = explode(",", $result->value);
$comments = explode(",", $result->comment);
$per_investigation = explode(",", $result->per_investigation);
$count_two = 0;
foreach ($investigations as $investigation) {
if (in_array($investigation, $invs_to_print)) {
$investigation_ids[] = $investigation;
$results[$count_two]['name'] = get_name($investigation, 'id', 'name', 'investigations');
if(get_name($investigation, 'id', 'range_type', 'investigations') == 1) {
$results[$count_two]['range'] = get_dynamic_normal_range($investigation, get_patient_age_group($patient->id), get_name($patient->id, 'id', 'gender', 'patients'));
} else {
$results[$count_two]['range'] = get_name($investigation, 'id', 'normal_ranges', 'investigations');
}
$results[$count_two]['type'] = get_name($investigation, 'id', 'type', 'investigations');
$results[$count_two]['units'] = get_name($investigation, 'id', 'units', 'investigations');
$results[$count_two]['result'] = $values[$count_two] ?? "";
$results[$count_two]['comment'] = $comments[$count_two] ?? "";
$results[$count_two]['authenticated'] = $per_investigation[$count_two] ?? "";
}
$count_two++;
}
}
$data = [
'ordered_investigation' => $ordered_investigation,
'results' => $results,
'hospitalInfo' => $hospital_information,
'id' => $id,
'patient' => $patient,
'investigation_ids' => count($investigation_ids) > 0 ? $investigation_ids : explode(",", $ordered_investigation->investigation_id),
];
$pdf = SnappyPDF::loadView("investigations::investigations/print/print-lab-result-details", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>');
return $pdf->inline('Investigation Details' . date(" d-m-y h:ia") . '.pdf');
}
public function print_selective_patient_investigation_results(Request $request) {
$invs_to_print = $request->invs_to_print;
if (is_null($invs_to_print)) {
flash("Please select investigations to print")->error();
return redirect('/home');
}
$result_id = $request->result_id;
$result = InvestigationResults::find($result_id);
$patient_id = $result->patient_id;
$hospital_information = HospitalInformation::first();
$patient = Patient::where(['id' => $patient_id])->first();
$inv = [];
$inv['episode_id'] = $result->episode_id;
$inv['date'] = streamline_date(get_name($result->episode_id, 'id', 'created_at', 'patient_episodes'));
$created_by = is_null($result->updated_by) ? $result->created_by : $result->updated_by;
$investigations = explode(",", $result->investigation_id);
$values = explode(",", $result->value);
$comments = explode(",", $result->comment);
$data = [];
$count = 0;
foreach ($investigations as $investigation) {
if (in_array($investigation, $invs_to_print)) {
$investigation_details = Investigation::find($investigation);
if ($investigation_details) {
$data[$count]['name'] = $investigation_details->name;
$data[$count]['range'] = $investigation_details->normal_ranges;
$data[$count]['slug'] = $investigation_details->slug;
$data[$count]['result'] = $values[$count];
$data[$count]['comment'] = $comments[$count];
$data[$count]['type'] = $investigation_details->type;
$count++;
}
}
}
$inv['data'] = $data;
$data = [
'inv' => $inv,
'patient' => $patient,
'hospitalInfo' => $hospital_information,
'created_by' => $created_by,
'performed_at' => streamline_date_time($result->created_at),
'requested_at' => streamline_date_time(get_name($result->order_id, 'id', 'created_at', 'ordered_investigations'))
];
$pdf = SnappyPDF::loadView("investigations::investigations/print/print_patient_investigation_results", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>');
return $pdf->inline($patient->first_name . ' ' . $patient->last_name . ' Investigation results' . date(" d-m-y h:ia") . '.pdf');
}
}
@@ -0,0 +1,188 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Streamline\Models\Investigation;
use Streamline\Models\InvestigationResultTemplate;
class InvestigationResultTemplateController extends Controller {
public function index() {
$result_templates = InvestigationResultTemplate::orderBy('template', 'asc')->get();
$investigations = Investigation::get();
return view('investigations::investigation_result_templates.index', compact('result_templates', 'investigations'));
}
public function create() {
$investigations = DB::table("investigations")->whereNull("deleted_at")->orderBy("name")->pluck("name", "id")->toArray();
$investigations = [0 => 'All Investigations'] + $investigations;
$investigations = ['' => '- select -'] + $investigations;
return view('investigations::investigation_result_templates.create', compact('investigations'));
}
public function store(Request $request) {
request()->validate([
'investigation_id' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
if ($request->is_specialised_variable == 1) {
$ids = $request->investigation_specialised_variable;
$templates = $request->template_var;
for($x = 0; $x < count($ids); $x++) {
$result_template = new InvestigationResultTemplate;
$result_template->investigation_id = $ids[$x];
$result_template->template = $templates[$x];
$result_template->is_specialised_variable = 1;
$result_template->created_by = $logged_in_user_id;
$result_template->updated_by = $logged_in_user_id;
$result_template->save();
}
} else {
$result_template = new InvestigationResultTemplate;
$result_template->template = $request->template;
$result_template->investigation_id = $request->investigation_id;
$result_template->is_specialised_variable = $request->is_specialised_variable;
$result_template->created_by = $logged_in_user_id;
$result_template->updated_by = $logged_in_user_id;
$result_template->save();
}
flash("Result Template has been saved")->success();
return redirect("/result_templates/");
}
public function show($id) {
//
}
public function edit($id) {
$result_template = InvestigationResultTemplate::where(['id' => $id])->first();
if (!$result_template) {
flash()->error("Result Template not found");
return redirect('/result_templates/');
} else {
return view('investigations::investigation_result_templates.edit', compact('result_template'));
}
}
public function update(Request $request, $id) {
request()->validate([
'template' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
$result_template = InvestigationResultTemplate::find($id);
$result_template->template = $request->template;
$result_template->created_by = $logged_in_user_id;
$result_template->updated_by = $logged_in_user_id;
try {
$result_template->save();
flash($request->name . "Result Template has been saved")->success();
return redirect("/result_templates/");
} catch (QueryException $e) {
flash("An error occurred. Please try again")->error();
return back()->withInput();
}
}
public function destroy($id) {
$result_template = InvestigationResultTemplate::find($id);
if ($result_template->delete()){
flash("Result Template has been deleted.")->error();
return redirect('/result_templates/');
} else {
flash("An error occurred. Please try again")->error();
return back()->withInput();
}
}
public function inactive() {
$result_templates = InvestigationResultTemplate::onlyTrashed()
->paginate(50);
if (count($result_templates) < 1) {
flash()->error("There is no inactive Result Templates");
return redirect('/result_templates/');
} else {
return view('investigations::investigation_result_templates.inactive', compact('result_templates'));
}
}
public function activate($id) {
$result_template = InvestigationResultTemplate::withTrashed()->find($id);
if ($result_template->restore()){
flash("Result Template has been activated.")->success();
return redirect('/result_templates/');
} else {
flash("An error occurred. Please try again")->error();
return back()->withInput();
}
}
public function check_investigation_speciality_type($id, $counter) {
if (get_name($id, 'id', 'type', 'investigations') == 1){
$code = "<label for='investigation_specialised_variable'>Investigation Specialised Variable</label>";
$code .= "<select name='investigation_specialised_variable[]' class='form-control' id='" . $counter . "'>";
$code .= "<option value=''> --select-- </option>";
$variables = DB::table('investigation_specialised_variables')
->where('investigation_id', $id)
->whereNull('deleted_at')
->get();
foreach ($variables as $variable){
$code .= "<option value='" . $variable->id . "'>" . $variable->name . "</option>";
}
$code .= "</select><br><br>";
$code .= "<label for='template'>Template</label>";
$code .= "<textarea class='form-control' rows='3' name='template_var[]'></textarea><br><br>";
} else {
$code = "0";
}
return $code;
}
public function get_templates_for_investigation($id, $is_variable) {
$templates = DB::table('investigation_result_templates')
->whereIn('investigation_id', [$id, 0])
->where('is_specialised_variable', $is_variable)
->whereNull('deleted_at')
->get();
$code = "<table class='table color-bordered-table success-bordered-table'>";
$code .= "<thead><tr>";
$code .= "<th>Template</th><th>Action</th>";
$code .= "</tr></thead><tbody>";
foreach($templates as $template) {
$code .= "<tr>";
$code .= "<td id='template_" . $template->id . "'>" . $template->template . "</td>";
$code .= "<td>";
$code .= "<button class='btn btn-rounded btn-success btn-sm' onclick='confirm_selection(" . '"' . $template->id . '"' . ")'>select</button>";
$code .= "</td>";
$code .= "</tr>";
}
$code .= "</tbody></table>";
return $code;
}
}
@@ -0,0 +1,250 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Streamline\Models\Investigation;
use Streamline\Models\InvestigationNormalRange;
use Streamline\Models\InvestigationSpecialisedVariable;
use Illuminate\Http\Request;
use Streamline\Models\UnitOfMeasure;
use Illuminate\Database\QueryException;
class InvestigationSpecialisedVariableController extends Controller
{
/**create
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$investigation_variables = InvestigationSpecialisedVariable::orderBy('name', 'asc')->get();
$investigations = Investigation::get();
$units = UnitOfMeasure::get();
return view('investigations::investigation_specialised_variables.index', compact('investigation_variables', 'investigations', 'units'));
}
/**
* Show the Investigation Variable for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
$investigations = Investigation::get();
$units = UnitOfMeasure::get();
return view('investigations::investigation_specialised_variables.create', compact('investigations', 'units'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
request()->validate([
'name' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
$investigation_specialised_variable = new InvestigationSpecialisedVariable;
$investigation_specialised_variable->name = $request->name;
$investigation_specialised_variable->investigation_id = $request->investigation;
$investigation_specialised_variable->units = $request->unit;
$investigation_specialised_variable->normal_ranges = $request->normal_ranges;
$investigation_specialised_variable->range_type = $request->range_type;
$investigation_specialised_variable->created_by = $logged_in_user_id;
$investigation_specialised_variable->updated_by = $logged_in_user_id;
$investigation = Investigation::find($request->investigation);
$investigation->type = 1;
try {
$investigation_specialised_variable->save();
$investigation->save();
if ($request->range_type == 1) {
$age_id = $request->age_id;
$dynamic_range_male = $request->dynamic_range_male;
$dynamic_range_female = $request->dynamic_range_female;
for ($x = 0; $x < count($age_id); $x++){
$new_range = new InvestigationNormalRange;
$new_range->male_range = $dynamic_range_male[$x];
$new_range->female_range = $dynamic_range_female[$x];
$new_range->age_group_id = $age_id[$x];
$new_range->test_id = $investigation_specialised_variable->id;
$new_range->is_specialised_variable = 1;
$new_range->created_by = $logged_in_user_id;
$new_range->save();
}
}
flash($request->name . "Investigation Specialised Variable has been saved")->success();
return redirect("/investigation_variables/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
$investigations = Investigation::get();
$units = UnitOfMeasure::get();
$investigation_specialised_variable = InvestigationSpecialisedVariable::where(['id' => $id])->first();
if (!$investigation_specialised_variable) {
flash()->error("Drug Investigation Variable not found");
return redirect('/investigation_variables/');
} else {
return view('investigations::investigation_specialised_variables.edit', compact('investigation_specialised_variable', 'investigations', 'units'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
request()->validate([
'name' => 'required'
]);
$logged_in_user_id = Auth::user()->id;
$investigation_specialised_variable = InvestigationSpecialisedVariable::find($id);
$investigation_specialised_variable->name = $request->name;
$investigation_specialised_variable->investigation_id = $request->investigation;
$investigation_specialised_variable->units = $request->unit;
$investigation_specialised_variable->normal_ranges = $request->normal_ranges;
$investigation_specialised_variable->range_type = $request->range_type;
$investigation_specialised_variable->created_by = $logged_in_user_id;
$investigation_specialised_variable->updated_by = $logged_in_user_id;
$investigation = Investigation::find($request->investigation);
$investigation->type = 1;
try {
$investigation_specialised_variable->save();
$investigation->save();
if ($request->range_type == 1) {
$age_id = $request->age_id;
$dynamic_range_male = $request->dynamic_range_male;
$dynamic_range_female = $request->dynamic_range_female;
for ($x = 0; $x < count($age_id); $x++){
$dynamic_normal_range = DB::table('investigations_normal_ranges')
->where('age_group_id', $age_id[$x])
->where('test_id', $investigation_specialised_variable->id)
->where('is_specialised_variable', 1)
->first();
if (!$dynamic_normal_range) {
$dynamic_normal_range = new InvestigationNormalRange;
$dynamic_normal_range->created_by = $logged_in_user_id;
} else {
$dynamic_normal_range = InvestigationNormalRange::find($dynamic_normal_range->id);
$dynamic_normal_range->updated_by = $logged_in_user_id;
}
$dynamic_normal_range->male_range = $dynamic_range_male[$x];
$dynamic_normal_range->female_range = $dynamic_range_female[$x];
$dynamic_normal_range->age_group_id = $age_id[$x];
$dynamic_normal_range->test_id = $investigation_specialised_variable->id;
$dynamic_normal_range->is_specialised_variable = 1;
$dynamic_normal_range->save();
}
}
flash($request->name . "Investigation Specialised Variable has been saved")->success();
return redirect("/investigation_variables/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$investigation_specialised_variable = InvestigationSpecialisedVariable::find($id);
$investigation_id = $investigation_specialised_variable->investigation_id;
if ($investigation_specialised_variable->delete()){
$variables = InvestigationSpecialisedVariable::where(['investigation_id' => $investigation_id])->count();
if ($variables < 1) {
$investigation = Investigation::find($investigation_id);
$investigation->type = 0;
$investigation->save();
}
flash("Investigation Variable has been deleted.")->success();
return redirect('/investigation_variables/');
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Http\Response
*/
public function inactive() {
$investigation_variables = InvestigationSpecialisedVariable::onlyTrashed()
->orderBy('name', 'asc')
->paginate(50);
if (empty($investigation_variables)) {
flash()->error("There is no inactive Drug Routes");
return redirect('/investigation_variables/');
} else {
return view('investigations::investigation_specialised_variables.inactive', compact('investigation_variables'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function activate($id) {
$investigation_specialised_variable = InvestigationSpecialisedVariable::withTrashed()->find($id);
$investigation = Investigation::find($investigation_specialised_variable->investigation_id);
$investigation->type = 1;
if ($investigation_specialised_variable->restore()){
$investigation->save();
flash("Investigation Variable has been activated.")->success();
return redirect('/investigation_variables/');
}
}
}
@@ -0,0 +1,236 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Streamline\Models\Investigation;
use Streamline\Models\InvestigationSpecialisedVariable;
use Streamline\Models\InvestigationTestCode;
use Streamline\Models\LabInstrument;
class InvestigationTestCodesController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function index() {
$test_codes = InvestigationTestCode::get();
$instruments = LabInstrument::pluck('name', 'id');
$investigations = Investigation::pluck('name', 'id');
$specialised_variables = InvestigationSpecialisedVariable::pluck('name', 'id');
return view('investigations::investigation_test_codes.index', compact('test_codes', 'investigations', 'instruments', 'specialised_variables'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function create() {
$investigations = Investigation::orderBy('name')
->pluck('name', 'id')
->prepend('- select -', '');
$instruments = LabInstrument::orderBy('name')
->pluck('name', 'id')
->prepend('- select -', '');
return view('investigations::investigation_test_codes.create', compact('investigations', 'instruments'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request) {
request()->validate([
'investigation_id' => 'required',
'machine_name' => 'required',
'test_code' => 'required'
]);
$test_code = new InvestigationTestCode();
$logged_in_user_id = Auth::user()->id;
if ($request->is_specialised_variable == 1){
if (is_null($request->investigation_specialised_variable)) {
flash("Please include the specialised variable for this investigation")->error();
return back()->withInput();
} else {
$test_code->investigation_id = $request->investigation_specialised_variable;
}
} else {
$test_code->investigation_id = $request->investigation_id;
}
$test_code->machine_name = $request->machine_name;
$test_code->test_code = $request->test_code;
$test_code->is_specialised_variable = $request->is_specialised_variable;
$test_code->created_by = $logged_in_user_id;
$test_code->updated_by = $logged_in_user_id;
try {
$test_code->save();
flash("Test Code has been saved")->success();
return redirect("/investigation_test_codes/");
} catch (QueryException $e) {
flash("Something went wrong. Please try again")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function edit($id) {
$test_code = InvestigationTestCode::where(['id' => $id])->first();
$investigations = Investigation::orderBy('name')
->pluck('name', 'id')
->prepend('- select -', '');
$instruments = LabInstrument::orderBy('name')
->pluck('name', 'id')
->prepend('- select -', '');
$specialised_variables = InvestigationSpecialisedVariable::orderBy('name')
->pluck('name', 'id')
->prepend('- select -', '');
if (!$test_code) {
flash()->error("Investigation test code not found");
return redirect('/investigation_test_codes/');
} else {
return view('investigations::investigation_test_codes.edit', compact('test_code', 'investigations', 'instruments', 'specialised_variables'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function update(Request $request, $id) {
request()->validate([
'investigation_id' => 'required',
'machine_name' => 'required',
'test_code' => 'required'
]);
//validation passed
$test_code = InvestigationTestCode::find($id);
$logged_in_user_id = Auth::user()->id;
if ($request->is_specialised_variable == 1){
if (is_null($request->investigation_specialised_variable)) {
flash("Please include the specialised variable for this investigation")->error();
return back()->withInput();
} else {
$test_code->investigation_id = $request->investigation_specialised_variable;
}
} else {
$test_code->investigation_id = $request->investigation_id;
}
$test_code->machine_name = $request->machine_name;
$test_code->test_code = $request->test_code;
$test_code->is_specialised_variable = $request->is_specialised_variable;
$test_code->updated_by = $logged_in_user_id;
try {
$test_code->save();
flash("Test code has been updated")->success();
return redirect("/investigation_test_codes/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy($id) {
$test_code = InvestigationTestCode::find($id);
if ($test_code->delete()) {
flash("Test Code has been deleted.")->success();
return redirect('/investigation_test_codes/');
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function inactive() {
$test_codes = InvestigationTestCode::onlyTrashed()->get();
$investigations = Investigation::pluck('name', 'id');
$instruments = LabInstrument::pluck('name', 'id');
$specialised_variables = InvestigationSpecialisedVariable::pluck('name', 'id');
if (count($test_codes) < 1) {
flash()->error("There is no inactive test code");
return redirect('/investigation_test_codes/');
} else {
return view('investigations::investigation_test_codes.inactive', compact('test_codes', 'investigations', 'instruments', 'specialised_variables'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function activate($id) {
$test_code = InvestigationTestCode::withTrashed()->find($id);
if($test_code->restore()){
flash("Test code has been activated.")->success();
return redirect('/investigation_test_codes/inactive');
}
}
public function check_investigation_speciality_type($id) {
if (get_name($id, 'id', 'type', 'investigations') == 1){
$code = "<select name='investigation_specialised_variable' id='investigation_specialised_variable' class='form-control select'>";
$code .= "<option value=''> --select-- </option>";
$variables = InvestigationSpecialisedVariable::where('investigation_id', $id)->get();
foreach ($variables as $variable){
$code .= "<option value='" . $variable->id . "'>" . $variable->name . "</option>";
}
$code .= "</select>";
} else {
$code = "0";
}
return $code;
}
}
@@ -0,0 +1,762 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Streamline\Models\ChartOfAccount;
use Streamline\Models\HospitalInformation;
use Streamline\Models\Lab;
use Streamline\Models\LabForm;
use Streamline\Models\LabUsageListing;
use Streamline\Models\OrderedInvestigation;
use Streamline\Models\Supplier;
use Streamline\Models\UnitOfMeasure;
use Streamline\Models\Requisition;
class LabController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('permission:lab-management', ['only' => ['index']]);
$this->middleware('permission:labs-create', ['only' => ['create', 'store']]);
$this->middleware('permission:labs-bulk-create', ['only' => ['add_bulk', 'store_bulk']]);
$this->middleware('permission:labs-bulk-edit', ['only' => ['edit_bulk', 'update_bulk']]);
$this->middleware('permission:labs-edit', ['only' => ['edit', 'update']]);
$this->middleware('permission:labs-delete', ['only' => ['destroy', 'inactive', 'activate']]);
$this->middleware('permission:labs-usage-listing', ['only' => ['lab_usage_listing']]);
$this->middleware('permission:labs-report-usage', ['only' => ['actual_lab_usage', 'labs_usages_report']]);
$this->middleware('permission:labs-bulk-delete', ['only' => ['delete_bulk']]);
$this->middleware('permission:requisition-for-labs', ['only' => ['requisition_for_labs','store_lab_requisitions']]);
$this->middleware('permission:labs-stock-sheet', ['only' => ['stock_sheet', 'update_laboratory_stock_sheet']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$labs = Lab::orderBy('name', 'asc')->get();
$labs= get_all_batch_details($labs,['store_stock','lab_stock'],['store_batches','lab_batches'],['total_store_stock','total_lab_stock'],5) ;
return view('investigations::labs.index', compact('labs'));
}
public function dashboard()
{
$end = Carbon::now()->endOfDay()->toDateTimeString();
$start = Carbon::now()->startOfDay()->toDateTimeString();
$labs = Lab::get();
$total_investigations = OrderedInvestigation::get();
$total_paid_investigations = OrderedInvestigation::where('payment_status', 1)->get();
$total_unpaid_investigations = OrderedInvestigation::where('payment_status', 0)->get();
$total_pending_investigations = OrderedInvestigation::where('investigation_status', 0)->get();
$total_investigation_deposits = DB::table('investigation_deposits')
->whereBetween('created_at', [$start, $end]);
return view('investigations::labs.dashboard', compact('labs', 'total_investigations', 'total_paid_investigations', 'total_unpaid_investigations', 'total_pending_investigations', 'total_investigation_deposits'));
}
public function lab_usage_listing()
{
/*$labs = DB::table('labs')->where('deleted_at', '=',null)->where('store_stock', '>', 0)->get();*/
$labs = Lab::orderBy('name', 'asc')->get();
$hospital_information = HospitalInformation::first();
$labs_usages = LabUsageListing::orderBy('id','desc')->limit(20)->get();
return view('investigations::labs.lab_usage_listing', compact('labs', 'hospital_information', 'labs_usages'));
}
public function clear_stock()
{
$lab_s = Lab::get();
foreach ($lab_s as $lab) {
$lab->delete();
}
$labs = Lab::get();
return view('investigations::labs.index', compact('labs'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$units = UnitOfMeasure::get();
$suppliers = Supplier::get();
$forms = LabForm::get();
$chart_of_accounts = ChartOfAccount::where(['type' => 1])
->orderBy('name', 'asc')
->pluck('name', 'id')
->toArray();
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ['' => '- select -'] + $payables_accounts;
return view('investigations::labs.create', compact('units', 'suppliers', 'forms', 'chart_of_accounts', 'expense_accounts', 'payables_accounts'));
}
public function add_bulk()
{
$units_of_measure = UnitOfMeasure::get();
$suppliers = Supplier::get();
$forms = LabForm::get();
//$chart_of_accounts = ChartOfAccount::get();
$chart_of_accounts = ChartOfAccount::where(['type' => 1])
->orderBy('name', 'asc')
->pluck('name', 'id')
->toArray();
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ['' => '- select -'] + $payables_accounts;
return view('investigations::labs.bulk.create', compact('units_of_measure', 'suppliers', 'forms', 'chart_of_accounts', 'expense_accounts', 'payables_accounts'));
}
public function get_lab_quantity(Request $request)
{
if (track_items_using_batches()){
$lab_stock =track_batch_stock(5,$request->id,'lab_stock');
$total_stock = 0;
foreach ($lab_stock as $lab) {
$total_stock += $lab->lab_stock;
}
$data = [
'laboratory_stock' => $total_stock,
'cost_price' => $lab_stock[0]->cost_price??0,
];
return $data;
}
return Lab::where('id', $request->id)->first();
}
public function actual_lab_usage(Request $request)
{
$lab_counter = 0;
$lab_item_array = $request->labItem;
$available_qty_array = $request->availableQty;
$available_qty_unit_cost_array = $request->unitCost;
$usage_qty_array = $request->requiredQty;
$usage_qty_cost_array = $request->totalCost;
if ($request->dates == 'today') {
$start = Carbon::now()->startOfDay()->toDateTimeString();
$end = Carbon::now()->endOfDay()->toDateTimeString();
} else {
$start = Carbon::parse($request->start_date)->endOfDay()->toDateTimeString();
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
}
for ($i = 0; $i < count($lab_item_array); $i++) {
if ($lab_item_array[$i]) {
if(track_items_using_batches()){
$datat=get_lab_batches_to_use_based_on_needed_quantity($lab_item_array[$i],5,$usage_qty_array[$i],'lab_stock');
$cost_value=0;
foreach ($datat as $key=> $val){
$unit_cost_value =(int) get_name($key, 'id', 'cost_price', 'item_batch_watcher');
//caluclate cost value
$cost_value += $unit_cost_value * $val;
reduce_batch_item_stock(5,$lab_item_array[$i], $key, 'labs', 'lab_stock', $val, 'lab_usage_listings','Labs', null, null);
}
$usage_qty_cost_array[$i]=$cost_value;
}
$remaining_qty = record_lab_usage_listing($lab_item_array[$i],$available_qty_unit_cost_array[$i], $available_qty_array[$i],$usage_qty_array[$i], $usage_qty_cost_array[$i],
$start,$end);
if (!($remaining_qty < 0)) {
$lab = Lab::find($lab_item_array[$i]);
$lab->laboratory_stock = ($lab->laboratory_stock - (int)$usage_qty_array[$i]);
$lab->save();
} else {
flash('Lab Item\'s ' . get_name($lab_item_array[$i], 'id', 'name', 'labs') . ' requested use quantity exceeds what is available.');
}
}
}
flash('Labs used from ' . streamline_date($start) . ' to ' . streamline_date($end) . ' have saved successfully')->success();
return redirect('/labs/usage/listing');
}
public function store_bulk(Request $request)
{
$validator = Validator::make($request->all(), [
//'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
flash($string)->error();
return back()->withErrors($validator)->withInput();
} else {
$name_array = $request->name;
for ($i = 0; $i < count($name_array); $i++) {
if ($request->name[$i] != "" && !is_null($request->name[$i])) {
try {
$lab = new Lab;
$lab->name = $request->name[$i];
// $lab->cost_price = isset($request->cost_price[$i])?$request->cost_price[$i] : null;
// $lab->non_insured_price = isset($request->non_insured_price[$i])?$request->non_insured_price[$i] : null;
// $lab->insured_price = isset($request->insured_price[$i])?$request->insured_price[$i] : null;
// $lab->account_id = isset($request->chart_of_account[$i])? $request->chart_of_account[$i] : null;
// $lab->store_stock = isset($request->stock[$i])?$request->stock[$i] : 0 ;
// if ($request->chi_status[$i] == '1') {
// $lab->insurance_coverage = 1;
// } else {
// $lab->insurance_coverage = 0;
// }
$lab->reorder_level = isset($request->re_order_level[$i]) ? $request->re_order_level[$i] :0;
$lab->description = $request->description[$i];
$lab->form_id = $request->form[$i];
$lab->unit_id = $request->unit[$i];
// $lab->expiry_date = isset($request->expiry_date[$i])? $request->expiry_date[$i] : null;
// $lab->supplier_id = isset($request->supplier[$i])? $request->supplier[$i] : null ;
$lab->expenses_account_id = isset($request->expenses_account_id[$i]) ? $request->expenses_account_id[$i] : null;
$lab->created_by = Auth::id();
$lab->save();
} catch (\Exception $e) {
flash('Error: ' . $e->getMessage())->error();
return redirect()->back();
}
}
}
}
return redirect('labs');
}
public function edit_bulk()
{
$labs = Lab::get();
$units_of_measure = UnitOfMeasure::get()->pluck('name','id')->toArray();
$units_of_measure = ['' => '- select -'] + $units_of_measure;
$suppliers = Supplier::get();
$forms = LabForm::pluck('name','id')->toArray();
$forms = ['' => '- select -'] + $forms;
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ['' => '- select -'] + $payables_accounts;
return view('investigations::labs.bulk.edit', compact('units_of_measure', 'suppliers', 'forms', 'labs', 'expense_accounts', 'payables_accounts'));
}
public function update_bulk(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
flash($string)->error();
return back()->withErrors($validator)->withInput();
} else {
$name_array = $request->name;
for ($i = 0; $i < count($name_array); $i++) {
try {
$lab = Lab::find($request->id[$i]);
$lab->name = $request->name[$i];
$lab->cost_price = isset($request->cost_price[$i]) ? $request->cost_price[$i] : null ;
$lab->expiry_date = isset($request->cost_price[$i]) ? $request->expiry_date[$i] : null;
$lab->non_insured_price = isset($request->cost_price[$i]) ? $request->non_insured_price[$i] : null;
$lab->insured_price = isset($request->cost_price[$i]) ? $request->insured_price[$i] : null;
$lab->account_id = isset($request->chart_of_account[$i]) ? $request->chart_of_account[$i] : null;
$lab->store_stock = isset($request->stock[$i]) ? $request->stock[$i] : null;
$lab->reorder_level = isset($request->re_order_level[$i]) ? $request->re_order_level[$i] : null;
$lab->description = $request->description[$i];
$lab->form_id = isset($request->form[$i]) ? $request->form[$i] : null;
$lab->unit_id = isset($request->unit[$i]) ? $request->unit[$i] : null;
$lab->supplier_id = isset($request->supplier[$i]) ? $request->supplier[$i] : null;
$lab->expenses_account_id = isset($request->expenses_account_id[$i]) ? $request->expenses_account_id[$i] : null;
$lab->updated_by = Auth::id();
$lab->save();
} catch (\Exception $e) {
flash('Error: ' . $e->getMessage())->error();
return redirect()->back();
}
}
}
return redirect('labs');
}
public function delete_bulk(Request $request)
{
$ids_array = $request->ids;
for ($i = 0; $i < count($ids_array); $i++) {
$lab = Lab::find($ids_array[$i]);
if ($lab) {
$lab->delete();
}
}
return 'success';
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
flash($string)->error();
return back()->withErrors($validator)->withInput();
} else {
$lab = new Lab;
$lab->name = $request->name;
$lab->cost_price = is_null($request->cost_price) ? null :$request->cost_price;
$lab->non_insured_price = is_null($request->non_insured_price) ? null :$request->non_insured_price;
$lab->insured_price =is_null($request->insured_price) ? null : $request->insured_price;
$lab->account_id = is_null($request->chart_of_account) ? null :$request->chart_of_account;
$lab->expiry_date = is_null($request->expiry_date) ? null : Carbon::createFromFormat('d/m/Y', $request->expiry_date)->toDateString();
$lab->store_stock = is_null($request->stock) ? 0 : $request->stock;
if ($request->chi_status == '1') {
$lab->insurance_coverage = 1;
} else {
$lab->insurance_coverage = 0;
}
$lab->reorder_level = is_null($request->re_order_level) ? 0 : $request->re_order_level;
$lab->description = $request->description;
$lab->form_id = $request->form;
$lab->unit_id = $request->unit;
$lab->supplier_id = $request->supplier;
$lab->expenses_account_id = $request->expenses_account_id;
//$lab->payables_account_id = $request->payables_account_id;
$lab->created_by = Auth::id();
flash("New lab has been added")->success();
$lab->save();
return redirect('labs');
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$lab = Lab::find($id);
$units = UnitOfMeasure::get()->pluck('name', 'id')->toArray();
$units = ['' => '- select -'] + $units;
$suppliers = Supplier::get();
$forms = LabForm::get()->pluck('name', 'id')->toArray();
$forms = ['' => '- select -'] + $forms;
$chart_of_accounts = ChartOfAccount::where(['type' => 1])
->orderBy('name', 'asc')
->pluck('name', 'id')
->toArray();
$chart_of_accounts = ['' => '- select -'] + $chart_of_accounts;
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ['' => '- select -'] + $payables_accounts;
return view('investigations::labs.edit', compact('lab', 'units', 'suppliers', 'forms', 'chart_of_accounts', 'expense_accounts', 'payables_accounts'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
flash($string)->error();
return back()->withErrors($validator)->withInput();
} else {
$lab = Lab::find($id);
$lab->name = $request->name;
$lab->cost_price = is_null($request->cost_price) ? null :$request->cost_price;
$lab->non_insured_price = is_null($request->non_insured_price) ? null :$request->non_insured_price;
$lab->insured_price =is_null($request->insured_price) ? null : $request->insured_price;
$lab->account_id = is_null($request->chart_of_account) ? null :$request->chart_of_account;
$lab->store_stock =is_null($request->stock) ? null : $request->stock;
$lab->reorder_level = is_null($request->re_order_level) ? null :$request->re_order_level;
$lab->description = $request->description;
$lab->form_id = $request->form;
$lab->unit_id = $request->unit;
$lab->expiry_date = is_null($request->expiry_date) ? null : $request->expiry_date;
$lab->supplier_id = is_null($request->supplier) ? null :$request->supplier;
$lab->expenses_account_id = $request->expenses_account_id;
//$lab->payables_account_id = $request->payables_account_id;
$lab->updated_by = Auth::id();
try {
$lab->save();
} catch (\Exception $e) {
}
}
return redirect('labs');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$lab = Lab::find($id);
if ($lab->delete()) {
flash("Lab has been deleted.")->success();
return redirect('labs');
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Http\Response
*/
public function inactive()
{
$labs = Lab::onlyTrashed()
->orderBy('name', 'asc')
->get();
if (count($labs) < 1) {
flash()->error("There is no inactive labs");
return redirect('labs');
}
return view('investigations::labs.inactive', compact('labs'));
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function activate($id)
{
$lab = Lab::withTrashed()->find($id);
if ($lab->restore()) {
flash("Labs has been activated.")->success();
return redirect('/labs/inactive');
}
}
/* requisition for labs */
public function requisition_for_labs(Request $request)
{
$results = Lab::orderBy('name', 'asc')->get();
$names_array = Lab::orderBy('name')->distinct()->pluck('name');
$labs = Lab::orderBy('name')->pluck('name', 'id');
// add start and end date
$date_filter = [];
if (isset($request->start_date) && isset($request->end_date)) {
if (isset($request->quotation_type)) {
$item_type = $request->quotation_type;
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>', $start_date]);
array_push($date_filter, ['created_at', '<', $end_date]);
}
} else {
$date_from = Carbon::today()->subDays(30)->format('Y-m-d');
$date_to = Carbon::today()->addDays(1)->format('Y-m-d');
array_push($date_filter, ['created_at', '>', $date_from]);
array_push($date_filter, ['created_at', '<', $date_to]);
}
return view('investigations::labs.requisition_for_labs', compact('results', 'names_array', 'labs'));
}
/**
* Previous lab requisitions
* return @var object
*/
public function previous_requisition_for_labs(Request $request)
{
$search_by = $request->search_by;
$reg_date = $request->reg_date;
$start_date = $request->start_date;
$end_date = $request->end_date;
$filters = [];
$search_string = "";
if ($search_by == 0) {
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($filters, ['created_at', '>=', $last_day]);
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($last_day) . "</h4>";
} elseif ($search_by == 1) {
// custom date
if (is_null($request->reg_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$selected_date_filter = Carbon::createFromFormat('d/m/Y', $request->reg_date)->toDateString();
array_push($filters, ['created_at', $selected_date_filter]);
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($selected_date_filter) . "</h4>";
} elseif ($search_by == 2) {
// custom date range
if (is_null($start_date) || is_null($end_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$start_date_search = Carbon::createFromFormat('d/m/Y', $start_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::createFromFormat('d/m/Y', $end_date)->endOfDay()->toDateTimeString();
array_push($filters, ['created_at', '>=', $start_date_search]);
array_push($filters, ['created_at', '<=', $end_date_search]);
$search_string = "<h4 class='label label-info'>Showing between " . streamline_date($start_date_search) . " and " . streamline_date($end_date_search) . "</h4>";
}else{
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($filters, ['created_at', '>=', $last_day]);
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($last_day) . "</h4>";
}
$data['previous_requisitions_results'] =Requisition::where('quotation_type_id', '=', 5)->where($filters)->orderBy('created_at', 'desc')->get();
$data['search_string'] = $search_string;
return view('investigations::labs.pre_requisition_for_labs', compact('data'));
}
public function store_lab_requisitions(Request $request)
{
$drug_id_array = $request->drug_id;
$quantity_array = $request->quantity;
$item_type = $request->item_type;
$user_id = Auth::id();
/* return back if no quantity has been filled */
if (array_sum($quantity_array) < 1) {
flash('Please insert some values!')->error();
return redirect()->back()->withInput();
}
if (isset($request->complete_request)) {
$filtered_drugs_array = [];
$filtered_quantities_array = [];
$associative_requested_drugs_array = [];
for ($i = 0; $i < count($drug_id_array); $i++) {
if ($quantity_array[$i] != "") {
$associative_requested_drugs_array[$drug_id_array[$i]] = $quantity_array[$i];
$filtered_drugs_array[] = $drug_id_array[$i];
$filtered_quantities_array[] = $quantity_array[$i];
}
}
$new_requisition = new Requisition;
$new_requisition->quotation_type_id = $item_type;
$new_requisition->drug_id = implode(',', $filtered_drugs_array);
$new_requisition->quantity_requested = implode(',', $filtered_quantities_array);
$new_requisition->created_by = $user_id;
$new_requisition->requisition_origin = 2; //1-pharmacy, 2-lab, 3-imaging
$new_requisition->save();
flash('Requisition number ' . $new_requisition->id . ' made successfully')->success();
//redirect to requisition
return redirect('/print_requisition_receipt/' . $new_requisition->id);
}
}
/* filter out items to requisition */
public function requisition_for_labs_search(Request $request)
{
$item_type = $request->item_type;
$item_ids_array = $request->items_ids;
$results = null;
$filters = [];
$items = null;
$results = Lab::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
$labs = Lab::orderBy('name')->pluck('name', 'id');
$date_filter = [];
if (isset($request->start_date) && isset($request->end_date)) {
if (isset($request->quotation_type)) {
$item_type = $request->quotation_type;
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>', $start_date]);
array_push($date_filter, ['created_at', '<', $end_date]);
}
} else {
$date_from = Carbon::today()->subDays(30)->format('Y-m-d');
$date_to = Carbon::today()->addDays(1)->format('Y-m-d');
array_push($date_filter, ['created_at', '>', $date_from]);
array_push($date_filter, ['created_at', '<', $date_to]);
}
$previous_requisitions_results =Requisition::where('quotation_type_id', '=', 5)->where($date_filter)->orderBy('created_at', 'desc')->get();
return view('investigations::labs.requisition_for_labs', compact('items', 'item_type', 'labs', 'results', 'previous_requisitions_results'));
}
/* view stock sheet */
public function stock_sheet()
{
$labs = DB::table('labs')->whereNull('deleted_at')->orderBy('name', 'asc')->paginate(1000);
// getting the labs stock batches
$labs= calculate_stock_value($labs,5,'lab_stock');
if (empty($labs)) {
flash()->error("There is out of stock of labs");
return redirect('/labs/');
} else {
return view('investigations::labs.labs_stock_sheet', compact('labs'));
}
}
public function update_laboratory_stock_sheet(Request $request)
{
$lab_ids_array = $request->lab_id;
$quantities_array = $request->quantity;
$expiry_dates_array = $request->expiry_date;
$batch_numbers_array = $request->batch_number;
$batch_quantity_balances_array = $request->batch_quantity_balance;
$batch_unit_cost = $request->batch_unit_cost;
$batch_db_record_ids_array = $request->batch_drug_id;
$batch_expiry_dates_array = $request->expiry_date;
$batch_drug_ids_array = $request->batch_item_id;
//update batch tracking tables with reconciliations
for ($i=0; $i < count($batch_numbers_array) ; $i++) {
if (!is_null($batch_numbers_array[$i]) && !is_null($batch_quantity_balances_array[$i]) ){
reconcile_batches(5, $batch_drug_ids_array[$i], $batch_numbers_array[$i], $batch_quantity_balances_array[$i], $batch_expiry_dates_array[$i], "lab", $batch_unit_cost[$i], $batch_db_record_ids_array[$i]??0, null);
}
}
for ($i = 0; $i < count($lab_ids_array); $i++) {
$lab = Lab::withTrashed()->find($lab_ids_array[$i]);
$lab->laboratory_stock = $quantities_array[$i];
// $lab->expiry_date = $expiry_dates_array[$i];
$lab->save();
}
flash('stock sheet has been updated')->success();
return redirect('laboratory_stock_sheet');
}
public function labs_usages_report(Request $request)
{
$labs = [];
// $labs = DB::table('labs')->orderBy('name', 'asc')->where('deleted_at', '=', null)->get();
$hospital_information = HospitalInformation::first();
$labs_options = Lab::orderBy('name', 'asc')->pluck('name', 'id')->prepend('- All labs - ', 'all_labs');
$search_by = $request->search_by;
$reg_date = $request->reg_date;
$start_date = $request->start_date;
$end_date = $request->end_date;
$filters = [];
$search_string = "";
if ($search_by == 0) {
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($filters, ['start_date', '>=', $last_day]);
if ($request->lab_id != 'all_labs') {
array_push($filters, ['lab_id', '=', $request->lab_id]);
}
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($last_day) . "</h4>";
} elseif ($search_by == 1) {
// custom date
if (is_null($request->reg_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$selected_date_filter = Carbon::createFromFormat('d/m/Y', $request->reg_date)->toDateString();
array_push($filters, ['start_date', $selected_date_filter]);
if ($request->lab_id != 'all_labs') {
array_push($filters, ['lab_id', '=', $request->lab_id]);
}
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($selected_date_filter) . "</h4>";
} elseif ($search_by == 2) {
// custom date range
if (is_null($start_date) || is_null($end_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$start_date_search = Carbon::createFromFormat('d/m/Y', $start_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::createFromFormat('d/m/Y', $end_date)->endOfDay()->toDateTimeString();
array_push($filters, ['start_date', '>=', $start_date_search]);
array_push($filters, ['end_date', '<=', $end_date_search]);
if ($request->lab_id != 'all_labs') {
array_push($filters, ['lab_id', '=', $request->lab_id]);
}
$search_string = "<h4 class='label label-info'>Showing between " . streamline_date($start_date_search) . " and " . streamline_date($end_date_search) . "</h4>";
}
$labs_usages = LabUsageListing::where($filters)->orderBy('id', 'desc')->limit(500)->get();
return view('investigations::labs.lab_usages_report', compact('labs', 'hospital_information', 'labs_usages', 'labs_options', 'search_string'));
}
}
@@ -0,0 +1,175 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Streamline\Models\LabForm;
use Illuminate\Http\Request;
class LabFormController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$lab_forms = LabForm::get();
return view('investigations::lab_forms.index', compact('lab_forms'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('investigations::lab_forms.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
//'mobile_number' => 'regex:/07\d{2} \d{3} \d{3}/'
//'mobile_number' => 'regex:/(07)[0-9]{8}/'
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
} else {
$logged_in_user_id = Auth::user()->id;
$lab_form = new LabForm;
$lab_form->name = $request->name;
$lab_form->created_by = $logged_in_user_id;
$lab_form->updated_by = $logged_in_user_id;
try {
$lab_form->save();
flash($request->name . " LabForm has been saved")->success();
return redirect("/lab_forms/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
}
/**
* Display the specified resource.
*
* @param \Streamline\Models\LabForm $labForm
* @return \Illuminate\Http\Response
*/
public function show(LabForm $labForm)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \Streamline\Models\LabForm $labForm
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$lab_form = LabForm::where(['id' => $id])->first();
return view('investigations::lab_forms.edit', compact('lab_form'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \Streamline\Models\LabForm $labForm
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
} else {
$logged_in_user_id = Auth::user()->id;
$lab_form = LabForm::find($id);
$lab_form->name = $request->name;
$lab_form->updated_by = $logged_in_user_id;
try {
$lab_form->save();
flash($request->name . " LabForm has been updated")->success();
return redirect("/lab_forms/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
}
/**
* Remove the specified resource from storage.
*
* @param \Streamline\Models\LabForm $labForm
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$lab = LabForm::find($id);
if ($lab->delete()) {
flash("Lab has been deleted.")->success();
return redirect('labs');
}
}
public function inactive() {
$lab_forms = LabForm::onlyTrashed()
->orderBy('name', 'asc')
->get();
if (count($lab_forms) < 1) {
flash()->error("There is no inactive lab forms");
return redirect('lab_forms');
}
return view('investigations::lab_forms.inactive', compact('lab_forms'));
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function activate($id) {
$lab_form = LabForm::withTrashed()->find($id);
if($lab_form->restore()){
flash("Lab Form has been activated.")->success();
return redirect('/lab_forms/inactive');
}
}
}
@@ -0,0 +1,161 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Streamline\Models\LabInstrument;
class LabInstrumentsController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function index() {
$instruments = LabInstrument::get();
return view('investigations::lab_instruments.index', compact('instruments'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function create() {
return view('investigations::lab_instruments.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(Request $request) {
request()->validate([
'name' => 'required'
]);
$instrument = new LabInstrument();
$logged_in_user_id = Auth::user()->id;
$instrument->name = $request->name;
$instrument->created_by = $logged_in_user_id;
$instrument->updated_by = $logged_in_user_id;
try {
$instrument->save();
flash("Lab Instrument has been saved")->success();
return redirect("/lab_instruments/");
} catch (QueryException $e) {
flash("Something went wrong. Please try again")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function edit($id) {
$instrument = LabInstrument::where(['id' => $id])->first();
if (!$instrument) {
flash()->error("Lab Instrument not found");
return redirect('/lab_instruments/');
} else {
return view('investigations::lab_instruments.edit', compact('instrument'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function update(Request $request, $id) {
request()->validate([
'name' => 'required',
]);
//validation passed
$instrument = LabInstrument::find($id);
$logged_in_user_id = Auth::user()->id;
$instrument->name = $request->name;
$instrument->updated_by = $logged_in_user_id;
try {
$instrument->save();
flash("Lab Instrument has been updated")->success();
return redirect("/lab_instruments/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy($id) {
$instrument = LabInstrument::find($id);
if ($instrument->delete()) {
flash("Lab Instrument has been deleted.")->success();
return redirect('/lab_instruments/');
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function inactive() {
$instruments = LabInstrument::onlyTrashed()->get();
if (count($instruments) < 1) {
flash()->error("There is no inactive Lab Instrument");
return redirect('/lab_instruments/');
} else {
return view('investigations::lab_instruments.inactive', compact('instruments'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function activate($id) {
$instrument = LabInstrument::withTrashed()->find($id);
if($instrument->restore()){
flash("Lab Instrument has been activated.")->success();
return redirect('/lab_instruments/inactive');
}
}
}
@@ -0,0 +1,313 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Streamline\Models\InvestigationResults;
use Streamline\Models\InvestigationSpecialisedResult;
use Streamline\Models\LabInstrument;
use Streamline\Models\LabMachineRestart;
use Streamline\Models\LabMachineResult;
use Streamline\Models\OrderedInvestigation;
use Streamline\Models\TrackReceipt;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class LabMachinesController extends Controller {
public function receive_results_mindray(Request $request) {
$test_id = $request->test_id; // the investigation order id
$arr_parameters = json_decode($request->parameters);
$results_time = $request->time;
$results_arr = [];
$flag_arr = [];
$test_code_arr = [];
foreach ($arr_parameters as $parameter) {
$results_arr[] = $parameter[1];
$flag_arr[] = $parameter[2];
$test_code_arr[] = $parameter[0];
}
$results = new LabMachineResult();
$results->sample_id = $test_id;
$results->results = implode(",", $results_arr);
$results->abnormal_flag = implode(",", $flag_arr);
$results->test_code = implode(",", $test_code_arr);
$results->results_time = $results_time;
$results->save();
}
public function receive_results_mispa(Request $request) {
$test_id = $request->SID ?? 0;
$patient_id = $request->PID ?? 0;
$machine_id = $request->machine_id ?? 0;
$arr_parameters = json_decode($request->results);
$results_arr = [];
$flag_arr = [];
$test_code_arr = [];
foreach ($arr_parameters as $parameter) {
$test_code_arr[] = $parameter[0];
$results_arr[] = str_replace(' ', '', $parameter[1]);
$flag_arr[] = strtoupper($parameter[2]);
}
$results = new LabMachineResult();
$results->sample_id = $test_id;
$results->results = implode(",", $results_arr);
$results->abnormal_flag = implode(",", $flag_arr);
$results->test_code = implode(",", $test_code_arr);
$results->machine_id = $machine_id;
$results->save();
}
public function import_results($sample_id) {
$lab_machine_result = LabMachineResult::where('sample_id', $sample_id)->orderBy('id', 'desc')->first();
$results = explode(",", $lab_machine_result->results);
$flag = explode(",", $lab_machine_result->abnormal_flag);
$test_code = explode(",", $lab_machine_result->test_code);
$machine_id = $lab_machine_result->machine_id;
$test_ids = [];
$test_flag = [];
$test_results = [];
for ($i = 0; $i < count($test_code); $i++) {
$filters = [];
if (is_integer($machine_id)) {
$filters[] = ['machine_name', '=', $machine_id];
}
$test_id = DB::table("investigation_test_codes")
->where("test_code", $test_code[$i])
->where($filters)->first()?->investigation_id;
if (is_numeric($test_id)) {
$test_flag[] = ($flag[$i] == "N") ? "" : $flag[$i];
$test_ids[] = $test_id;
$test_results[] = $results[$i];
}
}
if (count($test_ids) > 0) {
$correct_ids_array = [];
$correct_values_array = [];
$correct_comments_array = [];
$parent_investigation_id = get_name($test_ids[0], 'id', 'investigation_id', 'investigation_specialised_variables');
$specialized_variables = DB::table('investigation_specialised_variables')->whereNull('deleted_at')->where('investigation_id', $parent_investigation_id)->orderBy('ranking','asc')->get();
foreach ($specialized_variables as $variable) {
$key = array_search($variable->id, $test_ids);
if (is_integer($key)) {
$correct_ids_array[] = $test_ids[$key];
$correct_values_array[] = $test_results[$key];
$correct_comments_array[] = $test_flag[$key];
}
}
$this->map_machine_results_to_patient($correct_ids_array, $sample_id, $correct_values_array, $correct_comments_array);
flash("Results have been imported successfully")->success();
} else {
flash("Results not imported because the test codes are missing")->error();
}
return redirect('/investigations/view_lab_results_details/' . $sample_id);
}
public function map_machine_results_to_patient($test_ids, $sample_id, $results, $comments) {
// get investigation order details
$investigation_order = OrderedInvestigation::find($sample_id);
$parent_investigation_id = get_name($test_ids[0], 'id', 'investigation_id', 'investigation_specialised_variables');
if ($investigation_order){
// investigation ids
$investigation_ids = explode(",", $investigation_order->investigation_id);
// check if investigations results are available
$investigation_result = InvestigationResults::where('order_id', $sample_id)->first();
if ($investigation_result){
// edit the results
$investigation_result->updated_by = Auth::id();
$values_array = explode(",", $investigation_result->value);
$comments_array = explode(",", $investigation_result->comment);
$specialised_results_id = $values_array[array_search($parent_investigation_id, $investigation_ids)];
if (InvestigationSpecialisedResult::find($specialised_results_id)) {
$investigation_specialised_results = InvestigationSpecialisedResult::find($specialised_results_id);
} else {
$investigation_specialised_results = new InvestigationSpecialisedResult();
$investigation_specialised_results->created_by = Auth::id();
}
$investigation_specialised_results->specialised_variable_id = implode(',', $test_ids);
$investigation_specialised_results->value = implode(',', $results);
$investigation_specialised_results->comment = implode(',', $comments);
$investigation_specialised_results->updated_by = Auth::id();
$investigation_specialised_results->save();
$values_array[array_search($parent_investigation_id, $investigation_ids)] = $investigation_specialised_results->id;
$comments_array[array_search($parent_investigation_id, $investigation_ids)] = "-";
$investigation_result->value = implode(",", $values_array);
$investigation_result->comment = implode(",", $comments_array);
$investigation_result->save();
} else {
// add new results to the table
$order = new InvestigationResults;
$order->per_investigation = implode(",", array_fill(0, count($investigation_ids), '0'));
$order->all_authenticated = 0;
$order->order_id = $sample_id;
$order->patient_id = $investigation_order->patient_id;
$order->episode_id = $investigation_order->episode_id;
$order->created_by = Auth::id();
$order->inpatient = 0;
$order->result_type = $investigation_order->order_type;
$values_array = array_fill(0, count($investigation_ids), '');
$comments_array = array_fill(0, count($investigation_ids), '');
$investigation_specialised_results = new InvestigationSpecialisedResult();
$investigation_specialised_results->specialised_variable_id = implode(',', $test_ids);
$investigation_specialised_results->value = implode(',', $results);
$investigation_specialised_results->comment = implode(',', $comments);
$investigation_specialised_results->created_by = Auth::id();
$investigation_specialised_results->updated_by = Auth::id();
$investigation_specialised_results->save();
$values_array[array_search($parent_investigation_id, $investigation_ids)] = $investigation_specialised_results->id;
$comments_array[array_search($parent_investigation_id, $investigation_ids)] = "-";
$order->investigation_id = $investigation_order->investigation_id;
$order->value = implode(",", $values_array);
$order->comment = implode(",", $comments_array);
// save the order
$order->save();
}
}
}
public function view_lab_machine_results(Request $request) {
$search_text = "";
$filters = [];
// if patient id is active, get all records regardless of date; else search by date
if (isset($request->lab_number) && $request->lab_number != '') {
$filters[] = ['sample_id', '=', $request->lab_number];
$search_text .= "Lab Number: " . $request->lab_number;
} else {
switch ($request->search_date_by){
case 'yesterday':
$end_date = Carbon::yesterday()->endOfDay();
$start_date = Carbon::yesterday()->startOfDay();
$search_text .= "Yesterday ";
break;
case 'custom_date':
$end_date = Carbon::parse($request->start_date)->endOfDay();
$start_date = Carbon::parse($request->start_date)->startOfDay();
$search_text .= "From: " . streamline_date($start_date) . " ";
break;
case 'custom_date_range':
$end_date = Carbon::parse($request->end_date)->endOfDay();
$start_date = Carbon::parse($request->start_date)->startOfDay();
$search_text .= "From: " . streamline_date($start_date) . " to " . streamline_date($end_date) . " ";
break;
case 'today':
default:
$end_date = Carbon::today()->endOfDay();
$start_date = Carbon::today()->startOfDay();
$search_text .= "Today ";
break;
}
$filters[] = ['created_at', '>', $start_date];
$filters[] = ['created_at', '<', $end_date];
}
$results = LabMachineResult::where($filters)->get();
$lab_machines = LabInstrument::pluck("name", "id")->prepend('- select -', '');
return view('investigations::lab_instruments.view_lab_machine_results', compact('results', 'search_text', 'lab_machines'));
}
public function restart_python_script(Request $request) {
$lab_instrument = LabInstrument::find($request->lab_instrument);
if(!$lab_instrument || is_null($lab_instrument->restart_lis_path)) {
flash("Could not find the lab instrument selected")->error();
return back()->withInput();
}
// 'public/uploads/lab_machine_scripts/kisiizi/restart_lis.py'
$process = new Process(['python3', base_path($lab_instrument->restart_lis_path)]);
$process->run();
$process->wait();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$lab_machine_restart = new LabMachineRestart();
if (strpos($process->getOutput(), '1') !== false) {
flash("Lab integration has been restarted successfully")->success();
$lab_machine_restart->result = $process->getOutput();
} else {
flash("An error occurred while establishing a connection. Please contact the Stre@mline team")->error();
$lab_machine_restart->result = $process->getErrorOutput();
}
$lab_machine_restart->created_by = Auth::id();
$lab_machine_restart->save();
return redirect('lab_machines/view_lab_machine_results');
}
public function preview_lab_machine_results($id) {
$result = LabMachineResult::find($id);
$html_text = "<table class='table table-bordered table-striped'>";
$test_code_array = explode(",", $result->test_code);
$flag_array = explode(",", $result->abnormal_flag);
$results_array = explode(",", $result->results);
$html_text .= "<tr>";
$html_text .= "<th style='color: black' class='text-center'> Test Code </th>";
$html_text .= "<th style='color: black' class='text-center'> Specialised Variable </th>";
$html_text .= "<th style='color: black' class='text-center'> Result </th>";
$html_text .= "<th style='color: black' class='text-center'> Flag </th>";
$html_text .= "</tr>";
for ($i = 0; $i < count($test_code_array); $i++) {
$specialised_variable_id = get_name($test_code_array[$i], 'test_code', 'investigation_id', 'investigation_test_codes');
$specialised_variable_name = get_name($specialised_variable_id, 'id', 'name', 'investigation_specialised_variables');
$html_text .= "<tr>";
$html_text .= "<td class='text-center'>" . $test_code_array[$i] . "</td>";
$html_text .= "<td class='text-center'>" . $specialised_variable_name . "</td>";
$html_text .= "<td class='text-center'>" . $results_array[$i] . "</td>";
$html_text .= "<td class='text-center'>" . $flag_array[$i] . "</td>";
$html_text .= "</tr>";
}
$html_text .= "</table>";
return json_encode(["html" => $html_text]);
}
}
@@ -0,0 +1,174 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Http\Request;
use Streamline\Models\LaboratorySpecimen;
use Illuminate\Support\Facades\Validator;
class LaboratorySpecimenController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('permission:lab_specimen-list', ['only' => ['index']]);
$this->middleware('permission:lab_specimen-detail', ['only' => ['show']]);
$this->middleware('permission:lab_specimen-create', ['only' => ['create', 'store']]);
$this->middleware('permission:lab_specimen-edit', ['only' => ['edit', 'update']]);
$this->middleware('permission:lab_specimen-delete', ['only' => ['destroy']]);
$this->middleware('permission:lab_specimen-status', ['only' => ['activate, inactive']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$lab_specimens = LaboratorySpecimen::orderBy('name', 'asc')->paginate(50);
return view('investigations::laboratory_specimen.index',compact('lab_specimens'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('investigations::laboratory_specimen.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|unique:laboratory_specimens'
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
} else {
$specimen = new LaboratorySpecimen;
$specimen->name = $request->name;
$specimen->save();
if (isset($request->other_specimen_names)) {
$other_specimens_array = $request->other_specimen_names;
for ($i=0; $i < count($other_specimens_array) ; $i++) {
if (!is_null($other_specimens_array[$i]) && $other_specimens_array[$i] != "") {
$lab_specimen = new LaboratorySpecimen;
$lab_specimen->name = $other_specimens_array[$i];
$lab_specimen->created_by = auth()->user()->id;
$lab_specimen->updated_by = auth()->user()->id;
$lab_specimen->save();
}
}
}
flash('New specimen added successfully')->success();
return redirect('laboratory_specimen');
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$lab_specimen = LaboratorySpecimen::find($id);
if (!$lab_specimen) {
flash()->error("There is no such specimen");
return redirect('laboratory_specimen');
} else {
return view('investigations::laboratory_specimen.edit', compact('lab_specimen'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$lab_specimen = LaboratorySpecimen::find($id);
$lab_specimen->name = $request->name;
$lab_specimen->update();
flash('successfully updated details for '.$lab_specimen->name)->success();
return redirect('laboratory_specimen');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$lab_specimen = LaboratorySpecimen::find($id);
if ($lab_specimen->delete()) {
flash($lab_specimen->name. ' has been successfully deleted')->success();
return redirect('laboratory_specimen');
}
flash('error occurred. Contact system admin')->error();
return redirect()->back()->withInput();
}
/*
*Display inactive bed categories
*/
public function inactive()
{
$lab_specimens = LaboratorySpecimen::onlyTrashed()->orderBy('name','asc')->paginate(50);
if (count($lab_specimens) < 1) {
flash()->error("There is no inactive specimens");
return redirect('laboratory_specimen');
} else {
return view('investigations::laboratory_specimen.inactive', compact('lab_specimens'));
}
}
/*
* Activate an inactive inpatient bed category
*/
public function activate($id)
{
$lab_specimens = LaboratorySpecimen::withTrashed()->find($id);
if ($lab_specimens->restore()):
flash("Specimen has been activated.")->success();
return redirect('/inactive/laboratory_specimen/');
endif;
}
}
@@ -0,0 +1,700 @@
<?php
namespace Modules\Investigations\Http\Controllers;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Streamline\Models\Radiology;
use Streamline\Models\ChartOfAccount;
use Illuminate\Support\Facades\Auth;
use Streamline\Models\HospitalInformation;
use Illuminate\Support\Facades\Validator;
use Streamline\Models\RadiologyUsage;
use Illuminate\Support\Facades\DB;
use Streamline\Models\Requisition;
use Illuminate\Support\Carbon;
use Streamline\Models\GeneralForm;
class RadiologyController extends Controller
{
function __construct() {
$this->middleware('permission:radiologies-management', ['only' => ['index']]);
$this->middleware('permission:radiologies-create', ['only' => ['create', 'store']]);
$this->middleware('permission:radiologies-edit', ['only' => ['edit', 'update']]);
$this->middleware('permission:radiologies-delete', ['only' => ['destroy']]);
$this->middleware('permission:radiologies-usage-listing',['only'=>['radiology_usage_listing','store_radiology_usage']]);
$this->middleware('permission:radiologies-report-usage', ['only'=>['radiology_usages_report']]);
$this->middleware('permission:radiologies-stock-sheet', ['only'=>['radiology_stock_sheet']]);
$this->middleware('permission:requisition-for-radiologies', ['only'=>['requisition_for_radiologies','update_imaging_stock_sheet']]);
}
public function index()
{
$radiologies = Radiology::orderBy('name', 'asc')->get();
$chart_of_accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id');
$accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$radiologies= get_all_batch_details($radiologies,['store_stock','lab_stock'],['store_batches','lab_batches'],['total_store_stock','total_lab_stock'],4);
return view('investigations::radiologies.index', compact('radiologies', 'chart_of_accounts', 'accounts'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$forms = ['' => '- select -'] + GeneralForm::where('item_type',4)->pluck('name', 'id')->toArray();
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ['' => '- select -'] + $payables_accounts;
return view('investigations::radiologies.create', compact('cost_of_goods_accounts','forms', 'payables_accounts', 'expense_accounts'));
}
//edit all radiologies
public function edit_all(){
$cost_of_goods_accounts = ChartOfAccount::where(['type' => 7])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expense_accounts = ChartOfAccount::where(['type' => 2])
->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$payables_accounts = ChartOfAccount::where(['type' => 6])
->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$forms = ['' => '- select -'] + GeneralForm::where('item_type',4)->pluck('name', 'id')->toArray();
$cost_of_goods_accounts = ['' => '- select -'] + $cost_of_goods_accounts;
$expense_accounts = ['' => '- select -'] + $expense_accounts;
$payables_accounts = ['' => '- select -'] + $payables_accounts;
$radiologies = Radiology::orderBy('name', 'asc')->get();
return view('investigations::radiologies.edit_all', compact('cost_of_goods_accounts','radiologies','forms', 'payables_accounts', 'expense_accounts'));
}
//update all radiologies
public function update_all(Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required',
'cost_price' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
} else {
$logged_in_user_id = Auth::user()->id;
$id_array = $request->id;
$name_array = $request->name;
$cost_price_array = $request->cost_price;
$payables_account_id_array = $request->payables_account_id;
$expenses_account_id_array = $request->expenses_account_id;
$form_id_array = $request->form_id;
$re_order_level_array = $request->re_order_level;
for ($x = 0; $x < count($id_array); $x++):
$radiology = Radiology::find($id_array[$x]);
$radiology->name = $name_array[$x];
$radiology->cost_price = $cost_price_array[$x];
$radiology->payables_account_id = $payables_account_id_array[$x];
$radiology->expenses_account_id = $expenses_account_id_array[$x];
$radiology->form_id = $form_id_array[$x];
$radiology->reorder_level = $re_order_level_array[$x];
$radiology->updated_by = $logged_in_user_id;
try {
$radiology->save();
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
endfor;
flash("Radiology has been updated")->success();
return redirect("/radiology/");
}
}
//function to add Radiology form
public function create_radiology_form()
{
return view('investigations::radiologies.create_radiology_form');
}
//functiion to store radiology form
public function store_radiology_form (Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
} else {
$data['name']=$request->name;
$data['type']= 4;
try{
//create new radiology form
$new_form = GeneralForm::add_new_form((object)$data);
if($new_form){
flash("Radiology form has been created successfully")->success();
return redirect('/radiology');
}
}catch (QueryException $e){
flash("Something went wrong. Please try again")->error();
return back()->withInput();
}
}
}
//edit form
public function edit_form($id){
$form = GeneralForm::find($id);
if (!$form) flash()->error("Sundry Form not found");return redirect()->route('radiology_forms.all');
return view('investigations::radiologies.edit_radiology_form', compact('form'));
}
//update form
public function update_radiology_form(Request $request, $id){
$validator = Validator::make($request->all(), [
'name' => 'required',
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
} else {
$data['name']=$request->name;
$data['type']= 4;
try{
//update radiology form
$form = GeneralForm::find($id);
$form->update($data);
flash("Radiology form has been updated successfully")->success();
return redirect('/radiology_forms');
}catch (QueryException $e){
flash("Something went wrong. Please try again")->error();
return back()->withInput();
}
}
}
//delete form
public function delete_form($id){
try{
//delete radiology form
$form = GeneralForm::find($id);
$form->delete();
flash("Radiology form has been deleted successfully")->success();
return redirect('/radiology_forms');
}catch (QueryException $e){
flash("Something went wrong. Please try again")->error();
return back()->withInput();
}
}
//show inactive forms
public function inactive_forms(){
$inactive_forms = GeneralForm::onlyTrashed()
->where('item_type', 4)
->orderBy('name', 'asc')
->get();
if (count($inactive_forms) < 1) {
flash()->error("There is no inactive Radiology forms");
return redirect('radiology_forms');
}
return view('investigations::radiologies.inactive_radiology_forms', compact('inactive_forms'));
}
// reactivate form
public function activate_form($id) {
$lab_form = GeneralForm::withTrashed()->find($id);
if($lab_form->restore()){
flash("Radiology Form has been activated.")->success();
return redirect('/radiology_forms');
}
}
//get all radiology forms
public function get_all_radiology_form(){
$all_forms = GeneralForm::get_all_forms_type(4);
return view('investigations::radiologies.all_radiology_form',compact('all_forms'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
request()->validate([
'name' => 'required',
'cost_price' => 'required'
]);
$radiology = new Radiology();
$logged_in_user_id = Auth::user()->id;
$radiology->name = $request->name;
$radiology->cost_price = $request->cost_price;
$radiology->expenses_account_id = $request->expenses_account_id;
$radiology->payables_account_id = $request->payables_account_id;
$radiology->form_id = $request->form_id;
$radiology->reorder_level = $request->re_order_level;
$radiology->created_by = $logged_in_user_id;
$radiology->updated_by = $logged_in_user_id;
try {
$radiology->save();
flash("Radiology has been saved")->success();
return redirect("/radiology/");
} catch (QueryException $e) {
flash("Something went wrong. Please try again")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$radiology = Radiology::where(['id' => $id])->first();
$payables_accounts = ChartOfAccount::where(['type' => 6])->orWhere(['type' => 9])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expenses_accounts = ChartOfAccount::where(['type' => 2])->orderBy('name', 'asc')->pluck('name', 'id')->toArray();
$expenses_accounts = ['' => '- select -'] + $expenses_accounts;
$payables_accounts = ['' => '- select -'] + $payables_accounts;
$forms = ['' => '- select -'] + GeneralForm::where('item_type',4)->pluck('name', 'id')->toArray();
if (!$radiology) {
flash()->error("Radiology not found");
return redirect('/radiology/');
} else {
return view('investigations::radiologies.edit', compact('radiology', 'forms','payables_accounts', 'expenses_accounts'));
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
request()->validate([
'name' => 'required',
'cost_price' => 'required',
]);
//validation passed
$radiology = Radiology::find($id);
$logged_in_user_id = Auth::user()->id;
$radiology->name = $request->name;
$radiology->cost_price = $request->cost_price;
$radiology->expenses_account_id = $request->expenses_account_id;
$radiology->payables_account_id= $request->payables_account_id;
$radiology->form_id = $request->form_id;
$radiology->reorder_level = $request->re_order_level;
$radiology->updated_by = $logged_in_user_id;
try {
$radiology->save();
flash("Radiology has been updated")->success();
return redirect("/radiology/");
} catch (QueryException $e) {
flash("An error occurred")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$radiology = Radiology::find($id);
if ($radiology->delete()) {
flash("The item has been deleted.")->success();
return redirect('/radiology/');
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
*/
public function inactive() {
$radiologies = Radiology::onlyTrashed()->get();
$accounts = ChartOfAccount::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
if (count($radiologies) < 1) {
flash()->error("There is no inactive Radiology");
return redirect('/radiology/');
} else {
return view('investigations::radiologies.inactive', compact('radiologies', 'accounts'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function activate($id) {
$radiology = Radiology::withTrashed()->find($id);
if($radiology->restore()){
flash("A Radiology has been activated.")->success();
return redirect('/radiology/inactive');
}
}
public function radiology_usage_listing(){
$radiologies = DB::table('radiologies')->orderBy('name', 'asc')->where('deleted_at', '=',null)->get();
$hospital_information = HospitalInformation::first();
return view('investigations::radiologies.radiology_usage', compact('radiologies', 'hospital_information'));
}
public function store_radiology_usage(Request $request){
$lab_counter = 0;
$radiologies_item_array = $request->labItem;
$available_qty_array = $request->availableQty;
$available_qty_unit_cost_array = $request->unitCost;
$usage_qty_array = $request->requiredQty;
$usage_qty_cost_array = $request->totalCost;
if($request->dates == 'today'){
$start = Carbon::now()->startOfDay()->toDateTimeString();
$end = Carbon::now()->endOfDay()->toDateTimeString();
}else{
$start = Carbon::parse($request->start_date)->endOfDay()->toDateTimeString();
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
}
for($i = 0; $i < count($radiologies_item_array); $i++){
if($radiologies_item_array[$i]){
if(track_items_using_batches()){
$datat=get_lab_batches_to_use_based_on_needed_quantity($radiologies_item_array[$i],4,$usage_qty_array[$i],'lab_stock');
$cost_value=0;
foreach ($datat as $key=> $val){
$unit_cost_value =(int) get_name($key, 'id', 'cost_price', 'item_batch_watcher');
//caluclate cost value
$cost_value += $unit_cost_value * $val;
reduce_batch_item_stock(4,$radiologies_item_array[$i], $key, 'radiologies', 'lab_stock', $val, 'radiology_usages','Imaging', null, null);
}
$usage_qty_cost_array[$i]=$cost_value;
}
$remaining_qty = record_radiology_usage_listing($radiologies_item_array[$i],$available_qty_unit_cost_array[$i], $available_qty_array[$i],$usage_qty_array[$i], $usage_qty_cost_array[$i],
$start,$end);
if(!($remaining_qty < 0)){
$radiology = Radiology::find($radiologies_item_array[$i]);
$radiology->pharmacy_stock = ($radiology->pharmacy_stock - (int)$usage_qty_array[$i]);
$radiology->save();
}else{
flash('Item\'s '.get_name($radiologies_item_array[$i], 'id', 'name', 'labs').' requested use quantity exceeds what is available.');
}
}
}
flash('Radiologies Used from '.streamline_date($start).' to '.streamline_date($end).' have saved successfully')->success();
return redirect('/radiology_listing');
}
public function get_radiology_quantity(Request $request){
if (track_items_using_batches()){
// that is if batches is enabled
$lab_stock =track_batch_stock(4,$request->id,'lab_stock');
$total_stock = 0;
foreach ($lab_stock as $lab) {
$total_stock += $lab->lab_stock;
}
$data = [
'pharmacy_stock' => $total_stock,
'cost_price' => $lab_stock[0]->cost_price??0,
];
return $data;
}
return Radiology::where('id', $request->id)->first();
}
public function requisition_for_radiologies(Request $request)
{
$results = Radiology::orderBy('name','asc')->get();
$names_array = Radiology::orderBy('name')->distinct()->pluck('name');
$labs = Radiology::orderBy('name')->pluck('name', 'id');
$date_filter = [];
if(isset($request->start_date) && isset($request->end_date)){
if (isset($request->quotation_type)) {
$item_type = $request->quotation_type;
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>', $start_date]);
array_push($date_filter, ['created_at', '<', $end_date]);
}
} else {
$date_from = Carbon::today()->subDays(30)->format('Y-m-d');
$date_to = Carbon::today()->addDays(1)->format('Y-m-d');
array_push($date_filter, ['created_at', '>', $date_from]);
array_push($date_filter, ['created_at', '<', $date_to]);
}
$previous_requisitions_results = Requisition::where('quotation_type_id', '=', 4)->where($date_filter)->orderBy('created_at','desc')->get();
$results = get_all_batch_details($results,['store_stock','lab_stock'],['store_batches','lab_batches'],['total_store_stock','total_lab_stock'],4);
return view('investigations::radiologies.requisition_for_radiologies', compact('results', 'names_array', 'labs', 'previous_requisitions_results'));
}
public function previous_requisition_for_radiologies(Request $request){
$search_by = $request->search_by;
$reg_date = $request->reg_date;
$start_date = $request->start_date;
$end_date = $request->end_date;
$date_filter = [];
$search_string = "";
if ($search_by == 0) {
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($date_filter, ['created_at', '>=', $last_day]);
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($last_day) . "</h4>";
} elseif ($search_by == 1) {
// custom date
if (is_null($request->reg_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$selected_date_filter = Carbon::createFromFormat('d/m/Y', $request->reg_date)->toDateString();
array_push($date_filter, ['created_at', '=',$selected_date_filter]);
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($selected_date_filter) . "</h4>";
} elseif ($search_by == 2) {
// custom date range
if (is_null($start_date) || is_null($end_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$start_date_search = Carbon::createFromFormat('d/m/Y', $start_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::createFromFormat('d/m/Y', $end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>=', $start_date_search]);
array_push($date_filter, ['created_at', '<=', $end_date_search]);
$search_string = "<h4 class='label label-info'>Showing between " . streamline_date($start_date_search) . " and " . streamline_date($end_date_search) . "</h4>";
} else {
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($date_filter, ['created_at', '>=', $last_day]);
$search_string = "<h4 class='label label-info'>Showing results of " . streamline_date($last_day) . "</h4>";
}
$previous_requisitions_results = Requisition::where('quotation_type_id', '=', 4)->where($date_filter)->orderBy('created_at','desc')->get();
return view('investigations::radiologies.prev_requisition_for_radiologies', compact('previous_requisitions_results','search_string'));
}
public function store_radiology_requisitions(Request $request)
{
$drug_id_array = $request->drug_id;
$quantity_array = $request->quantity;
$item_type = $request->item_type;
$user_id = Auth::id();
/* return back if no quantity has been filled */
if (array_sum($quantity_array) < 1) {
flash('Please insert some values!')->error();
return redirect()->back()->withInput();
}
if (isset($request->complete_request)) {
$filtered_drugs_array = [];
$filtered_quantities_array = [];
$associative_requested_drugs_array = [];
for ($i=0; $i < count($drug_id_array) ; $i++) {
if ($quantity_array[$i] != "") {
$associative_requested_drugs_array[$drug_id_array[$i]] = $quantity_array[$i];
$filtered_drugs_array[] = $drug_id_array[$i];
$filtered_quantities_array[] = $quantity_array[$i];
}
}
$new_requisition = new Requisition;
$new_requisition->quotation_type_id = $item_type;
$new_requisition->drug_id = implode(',', $filtered_drugs_array);
$new_requisition->quantity_requested = implode(',', $filtered_quantities_array);
$new_requisition->created_by = $user_id;
$new_requisition->requisition_origin= 3; // 1-pharmacy, 2-lab, 3-imaging
$new_requisition->save();
flash('Requisition number ' . $new_requisition->id . ' made successfully')->success();
//redirect to requisition
return redirect('/print_requisition_receipt/' . $new_requisition->id);
}
}
/* filter out items to requisition */
public function requisition_for_radiology_search(Request $request)
{
$item_type = $request->item_type;
$item_ids_array = $request->items_ids;
$results = null;
$filters = [];
$items = null;
$results = Radiology::whereIn('id', $item_ids_array)->orderBy('name','asc')->get();
$labs = Radiology::orderBy('name')->pluck('name', 'id');
$date_filter = [];
if(isset($request->start_date) && isset($request->end_date)){
if (isset($request->quotation_type)) {
$item_type = $request->quotation_type;
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
array_push($date_filter, ['created_at', '>', $start_date]);
array_push($date_filter, ['created_at', '<', $end_date]);
}
} else {
$date_from = Carbon::today()->subDays(30)->format('Y-m-d');
$date_to = Carbon::today()->addDays(1)->format('Y-m-d');
array_push($date_filter, ['created_at', '>', $date_from]);
array_push($date_filter, ['created_at', '<', $date_to]);
}
$previous_requisitions_results = Requisition::where('quotation_type_id', '=', 5)->where($date_filter)->orderBy('created_at','desc')->get();
$results = get_all_batch_details($results,['store_stock','lab_stock'],['store_batches','lab_batches'],['total_store_stock','total_lab_stock'],4);
return view('investigations::radiologies.requisition_for_radiologies',compact('items','item_type','labs','results','previous_requisitions_results'));
}
public function radiology_usages_report(Request $request)
{
$radiologies = DB::table('radiologies')->orderBy('name', 'asc')->where('deleted_at', '=',null)->get();
$hospital_information = HospitalInformation::first();
$radiologies_options = DB::table('radiologies')->orderBy('name', 'asc')->pluck('name', 'id')->prepend('- All Radiologies - ', 'all_radiologies');
$search_by = $request->search_by;
$reg_date = $request->reg_date;
$start_date = $request->start_date;
$end_date = $request->end_date;
$filters = [];
$search_string = "";
if ($search_by == 0) {
// last 24 hours
$last_day = Carbon::now()->subDay();
array_push($filters, ['start_date', '>=', $last_day]);
if ($request->radiology_id != 'all_radiologies') {
array_push($filters, ['radiology_id', '=', $request->radiology_id]);
}
$search_string = "<h4 class='label label-info'>Showing results of ".streamline_date($last_day)."</h4>";
} elseif ($search_by == 1) {
// custom date
if (is_null($request->reg_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$selected_date_filter = Carbon::createFromFormat('d/m/Y', $request->reg_date)->toDateString();
array_push($filters, ['start_date', $selected_date_filter]);
if ($request->radiology_id != 'all_radiologies') {
array_push($filters, ['radiology_id', '=', $request->radiology_id]);
}
$search_string = "<h4 class='label label-info'>Showing results of ".streamline_date($selected_date_filter)."</h4>";
} elseif ($search_by == 2) {
// custom date range
if (is_null($start_date) || is_null($end_date)) {
flash('Please select a date')->error();
return redirect()->back();
}
$start_date_search = Carbon::createFromFormat('d/m/Y', $start_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::createFromFormat('d/m/Y', $end_date)->endOfDay()->toDateTimeString();
array_push($filters, ['start_date', '>=', $start_date_search]);
array_push($filters, ['end_date', '<=', $end_date_search]);
if ($request->radiology_id != 'all_radiologies') {
array_push($filters, ['radiology_id', '=', $request->radiology_id]);
}
$search_string = "<h4 class='label label-info'>Showing between ".streamline_date($start_date_search). " and ".streamline_date($end_date_search)."</h4>";
}
$radiologies_usages = RadiologyUsage::where($filters)->orderBy('id','desc')->limit(500)->get();
return view('investigations::radiologies.radiology_usages_report', compact( 'hospital_information', 'radiologies_usages', 'radiologies_options', 'search_string'));
}
//radiology stock sheet
public function radiology_stock_sheet()
{
$radiologies = DB::table('radiologies')->whereNull('deleted_at')->orderBy('name', 'asc')->get();
// getting the radiology stock batches
$radiologies= calculate_stock_value($radiologies,4,'lab_stock');
if (empty($radiologies)) {
flash()->error("There is out of stock of labs");
return redirect('/radiology/');
} else {
return view('investigations::radiologies.radiology_stock_sheet', compact('radiologies'));
}
}
public function update_imaging_stock_sheet(Request $request){
$radio_ids_array = $request->lab_id;
$quantities_array = $request->quantity;
$expiry_dates_array = $request->expiry_date;
$batch_numbers_array = $request->batch_number;
$batch_unit_cost = $request->batch_unit_cost;
$batch_quantity_balances_array = $request->batch_quantity_balance;
$batch_db_record_ids_array = $request->batch_drug_id;
$batch_expiry_dates_array = $request->expiry_date;
$batch_drug_ids_array = $request->batch_item_id;
//update batch tracking tables with reconciliations
for ($i=0; $i < count($batch_numbers_array) ; $i++) {
if (!is_null($batch_numbers_array[$i]) && !is_null($batch_quantity_balances_array[$i]) ){
reconcile_batches(4, $batch_drug_ids_array[$i], $batch_numbers_array[$i], $batch_quantity_balances_array[$i], $batch_expiry_dates_array[$i], "lab", $batch_unit_cost[$i], $batch_db_record_ids_array[$i]??0, null);
}
}
for ($i = 0; $i < count($radio_ids_array); $i++) {
$lab = Radiology::withTrashed()->find($radio_ids_array[$i]);
$lab->pharmacy_stock = $quantities_array[$i];
// $lab->expiry_date = $expiry_dates_array[$i];
$lab->save();
}
flash('stock sheet has been updated')->success();
return redirect('radiology_stock_sheet');
}
}