Files
streamline-emr/docker/streamline-src/app/Http/Controllers/BloodDonationsController.php
T
alec.turner 4a89356390 Import latest app updates from streamline
An updated set of source files and initialization was provided by streamline to
address issues observed during initial testing. These files have been updated in
order to generate a new set of app images.
2024-04-11 11:16:51 -07:00

133 lines
3.9 KiB
PHP
Executable File

<?php
namespace Streamline\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Streamline\Models\BloodDonation;
use Streamline\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class BloodDonationsController extends Controller {
public function __construct() {
$this->middleware('auth');
$this->middleware('permission:find-a-donor', ['only' => ['index']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$willing_donors = User::where(['willing_to_donate' => 1])->orderBy('blood_group_id', 'asc')->get();
$blood_groups = DB::table('blood_groups')
// ->where('active', 1)
->pluck("name", "id")
->prepend('- Select -', '');
return view('blood_donations.index', compact('willing_donors', 'blood_groups'));
}
/*
* Show the donors of selected blood group
*/
public function select_blood_group(Request $request) {
$willing_donors = User::where(['blood_group_id' => $request->blood_group_id, 'willing_to_donate' => 1])->orderBy('blood_group_id', 'asc')->get();
$blood_groups = DB::table('blood_groups')
// ->where('active', 1)
->pluck("name", "id")
->prepend('- Select -', '');
return view('blood_donations.index', compact('willing_donors', 'blood_groups'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
$donor_id = session()->get('donor_id');
$donor = User::find($donor_id);
return view('blood_donations.create', compact('donor'));
}
/*
* put the donor_id(same as $user->id) into a session then redirect to $this->create() function
*/
public function create_donation(Request $request) {
$selected_donor_id = $request->donor_id;
$donor_id = session()->put(['donor_id' => $selected_donor_id]);
return redirect('blood_donations/create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
$donation_date = Carbon::createFromFormat('d/m/Y', $request->donation_date)->toDateString();
$donor_id = $request->donor_id;
$new_blood_donation = new BloodDonation;
$new_blood_donation->donor_id = $donor_id;
$new_blood_donation->last_donation_date = $donation_date;
$new_blood_donation->created_by = Auth::id();
if ($new_blood_donation->save()) {
flash('New blood donation has been succesfully recorded')->success();
return redirect('blood_donations');
}
flash('error occured. Contact system admiin')->error();
return redirect()->back()->withInput();
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
$donor = User::find($id);
$blood_donations = BloodDonation::where('donor_id', $id)->orderBy('last_donation_date', 'desc')->get();
return view('blood_donations.show', compact('donor', 'blood_donations'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
//
}
}