"use strict"; /** * mplus_medicine */ var mplus_medicine = function() { // 상속 mplus_common.call(this); var self = this; var patientData = []; var medicineList = []; var medicineSelectItem = []; var myTimer; var actTypeCheck = "EMR"; this.init = function() { //여기서 모든화면 콤보박스데이터를 집어넣자!!! 그래야지 화면이동할때 속도가 오래걸리지않음!!! // 접근 권한 체크 localStorage.removeItem("defaultHomePage"); localStorage.setItem("defaultHomePage", "medicine"); checkAccessPermission(); // 초기 화면 조건 구성 initCondition(); // 이벤트 초기화 addEvent(); // 환자 검색 실행 및 환자 정보 화면 출력 //searchPatient(); // $("#txtPatientId").focus(); //gLoginUserId //gLoginUserNm }; //==== 접근 권한 체크 { ==== var checkAccessPermission = function() { //if( !self.common.checkAccessJobKind( "1000")){ // self.alertTrue("접근 권한이 없습니다.", self.common.gotoDefaultHomePage); //} //if( !self.common.checkAccessUserAuth( "01")){ // self.alertTrue("접근 권한이 없습니다.", self.common.gotoDefaultHomePage); //} //self.common.disableElements( $("#myModalBtn")); }; //==== 접근 권한 체크 } ==== //==== 초기화 설정 { ==== var initCondition = function() { // 초기 화면 조건 구성 //환자정보 초기화 initPatientInfo(); StartTimer(); // 콤보박스 시간 Setting actionHourSetting(); // 콤보박스 시간 Setting var strCurDate = self.util.toDate(new Date()); $("#spanDate").text(strCurDate); $("#todayDate").text(strCurDate); }; /** * 콤보박스 시간과 분을 세팅 */ function actionHourSetting() { var today = new Date(); var todayHH = today.getHours(); var todayMM = today.getMinutes(); if (todayHH < 10) { todayHH = "0" + todayHH } if (todayMM < 10) { todayMM = "0" + todayMM } var time = ""; var value = ""; // SelectBox Hour Setting for (var i = 0; i < 24; i++) { if (i < 10) { value = "0" + i; } else { value = i; } time += ""; } $("#actionHour").empty(); $("#actionHour").append(time); $("#actionHour").val(todayHH); $("#actionHour").off("focus"); // SelectBox Minute Setting time = ""; for (var i = 0; i < 60; i++) { if (i < 10) { value = "0" + i; } else { value = i; } time += " "; } $("#actionMinute").empty(); $("#actionMinute").append(time); $("#actionMinute").val(todayMM); $("#actionMinute").off("focus"); }; function StartTimer() { clearInterval(myTimer); myTimer = setInterval(actingTimer ,1000); } function ClearTimer() { clearInterval(myTimer); } var actingTimer = function() { var today = new Date(); var todayHH = today.getHours(); var todayMM = today.getMinutes(); if (todayHH < 10) { todayHH = "0" + todayHH } if (todayMM < 10) { todayMM = "0" + todayMM } if (String(todayHH) + String(todayMM) > $("#actionHour").val() + $("#actionMinute").val(todayMM)) { $("#actionMinute").val(todayMM); $("#actionHour").val(todayHH); } }; /** * 환자 정보 초기화 */ var initPatientInfo = function() { $("#txtPatientId").val(""); $("#patientName").text("환자명"); $("#patientName button").attr("style", "display: none"); $("#patient-gender-age").text("환자정보"); $("#spanWard").text("실시부서"); $("#spanAcrionUserName").text("실시자명 (사번)"); }; /** * 리스트 초기화 */ function emptyMedicine() { $("#listItem").remove(); $("#divScanMsg").attr("style", "display: ;"); StartTimer(); } //==== 이벤트 설정 { ==== var addEvent = function() { // 컬럼 클릭의 정렬 이벤트 // eventColumnClick(); // // eventRowClick(); // eventCondition(); medicineActionEvent(); eventBackBlock(); // // eventBackBlock(); }; //검색 페이지 뒤로가기 막기 var eventBackBlock = function(){ $(window).off("backbutton"); $(window).bind("backbutton", function(event) { alert("clickable true"); if (event.originalEvent.persisted) { document.location.reload(); } }); }; this.barcodeCallback = function(data){ if(data.includes("PO@") == true){ var tempData = data.split("@"); var param = { hospitalCd: localStorage.getItem("hospitalCd"), AtcBarCodeData: tempData[1], }; self.safety.getAtcPrescriptionList(param, processGetAtcPrescriptionList); return; } var result = self.util.decodeBarcode(data); if(self.util.isEmpty(result)){ // modal 호출 emptyData("정보조회에 실패하였습니다.", "다시 시도해주세요."); return; } else if(result.type == 'pid'){ // 환자 바코드 스캔 var patientId = result.data; $("#txtPatientId").val(patientId); getPocPatientInfo(patientId, false); $("#txtPatientId").blur(); } else if(result.type == 'medicine'){ $("#txtPatientId").blur(); if(self.util.isEmpty(patientData) || patientData.length == 0){ emptyData('환자정보가 조회되지 않았습니다.', '환자정보를 조회하여 주세요'); return; } // 단일 투약 스캔 var aaa = [result.data]; barCodeMedicineListToggle(aaa); } // poBarcode else if (result.type == "poBarcode") { $("#txtPatientId").blur(); if(self.util.isEmpty(patientData) || patientData.length == 0){ emptyData('환자정보가 조회되지 않았습니다.', '환자정보를 조회하여 주세요'); return; } var spanDate = $("#spanDate").text().trim().split("-"); var dateStr = spanDate[0] + spanDate[1] + spanDate[2]; var dataList = new Array(); result.data.forEach(barData =>{ if(barData.date.toString() == dateStr){ dataList.push(barData.item); } }); // 투약 리스트 스캔 console.log("origndataList -- > " + dataList); barCodeMedicineListToggle(dataList); } else if (result.type == "medicineList") { if (self.util.isEmpty(result.data)) { emptyData('투약실시 바코드가 아닙니다.', '바코드를 다시 확인해주세요'); } else { barCodeMedicineListToggle(result.data); } } else{ $("#txtPatientId").blur(); emptyData('투약실시 바코드가 아닙니다.', '바코드를 다시 확인해주세요'); // $("#Modal01").modal("show"); } // // null 이라면 반환 // if(self.util.isEmpty(data)){ // return; // } // else{ // var result = self.util.decodeBarcode(data); // } // // // 환자 번호라면 // if(result.type == 'pid'){ // // 최초 리딩 시 환자 정보 초기화 // $("#txtBleedingPatientSearch").val(''); // // console.log('data: ' + result.data); // // 환자번호 표시 // $("#txtBleedingPatientSearch").val(result.data); // // 환자 정보 호출 // var param = { // hospitalCd: localStorage.getItem("hospitalCd"), // userId: gLoginUserId, // patientId: $("#txtBleedingPatientSearch").val() // }; // // self.medical.getPatientInfo(param, processGetPatientInfo); // } // // 투약 번호라면 // else if(result.type == 'specimenCd'){ // // } }; var processGetAtcPrescriptionList = function(output) { console.log("output -- > " + output); if(self.util.isEmpty(output)){ // modal 호출 emptyData("정보조회에 실패하였습니다.", "다시 시도해주세요."); return; } $("#txtPatientId").blur(); if(self.util.isEmpty(patientData) || patientData.length == 0){ emptyData('환자정보가 조회되지 않았습니다.', '환자정보를 조회하여 주세요'); return; } var outputTempData = output[0].prescriptionData.slice(0, -1); var outputData = outputTempData.split("*"); console.log("outputData -- > " + outputData); var dataList = new Array(); for (var i = 0; i < outputData.length; i++) { var result = self.util.decodeBarcode(outputData[i]); console.log("result -- > " + JSON.stringify(result)); if (result.type == "poBarcode") { var spanDate = $("#spanDate").text().trim().split("-"); var dateStr = spanDate[0] + spanDate[1] + spanDate[2]; result.data.forEach(barData =>{ if(barData.date.toString() == dateStr){ console.log("barData -- > " + barData.item); dataList.push(barData.item); } }); } } // 투약 리스트 스캔 console.log("dataList -- > " + dataList); barCodeMedicineListToggle(dataList); // for (var i = 0; i < output.length; i++) { // var result = self.util.decodeBarcode(output[i].prescriptionData); // console.log("result -- > " + JSON.stringify(result)); // if (result.type == "poBarcode") { // var spanDate = $("#spanDate").text().trim().split("-"); // var dateStr = spanDate[0] + spanDate[1] + spanDate[2]; // result.data.forEach(barData =>{ // if(barData.date.toString() == dateStr){ // dataList.push(barData.item); // } // }); // } } var eventCondition = function() { //투약일자 현재의 전 날짜를 가져온다 $("#dateMinus").off("click"); $("#dateMinus").on("click", function() { $(this).blur(); $("#spanDate").text(minusDate()); $("#medicineSearchBtn").click(); }); //투약일자 현재 이후 날짜를 가져온다 단 현재일 보다 커질 수 없다 $("#datePlus").off("click"); $("#datePlus").on("click", function() { $(this).blur(); var changeDate = plusDate(); if (changeDate == "") { } else { $("#spanDate").text(changeDate); $("#medicineSearchBtn").click(); } }); /** * 조회 버튼 클릭 이벤트 */ $("#medicineSearchBtn").off("click"); $("#medicineSearchBtn").on("click", function() { $(this).blur(); var txtSearch = $("#txtPatientId").val(); if (txtSearch == "") { $("#Modal01 .modal-body h4").text("입력된 환자번호가 없습니다."); $("#Modal01 .modal-body p").text("환자번호를 입력해주세요."); $("#Modal01").modal("show"); } else { // $("#medicineSearchBtn").removeClass("btn-secondary").addClass("btn-primary"); getPocPatientInfo($("#txtPatientId").val(), false); } }); }; $("#actionHour").change(function() { $("#actionHour option:selected").each(function() { ClearTimer(); var today = new Date(); var todayHH = today.getHours(); var todayMM = today.getMinutes(); // patientData[0].dschYn = "Y"; if (todayHH < 10) { todayHH = "0" + todayHH } if (todayMM < 10) { todayMM = "0" + todayMM } var nowActTime = String(todayHH) + String(todayMM); var selectHourValue = String($("#actionHour option:selected").val()); var nowMinVal = String($("#actionMinute").val()); if (selectHourValue + nowMinVal > nowActTime) { if (patientData.length > 0 && patientData[0].dschYn == "Y") { $("#actionHour").val(selectHourValue); } else { emptyData("시간변경 오류", "현재시간 이후로는 변경할 수 없습니다"); $("#actionMinute").val(todayMM); $("#actionHour").val(todayHH); } } }); }); $("#actionMinute").change(function() { $("#actionMinute option:selected").each(function() { ClearTimer(); var today = new Date(); var todayHH = today.getHours(); var todayMM = today.getMinutes(); // patientData[0].dschYn = "Y"; if (todayHH < 10) { todayHH = "0" + todayHH } if (todayMM < 10) { todayMM = "0" + todayMM } var nowActTime = String(todayHH) + String(todayMM); var selectMinValue = String($("#actionMinute option:selected").val()); var nowHourVal = String($("#actionHour").val()); if (nowHourVal + selectMinValue > nowActTime) { if (patientData.length > 0 && patientData[0].dschYn == "Y") { $("#actionMinute").val(selectMinValue); } else { emptyData("시간변경 오류", "현재시간 이후로는 변경할 수 없습니다"); $("#actionMinute").val(todayMM); $("#actionHour").val(todayHH); } } }); }); /** * 환자 조회 * @param {*} patientId 입력받은 환자번호 * @param {*} isSecondTrial 두 번째 호출 여부 */ var getPocPatientInfo = function(patientId, isSecondTrial) { var param = { hospitalCd: localStorage.getItem("hospitalCd"), userId: gLoginUserId, patientId: patientId, isSecondTrial: isSecondTrial }; self.safety.getPocPatientInfo(param, patientId, isSecondTrial, processGetPocPatientInfo); }; /** * 호출된 기본정보를 화면에 매핑 * @param {*} lists API 반환 데이터 * @param {*} barPid 입력받은 환자번호 * @param {*} isSecondTrial 두 번째 호출 여부 */ var processGetPocPatientInfo = function(lists, barPid, isSecondTrial) { patientData = []; actionHourSetting(); if (lists == "undefined" || lists == null || lists.length == 0) { $("#txtPatientId").val(''); $("#txtPatientId").blur(); initPatientInfo(); emptyMedicine(); emptyData("환자정보 조회 실패", "환자정보 조회에 실패하였습니다."); return; } // 1. 만일 환자 정보가 맞다면 환자 정보를 보여준다. if (barPid == lists[0].patientId) { patientData = lists; $("#patientName").text(patientData[0].patientNm); $("#patient-gender-age").text(patientData[0].age + "/" + patientData[0].gender + " " + patientData[0].roomNm + "호"); $("#spanWard").text(localStorage.getItem("selectedDeptNm")); $("#spanAcrionUserName").text(gLoginUserNm + "(" + gLoginUserId + ")"); $("#patientName").append(""); var summaryCd = patientData[0].patientSummaryCd.split(","); var spanTag = ""; for (var i = 0; i < summaryCd.length; i++) { var sCd = summaryCd[i]; if (sCd == "!") { sCd = "t"; } else if (sCd == "₩") { sCd = "w"; } spanTag = "" $("#patient-gender-age").append(spanTag); } // getPrescriptionList(lists, ""); getPrescriptionList(false); // 2. 환자 정보가 맞지 않으면 } else { // 2.1 2번째 호출이 아니면 다시 환자 정보 조회 if (!isSecondTrial) { getPocPatientInfo(barPid, true) // 2.2 2번째 호출이면 Alert } else { initPatientInfo(); emptyMedicine(); emptyData("환자정보 조회 실패", "시스템 이용량이 많습니다. 다시 조회해 주세요."); } } } /** * * @param {*} isSecondTrial 두 번째 호출 여부 */ var getPrescriptionList = function(isSecondTrial) { var medicationDt = $("#spanDate").text().split("-"); var inDd = patientData[0].inDd; var param = { hospitalCd : patientData[0].hospitalCd, userId : gLoginUserId, patientId : patientData[0].patientId, medicationDt : medicationDt[0]+medicationDt[1]+medicationDt[2], inDd : inDd, cretNo : patientData[0].cretNo, isSecondTrial: isSecondTrial } self.safety.getPrescriptionList(param, isSecondTrial, processGetPrescriptionList); } /** * * @param {*} isSecondTrial 두 번째 호출 여부 * @param {*} result API 반환 데이터 */ var processGetPrescriptionList = function(isSecondTrial, result) { medicineList = []; medicineSelectItem = []; console.log("result -- > " + JSON.stringify(result)); $("#listItem").empty(); // $("#listItem").remove(); // 반환되는 데이터가 Null 일 경우 if(self.util.isEmpty(result) || result.length == 0){ $("#divScanMsg").css("display", ""); // return emptyData("처방정보 조회", "조회된 처방정보가 없습니다."); return; } // 기존 환자정보와 반환 데이터 환자정보가 일치할 경우 if (patientData[0].patientId == result[0].patientId) { for (var i = 0; i < result.length; i++) { if (result[i].flag == "N") { medicineList.push(result[i]); } } if (medicineList.length == 0) { $("#divScanMsg").css("display", ""); return emptyData("처방정보 조회", "조회된 처방정보가 없습니다."); } // medicineList = result; $("#divScanMsg").attr("style", "display: none"); $("#con").append("
" + " " + frontAct + ":" + medicineList[i].actMedicationTm.substring(2, 4) // 투여시간 hh:mm + " " + "
" + "" + " " + medicineList[i].prcpCd // 처방코드 + " " + "
" + "" + medicineList[i].prescriptionNo // 처방 번호 + "
" + "" + medicineList[i].prcpNm // 처방명 + "
" + "" + " " + medicineList[i].prescriptionCapaDay + medicineList[i].prescriptionCapaDayUnit // 1일 용량 + 1일 용량 단위 + " " + " |" + medicineList[i].prescriptionTmDay // 일일 횟수 + " |" + medicineList[i].actMedicationInfo // 용법 + "
" + "" + " " + frontAct + ":" + medicineObj.actMedicationTm.substring(2, 4) // 투여시간 hh:mm + " " + "
" + "" + " " + medicineObj.prcpCd // 처방코드 + " " + "
" + "" + medicineObj.prescriptionNo // 처방 번호 + "
" + "" + medicineObj.prescriptionTypeNm // 처방종류명 (경구, 주사, 마약, 수액) + "
" + "" + medicineObj.prcpNm // 처방명 + "
" + "" + " " + medicineObj.prescriptionCapaDay + medicineObj.prescriptionCapaDayUnit // 1일 용량 + 1일 용량 단위 + " " + " |" + medicineObj.prescriptionTmDay // 일일 횟수 + " |" + medicineObj.actMedicationInfo // 용법 + "
" + "