mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 10:41:32 +00:00
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.
316 lines
14 KiB
PHP
Executable File
316 lines
14 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Streamline\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Streamline\Models\District;
|
|
use Streamline\Models\HospitalInformation;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\File;
|
|
use Streamline\Models\Parish;
|
|
use Streamline\Models\Subcounty;
|
|
use Streamline\Models\StreamlineSetupStep;
|
|
|
|
//use Illuminate\Database\QueryException;
|
|
|
|
class HospitalInformationController extends Controller {
|
|
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('permission:hospital_information-edit', ['only' => ['edit', 'update']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index() {
|
|
return redirect('hospital_information/1/edit');
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create() {
|
|
$districts = District::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
$parishes = Parish::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
$subcounties = Subcounty::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
$districts = ['' => '- select -'] + $districts;
|
|
$parishes = ['' => '- select -'] + $parishes;
|
|
$subcounties = ['' => '- select -'] + $subcounties;
|
|
|
|
return view('hospital_information.create', compact('districts', 'parishes', 'subcounties'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request) {
|
|
//dd($request->all());
|
|
$validator = Validator::make($request->all(), [
|
|
'email' => 'required|email',
|
|
'level' => 'required',
|
|
'phone_number' => 'required',
|
|
'country' => 'required',
|
|
'patient_number_abbr' => 'required',
|
|
'name' => 'required',
|
|
'back_date' => 'required|numeric|min:0',
|
|
'address' => 'required',
|
|
'stamp' => 'nullable|file|mimes:jpg,jpeg,bmp,png,gif,svg,webp',
|
|
'lab_stamp' => 'nullable|file|mimes:jpg,jpeg,bmp,png,gif,svg,webp',
|
|
'logo' => 'nullable|file|mimes:jpg,jpeg,bmp,png,gif,svg,webp'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
flash($string)->error();
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
|
|
$hospital_information = new HospitalInformation;
|
|
$hospital_information->name = $request->name;
|
|
$hospital_information->level = $request->level;
|
|
$hospital_information->email = $request->email;
|
|
$hospital_information->code = $request->code;
|
|
$hospital_information->district = $request->district;
|
|
$hospital_information->parish = $request->parish;
|
|
$hospital_information->sub_county = $request->sub_county;
|
|
$hospital_information->sub_district = $request->sub_district;
|
|
$hospital_information->address = $request->address;
|
|
$hospital_information->website = $request->website;
|
|
$hospital_information->country = $request->country;
|
|
$hospital_information->app_name = $request->app_name;
|
|
$hospital_information->back_date = $request->back_date;
|
|
$hospital_information->app_version = $request->app_version;
|
|
$hospital_information->patient_number_abbr = $request->patient_number_abbr;
|
|
$hospital_information->financial_year_start_date = $request->financial_year_start_date;
|
|
|
|
$logo = $request->file('logo');
|
|
$logo_destination_path = $logo_name = '';
|
|
if ($logo) {
|
|
$logo_name = date("Ymd_H-i-s") . '_' . $logo->getClientOriginalName();
|
|
$logo_destination_path = 'uploads/logo/';
|
|
$random = '';
|
|
do {
|
|
$logo_name = date("Ymd_H-i-s") . '_' . Str::slug($logo->getClientOriginalName()) . $random . '.'
|
|
. File::extension($logo->getClientOriginalName());
|
|
$random = Str::random(6);
|
|
}
|
|
while (File::exists($logo_destination_path.$logo_name));
|
|
|
|
$logo->move($logo_destination_path, $logo_name);
|
|
}
|
|
$current_logo = $request->current_logo;
|
|
$new_logo = $logo_destination_path . $logo_name;
|
|
$hospital_information->logo = $new_logo ? $new_logo : $current_logo;
|
|
|
|
$stamp = $request->file('stamp');
|
|
$stamp_destination_path = $stamp_name = '';
|
|
if ($stamp) {
|
|
$stamp_name = date("Ymd_H-i-s") . '_' . $stamp->getClientOriginalName();
|
|
$stamp_destination_path = 'uploads/logo/';
|
|
$random = '';
|
|
do {
|
|
$stamp_name = date("Ymd_H-i-s") . '_' . Str::slug($stamp->getClientOriginalName()) . $random . '_stamp.'. File::extension($stamp->getClientOriginalName());
|
|
$random = Str::random(6);
|
|
}
|
|
while (File::exists($stamp_destination_path.$stamp_name));
|
|
|
|
$stamp->move($stamp_destination_path, $stamp_name);
|
|
}
|
|
$current_stamp = $request->current_stamp;
|
|
$new_stamp = $stamp_destination_path . $stamp_name;
|
|
$hospital_information->stamp = $new_stamp ? $new_stamp : $current_stamp;
|
|
|
|
$lab_stamp = $request->file('lab_stamp');
|
|
$lab_stamp_destination_path = $lab_stamp_name = '';
|
|
if ($lab_stamp) {
|
|
$lab_stamp_name = date("Ymd_H-i-s") . '_' . $lab_stamp->getClientOriginalName();
|
|
$lab_stamp_destination_path = 'uploads/logo/';
|
|
$random = '';
|
|
do {
|
|
$lab_stamp_name = date("Ymd_H-i-s") . '_' . Str::slug($lab_stamp->getClientOriginalName()) . $random . '_lab_stamp.'. File::extension($lab_stamp->getClientOriginalName());
|
|
$random = Str::random(6);
|
|
}
|
|
while (File::exists($lab_stamp_destination_path.$lab_stamp_name));
|
|
|
|
$lab_stamp->move($lab_stamp_destination_path, $lab_stamp_name);
|
|
}
|
|
$current_lab_stamp = $request->current_lab_stamp;
|
|
$new_lab_stamp = $lab_stamp_destination_path . $lab_stamp_name;
|
|
$hospital_information->lab_stamp = $new_lab_stamp ? $new_lab_stamp : $current_lab_stamp;
|
|
$hospital_information->updated_by = Auth::id();
|
|
$hospital_information->save();
|
|
|
|
//update the streamline setup table with the new finished step
|
|
$streamline_setup = new StreamlineSetupStep;
|
|
$streamline_setup->step = "hospital registration";
|
|
$streamline_setup->completion_status = 1;
|
|
$streamline_setup->save();
|
|
|
|
|
|
flash($request->name . " Hospital Information has been saved")->success();
|
|
return redirect("clinics/create"); //for the streamline set up process
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
$hospital_information = HospitalInformation::where(['id' => 1])->first();
|
|
|
|
$districts = District::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
|
|
$parishes = Parish::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
|
|
$subcounties = Subcounty::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
|
|
$districts = ['' => '- select -'] + $districts;
|
|
$parishes = ['' => '- select -'] + $parishes;
|
|
$subcounties = ['' => '- select -'] + $subcounties;
|
|
|
|
return view('hospital_information.edit', compact('hospital_information', 'districts', 'parishes', 'subcounties'));
|
|
}
|
|
|
|
/**
|
|
* 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(), [
|
|
'email' => 'required|email',
|
|
'level' => 'required',
|
|
'phone_number' => 'required',
|
|
'country' => 'required',
|
|
'patient_number_abbr' => 'required',
|
|
'name' => 'required',
|
|
'address' => 'required',
|
|
'stamp' => 'nullable|file|mimes:jpg,jpeg,bmp,png,webp,gif,svg',
|
|
'lab_stamp' => 'nullable|file|mimes:jpg,jpeg,bmp,png,gif,svg,webp',
|
|
'logo' => 'nullable|file|mimes:jpg,jpeg,bmp,png,gif,svg,webp',
|
|
'back_date' => 'required|numeric|min:0',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
flash($string)->error();
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
$logged_in_user_id = Auth::id();
|
|
$hospital_information = HospitalInformation::find($id);
|
|
|
|
$hospital_information->name = $request->name;
|
|
$hospital_information->email = $request->email;
|
|
$hospital_information->website = $request->website;
|
|
$hospital_information->phone_number = $request->phone_number;
|
|
$hospital_information->app_name = $request->app_name;
|
|
$hospital_information->app_version = $request->app_version;
|
|
$hospital_information->patient_number_abbr = $request->patient_number_abbr;
|
|
$hospital_information->financial_year_start_date = $request->financial_year_start_date;
|
|
$hospital_information->address = $request->address;
|
|
$hospital_information->level = $request->level;
|
|
$hospital_information->code = $request->code;
|
|
$hospital_information->country = $request->country;
|
|
$hospital_information->district = $request->district;
|
|
$hospital_information->parish = $request->parish;
|
|
$hospital_information->back_date = $request->back_date;
|
|
$hospital_information->sub_county = $request->sub_county;
|
|
$hospital_information->sub_district = $request->sub_district;
|
|
$hospital_information->print_footer = $request->print_footer;
|
|
|
|
if ($request->hasFile('logo')) {
|
|
$logo = $request->file('logo');
|
|
$logo_name = date("Ymd_H-i-s") . '.' . $logo->getClientOriginalExtension();
|
|
$destinationPath = 'uploads/logo';
|
|
$logoPath = $destinationPath . "/" . $logo_name;
|
|
$logo->move($destinationPath, $logoPath);
|
|
$hospital_information->logo = $logoPath;
|
|
}
|
|
|
|
if ($request->hasFile('stamp')) {
|
|
$stamp = $request->file('stamp');
|
|
$stamp_name = date("Ymd_H-i-s") . '_' . Str::slug($stamp->getClientOriginalName()) . '_stamp.'. File::extension($stamp->getClientOriginalName());
|
|
$destinationPath = 'uploads/logo';
|
|
$stampPath = $destinationPath . "/" . $stamp_name;
|
|
$stamp->move($destinationPath, $stampPath);
|
|
$hospital_information->stamp = $stampPath;
|
|
}
|
|
|
|
if ($request->hasFile('lab_stamp')) {
|
|
$lab_stamp = $request->file('lab_stamp');
|
|
$lab_stamp_name = date("Ymd_H-i-s") . '_' . Str::slug($lab_stamp->getClientOriginalName()) . '_lab_stamp.'. File::extension($lab_stamp->getClientOriginalName());
|
|
$destinationPath = 'uploads/logo';
|
|
$lab_stampPath = $destinationPath . "/" . $lab_stamp_name;
|
|
$lab_stamp->move($destinationPath, $lab_stampPath);
|
|
$hospital_information->lab_stamp = $lab_stampPath;
|
|
}
|
|
|
|
if ($request->hasFile('pdf_print_header')) {
|
|
$pdf_print_header = $request->file('pdf_print_header');
|
|
$pdf_print_header_name = date("Ymd_H-i-s") . '_print.' . $pdf_print_header->getClientOriginalExtension();
|
|
$destinationPath = 'uploads/logo';
|
|
$pdf_print_headerPath = $destinationPath . "/" . $pdf_print_header_name;
|
|
$pdf_print_header->move($destinationPath, $pdf_print_headerPath);
|
|
$hospital_information->pdf_print_header = $pdf_print_headerPath;
|
|
}
|
|
|
|
$hospital_information->updated_by = $logged_in_user_id;
|
|
$hospital_information->save();
|
|
|
|
flash($request->name . " Hospital Information has been updated")->success();
|
|
return redirect("/hospital_information/1/edit")->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id) {
|
|
//
|
|
}
|
|
|
|
public function remove_print_banner() {
|
|
$hospital_information = HospitalInformation::find(1);
|
|
$hospital_information->pdf_print_header = NULL;
|
|
$hospital_information->save();
|
|
|
|
flash("Hospital Information has been updated")->success();
|
|
return redirect("/hospital_information/1/edit");
|
|
}
|
|
|
|
}
|