"use strict";
/**
 * mplus_safety_bloodManagement
 * 수혈 탭으로 변경 예정 -- jmRyu
 */
var mplus_safety_bloodManagement = function(){
    // 상속
    mplus_common.call(this);

    // 상위 객체 생성
    //var mplusPatient = new mplus_mobile_patient();
    //var mplusNursing = new mplus_nursing();

    //super
    var self = this;

    //==== 변수 { ====
    // column 정렬의 토글 상태 제어용 : 0: not selected, 1:오름차순, 2:내림차순
    var varToggleCol1 = 0;
    var varToggleCol2 = 0;
    var varToggleCol3 = 0;
    var varToggleCol4 = 0;
    var varToggleCol5 = 0;
    var varToggleCol6 = 0;
    var varToggleCol7 = 0;
    var varToggleCol8 = 0;

    var varResultLists = [];

    var varSearchCls = "OP";// 조회구분(I:입원, O:외래, E:응급, OP:수술, T:시술, C:협진)

    var varSearchDateGap = 2;	// 날짜검색 간격
    var varPationNumLength = 8;
    // TODO : 환자정보에 혈액정보 넣어야함 테스트용으로 변수로 처리
    var pationBloodGroup = "";

    //투약번호 Length처리
    //단일 한건처리로 1로 초기화
    var inputBloodManagementLength = 1;

    //==== 변수 } ====

    /**
     * 초기화
     */
    this.init = function(){ //여기서 모든화면 콤보박스데이터를 집어넣자!!! 그래야지 화면이동할때 속도가 오래걸리지않음!!!
        // 접근 권한 체크
        checkAccessPermission();

        // 초기 화면 조건 구성
        initCondition();

        // 이벤트 초기화
        addEvent();

        // 환자 검색 실행 및 환자 정보 화면 출력
        //searchPatient();

        $("#txtBloodManagementPatientSearchTxt").focus();
    };

    //==== 접근 권한 체크 { ====
    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();

        //환자번호 길이 제한
        //$("#txtBloodManagementPatientSearchTxt").prop("maxLength" , varPationNumLength);

        // 종료 날짜를 현재 날짜로 등록
        var varCurDate = new Date();
        var strCurDate = self.util.toDate( new Date());
        $("#dateBloodManagementEndDt").val( strCurDate);

        // 시작 날짜를 날짜 검색 간격 전 날짜를 등록
        var var2DaysAgo = varCurDate;
        var2DaysAgo.setDate( varCurDate.getDate() - varSearchDateGap);
        var str2DaysAgo = self.util.toDate( var2DaysAgo);
        //$("#dateOppatientStartDt").val( str2DaysAgo);
        $("#dateBloodManagementStartDt").val( str2DaysAgo);

    };

    //환자 정보 초기화
    var initPatientInfo = function(){
        //$("#divResultRows").empty();

        //수혈 실행 버튼
        $("#btnInputBloodManagementAct").attr("disabled" , true);

        $(".modal-patient-name").text("-");
        $(".modal-patient-id").text("-");
        $(".modal-patient-age-gender").text("-");
        $(".modal-patient-treat-cls").text("-");

    };

    //수혈실시 초기화
    /*
    var initInputBloodManagement = function(){
        $("#bloodManagementActionNum").empty();
        //CheckBoxLength 초기화
        inputBloodManagementLength = 0;
        //처방번호 체크
        for(var fCnt = 0 ; fCnt < varResultLists.length ; fCnt++){
            if($("#checkBloodManagementSel" + fCnt).is(":checked")){
                var tempSpan = "<p>"
                    + "<span id=\"spanInputBloodManagementNum" + inputBloodManagementLength +"\" style=\"color:red;\">" + varResultLists[fCnt].col6 + "</span>"
                    + "&nbsp;&nbsp;<button type=\"button\" name=\"button\" class=\"btn btn-primary classBtnInPutActBarcode\" btnLength=\"" + inputBloodManagementLength + "\" id=\"btnInPutActBarcode" + inputBloodManagementLength + "\" style=\"color: #ffffff;background: #0067a1;text-align: center;\">"
                    + "<span style=\"color:white;\">⊙</span>"
                    + "</button><p/>";
                $("#bloodManagementActionNum").append(tempSpan);
                inputBloodManagementLength++;
            }
        }
        eventMakeBarcodeCondition();
    };
    */

    // 환자정보 요청
    var getPatientInfo = function(){
        var param = {
            userId: $("#txtBloodManagementPatientSearchTxt").val(),
            patientId: "",
            receiptNo: "",
            treatCls: "I"
        };
        self.medical.getPatientInfo(param, processGetPatientInfo);
    };

    // 수혈 목록을 처리
    var processGetPatientInfo = function( lists){

        $(".modal-patient-name").text(lists[0].patientNm);
        $(".modal-patient-id").text(lists[0].patientId);
        $(".modal-patient-age-gender").text(lists[0].age + " / " + lists[0].gender);
        $(".modal-patient-treat-cls").text("입원");
        pationBloodGroup = lists[0].bloodGroup;

        switchGetBloodManagementList($("#sltBloodManagementCd").val());
    };

    //화면별 분기 처리
    //데이터 조회 분기
    var switchGetBloodManagementList = function(mode){
        var param;
        switch (mode) {
            case "1" :
                //혈액신청리스트
                param = {
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                };
                self.safety.getBloodRequestList(param, processGetBloodRequestList);
                break;
            case "2" :
                //혈액수령리스트
                param = {
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                };
                self.safety.getBloodReceiveList(param, processGetBloodReceiveList);
                break;
            case "3" :
                //수혈확인리스트
                param = {
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                };
                self.safety.getBloodCheckList(param, processGetBloodCheckList);
                break;
            case "4" :
                //혈액반납리스트
                param = {
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                };
                self.safety.getBloodCancelList(param, processGetBloodCancelList);
                break;
            default:
                return;

        }
    };

    //혈액신청리스트
    var processGetBloodRequestList = function(lists){
        varResultLists = lists;
        var strDisplayTemp = "";
        $("#divResultRows").empty();
        if( lists.length == 0){
            strDisplayTemp = "<div class=\"row text-center\" style=\"line-height: 60px; vertical-align: middle;\"> 검색 결과가 없습니다. </div>"
                + "<div style=\"height: 55vh;\"></div>";
        }
        for( var i = 0; i < lists.length; i++){

            strDisplayTemp += "<div class=\"chart-content well\">"
                + "  <div class=\"row patient-row\" rowNo=\"" + i  + "\">"
                + "    <div class=\"col-xs-12\">"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col1 + "</div>"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col2 + "</div>"
                + "      <div class=\"col-xs-4 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col3 + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col4 + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + moment(lists[i].col5).format("MM-DD") + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col6 + "</div>"
                + "    </div>"
                + "</div>"
                + "</div>";
            //console.log( i + " : " + lists[i].patientId + " : " + lists[i].patientNm);
        }

        $("#divResultRows").append(strDisplayTemp);	// element 추가
        eventRowClick();
    };

    //혈액수령리스트
    var processGetBloodReceiveList = function(lists){
        varResultLists = lists;
        var strDisplayTemp = "";
        $("#divResultRows").empty();
        if( lists.length == 0){
            strDisplayTemp = "<div class=\"row text-center\" style=\"line-height: 60px; vertical-align: middle;\"> 검색 결과가 없습니다. </div>"
                + "<div style=\"height: 55vh;\"></div>";
        }
        for( var i = 0; i < lists.length; i++){

            strDisplayTemp += "<div class=\"chart-content well\">"
                + "  <div class=\"row patient-row\" rowNo=\"" + i  + "\">"
                + "    <div class=\"col-xs-12\">"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col1 + "</div>"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col2 + "</div>"
                + "      <div class=\"col-xs-4 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col3 + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col4 + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + moment(lists[i].col5).format("MM-DD") + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col6 + "</div>"
                + "    </div>"
                + "</div>"
                + "</div>";
            //console.log( i + " : " + lists[i].patientId + " : " + lists[i].patientNm);
        }

        $("#divResultRows").append(strDisplayTemp);	// element 추가
        eventRowClick();
    };

    //수혈확인리스트
    var processGetBloodCheckList = function(lists){
        varResultLists = lists;
        var strDisplayTemp = "";
        $("#divResultRows").empty();
        if( lists.length == 0){
            strDisplayTemp = "<div class=\"row text-center\" style=\"line-height: 60px; vertical-align: middle;\"> 검색 결과가 없습니다. </div>"
                + "<div style=\"height: 55vh;\"></div>";
        }
        for( var i = 0; i < lists.length; i++){

            strDisplayTemp += "<div class=\"chart-content well\">"
                + "  <div class=\"row patient-row\" rowNo=\"" + i  + "\">"
                + "    <div class=\"col-xs-12\">"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col1 + "</div>"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col2 + "</div>"
                + "      <div class=\"col-xs-4 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col3 + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col4 + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + moment(lists[i].col5).format("MM-DD") + "</div>"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col6 + "</div>"
                + "    </div>"
                + "</div>"
                + "</div>";
            //console.log( i + " : " + lists[i].patientId + " : " + lists[i].patientNm);
        }

        $("#divResultRows").append(strDisplayTemp);	// element 추가
        eventRowClick();
    };

    //혈액반납리스트
    var processGetBloodCancelList = function(lists){
        varResultLists = lists;
        var strDisplayTemp = "";
        $("#divResultRows").empty();
        if( lists.length == 0){
            strDisplayTemp = "<div class=\"row text-center\" style=\"line-height: 60px; vertical-align: middle;\"> 검색 결과가 없습니다. </div>"
                + "<div style=\"height: 55vh;\"></div>";
        }
        for( var i = 0; i < lists.length; i++){

            strDisplayTemp += "<div class=\"chart-content well\">"
                + "  <div class=\"row patient-row\" rowNo=\"" + i  + "\">"
                + "    <div class=\"col-xs-12\">"
                + "      <div class=\"col-xs-2 text-center\" style=\"padding:0px;word-break: break-word;\">" + moment(lists[i].col1).format("MM-DD") + "</div>"
                + "      <div class=\"col-xs-4 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col2 + "</div>"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col3 + "</div>"
                + "      <div class=\"col-xs-4 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col4 + "</div>"
                + "      <div class=\"col-xs-1 text-center\" style=\"padding:0px;word-break: break-word;\">" + lists[i].col5 + "</div>"
                + "    </div>"
                + "</div>"
                + "</div>";
            //console.log( i + " : " + lists[i].patientId + " : " + lists[i].patientNm);
        }

        $("#divResultRows").append(strDisplayTemp);	// element 추가
        eventRowClick();
    };

    // 투약실시
    var switchInputBloodManagement = function(mode){
        var params = {param: []};
        switch (mode) {
            case "1" :
                //혈액신청리스트
                params.param.push({
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                });
                self.safety.inputBloodRequest(params, processInputBloodManagement);
                break;
            case "2" :
                //혈액수령리스트
                params.param.push({
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                });
                self.safety.inputBloodReceive(params, processInputBloodManagement);
                break;
            case "3" :
                //수혈확인리스트
                params.param.push({
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                });
                self.safety.inputBloodCheck(params, processInputBloodManagement);
                break;
            case "4" :
                //혈액반납리스트
                params.param.push({
                    userId: "",
                    patientId: "",
                    receiptNo: "",
                    treatCls: ""
                });
                self.safety.inputBloodCancel(params, processInputBloodManagement);
                break;
            default:
                return;

        }
    };

    var processInputBloodManagement = function(lists){
        if(lists != undefined && lists.length > 0){
            var inputCnt = 0;
            for(var fCnt = 0 ; fCnt < lists.length ; fCnt++){
                if(lists[fCnt].returnCd == "0000"){
                    inputCnt++;
                }
            }
            self.alert(inputCnt + "건 처리되었습니다.");
            //데이터 초기화
            $("#mplusAlertBloodManagementAction").modal("hide");
            initPatientInfo();
            getPatientInfo();
        }else{
            self.alert("처리중 오류가 발생했습니다.");
        }
    };

    var changeResultHeader = function(mode){
        //초기화
        //투약 실행 버튼
        $("#btnInputBloodManagementAct").attr("disabled" , true);
        //inputBloodManagementLength = 0;
        varResultLists = [];

        $("#divResultHeaderInfo").empty();

        var resultHeaderInfo = "";

        switch (mode) {
            case "1" :
                //혈액신청리스트
                resultHeaderInfo =
                    "<div id=\"divResultHeaderColumn1\" class=\"col-xs-1 text-center\">ABO<p/>Rh</div>" +
                    "<div id=\"divResultHeaderColumn2\" class=\"col-xs-1 text-center\">IPO<span id=\"spanSortColumn2\"></span></div>" +
                    "<div id=\"divResultHeaderColumn3\" class=\"col-xs-4 text-center\">성분제제<span id=\"spanSortColumn3\"></span></div>" +
                    "<div id=\"divResultHeaderColumn4\" class=\"col-xs-2 text-center\">처방량<p/>(ml)<span id=\"spanSortColumn4\"></span></div>" +
                    "<div id=\"divResultHeaderColumn5\" class=\"col-xs-2 text-center\">처방일<span id=\"spanSortColumn5\"></span></div>" +
                    "<div id=\"divResultHeaderColumn6\" class=\"col-xs-2 text-center\">신청가능<p/>수량<span id=\"spanSortColumn6\"></span></div>";
                $("#divResultHeaderInfo").append(resultHeaderInfo);
                break;
            case "2" :
                //혈액수령리스트
                resultHeaderInfo =
                    "<div id=\"divResultHeaderColumn1\" class=\"col-xs-1 text-center\">ABO<p/>Rh</div>" +
                    "<div id=\"divResultHeaderColumn2\" class=\"col-xs-1 text-center\">IPO<span id=\"spanSortColumn2\"></span></div>" +
                    "<div id=\"divResultHeaderColumn3\" class=\"col-xs-4 text-center\">성분제제<span id=\"spanSortColumn3\"></span></div>" +
                    "<div id=\"divResultHeaderColumn4\" class=\"col-xs-2 text-center\">처방량<p/>(ml)<span id=\"spanSortColumn4\"></span></div>" +
                    "<div id=\"divResultHeaderColumn5\" class=\"col-xs-2 text-center\">처방일<span id=\"spanSortColumn5\"></span></div>" +
                    "<div id=\"divResultHeaderColumn6\" class=\"col-xs-2 text-center\">신청<p/>수량<span id=\"spanSortColumn6\"></span></div>";
                $("#divResultHeaderInfo").append(resultHeaderInfo);
                break;
            case "3" :
                //수혈확인리스트
                resultHeaderInfo =
                    "<div id=\"divResultHeaderColumn1\" class=\"col-xs-1 text-center\">ABO<p/>Rh</div>" +
                    "<div id=\"divResultHeaderColumn2\" class=\"col-xs-1 text-center\">IPO<span id=\"spanSortColumn2\"></span></div>" +
                    "<div id=\"divResultHeaderColumn3\" class=\"col-xs-4 text-center\">성분제제<span id=\"spanSortColumn3\"></span></div>" +
                    "<div id=\"divResultHeaderColumn4\" class=\"col-xs-2 text-center\">처방량<p/>(ml)<span id=\"spanSortColumn4\"></span></div>" +
                    "<div id=\"divResultHeaderColumn5\" class=\"col-xs-2 text-center\">처방일<span id=\"spanSortColumn5\"></span></div>" +
                    "<div id=\"divResultHeaderColumn6\" class=\"col-xs-2 text-center\">처방의<span id=\"spanSortColumn6\"></span></div>";
                $("#divResultHeaderInfo").append(resultHeaderInfo);
                break;
            case "4" :
                //혈액반납리스트
                resultHeaderInfo =
                    "<div id=\"divResultHeaderColumn1\" class=\"col-xs-2 text-center\">출고일자</div>" +
                    "<div id=\"divResultHeaderColumn2\" class=\"col-xs-4 text-center\">혈액번호<span id=\"spanSortColumn2\"></span></div>" +
                    "<div id=\"divResultHeaderColumn3\" class=\"col-xs-1 text-center\">항변<span id=\"spanSortColumn3\"></span></div>" +
                    "<div id=\"divResultHeaderColumn4\" class=\"col-xs-4 text-center\">성분제제<span id=\"spanSortColumn4\"></span></div>" +
                    "<div id=\"divResultHeaderColumn5\" class=\"col-xs-1 text-center\">수령<p/>여부<span id=\"spanSortColumn5\"></span></div>";
                $("#divResultHeaderInfo").append(resultHeaderInfo);
                break;
            default:
                return;

        }
    };

    var checkInputBloodManagementData = function(mode){
        return false;
        switch (mode) {
            case "1":
                return true;
                break;
            case "2":

                break;
            case "3":

                break;
            case "4":

                break;
            default :
                return;
        }

        if($("#dateBloodManagementActionDate").val() == ""){
            self.alert("투약일을 입력해주세요.");
            return false;
        } else if($("#dateBloodManagementActionTime").val()  == "") {
            self.alert("투약시간을 입력해주세요.");
            return false;
        }

        //바코드 체크
        var btnInPutActBarcodeCheck = false;
        for(var fCnt = 0 ; fCnt < inputBloodManagementLength ; fCnt++){
            //console.log("TEST : " + $("#btnInPutActBarcode" + fCnt).is("[disabled]"));
            if(!$("#btnInPutActBarcode" + fCnt).is("[disabled]")){
                btnInPutActBarcodeCheck = true;
            }
        }
        if(btnInPutActBarcodeCheck){
            self.alert("투약번호 바코드를 확인해주세요.");
            return false;
        }

        return true;
    };

    var settingSetInputBloodManagement = function(){
        $("#dateBloodManagementActionDate").val(moment(new Date()).format("YYYY-MM-DD"));
        $("#dateBloodManagementActionTime").val(moment(new Date()).format("HH:mm:ss"));
    };

    /*
    var checkBarcodeNum = function(barcodeNum){
        for(var fCnt = 0 ; fCnt < inputBloodManagementLength ; fCnt++){
            if(barcodeNum == $("#spanInputBloodManagementNum" + fCnt).text()){
                $("#spanInputBloodManagementNum" + fCnt).css("color" , "blue");
                $("#btnInPutActBarcode" + fCnt).attr("disabled" , true);
            }
        }
    };
    */

    //==== 초기화 설정 } ====

    //==== 이벤트 설정 { ====
    var addEvent = function(){
        // 컬럼 클릭의 정렬 이벤트
        eventColumnClick();

        eventCondition();

        eventBackBlock();
    };

    // 20190228 shinsunwoo 환자의 바코드 추출 toNative 호출
    var readBarcode = function(barMode){
        var callbackFn = "window.activeObj.readBarcodeCallBack";
        if(barMode == "search"){
            callbackFn = "window.activeObj.readBarcodeCallBack";
        }else if(barMode == "check"){
            callbackFn = "window.activeObj.readBarcodeCallBackCheck";
        }else{
            callbackFn = "window.activeObj.readBarcodeCallBack";
        }
        console.log('call readBarcode');
        var msg = {
            type : "command",
            functionType : "readBarcode",
            value : {
                callbackFn : callbackFn
            }
        };
        self.toNative( msg );
    };

    // 20190228 shinsunwoo 환자의 바코드 추출 callback 처리
    this.readBarcodeCallBack = function( returnCode){
        var results = new Object();
        if( typeof returnCode === "string" ){
            results = self.util.parseJson( returnCode );
        } else {
            results = returnCode;
        }

        if( results.success != undefined && results.success == "true" ) {
            console.log("readBarcode : success");
            console.log( results.result);
            $("#txtBloodManagementPatientSearchTxt").val(results.result)
            getPatientInfo();
        } else {
            console.log("readBarcode : failed");
            self.alert( "readBarcode APP function 호출 오류 " );
        }
    };

    this.readBarcodeCallBackCheck = function( returnCode){
        var results = new Object();
        if( typeof returnCode === "string" ){
            results = self.util.parseJson( returnCode );
        } else {
            results = returnCode;
        }

        if( results.success != undefined && results.success == "true" ) {
            console.log("readBarcode : success");
            console.log( results.result);
            checkBarcodeNum(results.result);

        } else {
            console.log("readBarcode : failed");
            self.alert( "readBarcode APP function 호출 오류 " );
        }
    };

    this.deviceBarcodeCallBackCheck = function( returnCode){
        var results = new Object();
        if( typeof returnCode === "string" ){
            results = self.util.parseJson( returnCode );
        } else {
            results = returnCode;
        }

        if( results.success != undefined && results.success == "true" ) {
            console.log("readBarcode : success");
            console.log( results.result);
            checkBarcodeNum(results.result);

        } else {
            console.log("readBarcode : failed");
            self.alert( "readBarcode APP function 호출 오류 " );
        }
    };

    //검색 페이지 뒤로가기 막기
    var eventBackBlock = function(){
        $(window).off("pageshow");
        $(window).bind("pageshow", function(event) {
            if (event.originalEvent.persisted) {
                document.location.reload();
            }
        });
    };

    var eventColumnClick = function(){
        /*
        $("#divResultHeaderColumn1").off("click");
        $("#divResultHeaderColumn1").on("click", function(){
            //alert("column1 clicked!!");
            sortColumn( 1, "patientId");
        });

        $("#divResultHeaderColumn2").off("click");
        $("#divResultHeaderColumn2").on("click", function(){
            //alert("column2 clicked!!");
            sortColumn( 2, "patientNm");
        });

        $("#divResultHeaderColumn3").off("click");
        $("#divResultHeaderColumn3").on("click", function(){
            //alert("column3 clicked!!");
            sortColumn( 3, "roomNm");
        });

        $("#divResultHeaderColumn4").off("click");
        $("#divResultHeaderColumn4").on("click", function(){
            //alert("column4 clicked!!");
            sortColumn( 4, "age");
        });

        $("#divResultHeaderColumn5").off("click");
        $("#divResultHeaderColumn5").on("click", function(){
            //alert("column5 clicked!!");
            sortColumn( 5, "operationDt");
        });

        $("#divResultHeaderColumn6").off("click");
        $("#divResultHeaderColumn6").on("click", function(){
            //alert("column6 clicked!!");
            sortColumn( 6, "anesthesiaTy");
        });

        $("#divResultHeaderColumn7").off("click");
        $("#divResultHeaderColumn7").on("click", function(){
            //alert("column7 clicked!!");
            sortColumn( 7, "deptNm");
        });

        $("#divResultHeaderColumn8").off("click");
        $("#divResultHeaderColumn8").on("click", function(){
            //alert("column8 clicked!!");
            sortColumn( 8, "operationStatNm");
        });
        */
    };

    var eventRowClick = function(){
        // 환자 선택 이벤트 처리
        $("#divResultRows .patient-row").off("click"); // 기존 이벤트 해제
        $("#divResultRows .patient-row").on("click", function(e){
            var rowCnt = e.currentTarget.attributes.rowNo.value;
            switchCallModal($("#sltBloodManagementCd").val() , rowCnt);
            switchModalInit($("#sltBloodManagementCd").val() , rowCnt);
        });
    };

    var switchCallModal = function(mode , listCnt){
        //바코드 초기화
        $("#bloodRequestActionNum").empty();
        $("#bloodReceiveActionNum").empty();
        $("#bloodCheckActionNum").empty();
        $("#bloodCancelActionNum").empty();

        var spanBarID = "";

        switch (mode) {
            case "1":
                //init
                $("#bloodRequestActionNum").text(varResultLists[listCnt].col11);
                $("#dataBloodRequestGroup").text(varResultLists[listCnt].col1);
                $("#dataBloodRequestConstituent").text(varResultLists[listCnt].col3);
                $("#dataBloodRequestQuantity").empty();
                for(var fCnt = 1 ; fCnt <= Number(varResultLists[listCnt].col6) ; fCnt++){
                    var appendTemp = "<option var=\"" +fCnt+ "\">"+fCnt+"</option>";
                    $("#dataBloodRequestQuantity").append(appendTemp);
                }
                //dataBloodRequestQuantity
                $("#mplusAlertBloodRequestAction").modal("show");
                break;
            case "2":
                var tempSpan = ""
                    //+ "<span id=\"spanInputBloodReceive0\" style=\"color:red;\">" + varResultLists[listCnt].col11 + "</span>"
                    + "<div class=\"col-xs-8\" style=\"padding: 0;\"><input id=\"inputBloodReceive\" class=\"form-control bloodReceiveNum\"></div>"
                    + "<div class=\"col-xs-4\" style=\"padding: 0;\"><button type=\"button\" name=\"button\" class=\"btn btn-primary classBtnInPutActBarcode\" btnLength=\"0\" id=\"btnInPutActBarcode0\" style=\"color: #ffffff;background: #0067a1;text-align: center;\">"
                    + "<span style=\"color:white;\">X</span>"
                    + "</button></div>";
                $("#bloodReceiveActionNum").append(tempSpan);
                //spanBarID = "spanInputBloodReceive";
                //eventMakeBarcodeCondition(spanBarID);
                $("#dateBloodReceiveActionDate").val(moment(new Date()).format("YYYY-MM-DD"));
                $("#dateBloodReceiveActionTime").val(moment(new Date()).format("HH:mm:ss"));
                $("#dataBloodReceiveConstituent").text(varResultLists[listCnt].col3);
                $("#dataBloodReceiveABO").text(varResultLists[listCnt].col1);
                $("#dataBloodReceiveIPO").text(varResultLists[listCnt].col2);
                $("#dataBloodReceiveQuantity").text(varResultLists[listCnt].col6);

                $("#mplusAlertBloodReceiveAction").modal("show");
                break;
            case "3":
                //console.log("varResultLists : " + JSON.stringify(varResultLists[listCnt]));
                var tempSpan = ""
                    //+ "<span id=\"spanInputBloodCheck0\" style=\"color:red;\">" + varResultLists[listCnt].col11 + "</span>"
                    + "<div class=\"col-xs-8\" style=\"padding: 0;\"><input id=\"inputBloodCheck\" class=\"form-control bloodReceiveNum\"></div>"
                    + "<div class=\"col-xs-4\" style=\"padding: 0;\"><button type=\"button\" name=\"button\" class=\"btn btn-primary classBtnInPutActBarcode\" btnLength=\"0\" id=\"btnInPutActBarcode0\" style=\"color: #ffffff;background: #0067a1;text-align: center;\">"
                    + "<span style=\"color:white;\">X</span>"
                    + "</button></div>";
                $("#bloodCheckActionNum").append(tempSpan);
                //spanBarID = "spanInputBloodCheck";
                //eventMakeBarcodeCondition(spanBarID);
                $("#dateBloodCheckActionDate").val(moment(new Date()).format("YYYY-MM-DD"));
                $("#dataBloodCheckConstituent").text(varResultLists[listCnt].col3);
                $("#dataBloodCheckABO").text(varResultLists[listCnt].col1);
                $("#dataBloodCheckIPO").text(varResultLists[listCnt].col2);
                $("#dataBloodCheckQuantity").text(varResultLists[listCnt].col4);
                //$("#bloodCheckActionDoc").text(varResultLists[listCnt].col6);
                //$("#bloodCheckActionUser").text(varResultLists[listCnt].col10);

                $("#inputBloodCheckActionDoc").prop("placeholder" , varResultLists[listCnt].col6);
                $("#inputBloodCheckActionUser").prop("placeholder" , varResultLists[listCnt].col10);

                $("#mplusAlertBloodCheckAction").modal("show");
                break;
            case "4":
                var tempSpan = ""
                    //+ "<span id=\"spanInputBloodCancel0\" style=\"color:red;\">" + varResultLists[listCnt].col10 + "</span>"
                    + "<div class=\"col-xs-8\" style=\"padding: 0;\"><input id=\"inputBloodCancel\" class=\"form-control bloodReceiveNum\"></div>"
                    + "<div class=\"col-xs-4\" style=\"padding: 0;\"><button type=\"button\" name=\"button\" class=\"btn btn-primary classBtnInPutActBarcode\" btnLength=\"0\" id=\"btnInPutActBarcode0\" style=\"color: #ffffff;background: #0067a1;text-align: center;\">"
                    + "<span style=\"color:white;\">X</span>"
                    + "</button></div>";
                $("#bloodCancelActionNum").append(tempSpan);
                //spanBarID = "spanInputBloodCancel";
                //eventMakeBarcodeCondition(spanBarID);

                $("#dateBloodCancelOutDate").val(moment(varResultLists[listCnt].col1).format("YYYY-MM-DD"));
                $("#dateBloodCancelActionDate").val(moment(new Date()).format("YYYY-MM-DD"));
                $("#dataBloodCancelConstituent").text(varResultLists[listCnt].col4);
                //$("#bloodCancelActionUser").text(varResultLists[listCnt].col9);
                $("#inputBloodCancelActionUser").prop("placeholder" , varResultLists[listCnt].col9);

                $("#mplusAlertBloodCancelAction").modal("show");
                break;
            default :
                return;
        }


    };

    var switchModalInit = function(mode , listCnt){
        switch(mode){
            case "1":

                break;
            case "2":
                $("#inputBloodReceive").prop("placeholder" , varResultLists[listCnt].col11);
                $("#inputBloodReceive").off("keydown");
                $("#inputBloodReceive").on("keydown" , function(e){
                    if (e.keyCode == 13 && varResultLists.length != 0) {
                        if(varResultLists[listCnt].col11 != $(this).val()){
                            $("#btnInPutActBarcode0").text("X");
                            $(this).val("");
                            $(this).focus();
                            self.alert("혈액번호를 확인해주세요.");
                            return;
                        }
                        $("#btnInPutActBarcode0").text("O");
                        $(this).prop("disabled" , true);
                    }
                });
                $("#inputBloodReceive").focus();
                break;
            case "3":
                $("#inputBloodCheck").prop("placeholder" , varResultLists[listCnt].col11);
                $("#inputBloodCheck").off("keydown");
                $("#inputBloodCheck").on("keydown" , function(e){
                    if (e.keyCode == 13 && varResultLists.length != 0) {
                        if(varResultLists[listCnt].col11 != $(this).val()){
                            $("#btnInPutActBarcode0").text("X");
                            $(this).val("");
                            $(this).focus();
                            self.alert("혈액번호를 확인해주세요.");
                            return;
                        }
                        $("#btnInPutActBarcode0").text("O");
                        $(this).prop("disabled" , true);
                        $("#inputBloodCheckActionDoc").focus();
                    }
                });
                $("#inputBloodCheckActionDoc").off("keydown");
                $("#inputBloodCheckActionDoc").on("keydown" , function(e){
                    if (e.keyCode == 13 && varResultLists.length != 0) {
                        if(varResultLists[listCnt].col6 != $(this).val()){
                            $("#btnBloodCheckActionDoc").text("X");
                            $(this).val("");
                            $(this).focus();
                            self.alert("의사번호를 확인해주세요.");
                            return;
                        }
                        $("#btnBloodCheckActionDoc").text("O");
                        $(this).prop("disabled" , true);
                        $("#inputBloodCheckActionUser").focus();
                    }
                });
                $("#inputBloodCheckActionUser").off("keydown");
                $("#inputBloodCheckActionUser").on("keydown" , function(e){
                    if (e.keyCode == 13 && varResultLists.length != 0) {
                        if(varResultLists[listCnt].col10 != $(this).val()){
                            $("#btnBloodCheckActionUser").text("X");
                            $(this).val("");
                            $(this).focus();
                            self.alert("의료진번호를 확인해주세요.");
                            return;
                        }
                        $("#btnBloodCheckActionUser").text("O");
                        $(this).prop("disabled" , true);
                    }
                });
                $("#inputBloodCheck").focus();
                break;
            case "4":
                $("#inputBloodCancel").prop("placeholder" , varResultLists[listCnt].col10);
                $("#inputBloodCancel").off("keydown");
                $("#inputBloodCancel").on("keydown" , function(e){
                    if (e.keyCode == 13 && varResultLists.length != 0) {
                        if(varResultLists[listCnt].col10 != $(this).val()){
                            $("#btnInPutActBarcode0").text("X");
                            $(this).val("");
                            $(this).focus();
                            self.alert("혈액번호를 확인해주세요.");
                            return;
                        }
                        $("#btnInPutActBarcode0").text("O");
                        $(this).prop("disabled" , true);
                        $("#inputBloodCancelActionUser").focus();
                    }
                });
                $("#inputBloodCancelActionUser").off("keydown");
                $("#inputBloodCancelActionUser").on("keydown" , function(e){
                    if (e.keyCode == 13 && varResultLists.length != 0) {
                        if(varResultLists[listCnt].col9 != $(this).val()){
                            $("#btnBloodCancelActionUser").text("X");
                            $(this).val("");
                            $(this).focus();
                            self.alert("의사번호를 확인해주세요.");
                            return;
                        }
                        $("#btnBloodCancelActionUser").text("O");
                        $(this).prop("disabled" , true);
                    }
                });
                $("#inputBloodCancel").focus();
                break;
            default:
                return;
        }
    }

    var switchCheckBarcodeNum = function(mode , barcodeNum){
        var spanID = "";
        switch(mode){
            case "1":
                spanID = "spanInputBloodRequest";
                break;
            case "2":
                spanID = "spanInputBloodReceive";
                break;
            case "3":
                spanID = "spanInputBloodCheck";
                break;
            case "4":
                spanID = "spanInputBloodCancel";
                break;
            default:
                return;

        }

        for(var fCnt = 0 ; fCnt <  inputBloodManagementLength ; fCnt++){
            if(barcodeNum == $("#" + spanID + fCnt).text()){
                $("#" + spanID + fCnt).css("color" , "blue");
                $("#btnInPutActBarcode" + fCnt).attr("disabled" , true);
            }
        }
    };
    
    var switchCheckInputFocus = function(mode){
        var spanID = "";
        switch(mode){
            case "1":
                break;
            case "2":
            	if($("#inputBloodReceive").is(":disabled") == false){
            		$("#inputBloodReceive").focus();
            	}
                break;
            case "3":
            	if($("#inputBloodCheck").is(":disabled") == false){
            		$("#inputBloodCheck").focus();
            	}else if($("#inputBloodCheckActionDoc").is(":disabled") == false){
            		$("#inputBloodCheckActionDoc").focus();
            	}else if($("#inputBloodCheckActionUser").is(":disabled") == false){
            		$("#inputBloodCheckActionUser").focus();
            	}
                break;
            case "4":
            	if($("#inputBloodCancel").is(":disabled") == false){
            		$("#inputBloodCancel").focus();
            	}else if($("#inputBloodCancelActionUser").is(":disabled") == false){
            		$("#inputBloodCancelActionUser").focus();
            	}
                break;
            default:
                return;

        }
    };

    var eventCondition = function(){

        ///////////////////////////////////////////////////////////////////////////////// 2019.09.04 추가 Start

        //데이터 전체길이 입력시 검색
        $("#txtBloodManagementPatientSearchTxt").off("keydown");
        $("#txtBloodManagementPatientSearchTxt").on("keydown" , function(e){
            if (e.keyCode == 13 && $("#txtBloodManagementPatientSearchTxt").val().length != 0) {
                initPatientInfo();
                getPatientInfo();
            }else if(e.keyCode == 13 && $("#txtBloodManagementPatientSearchTxt").val().length == 0){
                self.alert("환자번호를 입력해주세요.");
                $("#txtBloodManagementPatientSearchTxt").focus();
            }
        });

        //포커스 초기화
        $("#txtBloodManagementPatientSearchTxt").off("focus");
        $("#txtBloodManagementPatientSearchTxt").on("focus" , function(){
            $(this).val("");
        });
        
        $("#mplusAlert").off("hidden.bs.modal");
        $("#mplusAlert").on("hidden.bs.modal", function () {
        	switchCheckInputFocus($("#sltBloodManagementCd").val());
        });

        ///////////////////////////////////////////////////////////////////////////////// 2019.09.04 추가 End


        // 환자 조회 이벤트 처리
        $("#btnBloodManagementSearch").off("click");
        $("#btnBloodManagementSearch").on("click", function(){
            var searchTxt = $("#txtBloodManagementPatientSearchTxt").val();
            if(searchTxt == ""){
                self.alert("환자번호를 입력해주세요.");
                return;
            }
            initPatientInfo();
            getPatientInfo();
        });

        // 바코드 검색
        $("#btnBarcodeSearch").off("click");
        $("#btnBarcodeSearch").on("click", function(){
            $("#txtBloodManagementPatientSearchTxt").val("");
            readBarcode("search");
        });

        // 투약처리
        /*
        $("#btnInputBloodManagementAct").off("click");
        $("#btnInputBloodManagementAct").on("click", function(){
            initInputBloodManagement();
            settingSetInputBloodManagement();
            $("#mplusAlertBloodManagementAction").modal("show");
        });
        */

        // 투약실시 선택
        $("#checkBloodManagementAll").off("change");
        $("#checkBloodManagementAll").on("change", function(){
            if($("#checkBloodManagementAll").is(":checked")){
                $(".checkClassBloodManagementSel").prop("checked" , true);
                $(".checkClassBloodManagementSel").trigger("change");
            }else{
                $(".checkClassBloodManagementSel").prop("checked" , false);
                $(".checkClassBloodManagementSel").trigger("change");
            }
        });

        //mode변경
        $("#sltBloodManagementCd").off("change");
        $("#sltBloodManagementCd").on("change", function(){
            $("#divResultRows").empty();
            changeResultHeader($("#sltBloodManagementCd").val());

            var searchTxt = $("#txtBloodManagementPatientSearchTxt").val();
            if(searchTxt != ""){
                switchGetBloodManagementList($("#sltBloodManagementCd").val());
                return;
            }

        });

        // 혈액신청
        $("#btnBloodRequestAct").off("click");
        $("#btnBloodRequestAct").on("click", function(){
            //TEST
            $("#mplusAlertBloodRequestAction").modal("hide");
            self.alert("혈액신청되었습니다.");
            return;

            switchInputBloodManagement($("#sltBloodManagementCd").val());
        });
        // 취소
        $("#btnBloodRequestCancel").off("click");
        $("#btnBloodRequestCancel").on("click", function(){
            $("#mplusAlertBloodRequestAction").modal("hide");
        });

        // 혈액확인
        $("#btnBBloodReceiveAct").off("click");
        $("#btnBBloodReceiveAct").on("click", function(){

            if($("#btnInPutActBarcode0").text() == "O"){
                //TEST
                $("#mplusAlertBloodReceiveAction").modal("hide");
                self.alert("혈액확인되었습니다.");
                return;

                switchInputBloodManagement($("#sltBloodManagementCd").val());
            }else{
                self.alert("혈액번호를 확인해주세요.");
            }
        });
        // 취소
        $("#btnBloodReceiveCancel").off("click");
        $("#btnBloodReceiveCancel").on("click", function(){
            $("#mplusAlertBloodReceiveAction").modal("hide");
        });

        // 수혈확인
        $("#btnBloodCheckAct").off("click");
        $("#btnBloodCheckAct").on("click", function(){
            //TEST
            $("#mplusAlertBloodCheckAction").modal("hide");
            self.alert("수혈확인되었습니다.");
            return;

            if(checkInputBloodManagementData()){
                switchInputBloodManagement($("#sltBloodManagementCd").val());
            }
        });
        // 취소
        $("#btnBloodCheckCancel").off("click");
        $("#btnBloodCheckCancel").on("click", function(){
            $("#mplusAlertBloodCheckAction").modal("hide");
        });

        // 혈액반환
        $("#btnBloodCancelAct").off("click");
        $("#btnBloodCancelAct").on("click", function(){
            //TEST
            $("#mplusAlertBloodCancelAction").modal("hide");
            self.alert("혈액반환되었습니다.");
            return;

            if(checkInputBloodManagementData()){
                switchInputBloodManagement($("#sltBloodManagementCd").val());
            }
        });
        // 취소
        $("#btnBloodCancelCancel").off("click");
        $("#btnBloodCancelCancel").on("click", function(){
            $("#mplusAlertBloodCancelAction").modal("hide");
        });
    };

    var eventMakeCondition = function() {
        /*
        $(".checkClassBloodManagementSel").off("change");
        $(".checkClassBloodManagementSel").on("change", function(){
            var checkSelected = false;
            for(var fCnt = 0 ; fCnt < varResultLists.length ; fCnt++){
                if($("#checkBloodManagementSel" + fCnt).is(":checked")){
                    checkSelected = true;
                    break;
                }
            }

            if(checkSelected){
                $("#btnInputBloodManagementAct").attr("disabled" , false);
            }else{
                $("#btnInputBloodManagementAct").attr("disabled" , true);
            }

        });*/

        //div 선택 이벤트


    };

    var eventMakeBarcodeCondition = function(spanInputID) {
        $(".classBtnInPutActBarcode").off("click");
        $(".classBtnInPutActBarcode").on("click", function(){
            //readBarcode("check");
            console.log("classBtnInPutActBarcode click!");
            //TEST 삭제
            for(var fCnt = 0 ; fCnt < inputBloodManagementLength ; fCnt++){
                switchCheckBarcodeNum($("#sltBloodManagementCd").val() , $("#" + spanInputID +fCnt).text());
            }
        });
    };



    //==== 이벤트 설정 } ====

    //==== 환자 정보 조회 처리 { ====

    //==== 환자 정보 조회 처리 } ====

    //==== 컬럼 정렬 프로세스 { ====
    // 컬럼 상태를 초기화 처리
    var initColumnStatus = function(){
        varToggleCol1 = 0;
        varToggleCol2 = 0;
        varToggleCol3 = 0;
        varToggleCol4 = 0;
        varToggleCol5 = 0;
        varToggleCol6 = 0;
        varToggleCol7 = 0;
        varToggleCol8 = 0;

        // 컬럼 정렬 아이콘 초기화 :  ▼ ▲
        $("#spanSortColumn1").text("");
        $("#spanSortColumn2").text("");
        $("#spanSortColumn3").text("");
        $("#spanSortColumn4").text("");
        $("#spanSortColumn5").text("");
        $("#spanSortColumn6").text("");
        $("#spanSortColumn7").text("");
        $("#spanSortColumn8").text("");
    };

    // 컬럼 상태를 설정(정렬 조건 적용)
    var setColumnStatus = function( columnNo){

        // 클릭된 column의 현재 상태를 백업
        var copyToggleStatus = 0;
        if( columnNo == 1)
            copyToggleStatus = varToggleCol1;
        else if( columnNo == 2)
            copyToggleStatus = varToggleCol2;
        else if( columnNo == 3)
            copyToggleStatus = varToggleCol3;
        else if( columnNo == 4)
            copyToggleStatus = varToggleCol4;
        else if( columnNo == 5)
            copyToggleStatus = varToggleCol5;
        else if( columnNo == 6)
            copyToggleStatus = varToggleCol6;
        else if( columnNo == 7)
            copyToggleStatus = varToggleCol7;
        else if( columnNo == 8)
            copyToggleStatus = varToggleCol8;

        // column 상태를 초기화
        initColumnStatus();

        // 클릭된 column의 백업된 상태에서 한단계 진핸된 상태로 변경
        if( columnNo == 1)
            copyToggleStatus == 0 ? varToggleCol1 = 1 : copyToggleStatus == 1 ? varToggleCol1 = 2 : varToggleCol1 = 1;
        else if( columnNo == 2)
            copyToggleStatus == 0 ? varToggleCol2 = 1 : copyToggleStatus == 1 ? varToggleCol2 = 2 : varToggleCol2 = 1;
        else if( columnNo == 3)
            copyToggleStatus == 0 ? varToggleCol3 = 1 : copyToggleStatus == 1 ? varToggleCol3 = 2 : varToggleCol3 = 1;
        else if( columnNo == 4)
            copyToggleStatus == 0 ? varToggleCol4 = 1 : copyToggleStatus == 1 ? varToggleCol4 = 2 : varToggleCol4 = 1;
        else if( columnNo == 5)
            copyToggleStatus == 0 ? varToggleCol5 = 1 : copyToggleStatus == 1 ? varToggleCol5 = 2 : varToggleCol5 = 1;
        else if( columnNo == 6)
            copyToggleStatus == 0 ? varToggleCol6 = 1 : copyToggleStatus == 1 ? varToggleCol6 = 2 : varToggleCol6 = 1;
        else if( columnNo == 7)
            copyToggleStatus == 0 ? varToggleCol7 = 1 : copyToggleStatus == 1 ? varToggleCol7 = 2 : varToggleCol7 = 1;
        else if( columnNo == 8)
            copyToggleStatus == 0 ? varToggleCol8 = 1 : copyToggleStatus == 1 ? varToggleCol8 = 2 : varToggleCol8 = 1;

        // 정렬 상태 화면에 그리기
        varToggleCol1 == 1 ? $("#spanSortColumn1").text("▲") : varToggleCol1 == 2 ? $("#spanSortColumn1").text("▼") : $("#spanSortColumn1").text("");
        varToggleCol2 == 1 ? $("#spanSortColumn2").text("▲") : varToggleCol2 == 2 ? $("#spanSortColumn2").text("▼") : $("#spanSortColumn2").text("");
        varToggleCol3 == 1 ? $("#spanSortColumn3").text("▲") : varToggleCol3 == 2 ? $("#spanSortColumn3").text("▼") : $("#spanSortColumn3").text("");
        varToggleCol4 == 1 ? $("#spanSortColumn4").text("▲") : varToggleCol4 == 2 ? $("#spanSortColumn4").text("▼") : $("#spanSortColumn4").text("");
        varToggleCol5 == 1 ? $("#spanSortColumn5").text("▲") : varToggleCol5 == 2 ? $("#spanSortColumn5").text("▼") : $("#spanSortColumn5").text("");
        varToggleCol6 == 1 ? $("#spanSortColumn6").text("▲") : varToggleCol6 == 2 ? $("#spanSortColumn6").text("▼") : $("#spanSortColumn6").text("");
        varToggleCol7 == 1 ? $("#spanSortColumn7").text("▲") : varToggleCol7 == 2 ? $("#spanSortColumn7").text("▼") : $("#spanSortColumn7").text("");
        varToggleCol8 == 1 ? $("#spanSortColumn8").text("▲") : varToggleCol8 == 2 ? $("#spanSortColumn8").text("▼") : $("#spanSortColumn8").text("");
    };

    // 컬럼 상태를 조회(정렬 조건 적용)
    var getColumnStatus = function( columnNo){
        if( columnNo == 1)
            return varToggleCol1;
        else if( columnNo == 2)
            return varToggleCol2;
        else if( columnNo == 3)
            return varToggleCol3;
        else if( columnNo == 4)
            return varToggleCol4;
        else if( columnNo == 5)
            return varToggleCol5;
        else if( columnNo == 6)
            return varToggleCol6;
        else if( columnNo == 7)
            return varToggleCol7;
        else if( columnNo == 8)
            return varToggleCol8;
    };

    // 컬럼의 정렬을 실행
    var sortColumn = function( columnNo, fieldName){
        // 컬럼 상태 설정
        setColumnStatus( columnNo);

        // 오름차순, 내림차순 선택
        var isAscending = true;
        getColumnStatus( columnNo) == 1 ? isAscending = true : getColumnStatus( columnNo) == 2 ? isAscending = false : isAscending = true;

        // 정렬 실행
        self.common.sortArrayObject( varResultLists, fieldName, isAscending);

        // 환자 정보 다시 그리기
        drawPatientList();
    };
    //==== 컬럼 정렬 프로세스 } ====


};