var D3ER = new function () {
this.eyes = function () {
if (D3Api.hasClass(document.body, 'er-eyes')) {
D3Api.removeClass(document.body, 'er-eyes');
D3Api.globalClientData.set('erEyes', 0);
} else {
D3Api.addClass(document.body, 'er-eyes');
D3Api.globalClientData.set('erEyes', 1);
}
};
this.loupe = function (isUserEvent) {
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i = 0;i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
}
var html = document.documentElement;
var date = new Date(2099, 0, 1);
var loupe = 'false';
if (isUserEvent) {
if (readCookie('er_loupe') === 'true') {
html.style.fontSize = parseInt(getComputedStyle(html, '').fontSize) - 6 + 'px';
} else if (readCookie('er_loupe') === 'false'){
html.style.fontSize = parseInt(getComputedStyle(html, '').fontSize) + 6 + 'px';
loupe = 'true';
}
document.cookie = 'er_loupe=' + loupe + '; expires=' + date.toUTCString();
} else {
if (readCookie('er_loupe') === 'true') {
html.style.fontSize = parseInt(getComputedStyle(html, '').fontSize) + 6 + 'px';
}
}
};
this.startLoad = function () {
document.getElementById('D3LoadContainer').style.display = 'block';
clearTimeout(D3ER._timerInactivitySystem);
};
this.endLoad = function () {
document.getElementById('D3LoadContainer').style.display = '';
var option = (D3ER.isInfomate()) ? 'inactivitySystem' : 'inactivitySystemPC';
var minute = D3Api.getOption(option, 0) * 60 * 1000;
if (minute > 0 && minute < Infinity) {
D3ER.checkActivity(minute);
}
};
var performanceStart = Date.now();
this.getPerformanceNow = function()
{
if(window.performance && window.performance.now) {
return window.performance.now();
} else {
return Date.now()-performanceStart;
}
}
this.setCurrentDate = function (str) {
D3ER._currentDate = {
date: D3ER.getDateFromString(str),
datewot: D3ER.getDateFromString(str.split(' ')[0]),
now: D3ER.getPerformanceNow()
};
};
this.checkActivity = function (minute) {
function resetTimeOut() {
clearTimeout(D3ER._timerInactivitySystem);
D3ER._timerInactivitySystem = setTimeout(function () {
D3ER.erExit();
}, minute);
}
document.addEventListener('mousemove', resetTimeOut);
document.addEventListener('wheel', resetTimeOut);
document.addEventListener('keydown', resetTimeOut);
};
this.getCurrentDate = function () {
return new Date(+D3ER._currentDate.date + D3ER.getPerformanceNow() - D3ER._currentDate.now);
};
this.getDateFromString = function (str) {
var match = str.match(/^(\d{2})\.(\d{2})\.(\d{4})(?=\s(\d{2}):(\d{2})(?=:(\d{2})|)|)/);
return new Date(match[3], match[2] - 1, match[1], match[4] || 0, match[5] || 0, match[6] || 0);
};
this.getStrMonth = function (date) {
return ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'][date.getMonth()];
};
this.getStrMonthNormal = function (date) {
return ['январь', 'февраль', 'март', 'апрель', 'май', 'июнь', 'июль', 'август', 'сентябрь', 'октябрь', 'ноябрь', 'декабрь'][date.getMonth()];
};
this.getStrDay = function (date) {
return ['воскресенье', 'понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота'][date.getDay()];
};
this.strDate = function (s) {
return (s < 10) ? '0' + s : '' + s;
};
this.formatDate = function (date, time) {
var s = D3ER.strDate(date.getDate()) + '.' + D3ER.strDate(date.getMonth() + 1) + '.' + date.getFullYear();
if (time) {
s += ' ' + D3ER.strDate(date.getHours()) + ':' + D3ER.strDate(date.getMinutes());
}
return s;
};
this.getDay = function (date) {
return date.getDay() || 7;
};
this.regexString = function (value) {
return String(value || '').replace(/([)(\\.?\[\]\{\}^$+-])/g, '\\$1');
};
this.printTicket = function (response) {
D3ER.printHTML(
'
' + 'Талон на прием к врачу' + '
' +
(response.ticket_no && '' + 'Талон: ' + response.ticket_no + '
' || '') +
'Дата приема: ' + response.rec_date_cap + '' +
(response.cablab && '' + 'Кабинет: ' + response.cablab + '
' || '') +
(response.doctor_fio && '' + 'ФИО врача: ' + response.doctor_fio + '
' || '') +
(response.service && '' + 'Услуга: ' + response.service + '
' || '') +
(response.payment && '' + 'Тип оплаты: ' + response.payment + '
' || '') +
(response.cost && '' + 'Стоимость приема: ' + response.cost + 'руб' + '
' || '') +
(response.lpu && '' + 'МО: ' + response.lpu + '
' || '') +
((response.division || response.address) ? '' + 'Место приема: ' + (response.division || '') + ((response.division && response.address) ? ', ' : '') + (response.address || '') + '
' : '') +
(response.phones && '' + 'Тел. регистратуры: ' + response.phones + '
' || '') +
(response.patient_fio && '' + 'Пациент: ' + response.patient_fio + '
' || '') +
(response.rec_comment && '' + 'Комментарий: ' + response.rec_comment + '
' || '')
);
};
this.printDirection = function (response) {
D3ER.printHTML(
'' + 'Талон направления к врачу' + '
' +
'Направление на: ' + response.service + '' +
(response.fio && '' + 'ФИО пациента: ' + response.fio + '
' || '') +
(response.polis && '' + 'Полис: ' + response.polis + '
' || '') +
(response.date_begin_cap && '' + 'Действует с: ' + response.date_begin_cap + '
' || '') +
(response.date_end_cap && '' + 'Действует до: ' + response.date_end_cap + '
' || '') +
(response.lpu && '' + 'ЛПУ направления: ' + response.lpu + '
' || '') +
(response.phone && '' + 'Тел. для справок: ' + response.phone + '
' || '')
);
};
this.printHTML = function (html) {
var windowPrint = window.frames.D3PrintContainer,
documentPrint = windowPrint.document,
bodyPrint = documentPrint.body;
documentPrint.title = 'Электронная регистратура';
bodyPrint.innerHTML = (html || '') +
'';
windowPrint.focus();
windowPrint.print();
};
this.isInfomate = function () {
return /[?&]infomate=true(&|$)/.test(window.location.search);
};
this.addReCaptchaNode = function (dom, callBackFunction) {
if (this.reCaptchaCount) {
this.reCaptchaCount++;
} else {
this.reCaptchaCount = 0;
}
var siteKey = D3Api.getOption('sitekey', false);
var newNode = document.createElement('div');
var id = 'er-captcha_' + D3Api.getUniqId();
newNode.setAttribute('id', id);
dom.appendChild(newNode);
D3Api.setProperty(dom, 'captcha', id);
var watch_id = grecaptcha.render(id, {
'sitekey': siteKey,
'theme': 'light',
'callback': callBackFunction
});
this.reCaptchaCount = watch_id;
dom.setAttribute('captcha', watch_id);
};
this.resetReCaptcha = function () {
grecaptcha.reset(this.reCaptchaCount);
};
this.getDataUrl = function () {
var arrSearch = window.location.search.split(/[?&]/);
var urlData = {};
for (var i = 0; i < arrSearch.length; i++) {
var arrItem = arrSearch[i].split('=');
if (!arrItem[0]) {
continue;
}
urlData[arrItem[0]] = arrItem[1] || '';
}
return urlData;
};
this.locationSearch = function (options) {
var path = [];
var data = D3ER.getDataUrl();
delete data.D3ErUsername;
if (!options) {
options = {};
}
for (var key in options) {
data[key] = options[key];
}
for (var key in data) {
path.push(key + ((data[key]) ? '=' + data[key] : ''));
}
return (path.length > 0) ? '?' + path.join('&') : '';
};
this.erHome = function () {
var locationSearch = D3ER.locationSearch();
if (location.search !== locationSearch) {
location.search = locationSearch;
} else {
location.reload(true);
}
};
this.setUserActivity = function () {
var cur_date = new Date();
D3Api.globalClientData.set('erActivate', JSON.stringify({
exitDate: cur_date
}));
};
this.checkUserActive = function () {
var erActivate = JSON.parse(D3Api.globalClientData.get('erActivate', 'null'));
var option = (D3ER.isInfomate()) ? 'inactivitySystem' : 'inactivitySystemPC';
var minute = 10;
var current_date = new Date();
if (erActivate) {
var active_date = new Date(erActivate.exitDate);
var erLogin = JSON.parse(D3Api.globalClientData.get('erLogin', 'null'));
active_date.setSeconds(active_date.getSeconds() + minute);
if (active_date < current_date && erLogin) {
D3Api.globalClientData.set('erLogin');
}
D3Api.globalClientData.set('erActivate');
}
};
this.erExit = function () {
var erLogin = JSON.parse(D3Api.globalClientData.get('erLogin', 'null'));
D3Api.globalClientData.set('erLogin');
if (erLogin) {
window.open('webservice/er/logout' + D3ER.locationSearch(), '_self');
} else {
D3ER.erHome();
}
};
};