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

768 lines
39 KiB
PHP
Executable File

@php use Streamline\Enums\Roles; @endphp
@extends('layouts.main')
@push('styles')
<link href="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.css') }}"
rel="stylesheet" type="text/css"/>
<link href="{{ asset('elite/bower_components/select2/select2.min.css') }}" rel="stylesheet"/>
@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">{{ __('patients.edit_patient') }}</h4>
</div>
<div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}">{{ __('patients.dashboard') }}</a></li>
<li><a href="{{ route('patients.index') }}">{{ __('patients.patients') }}</a></li>
<li class="active">{{ __('patients.edit_patient') }}</li>
</ol>
</div>
<!-- /.col-lg-12 -->
</div>
<div class="row">
<div class="col-md-12">
@include('flash::message')
@foreach ($errors->all() as $error)
<div>
<font color="red">{{ $error }}</font>
</div>
@endforeach
<div class="white-box" id="white-box">
{{ Form::model($patient, ['method' => 'PUT', 'route' => ['patients.update',$patient], 'data-toggle' => 'validator']) }}
<div class="row">
<div class="col-sm-4">
<div class="form-group">
{{ Form::label('first_name',__('patients.first_name')) }}
{{ Form::text('first_name',$patient->first_name,['class' => 'form-control compulsory', 'required', 'data-error'=>'','placeholder'=>'Christian name eg Fred']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('last_name',__('patients.last_name')) }}
{{ Form::text('last_name',$patient->last_name,['class' => 'form-control compulsory', 'required','placeholder'=>'Surname eg Asiimwe']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('gender',__('patients.gender')) }}
<br>
{{ Form::radio('gender', 1, false, ["required"]) }} {{ __('patients.male') }} &nbsp;&nbsp;
{{ Form::radio('gender', 2, false, ["required"]) }} {{ __('patients.female') }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('national_id',__('patients.national_id')) }}
{{ Form::text('national_id', strtoupper($patient->national_id),['class' => 'form-control','maxlength'=>15]) }}
</div>
<div class="form-group">
{{ Form::label('date_of_birth',__('patients.date_of_birth')) }}
<div class="input-group">
{{ Form::text('date_of_birth',$dob,['class' => 'form-control compulsory', 'required','readonly','id'=>'date_of_birth']) }}
<span class="input-group-addon"><i class="icon-calender"></i></span>
</div>
<div class="help-block with-errors"></div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
{{ Form::label('age',__('patients.years')) }}
{{ Form::number('age_in_years',\Carbon\Carbon::now()->diffInYears($patient->date_of_birth),['class' => 'form-control compulsory','id'=>'age_in_years','min'=>'0', 'max'=>'120']) }}
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
@php
$months = \Carbon\Carbon::now()->diffInMonths($patient->date_of_birth) - (\Carbon\Carbon::now()->diffInYears($patient->date_of_birth) *12);
@endphp
{{ Form::label('age',__('patients.months')) }}
{{ Form::number('age_in_months',$months,['class' => 'form-control','id'=>'age_in_months','min'=>'0','max'=>'12']) }}
</div>
</div>
</div>
<div class="form-group">
{{ Form::label('marital_status',__('patients.marital_status')) }}
<br>
@foreach($marital_statuses as $key=>$value)
{{ Form::radio('marital_status', $key,false,[]) }} {{ $value }} &nbsp;&nbsp;
@endforeach
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('religion',__('patients.religion')) }}
{{ Form::select('religion',$religions,$patient->religion_id,['class' => 'form-control']) }}
<div class="help-block with-errors"></div>
</div>
@if( Auth::user()->hasRole(Roles::SUPER_ADMIN->value))
<div class="form-group">
{{ Form::label('is_test_patient',__('patients.is_test_patient')) }}
<br>
{{ Form::radio('is_test_patient', 1, $patient->is_test_patient == 1) }} Yes &nbsp;&nbsp;
{{ Form::radio('is_test_patient', 0, $patient->is_test_patient == 0) }} No &nbsp;&nbsp;
<div class="help-block with-errors"></div>
</div>
@endif
</div>
<div class="col-md-4">
<div class="form-group">
{{ Form::label('occupation',__('patients.occupation')) }}
{{ Form::select('occupation',$occupations, $patient->occupation_id,['class' => 'form-control']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('next_of_kin',__('patients.next_of_kin')) }}
{{ Form::text('next_of_kin',$patient->next_of_kin,['class' => 'form-control compulsory','required', 'onchange' => "show('kin_div')"]) }}
</div>
<div class="form-group" id="kin_div">
{{ Form::label('next_of_kin_relationship',__('patients.next_of_kin_relationship')) }}
{{ Form::select('next_of_kin_relationship',$relationships,$patient->next_of_kin_relationship,['class' => 'form-control compulsory']) }}
<br>
{{ Form::label('next_of_kin_phone',__('patients.next_of_kin_phone')) }}
{{ Form::text('next_of_kin_phone',$patient->phone_of_next_of_kin,['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('phone',__('patients.phone')) }}
{{ Form::text('phone',$patient->phone,['class' => 'form-control compulsory']) }}
</div>
<div class="form-group">
{{ Form::label('alternative_phone', 'Alternative Phone Number') }}
{{ Form::text('alternative_phone',$patient->alternative_phone,['class' => 'form-control','id' => 'alternative_phone']) }}
</div>
<div class="form-group">
{{ Form::label('phone_owner',__('patients.phone_owner')) }}
<br>
{{ Form::radio('phone_owner','self',($patient->phone_owner == "Self" || $patient->phone_owner == "self") ? 1 : 0,['id'=>'owned']) }} {{ __('patients.self') }}
&nbsp;&nbsp;
{{ Form::radio('phone_owner','other',$patient->phone_owner != "Self" ? 1 : 0,['id'=>'non_owned']) }} {{ __('patients.other') }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group owners_name">
{{ Form::label("owner_name",__('patients.phone_owner_name')) }}
{{ Form::text('owner_name',$patient->phone_owner,['id'=>'owner_name','class' => 'form-control compulsory']) }}
</div>
<!-- <div class="form-group">
{{ Form::label('lc_one',__('patients.lc_one')) }}
{{ Form::text('lc_one',$patient->lc_one,['class' => 'form-control', 'data-error'=>'LC 1 chairman\'s name']) }}
<div class="help-block with-errors"></div>
</div> -->
<div class="form-group">
{{ Form::label('patient_category',__('patients.patient_category'))}}
{{ Form::select('patient_category',$patient_categories,$patient->category_id,['class' => 'form-control compulsory', 'required', 'data-error'=>'']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('company',__('patients.company_slash_employer'))}}
{{ Form::select('company', $companies ,$patient->company_id,['class' => 'form-control', 'data-error'=>'', 'id' => 'company']) }}
<div class="help-block with-errors"></div>
<a href="#modal_company" data-toggle="modal" id="modal_company_link"><font
size="1">{{ __('patients.add_new_company') }} </font></a>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
{{ Form::label('language',__('patients.preferred_language')) }}
{{ Form::select('language',['' => '- select -','eng'=>'English','vern'=>'Vernacular'],$patient->language,['class' => 'form-control compulsory', 'required', 'data-error'=>'Select the language']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('citizenship',__('patients.citizenship')) }}
{{ Form::select('citizenship',['' => '- Select -','1'=>'Ugandan','0'=>'Non Ugandan'],$patient->citizenship,['class' => 'form-control compulsory', 'required', 'data-error'=>'Select the language','id' => 'citizenship']) }}
<div class="help-block with-errors"></div>
</div>
<div id="not_ugandan_regions" @if($patient->citizenship == 1) style="display: none" @endif>
<div class="form-group">
{{ Form::label('country_id',__('patients.country_of_origin')) }}
{{ Form::select('country_id', $countries, $patient->country_id, ['class' => 'form-control', 'data-error'=>'Select the country']) }}
<div class="help-block with-errors"></div>
</div>
</div>
<div id="ugandan_regions" @if($patient->citizenship == 0) style="display: none" @endif>
<div class="form-group">
{{ Form::label('residence','Residence') }}
<select class="form-control" name="residence" id="residence" required>
@php
$residence_array = explode(",", $patient->address_details);
$district_id = $residence_array[4] ?? 0;
$county_id = $residence_array[3] ?? 0;
$subcounty_id = $residence_array[2] ?? 0;
$parish_id = $residence_array[1] ?? 0;
$village_id = $residence_array[0] ?? 0;
@endphp
<option value="{{ $patient->address_details ?? '0,0,0,0,0' }}" selected>{{ __('patients.village') }}
: {{ get_name($village_id, "id", "name", "villages") }} {{ __('patients.district') }}
: {{ get_name($district_id, "id", "name", "districts") }}</option>
</select>
<div class="help-block with-errors"></div>
<a href="#modal_village_residence" data-toggle="modal"
id="modal_village_residence_link"><font
size="1">{{ __('patients.add_new_residence') }} </font></a>
</div>
</div>
@if (!empty($patient_registration_fields))
@php $registration_fields = !empty($patient->registration_fields)? json_decode($patient->registration_fields, true):[]; @endphp
@foreach ($patient_registration_fields as $patient_registration_field)
@php
$field_value = 'reg_field_'.$patient_registration_field->id;
@endphp
<input type="hidden" name="registration_field_names[]"
id="reg_field_{{$patient_registration_field->id}}"
value="reg_field_{{$patient_registration_field->id}}"/>
@if (!empty($patient_registration_field->options))
<div class="form-group">
{{ Form::label($patient_registration_field->name, $patient_registration_field->name) }}
<select name="registration_field_values[]"
id="{{$patient_registration_field->name}}"
class="col-sm-12 {{ ($patient_registration_field->compulsory == 1)? 'compulsory':'' }} form-control" {{ ($patient_registration_field->compulsory == 1)? 'required':'' }}>
<option value="">--select--</option>
@php
$options = explode(',',$patient_registration_field->options);
for ($i=0; $i < count($options) ; $i++) {
if(!empty($registration_fields[$field_value]) && $options[$i] == $registration_fields[$field_value]) echo '<option selected value="'.$options[$i].'">'.$options[$i].'</option>';
else echo '<option value="'.$options[$i].'">'.$options[$i].'</option>';
}
@endphp
</select>
</div>
@else
<div class="form-group">
{{ Form::label($patient_registration_field->name, $patient_registration_field->name) }}
<input type="text" name="registration_field_values[]"
class="col-sm-12 {{ ($patient_registration_field->compulsory == 1)? 'compulsory':'' }} form-control"
{{ ($patient_registration_field->compulsory == 1)? 'required':'' }} value="{{ !empty($registration_fields[$field_value])? $registration_fields[$field_value]:'' }}">
</div>
@endif
@endforeach
@endif
@if(is_fingerprint_enabled())
<div>
{{ Form::label('fingerprint_template', __('patients.patient_fingerprint')) }}
<div class="fingerprint_box text-center">
<img id="fingerprint_image" height="240" width="220">
</div>
{{ Form::hidden('fingerprint_template', '', ['id' => 'fingerprint_template']) }}
<button type="button" onClick='capture_fingerprint()'
class="btn btn-sm btn-primary">{{ __('patients.capture_fingerprint') }}</button>
<p id="scanner_msg"></p>
</div>
@endif
</div>
<div class="col-md-8">
<hr>
</div>
<div class="col-md-4">
{{ Form::button(__('patients.submit'),['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10', 'id' => 'patients_submit']) }}
{{ Form::button(__('patients.cancel'),['type'=>'reset','class'=>'btn btn-default waves-effect waves-light']) }}
{{ Form::close() }}
@if (!in_array($patient->id, $episodes))
<form action="{{url('patients', [$patient->id])}}" method="POST" style="float: right;">
<input type="hidden" name="_method" value="<?php echo __('patients.delete') ?>">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input href="#modal_reason" data-toggle="modal" id="modal_reason_link" type="button"
class="btn btn-danger" value="<?php echo __('patients.deactivate_patient') ?>"/>
</form>
@endif
</div>
</div>
</div>
</div>
</div>
<!-- Reason for Patient De-activation modal -->
<div class="modal fade" id="modal_reason" tabindex="-1" role="dialog">
<div class="modal-dialog" 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="exampleModalLabel1">{{ __('patients.reason_for_deactivating_patient') }}</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input class="form-control compulsory" id="patient_deactivation_reasons"
name="patient_deactivation_reasons" type="text" cols="44" rows="5"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">{{ __('patients.cancel') }}</button>
<button type="button" class="btn btn-danger"
onclick="submitDeactivationReason()"><?php echo __('patients.deactivate_patient') ?></button>
</div>
</div>
</div>
</div>
<!-- new residence modals (add village + add district) -->
<div class="modal fade" id="modal_village_residence" tabindex="-1" role="dialog">
<div class="modal-dialog" 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="exampleModalLabel1">{{ __('patients.add_new_residence') }}</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>{{ __('patients.district') }}</label>
{{ Form::select('residence_district_name', $districts, '', ['id'=>'residence_district_name','class'=>'form-control compulsory']) }}
<a id="modal_district_residence_link" style="cursor: pointer;"><font
size="1">{{ __('patients.add_new_district') }} </font></a>
</div>
<div class="form-group">
<label>{{ __('patients.village') }}</label>
<input class="form-control compulsory" id="new_residence_village_name"
name="new_residence_village_name" type="text"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">{{ __('patients.cancel') }}</button>
<a class="btn btn-success" onclick="submitResidenceVillage()">{{ __('patients.save') }}</a>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal_district_residence" tabindex="-1" role="dialog" style="padding-top: 50px;">
<div class="modal-dialog modal-dialog-centered" 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="exampleModalLabel1">{{ __('patients.add_new_residence') }}</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>{{ __('patients.district') }}</label>
<input class="form-control compulsory" id="new_residence_district_name"
name="new_residence_district_name" type="text"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">{{ __('patients.cancel') }}</button>
<a class="btn btn-success" onclick="submitResidenceDistrict()">{{ __('patients.save') }}</a>
</div>
</div>
</div>
</div>
<!-- end of residence modals -->
<div class="modal fade" id="modal_company" tabindex="-1" role="dialog">
<div class="modal-dialog" 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="exampleModalLabel1">{{ __('patients.register_company') }}</h4>
</div>
<div class="modal-body">
<div class="form-group">
{{ Form::label('company_name', __('patients.company_name')) }}
{{ Form::text('company_name', '', ['class' => 'form-control compulsory', 'id' => 'company_name']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('company_contact', __('patients.contact')) }}
{{ Form::text('company_contact', '', ['class' => 'form-control compulsory', 'id' => 'company_contact']) }}
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
{{ Form::label('company_identifier', __('patients.identifier')) }}
{{ Form::text('company_identifier', '', ['class' => 'form-control', 'id' => 'company_identifier']) }}
<div class="help-block with-errors"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">{{ __('patients.cancel') }}</button>
<a class="btn btn-success" onclick="submitCompany()">{{ __('patients.save') }}</a>
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<!-- <script src="{{ asset('elite/js/validator.js') }}"></script> -->
<!-- pull in select2 for auto searchanble drop downs -->
<script src="{{ asset('elite/bower_components/select2/select2.min.js') }}"></script>
<!-- Date Picker Plugin JavaScript -->
<script src="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.js') }}"></script>
<script src="{{ asset('elite/js/mask.js') }}"></script>
<script type="text/javascript">
let patient_id = <?php echo $patient->id; ?>;
function capture_fingerprint() {
$.ajax({
url: '/patients/fetch_fingerprint_from_scanner/',
success: function (response) {
let responseArray = JSON.parse(response);
if (responseArray["error_code"] == "0") {
let template = responseArray["template"];
let pngImage = "data:image/png;base64," + responseArray["image"];
$("#fingerprint_image").attr('src', pngImage);
$('#fingerprint_template').val(template);
$('#scanner_msg').text("Fingerprint Captured").css('color', 'green');
} else {
$('#scanner_msg').text("Error Code: " + responseArray["error_code"] + " - Error Message: " + responseArray["error_message"]).css('color', 'red');
}
}
});
}
function submitResidenceDistrict() {
var new_residence_district_name = $("#new_residence_district_name").val();
if ($("#new_residence_district_name").val() === "" || !$("#new_residence_district_name").val()) {
alert("Please make sure that you fill in a district name");
return false;
}
var data = {'new_residence_district_name': new_residence_district_name};
$.ajax({
method: 'POST',
url: '/patients/quick_add_district_residence',
data: data,
success: function (response) {
if (!isNaN(response)) {
//response = last inserted id
$('#residence_district_name').append($('<option>', {
value: response,
text: new_residence_district_name
}));
$('#residence_district_name').val(response);//preselect the newly added
$('#modal_district_residence').modal('hide'); //manually hide the modal
$('#modal_village_residence').modal('show');
} else {
alert("error occurred");
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(JSON.stringify(jqXHR));
console.log(JSON.stringify(jqXHR));
}
});
}
function submitResidenceVillage() {
var residence_district_name = $("#residence_district_name").val();
var new_residence_village_name = $("#new_residence_village_name").val();
if ($("#new_residence_village_name").val() === "" || !$("#new_residence_village_name").val() || !$("#residence_district_name").val()) {
alert("Please make sure that you fill in a village name and a district");
return false;
}
var data = {
'residence_district_name': residence_district_name,
'new_residence_village_name': new_residence_village_name
};
var district_village_ids = "";
$.ajax({
method: 'POST',
url: '/patients/quick_add_village_residence',
data: data,
success: function (response) {
if (!isNaN(response)) {
//response = newly created village. Now create residence string i.e village,parish etc
district_village_ids = response + ",0" + ",0" + ",0," + residence_district_name;
$('#residence').append($('<option>', {
value: district_village_ids,
text: new_residence_village_name
}));
$('#residence').val(district_village_ids);//preselect the newly added
$('#modal_village_residence').modal('hide'); //manually hide the modal
} else {
alert("error occurred");
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(JSON.stringify(jqXHR));
console.log(JSON.stringify(jqXHR));
}
});
}
function submitDeactivationReason() {
var reason = $("#patient_deactivation_reasons").val();
if ($("#patient_deactivation_reasons").val() === "" || !$("#patient_deactivation_reasons").val()) {
alert("Please fill in the reason for deleting the Patient");
return false;
}
var data = {'patient_deactivation_reasons': reason, 'patient_id': patient_id};
$.ajax({
method: 'POST',
url: '/patients/delete_patient_with_reason',
data: data,
success: function (response) {
if (response == 1) {
window.location.href = "/patients";
} else {
alert("error occurred");
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(JSON.stringify(jqXHR));
console.log(JSON.stringify(jqXHR));
}
});
}
function submitCompany() {
var company_name = $("#company_name").val();
var company_contact = $("#company_contact").val();
var company_identifier = $("#company_identifier").val();
if ($("#company_name").val() === "" || !$("#company_name").val()) {
alert("Please make sure that you fill in a company name");
return false;
}
if ($("#company_contact").val() === "" || !$("#company_contact").val()) {
alert("Please make sure that you add the company contact");
return false;
}
var data = {
'company_name': company_name,
'company_contact': company_contact,
'company_identifier': company_identifier
};
$.ajax({
method: 'POST',
url: '/patients/add_company',
data: data,
success: function (response) {
if (!isNaN(response)) {
//response = last inserted id
$('#company').append($('<option>', {
value: response,
text: company_name
}));
$('#company').val(response);//preselect the newly added referral
$('#modal_company').modal('hide'); //manually hide the modal
} else {
alert("error occurred");
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(JSON.stringify(jqXHR));
console.log(JSON.stringify(jqXHR));
}
});
}
$('#owned').on("click", function () {
$('.owners_name').hide();
$('#owner_name').val('');
});
$('#non_owned').on("click", function () {
$('.owners_name').show();
});
$('#h_contact_yes').on("click", function () {
$('.hosp_contact_div').show();
});
$('#h_contact_no').on("click", function () {
$('.hosp_contact_div').hide();
$('#hospital_contact').val('');
});
jQuery('#date_of_birth').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd/mm/yyyy',
endDate: new Date()
});
$('#age_in_years, #age_in_months').on('change', function () {
let years = parseInt($('#age_in_years').val());
let months = parseInt($('#age_in_months').val());
let possibleBirthday = new Date();
if (!isNaN(years) || !isNaN(months)) {
possibleBirthday.setMonth(possibleBirthday.getMonth() - (months + (years * 12)));
$('#date_of_birth').val(format_date(possibleBirthday));
} else {
alert("<?php echo __('patients.valid_number_years') ?>")
}
});
function format_date(date) {
let d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) {
month = '0' + month;
}
if (day.length < 2) {
day = '0' + day;
}
return [day, month, year].join('/');
}
$("#date_of_birth").on('change', function () {
var today = new Date();
var birthDate = $(this).val();
var temp_date = birthDate.split("/");
birthDate = new Date(temp_date[2], (temp_date[1] - 1), temp_date[0]);
//calculate years
var age = today.getFullYear() - birthDate.getFullYear();
age = parseInt(age);
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
//calculate months
var monthBirth = birthDate.getMonth() + 1;
var monthToday = today.getMonth() + 1;
if (monthToday > monthBirth) {
var months = monthToday - monthBirth;
} else if (monthToday == monthBirth) {
var months = 0;
} else if (monthToday < monthBirth) {
var months = monthToday - monthBirth;
months = months + 12;
}
if (months < 10) {
months = '0' + months
}
//set the values
$('#age_in_years').val(age);
$('#age_in_months').val(months);
});
$('#next_of_kin').on('change', function () {
if ($(this).val() != "" && $(this).val() != " ") {
$('#kin_div').show();
} else {
$('#kin_div').hide();
}
});
/* make residence drop downs searchable */
$('#company').select2({
placeholder: "-- select --"
});
//$('.select2-selection.select2-selection--single').addClass('form-control');//add class to select2 display
$('.select2-selection.select2-selection--single').css('height', 'calc(3.85rem)');
$('.select2-selection.select2-selection--single').css('padding-top', '5px');
$('.select2-selection__arrow').css('top', '3px');
$("#citizenship").click(function () {
var citizenship = $("#citizenship").val();
if (citizenship == 0) {
$("#not_ugandan_regions").show();
$("#ugandan_regions").hide();
$('#residence').prop('required', false);
} else {
$("#not_ugandan_regions").hide();
$("#ugandan_regions").show();
$('#residence').prop('required', true);
}
});
$('#residence').select2({
placeholder: 'Search residences',
ajax: {
url: '/patients/search_residences',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.text,
id: item.ids
}
})
};
},
cache: true
}
});
$("#patients_submit").click(function (e) { // make sure that all compulsory fields have been filled out
var empty_compulsory_fields = [];
$("#white-box.compulsory").each(function () {
if ($(this).val() == "") {
var textname = $(this).attr('name');
$(this).focus();
empty_compulsory_fields.push(textname);
$(this).css('border', '1px solid #F08080');
}
});
/* check if the array containing empty compulsory fields is not empty then return false */
if (empty_compulsory_fields.length != 0) {
alert("Please fill in all compulsory fields");
console.log(empty_compulsory_fields);
e.preventDefault();
return false;
}
});
</script>
@endpush