Files

445 lines
23 KiB
PHP
Executable File

@extends('layouts.main')
@push('styles')
<link href="{{ asset('elite/bower_components/select2/select2.min.css') }}" rel="stylesheet"/>
<link href="{{ asset('elite/bower_components/switchery/dist/switchery.min.css') }}" rel="stylesheet"/>
@endpush
@section('content')
<div class="row bg-title">
<div class="col-lg-4 col-md-5 col-sm-5 col-xs-12">
<h4 class="page-title">{{ __('investigations.order_investigations') }}</h4>
</div>
<div class="col-lg-8 col-sm-7 col-md-7 col-xs-12">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}">{{ __('investigations.dashboard') }}</a></li>
<li><a href="/investigations/index">{{ __('investigations.investigations') }}</a></li>
<li class="active">{{ __('investigations.order') }}</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-sm-12">
@include('patients::allergies.header')
<br>
</div>
</div>
<div class="white-box">
<!--Flash messages at the top -->
@include('flash::message')
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
@if (count($chronic_array) > 0)
<table class='table color-bordered-table success-bordered-table'>
<thead><tr><th colspan="2">Patient's Chronic Investigations</th></tr></thead>
<tbody>
@foreach ($chronic_array as $chronic_inv)
@if(isset($investigations[$chronic_inv->investigation_id]))
<tr>
<td>{{ $investigations[$chronic_inv->investigation_id] }}</td>
<td><button type="button" class="btn btn-sm btn-rounded btn-outline-primary" onclick="add_inv_to_order({{ $chronic_inv->investigation_id }})">Add to current order</button></td>
</tr>
@endif
@endforeach
</tbody>
</table>
<hr>
@endif
{{ Form::open(['route' => 'investigations.submit_ordered_investigations']) }}
@php $patient_insurance_status = patient_insurance_status($patient_id); @endphp
{{ Form::hidden('patient_id', $patient_id, ['id' => 'patient_id']) }}
{{ Form::hidden('episode_id', $episode_id, ['id' => 'episode_id']) }}
{{ Form::hidden('patient_insurance_status', $patient_insurance_status, ['id' => 'patient_insurance_status'])}}
<div id='payments_items'>
<table class='table color-bordered-table success-bordered-table'>
<thead>
<tr>
<th>
<div class='row'>
<div class='col-3'>{{ __('investigations.investigation') }}</div>
<div class='col-2'>{{ __('investigations.lab_comments') }}</div>
<div class='col-3'>{{ __('investigations.order_comments') }}</div>
<div class='col-2' @if(view_investigation_price_on_order()==0) style='display: none' @endif>Cost</div>
<div class='col-1'>{{ __('investigations.urgent') }}</div>
<div class='col-1'></div>
</div>
</th>
</tr>
</thead>
@php
$counter = 0;
$total_selling_price = 0;
@endphp
<tbody class='input_fields_wrap'>
@if(count($ordered_investigations) > 0)
@foreach($ordered_investigations as $ordered_investigation)
{{ Form::hidden('order_id[]', $ordered_investigation->id) }}
@php
$investigations_ids = explode(",", $ordered_investigation->investigation_id);
$urgent_ids_array = explode(",", $ordered_investigation->urgent_ids);
$order_comments_array = explode(",", $ordered_investigation->order_comments);
$eye_array = explode(",", $ordered_investigation->eye);
@endphp
@for($i = 0; $i < count($investigations_ids); $i++)
<tr>
<td>
<div class='row'>
<div class='col-3'>
<div class='form-group'>
<div class='controls'>
{{ Form::select('investigations_id[]', $investigations_to_order, $investigations_ids[$i], ['class' => 'form-control compulsory required investigations_id_class', 'id' => 'investigations_id_' . $counter, 'required']) }}
</div>
<div id='chi_coverage_div_{{ $counter }}'>
@if (is_chi_enabled())
@if (is_patient_item_covered($patient_id, $investigations_ids[$i], 3))
&nbsp;&nbsp;<br><span style="color: darkgreen"><b>Covered by CHI</b></span>
@else
&nbsp;&nbsp;<br><span style="color: darkorange"><b>Not covered by CHI</b></span>
@endif
@endif
</div>
</div>
<div @if(!is_eye_module_enabled() || !is_patient_in_eye_clinic($episode_id)) style='display: none' @endif>
<hr>
<label><b>Eye</b></label>
{{ Form::select('eye[]', [2 => 'Both', 0 => 'Left', 1 => 'Right'], $eye_array[$i] ?? 2, ['class' => 'form-control compulsory', 'required', 'onchange' => 'eye_select(this.value, ' . $counter . ')']) }}
</div>
</div>
<div class='col-2'>
<div style='padding: 3px 3px 3px 4px; color: #C85F6A;' class='well margin-none span12' id='lab_comments_{{ $counter }}'>{{ get_name($investigations_ids[$i], 'id', 'comments', 'investigations') }}</div>
</div>
<div class='col-3'>
<div class='form-group'>
<div class='controls'>
<textarea class='form-control order_comments' name='order_comments[]' id='order_comments_{{ $counter }}' rows='3'>{{ $order_comments_array[$i] }}</textarea>
</div>
</div>
</div>
@php
if($patient_insurance_status == 1) {
$selling_price = get_item_insurance_co_payment($patient_id, $investigations_ids[$i], 3, false, 0);
} else {
// check if the patient category is attached to a price list
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
if ($price_list_id) {
$selling_price = get_price_list_category_price($price_list_id, 2, $investigations_ids[$i]);
} else {
$selling_price = get_name($investigations_ids[$i], 'id', 'non_insured_price', 'investigations');
}
}
$selling_price = $selling_price * ((isset($eye_array[$i]) && $eye_array[$i] == 2) ? 2 : 1);
$total_selling_price += $selling_price;
@endphp
<div class='col-2' @if(view_investigation_price_on_order()==0) style='display: none' @endif>
<div class='form-group'>
<div class='controls'>
<input type='number' name='investigation_cost[]' id='investigation_cost_{{ $counter }}' class='form-control investigation_cost compulsory' readonly value='{{ $selling_price }}'/>
</div>
</div>
</div>
<div class='col-1'>
<input type='checkbox' name='urgent_id[]' id='urgent_id_{{ $counter }}' class='js-switch' data-color='#f96262' data-size='small' value="{{ $investigations_ids[$i] }}" @if(in_array($investigations_ids[$i], $urgent_ids_array)) checked @endif/>
</div>
<div class='col-1'>
<div class='form-group' style='margin-top: 10px;'>
@if($counter == 0)
<button class='btn btn-sm btn-rounded btn-success add_item' style='color: white; margin-left: 25px;'><i class='fa fa-plus'></i></button>
@else
<button class='remove_field btn btn-sm btn-rounded btn-danger' style='color: white; margin-left: 25px;'><i class='fa fa-trash'></i></button>
@endif
</div>
</div>
</div>
</td>
</tr>
@php $counter++; @endphp
@endfor
@endforeach
@else
<tr>
<td>
<div class='row'>
<div class='col-3'>
<div class='form-group'>
<div class='controls'>
<select name='investigations_id[]' id='investigations_id_{{ $counter }}' class='form-control compulsory required investigations_id_class'>@php echo $investigations_select_code; @endphp</select>
</div>
<div id='chi_coverage_div_{{ $counter }}'></div>
</div>
<div @if(!is_eye_module_enabled() || !is_patient_in_eye_clinic($episode_id)) style='display: none' @endif>
<hr>
<label><b>Eye</b></label>
<select name='eye[]' class='form-control compulsory' onchange="eye_select(this.value, {{ $counter }})">
<option selected value='0'>Left</option>
<option value='1'>Right</option>
<option value='2'>Both</option>
</select>
</div>
</div>
<div class='col-2'>
<div style='padding: 3px 3px 3px 4px; color: #C85F6A;' class='well margin-none span12' id='lab_comments_{{ $counter }}' ></div>
</div>
<div class='col-3'>
<div class='form-group'>
<div class='controls'>
<textarea class='form-control order_comments' name='order_comments[]' id='order_comments_{{ $counter }}' rows='3'></textarea>
</div>
</div>
</div>
<div class='col-2' @if(view_investigation_price_on_order()==0) style='display: none' @endif>
<div class='form-group'>
<div class='controls'>
<input type='number' name='investigation_cost[]' id='investigation_cost_{{ $counter }}' class='form-control investigation_cost compulsory' readonly/>
</div>
</div>
</div>
<div class='col-1'>
<input type='checkbox' name='urgent_id[]' id='urgent_id_{{ $counter }}' class='js-switch' data-color='#f96262' data-size='small'/>
</div>
<div class='col-1'>
<div class='form-group' style='margin-top: 10px;'>
<button class='btn btn-sm btn-rounded btn-success add_item' style='color: white; margin-left: 25px;'><i class='fa fa-plus'></i></button>
</div>
</div>
</div>
</td>
</tr>
@endif
</tbody>
@if( Auth::user()->can('add-row-on-prescription'))
<tr>
<td>
<div class='row'>
<div class='col-6'>
</div>
<div class='col-1 prompts_div' id='prompts_div_{{ $counter }}'></div>
<div class='col-1'>
</div>
<div class='col-1 first_dose_quantity_div' style="display: none">
</div>
<div class='col-1' @if(view_prescription_price_on_order()==0) style='display: none' @endif>
</div>
<div class='col-1'>
</div>
<div class='col-1'>
<div class='form-group' style='margin-top: 10px;'>
<button class='btn btn-sm btn-rounded btn-success add_item pull-left' style='color: white; margin-left: 25px;'><span>Add row</span></button>
</div>
</div>
</div>
</td>
</tr>
@endif
</table>
</div>
<h3 @if(view_procedure_price_on_order()==0) style='display: none' @endif>Total: <span id="itemGrandTotal"> {{ ugandan_shillings($total_selling_price) }}</span></h3>
<div class="pull-right">
{{ Form::button(__('investigations.submit_requests'),['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10', 'id'=>'submit_button','name'=>'submit_button','value'=>'submit_button']) }}
{{ Form::button(__('investigations.print_requests'),['type'=>'submit','class'=>'btn btn-primary waves-effect waves-light m-r-10', 'id'=>'print_request','name'=>'submit_button','value'=>'print_request']) }}
</div>
<br
{{ Form::close() }}
</div>
@endsection
@push('scripts')
<script src="{{ asset('elite/bower_components/select2/select2.min.js') }}"></script>
<script src="{{ asset('elite/bower_components/switchery/dist/switchery.min.js') }}"></script>
<script type="text/javascript">
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
$('.js-switch').each(function () {
new Switchery($(this)[0], $(this).data());
});
var max_rows = 500;
var wrapper = $(".input_fields_wrap");
var add_button = $(".add_item");
var show_price_setting = <?php echo view_investigation_price_on_order(); ?>;
var is_eye_module_enabled = <?php echo (!is_eye_module_enabled() || !is_patient_in_eye_clinic($episode_id)) ? 1 : 0; ?>;
var x = <?php echo $counter + 1; ?> // initial row count
add_button.click(function (e) { // on add input button click
e.preventDefault();
add_invs_row();
});
function add_invs_row() {
if (x < max_rows) {
$(wrapper).append("\
<tr>\
<td>\
<div class='row'>\
<div class='col-3'>\
<div class='form-group'>\
<div class='controls'>\
<select name='investigations_id[]' id='investigations_id_" + x + "' class='form-control compulsory required investigations_id_class' required>@php echo $investigations_select_code; @endphp</select>\
</div>\
<div id='chi_coverage_div_" + x + "'></div>\
</div>\
<div "+(is_eye_module_enabled==1?'style="display:none"':'')+">\
<hr><label><b>Eye</b></label>\
<select name='eye[]' class='form-control compulsory' onchange='eye_select(this.value, " + x + ")'>\
<option selected value='0'>Left</option>\
<option value='1'>Right</option>\
<option value='2'>Both</option>\
</select></div>\
</div>\
<div class='col-2'>\
<div style='padding: 3px 3px 3px 4px; color: #C85F6A;' class='well margin-none span12' id='lab_comments_" + x + "' ></div>\
</div>\
<div class='col-3'>\
<div class='form-group'>\
<div class='controls'>\
<textarea class='form-control order_comments' name='order_comments[]' id='order_comments_" + x + "' rows='3'></textarea>\
</div>\
</div>\
</div>\
<div class='col-2'"+(show_price_setting==0?'style="display:none"':'')+">\
<div class='form-group'>\
<div class='controls'>\
<input type='number' name='investigation_cost[]' id='investigation_cost_" + x + "' class='form-control investigation_cost compulsory' readonly/>\
</div>\
</div>\
</div>\
<div class='col-1'>\
<input type='checkbox' name='urgent_id[]' id='urgent_id_" + x + "' class='js-switch' data-color='#f96262' data-size='small'/>\
</div>\
<div class='col-1'>\
<div class='form-group' style='margin-top: 10px;'>\
<button class='btn btn-sm btn-rounded btn-danger remove_field' style='color: white; margin-left: 25px;'><i class='fa fa-trash'></i></button>\
</div>\
</div>\
</div>\
</td>\
</tr>");
generalSelect2Set('investigations_id_'+x);
new Switchery($('#urgent_id_'+x)[0], $('#urgent_id_'+x).data());
x++;
}
}
$(wrapper).on("click", ".remove_field", function (e) {
e.preventDefault();
$(this).parent('div').parent('div').parent('div').parent('td').parent('tr').remove();
});
$(".investigations_id_class").select2({
width: "100%"
});
function eye_select(value, id) {
// for eye both
if(value == 2) {
let item = $("#investigations_id_" + id).val();
let patient_id = $('#patient_id').val();
$.ajax({
url: '/investigations/get_investigation_details',
data: {'investigation_id':item, 'patient_id':patient_id},
success: function(response){
let arr = JSON.parse(response);
$('#investigation_cost_' + id).val(arr["selling_price"] * 2);
calculateTotal();
}
});
}
}
$(".input_fields_wrap").on('change', ".investigations_id_class", function () {
var id = /\d+(?=\D*$)/.exec($(this).attr('id'));
var item = $("#investigations_id_" + id).val();
var patient_id = $('#patient_id').val();
let patient_insurance_status = $('#patient_insurance_status').val();
$.ajax({
url: '/investigations/get_investigation_details',
data: {'investigation_id':item, 'patient_id':patient_id, 'patient_insurance_status': patient_insurance_status},
success: function(response){
let arr = JSON.parse(response);
$('#order_comments_' + id).text(arr["comments"]);
$('#investigation_cost_' + id).val(arr["selling_price"]);
$('#urgent_id_' + id).val(item);
if (arr["covered_by_chi"] !== "") {
$("#chi_coverage_div_" + id).html(arr["covered_by_chi"]).show();
} else {
$("#chi_coverage_div_" + id).hide();
}
calculateTotal();
}
});
});
function calculateTotal() {
//loop through the prices
let auto_price_grand_total = 0;
$(".investigation_cost").each(function(){
auto_price_grand_total += parseInt($(this).val());
});
// recalculate the grand total
$("#itemGrandTotal").html(numberWithCommas(auto_price_grand_total) + " Ugx");
}
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function generalSelect2Set(id) {
$('#'+id).select2({
width: "100%"
});
}
function add_inv_to_order(inv_id) {
add_invs_row();
$('#investigations_id_' + (x - 1)).select2().val(inv_id).trigger('change');
}
</script>
@endpush