Created
May 19, 2017 13:37
-
-
Save iaditya/0eda2f7253d106f2b69cf4a4a634eb13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo $this->Html->script('moment/moment.min'); | |
echo $this->Html->css('AdminLTE./bootstrap/css/bootstrap-datetimepicker.min'); | |
echo $this->Html->script('AdminLTE./bootstrap/js/bootstrap-datetimepicker'); | |
echo $this->Html->script('AdminLTE./plugins/datepicker/bootstrap-datepicker'); | |
$log_role = $this->request->session()->read('Auth.User.role'); | |
?> | |
<div class="events form col-lg-10 col-md-9 columns"> | |
<?= $this->Form->create($event, ['id' => 'myForm']); ?> | |
<div id="logRole" data-role="<?= $log_role; ?>"></div> | |
<div id="patientId" data-patient-id="<?= $patient->id; ?>"></div> | |
<fieldset> | |
<legend><?= __('Appointment') ?></legend> | |
<?php | |
echo "<b>Patient Name:</b> " . $patient->user->full_name; | |
echo "<br>"; | |
echo "<b>Provider Name:</b> " . $provider->user->full_name; | |
echo "<br>"; | |
echo "<b>Facility:</b> " . $facility->name; | |
echo "<br>"; | |
if (empty($slot_type)) { | |
echo $this->Form->input('event_type_id', ['type' => 'radio', 'required' => true], ['options' => $eventTypes]); | |
} else { | |
if ($slot_type === 'inhouse') { | |
echo "<b>Event Type :</b> In House Appointment"; | |
echo "<BR>"; | |
echo $this->Form->hidden('event_type_id', ['value' => 1]); | |
} else if ($slot_type === 'telecon') { | |
echo "<b>Event Type :</b> Telecon Appointment"; | |
echo "<BR>"; | |
echo $this->Form->hidden('event_type_id', ['value' => 2]); | |
} else { | |
echo '<div id="both">' . $this->Form->input('event_type_id', ['type' => 'radio', 'required' => true], ['options' => $eventTypes]) . '</div>'; | |
} | |
} | |
echo "<br>"; | |
// echo $slot_type; | |
echo $this->Form->input('title', array('default' => "Patient: " . $patient->user->full_name . " Provider: " . $provider->user->full_name . " At Facility: " . $facility->name)); | |
if ($this->request->session()->read('Auth.User.role') == "Patient") { | |
$readonly='true'; | |
if (!empty($facility) && ($facility->appointment_autoconfirm == 1)) { | |
echo $this->Form->hidden('status', ['value' => 'Confirmed']); | |
} else { | |
echo $this->Form->hidden('status', ['value' => 'Pending']); | |
} | |
} else { | |
$readonly='false'; | |
echo $this->Form->label('Appointment Status ') . "<br>"; | |
echo $this->Form->select('status', ['Confirmed' => 'Confirmed', 'Pending' => 'Pending']); | |
} | |
echo "<br><br>"; | |
echo $this->Form->hidden('active', ['value' => 1]); | |
echo $this->Form->input('start', ['value' => $start, 'label' => 'Start Date', 'type' => 'text', 'class' => 'datetimepicker', 'readonly'=>$readonly]); | |
echo $this->Form->input('end', ['value' => $end, 'label' => 'End Date', 'type' => 'text', 'class' => 'datetimepicker', 'readonly'=>$readonly]); | |
echo $this->Form->hidden('all_day', ['value' => 0]); | |
echo "<br>"; | |
// debug($slot_type); | |
if (!empty($provider)) { | |
echo $this->Form->hidden('provider_id', ['value' => $provider->id]); | |
} else { | |
echo $this->Form->input('provider_id', ['options' => $providers, 'id' => 'provider_list']); | |
} | |
if (!empty($patient)) { | |
echo $this->Form->hidden('patient_id', ['value' => $patient->id]); | |
} else { | |
echo $this->Form->input('patient_id', ['options' => $patients]); | |
} | |
if (!empty($facility)) { | |
echo $this->Form->hidden('facility_id', ['value' => $facility->id]); | |
} else { | |
echo $this->Form->input('facility_id', ['options' => $facilities, 'empty' => true, 'id' => 'facility_list']); | |
} | |
echo $this->Form->input('details'); | |
echo $this->Form->input('issues.0.issue_type_id', ['options' => $issueTypes, 'empty' => true]); | |
// echo $this->Form->input('issues.0.begindate'); | |
echo $this->Form->input('issues.0.referredby', ['label' => 'Referred By']); | |
echo $this->Form->input('issues.0.reaction'); | |
echo $this->Form->input('issues.0.allergies'); | |
?> | |
</fieldset> | |
<br> | |
<?= $this->Form->button(__('Submit'), ['class' => 'btn-success']) ?> | |
<?= $this->Form->end() ?> | |
</div> | |
<script type="text/javascript"> | |
$(function () { | |
$('.datetimepicker').datetimepicker({ | |
format: 'YYYY-MM-DD hh:mm A' | |
}); | |
if($('#both').length != 0) { | |
var inhouseSlotTime = '<?= $provider->inhouse_slot_time ?>'; | |
var teleconSlotTime = '<?= $provider->telecon_slot_time ?>'; | |
// "both slot type " - radio button exists | |
$('#myForm input').on('change', function() { | |
var start = $('#start').val(); | |
var end = $('#end'); | |
var selectedVal = $('input[name=event_type_id]:checked', '#myForm').val(); | |
if(selectedVal == 1) { | |
// In House | |
end.val(moment(start).add(inhouseSlotTime, 'm').format("YYYY-MM-DD hh:mm A")); | |
} else { | |
// selectedVal == 2, tele app | |
end.val(moment(start).add(teleconSlotTime, 'm').format("YYYY-MM-DD hh:mm A")); | |
} | |
}); | |
} | |
}); | |
</script> | |
<script> | |
// caregiver_type => 0 for Primary, 1 for Second | |
function addCaregiver(patientId, caregiver_type) { | |
jQuery.ajax({ | |
type: 'POST', | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
}, | |
async: true, | |
cache: false, | |
url: '/patients/addCg/' + patientId + "/" + caregiver_type, | |
//data: {'patient_id': patientId}, | |
success: function (response) { | |
//alert("success, " + " Caregiver Added!"); | |
console.log(response); | |
}, | |
error: function (e) { | |
//alert("something went wrong."); | |
console.log("error: " + e.responseText); | |
} | |
}); | |
} | |
function getPatientEntity(patientId) { | |
$.ajax({ | |
url: '/patients/patientCaregiver/' + patientId + '.json', | |
type: 'GET', | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
}, | |
data: { | |
format: 'json' | |
}, | |
success: function (response) { | |
if (response.patient) { | |
var patient = response.patient; | |
//return patient; | |
patientData(patient); | |
} | |
}, | |
error: function (e) { | |
//alert(e.status); | |
if (e.status == 404 || e.status == 500) { | |
//console.log('Internel Server Error.'); | |
} | |
} | |
}); | |
} | |
//callback | |
function patientData(patient) { | |
var patientId = $('#patientId').data('patient-id'); | |
var caregiverLabel1 = patient.primary_caregiver_active; | |
var caregiverLabel2 = patient.second_caregiver_active; | |
var age = patient.age; | |
var caregiverName1 = patient.primary_contact_name ? patient.primary_contact_name : ""; | |
var caregiverName2 = patient.second_contact_name ? patient.second_contact_name : ""; | |
var caregiverRelation1 = patient.primary_contact_relationship ? patient.primary_contact_relationship : ""; | |
var caregiverRelation2 = patient.second_contact_relationship ? patient.second_contact_relationship : ""; | |
var patientAge = age ? age : null; | |
var caregiverMobile1 = patient.primary_contact_phone1 ? patient.primary_contact_phone1 : ""; | |
var caregiverMobile2 = patient.second_contact_phone1 ? patient.second_contact_phone1 : ""; | |
//throw new Error("Something went badly wrong!"); | |
// if both | |
if (((!caregiverLabel1) && (caregiverName1)) && ((!caregiverLabel2) && (caregiverName1))) { | |
// add caregiver for non-minor | |
// mobile number is requireed for creating new user/caregiver. | |
if(caregiverMobile1 && caregiverMobile2) { | |
if ((patientAge != null) && (patientAge >= 18)) { | |
var reply = confirm("This Patient have two caregiver with their relationship : \n" + caregiverName1 + " - " + caregiverRelation1 + " \n " + caregiverName2 + " - " + caregiverRelation2 + " \nclick ok to send notification/activation regarding appointment to caregiver also."); | |
if (reply == true) { | |
//console.log("Sent notification to CG"); | |
// add caregiver | |
console.log(patientId); | |
addCaregiver(patientId, 1); | |
addCaregiver(patientId, 2); | |
} | |
alert("success, " + " Caregiver Added!"); | |
} | |
} | |
} | |
// if primary | |
else if ((!caregiverLabel1) && (caregiverName1)) { | |
if(caregiverMobile1) { | |
if ((patientAge != null) && (patientAge >= 18)) { | |
var reply = confirm("This Patient have primary caregiver with relationship : \n" + caregiverName1 + " - " + caregiverRelation1 + " \n " + " \nclick ok to send notification/activation regarding appointment to caregiver also."); | |
if (reply == true) { | |
addCaregiver(patientId, 1); | |
} | |
alert("success, " + " Caregiver Added!"); | |
} | |
} | |
} | |
// if secondary | |
else { | |
if(caregiverMobile2) { | |
if ((patientAge != null) && (patientAge >= 18)) { | |
var reply = confirm("This Patient have secondary caregiver with relationship : \n" + caregiverName2 + " - " + caregiverRelation2 + " \n " + " \nclick ok to send notification/activation regarding appointment to caregiver also."); | |
if (reply == true) { | |
addCaregiver(patientId, 2); | |
} | |
alert("success, " + " Caregiver Added!"); | |
} | |
} | |
} | |
} | |
$(document).ready(function () { | |
$('#provider_list').change(function () { | |
//alert($(this).val()); | |
jQuery.ajax({ | |
type: 'POST', | |
beforeSend: function (xhr) { | |
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
}, | |
async: true, | |
cache: false, | |
url: '/facilities/get_facility_by_provider', | |
data: { | |
"provider_id": $(this).val() | |
}, | |
success: function (response) { | |
//alert("success" + response); | |
$('#facility_list').html(response.content); | |
}, | |
error: function (e) { | |
alert("error: " + e.responseText); | |
} | |
}); | |
return false; | |
}); | |
var patientId = $('#patientId').data('patient-id'); | |
var role = $('#logRole').data('role'); | |
//console.log(role); | |
// provider approval - decrypted now. | |
//if (role == "Provider") { | |
// getPatientEntity(patientId); | |
//} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment