223 lines
10 KiB
HTML
223 lines
10 KiB
HTML
{% load static %}
|
|
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Transfer Patient</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="transferForm" method="post" action="{% url 'inpatients:request_transfer' admission_id=admission.id %}">
|
|
{% csrf_token %}
|
|
|
|
<div class="patient-info mb-3">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<p><strong>Patient:</strong> {{ admission.patient.get_full_name }}</p>
|
|
<p><strong>MRN:</strong> {{ admission.patient.mrn }}</p>
|
|
<p><strong>Admission Date:</strong> {{ admission.admission_datetime|date:"M d, Y H:i" }}</p>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<p><strong>Current Ward:</strong> {{ admission.current_ward.name }}</p>
|
|
<p><strong>Current Room:</strong> {{ admission.current_bed.room_number }}</p>
|
|
<p><strong>Current Bed:</strong> {{ admission.current_bed.bed_number }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="transfer_type" class="form-label">Transfer Type <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="transfer_type" name="transfer_type" required>
|
|
<option value="">Select transfer type</option>
|
|
<option value="WARD">Ward Transfer</option>
|
|
<option value="BED">Bed Transfer (Same Ward)</option>
|
|
<option value="LEVEL">Level of Care Transfer</option>
|
|
<option value="SERVICE">Service Transfer</option>
|
|
</select>
|
|
<div class="form-text">Select the type of transfer being requested.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="target_ward" class="form-label">Target Ward <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="target_ward" name="target_ward" required>
|
|
<option value="">Select target ward</option>
|
|
{% for ward in wards %}
|
|
<option value="{{ ward.id }}" {% if ward.id == admission.current_ward.id %}data-same-ward="true"{% endif %}>
|
|
{{ ward.name }} ({{ ward.available_beds }} available beds)
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
<div class="form-text">Select the ward where the patient will be transferred.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="target_bed" class="form-label">Target Bed <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="target_bed" name="target_bed" required disabled>
|
|
<option value="">Select ward first</option>
|
|
</select>
|
|
<div class="form-text">Select the specific bed for the patient.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="transfer_reason" class="form-label">Reason for Transfer <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="transfer_reason" name="transfer_reason" required>
|
|
<option value="">Select reason</option>
|
|
<option value="CLINICAL">Clinical Need</option>
|
|
<option value="CAPACITY">Capacity Management</option>
|
|
<option value="ISOLATION">Isolation Requirement</option>
|
|
<option value="LEVEL_OF_CARE">Change in Level of Care</option>
|
|
<option value="SERVICE_CHANGE">Service Change</option>
|
|
<option value="PATIENT_REQUEST">Patient Request</option>
|
|
<option value="OTHER">Other (specify in notes)</option>
|
|
</select>
|
|
<div class="form-text">Select the primary reason for this transfer.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="requested_datetime" class="form-label">Requested Transfer Time <span class="text-danger">*</span></label>
|
|
<input type="datetime-local" class="form-control" id="requested_datetime" name="requested_datetime" required>
|
|
<div class="form-text">When should this transfer take place?</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="priority" class="form-label">Priority <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="priority" name="priority" required>
|
|
<option value="">Select priority</option>
|
|
<option value="ROUTINE">Routine</option>
|
|
<option value="URGENT">Urgent</option>
|
|
<option value="EMERGENCY">Emergency</option>
|
|
</select>
|
|
<div class="form-text">Select the priority level for this transfer.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="notes" class="form-label">Notes</label>
|
|
<textarea class="form-control" id="notes" name="notes" rows="3" placeholder="Enter any additional information about this transfer"></textarea>
|
|
<div class="form-text">Please provide any additional details about this transfer request.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="notify_team" name="notify_team" checked>
|
|
<label class="form-check-label" for="notify_team">
|
|
Notify care team about this transfer
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="submit" form="transferForm" class="btn btn-primary">
|
|
<i class="fa fa-exchange-alt"></i> Request Transfer
|
|
</button>
|
|
</div>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Set default requested datetime to current time + 1 hour
|
|
var now = new Date();
|
|
now.setHours(now.getHours() + 1);
|
|
var defaultDateTime = now.toISOString().slice(0, 16);
|
|
$('#requested_datetime').val(defaultDateTime);
|
|
|
|
// Handle transfer type change
|
|
$('#transfer_type').change(function() {
|
|
var transferType = $(this).val();
|
|
|
|
if (transferType === 'BED') {
|
|
// For bed transfers, pre-select current ward and disable ward selection
|
|
$('#target_ward option').each(function() {
|
|
if ($(this).data('same-ward')) {
|
|
$(this).prop('selected', true);
|
|
}
|
|
});
|
|
$('#target_ward').prop('disabled', true);
|
|
loadBeds();
|
|
} else {
|
|
// For other transfers, enable ward selection
|
|
$('#target_ward').prop('disabled', false);
|
|
$('#target_ward').val('');
|
|
$('#target_bed').html('<option value="">Select ward first</option>');
|
|
$('#target_bed').prop('disabled', true);
|
|
}
|
|
});
|
|
|
|
// Load beds when ward is selected
|
|
$('#target_ward').change(function() {
|
|
loadBeds();
|
|
});
|
|
|
|
function loadBeds() {
|
|
var wardId = $('#target_ward').val();
|
|
if (!wardId) {
|
|
$('#target_bed').html('<option value="">Select ward first</option>');
|
|
$('#target_bed').prop('disabled', true);
|
|
return;
|
|
}
|
|
|
|
// Show loading indicator
|
|
$('#target_bed').html('<option value="">Loading beds...</option>');
|
|
|
|
// AJAX call to get available beds
|
|
$.ajax({
|
|
url: '{% url "inpatients:get_available_beds" %}',
|
|
data: {
|
|
'ward_id': wardId
|
|
},
|
|
dataType: 'json',
|
|
success: function(data) {
|
|
var options = '<option value="">Select bed</option>';
|
|
if (data.beds.length > 0) {
|
|
$.each(data.beds, function(index, bed) {
|
|
options += '<option value="' + bed.id + '">' +
|
|
'Room ' + bed.room_number + ', Bed ' + bed.bed_number +
|
|
' (' + bed.bed_type + ', ' + bed.room_type + ')</option>';
|
|
});
|
|
$('#target_bed').prop('disabled', false);
|
|
} else {
|
|
options = '<option value="">No available beds in this ward</option>';
|
|
$('#target_bed').prop('disabled', true);
|
|
}
|
|
$('#target_bed').html(options);
|
|
},
|
|
error: function() {
|
|
$('#target_bed').html('<option value="">Error loading beds</option>');
|
|
$('#target_bed').prop('disabled', true);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Form validation
|
|
$('#transferForm').submit(function(e) {
|
|
var isValid = true;
|
|
|
|
// Required fields
|
|
var requiredFields = ['#transfer_type', '#target_ward', '#target_bed',
|
|
'#transfer_reason', '#requested_datetime', '#priority'];
|
|
|
|
$.each(requiredFields, function(index, field) {
|
|
if ($(field).val() === '' || $(field).val() === null) {
|
|
$(field).addClass('is-invalid');
|
|
isValid = false;
|
|
} else {
|
|
$(field).removeClass('is-invalid');
|
|
}
|
|
});
|
|
|
|
// Check if "Other" reason is selected but no notes provided
|
|
if ($('#transfer_reason').val() === 'OTHER' && $('#notes').val().trim() === '') {
|
|
$('#notes').addClass('is-invalid');
|
|
$('#notes').closest('.mb-3').find('.form-text').html('<span class="text-danger">Please provide details for "Other" reason.</span>');
|
|
isValid = false;
|
|
}
|
|
|
|
if (!isValid) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
});
|
|
</script>
|
|
|