"use strict"; /** * mplus_safety_bleeding */ var mplus_safety_bleeding = function() { // 상속 mplus_common.call(this); //super var self = this; var curPage = ""; var testId = localStorage.getItem("initLoginDtTm"); console.log(testId); //==== 변수 { ==== var varResultLists = []; var patientInfo = []; /* Fatima 전역 변수 */ var specimenSearchCls = 0; // 실시조회 및 취소조회 검색 조건(실시 = 0, 취소 = 1) var gActSpecimenType = "Y"; // 실시조회 및 취소조회 검색 조건(처리 = Y, 취소 = C) var checkBoxArr = []; // checkBox 선택된 list를 따로 배열로 이동 /* Fatima 전역 변수 */ //==== 변수 } ==== /** * 초기화 */ this.init = function() { //여기서 모든화면 콤보박스데이터를 집어넣자!!! 그래야지 화면이동할때 속도가 오래걸리지않음!!! localStorage.removeItem("defaultHomePage"); localStorage.setItem("defaultHomePage", "bleeding"); // 초기 화면 조건 구성 initCondition(); // 이벤트 초기화 addEvent(); // 환자 검색 실행 및 환자 정보 화면 출력 //searchPatient(); $("#txtBleedingPatientSearch").focus(); }; this.barcodeCallback = function(data){ console.log("barcode read! inside bleeding.js"); // null 이라면 반환 if(self.util.isEmpty(data)){ return; } else{ var result = self.util.decodeBarcode(data); } if(self.util.isEmpty(result) || result.type == 'errBarcode'){ $("#txtBleedingPatientSearch").blur(); // if(result === null || result === undefined || result.type == 'errBarcode'){ $("#alertBarcodeCheck").modal("show"); return; } // 환자 번호라면 else if(result.type == 'pid'){ $("#txtBleedingPatientSearch").blur(); // 최초 리딩 시 환자 정보 초기화 $("#txtBleedingPatientSearch").val(''); var patientId = result.data; $("#txtBleedingPatientSearch").val(patientId); if (gActSpecimenType == "Y") { $("#btnBleedingList").removeClass().addClass("btn btn-primary btn-block"); $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block"); $("#btnCancleList").removeClass().addClass("btn btn-secondary btn-block"); $("#btnBleedingAct").text("채혈 실시"); } else { $("#btnBleedingList").removeClass().addClass("btn btn-secondary btn-block"); $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block"); $("#btnCancleList").removeClass().addClass("btn btn-councel btn-block"); $("#btnBleedingAct").text("채혈 취소"); } getPocPatientInfo(patientId, false); } // 채혈 번호라면 else if(result.type == 'specimenCd'){ $("#txtBleedingPatientSearch").blur(); if(self.util.isEmpty(patientInfo) || patientInfo.length == 0){ $("#alertEmptyPatient").modal("show"); return; } // 3 번째를 barcode //varResultLists var foundCnt = 0; for(var idx = 0; idx < varResultLists.length; idx++){ if(varResultLists[idx].mainSpecimenCd == result.data){ console.log("label[for='checkBleedingSel" + idx + "']"); var labelObj = $("label[for='checkBleedingSel" + idx + "']"); labelObj.attr('class', 'btn btn-barcode icon'); var iptObj = $('input:checkbox[id="checkBleedingSel' + idx + '"]'); iptObj.prop('checked', true); var li = $('li[id="listGroupItem_' + idx + '"]'); li.addClass("active"); foundCnt++; } } if(foundCnt == 0){ $('#alertSpecimen').modal('show'); } } else{ $("#txtBleedingPatientSearch").blur(); $("#alertBarcodeCheck").modal("show"); } }; //==== 초기화 설정 { ==== var initCondition = function() { // 초기 화면 조건 구성 //환자정보 초기화 initPatientInfo(); }; /** * 환자 정보 초기화 */ var initPatientInfo = function() { $(".patient-name").text("환자명"); $(".patient-gender-age").text("성별/나이"); $(".patient-birthDt").text("생년월일"); $("#patientInfo").text("성별/나이"); $(".dept-name").text("실시부서"); $(".user-name").text("실시자명"); $(".user-code").text("(사원번호)"); $(".patient-name button").attr("style", "display: none"); }; /** * 리스트 초기화 */ var initList = function() { $("#bleedingListGroup").empty(); $("#barcodeGroup").attr("style", "display: ;"); } /** * 채혈실시 초기화 및 체크된 데이터 배열에 담음 */ var initactSpecimen = function() { console.log('initactSpecimen'); checkBoxArr = []; //CheckBoxLength 초기화 // actSpecimenLength = 0; //처방번호 체크 for (var fCnt = 0; fCnt < varResultLists.length; fCnt++) { if ($("#checkBleedingSel" + fCnt).is(":checked")) { // checkBoxArr.push(varResultLists[fCnt]); checkBoxArr[fCnt] = varResultLists[fCnt]; // actSpecimenLength++; } } actSpecimen(); // console.log("checkBoxArr -- > " + JSON.stringify(checkBoxArr)); // // for (var key in checkBoxArr) { // console.log("key -- > " + key); // } //eventMakeBarcodeCondition(); }; /** * 환자정보 요청 * @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) { patientInfo = []; // 반환받은 데이터가 Null 일 경우 Alert if(self.util.isEmpty(lists) || lists.length == 0){ initPatientInfo(); initList(); $("#txtBleedingPatientSearch").blur(); $("#alertSuccess .modal-body h4").text("환자정보 조회 실패"); $("#alertSuccess .modal-body p").text("환자정보 조회에 실패하였습니다"); $("#alertSuccess").modal("show"); return; } // 입력받은 환자번호와 반환 데이터의 환자번호가 일치하는 경우 if (barPid == lists[0].patientId) { patientInfo = lists; $(".patient-name").text(lists[0].patientNm); $("#patientInfo").text(lists[0].age + "/" + lists[0].gender + " " + lists[0].roomNm + "호"); $("#todayDate").text("현재 날짜 : " + moment(new Date()).format("YYYY-MM-DD")); $(".patient-birthDt").text(lists[0].birthDt); $(".dept-name").text(localStorage.getItem("selectedDeptNm")); $(".user-name").text(gLoginUserNm); $(".user-code").text("(" + gLoginUserId + ")"); $(".patient-name").append(""); var summaryCd = lists[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 = "" $("#patientInfo").append(spanTag); } getSpecimenList(false); // 환자 정보가 일치하지 않는 경우 } else { // 첫 번째 호출인 경우 if (!isSecondTrial) { getPocPatientInfo(barPid, true) // 두 번째 호출인 경우 } else { initPatientInfo(); initList(); $("#txtBleedingPatientSearch").blur(); $("#alertSuccess .modal-body h4").text("환자정보 조회 실패"); $("#alertSuccess .modal-body p").text("시스템 이용량이 많습니다. 다시 조회해 주세요."); $("#alertSuccess").modal("show"); } } }; /** * 채혈 정보 호출 * @param {*} isSecondTrial 두 번째 호출 여부 */ var getSpecimenList = function(isSecondTrial) { var param = { hospitalCd: "", userId: gLoginUserId, patientId: patientInfo[0].patientId, specimenSearchCls: specimenSearchCls, isSecondTrial: isSecondTrial }; self.safety.getSpecimenList(param, isSecondTrial, processGetSpecimenList); }; /** * * @param {*} isSecondTrial 두 번째 호출 여부 * @param {*} lists API 반환 데이터 */ var processGetSpecimenList = function(isSecondTrial, lists){ checkBoxArr = []; varResultLists = []; var strDisplayTemp = ""; $("#bleedingListGroup").empty(); // 반환되는 데이터가 Null 인 경우 if(self.util.isEmpty(lists) || lists.length == 0){ // $("#alertEmptyPatient .modal-body h4").text("검체정보 조회"); // $("#alertEmptyPatient .modal-body p").text("조회된 검체정보가 없습니다."); // $("#alertEmptyPatient").modal("show"); return; } // 기존의 환자정보와 반환 데이터의 환자정보가 일치하는 경우 if (patientInfo[0].patientId == lists[0].patientId) { varResultLists = lists; $("#barcodeGroup").attr("style", "display: none;"); for( var i = 0; i < lists.length; i++){ strDisplayTemp += "
  • " + "
    " + "
    " + "

    " + lists[i].specimenCd + "

    " + "

    " + lists[i].specimenNm + "

    " + "
    " + "
    " + "" + "
    " + "" + "" + "
    " + "
    " + "
  • "; } $("#bleedingListGroup").append(strDisplayTemp); eventMakeCondition(); // 환자정보가 일치하지 않는 경우 } else { // 첫 번째 호출인 경우 if (!isSecondTrial) { getSpecimenList(true) // 두 번째 호출인 경우 } else { $("#alertEmptyPatient .modal-body h4").text("채혈정보 조회 오류"); $("#alertEmptyPatient .modal-body p").text("시스템 이용량이 많습니다. 다시 조회해 주세요."); $("#alertEmptyPatient").modal("show"); } } }; // 채혈실시 var actSpecimen = function() { if (checkBoxArr.length == 0) { $("#alertSuccess .modal-body h4").text("실시할 채혈 정보가 없습니다."); $("#alertSuccess .modal-body p").text(inputCnt + "실시할 채혈 정보를 선택해주세요."); $("#alertSuccess").modal("show"); } else { var cnt = 0; var count = 0; for (var key in checkBoxArr) { cnt = cnt + 1; } for (var key in checkBoxArr) { var hospitalCd = localStorage.getItem("hospitalCd"); // 병원코드 var userId = gLoginUserId; // 사용자 ID var specimenCd = checkBoxArr[key].specimenCd; // 검체바코드 번호 var specimenNm = checkBoxArr[key].specimenNm; // 검체명 var actSpecimenType = gActSpecimenType; // 검체처리구분(처리 : Y, 취소 : C) var actSpecimenDtTm = moment(new Date).format("YYYYMMDDHHMM"); // 검체처리일시 var actType = ""; // 처리구분 (POC, EMR) var checkedItem = $("label[name=checkedItem" + key + "]"); if (checkedItem.hasClass("btn-barcode")) { actType = "POC"; } else { actType = "EMR"; } var param = { hospitalCd : hospitalCd , userId : userId , specimenCd : specimenCd , specimenNm : specimenNm , actSpecimenType : actSpecimenType, actSpecimenDtTm : actSpecimenDtTm, actType : "POC" , actTypeCheck : actType }; var result = self.safety.actSpecimen(param); count = count + 1; if (result != "") { if (cnt == count) { var succMsg = ""; var failMsg = ""; if (result == "failed") { if (gActSpecimenType == "Y") { failMsg = "채혈실시에 오류가 발생하였습니다."; } else { failMsg = "채혈취소에 오류가 발생하였습니다."; } alert(failMsg); } else { if (gActSpecimenType == "Y") { succMsg = "채혈실시가 처리되었습니다."; } else { succMsg = "채혈취소가 처리되었습니다."; } alert(succMsg); } getPocPatientInfo($("#txtBleedingPatientSearch").val(), false); } } } } }; var cnt = 0; var outputAr = []; var processActSpecimen = function(output, size, key) { console.log("processActSpecimen -- > " + JSON.stringify(output)); console.log("processActSpecimen -- > " + size); console.log("processActSpecimen -- > " + key); var param = {output, key}; outputAr.push(param); if (size == outputAr.length) { var errorFlag = false; for (var i = 0; i < outputAr.length; i++) { console.log("output[i] -- > " + outputAr[i].output); if (outputAr[i].output == "0001") { errorFlag = true; } } var succMsg = ""; var failMsg = ""; if (gActSpecimenType == "Y") { succMsg = "채혈실시가 처리되었습니다."; failMsg = "채혈실시에 오류가 발생하였습니다."; } else { succMsg = "채혈취소가 처리되었습니다."; failMsg = "채혈취소에 오류가 발생하였습니다."; } if (errorFlag == true) { alert(failMsg); } else { alert(succMsg); } outputAr = []; getPocPatientInfo($("#txtBleedingPatientSearch").val(), false); } }; // 버튼 색상 및 글자 초기화 var initButtonSetting = function() { $("#btnBleedingList").removeClass().addClass("btn btn-secondary btn-block"); $("#btnCancleList").removeClass().addClass("btn btn-secondary btn-block"); $("#btnBleedingAct").removeClass().addClass("btn btn-secondary btn-block"); $("#btnBleedingAct").text("실시/취소"); } //==== 초기화 설정 } ==== //==== 이벤트 설정 { ==== var addEvent = function() { eventCondition(); eventBackBlock(); }; //검색 페이지 뒤로가기 막기 var eventBackBlock = function() { $(window).off("pageshow"); $(window).bind("pageshow", function(event) { if (event.originalEvent.persisted) { document.location.reload(); } }); }; var eventCondition = function() { // 실시 조회 이벤트 처리 $("#btnBleedingList").off("click"); $("#btnBleedingList").on("click", function() { $(this).blur(); var searchTxt = $("#txtBleedingPatientSearch").val(); if (searchTxt == "") { $("#alertEmptyText").modal("show"); } else { specimenSearchCls = 0; gActSpecimenType = "Y"; //버튼 색상 변경 $("#btnBleedingList").removeClass().addClass("btn btn-primary btn-block"); $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block"); $("#btnCancleList").removeClass().addClass("btn btn-secondary btn-block"); $("#btnBleedingAct").text("채혈 실시"); // initPatientInfo(); getPocPatientInfo(searchTxt, false); } }); // 취소 조회 이벤트 처리 $("#btnCancleList").off("click"); $("#btnCancleList").on("click", function() { $(this).blur(); var searchTxt = $("#txtBleedingPatientSearch").val(); if (searchTxt == "") { $("#alertEmptyText").modal("show"); } else { specimenSearchCls = 1; gActSpecimenType = "C"; //버튼 색상 변경 $("#btnBleedingList").removeClass().addClass("btn btn-secondary btn-block"); $("#btnBleedingAct").removeClass().addClass("btn btn-danger btn-block"); $("#btnCancleList").removeClass().addClass("btn btn-councel btn-block"); $("#btnBleedingAct").text("채혈 취소"); // initPatientInfo(); getPocPatientInfo(searchTxt, false); } }); // 실시/취소 버튼 $("#btnBleedingAct").off("click"); $("#btnBleedingAct").on("click", function() { $(this).blur(); if ($("input:checkbox[class=checkClassBleedingSel]:checked").length <= 0) { $("#alertEmptySpecimen").modal("show"); } else { initactSpecimen(); } }); }; // 바코드 검색 $("#btnBarcodeSearch").off("click"); $("#btnBarcodeSearch").on("click", function() { $("#txtBleedingNumberSearchTxt").val(""); readBarcode("number"); }); /* * 체크박스 상태 변경 * 체크박스 체크 선택 시 Background 추가 * * 바코드 리딩 체크박스 해제시 원래 체크박스 클래스로 바꿔줌 */ var eventMakeCondition = function() { $("#bleedingListGroup li input").off("click"); $("#bleedingListGroup li input").on("click", function() { var li = $(this).parent().parent().parent(); // listGroupItem_ + i var id = li.attr("id"); var rowNo = id.split('_')[1]; var checkBox = $("#checkBleedingSel" + rowNo); var firstLabel = checkBox.parent().children().children().eq(0); var secondLabel = checkBox.parent().children().children().eq(1); if (checkBox.is(":checked") == true) { li.toggleClass("active"); console.log(checkBox.is(":checked")); } else { li.toggleClass("active"); firstLabel.attr("class", "btn btn-check icon"); secondLabel.attr("class", "btn btn-outline-check icon"); } }); }; }