Files

3170 lines
215 KiB
PHP
Executable File

@extends('layouts.main')
@push('styles')
<link href="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.css') }}" rel="stylesheet" type="text/css" />
@endpush
@section('content')
<div class="row bg-title">
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
<h4 class="page-title">{{ __('inpatient.inpatient_billing') }}</h4>
</div>
<div class="col-lg-9 col-md-8 col-xs-12">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}"><i class="fa fa-home"></i> {{ __('inpatient.dashboard') }}</a></li>
<li><a href="{{ route('wards.select') }}">{{ __('wards.select_ward') }}</a></li>
<li><a href="{{ route('patients.index') }}"><i class="fa fa-user"></i> {{ __('inpatient.patients') }}</a></li>
<li class="active">{{ __('inpatient.inpatient_billing') }}</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-md-12">
@include('patients::allergies.header')
</div>
</div>
<br>
@include('flash::message')
@php
$total_deposits_paid = 0;
$total_amount_to_pay = 0;
$discount_amount = 0;
$insurance_investigations = 0;
$insurance_treatments = 0;
$insurance_sundries = 0;
$insurance_services = 0;
$insurance_procedures = 0;
$insurance_tta = 0;
$investigation_amount_total = 0;
$insurance_opd_treatment = 0;
$opd_procedure_insurance_amount_total = 0;
$opd_unpaid_treatment_total = $opd_sundries_total_cost = $opd_services_amount_total = $opd_procedure_amount_total = 0;
$price_list_set_serial = serialize(['price_list_set' => $price_list_set]);
$patient_insurance_status = (patient_insurance_status($patient_id) == 1);
$counter = 0;
$bill_closed = false;
@endphp
<div class="white-box">
@php $price_list_id = is_patient_category_attached_to_price_list($patient_id); @endphp
@if(Auth::user()->can('price-list-category-change-billing') && !$patient_insurance_status)
{{ Form::open(['route' => 'inpatient_billing', 'data-toggle' => 'validator']) }}
<div class="row">
<div class="col-md-6">
<div class="form-group">
{{ Form::label('price_list_category_id', __('inpatient.price_list_category')) }}
<select name="price_list_category_id" class="form-control compulsory" required>
<option value="0">- {{ __('inpatient.default_pricing') }} -</option>
@foreach($price_list_categories as $record)
<option value="{{ $record->id }}">{{ get_name($record->patient_category_id, 'id', 'name', 'patient_categories') }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-6">
<br>
{{ Form::button(__('inpatient.apply_changes'),['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10']) }}
</div>
</div>
<hr>
{{ Form::close() }}
@endif
@if(is_null($inpatient_info->bed_category_id))
<h3><span class="label label-danger">{{ __('inpatient.select_bed_category_warning') }}</span></h3>
@endif
<div id="printableContent">
<div class="row">
<div class="col-md-10">
{{ Form::open(['route' => 'store_inpatient_bill', 'id' => 'inpatient_bill_form']) }}
{{ Form::hidden('billing_price_list', $price_list_set) }}
{{ Form::hidden('patient_insurance_status', $patient_insurance_status) }}
<div class="table-responsive">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td><b>{{ __('inpatient.ward') }}</b></td>
<td>{{ get_name($inpatient_info->ward_id, 'id', 'name', 'wards') }}</td>
<td><b>{{ __('inpatient.bed_category') }}</b></td>
<td>
@if(is_null($inpatient_info->bed_category_id))
<select name="bed_category" class="form-control" onchange="update_bed_category(this.value, <?php echo $inpatient_info->id ?>)">
{!! custom_dropdown_selected("inpatient_bed_categories", "id", "name", $inpatient_info->bed_category_id) !!}
</select>
@else
{{ get_name($inpatient_info->bed_category_id, 'id', 'name', 'inpatient_bed_categories') }}
@endif
</td>
<td><b>{{ __('inpatient.residence') }}</b></td>
<td>{{ patient_residence($patient->id) }}</td>
</tr>
<tr>
<td><b>{{ __('inpatient.admitted') }}</b></td>
@if($inpatient_info->discharged == 1)
@php $end_date = new DateTime($inpatient_info->discharged_on) @endphp
@else
@php $end_date = new DateTime(date('Y-m-d')) @endphp
@endif
@php
$start_date = new DateTime($inpatient_info->admitted_on);
$days_spent_in_ward = ($end_date->diff($start_date)->format('%a'));
@endphp
<td>{{ streamline_date($inpatient_info->admitted_on) }} ( {{ $days_spent_in_ward }} days)</td>
{{ Form::hidden("duration", $days_spent_in_ward) }}
{{ Form::hidden("inpatient_info_id", $inpatient_info->id) }}
<td><b>{{ __('inpatient.discharged_on') }}</b></td>
@if($inpatient_info->discharged == 1)
<td style="color:green; font-weight:bold">{{ streamline_date($inpatient_info->discharged_on) }}</td>
@else
<td style="color:red; font-weight: bold">{{ __('inpatient.still_admitted') }}</td>
@endif
<td><b>{{ __('inpatient.category') }}</b></td>
<td>
{{ get_name($patient->category_id, 'id', 'name', 'patient_categories') }}
@if(!is_null($patient_discount))
({{ $patient_discount["discount"] }} % {{ __('inpatient.discount') }})
@endif
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<?php
$ward_bed_stays = \Streamline\Models\WardBedStay::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$ward_bed_admission_total_cost = $chi_ward_accomodation_to_pay = 0;
?>
@if(count($ward_bed_stays) > 0)
<div class="row">
<div class="col-md-2">{{ __('inpatient.accomodation') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" data-target="#bedAdmissionDetails" style="padding: 0px;">{{ __('inpatient.view_bed_admission_details') }}</a></div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.bed_no') }}</th>
<th>{{ __('inpatient.bed_category') }}</th>
<th>{{ __('inpatient.from') }}</th>
<th>{{ __('inpatient.to') }}</th>
<th>{{ __('inpatient.duration') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@if(count($ward_bed_stays) > 0)
@foreach($ward_bed_stays as $bed_record)
@php
$accomodation_cost = $bed_record->bed_fee_total;
$chi_accomodation_cost = $bed_record->chi_bed_fee_total;
$chi_ward_accomodation_to_pay += $chi_accomodation_cost;
$ward_bed_admission_total_cost += $accomodation_cost;
@endphp
<tr>
<td>{{ $bed_record->bed_number}}</td>
<td>{{ get_name($bed_record->bed_category, "id", "name", "inpatient_bed_categories") }}</td>
<td>{{ streamline_date($bed_record->from) }}</td>
<td>{{ streamline_date($bed_record->to) }}</td>
<td>{{ $bed_record->duration }}</td>
<td>{{ ugandan_shillings_with_decimals($accomodation_cost) }}</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ ugandan_shillings_with_decimals($chi_accomodation_cost) }}
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('ward_bed_admission_cost', $ward_bed_admission_total_cost, ['id' => 'ward_bed_admission_cost']) }}
{{ Form::text('display_ward_bed_admission_cost', ugandan_shillings_with_decimals($ward_bed_admission_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_ward_bed_admission_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::hidden('insurance_admission_cost', $chi_ward_accomodation_to_pay, ['id' => 'insurance_admission_cost']) }}
{{ Form::text('display_insurance_ward_bed_admission_cost', ugandan_shillings_with_decimals($chi_ward_accomodation_to_pay), ['class' => 'form-control compulsory', 'readonly']) }}
@endif
</div>
</div>
@endif
@php $admission_cost = $ward_bed_admission_total_cost; @endphp
<hr>
<div class="row" @if($ordered_ward_investigations->count() < 1) style="display: none" @endif>
<div class="col-md-2">
{{ __('inpatient.investigations') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" data-target="#investigationsPerformedDetails" style="padding: 0px;">{{ __('inpatient.view_investigation_details') }}</a>
</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@if(count($ordered_ward_investigations) > 0)
@php
// ids of the ordered investigations
$investigation_ids = $ward_inv_pricing = $order_ids = $all_order_ids_array = [];
foreach($ordered_ward_investigations as $ordered_investigation){
if (get_investigation_billing_mode() == 1 && $ordered_investigation->investigation_status == 0) {
// no results yet, so ignore
continue;
}
$investigation_ids = array_merge($investigation_ids, explode(",", $ordered_investigation->investigation_id));
$ward_inv_pricing = array_merge($ward_inv_pricing, explode(",", $ordered_investigation->ward_pricing_id));
$single_order_investigations = explode(",",$ordered_investigation->investigation_id);
for ($w=0; $w < count($single_order_investigations) ; $w++) {
echo '<input type="hidden" name="investigation_order_ids[]" value="'. $ordered_investigation->id.'">';
$all_order_ids_array[] = $ordered_investigation->id;
}
array_push($order_ids, $ordered_investigation->id);
}
$count_orders = count($order_ids);
// create strings from arrays to use when submitting
$investigation_ids_string = implode(',', $investigation_ids);
$investigation_amount = 0;
@endphp
{{ Form::hidden('investigation_ids', $investigation_ids_string) }}
@for ($i = 0; $i < count($investigation_ids); $i++)
@php
// get insurance status for investigation
$investigation_insurance_status = get_name($investigation_ids[$i], "id", "insurance_coverage", "investigations");
// insurance flag
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$investigation_amount_insurance = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $investigation_ids[$i], 3, true, $inpatient_info->ward_id);
$investigation_amount = $item_insurance_details[2];
$investigation_amount_insurance = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if ($price_list_set && $price_list_set != 0){
$investigation_amount = get_price_list_category_price($price_list_set, 2, $investigation_ids[$i]);
} elseif ($price_list_id) {
$investigation_amount = get_price_list_category_price($price_list_id, 2, $investigation_ids[$i]);
} else {
$investigation_amount = get_name($investigation_ids[$i], "id", "non_insured_price", "investigations");
}
}
if (isset($ward_inv_pricing[$i]) && is_numeric($ward_inv_pricing[$i])) {
$saved_prices = get_investigation_ward_pricing_by_id($ward_inv_pricing[$i]);
$saved_ward_chi_price = $saved_prices[1];
$saved_ward_price = $saved_prices[0];
} else {
$saved_prices = get_investigation_ward_pricing($patient_id, $episode_id, $investigation_ids[$i], $all_order_ids_array[$i]);
$saved_ward_chi_price = $saved_prices[1];
$saved_ward_price = $saved_prices[0];
if($saved_prices[2]) {
$ward_inv_pricing[$i] = $saved_prices[2];
}
}
//if the inv exists in ward pricing table use that price else use default
if($saved_ward_price != "N/A"){
$investigation_amount = (is_null($price_list_set) || $price_list_set == "") ? $saved_ward_price : $investigation_amount;
}
$investigation_amount_insurance = $saved_ward_chi_price == 'N/A' ? $investigation_amount_insurance : $saved_ward_chi_price;
$investigation_amount_total += $investigation_amount;
$insurance_investigations += $investigation_amount_insurance;
@endphp
<tr>
<td>
@if($is_insured == 1)
<label style="color:green;">{{ get_name($investigation_ids[$i], "id", "name", "investigations") }}</label>
@else
<label style="color:orange;">{{ get_name($investigation_ids[$i], "id", "name", "investigations") }}</label>
@endif
</td>
<td>
{{ Form::hidden('investigations_item_ids[]', $investigation_ids[$i]) }}
{{ Form::hidden('investigations_tariff_ids[]', $tariff_id) }}
{{ Form::hidden('investigations_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('ward_inv_pricing_ids[]', ((isset($ward_inv_pricing[$i]) && is_numeric($ward_inv_pricing[$i])) ? $ward_inv_pricing[$i] : 0)) }}
@if(Auth::user()->can('edit-investigation-prices-on-inpatient-bill') && $is_insured == 0)
{{ Form::number('investigation_amount[]', $investigation_amount, ['class' => 'form-control investigation_amount', 'id' => 'investigation_amount_' . $counter]) }}
@else
{{ Form::number('investigation_amount[]', $investigation_amount, ['class' => 'form-control investigation_amount', 'readonly', 'id' => 'investigation_amount_' . $counter]) }}
@endif
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::hidden('investigation_insured[]', $is_insured) }}
{{ Form::hidden('investigation_summed_amount[]', ($investigation_amount_insurance + $investigation_amount), ['id' => 'investigation_summed_amount_' . $counter]) }}
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('investigation_insurance_amount[]', $investigation_amount_insurance, ['class' => 'form-control investigation_insurance_amount', 'id' => 'investigation_insurance_amount_' . $counter]) }}
@else
{{ Form::number('investigation_insurance_amount[]', $investigation_amount_insurance, ['class' => 'form-control investigation_insurance_amount', 'readonly', 'id' => 'investigation_insurance_amount_' . $counter]) }}
@endif
</td>
</tr>
@php $counter++; @endphp
@endfor
@else
<tr>
<td colspan="2" class="text-center" style="color: maroon">{{ __('inpatient.no_investigations_ordered') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('investigation_cost', $investigation_amount_total, ['id' => 'investigation_cost']) }}
{{ Form::hidden('insurance_investigation_cost', $insurance_investigations, ['id' => 'insurance_investigation_cost']) }}
{{ Form::text('display_investigation_cost', ugandan_shillings_with_decimals($investigation_amount_total), ['class' => 'form-control compulsory', 'readonly','id' => 'display_investigation_cost']) }}
@if($patient_insurance_status)
<br>{{ __('inpatient.insurance_to_pay') }}<br>
{{ Form::text('display_insurance_investigation_cost', ugandan_shillings_with_decimals($insurance_investigations), ['class' => 'form-control compulsory', 'readonly','id' => 'display_insurance_investigation_cost']) }}
@endif
</div>
</div>
<hr @if($ordered_ward_investigations->count() < 1) style="display: none" @endif>
@php
$inpatient_info_ward_treatments_array = unserialize($inpatient_info->ward_treatments);
$this_drug_sp = 0;
$insurance_treatment_to_pay = 0;
@endphp
<div class="row" @if(empty($dispensed_drug_quantity_given_array) && empty($inpatient_info_ward_treatments_array)) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.treatments') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" data-target="#wardDispensationDetails" style="padding: 0px;">{{ __('inpatient.view_ward_treatment_details') }}</a></div>
<div class="col-md-8">
@php $treatment_total_cost = 0; @endphp
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
@if(get_ward_prescription_model() == 1 || $patient_insurance_status)
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.treatment') }}</th>
<th>{{ __('inpatient.unit_price') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('inpatient.quantity_given') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@if(!empty($dispensed_drug_quantity_given_array))
@foreach($dispensed_drug_quantity_given_array as $drug_id => $quantity_given)
@php
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $drug_id, 4, true, $inpatient_info->ward_id);
$drugs_cost = $item_insurance_details[2];
$insurance_treatment_to_pay = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if ($price_list_set && $price_list_set != 0){
$drugs_cost = get_price_list_category_price($price_list_set, 3, $drug_id);
} elseif ($price_list_id) {
$drugs_cost = get_price_list_category_price($price_list_id, 3, $drug_id);
} else {
$drugs_cost = get_name($drug_id, "id", "non_insured_price", "drugs");
}
}
//get actual total costs incase the price of item changed after dispensation to allow retro billing
$this_drug_total_price = 0;
$per_ward_drug_given_rows = \Illuminate\Support\Facades\DB::table('ward_treatment_dispensations')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'drug_id' => $drug_id])->get();
foreach ($per_ward_drug_given_rows as $drug_ward_record) {
$this_drug_sp = (is_null($price_list_set) || $price_list_set == "") ? $drug_ward_record->price : $drugs_cost;
$this_drug_sp = is_numeric($this_drug_sp) ? $this_drug_sp : 0;
$this_drug_total_price += ($this_drug_sp * $drug_ward_record->quantity_given);
$insurance_treatment_to_pay = $drug_ward_record->chi_price;
}
$treatment_total_cost += $this_drug_total_price;
$insurance_treatments += ($insurance_treatment_to_pay * $quantity_given);
@endphp
<tr>
<td>
@if($is_insured == 1)
<label style="color:green;">{{ get_name($drug_id, "id", "name", "drugs") }}</label>
@else
<label style="color:orange;">{{ get_name($drug_id, "id", "name", "drugs") }}</label>
@endif
</td>
<td>
{{ Form::number('prescription_treatment_item_prices[]', $this_drug_sp, ['class' => 'form-control', 'readonly', 'id' => 'drug_unit_price_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('drug_unit_insurance_amount[]', $insurance_treatment_to_pay, ['class' => 'form-control ward_treatment_insurance', 'id' => 'drug_unit_insurance_amount_' . $counter]) }}
@else
{{ Form::number('drug_unit_insurance_amount[]', $insurance_treatment_to_pay, ['class' => 'form-control ward_treatment_insurance', 'readonly', 'id' => 'drug_unit_insurance_amount_' . $counter]) }}
@endif
</td>
<td>{{ Form::number('ward_drug_quantity[]', $quantity_given, ['class' => 'form-control', 'readonly', 'id' => 'ward_drug_quantity_' . $counter]) }}</td>
{{ Form::hidden('prescription_treatment_item_ids[]', $drug_id) }}
{{ Form::hidden('prescription_treatment_tariff_ids[]', $tariff_id) }}
{{ Form::hidden('prescription_treatment_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('drug_summed_amount[]', ($this_drug_sp + $insurance_treatment_to_pay), ['id' => 'drug_summed_amount_' . $counter]) }}
<td>
{{ Form::number('drug_subtotal[]', $this_drug_total_price, ['class' => 'form-control ward_drug_amounts', 'readonly', 'id' => 'drug_subtotal_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('drug_insurance_amount[]', $insurance_treatment_to_pay * $quantity_given, ['class' => 'form-control ward_drug_chi_amount', 'readonly', 'id' => 'drug_insurance_amount_' . $counter]) }}
</td>
</tr>
@php $counter++; @endphp
@endforeach
@else
<tr>
<td colspan="4" class="text-center" style="color: maroon">{{ __('inpatient.no_treatments_ordered') }}</td>
</tr>
@endif
</tbody>
</table>
@elseif(get_ward_prescription_model() == 2)
<table class="table table-bordered color-bordered-table success-bordered-table">
@php
$inpatient_ward_treatment = unserialize($inpatient_info->ward_treatments);
$dob = get_name($patient_id, "id", "date_of_birth", "patients");
$difference = days_months_years($dob, date("Y-m-d"));
$days = $difference[0];
$months = $difference[1];
$years = $difference[2];
$age_bracket = "";
if (between($years, 0, 5)){
$age_bracket = __('inpatient.infant');
} elseif (between($years, 6, 12)){
$age_bracket = __('inpatient.child');
} elseif ($years > 12){
$age_bracket = __('inpatient.adult');
}
@endphp
<thead>
<tr>
<th>{{ __('inpatient.treatment') }}</th>
<th>{{ __('inpatient.days') }}</th>
<th>{{ __('inpatient.daily_cost_for') }} {{ $age_bracket }}</th>
<th>{{ __('inpatient.total_cost') }}</th>
</tr>
</thead>
<tbody>
@if(is_null($inpatient_ward_treatment))
<tr>
<td colspan="4" class="text-center" style="color: maroon">{{ __('inpatient.no_treatments_ordered') }}</td>
</tr>
@else
@php
// for old streamline system records which were using a weird naming convention
$drugs = $inpatient_ward_treatment['drugs'] ?? $inpatient_ward_treatment['Drugs'];
$days = $inpatient_ward_treatment['days'] ?? $inpatient_ward_treatment['Days'];
@endphp
@for($i = 0; $i < count($drugs); $i++)
@php
$daily_cost = 0;
if ($age_bracket == __('inpatient.infant')){
$daily_cost = get_name($drugs[$i], 'id', 'ip_daily_cost_infant', 'drugs');
} elseif ($age_bracket == __('inpatient.child')){
$daily_cost = get_name($drugs[$i], 'id', 'ip_daily_cost_children', 'drugs');
} elseif ($age_bracket == __('inpatient.adult')){
$daily_cost = get_name($drugs[$i], 'id', 'ip_daily_cost_adult', 'drugs');
}
if (!is_numeric($daily_cost)){
$daily_cost = 0;
}
@endphp
<tr>
<td>
<label>{{ get_name($drugs[$i], "id", "name", "drugs") }}</label>
</td>
<td>{{ $days[$i] }}</td>
<td>{{ ugandan_shillings_with_decimals($daily_cost) }}</td>
<input type="hidden" name="pf_treatment_item_ids[]" value="{{ $drugs[$i] }}">
<input type="hidden" name="pf_treatment_item_prices[]" value="{{ $daily_cost }}">
<td>{{ ugandan_shillings_with_decimals($daily_cost * $days[$i]) }}</td>
@php $treatment_total_cost += $daily_cost * $days[$i]; @endphp
</tr>
@endfor
@endif
</tbody>
</table>
@endif
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('treatment_cost', (int)$treatment_total_cost, ['id' => 'treatment_cost']) }}
{{ Form::hidden('insurance_treatment_cost', $insurance_treatments, ['id' => 'insurance_treatment_cost']) }}
{{ Form::text('display_treatment_cost', ugandan_shillings_with_decimals((int)$treatment_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_treatment_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_treatment_cost', ugandan_shillings_with_decimals($insurance_treatments), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_treatment_cost']) }}
@endif
</div>
</div>
{{-- opd unpaid treatments --}}
@php
$opd_unpaid_treatments = \Streamline\Models\Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id,'payment_status' => 0, 'tta' => 0])->get();
@endphp
@if (count($opd_unpaid_treatments) > 0)
<hr>
<div class="row" @if(count($opd_unpaid_treatments) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.unpaid_opd_treatment') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.quantity') }}</th>
<th>{{ __('inpatient.unit_price') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@php
$opd_unpaid_treatment_total = $insurance_opd_treatment = 0;
@endphp
@foreach($opd_unpaid_treatments as $opd_treatment)
@if(!(is_incoming_prescriptions_feature_enabled() && $opd_treatment->confirmation_status == 0))
@php
$opd_treatment_amount = 0;
$opd_treatment_insurance_amount = 0;
$opd_drug_ids = explode(",", $opd_treatment->drugs);
$drug_quantities = explode(",", $opd_treatment->quantities_dispensed);
$purchased_elsewhere = explode(",", $opd_treatment->purchased_elsewhere);
$unit_selling_prices_array = is_null($opd_treatment->unit_selling_prices) ? [] : explode(",", $opd_treatment->unit_selling_prices);
@endphp
@for ($i = 0; $i < count($opd_drug_ids); $i++)
@if(get_name($opd_drug_ids[$i], "id", "name", "drugs") != "N/A")
@php
// insurance flag
$is_insured = 0;
$opd_treatment_insurance_amount = 0;
$tariff_id = 0;
$benefit_id = 0;
// check if drug and patient is eligible for insurance
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $opd_drug_ids[$i], 4, true, $inpatient_info->ward_id);
$opd_treatment_amount = $item_insurance_details[2];
$opd_treatment_insurance_amount = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if (isset($unit_selling_prices_array[$i]) && !is_null($unit_selling_prices_array[$i])) {
$opd_treatment_amount = is_numeric($unit_selling_prices_array[$i]) ? $unit_selling_prices_array[$i] : 0;
} else {
if ($price_list_set && $price_list_set != 0){
$opd_treatment_amount = get_price_list_category_price($price_list_set, 3, $opd_drug_ids[$i]);
} elseif ($price_list_id) {
$opd_treatment_amount = get_price_list_category_price($price_list_id, 3, $opd_drug_ids[$i]);
} else {
$opd_treatment_amount = get_name($opd_drug_ids[$i], "id", "non_insured_price", "drugs");
}
}
}
// get money saved from the inpatient bill table
$opd_treatment_amount = $saved_drug_prices[$opd_drug_ids[$i]] ?? $opd_treatment_amount;
$opd_treatment_insurance_amount = $saved_chi_drug_prices[$opd_drug_ids[$i]] ?? $opd_treatment_insurance_amount;
if(isset($drug_quantities[$i]) && $drug_quantities[$i] != ""){
$opd_treatment_subtotal = $drug_quantities[$i] * $opd_treatment_amount;
$opd_treatment_insurance_subtotal = $drug_quantities[$i] * $opd_treatment_insurance_amount;
} else {
$opd_treatment_subtotal = 0;
$opd_treatment_insurance_subtotal = 0;
}
// add amounts to totals
$opd_unpaid_treatment_total += $opd_treatment_subtotal;
$insurance_opd_treatment += $opd_treatment_insurance_subtotal;
if (is_chi_enabled()) {
$insurance_color = ($is_insured == 1) ? "green" : "orange";
} else {
$insurance_color = (is_drug_covered_by_pay_later_category(get_name($patient_id, 'id', 'category_id', 'patients'), $opd_drug_ids[$i])) ? "green" : "orange";
}
@endphp
@if (count($purchased_elsewhere) > 0 && isset($purchased_elsewhere[$i]) && $purchased_elsewhere[$i] == 1)
<tr>
<td>
<label style="color:{{ $insurance_color }}">{{ get_name($opd_drug_ids[$i], "id", "name", "drugs") }}</label>
@if (!is_chi_enabled() && !is_drug_covered_by_pay_later_category(get_name($patient_id, 'id', 'category_id', 'patients'), $opd_drug_ids[$i]))
&nbsp;&nbsp;<br><span class='badge badge-danger'>{{ __('inpatient.not_covered_by') }} {{ get_name(get_name($patient_id, 'id', 'category_id', 'patients'), 'id', 'name', 'patient_categories') }}</span>
@endif
</td>
<td>
{{ Form::number('treatment_quantity_show', $drug_quantities[$i], ['class' => 'form-control', 'readonly']) }}
</td>
<td>
{{ Form::number('treatment_amount_show', $opd_treatment_amount, ['class' => 'form-control', 'readonly']) }}
</td>
<td style='color: orange' colspan="3" class="text-center">{{ __('inpatient.purchased_from_elsewhere') }}</td>
</tr>
@else
<tr>
<td>
<label style="color:{{ $insurance_color }}">{{ get_name($opd_drug_ids[$i], "id", "name", "drugs") }}</label>
@if (!is_chi_enabled() && !is_drug_covered_by_pay_later_category(get_name($patient_id, 'id', 'category_id', 'patients'), $opd_drug_ids[$i]))
&nbsp;&nbsp;<br><span class='badge badge-danger'>{{ __('inpatient.not_covered_by') }} {{ get_name(get_name($patient_id, 'id', 'category_id', 'patients'), 'id', 'name', 'patient_categories') }}</span>
@endif
</td>
<td>
{{ Form::number('opd_treatment_quantity[]', $drug_quantities[$i], ['class' => 'form-control', 'readonly', 'id' => 'opd_treatment_quantity_' . $counter]) }}
</td>
<td>
{{ Form::number('opd_treatment_amount[]', $opd_treatment_amount, ['class' => 'form-control', 'readonly', 'id' => 'opd_treatment_amount_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('opd_treatment_insurance_unit_amount[]', $opd_treatment_insurance_amount, ['class' => 'form-control opd_drugs_insurance_unit_amount', 'id' => 'opd_treatment_insurance_unit_amount_' . $counter]) }}
@else
{{ Form::number('opd_treatment_insurance_unit_amount[]', $opd_treatment_insurance_amount, ['class' => 'form-control opd_drugs_insurance_unit_amount', 'readonly', 'id' => 'opd_treatment_insurance_unit_amount_' . $counter]) }}
@endif
</td>
{{ Form::hidden('opd_treatment_summed[]', ($opd_treatment_amount + $opd_treatment_insurance_amount), ['id' => 'opd_treatment_summed_' . $counter]) }}
{{ Form::hidden('opd_inpatient_bill_generated[]', $opd_treatment->inpatient_bill_generated) }}
<td>
{{ Form::number('opd_treatment_subtotal[]', $opd_treatment_subtotal, ['class' => 'form-control opd_treatment_subtotal', 'readonly', 'id' => 'opd_treatment_subtotal_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('opd_treatment_insurance_amount[]', $opd_treatment_insurance_subtotal, ['class' => 'form-control opd_treatment_insurance_amount', 'readonly', 'id' => 'opd_treatment_insurance_amount_' . $counter]) }}
</td>
</tr>
{{ Form::hidden('opd_treatment_insurance_status[]', $is_insured) }}
{{ Form::hidden('opd_treatment_item[]', $opd_drug_ids[$i]) }}
{{ Form::hidden('opd_treatment_tariff[]', $tariff_id) }}
{{ Form::hidden('opd_treatment_benefit[]', $benefit_id) }}
{{ Form::hidden('opd_treatment_id[]', $opd_treatment->id) }}
@endif
@endif
@php $counter++; @endphp
@endfor
@else
<tr>
<td colspan="4"><h4 class="text-center"><code>{{ __('inpatient.treatments_not_confirmed') }}</code></h4></td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('opd_treatment_cost', $opd_unpaid_treatment_total, ['id' => 'opd_treatment']) }}
{{ Form::hidden('insurance_opd_treatment', $insurance_opd_treatment, ['id' => 'insurance_opd_treatment']) }}
{{ Form::text('display_opd_treatment', ugandan_shillings_with_decimals($opd_unpaid_treatment_total), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_opd_treatment']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_opd_treatment', ugandan_shillings_with_decimals($insurance_opd_treatment), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_opd_treatment']) }}
@endif
</div>
</div>
@endif
{{-- sundries section below --}}
<hr @if(count($opd_unpaid_treatments) < 1 && $ordered_ward_investigations->count() < 1) style="display: none" @endif>
<?php
$sundries_total_cost = 0;
$ward_sundry_quantities_given = DB::table('ward_sundry_dispensations')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->groupBy('sundry_id')->selectRaw('*, sum(quantity_given) as quantity_given')->get();
?>
<div class="row" @if(count($ward_sundry_quantities_given) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.sundries') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" data-target="#sundriesConsumptionDetails" style="padding: 0px;">{{ __('inpatient.view_sundries_consumption_details') }}</a></div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('patient_finance.unit_cost') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('inpatient.quantity') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@if(count($ward_sundry_quantities_given) > 0)
@foreach($ward_sundry_quantities_given as $sundry_record)
@php
$sundries_cost = $this_sundry_sp = 0;
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$insurance_sundry_amount = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $sundry_record->sundry_id, 5, true, $inpatient_info->ward_id);
$sundries_cost = $item_insurance_details[2];
$insurance_sundry_amount = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if ($price_list_set && $price_list_set != 0){
$sundries_cost = get_price_list_category_price($price_list_set, 5, $sundry_record->sundry_id);
} elseif ($price_list_id) {
$sundries_cost = get_price_list_category_price($price_list_id, 5, $sundry_record->sundry_id);
} else {
$sundries_cost = get_name($sundry_record->sundry_id, "id", "non_insured_price", "sundries");
}
}
//get actual total costs incase the price of item changed after dispensation to allow retro billing
$this_sundry_total_price = 0;
$per_ward_sundry_given_rows = DB::table('ward_sundry_dispensations')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'sundry_id' => $sundry_record->sundry_id])->get();
if (count($per_ward_sundry_given_rows) > 0) {
foreach ($per_ward_sundry_given_rows as $sundry_ward_record) {
$this_sundry_sp = ($sundry_ward_record->price != 0 && (is_null($price_list_set) || $price_list_set == "")) ? $sundry_ward_record->price : $sundries_cost;
$this_sundry_total_price += ($this_sundry_sp * $sundry_ward_record->quantity_given);
$insurance_sundry_amount = $sundry_ward_record->chi_price;
}
} else {
$this_sundry_total_price = $sundry_record->quantity_given * $sundries_cost;
}
$sundries_total_cost += $this_sundry_total_price;
$insurance_sundries += ($sundry_record->quantity_given * $insurance_sundry_amount);
@endphp
<tr>
<td>
@if($is_insured)
<label style="color:green;">{{ get_name($sundry_record->sundry_id, "id", "name", "sundries") }}</label>
@else
<label style="color:orange;">{{ get_name($sundry_record->sundry_id, "id", "name", "sundries") }}</label>
@endif
{{ Form::hidden('sundries_item_ids[]', $sundry_record->sundry_id) }}
{{ Form::hidden('sundries_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('sundries_tariff_ids[]', $tariff_id) }}
</td>
<td>
{{ Form::number('sundries_item_prices[]', $this_sundry_sp, ['class' => 'form-control', 'readonly', 'id' => 'sundries_item_prices_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('sundry_unit_insurance_amount[]', $insurance_sundry_amount, ['class' => 'form-control sundry_unit_insurance_amount', 'id' => 'sundry_unit_insurance_amount_' . $counter]) }}
@else
{{ Form::number('sundry_unit_insurance_amount[]', $insurance_sundry_amount, ['class' => 'form-control sundry_unit_insurance_amount', 'readonly', 'id' => 'sundry_unit_insurance_amount_' . $counter]) }}
@endif
</td>
{{ Form::hidden('sundry_amount_summed[]', $insurance_sundry_amount + $this_sundry_sp, ['id' => 'sundry_amount_summed_' . $counter]) }}
<td>
{{ Form::number('sundry_quantity_given[]', $sundry_record->quantity_given, ['class' => 'form-control', 'readonly', 'id' => 'sundry_quantity_given_' . $counter]) }}
</td>
<td>
{{ Form::number('sundry_subtotal[]', $this_sundry_total_price, ['class' => 'form-control sundry_subtotal', 'readonly', 'id' => 'sundry_subtotal_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('sundry_insurance_amount[]', $sundry_record->quantity_given * $insurance_sundry_amount, ['class' => 'form-control sundry_insurance_amount', 'readonly', 'id' => 'sundry_insurance_amount_' . $counter]) }}
</td>
</tr>
@php $counter++; @endphp
@endforeach
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('sundries_cost', $sundries_total_cost, ['id' => 'sundries_cost']) }}
{{ Form::hidden('insurance_sundries_cost', $insurance_sundries, ['id' => 'insurance_sundries_cost']) }}
{{ Form::text('display_sundries_cost', ugandan_shillings_with_decimals($sundries_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_sundries_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_sundries_cost', ugandan_shillings_with_decimals($insurance_sundries), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_sundries_cost']) }}
@endif
</div>
</div>
{{-- opd unpaid sundries --}}
@php
$opd_unpaid_sundries = \Streamline\Models\OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id,'payment_status' => 0,'inpatient_bill_generated' => 0])->get();
$opd_sundries_total_cost = $opd_insurance_sundries = 0;
@endphp
@if (count($opd_unpaid_sundries) > 0)
<hr>
@php
$opd_sundries_ids = [];
$opd_sundries_quantity = [];
$opd_sundry_order_ids = [];
$opd_sundries_orders_amounts = [];
$opd_unit_sundries_selling_prices_array = [];
foreach($opd_unpaid_sundries as $opd_ordered_sundry){
$opd_sundries_ids = array_merge($opd_sundries_ids, explode(",", $opd_ordered_sundry->sundries_id));
$opd_sundries_quantity = array_merge($opd_sundries_quantity, explode(",",$opd_ordered_sundry->quantity));
$opd_unit_sundries_selling_prices_array = array_merge($opd_unit_sundries_selling_prices_array, explode(",",$opd_ordered_sundry->sundries_amount));// is_null($treatment->sundries_amount) ? [] : explode(",", $treatment->unit_selling_prices);
array_push($opd_sundry_order_ids, $opd_ordered_sundry->id);
//if amounts are put at the time of ordering
$opd_sundries_orders_amounts = is_null($opd_ordered_sundry->sundries_amount) ? array_merge($opd_sundries_orders_amounts, []) : array_merge($opd_sundries_orders_amounts, explode(",", $opd_ordered_sundry->sundries_amount));
}
$count_orders = count($opd_sundry_order_ids);
// create strings from arrays to use when submitting
$opd_sundry_order_ids_string = implode(',', $opd_sundry_order_ids);
@endphp
<div class="row" @if(count($opd_unpaid_sundries) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.unpaid_opd_sundries') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('patient_finance.sundry_name') }}</th>
<th>{{ __('patient_finance.unit_cost') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('patient_finance.quantity') }}</th>
<th>{{ __('patient_finance.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('patient_finance.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@php $orders_count = 0; @endphp
{{ Form::hidden('opd_sundry_order_ids', $opd_sundry_order_ids_string) }}
@for ($i = 0; $i < count($opd_sundries_ids); $i++)
@php
// get insurance status for sundry
$opd_sundry_insurance_status = get_name($opd_sundries_ids[$i], "id", "insurance", "sundries");
// insurance flag
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$opd_sund_insurance_amount = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $opd_sundries_ids[$i], 5, true, $inpatient_info->ward_id);
$opd_sundry_amount = $item_insurance_details[2];
$opd_sund_insurance_amount = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if (isset($opd_unit_sundries_selling_prices_array[$i]) && !is_null($opd_unit_sundries_selling_prices_array[$i]) && is_numeric($opd_unit_sundries_selling_prices_array[$i])) {
$opd_sundry_amount = $opd_unit_sundries_selling_prices_array[$i];
} else {
// check if the patient category is attached to a price list
if ($price_list_set && $price_list_set != 0){
$opd_sundry_amount = get_price_list_category_price($price_list_set, 5, $opd_sundries_ids[$i]);
} elseif ($price_list_id) {
$opd_sundry_amount = get_price_list_category_price($price_list_id, 5, $opd_sundries_ids[$i]);
} else {
//if amount was set at time of ordering
if (isset($opd_sundries_orders_amounts[$i]) && !is_null($opd_sundries_orders_amounts[$i])) {
$opd_sundry_amount = $opd_sundries_orders_amounts[$i];
} else{
$opd_sundry_amount = get_name($opd_sundries_ids[$i], "id", "non_insured_price", "sundries");
}
}
}
}
$opd_sundry_amount = $saved_sundry_prices[$opd_sundries_ids[$i]] ?? $opd_sundry_amount;
$opd_sund_insurance_amount = $saved_chi_sundry_prices[$opd_sundries_ids[$i]] ?? $opd_sund_insurance_amount;
// get the subtotal for this sundry
$opd_sundry_subtotal = $opd_sundries_quantity[$orders_count] * $opd_sundry_amount;
$opd_sundry_insurance_subtotal = $opd_sundries_quantity[$orders_count] * $opd_sund_insurance_amount;
@endphp
<tr>
<td>
@if($is_insured)
<label style="color:green;">{{ get_name($opd_sundries_ids[$i], "id", "name", "sundries") }}</label>
@else
<label style="color:orange;">{{ get_name($opd_sundries_ids[$i], "id", "name", "sundries") }}</label>
@endif
{{ Form::hidden('opd_sundries_ids[]', $opd_sundries_ids[$i]) }}
{{ Form::hidden('opd_sundries_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('opd_sundries_tariff_ids[]', $tariff_id) }}
</td>
<td>
{{ Form::number('opd_sundry_amount[]', $opd_sundry_amount, ['class' => 'form-control', 'readonly', 'id' => 'opd_sundry_amount_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('opd_sundry_insurance_unit[]', $opd_sund_insurance_amount, ['class' => 'form-control opd_sundry_insurance_unit', 'id' => 'opd_sundry_insurance_unit_' . $counter]) }}
@else
{{ Form::number('opd_sundry_insurance_unit[]', $opd_sund_insurance_amount, ['class' => 'form-control opd_sundry_insurance_unit', 'readonly', 'id' => 'opd_sundry_insurance_unit_' . $counter]) }}
@endif
</td>
{{ Form::hidden('opd_sundry_summed[]', $opd_sund_insurance_amount + $opd_sundry_amount, ['id' => 'opd_sundry_summed_' . $counter]) }}
<td>
{{ Form::number('opd_sundry_quantity[]', $opd_sundries_quantity[$orders_count], ['class' => 'form-control', 'readonly', 'id' => 'opd_sundry_quantity_' . $counter]) }}
</td>
<td>
{{ Form::number('opd_sundry_subtotal[]', $opd_sundry_subtotal, ['class' => 'form-control opd_sundry_subtotal', 'readonly', 'id' => 'opd_sundry_subtotal_' . $counter]) }}
{{ Form::hidden('opd_sundry_insurance_status[]', $is_insured) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('opd_sundry_insurance_amount[]', $opd_sundry_insurance_subtotal, ['class' => 'form-control opd_sundry_insurance_amount', 'readonly', 'id' => 'opd_sundry_insurance_amount_' . $counter]) }}
</td>
</tr>
@php
$orders_count++;
$opd_sundries_total_cost += $opd_sundry_subtotal;
$opd_insurance_sundries += $opd_sundry_insurance_subtotal;
$counter++;
@endphp
@endfor
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('opd_sundries_cost', $opd_sundries_total_cost, ['id' => 'opd_sundries_cost']) }}
{{ Form::hidden('insurance_opd_sundries_cost', $opd_insurance_sundries, ['id' => 'insurance_opd_sundries_cost']) }}
{{ Form::text('display_opd_sundries_cost', ugandan_shillings_with_decimals($opd_sundries_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_opd_sundries_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_opd_sundries_cost', ugandan_shillings_with_decimals($opd_insurance_sundries), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_opd_sundries_cost']) }}
@endif
</div>
</div>
@endif
{{-- services section below --}}
<hr @if(count($ward_sundry_quantities_given) < 1 && count($opd_unpaid_sundries) < 1) style="display: none" @endif>
@php
$services_total_cost = 0;
$ward_services_quantities_given = DB::table('ward_consultations_and_services')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
@endphp
<div class="row" @if(count($ward_services_quantities_given) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.consultation_and_services') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" style="padding: 0px;" data-target="#consultationAndServicesDetails">{{ __('inpatient.view_consultation_and_services_details') }}</a></div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.unit_cost') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('inpatient.quantity') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@foreach($ward_services_quantities_given as $record)
@php
$services_cost = 0;
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$service_amount_insurance = 0;
$service_id = 0;
if(array_key_exists($record->service_id, $services_with_users_array)){
$custom_service_name = $services_with_users_array[$record->service_id];
$services_user_key = explode("__", $record->service_id);
$service_id = $services_user_key[0];
} else {
$service_id = $record->service_id;
}
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $service_id, 1, true, $inpatient_info->ward_id);
$services_cost = $item_insurance_details[2];
$service_amount_insurance = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if ($price_list_set && $price_list_set != 0){
$services_cost = get_price_list_category_price($price_list_set, 6, $service_id);
} elseif ($price_list_id) {
$services_cost = get_price_list_category_price($price_list_id, 6, $service_id);
} else {
$services_cost = get_name($service_id, "id", "non_insured_price", "services");
}
}
$services_cost = (is_null($price_list_set) || $price_list_set == "") ? $record->unit_price : $services_cost;
$service_amount_insurance = $record->chi_price;
$services_total_cost += ($services_cost * $record->quantity_given);
$insurance_services += ($record->quantity_given * $service_amount_insurance);
@endphp
<tr>
<td>
@if($is_insured)
<label style="color:green;">{{ $service_items[$record->service_id] ?? "" }}</label>
@else
<label style="color:orange;">{{ $service_items[$record->service_id] ?? "" }}</label>
@endif
{{ Form::hidden('service_item_ids[]', $record->service_id) }}
{{ Form::hidden('service_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('service_tariff_ids[]', $tariff_id) }}
</td>
<td>
{{ Form::number('services_item_prices[]', $services_cost, ['class' => 'form-control', 'readonly', 'id' => 'services_item_prices_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('service_insurance_unit[]', $service_amount_insurance, ['class' => 'form-control service_insurance_unit', 'id' => 'service_insurance_unit_' . $counter]) }}
@else
{{ Form::number('service_insurance_unit[]', $service_amount_insurance, ['class' => 'form-control service_insurance_unit', 'readonly', 'id' => 'service_insurance_unit_' . $counter]) }}
@endif
</td>
{{ Form::hidden('service_summed[]', $services_cost + $service_amount_insurance, ['id' => 'service_summed_' . $counter]) }}
<td>
{{ Form::number('service_quantity[]', $record->quantity_given, ['class' => 'form-control', 'readonly', 'id' => 'service_quantity_' . $counter]) }}
</td>
<td>
<input type="hidden" name="services_item_ids[]" value="{{ $record->service_id }}">
{{ Form::number('service_total_cost[]', $services_cost * $record->quantity_given, ['class' => 'form-control service_total_cost', 'readonly', 'id' => 'service_total_cost_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('service_insurance_amount[]', $record->quantity_given * $service_amount_insurance, ['class' => 'form-control service_insurance_amount', 'readonly', 'id' => 'service_insurance_amount_' . $counter]) }}
</td>
</tr>
@php $counter++; @endphp
@endforeach
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('services_cost', $services_total_cost, ['id' => 'grand_services_cost']) }}
{{ Form::hidden('insurance_services_cost', $insurance_services, ['id' => 'insurance_services_cost']) }}
{{ Form::text('display_services_cost', ugandan_shillings_with_decimals($services_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_services_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_services_cost', ugandan_shillings_with_decimals($insurance_services), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_services_cost']) }}
@endif
</div>
</div>
{{-- opd unpaid services --}}
@php
$opd_unpaid_services = \Streamline\Models\OrderedService::where(['patient_id' => $patient_id, 'episode_id' => $episode_id,'payment_status' => 0,'inpatient_bill_generated' => 0])->get();
$opd_services_amount_total = $opd_services_insurance_amount_total = 0;
@endphp
@if (count($opd_unpaid_services) > 0)
<hr>
<div class="row" @if(count($opd_unpaid_services) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.unpaid_opd_services') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.unit_cost') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('inpatient.quantity') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@foreach($opd_unpaid_services as $used_service)
@php
$service_ids = explode(",", $used_service->service_id);
$service_quantity = explode(",", $used_service->quantity);
$ordered_services_amounts = (is_null($used_service->service_amount) || $used_service->service_amount == '') ? []: explode(",", $used_service->service_amount);
@endphp
{{ Form::hidden('opd_service_order_id[]', $used_service->id) }}
@for($i = 0; $i < count($service_ids); $i++)
@php
$service_cost = 0;
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$opd_service_insurance = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $service_ids[$i], 1, true, $inpatient_info->ward_id);
$service_cost = $item_insurance_details[2];
$opd_service_insurance = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if($price_list_set && $price_list_set != 0){
$service_cost = get_price_list_category_price($price_list_set, 6, $service_ids[$i]);
}else if($price_list_id){
$service_cost = get_price_list_category_price($price_list_id, 6, $service_ids[$i]);
} else {
$pre_order = \Streamline\Models\Services::withTrashed()->find($service_ids[$i]);
//if amount was set at time of ordering
if (isset($ordered_services_amounts[$i]) && !is_null($ordered_services_amounts[$i])) {
$service_cost = $ordered_services_amounts[$i];
} else{
$service_cost = $pre_order->non_insured_price;
}
}
}
$service_cost = $saved_services_prices[$service_ids[$i]] ?? $service_cost;
$opd_service_insurance = $saved_chi_services_prices[$service_ids[$i]] ?? $opd_service_insurance;
@endphp
<tr>
<td>
@if($is_insured == 1)
<label style="color:green;">{{ $service_items[$service_ids[$i]] ?? "" }}</label>
@else
<label style="color:orange;">{{ $service_items[$service_ids[$i]] ?? "" }}</label>
@endif
{{ Form::hidden('opd_service_id[]', $service_ids[$i]) }}
{{ Form::hidden('opd_service_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('opd_service_tariff_ids[]', $tariff_id) }}
{{ Form::hidden('opd_service_insurance_status[]', $is_insured) }}
</td>
<td>
{{ Form::number('opd_service_unit_cost[]', $service_cost, ['class' => 'form-control', 'readonly', 'id' => 'opd_service_unit_cost_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('opd_service_insurance_unit[]', $opd_service_insurance, ['class' => 'form-control opd_service_insurance_unit', 'id' => 'opd_service_insurance_unit_' . $counter]) }}
@else
{{ Form::number('opd_service_insurance_unit[]', $opd_service_insurance, ['class' => 'form-control opd_service_insurance_unit', 'readonly', 'id' => 'opd_service_insurance_unit_' . $counter]) }}
@endif
</td>
{{ Form::hidden('opd_services_summed[]', $service_cost + $opd_service_insurance, ['id' => 'opd_services_summed_' . $counter]) }}
<td>
{{ Form::number('opd_service_quantity[]', $service_quantity[$i], ['class' => 'form-control', 'readonly', 'id' => 'opd_service_quantity_' . $counter]) }}
</td>
<td>
{{ Form::number('opd_service_amount[]', $service_cost * $service_quantity[$i], ['class' => 'form-control opd_service_amount', 'readonly', 'id' => 'opd_service_amount_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('opd_service_insurance_amount[]', $opd_service_insurance * $service_quantity[$i], ['class' => 'form-control opd_service_insurance_amount', 'readonly', 'id' => 'opd_service_insurance_amount_' . $counter]) }}
</td>
</tr>
@php
$opd_services_amount_total += ($service_cost * $service_quantity[$i]);
$opd_services_insurance_amount_total += ($opd_service_insurance * $service_quantity[$i]);
$counter++;
@endphp
@endfor
@endforeach
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('opd_services_cost', $opd_services_amount_total, ['id' => 'opd_services_cost']) }}
{{ Form::hidden('insurance_opd_services_cost', $opd_services_insurance_amount_total, ['id' => 'insurance_opd_services_cost']) }}
{{ Form::text('display_opd_services_cost', ugandan_shillings_with_decimals($opd_services_amount_total), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_opd_services_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_opd_services_cost', ugandan_shillings_with_decimals($opd_services_insurance_amount_total), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_opd_services_cost']) }}
@endif
</div>
</div>
@endif
<hr @if(count($ward_services_quantities_given) < 1) style="display: none" @endif>
@php
$ward_procedures = DB::table('ward_procedures')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$procedures_total_cost = 0;
@endphp
<div class="row" @if(count($ward_procedures) < 1) style="display: none" @endif >
<div class="col-md-2">{{ __('inpatient.procedures') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" style="padding: 0px;" data-target="#proceduresConsumptionDetails">{{ __('inpatient.view_procedures_details') }}</a></div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.hospital_fee') }}</th>
<th>{{ __('inpatient.staff_fee') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@foreach($ward_procedures as $ward_procedure)
@php
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$procedure_amount_insurance = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $ward_procedure->procedure_id, 2, true, $inpatient_info->ward_id);
$procedure_price = $item_insurance_details[2];
$procedure_amount_insurance = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
$procedure_price = 0;
if ($price_list_set && $price_list_set != 0){
$procedure_price = get_price_list_category_price($price_list_set, 4, $ward_procedure->procedure_id);
} elseif ($price_list_id) {
$procedure_price = get_price_list_category_price($price_list_id, 4, $ward_procedure->procedure_id);
} else {
$procedure_price = get_name($ward_procedure->procedure_id, "id", "non_insured_price", "procedures");
}
}
$procedure_price = (is_null($price_list_set) || $price_list_set == "") ? $ward_procedure->hospital_fee : $procedure_price;
$procedure_amount_insurance = $ward_procedure->chi_price;
$procedures_cost = $procedure_price + $ward_procedure->staff_fee;
$procedures_total_cost += $procedures_cost;
$insurance_procedures += $procedure_amount_insurance;
@endphp
<tr>
<td>
@if($is_insured)
<label style="color:green;">{{ get_name($ward_procedure->procedure_id, "id", "name", "procedures") }}</label>
@else
<label style="color:orange;">{{ get_name($ward_procedure->procedure_id, "id", "name", "procedures") }}</label>
@endif
{{ Form::hidden('ipd_procedure_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('ipd_procedure_tariff_ids[]', $tariff_id) }}
{{ Form::hidden('ipd_procedure_order_ids[]', $ward_procedure->id) }}
</td>
<td>
{{ Form::number('ipd_procedure_amount[]', $procedure_price, ['class' => 'form-control', 'readonly', 'id' => 'ipd_procedure_amount_' . $counter]) }}
</td>
<td>
{{ Form::number('ipd_procedure_staff_fee[]', $ward_procedure->staff_fee, ['class' => 'form-control', 'readonly', 'id' => 'ipd_procedure_staff_fee_' . $counter]) }}
</td>
<td>
<input type="hidden" name="procedures_item_ids[]" value="{{ $ward_procedure->procedure_id }}">
{{ Form::number('procedures_item_prices[]', $procedures_cost, ['class' => 'form-control procedures_item_prices', 'readonly', 'id' => 'procedures_item_prices_' . $counter]) }}
</td>
{{ Form::hidden('ipd_procedure_summed[]', $procedure_price + $procedure_amount_insurance, ['id' => 'ipd_procedure_summed_' . $counter]) }}
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('ipd_procedure_insurance_amount[]', $procedure_amount_insurance, ['class' => 'form-control ipd_procedure_insurance_amount', 'id' => 'ipd_procedure_insurance_amount_' . $counter]) }}
@else
{{ Form::number('ipd_procedure_insurance_amount[]', $procedure_amount_insurance, ['class' => 'form-control ipd_procedure_insurance_amount', 'readonly', 'id' => 'ipd_procedure_insurance_amount_' . $counter]) }}
@endif
</td>
</tr>
@php $counter++; @endphp
@endforeach
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('procedures_cost', $procedures_total_cost, ['id' => 'procedures_cost']) }}
{{ Form::hidden('insurance_procedures_cost', $insurance_procedures, ['id' => 'insurance_procedures_cost']) }}
{{ Form::text('display_procedures_cost', ugandan_shillings_with_decimals($procedures_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_procedures_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_procedures_cost', ugandan_shillings_with_decimals($insurance_procedures), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_procedures_cost']) }}
@endif
</div>
</div>
{{-- opd unpaid procedures --}}
@php
$opd_unpaid_procedures = \Streamline\Models\OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id,'payment_status' => 0,'inpatient_bill_generated' => 0])->get();
$opd_procedures_total_cost = $opd_insurance_procedures = 0;
@endphp
<hr @if(empty($inpatient_procedures)) style="display: none" @endif>
@if (count($opd_unpaid_procedures) > 0)
@php
$opd_procedure_ids = [];
$opd_procedure_order_ids = [];
// amounts at the time was ordered
$opd_procedures_orders_amounts = [];
foreach($opd_unpaid_procedures as $opd_ordered_procedure){
$opd_procedure_ids = array_merge($opd_procedure_ids, explode(",", $opd_ordered_procedure->procedure_id));
array_push($opd_procedure_order_ids, $opd_ordered_procedure->id);
//if amounts are put at the time of ordering
$opd_procedures_orders_amounts = is_null($opd_ordered_procedure->procedure_amount) ? array_merge($opd_procedures_orders_amounts, []) : array_merge($opd_procedures_orders_amounts, explode(",", $opd_ordered_procedure->procedure_amount));
}
$opd_count_orders = count($opd_procedure_order_ids);
// create strings from arrays to use when submitting
$opd_procedure_order_ids_string = implode(',', $opd_procedure_order_ids);
$opd_procedure_ids_string = implode(',', $opd_procedure_ids);
$procedure_orders_amounts_string = implode(',', $opd_procedures_orders_amounts);
@endphp
<div class="row" @if(count($opd_unpaid_procedures) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.unpaid_opd_procedures') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('patient_finance.procedure_name') }}</th>
<th>{{ __('patient_finance.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@php
$opd_procedure_amount = 0;
@endphp
{{ Form::hidden('opd_procedure_order_ids', $opd_procedure_order_ids_string) }}
{{ Form::hidden('opd_procedure_ids', $opd_procedure_ids_string) }}
@for ($i = 0; $i < count($opd_procedure_ids); $i++)
@php
// insurance flag
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$opd_insurance_amount = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $opd_procedure_ids[$i], 2, true, $inpatient_info->ward_id);
$opd_procedure_amount = $item_insurance_details[2];
$opd_insurance_amount = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
// check if the patient category is attached to a price list
if ($price_list_set && $price_list_set != 0){
$opd_procedure_amount = get_price_list_category_price($price_list_set, 4, $opd_procedure_ids[$i]);
} elseif ($price_list_id) {
$opd_procedure_amount = get_price_list_category_price($price_list_id, 4, $opd_procedure_ids[$i]);
} else {
//if amount was set at time of ordering
if (isset($opd_procedures_orders_amounts[$i]) && !is_null($opd_procedures_orders_amounts[$i])) {
$opd_procedure_amount = $opd_procedures_orders_amounts[$i];
} else{
$opd_procedure_amount = get_name($opd_procedure_ids[$i], "id", "non_insured_price", "procedures");
}
}
}
$opd_procedure_amount = $saved_procedures_prices[$opd_procedure_ids[$i]] ?? $opd_procedure_amount;
$opd_insurance_amount = $saved_chi_procedures_prices[$opd_procedure_ids[$i]] ?? $opd_insurance_amount;
// add amounts to totals
$opd_procedure_amount_total += $opd_procedure_amount;
$opd_procedure_insurance_amount_total += $opd_insurance_amount;
@endphp
<tr>
<td>
@if($is_insured)
<label style="color:green;">{{ get_name($opd_procedure_ids[$i], "id", "name", "procedures") }}</label>
@else
<label style="color:orange;">{{ get_name($opd_procedure_ids[$i], "id", "name", "procedures") }}</label>
@endif
{{ Form::hidden('opd_procedure_ids[]', $opd_procedure_ids[$i]) }}
{{ Form::hidden('opd_procedure_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('opd_procedure_tariff_ids[]', $tariff_id) }}
</td>
{{ Form::hidden('opd_procedure_summed[]', $opd_procedure_amount + $opd_insurance_amount, ['id' => 'opd_procedure_summed_' . $counter]) }}
<td>
{{ Form::number('opd_procedure_amount[]', $opd_procedure_amount, ['class' => 'form-control opd_procedure_amount', 'readonly', 'id' => 'opd_procedure_amount_' . $counter]) }}
{{ Form::hidden('opd_procedure_insurance_status[]', $is_insured) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('opd_procedure_insurance_amount[]', $opd_insurance_amount, ['class' => 'form-control opd_procedure_insurance_amount', 'id' => 'opd_procedure_insurance_amount_' . $counter]) }}
@else
{{ Form::number('opd_procedure_insurance_amount[]', $opd_insurance_amount, ['class' => 'form-control opd_procedure_insurance_amount', 'readonly', 'id' => 'opd_procedure_insurance_amount_' . $counter]) }}
@endif
</td>
</tr>
@php $counter++; @endphp
@endfor
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('opd_procedures_cost', $opd_procedure_amount_total, ['id' => 'opd_procedures_cost']) }}
{{ Form::hidden('insurance_opd_procedures_cost', $opd_procedure_insurance_amount_total, ['id' => 'insurance_opd_procedures_cost']) }}
{{ Form::text('display_opd_procedures_cost', ugandan_shillings_with_decimals($opd_procedure_amount_total), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_opd_procedures_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_opd_procedures_cost', ugandan_shillings_with_decimals($opd_procedure_insurance_amount_total), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_opd_procedures_cost']) }}
@endif
</div>
</div>
@endif
<hr @if(empty($opd_unpaid_procedures) || empty($inpatient_procedures)) style="display: none" @endif>
@php $drugs_given_anae_cost_total = 0; @endphp
{{--<?php if ($anaesthesia && !is_null($anaesthesia->other_drugs_given)): ?>
<div class="row">
<div class="col-md-2">{{ __('inpatient.anaesthetics') }}</div>
<div class="col-md-8">
<table class="table table-bordered color-bordered-table success-bordered-table table-sm">
<thead>
<tr>
<th>{{ __('inpatient.drug_name') }}</th>
<th>{{ __('inpatient.dose') }}</th>
<th>{{ __('inpatient.unit_price') }}</th>
</tr>
</thead>
<tbody>
<?php
$drugs_given_anae = unserialize($anaesthesia->other_drugs_given);
$drugs_given_anae_cost = unserialize($anaesthesia->other_drugs_cost);
$do_not_bill_other_drugs = explode(",", $anaesthesia->other_drugs_bill);
$drugs = DB::table('drugs')->where('available', 1)->whereNull('deleted_at')->pluck('name', 'id');
$units = DB::table('drug_units')->whereNull('deleted_at')->pluck('name', 'id');
if (count($drugs_given_anae) > 0) {
foreach ($drugs_given_anae as $key => $value) {
if (isset($drugs[$value['id']]) && !in_array($value['id'], $do_not_bill_other_drugs)) {
$name = $drugs[$value['id']] ?? "";
$dose = $value['dose'] ?? "";
$unit = $units[$value['unit']] ?? "";
$cost = isset($drugs_given_anae_cost[$key]) ? trim($drugs_given_anae_cost[$key]) : 0;
$drugs_given_anae_cost_total += $cost;
echo "<tr>"
. "<td>{$name}</td>"
. "<td>{$dose}{$unit}</td>"
. "<td>".ugandan_shillings_with_decimals($cost)."</td>"
. "</tr>";
}
}
}
?>
</tbody>
</table>
</div>
<div class="col-md-2">
<?php echo Form::text('display_anaesthetics_drugs_cost', ugandan_shillings_with_decimals($drugs_given_anae_cost_total), ['class' => 'form-control compulsory', 'readonly']); ?>
</div>
</div>
<hr>
<?php endif; ?>--}}
<div class="row" @if(count($treatment_to_take_away) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.tta') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.unit_price') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_unit_price') }}</th>
<th>{{ __('inpatient.quantity') }}</th>
<th>{{ __('inpatient.patient_to_pay') }}</th>
<th @if(!$patient_insurance_status) style="display: none" @endif>{{ __('inpatient.insurance_to_pay') }}</th>
</tr>
</thead>
<tbody>
@php $tta_total_cost = 0; @endphp
@if(count($treatment_to_take_away) > 0)
@foreach($treatment_to_take_away as $treatment)
@php
$tta_drugs_array = explode(",", $treatment->drugs);
$tta_dispensed_array = explode(",", $treatment->quantities_dispensed);
$tta_unit_selling_prices_array = is_null($treatment->unit_selling_prices) ? [] : explode(",", $treatment->unit_selling_prices);
@endphp
@for($x = 0; $x < count($tta_drugs_array); $x++)
@php
$is_insured = 0;
$tariff_id = 0;
$benefit_id = 0;
$tta_insurance_amount = 0;
if($patient_insurance_status){
$item_insurance_details = get_item_insurance_pricing($patient_id, $tta_drugs_array[$x], 4, true, $inpatient_info->ward_id);
$drugs_cost = $item_insurance_details[2];
$tta_insurance_amount = $item_insurance_details[1];
$is_insured = $item_insurance_details[0];
$tariff_id = $item_insurance_details[3];
$benefit_id = $item_insurance_details[4];
} else {
if (isset($tta_unit_selling_prices_array[$x])) {
$drugs_cost = is_numeric($tta_unit_selling_prices_array[$x]) ? $tta_unit_selling_prices_array[$x] : 0;
} else {
if ($price_list_set && $price_list_set != 0){
$drugs_cost = get_price_list_category_price($price_list_set, 3, $tta_drugs_array[$x]);
} elseif ($price_list_id) {
$drugs_cost = get_price_list_category_price($price_list_id, 3, $tta_drugs_array[$x]);
} else {
$drugs_cost = get_name($tta_drugs_array[$x], "id", "non_insured_price", "drugs");
}
}
}
$drugs_cost = $saved_tta_prices[$tta_drugs_array[$x]] ?? $drugs_cost;
$tta_insurance_amount = $saved_chi_tta_prices[$tta_drugs_array[$x]] ?? $tta_insurance_amount;
$insurance_tta += $tta_dispensed_array[$x] * $tta_insurance_amount;
@endphp
<tr>
<td>
@if($is_insured == 1)
<label style="color:green;">{{ get_name($tta_drugs_array[$x], "id", "name", "drugs") }}</label>
@else
<label style="color:orange;">{{ get_name($tta_drugs_array[$x], "id", "name", "drugs") }}</label>
@endif
{{ Form::hidden('tta_drugs_array[]', $tta_drugs_array[$x]) }}
{{ Form::hidden('tta_tariff_ids[]', $tariff_id) }}
{{ Form::hidden('tta_benefit_ids[]', $benefit_id) }}
{{ Form::hidden('tta_treatment_id[]', $treatment->id) }}
{{ Form::hidden('tta_inpatient_bill_generated[]', $treatment->inpatient_bill_generated) }}
</td>
<td>
{{ Form::number('tta_unit_cost[]', $drugs_cost, ['class' => 'form-control', 'readonly', 'id' => 'tta_unit_cost_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
@if($is_insured == 1 && Auth::user()->can('chi-to-pay-edit'))
{{ Form::number('tta_insurance_unit[]', $tta_insurance_amount, ['class' => 'form-control tta_insurance_unit', 'id' => 'tta_insurance_unit_' . $counter]) }}
@else
{{ Form::number('tta_insurance_unit[]', $tta_insurance_amount, ['class' => 'form-control tta_insurance_unit', 'readonly', 'id' => 'tta_insurance_unit_' . $counter]) }}
@endif
</td>
{{ Form::hidden('tta_summed[]', $drugs_cost + $tta_insurance_amount, ['id' => 'tta_summed_' . $counter]) }}
<td>
{{ Form::number('tta_quantity[]', $tta_dispensed_array[$x], ['class' => 'form-control', 'readonly', 'id' => 'tta_quantity_' . $counter]) }}
</td>
<td>
@php $tta_total_cost += $drugs_cost * $tta_dispensed_array[$x]; @endphp
{{ Form::number('tta_amount[]', $drugs_cost * $tta_dispensed_array[$x], ['class' => 'form-control tta_amount', 'readonly', 'id' => 'tta_amount_' . $counter]) }}
</td>
<td @if(!$patient_insurance_status) style="display: none" @endif>
{{ Form::number('tta_insurance_amount[]', $tta_dispensed_array[$x] * $tta_insurance_amount, ['class' => 'form-control tta_insurance_amount', 'readonly', 'id' => 'tta_insurance_amount_' . $counter]) }}
</td>
</tr>
@php $counter++; @endphp
@endfor
<tr>
<td colspan="3">
{{ __('inpatient.ordered_by') }} : <font color="blue">{{ get_full_name($treatment->created_by, "id", "first_name", "last_name", "users") }}</font>
</td>
</tr>
@endforeach
@else
<tr>
<td colspan="3" class="text-center" style="color: maroon">{{ __('inpatient.no_tta_ordered') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.patient_to_pay') }}
<br>
{{ Form::hidden('tta_cost', $tta_total_cost, ['id' => 'tta_cost']) }}
{{ Form::hidden('insurance_tta_cost', $insurance_tta, ['id' => 'insurance_tta_cost']) }}
{{ Form::text('display_tta_cost', ugandan_shillings_with_decimals($tta_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_tta_cost']) }}
@if($patient_insurance_status)
<br>
{{ __('inpatient.insurance_to_pay') }}
<br>
{{ Form::text('display_insurance_tta_cost', ugandan_shillings_with_decimals($insurance_tta), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_tta_cost']) }}
@endif
</div>
</div>
<hr @if(count($treatment_to_take_away) < 1) style="display: none" @endif>
<?php
$extras_total_cost = 0;
$ward_extras_given = DB::table('ward_extras')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
?>
<div class="row" @if(count($ward_extras_given) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.extras') }}<br><a type="button" class="btn btn-sm btn-link text-blue" data-toggle="modal" style="padding: 0px;" data-target="#extrasConsumptionDetails">{{ __('inpatient.view_extras_consumption_details') }}</a></div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.name') }}</th>
<th>{{ __('inpatient.cost') }}</th>
</tr>
</thead>
<tbody>
@if(count($ward_extras_given) > 0)
@foreach($ward_extras_given as $extras_record)
<tr>
<td>{{ $extras_record->extra_item }}</td>
<td>{{ ugandan_shillings_with_decimals($extras_record->extra_cost) }}</td>
</tr>
@php $extras_total_cost += $extras_record->extra_cost; @endphp
@endforeach
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ Form::hidden('extras_cost', $extras_total_cost, ['id' => 'extras_cost']) }}
{{ Form::text('display_extras_cost', ugandan_shillings_with_decimals($extras_total_cost), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_extras_cost']) }}
</div>
</div>
<hr @if(empty($inpatient_extras)) style="display: none" @endif>
@php
$unpaid_opd_grand_total = $opd_unpaid_treatment_total + $opd_sundries_total_cost + $opd_services_amount_total + $opd_procedure_amount_total;
$amount_to_pay = $extras_total_cost + $tta_total_cost + $procedures_total_cost + $sundries_total_cost + $treatment_total_cost + $admission_cost + $investigation_amount_total + $services_total_cost + $drugs_given_anae_cost_total + $unpaid_opd_grand_total;
$total_insurance_payment = $chi_ward_accomodation_to_pay + $insurance_investigations + $insurance_treatments + $insurance_sundries + $insurance_procedures + $insurance_tta + $insurance_services +
$insurance_opd_treatment + $opd_insurance_sundries + $opd_services_insurance_amount_total + $opd_procedure_insurance_amount_total;
@endphp
@if(count($service_deposits) > 0)
@foreach($service_deposits as $service_deposit)
@if(($service_deposit->service_type == "Inpatient_Deposit") && ($service_deposit->patient_id == $patient_id) && ($service_deposit->episode_id == $episode_id))
@php
$total_deposits_paid += $service_deposit->patient_amount_paid;
@endphp
@endif
@endforeach
@endif
@php
$co_payment = check_patient_category_co_payment_status($patient->category_id);
$total_copayment_share = 0;
if(!empty($co_payment) && $co_payment['co_payment_share'] != 0){
$total_copayment_share = $amount_to_pay / $co_payment['co_payment_share'];
}
@endphp
<div class="row">
<div class="col-md-4">
<b>{{ __('inpatient.initial_total_bill') }}</b>
<br><br>
{{ Form::text('display_insurance_amount_owed', ugandan_shillings_with_decimals((int)$total_insurance_payment + (int)$amount_to_pay), ['class' => 'form-control compulsory', 'readonly']) }}
</div>
<div class="col-md-4">
<b>{{ __('inpatient.patient_to_pay_total') }}</b>
<br><br>
{{ Form::hidden('original_amount_owed', (int)$amount_to_pay, ['id' => 'original_amount_owed']) }}
{{ Form::text('display_amount_owed', ugandan_shillings_with_decimals((int)$amount_to_pay), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_amount_owed']) }}
</div>
@if($total_insurance_payment == 0)
<div class="col-md-4">
<b>{{ __('inpatient.insurance_to_pay_total') }}</b>
<br><br>
{{ Form::hidden('original_insurance_amount_owed', (int)$total_insurance_payment, ['id' => 'original_insurance_amount_owed']) }}
{{ Form::text('display_insurance_amount_owed', ugandan_shillings_with_decimals($total_insurance_payment), ['class' => 'form-control compulsory', 'readonly', 'id' => 'display_insurance_amount_owed']) }}
</div>
@endif
</div>
</div>
@php
$ward_discount_records = \Streamline\Models\InpatientWardDiscounts::where(['inpatient_info_id' => $inpatient_info->id])->get();
$ward_discount_total = 0;
@endphp
@if(count($ward_discount_records) > 0)
<hr id="tenth_hr">
<div class="row">
<div class="col-md-2">{{ __('inpatient.ward_discount_amount') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.staff_in_charge') }}</th>
<th>{{ __('inpatient.ward') }}</th>
<th>{{ __('inpatient.amount') }}</th>
<th>{{ __('inpatient.date_received') }}</th>
</tr>
</thead>
<tbody>
@if(count($ward_discount_records) > 0)
@foreach($ward_discount_records as $ward_discount)
<tr>
<td>{{ get_full_name($ward_discount->created_by, 'id', 'first_name', 'last_name', 'users') }}</td>
<td>{{ get_name($ward_discount->ward_id, 'id', 'name', 'wards') }}</td>
<td>{{ ugandan_shillings_with_decimals($ward_discount->amount) }}</td>
<td>{{ streamline_date_time($ward_discount->created_at) }}</td>
@php
$ward_discount_total += $ward_discount->amount;
@endphp
</tr>
@endforeach
@else
<tr>
<td colspan="3">{{ __('inpatient.no_ward_discounts_given') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.total_ward_discount_amount') }}
<br>
{{ Form::hidden('ward_discount_total', $ward_discount_total, ['id' => 'ward_discount_total']) }}
{{ Form::text('display_ward_discount_total', ugandan_shillings_with_decimals($ward_discount_total), ['class' => 'form-control compulsory', 'readonly']) }}
</div>
</div>
@endif
<hr>
@php
$category_to_pay_deposits = 0;
$patient_category_invoices_record = \Streamline\Models\PatientCategoryInvoice::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'patient_category' => $patient->category_id])->get();
@endphp
<div class="row" @if(count($patient_category_invoices_record) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.invoices_created') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.invoice_number') }}</th>
<th>{{ __('inpatient.patient_category') }}</th>
<th>{{ __('inpatient.amount') }}</th>
<th>{{ __('inpatient.date_received') }}</th>
</tr>
</thead>
<tbody>
@if(count($patient_category_invoices_record) > 0)
@foreach($patient_category_invoices_record as $invoice_record)
@if($invoice_record->tag_id == 9 || $invoice_record->tag_id == 10)
<tr>
<td>{{ $invoice_record->receipt_number }}</td>
<td>{{ get_name($invoice_record->patient_category, "id", "name", "patient_categories") }}</td>
<td>{{ ugandan_shillings_with_decimals($invoice_record->patient_amount) }}</td>
<td>
{{ streamline_date_time($invoice_record->created_at) }}
By <span style="color: rgb(70, 122, 172); font-weight: 900">{{ get_full_name($invoice_record->created_by, "id", "first_name", "last_name", "users") }}</span>
</td>
</tr>
@php
$category_to_pay_deposits += $invoice_record->patient_amount;
@endphp
@endif
@endforeach
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.total_invoices_made') }}
<br>
{{ Form::hidden('invoices_amount', $category_to_pay_deposits, ['id' => 'invoices_amount']) }}
{{ Form::text('display_invoices_amount', ugandan_shillings_with_decimals($category_to_pay_deposits), ['class' => 'form-control compulsory', 'readonly']) }}
</div>
</div>
<hr>
@php
$dependant_consumptions_total = 0;
$dependant_consumptions = \Streamline\Models\DependantsConsumption::where(['dependant_patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
@endphp
<div class="row" @if(count($dependant_consumptions) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.consumption_on_dependant_account') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.invoice_number') }}</th>
<th>{{ __('inpatient.amount') }}</th>
<th>{{ __('inpatient.date_received') }}</th>
</tr>
</thead>
<tbody>
@if(count($dependant_consumptions) > 0)
@foreach($dependant_consumptions as $dependant_consumption_record)
@if($dependant_consumption_record->items_ids == "Inpatient-deposit")
<tr>
<td>{{ $dependant_consumption_record->receipt_number }}</td>
<td>{{ ugandan_shillings_with_decimals($dependant_consumption_record->amount_consumed) }}</td>
<td>
{{ streamline_date_time($dependant_consumption_record->created_at) }}
By <span style="color: rgb(70, 122, 172); font-weight: 900">{{ get_full_name($dependant_consumption_record->created_by, "id", "first_name", "last_name", "users") }}</span>
</td>
</tr>
@php
$dependant_consumptions_total += $dependant_consumption_record->amount_consumed;
@endphp
@endif
@endforeach
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.total_dependant_account_amount') }}
<br>
{{ Form::hidden('dependant_account', $dependant_consumptions_total, ['id' => 'dependant_account']) }}
{{ Form::text('display_dependant_account', ugandan_shillings_with_decimals($dependant_consumptions_total), ['class' => 'form-control compulsory', 'readonly']) }}
</div>
</div>
<hr @if(count($patient_category_invoices_record) < 1) style="display: none" @endif>
@php
$debt_plan_total = 0;
$debt_plan_payments = \Streamline\Models\DebtPlan::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'tag_id' => 10])->get();
@endphp
<div class="row" @if(count($debt_plan_payments) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.debt_plan_payments') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('patient_finance.received_on') }}</th>
<th>{{ __('patient_finance.patient_amount') }}</th>
</tr>
</thead>
<tbody>
@foreach($debt_plan_payments as $debt_plan_payment)
<tr>
<td>{{ streamline_date_time($debt_plan_payment->created_at) }}</td>
@php $debt_plan_total += $debt_plan_payment->staff_guarantor_to_pay; @endphp
<td>{{ ugandan_shillings_with_decimals($debt_plan_payment->staff_guarantor_to_pay) }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.total_debt_plan_payments') }}
<br>
{{ Form::hidden('debt_plan_total', $debt_plan_total, ['id' => 'debt_plan_total']) }}
{{ Form::text('display_debt_plan_total', ugandan_shillings_with_decimals($debt_plan_total), ['class' => 'form-control compulsory', 'readonly']) }}
</div>
</div>
<hr @if(count($debt_plan_payments) < 1) style="display: none" @endif>
<div class="row" @if(count($service_deposits) < 1) style="display: none" @endif>
<div class="col-md-2">{{ __('inpatient.deposits_received') }}</div>
<div class="col-md-8">
<div class="table-responsive" style="padding-left: 30px; padding-right: 30px;">
<table class="table table-bordered color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('inpatient.deposit_receipt_number') }}</th>
<th>{{ __('inpatient.amount') }}</th>
<th>{{ __('inpatient.date_received') }}</th>
</tr>
</thead>
<tbody>
@if(count($service_deposits) > 0)
@foreach($service_deposits as $service_deposit)
@php
$item_ids_array = explode(",", $service_deposit->items_ids);
$item_amounts_array = explode(",", $service_deposit->items_amounts);
@endphp
@if(($service_deposit->service_type == "Inpatient_Deposit") && ($service_deposit->patient_id == $patient_id) && ($service_deposit->episode_id == $episode_id))
<tr>
<td>{{ $service_deposit->receipt_number }}</td>
<td>{{ ugandan_shillings_with_decimals($service_deposit->patient_amount_paid) }}</td>
<td>
{{ streamline_date_time($service_deposit->created_at) }}
By <span style="color: rgb(70, 122, 172); font-weight: 900">{{ get_full_name($service_deposit->created_by, "id", "first_name", "last_name", "users") }}</span>
</td>
</tr>
@endif
@endforeach
@else
<tr>
<td colspan="3" class="text-center" style="color: maroon">{{ __('inpatient.no_deposits_made') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-2">
{{ __('inpatient.total_deposits_made') }}
<br>
{{ Form::hidden('deposits_made', (int)$total_deposits_paid, ['id' => 'deposits_made']) }}
{{ Form::text('display_deposits_made', ugandan_shillings_with_decimals($total_deposits_paid), ['class' => 'form-control compulsory', 'readonly']) }}
<br>
{{ __('inpatient.patient_balance_to_pay') }}
<br>
{{ Form::hidden('amount_owed', ((int)$amount_to_pay - (int)$total_deposits_paid - (int)$category_to_pay_deposits - (int)$ward_discount_total - (int)$debt_plan_total - (int)$dependant_consumptions_total), ['id' => 'amount_owed']) }}
{{ Form::text('display_deposits_made', ugandan_shillings_with_decimals((int)$amount_to_pay - (int)$total_deposits_paid - (int)$category_to_pay_deposits - (int)$ward_discount_total - (int)$debt_plan_total- (int)$dependant_consumptions_total), ['class' => 'form-control compulsory', 'readonly']) }}
</div>
</div>
<hr @if(count($service_deposits) < 1) style="display: none" @endif>
@if (Auth::user()->can('view-inpatient-bill-saving-history'))
@if ($inpatient_bill_info && !is_null($inpatient_bill_info->bill_saved_by))
@php
$bill_savers_array = explode(",", $inpatient_bill_info->bill_saved_by);
$saver_timestamps_array = explode(",", $inpatient_bill_info->bill_saved_at);
@endphp
<div class="card">
<div class="card-header">
{{ __('inpatient.bill_saving_trail') }}
</div>
@for ($i = 0; $i < count($bill_savers_array); $i++)
@if (isset($bill_savers_array[$i]) && isset($saver_timestamps_array[$i]))
<ul class="list-group list-group-flush">
<li class="list-group-item">
{{ get_full_name($bill_savers_array[$i], "id", "first_name", "last_name", "users") }}
<span class="float-right">{{ streamline_date_time($saver_timestamps_array[$i]) }}</span>
</li>
</ul>
@endif
@endfor
</div>
<hr>
@endif
@endif
<p><b>{{ __('inpatient.bill_checked_by') }}:</b> {{ get_full_name(Illuminate\Support\Facades\Auth::id(), "id", "first_name", "last_name", "users") }} {{ __('inpatient.on') }} {{ streamline_date_time(date("Y-m-d")) }}</p>
@if ($inpatient_bill_info)
<p>
<b>{{ __('inpatient.bill_authorized_by') }}:</b>
@php
$bill_authorized_by_array = is_null($inpatient_bill_info->bill_authorized_by) ? [] : explode(",", $inpatient_bill_info->bill_authorized_by);
$bill_authorized_at_array = is_null($inpatient_bill_info->bill_authorized_at) ? [] : explode(",",$inpatient_bill_info->bill_authorized_at);
$bill_closed = $inpatient_bill_info->bill_closed == 1;
@endphp
@for ($i = 0; $i < count($bill_authorized_by_array); $i++)
{{ get_full_name($bill_authorized_by_array[$i], "id", "first_name", "last_name", "users") }} {{ __('inpatient.on') }} {{ streamline_date_time($bill_authorized_at_array[$i]) }}
@endfor
</p>
@if($inpatient_bill_info->bill_closed == 1)
<p>
<b>{{ __('inpatient.bill_closed_by') }}:</b>
{{ get_full_name($inpatient_bill_info->bill_closed_by, "id", "first_name", "last_name", "users") }} {{ __('inpatient.on') }} {{ streamline_date_time($inpatient_bill_info->bill_closed_at) }}
</p>
@endif
@endif
<hr>
<div class="row">
@if( Auth::user()->can('view-inpatient-sheet'))
<div class="col-md-2">
<a href="{{ url('in_patient_sheet') }}" class="btn btn-info col-md-12"> {{ __('inpatient.inpatient_sheet') }} </a>
</div>
@endif
@if(Auth::user()->can('view-recalculate-inpatient-bill') && !$bill_closed)
<div class="col-md-2">
{{ Form::button(__('inpatient.re_calculate_bill'),['type'=>'submit','class' => 'btn btn-success col-md-12', 'name'=>'submit-btn','value'=>'re_calculate_bill', 'id' => 'recalculateBillBtn']) }}
</div>
@endif
@if( Auth::user()->can('authorize-inpatient-bill') && !$bill_closed)
<div class="col-md-2">
{{ Form::button(__('inpatient.authorize_bill'),['type'=>'submit','class' => 'btn btn-primary col-md-12', 'name'=>'submit-btn','value'=>'authorize_bill']) }}
</div>
@endif
<div class="col-md-2">
<a href="{{ url('in_patient_bill_print') }}/{{ $patient_id }}/{{ $episode_id }}/{{ $price_list_set_serial }}" target="_blank" class="btn btn-default col-md-12">{{ __('inpatient.print_detailed_bill') }}</a>
</div>
<div class="col-md-2">
<a href="{{ url('inpatient_bill_summary_print') }}/{{ $patient_id }}/{{ $episode_id }}/{{ $price_list_set_serial }}" target="_blank" class="btn btn-default col-md-12">{{ __('inpatient.print_bIll_summary') }}</a>
</div>
@if (Auth::user()->can('pay-inpatient-bill-from-inpatient-billing-page') && !$bill_closed)
<div class="col-md-2">
{{ Form::button(__('inpatient.pay_bill'),['type'=>'submit','class' => 'btn btn-success col-md-12', 'name'=>'submit-btn','value'=>'pay_bill']) }}
</div>
@endif
@if (Auth::user()->can('open-inpatient-bill') && $bill_closed)
<div class="col-md-2">
<a href="/open_inpatient_bill/{{ $inpatient_bill_info->id }}" class="btn btn-success col-md-12"> {{ __('inpatient.open_bill') }} </a>
</div>
@endif
</div>
<br>
<div class="row">
@if (Auth::user()->can('save-inpatient-bill') && !$bill_closed)
<div class="col-md-2">
{{ Form::button(__('inpatient.save_bill'),['type'=>'submit','class' => 'btn btn-success col-md-12', 'name'=>'submit-btn','value'=>'save']) }}
</div>
@endif
@if (Auth::user()->can('save-and-close-inpatient-bill') && $inpatient_info->discharged == 1 && !$bill_closed)
<div class="col-md-2">
{{ Form::button(__('inpatient.save_close_bill'),['type'=>'submit','class' => 'btn btn-success col-md-12', 'name'=>'submit-btn','value'=>'save_close_bill', 'id' => 'save_close_bill']) }}
</div>
@endif
</div>
{{ Form::close() }}
</div>
<div class="modal fade" id="wardDispensationDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="wardDispensationModalLabel1">{{ __('inpatient.ward_dispensation_details_of') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_treatment_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<?php
//get the quantity given so far of this particular treatment
$ward_quantities_given_option2 = DB::table('ward_treatment_dispensations')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->groupBy('drug_id')->selectRaw('*, sum(quantity_given) as quantity_given')->get();
?>
@if(count($ward_quantities_given_option2) > 0)
@foreach($ward_quantities_given_option2 as $record)
<div class="row" style="background-color: #dde4e6; padding: 5px; word-wrap: break-word;">
<div class="col-sm-8">
{{ get_name($record->drug_id, "id", "name", "drugs") }}
</div>
<div class="col-sm-4">
<strong>{{ __('inpatient.quantity_given') }}</strong>
</div>
<?php
$dispensation_details = \Streamline\Models\WardTreatmentDispensation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'drug_id' => $record->drug_id])->get();
?>
@foreach($dispensation_details as $dispensation)
<div class="col-sm-8">
{{ __('inpatient.date') }}: {{ streamline_date($dispensation->created_at)}}
{{ __('inpatient.by') }}: <font color="blue">{{ get_full_name($dispensation->created_by, "id", "first_name", "last_name", "users")}}</font>
</div>
<div class="col-sm-4">
{{ __('inpatient.quantity') }}:
{{ $dispensation->quantity_given }} ({{ __('inpatient.unit_price') }}:{{ugandan_shillings_with_decimals($dispensation->price) }})
</div>
@endforeach
<div class="col-sm-8" style="border-top:1px solid rgb(173 171 171);"><strong>{{ __('inpatient.total') }}</strong></div>
<div class="col-sm-4" style="border-top:1px solid rgb(173 171 171);"><strong>{{ $record->quantity_given }}</strong></div>
</div>
@endforeach
@endif
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="consultationAndServicesDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="wardDispensationModalLabel1">{{ __('inpatient.consultation_and_services') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_consultation_and_services_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<?php
$ward_services_quantities_given = DB::table('ward_consultations_and_services')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
?>
@if(count($ward_services_quantities_given) > 0)
@foreach($ward_services_quantities_given as $record)
<div class="row" style="background-color: #dde4e6; padding: 5px; word-wrap: break-word;">
<div class="col-sm-8">
{{ isset($service_items[$record->service_id]) ? $service_items[$record->service_id] : "" }}
</div>
<div class="col-sm-4">
<strong>{{ __('inpatient.quantity_given') }}</strong>
</div>
<div class="col-sm-8">
{{ __('inpatient.date') }}: {{ is_null($record->dispensation_date) ? streamline_date($record->created_at) : streamline_date($record->dispensation_date) }}
{{ __('inpatient.by') }}: <font color="blue">{{ get_full_name($record->created_by, "id", "first_name", "last_name", "users")}}</font>
</div>
<div class="col-sm-4">
{{ __('inpatient.quantity') }}:
{{ $record->quantity_given }}
</div>
<div class="col-sm-8" style="border-top:1px solid rgb(173 171 171);"><strong>{{ __('inpatient.total') }}</strong></div>
<div class="col-sm-4" style="border-top:1px solid rgb(173 171 171);"><strong>{{ $record->quantity_given }}</strong></div>
</div>
@endforeach
@endif
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="sundriesConsumptionDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="sundriesConsumptionModalLabel1">{{ __('inpatient.sundries_consumption') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_sundries_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<?php
$ward_sundry_quantities_given = DB::table('ward_sundry_dispensations')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->groupBy('sundry_id')->selectRaw('*, sum(quantity_given) as quantity_given')->get();
?>
@if(count($ward_sundry_quantities_given) > 0)
@foreach($ward_sundry_quantities_given as $record)
<div class="row" style="background-color: #dde4e6; padding: 5px; word-wrap: break-word;">
<div class="col-sm-8">
{{ $sundries[$record->sundry_id] ?? '' }}
</div>
<div class="col-sm-4">
<strong>{{ __('inpatient.quantity_given') }}</strong>
</div>
<?php
$dispensation_details = \Streamline\Models\WardSundryDispensation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'sundry_id' => $record->sundry_id])->get();
?>
@foreach($dispensation_details as $dispensation)
<div class="col-sm-8">
{{ __('inpatient.date') }}: {{ is_null($dispensation->dispensation_date) ? streamline_date($dispensation->created_at) : streamline_date($dispensation->dispensation_date) }}
{{ __('inpatient.by') }}: <font color="blue">{{ get_full_name($dispensation->created_by, "id", "first_name", "last_name", "users")}}</font>
</div>
<div class="col-sm-4">
{{ __('inpatient.quantity') }}:
{{ $dispensation->quantity_given }} ({{ __('inpatient.unit_price') }}:{{ugandan_shillings_with_decimals($dispensation->price)}})
</div>
@endforeach
<div class="col-sm-8" style="border-top:1px solid rgb(173 171 171);"><strong>{{ __('inpatient.total') }}</strong></div>
<div class="col-sm-4" style="border-top:1px solid rgb(173 171 171);"><strong>{{ $record->quantity_given }}</strong></div>
</div>
@endforeach
@endif
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="extrasConsumptionDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="extrasConsumptionModalLabel1">{{ __('inpatient.extras_consumption') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_extras_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<?php
$ward_extras_given = DB::table('ward_extras')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
?>
@if(count($ward_extras_given) > 0)
@php $total_modal_extras_cost = 0; @endphp
@foreach($ward_extras_given as $extras_record)
<div class="row" style="background-color: #dde4e6; padding: 5px; word-wrap: break-word;">
<div class="col-sm-4">
{{ __('inpatient.date') }}: {{ is_null($extras_record->dispensation_date) ? streamline_date($extras_record->created_at) : streamline_date($extras_record->dispensation_date) }}
{{ __('inpatient.by') }}: <font color="blue">{{ get_full_name($extras_record->created_by, "id", "first_name", "last_name", "users")}}</font>
</div>
<div class="col-sm-4">
{{ __('inpatient.item') }}:
{{ $extras_record->extra_item }}
</div>
<div class="col-sm-4">
{{ __('inpatient.item_cost') }}:
{{ ugandan_shillings_with_decimals($extras_record->extra_cost) }}
@php $total_modal_extras_cost += $extras_record->extra_cost; @endphp
</div>
</div>
@endforeach
<div class="row">
<div class="col-sm-6" style="border-top:1px solid rgb(173 171 171);"><strong>{{ __('inpatient.total') }}</strong></div>
<div class="col-sm-2"></div>
<div class="col-sm-4" style="border-top:1px solid rgb(173 171 171);"><strong>{{ ugandan_shillings_with_decimals($total_modal_extras_cost) }}</strong></div>
</div>
@endif
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="proceduresConsumptionDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="proceduresConsumptionModalLabel1">{{ __('inpatient.procedure_details') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_procedures_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<?php
$ward_procedures = DB::table('ward_procedures')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
?>
@if(count($ward_procedures) > 0)
@php $total_modal_procedures_cost = 0; @endphp
@foreach($ward_procedures as $ward_procedure_record)
<div class="row" style="background-color: #dde4e6; padding: 5px; word-wrap: break-word;">
<div class="col-sm-3">
Recorded By: <font color="blue">{{ get_full_name($ward_procedure_record->created_by, "id", "first_name", "last_name", "users")}}</font>
{{ __('inpatient.on') }} <b>{{ is_null($ward_procedure_record->procedure_date) ? streamline_date($ward_procedure_record->created_at) : streamline_date($ward_procedure_record->procedure_date) }}</b>
</div>
<div class="col-sm-3">
{{ __('inpatient.name') }}:
{{ get_name($ward_procedure_record->procedure_id, "id", "name", "procedures") }}
@php
$single_procedure_cost = 0;
if($ward_procedure_record->hospital_fee || $ward_procedure_record->staff_fee){
$single_procedure_cost = $ward_procedure_record->hospital_fee + $ward_procedure_record->staff_fee;
}
@endphp
({{ __('inpatient.cost') }}: {{ugandan_shillings($single_procedure_cost) }})
</div>
<div class="col-sm-2">
{{ __('inpatient.hospital_fees') }}:{{ ugandan_shillings($ward_procedure_record->hospital_fee) }}
</div>
<div class="col-sm-2">
{{ __('inpatient.staff_fees') }}:{{ ugandan_shillings($ward_procedure_record->staff_fee) }}
</div>
<div class="col-sm-2">
{{ __('inpatient.performed_by') }}:
{{ get_full_name($ward_procedure_record->performed_by, "id", "first_name", "last_name", "users") }}
</div>
</div>
@php $total_modal_procedures_cost += $single_procedure_cost; @endphp
@endforeach
<div class="row">
<div class="col-sm-3" style="border-top:1px solid rgb(173 171 171);"><strong>{{ __('inpatient.total_cost_of_procedures') }}</strong></div>
<div class="col-sm-3" style="border-top:1px solid rgb(173 171 171);"><strong>{{ ugandan_shillings($total_modal_procedures_cost) }}</strong></div>
<div class="col-sm-6" style="border-top:1px solid rgb(173 171 171);"></div>
</div>
@endif
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="bedAdmissionDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="bedAdmissionDetailsModalLabel1">{{ __('inpatient.bed_details') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_bed_stay_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered">
<?php
$ward_bed_stays = DB::table('ward_bed_stays')->whereNull('deleted_at')->where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$total_modal_bed_stay_cost = 0;
?>
@if(count($ward_bed_stays) > 0)
@foreach($ward_bed_stays as $bed_record)
<div class="row" style="background-color: #dde4e6; padding: 5px; word-wrap: break-word;">
<div class="col-sm-3">
{{ __('inpatient.recorded_by') }}: <font color="blue">{{ get_full_name($bed_record->created_by, "id", "first_name", "last_name", "users")}}</font>
{{ __('inpatient.on') }} <b>{{ streamline_date($bed_record->created_at)}}</b>
</div>
<div class="col-sm-3">
<b>{{ __('inpatient.name') }}: </b>
{{ get_name($bed_record->bed_category, "id", "name", "inpatient_bed_categories") }}
</div>
<div class="col-sm-2">
<b>{{ __('inpatient.bed') }}: </b> {{ $bed_record->bed_number }}
</div>
<div class="col-sm-2">
<b>{{ __('inpatient.from') }}: </b> {{ streamline_date($bed_record->from) }}<br>
<b>{{ __('inpatient.to') }}: </b> {{ streamline_date($bed_record->to) }}<br>
<b>{{ __('inpatient.duration') }}: </b>{{ $bed_record->duration }}
</div>
<div class="col-sm-2">
<b>{{ __('inpatient.cost') }}: </b>
{{ ugandan_shillings_with_decimals($bed_record->bed_fee_total) }}
</div>
</div>
@php $total_modal_bed_stay_cost += $bed_record->bed_fee_total; @endphp
@endforeach
<div class="row">
<div class="col-sm-10" style="border-top:1px solid rgb(173 171 171);"><strong>{{ __('inpatient.total_cost_of_ward_stay') }}</strong></div>
<div class="col-sm-2" style="border-top:1px solid rgb(173 171 171);"><strong>{{ ugandan_shillings_with_decimals($total_modal_bed_stay_cost) }}</strong></div>
</div>
@endif
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="investigationsPerformedDetails" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="proceduresConsumptionModalLabel1">{{ __('inpatient.investigations_details') }} <strong>{{ get_full_name($patient_id, "id", "first_name", "last_name", "patients") }} ({{ $patient->number }})</strong> <a class="btn btn-info btn-rounded" style="float: right;" href="{{ url('inpatient_investigations_print') }}/{{ $patient_id }}/{{ $episode_id }}" target="_blank">{{ __('inpatient.print') }}</a></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th><b>{{ __('inpatient.name') }}</b></th>
<th><b>{{ __('inpatient.value') }}</b></th>
<th><b>{{ __('inpatient.comment') }}</b></th>
</tr>
</thead>
<tbody>
<?php
// prep the inpatient investigation arrays and counters
$opd_investigations = [];
$opd_investigations_position = [];
$opd_investigations_date = [];
$ward_investigations = [];
$ward_investigations_position = [];
$ward_investigations_date = [];
// get all investigations ordered in this episode
$ordered_ward_investigations = \Streamline\Models\OrderedInvestigation::where(['episode_id' => $episode_id])->get();
// get all results
$investigation_results_order_ids = \Streamline\Models\InvestigationResults::pluck('order_id', 'id')->toArray();
foreach ($ordered_ward_investigations as $investigation) {
if (isset($ward_investigations['id'])) {
$ward_investigations_position[] = count($ward_investigations['id']);
} else {
$ward_investigations_position[] = 0;
}
if (isset($opd_investigations['id'])) {
$opd_investigations_position[] = count($opd_investigations['id']);
} else {
$opd_investigations_position[] = 0;
}
$ward_investigations_date[] = "Ordered on " . streamline_date_time($investigation->created_at) . " by " .
get_full_name($investigation->created_by, 'id', 'first_name', 'last_name', 'users');
$opd_investigations_date[] = streamline_date_time($investigation->created_at);
$investigation_ids = explode(",", $investigation->investigation_id);
$inpatient_status = explode(",", $investigation->for_inpatient);
// check if results are available for this investigation
if (in_array($investigation->id, $investigation_results_order_ids)) {
// get the key if available
$key = array_search($investigation->id, $investigation_results_order_ids);
// get the results object
$results = \Streamline\Models\InvestigationResults::find($key);
// exclude obstetric u/s results
if ($results->result_type != "Ultrasound_Obstetric") {
$investigation_results = explode(",", $results->value);
$investigation_per_valid = explode(",", $results->per_investigation);
$investigation_comments = explode(",", $results->comment);
if ($results->all_authenticated == 1) {
for ($i = 0; $i < count($inpatient_status); $i++) {
if (isset($inpatient_status[$i]) && $inpatient_status[$i] == 0) {
$result = \Streamline\Models\Investigation::withTrashed()->find($investigation_ids[$i]);
$opd_investigations['id'][] = $result->id;
$opd_investigations['name'][] = $result->name;
$opd_investigations['type'][] = $result->type;
$opd_investigations['slug'][] = $result->slug;
$opd_investigations['value'][] = $investigation_results[$i] ?? "";
$opd_investigations['comment'][] = $investigation_comments[$i] ?? "";
} else {
$result = \Streamline\Models\Investigation::withTrashed()->find($investigation_ids[$i]);
$ward_investigations['id'][] = $result->id;
$ward_investigations['name'][] = $result->name;
$ward_investigations['type'][] = $result->type;
$ward_investigations['slug'][] = $result->slug;
$ward_investigations['value'][] = $investigation_results[$i] ?? "";
$ward_investigations['comment'][] = $investigation_comments[$i] ?? "";
}
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
$investigation = \Streamline\Models\Investigation::withTrashed()->find($investigation_ids[$i]);
if (isset($investigation_per_valid[$i]) && $investigation_per_valid[$i] == 1) {
// this investigation is authenticated
if (isset($inpatient_status[$i]) && $inpatient_status[$i] == 0) {
$opd_investigations['id'][] = $investigation->id;
$opd_investigations['name'][] = $investigation->name;
$opd_investigations['type'][] = $investigation->type;
$opd_investigations['slug'][] = $investigation->slug;
$opd_investigations['value'][] = $investigation_results[$i] ?? "";
$opd_investigations['comment'][] = $investigation_comments[$i] ?? "";
} else {
$ward_investigations['id'][] = $investigation->id;
$ward_investigations['name'][] = $investigation->name;
$ward_investigations['type'][] = $investigation->type;
$ward_investigations['slug'][] = $investigation->slug;
$ward_investigations['value'][] = $investigation_results[$i] ?? "";
$ward_investigations['comment'][] = $investigation_comments[$i] ?? "";
}
} else {
if (isset($investigation_per_valid[$i]) && $inpatient_status[$i] == 0) {
$opd_investigations['id'][] = $investigation->id;
$opd_investigations['name'][] = $investigation->name;
$opd_investigations['type'][] = $investigation->type;
$opd_investigations['slug'][] = $investigation->slug;
$opd_investigations['value'][] = "Pending";
$opd_investigations['comment'][] = "Pending";
} else {
$ward_investigations['id'][] = $investigation->id;
$ward_investigations['name'][] = $investigation->name;
$ward_investigations['type'][] = $investigation->type;
$ward_investigations['slug'][] = $investigation->slug;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
}
}
}
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
if (isset($inpatient_status[$i]) && $inpatient_status[$i] == 0) {
$result = \Streamline\Models\Investigation::withTrashed()->find($investigation_ids[$i]);
$opd_investigations['id'][] = $result->id;
$opd_investigations['name'][] = $result->name;
$opd_investigations['type'][] = $result->type;
$opd_investigations['slug'][] = $result->slug;
$opd_investigations['value'][] = "Pending";
$opd_investigations['comment'][] = "Pending";
} else {
$result = \Streamline\Models\Investigation::withTrashed()->find($investigation_ids[$i]);
$ward_investigations['id'][] = $result->id;
$ward_investigations['name'][] = $result->name;
$ward_investigations['type'][] = $result->type;
$ward_investigations['slug'][] = $result->slug;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
}
}
}
?>
@if(count($ward_investigations) > 0)
@for($i = 0; $i < count($ward_investigations['name']); $i++)
@if(in_array($i, $ward_investigations_position))
<tr>
<td colspan="3">
<h5><code>{{ $ward_investigations_date[array_search($i, $ward_investigations_position)] }}</code></h5>
</td>
</tr>
@endif
<tr>
<td>{{ $ward_investigations['name'][$i] }}</td>
<input type="hidden" name="ward_investigation_ids[]" value="{{ $ward_investigations['id'][$i] }}">
<td>
@if($ward_investigations['type'][$i] == 1 && $ward_investigations['value'][$i] != "Pending")
<a class="btn btn-sm btn-link text-blue" onclick="showComplexLabResults({{ $ward_investigations['value'][$i] }}, {{ $inpatient_info->patient_id }})">{{ __('inpatient.view_results') }}</a>
@else
{{ $ward_investigations['value'][$i] }}
@endif
</td>
<td>{{ $ward_investigations['comment'][$i] }}</td>
</tr>
@endfor
@else
<tr>
<td colspan="3">{{ __('inpatient.no_ward_invs') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="billRecalculationMessage" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<h3><span style="color: blue; font-weight:bolder">Note:</span> Please note that the bill is going to be re-calculated using the current price list that the patient is attached to. <b>This process is irreversible</b></h3>
</div>
</div>
</div>
<div class="modal-footer">
<a id="continueRecalculation" class="btn btn-success">{{ __('inpatient.continue') }}</a>
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('layout.close') }}</button>
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
// check if print is required
let print_bill = <?php echo $print_bill; ?>;
if (print_bill == 1) {
let win = window.open('in_patient_bill_print/<?php echo $patient_id; ?>/<?php echo $episode_id; ?>/<?php echo $price_list_set_serial; ?>', '_blank');
if (win) {
win.focus();
} else {
alert("<?php echo __('inpatient.allow_pop_ups');?>")
}
}
});
function update_bed_category(category_id, inpatient_id) {
let data = "bed_category=" + category_id + "&inpatient_id=" + inpatient_id;
$.ajax({
type: "POST",
url: "/submit_bed_category",
data: data,
cache: false,
success: function (result) {
if (result === "success") {
alert("<?php echo __('inpatient.bed_category_saved');?>");
location.reload();
} else {
alert("<?php echo __('inpatient.error_occurred');?>");
}
}
});
}
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
$(".investigation_amount").on("change", function (e) {
let investigation_amount_total = 0;
$(".investigation_amount").each(function () {
investigation_amount_total += parseInt($(this).val());
});
$("#investigation_cost").val(investigation_amount_total);
$("#display_investigation_cost").val(numberWithCommas(investigation_amount_total) + " Ugx");
recalculate_totals();
});
$(".investigation_insurance_amount").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = $('#investigation_summed_amount_' + id).val();
let amount = $(this).val();
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#investigation_amount_' + id).val(summed);
$(".investigation_amount").each(function () {
amount_total += parseInt($(this).val());
});
$("#investigation_cost").val(amount_total);
$("#display_investigation_cost").val(numberWithCommas(amount_total) + " Ugx");
$(".investigation_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_investigation_cost").val(insurance_amount_total);
$("#display_insurance_investigation_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".ward_treatment_insurance").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#drug_summed_amount_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#ward_drug_quantity_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#drug_unit_price_' + id).val(summed);
$('#drug_subtotal_' + id).val(summed * quantity);
$(".ward_drug_amounts").each(function () {
amount_total += parseInt($(this).val());
});
$("#treatment_cost").val(amount_total);
$("#display_treatment_cost").val(numberWithCommas(amount_total) + " Ugx");
$('#drug_insurance_amount_' + id).val(amount * quantity);
$(".ward_drug_chi_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_treatment_cost").val(insurance_amount_total);
$("#display_insurance_treatment_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".opd_drugs_insurance_unit_amount").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#opd_treatment_summed_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#opd_treatment_quantity_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#opd_treatment_amount_' + id).val(summed);
$('#opd_treatment_subtotal_' + id).val(summed * quantity);
$(".opd_treatment_subtotal").each(function () {
amount_total += parseInt($(this).val());
});
$("#opd_treatment").val(amount_total);
$("#display_opd_treatment").val(numberWithCommas(amount_total) + " Ugx");
$('#opd_treatment_insurance_amount_' + id).val(amount * quantity);
$(".opd_treatment_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_opd_treatment").val(insurance_amount_total);
$("#display_insurance_opd_treatment").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".sundry_unit_insurance_amount").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#sundry_amount_summed_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#sundry_quantity_given_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#sundries_item_prices_' + id).val(summed);
$('#sundry_subtotal_' + id).val(summed * quantity);
$(".sundry_subtotal").each(function () {
amount_total += parseInt($(this).val());
});
$("#sundries_cost").val(amount_total);
$("#display_sundries_cost").val(numberWithCommas(amount_total) + " Ugx");
$('#sundry_insurance_amount_' + id).val(amount * quantity);
$(".sundry_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_sundries_cost").val(insurance_amount_total);
$("#display_insurance_sundries_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".opd_sundry_insurance_unit").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#opd_sundry_summed_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#opd_sundry_quantity_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#opd_sundry_amount_' + id).val(summed);
$('#opd_sundry_subtotal_' + id).val(summed * quantity);
$(".opd_sundry_subtotal").each(function () {
amount_total += parseInt($(this).val());
});
$("#opd_sundries_cost").val(amount_total);
$("#display_opd_sundries_cost").val(numberWithCommas(amount_total) + " Ugx");
$('#opd_sundry_insurance_amount_' + id).val(amount * quantity);
$(".opd_sundry_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_opd_sundries_cost").val(insurance_amount_total);
$("#display_insurance_opd_sundries_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".service_insurance_unit").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#service_summed_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#service_quantity_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#services_item_prices_' + id).val(summed);
$('#service_total_cost_' + id).val(summed * quantity);
$(".service_total_cost").each(function () {
amount_total += parseInt($(this).val());
});
$("#grand_services_cost").val(amount_total);
$("#display_services_cost").val(numberWithCommas(amount_total) + " Ugx");
$('#service_insurance_amount_' + id).val(amount * quantity);
$(".service_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_services_cost").val(insurance_amount_total);
$("#display_insurance_services_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".opd_service_insurance_unit").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#opd_services_summed_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#opd_service_quantity_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#opd_service_unit_cost_' + id).val(summed);
$('#opd_service_amount_' + id).val(summed * quantity);
$(".opd_service_amount").each(function () {
amount_total += parseInt($(this).val());
});
$("#opd_services_cost").val(amount_total);
$("#display_opd_services_cost").val(numberWithCommas(amount_total) + " Ugx");
$('#opd_service_insurance_amount_' + id).val(amount * quantity);
$(".opd_service_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_opd_services_cost").val(insurance_amount_total);
$("#display_insurance_opd_services_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".ipd_procedure_insurance_amount").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#ipd_procedure_summed_' + id).val());
let staff_fee = parseInt($('#ipd_procedure_staff_fee_' + id).val());
let amount = parseInt($(this).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#ipd_procedure_amount_' + id).val(summed);
$('#procedures_item_prices_' + id).val(summed + staff_fee);
$(".procedures_item_prices").each(function () {
amount_total += parseInt($(this).val());
});
$("#procedures_cost").val(amount_total);
$("#display_procedures_cost").val(numberWithCommas(amount_total) + " Ugx");
$(".ipd_procedure_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_procedures_cost").val(insurance_amount_total);
$("#display_insurance_procedures_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".opd_procedure_insurance_amount").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = $('#opd_procedure_summed_' + id).val();
let amount = $(this).val();
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#opd_procedure_amount_' + id).val(summed);
$(".opd_procedure_amount").each(function () {
amount_total += parseInt($(this).val());
});
$("#opd_procedures_cost").val(amount_total);
$("#display_opd_procedures_cost").val(numberWithCommas(amount_total) + " Ugx");
$(".opd_procedure_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_opd_procedures_cost").val(insurance_amount_total);
$("#display_insurance_opd_procedures_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
$(".tta_insurance_unit").on("change", function (e) {
let amount_total = 0;
let insurance_amount_total = 0;
let id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let summed = parseInt($('#tta_summed_' + id).val());
let amount = $(this).val();
let quantity = parseInt($('#tta_quantity_' + id).val());
// subtract amount from the sum and if negative then reject
summed -= amount;
// check if limits are good and continue to add sum amount to patient to pay
if(summed < 0) {
alert("Amount limits have been exceeded");
window.location.reload();
}
$('#tta_unit_cost_' + id).val(summed);
$('#tta_amount_' + id).val(summed * quantity);
$(".tta_amount").each(function () {
amount_total += parseInt($(this).val());
});
$("#tta_cost").val(amount_total);
$("#display_tta_cost").val(numberWithCommas(amount_total) + " Ugx");
$('#tta_insurance_amount_' + id).val(amount * quantity);
$(".tta_insurance_amount").each(function () {
insurance_amount_total += parseInt($(this).val());
});
$("#insurance_tta_cost").val(insurance_amount_total);
$("#display_insurance_tta_cost").val(numberWithCommas(insurance_amount_total) + " Ugx");
recalculate_totals();
});
function recalculate_totals() {
let admission_grand_total = parseInt($("#ward_bed_admission_cost").val()) || 0;
let investigation_grand_total = parseInt($("#investigation_cost").val()) || 0;
let treatment_grand_total = (parseInt($("#treatment_cost").val()) || 0) + (parseInt($("#opd_treatment").val()) || 0);
let sundries_grand_total = (parseInt($("#sundries_cost").val()) || 0) + (parseInt($("#opd_sundries_cost").val()) || 0);
let extras_grand_total = parseInt($("#extras_cost").val()) || 0;
let services_grand_total = (parseInt($("#grand_services_cost").val()) || 0) + (parseInt($("#opd_services_cost").val()) || 0);
let procedures_grand_total = (parseInt($("#procedures_cost").val()) || 0) + (parseInt($("#opd_procedures_cost").val()) || 0);
let tta_grand_total = parseInt($("#tta_cost").val()) || 0;
let patient_to_pay = services_grand_total + admission_grand_total + investigation_grand_total + treatment_grand_total + sundries_grand_total + procedures_grand_total +
tta_grand_total + extras_grand_total;
$("#display_amount_owed").val(numberWithCommas(patient_to_pay) + " Ugx");
$("#original_amount_owed").val(patient_to_pay);
let amount_owed = patient_to_pay - (parseInt($('#deposits_made').val()) || 0) - (parseInt($('#invoices_amount').val()) || 0) - (parseInt($('#ward_discount_total').val()) || 0)
- (parseInt($('#debt_plan_total').val()) || 0) - (parseInt($('#dependant_account').val()) || 0);
$("#amount_owed").val(amount_owed);
let admission_insurance_total = parseInt($("#insurance_admission_cost").val()) || 0;
let investigation_insurance_total = parseInt($("#insurance_investigation_cost").val()) || 0;
let treatment_insurance_total = (parseInt($("#insurance_treatment_cost").val()) || 0) + (parseInt($("#insurance_opd_treatment").val()) || 0);
let sundries_insurance_total = (parseInt($("#insurance_sundries_cost").val()) || 0) + (parseInt($("#insurance_opd_sundries_cost").val()) || 0);
let services_insurance_total = (parseInt($("#insurance_services_cost").val()) || 0) + (parseInt($("#insurance_opd_services_cost").val()) || 0);
let procedures_insurance_total = (parseInt($("#insurance_procedures_cost").val()) || 0) + (parseInt($("#insurance_opd_procedures_cost").val()) || 0);
let tta_insurance_total = parseInt($("#insurance_tta_cost").val()) || 0;
let insurance_to_pay = services_insurance_total + admission_insurance_total + investigation_insurance_total + treatment_insurance_total +
sundries_insurance_total + procedures_insurance_total + tta_insurance_total;
$("#display_insurance_amount_owed").val(numberWithCommas(insurance_to_pay) + " Ugx");
$("#original_insurance_amount_owed").val(insurance_to_pay);
}
$("#recalculateBillBtn").click(function(e){
e.preventDefault();
$("#billRecalculationMessage").modal('show');
});
$("#continueRecalculation").click(function(e){
$('#recalculateId').val('re_calculate_bill');
$('#inpatient_bill_form').attr('action', "/re_calculate_inpatient_bill").submit();
});
</script>
@endpush