Files

175 lines
5.7 KiB
JavaScript
Executable File
Vendored

$('#primary_diagnosis').on('change', function () {
var data = 'diagnosis_id=' + $(this).val();
$.ajax({
type: "get",
url: "/diagnoses/get_diagnosis",
data: data,
cache: false,
success: function (result) {
var prompt_and_references = result.split('&&');
$('#primary_diagnosis_prompt').html(prompt_and_references[0]);
$('#primary_diagnosis_reference').html(prompt_and_references[1]);
}
});
});
$('#wrapper').on( 'change', '[id^=left_eye_diagnosis_id_]', function () {
var data = 'diagnosis_id=' + $(this).val();
var other_diagnosis_id = $(this).attr('id');
var nth = other_diagnosis_id.substring(22); //remove "other_diagnosis_id_" from strg to remain with the no e.g 1003
var prompt_id = parseInt(nth) - 1000;
var reference_id = prompt_id + 100;
$.ajax({
type: "get",
url: "/diagnoses/get_diagnosis_categories",
data: data,
cache: false,
success: function (result) { console.log(result)
$('#right_diagnosis_category_'+prompt_id).html("<select class='form-control select'>"+ result +"</select>");
$('#other_diagnosis_id_'+reference_id).html("<select class='form-control select'></select>");
}
});
});
$('#wrapper').on( 'change', '[id^=other_diagnosis_id_]', function () {
var data = 'diagnosis_id=' + $(this).val();
var other_diagnosis_id = $(this).attr('id');
var nth = other_diagnosis_id.substring(19); //remove "other_diagnosis_id_" from strg to remain with the no e.g 1003
var prompt_id = parseInt(nth) - 1000;
var reference_id = prompt_id + 100;
$.ajax({
type: "get",
url: "/diagnoses/get_diagnosis",
data: data,
cache: false,
success: function (result) {
var prompt_and_references = result.split('&&');
if (nth < 1000) {
$('#secondary_diagnosis_prompt1').html(prompt_and_references[0]);
$('#secondary_diagnosis_reference1').html(prompt_and_references[1]);
}
else{
// this is for prompts and references added dynamically using the addrow button
$('#secondary_diagnosis_prompt'+prompt_id).html(prompt_and_references[0]);
$('#secondary_diagnosis_reference'+reference_id).html(prompt_and_references[1]);
}
}
});
});
$("#outcome").change(function () {
var id = $(this).val();
switch (id) {
case "1": // Admitted
$('#admitted_div').show();
$('#home_with_followup_div').hide();
$('#referred_div').hide();
break;
case "3": // Home with follow up
$('#home_with_followup_div').show();
$('#admitted_div').hide();
$('#referred_div').hide();
break;
case "4": // Referred
$('#referred_div').show();
$('#home_with_followup_div').hide();
$('#admitted_div').hide();
break;
default:
$('#admitted_div').hide();
$('#home_with_followup_div').hide();
$('#referred_div').hide();
break;
}
});
jQuery('.datepicker-autoclose').datepicker({
autoclose: true,
format: 'yyyy-mm-dd',
});
function select2set(id) {
$('#'+id).select2();
}
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for (var i = 0; i < colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
/* set new id for the symptom select tag which is found in the first cell of every row
* this makes the symptom select tag id dynamic and different for each table row
* the id should be the rowCount +1000 to avoid a similar id with prompt div tag id set below
*/
if (i == 1) {
newcell.childNodes[1].id = 'other_diagnosis_id_'+(rowCount + 1000);
select2set('other_diagnosis_id_'+(rowCount + 1000));
}
/*
* set new value for the prompt div tag
*/
if (i == 2) {
table.rows[rowCount].cells[2].innerHTML = '';
table.rows[rowCount].cells[2].innerHTML = '<div class="well well-sm" id="secondary_diagnosis_prompt' + rowCount + '">&nbsp;</div>';
}
if (i == 3) {
// var myid = (rowCount + 100);
table.rows[rowCount].cells[3].innerHTML = '';
table.rows[rowCount].cells[3].innerHTML = '<div class="well well-sm" id="secondary_diagnosis_reference' + (rowCount + 100) + '">&nbsp;</div>';
// alert(myid);
}
switch (newcell.childNodes[0].type) {
case "text":
// newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
if (rowCount <= 2) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}