"use strict";
/**
 * mplus_modal_examrsltty1
 */
var mplus_modal_examrsltty1 = function(){
	// 상속
	mplus_common.call(this);
	
	// 상위 객체 생성
	//var mplusPatient = new mplus_mobile_patient();
	//var mplusNursing = new mplus_nursing();
	
	//super
	var self = this;
	
	//==== 변수 { ====
	//==== 변수 } ====
		
	/**
	 * 초기화
	 */
	this.init = function(param){ //여기서 모든화면 콤보박스데이터를 집어넣자!!! 그래야지 화면이동할때 속도가 오래걸리지않음!!!
		//초기화
		initEmptyData();
		
		// 초기 화면 조건 구성
		initCondition(param);
		
		// 이벤트 초기화
		addEvent();		
	};
	
	var initEmptyData = function(){
		$("#divExamRsltTy1Result").empty();
	}
	
	//==== 초기화 설정 { ====
	var initCondition = function(param){
		// 초기 화면 조건 구성
		if(param != null){
			// 20190607 dkchoi75 검사결과>검사결과 조회 value vaildation Check
			var varExamDt = "";
			if(param.examDt != undefined && param.examDt != "" && param.examDt != null) {
				varExamDt = moment(param.examDt , "YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm");
			} else {
				varExamDt = param.examDt;
			}

			//상단정보
			if(param.examDt != undefined || param.examNm != undefined ){
			//	$("#spanExamRsltTy1ExamDtExamNm").text(moment(param.examDt , "YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm") + " / " + param.examNm);
				$("#spanExamRsltTy1ExamDtExamNm").text(varExamDt + " / " + param.examNm);
			}else{
				$("#spanExamRsltTy1ExamDtExamNm").text("처방번호 : " + param.prescriptionNo);
			}

			var varExamRsltKey3 = "";
			if(param.examResultKey != undefined && param.examResultKey != null){
				varExamRsltKey3 = param.examResultKey;
			}else if(param.examRsltKey3 != undefined && param.examRsltKey3 != null){
				varExamRsltKey3 = param.examRsltKey3;
			}
			
			//검사정보
			var sendParam = {
					userId:gLoginUserId,
					patientId:gPatientId,
				/*
					examCd:"-",
					examRsltKey:"-",
					examRsltKey2:"-",
					examRsltKey3:varExamRsltKey3
				*/
				/*
				examCd: (param.examCd != undefined || param.examCd != null || param.examCd !== "-") ? param.examCd : "-",
				examRsltKey:(param.examRsltKey != undefined || param.examRsltKey != null || param.examRsltKey !== "-") ? param.examRsltKey : "-",
				examRsltKey2:(param.examRsltKey2 != undefined || param.examRsltKey2 != null || param.examRsltKey2 !== "-") ? param.examRsltKey2 : "-",
				examRsltKey3:(param.examRsltKey3 != undefined || param.examRsltKey3 != null || param.examRsltKey3 !== "-") ? param.examRsltKey3 : param.examResultKey
 			    */
				examCd: (param.examCd != undefined || param.examCd != null) ? param.examCd : "---",
				examRsltKey:(param.examRsltKey != undefined || param.examRsltKey != null) ? param.examRsltKey : "---",
				examRsltKey2:(param.examRsltKey2 != undefined || param.examRsltKey2 != null) ? param.examRsltKey2 : "---",
				examRsltKey3:(param.examRsltKey3 != undefined || param.examRsltKey3 != null) ? param.examRsltKey3 : "---"
			};
			
			self.medical.getExamRsltTy1(sendParam, processSearchExamrsltty1);
		}
	};
	
	var processSearchExamrsltty1 = function(lists){
		var strDisplayTemp = "";
		
		strDisplayTemp += "<table style=\"width: max-content; max-width: initial; min-width: 100%; margin: 5px; border: 1px solid #444444;\">"
			+ "<thead><tr class=\"exam-header\">" +
					"<th class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">검사명</th>" +
					"<th class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">결과</th>" +
					"<th class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">참고치</th>" +
					"<th class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">단위</th>" +
					"<th class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">상태</th></tr></thead><tbody>";
		
		if(lists != null){
			for( var i = 0; i < lists.length; i++){
				strDisplayTemp += "" 
				+ "  <tr>"
				+ "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\"><p>" + lists[i].examNm + "</p></td>";
				if(lists[i].judgment == "H"){
					strDisplayTemp += "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">" + lists[i].examRsltVal + "<span style=\"color:red;\">▲</span></td>";
				}else if(lists[i].judgment == "L"){
					strDisplayTemp += "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">" + lists[i].examRsltVal + "<span style=\"color:blue;\">▼</span></td>";
				}else{
					strDisplayTemp += "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\">" + lists[i].examRsltVal + "</td>";
				}
				
				strDisplayTemp += ""
				+ "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\"><p>" + lists[i].referenceVal + "</p></td>"
				+ "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\"><p>" + lists[i].examRsltUnit + "</p></td>"
				+ "    <td class=\"text-center\" style=\"border: 1px solid #444444;padding: 5px;\"><p>" + lists[i].examStatNm + "</p></td>"			
				+ " </tr>"
				;
				//console.log( i + " : " + lists[i].deptNm);
			}
		}
		strDisplayTemp += "</tbody></table>";
		
		$("#divExamRsltTy1Result").append(strDisplayTemp);	// element 추가
	};
	
	//==== 초기화 설정 } ====
	
	//==== 이벤트 설정 { ====
	var addEvent = function(){
		//$("#btnLogout").on("click", function(){
		//	logout();
		//});
		
		eventColumnClick();
		
		eventRowClick();
	};
	
	var eventColumnClick = function(){

	};
	
	var eventRowClick = function(){
		
	};
	//==== 이벤트 설정 } ====
	
	
	//==== 서비스 실행 { ====
	//==== 서비스 실행 { ====
	
};