$(document).ready(function () {
$("#fio").select2({
tags: true
});
$("#fio").on("change", function() {
id = this.value;
text = $( "#fio option:selected" ).text();
if (id == text)
{
console.log('New Patient');
}
else{
$.ajax({
type: "GET",
url: '/get_patient_clinic/' + id,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: (data) => {
$("#med_card").val(data['card_number']);
$("#telephone").val(data['telephone']);
$("#dob").val(data['dob']);
$("#sex").val(data['sex']);
updateInfo();
}
})
}
})
load__endo_history(true);
function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
return false;
};
$('.close-modal').on('click', function(){
$('#standart_modal').modal('toggle');
});
$('#short_std').on('click', function(){
standart_load($('#cur_modal_std').val(), false, $('#cur_modal_tag_id').val());
$('#short_std').hide();
$('#long_std').show();
});
$('#long_std').on('click', function(){
standart_load($('#cur_modal_std').val(), true, $('#cur_modal_tag_id').val());
$('#short_std').show();
$('#long_std').hide();
});
$('#med_card').on('change', function(){updateInfo()});
$('#telephone').on('change', function(){updateInfo()});
// $('#fio').on('change', function(){updateInfo()});
$('#dob').on('change', function(){updateInfo()});
$('#sex').on('change', function(){updateInfo()});
$('#complaints_input').on('change', function(){updateInfo()});
$('#anamnesis_input').on('change', function(){updateInfo()});
function complete_med_exam(visit_id){
var message = {
visit_id : visit_id
}
$.ajax({
type:'POST',
url: '/complete_med_exam',
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
data: JSON.stringify(message),
success: (data) => {
if(data['success'] == true)
{
show_success('Профосмотр сохранён', false);
}
else
{
show_error('Не удалось завершить профосмотр' ,0);
}
},
error:function (jqXHR, exception) {
show_error('Не удалось завершить профосмотр' ,0);
}
});
}
$('#clear_med_exam').click(function(){
$('#med_card').val('');
$('#telephone').val('');
$('#fio').val('');
$('#dob').val('');
$('#sex').val('');
$('#complaints_input').val('');
$('#anamnesis_input').val('');
$('#short_endo_history').empty();
let visit_id = $('#visit_id').val();
complete_med_exam(visit_id);
updateStatus();
$.ajax({
type:'GET',
url: '/get_new_visit_id',
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: (data) => {
$('#visit_id').val(data['visit_id']);
console.log('New visit ID');
console.log($('#visit_id').val());
},
error:function (jqXHR, exception) {
after_error();
}
});
})
function updateInfo(){
updateStatus();
if ($('#visit_id').val())
startLoad(null)
else
console.log('no visit')
}
function previewIMG(input, preview) {
var reader = new FileReader();
reader.onload = function(e) {
$(preview).attr('src', e.target.result);
}
reader.readAsDataURL(input);
}
$("#file_input").change(function(){
$('#imgs_preview').empty();
$('#file-input-greenspan').html('');
if ($(this)[0].files[0]) {
$('#pre_load').hide();
$('#file-input-greenspan').html('Загружено снимков: ' + $(this)[0].files.length);
for(i=0;i<$(this)[0].files.length;i++)
{
if (($(this)[0].files[i].type.includes('image')))
{
div = document.createElement('div');
div.setAttribute('class', 'col-3 p-1 m-0');
img = document.createElement('img');
img.setAttribute('class', 'preview_img');
previewIMG($(this)[0].files[i], $(img));
div.appendChild(img);
document.getElementById("imgs_preview").appendChild(div);
startLoad(null);
}
}
}
});
function reload_visit_info(){
lang = getUrlParameter('lang');
$.ajax({
type:'GET',
url: '/reload_visit_info/' + $('#visit_id').val() + '?task=off'+'&lang='+lang,
processData: false,
contentType: false,
success: (data) => {
//load__endo_history(false);
}
});
}
function load__endo_history(rvn){
$('#short_endo_history').empty();
if(rvn)
reload_visit_info();
$.ajax({
type:'GET',
url: '/get_visit_info/' + $('#visit_id').val() + '?task=off',
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentTypestatus
success: (data) => {
var label_id = 0
for (untask_num in data['untask_pics'])
{
pic = data['untask_pics'][untask_num]
organ = ''
if (pic['organ'])
{
organ = pic['organ']
}
if($('#language').val() == 'ru')
$('#short_endo_history').append('
Стандарт
');
else
$('#short_endo_history').append('
Standart
');
label_id = label_id + 1
}
for (task_num in data['tasks'])
{
task = data['tasks'][task_num]
if ('task' in task)
if (task['task'])
if ('result' in task['task'])
for (result_num in task['task']['result'])
{
result = task['task']['result'][result_num]
var code = ''
var name = ''
var probability = 0
if ('diseases' in result)
for (d_num in result['diseases'])
{
disease = result['diseases'][d_num]
if(disease['probability'] > probability)
{
probability = disease['probability']
code = disease['code']
name = disease['name']
}
}
var organ = result['organ']
if (organ == undefined)
organ = 'Ошибка - '+task['task']['status']
if (probability > 0)
if($('#language').val() == 'ru')
$('#short_endo_history').append('
');
label_id = label_id + 1
}
}
select_fill();
for (pic_num in data['pics'])
{
pic = data['pics'][pic_num]
if (pic.length > 0){
if(pic.length > 1)
{
console.log('Обнаружены снимки с дублирующимся описанием')
}
$.each($('.diagnoses_select'), function(e) {
if($(this).data('img') == pic[0]['hash_name'])
{
$(this).val(pic[0]['tag_id']);
$(this).parent().children('.standart_modal').data('code', pic[0]['icd']);
$(this).parent().children('.standart_modal').removeClass('btn-secondary');
$(this).parent().children('.standart_modal').addClass('btn-primary');
}
})
}
}
for (pic_num in data['expert_pics'])
{
pic = data['expert_pics'][pic_num]
if (pic.length > 0){
if(pic.length > 1)
{
console.log('Обнаружены снимки с дублирующимся экспертым описанием')
}
$.each($('.expert_diagnos'), function(e) {
if($(this).data('img') == pic[0]['hash_name'])
{
$(this).html(pic[0]['icd']+' '+pic[0]['tag'])
$(this).parent().children('.standart_modal').data('tag_id', pic[0]['tag_id']);
$(this).parent().children('.standart_modal').data('code', pic[0]['icd']);
$(this).parent().children('.standart_modal').removeClass('btn-secondary');
$(this).parent().children('.standart_modal').addClass('btn-primary');
}
})
}
}
$('.standart_modal').on('click', function(){
$('#standart_modal').modal('toggle');
standart_load($(this).data('code'), false, $(this).data('tag_id'));
})
$('.preview_img').click(function(){
$(this).attr('src', $(this).attr('src')+getRandomInt(99));
})
$('.diagnoses_select').on('change', function() {
save_select(this);
$(this).parent().children('.standart_modal').removeClass('btn-secondary');
$(this).parent().children('.standart_modal').addClass('btn-primary');
});
$('.diagnoses_select').select2();
},
error:function (jqXHR, exception) {
}
});
}
//saving on select change
function save_select(element){
var message = {
diagnos_id: element.value,
pic_name: $(element).data('img'),
visit_id: $('#visit_id').val(),
}
$.ajax({
type:'POST',
url: '/save_pic_diagnos',
async: false ,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
data: JSON.stringify(message),
success: (data) => {
if(data['success'] == true)
{
$(element).parent().children('.standart_modal').data('code', data['icd']);
$(element).parent().children('.standart_modal').data('tag_id', data['tag_id']);
$('#success').html('Диагноз сохранен');
$('#success').slideDown(500);
$('#success').delay(2000).slideUp();
}
else
{
after_error();
}
},
error:function (jqXHR, exception) {
after_error();
}
});
}
function getId(str)
{
return(str.replaceAll(' ','').replaceAll(',','').replaceAll('.','').replaceAll(';','').replaceAll(':','').replaceAll('(','').replaceAll(')','').replaceAll('-','').replaceAll('/','').replaceAll('\\',''))
}
function standart_load(code, full, tag_id){
$('#cur_modal_std').val(code);
$('#cur_modal_tag_id').val(tag_id);
lang = getUrlParameter('lang');
console.log('lang - '+lang);
$.ajax({
type:'GET',
url: '/get_diagnos_standart?icd='+code+'&tag_id='+tag_id+'&lang='+lang,
async: true,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: (data) => {
$('#standart_body').empty();
$('#standart_name').html(data['standart_name']);
if(lang == 'en'){
$('#standart_diagnos').html('Diagnosis: ' + data['name']+'');
$('#standart_type').html('Type of standard: '+data['standart_type']+'');
$('#standart_icd_code').html('ICD-10 code: '+data['icd']+'');
$('#standart_time').html('Treatment time (days): '+data['days_min']+' - '+data['days_max']+'');
}
else
{
$('#standart_diagnos').html('Диагноз: ' + data['name']+'');
$('#standart_type').html('Вид стандарта: '+data['standart_type']+'');
$('#standart_icd_code').html('Код по МКБ-10: '+data['icd']+'');
$('#standart_time').html('Сроки лечения (дней): '+data['days_min']+' - '+data['days_max']+'');
}
var groups = [];
for (std_num in data['standart'])
{
var std = data['standart'][std_num]
if (!(groups.includes(std['service_type'])))
{
groups.push(std['service_type'])
$('#standart_body').append('
'+std['service_type']+'
');
}
}
var sub_groups = [];
for (std_num in data['standart'])
{
var std = data['standart'][std_num]
for (group in groups){
if(!($('#group'+getId(std['service_type'])).data('dt'+getId(std['service_subtype'])) == true))
{
$('#group'+getId(std['service_type'])).data('dt'+getId(std['service_subtype']), true);
$('#group'+getId(std['service_type'])).append('