mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 03:01:32 +00:00
resolved conflicts
This commit is contained in:
+150
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\HospitalInformation;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientEpisode;
|
||||
use Streamline\Models\PaymentItem;
|
||||
use Streamline\Models\StreamlineBillReport;
|
||||
|
||||
class StreamlineBillsController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:streamline-bills-create');
|
||||
$this->middleware('permission:streamline-bills-index');
|
||||
}
|
||||
|
||||
public function index(){
|
||||
$reports = StreamlineBillReport::all();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
return view('finance::streamline_bills.index', compact('reports', 'hospital_information'));
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$episodes = [];
|
||||
$patients = [];
|
||||
$user = Auth::id();
|
||||
$date_string = '';
|
||||
$patient_string = '';
|
||||
$report = new StreamlineBillReport;
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
return view('finance::streamline_bills.create', compact( 'hospital_information','user', 'episodes', 'patients', 'date_string',
|
||||
'patient_string', 'patients'));
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$user = Auth::id();
|
||||
$report = StreamlineBillReport::where('id', $id)->first();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
return view('finance::streamline_bills.detail', compact( 'hospital_information', 'report', 'user'));
|
||||
}
|
||||
|
||||
public function generate(Request $request){
|
||||
$user = Auth::id();
|
||||
$patients = [];
|
||||
$report = new StreamlineBillReport;
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
if($request->dates == "yesterday") {
|
||||
$start = Carbon::yesterday()->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::yesterday()->endOfDay()->toDateTimeString();
|
||||
} else if($request->dates == "custom_date") {
|
||||
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::parse($request->start_date)->endOfDay()->toDateTimeString();
|
||||
} else if($request->dates == "custom_date_range") {
|
||||
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
||||
} else {
|
||||
$start = Carbon::today()->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::today()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
|
||||
$dates = array($start, $end);
|
||||
$date_string = implode('&', $dates);
|
||||
$episodes = PatientEpisode::whereBetween('created_at', [$start, $end])->groupBy('patient_id')->get();
|
||||
foreach ($episodes as $item){
|
||||
$patient = Patient::where('id', $item->patient_id)->whereNotIn('id', findTestOrDemoPatients())->whereBetween('created_at', [$start, $end])->first();
|
||||
if(isset($patient->number)){
|
||||
array_push($patients, $patient->id);
|
||||
}
|
||||
}
|
||||
|
||||
$patient_string = implode('/', $patients);
|
||||
$report_check = StreamlineBillReport::where('patients', '=', $patient_string)->first();
|
||||
if($report_check === null){
|
||||
$report->patients = $patient_string;
|
||||
$report->time_frame = $date_string;
|
||||
$report->type = 3;
|
||||
$report->created_by = Auth::id();
|
||||
$report->save();
|
||||
}
|
||||
|
||||
return view('finance::streamline_bills.create', compact( 'hospital_information','user', 'dates',
|
||||
'episodes', 'request', 'patients', 'date_string', 'patient_string'));
|
||||
}
|
||||
|
||||
public function transfer(Request $request){
|
||||
|
||||
$result = StreamlineBillReport::where('patients', $request->patient_string)->update([
|
||||
'amount_to_be_paid'=>$request->total,
|
||||
'amount_paid'=>0
|
||||
]);
|
||||
|
||||
$current_balance = ChartOfAccount::where('id', 14)->pluck('balance')->first();
|
||||
$transfer = ChartOfAccount::where('id', 14)->update(['balance' => ((int)$request->total + $current_balance)]);
|
||||
$total_amount_transfer = ((int)$request->total);
|
||||
$deposit_on_item = PaymentItem::where('name', 'streamline bill')->update(['unit_cost'=> $total_amount_transfer]);
|
||||
|
||||
if($transfer == 1 && $deposit_on_item == 1){
|
||||
flash('Streamline Bill Transfer was Successful')->success();
|
||||
}else{
|
||||
flash('Streamline Bill Transfer Failed')->error();
|
||||
}
|
||||
|
||||
return redirect('/streamline_bill');
|
||||
}
|
||||
|
||||
public function view_patients(Request $request){
|
||||
$patients_string = StreamlineBillReport::where('id', $request->id)->pluck('patients')->first();
|
||||
$patients = explode("/", $patients_string);
|
||||
$display = "";
|
||||
foreach ($patients as $patient){
|
||||
$display .= "<li>".get_full_name($patient, 'id', 'first_name', 'last_name', 'patients')."</li>";
|
||||
}
|
||||
return $display;
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$streamline_bill = StreamlineBillReport::find($id);
|
||||
|
||||
if ($streamline_bill->delete()):
|
||||
flash("Streamline Bill has been deleted.")->success();
|
||||
return redirect('/streamline_bill/');
|
||||
endif;
|
||||
}
|
||||
|
||||
public function verify_patients($patient_id){
|
||||
$reports = StreamlineBillReport::all();
|
||||
foreach($reports as $item){
|
||||
$patient_array = explode('/', $item['patients']);
|
||||
for($i = 0; $i < count($patient_array); $i++){
|
||||
if($patient_array[$i] == $patient_id){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
return $patient_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user