/**
 * mplus_nursing
 */
var mplus_nursing = function(){
	//상속
	mplus_common.call(this);
	//super
	var self = this;
	
	//변수
	
	//임상 페이지 변수
	var btnPlusMaxBps = $('#btnPlusMaxBps');
	var btnMinusMaxBps = $('#btnMinusMaxBps');
	var maxBpsCheck = $('#maxBpsCheck');
	
	var btnPlusMinBps = $('#btnPlusMinBps');
	var btnMinusMinBps = $('#btnMinusMinBps');
	var minBpsCheck = $('#minBpsCheck');
	
	var btnPlusPulse = $('#btnPlusPulse');
	var btnMinusPulse = $('#btnMinusPulse');
	var pulseCheck = $('#pulseCheck');
	
	var btnPlusTemperature = $('#btnPlusTemperature');
	var btnMinusTemperature = $('#btnMinusTemperature');
	var temperatureCheck = $('#temperatureCheck');
	
	var btnPlusBreath = $('#btnPlusBreath');
	var btnMinusBreath = $('#btnMinusBreath');
	var breathCheck = $('#breathCheck');
	
	var btnPlusSpO2 = $('#btnPlusSpO2');
	var btnMinusSpO2 = $('#btnMinusSpO2');
	var spO2Check = $('#spO2Check');
	
	var sliderMaxBps = $("#sliderMaxBps");
	var sliderMinBps = $("#sliderMinBps");
	var sliderPulse = $("#sliderPulse");
	var sliderTemperature = $("#sliderTemperature");
	var sliderBreath = $("#sliderBreath");
	var sliderSpO2 = $("#sliderSpO2");
	
	var txtMaxBps = $('#txtMaxBps');
	var txtMinBps = $('#txtMinBps');
	var txtPulse = $('#txtPulse');
	var txtTemperature = $('#txtTemperature');
	var txtBreath = $('#txtBreath');
	var txtSpO2 = $('#txtSpO2');
		
	var div = $('<div></div>');
	var span = $('<span></span>');
	var tr = $('<tr></tr>');
	var td = $('<td></td>');
	var li = $('<li></li>');
	var input = $('<input></input>');
	var label = $('<label></label>');
	
	//약실시 변수
	var actingList;
	/**
	 * 초기화
	 */
	this.init = function(){
		addEvent();
		// 처음에 정보탭이 열리니까 여기서 이걸 해줘야하는건가...??
		// 위에 addEvent 안에서 해야되나..?
		infoInit();
		
		$('#nursingRecodeTab a[data-toggle="tab"]').unbind();
		$('#nursingRecodeTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			if($("ul#nursingRecodeTab.nav-tabs li.active a").attr('aria-controls')=='tabInfo'){
				infoInit();
			}else if($("ul#nursingRecodeTab.nav-tabs li.active a").attr('aria-controls')=='tabHistory'){
				historyInit();
			}else if($("ul#nursingRecodeTab.nav-tabs li.active a").attr('aria-controls')=='tabVital'){
				vitalInit();
			}else if($("ul#nursingRecodeTab.nav-tabs li.active a").attr('aria-controls')=='tabInject'){
				//self.rotateScreen('vertical');
				injectInit();
			}else if($("ul#nursingRecodeTab.nav-tabs li.active a").attr('aria-controls')=='tabCure'){
				//self.rotateScreen('landscape');
				cureInit();
			}else{
				/*slef.alert('에러메시지?');*/
			};
		});
		
/*		$('#nursingRecodeTab a[data-toggle="tab"]').on('hide.bs.tab', function (e) {
			if($("ul#nursingRecodeTab.nav-tabs li.active a").attr('aria-controls')=='tabCure'){
				self.rotateScreen('vertical');
			}
		});*/
	};
	//토글이 열려있는 상태에서 다른환자 클릭시 호출
	this.reInit = function(tabName){
		if(tabName=='tabInfo'){
			infoInit();
		}else if(tabName=='tabHistory'){
			historyInit();
		}else if(tabName=='tabVital'){
			vitalInit();
		}else if(tabName=='tabInject'){
			injectInit();
		}else if(tabName=='tabCure'){
			cureInit();
		};
	};
	/**
	 * 이벤트 등록
	 */
	var addEvent = function(){
		
	};
	//------------------------------------정보 탭---------------------------------------
	var infoInit = function() {
		// 환자정보 받기
		// 환자 상세정보받기
		$('#tabInfo').scrollTop(0);
		addEventInfo();
	};
	var addEventInfo = function() {
		// 환자 상세정보 Text 펼치기/접기
		$('#infoPatientDetail').unbind();
		$('#infoPatientDetail').click(function(){
			if( $('#infoPatientDetailTxt').hasClass('in')) {
				$('#infoPatientDetailTxt').removeClass('in').fadeOut("fast", "linear");
			} else {
				$('#infoPatientDetailTxt').addClass('in').fadeIn("slow", "linear");
			} 
		});
		$('#infoPatientDetailTxt').click(function(){
			$('#infoPatientDetailTxt').removeClass('in').fadeOut("fast", "linear");
		});
		
	};
	//------------------------------------정보 탭 종료 -----------------------------------
	//------------------------------------이력 탭---------------------------------------
	var historyInit = function() {
		historyDataSetting('ALL', 'N', null);
		addEventHistory();
		
		$('#tabHistory').scrollTop(0);
	};
	
	var addEventHistory = function () {
		$('#historyOutMore, #historyInMore, #historyOpMore').unbind();
		$('#historyOutMore, #historyInMore, #historyOpMore').click( function(e) {
			var targetId = e.currentTarget.id;
			var listId = targetId.replace('More', '');
			$('#' + targetId).before($('#'+ listId).find('.history-item:last').clone()); /* 야매 코드 */
		});
	};
	
	var historyDataSetting = function(type, addYn, endDt){
		var patientInfo = JSON.parse(localStorage.patientInfo);
		var today = new Date();
		var targetEndDt = endDt==null? moment(today).format('YYYYMMDD'): moment(moment(endDt)._d  - 1 * 1000 * 60 * 60 * 24).format('YYYYMMDD');
		var targetStartDt = moment(moment(targetEndDt)._d  - 30 * 1000 * 60 * 60 * 24).format('YYYYMMDD');
		var param = {
				patientId: patientInfo.patientId,
				startDt: targetStartDt,
				endDt: targetEndDt
		};
		if(type=='ALL'){ //바인딩할때 리스트 empty하니 탭 이동할때 데이터 조회 오류가나도 empty가 되지않아 여기서 해줌!
			if(addYn=='N'){
				$('#historyIn').empty();
				$('#historyOut').empty();
				$('#historyOp').empty();
			};
			self.nursing.getVisitList(param, 'in', addYn, targetStartDt);
			self.nursing.getVisitList(param, 'out', addYn, targetStartDt);
			self.nursing.getVisitList(param, 'op', addYn, targetStartDt);
		}else{
			if(addYn=='N'){
				if(type=='in'){
					$('#historyIn').empty(); 
				}else if(type=='out'){
					$('#historyOut').empty();
				}else{
					$('#historyOp').empty();
				};
			};
			self.nursing.getVisitList(param, type, addYn, targetStartDt);
		};
	};
	
	var spanMoreIcon = span.clone().addClass('glyphicon glyphicon-menu-down').attr('aria-hidden', 'true');
	var spanCloseIcon = span.clone().addClass('glyphicon glyphicon-menu-up').attr('aria-hidden', 'true');
	
	bindingVisitList = function(visitList, type, addYn, endDt){
		var today = new Date();
		if(type=='in'){
			//입원
			$('#inSearchDt').text(moment(endDt).format('YYYY-MM-DD') + ' ~ ' + moment(today).format('YYYY-MM-DD'));
			if(addYn=='Y'){
				$('#historyInMore').remove();
				$('#historyInClose').remove();
			};
			for(var j=0; j<visitList.length; j++){
				var divTreatDt = div.clone().addClass('col-xs-4 col-sm-3 pdl0').append($('<strong></strong>').clone().text(moment(visitList[j].inDt).format('YYYY-MM-DD') + ' ~ ' + (visitList[j].outDt==''? '': moment(visitList[j].outDt).format('YYYY-MM-DD'))));
				var divDoctor = div.clone().addClass('col-xs-8 col-sm-4 pd0').text(visitList[j].departmentNm + ' ' + visitList[j].doctorNm + ' ' + visitList[j].wardNm + '/' + visitList[j].roomNm + '/' + visitList[j].bedNm);
				var divEmpty = div.clone().addClass('col-xs-4 pd0');
				var divDiagnosisNm = div.clone().addClass('col-xs-8 col-sm-5 pd0').text(visitList[j].diagnosisNm);
				
				$('#historyIn').append(div.clone().addClass('history-item col-xs-12').append(divTreatDt).append(divDoctor).append(divEmpty).append(divDiagnosisNm));
			};
			
			/*if(visitList.length>0){*/
				var divInMore = div.clone().addClass('col-xs-6 history-more text-center').attr('id', 'historyInMore').attr('endDt', endDt);
				var divInClose = div.clone().addClass('col-xs-6 history-more text-center').attr('id', 'historyInClose');
				
				$('#historyIn').append(divInMore.append(spanMoreIcon.clone())).append(divInClose.append(spanCloseIcon.clone()));
				
				$('#historyInMore').unbind();
				$('#historyInMore').on('click', function(){
					historyDataSetting('in', 'Y', $('#historyInMore').attr('endDt'));
				});
				
				$('#historyInClose').unbind();
				$('#historyInClose').on('click', function(){
					$('#inSearchDt').text('');
					$('#historyInMore').removeAttr('endDt');
					$('#historyIn').find('.history-item').remove();
				});
			/*};*/
		}else if(type=='out'){
			//외래
			$('#outSearchDt').text(moment(endDt).format('YYYY-MM-DD') + ' ~ ' + moment(today).format('YYYY-MM-DD'));
			if(addYn=='Y') {
				$('#historyOutMore').remove();
				$('#historyOutClose').remove();
			};
			for(var i=0; i<visitList.length; i++){
				var divTreatDt = div.clone().addClass('col-xs-4 col-sm-3 pdl0').append($('<strong></strong>').clone().text(moment(visitList[i].treatDt).format('YYYY-MM-DD')));
				var divDoctor = div.clone().addClass('col-xs-8 col-sm-4 pd0').text(visitList[i].departmentNm + ' ' + visitList[i].doctorNm);
				var divEmpty = div.clone().addClass('col-xs-4 pd0');
				var divDiagnosisNm = div.clone().addClass('col-xs-8 col-sm-5 pd0').text(visitList[i].diagnosisNm);
				
				$('#historyOut').append(div.clone().addClass('history-item col-xs-12').append(divTreatDt).append(divDoctor).append(divEmpty).append(divDiagnosisNm));
			};
			
			/*if(visitList.length>0){*/
				var divOutMore = div.clone().addClass('col-xs-6 history-more text-center').attr('id', 'historyOutMore').attr('endDt', endDt);
				var divOutClose = div.clone().addClass('col-xs-6 history-more text-center').attr('id', 'historyOutClose');
				
				$('#historyOut').append(divOutMore.append(spanMoreIcon.clone())).append(divOutClose.append(spanCloseIcon.clone()));
				
				$('#historyOutMore').unbind();
				$('#historyOutMore').on('click', function(){
					historyDataSetting('out', 'Y', $('#historyOutMore').attr('endDt'));
				});
				
				$('#historyOutClose').unbind();
				$('#historyOutClose').on('click', function(){
					$('#outSearchDt').text('');
					$('#historyOutMore').removeAttr('endDt');
					$('#historyOut').find('.history-item').remove();
				});
			/*};*/
		}else{
			//수술
			$('#opSearchDt').text(moment(endDt).format('YYYY-MM-DD') + ' ~ ' + moment(today).format('YYYY-MM-DD'));
			if(addYn=='Y'){
				$('#historyOpMore').remove();
				$('#historyOpClose').remove();
			};
			for(var k=0; k<visitList.length; k++){
				var divTreatDt = div.clone().addClass('col-xs-4 col-sm-3 pdl0').append($('<strong></strong>').clone().text(moment(visitList[k].operatingDt).format('YYYY-MM-DD')));
				var divDoctor = div.clone().addClass('col-xs-8 col-sm-4 pd0').text(visitList[k].operatingNm + ', ' + visitList[k].diagnosisNm);
				var divEmpty = div.clone().addClass('col-xs-4 pd0');
				var divDiagnosisNm = div.clone().addClass('col-xs-8 col-sm-5 pd0').text(visitList[k].operatingDeptNm + ' '+ visitList[k].operatingDrNm);
				
				$('#historyOp').append(div.clone().addClass('history-item col-xs-12').append(divTreatDt).append(divDoctor).append(divEmpty).append(divDiagnosisNm));
			};
			
			/*if(visitList.length>0){*/
				var divOpMore = div.clone().addClass('col-xs-6 history-more text-center').attr('id', 'historyOpMore').attr('endDt', endDt);
				var divOpClose = div.clone().addClass('col-xs-6 history-more text-center').attr('id', 'historyOpClose');
				
				$('#historyOp').append(divOpMore.append(spanMoreIcon.clone())).append(divOpClose.append(spanCloseIcon.clone()));
			
				$('#historyOpMore').unbind();
				$('#historyOpMore').on('click', function(){
					historyDataSetting('op', 'Y', $('#historyOpMore').attr('endDt'));
				});
				
				$('#historyOpClose').unbind();
				$('#historyOpClose').on('click', function(){
					$('#opSearchDt').text('');
					$('#historyOpMore').removeAttr('endDt');
					$('#historyOp').find('.history-item').remove();
				});
			/*};*/
		};
	};
	//------------------------------------이력 탭 종료 -----------------------------------
	//------------------------------------임상 탭---------------------------------------
	var vitalInit = function(){
		$('#vitalSearch').css('display', 'block');
		$('#vitalInfo').css('display', 'none');
		
		$('#vitalSearch #vitalSearchDate').text(moment(new Date).format('YYYY-MM-DD'));
		
		self.lastVital = new Array();
		vitalDataSetting(true);
		addEventVital();
		
		$('#tabVital').scrollTop(0);
	};
	
	var vitalDataSetting = function(saveLastVital){
		var patientInfo = JSON.parse(localStorage.patientInfo);
		if(patientInfo.visitNo == undefined) return;
		var param = {visitNo: patientInfo.visitNo, searchDt: $('#vitalSearchDate').text()};
		
		var vitalList = self.nursing.getVitalList(param);
		
		var vitalListArr = [];
		
		for(var i=0; i<vitalList.length; i++){
			/* 2018.06.18. 안드로이드 호환 변경
			//if(vitalListArr.find(o => o.time === vitalList[i].ActDt.split(' ')[1])==undefined){
			if(vitalListArr.find(function(o){return o.time === vitalList[i].ActDt.split(' ')[1];})==undefined){
				vitalListArr.push({
					'time': vitalList[i].ActDt.split(' ')[1],
					'pulse': '-',
					'breath': '-',
					'temperature': '-',
					'minBps': '-',
					'maxBps': '-',
					'spO2': '-'
				});
			}*/
			var Arrtemp = undefined;
			for(var j=0; j<vitalListArr.length ; j++){
				if(vitalListArr[j].time === vitalList[i].actDt.split(' ')[1]){
					Arrtemp = vitalListArr[j];
					break;
				}
			}
			if(Arrtemp == undefined){
				vitalListArr.push({
					'time': vitalList[i].actDt.split(' ')[1],
					'pulse': '-',
					'breath': '-',
					'temperature': '-',
					'minBps': '-',
					'maxBps': '-',
					'spO2': '-'
				});
			}
			
			//2018.06.18. 안드로이드 호환 변경
			//var targetObject = vitalListArr.find(o => o.time === vitalList[i].ActDt.split(' ')[1]);			
			var targetObject = null;
			for(var j=0; j<vitalListArr.length ; j++){
				if(vitalListArr[j].time === vitalList[i].actDt.split(' ')[1]){
					targetObject = vitalListArr[j];
					break;
				}
			}
			
			if(vitalList[i].itmCd=='1000500001'){//맥박
				targetObject.pulse = vitalList[i].msmtVal;
			}else if(vitalList[i].itmCd=='1000600001'){//호흡
				targetObject.breath = vitalList[i].msmtVal;
			}else if(vitalList[i].itmCd=='1000700001'){//DBP
				targetObject.temperature = vitalList[i].msmtVal;
			}else if(vitalList[i].itmCd=='1000900001'){//DBP
				targetObject.minBps = vitalList[i].msmtVal;
			}else if(vitalList[i].itmCd=='1000800001'){//SBP
				targetObject.maxBps = vitalList[i].msmtVal;
			}else if(vitalList[i].itmCd=='2001100049'){//SPO2
				targetObject.spO2 = vitalList[i].msmtVal;
			}else{
				
			}
		}
		
		vitalListArr = self.util.sortObj(vitalListArr, 'time', 'string', 'down');
		if( saveLastVital && vitalListArr.length > 0) {
			self.lastVital.push(vitalListArr[0]);
		}
		vitalDataBinding(vitalListArr);
	};
	
	var vitalDataBinding = function(vitalList){
		$('#vitalList').empty();
		
		for(var i=0; i<vitalList.length; i++){
			var timeCell = td.clone().text(vitalList[i].time);
			var pulseCell = td.clone().text(vitalList[i].pulse==''? '-': vitalList[i].pulse);
			var breathCell = td.clone().text(vitalList[i].breath==''? '-': vitalList[i].breath);
			var temperatureCell = td.clone().text(vitalList[i].temperature==''? '-': vitalList[i].temperature);
			var minBpsCell = td.clone().text(vitalList[i].minBps==''? '-': vitalList[i].minBps);
			var maxBpsCell = td.clone().text(vitalList[i].maxBps==''? '-': vitalList[i].maxBps);
			var spO2Cell = td.clone().text(vitalList[i].spO2==''? '-': vitalList[i].spO2);
			
			var vitalRow = tr.clone().append(timeCell).append(pulseCell).append(breathCell)
						.append(temperatureCell).append(maxBpsCell).append(minBpsCell).append(spO2Cell);
			
			$('#vitalList').append(vitalRow);
			
		}
	};
	
	var addEventVital = function(){
		$('#vitalSearch .vital-prev-day').unbind();
		$('#vitalSearch .vital-prev-day').click(function() {
			var currentDate = moment($('#vitalSearch #vitalSearchDate').text()).format('YYYY-MM-DD');
			
			$('#vitalSearch #vitalSearchDate').text(moment(currentDate).add(-1, 'days').format('YYYY-MM-DD'));
			vitalDataSetting(false);
		});
		
		$('#vitalSearch .vital-next-day').unbind();
		$('#vitalSearch .vital-next-day').click(function() {
			var currentDate = moment($('#vitalSearch #vitalSearchDate').text()).format('YYYY-MM-DD');
			
			$('#vitalSearch #vitalSearchDate').text(moment(currentDate).add(1, 'days').format('YYYY-MM-DD'));
			vitalDataSetting(false);
		});

		$('#btnInputVital').unbind();
		$('#btnInputVital').click(function(){
			$('#vitalSearch').css('display', 'none');
			$('#vitalInfo').css('display', 'block');
			initVitalData();
		});
		
		$('#btnSearchVital').unbind();
		$('#btnSearchVital').click(function(){
			$('#vitalSearch').css('display', 'block');
			$('#vitalInfo').css('display', 'none');
			vitalInit();
		});
		
		maxBpsCheck.unbind();
		maxBpsCheck.change(function(e){
			if(e.currentTarget.checked){
				sliderMaxBps.slider('enable', true);
				btnPlusMaxBps.attr('disabled', false);
				btnMinusMaxBps.attr('disabled', false);
				txtMaxBps.attr('disabled', false);
			}else{
				sliderMaxBps.slider('disable', true);
				btnPlusMaxBps.attr('disabled', 'disabled');
				btnMinusMaxBps.attr('disabled', 'disabled');
				txtMaxBps.attr('disabled', 'disabled');
			};
		});
		
		btnPlusMaxBps.unbind();
		btnPlusMaxBps.click(function(e){
			sliderMaxBps.slider('setValue', Number(sliderMaxBps.val())+1);
			txtMaxBps.val(sliderMaxBps.val());
		});
		
		btnMinusMaxBps.unbind();
		btnMinusMaxBps.click(function(e){
			sliderMaxBps.slider('setValue', Number(sliderMaxBps.val())-1);
			txtMaxBps.val(sliderMaxBps.val());
		});	
		
		minBpsCheck.unbind();
		minBpsCheck.change(function(e){
			if(e.currentTarget.checked){
				sliderMinBps.slider('enable', true);
				btnPlusMinBps.attr('disabled', false);
				btnMinusMinBps.attr('disabled', false);
				txtMinBps.attr('disabled', false);
			}else{
				sliderMinBps.slider('disable', true);
				btnPlusMinBps.attr('disabled', 'disabled');
				btnMinusMinBps.attr('disabled', 'disabled');
				txtMinBps.attr('disabled', 'disabled');
			};
		});
		
		btnPlusMinBps.unbind();
		btnPlusMinBps.click(function(e){
			sliderMinBps.slider('setValue', Number(sliderMinBps.val())+1);
			txtMinBps.val(sliderMinBps.val());
		});
		
		btnMinusMinBps.unbind();
		btnMinusMinBps.click(function(e){
			sliderMinBps.slider('setValue', Number(sliderMinBps.val())-1);
			txtMinBps.val(sliderMinBps.val());
		});
		
		pulseCheck.unbind();
		pulseCheck.change(function(e){
			if(e.currentTarget.checked){
				sliderPulse.slider('enable', true);
				btnPlusPulse.attr('disabled', false);
				btnMinusPulse.attr('disabled', false);
				txtPulse.attr('disabled', false);
			}else{
				sliderPulse.slider('disable', true);
				btnPlusPulse.attr('disabled', 'disabled');
				btnMinusPulse.attr('disabled', 'disabled');
				txtPulse.attr('disabled', 'disabled');
			};
		});
		
		btnPlusPulse.unbind();
		btnPlusPulse.click(function(e){
			sliderPulse.slider('setValue', Number(sliderPulse.val())+1);
			txtPulse.val(sliderPulse.val());
		});
		
		btnMinusPulse.unbind();
		btnMinusPulse.click(function(e){
			sliderPulse.slider('setValue', Number(sliderPulse.val())-1);
			txtPulse.val(sliderPulse.val());
		});
		
		temperatureCheck.unbind();
		temperatureCheck.change(function(e){
			if(e.currentTarget.checked){
				sliderTemperature.slider('enable', true);
				btnPlusTemperature.attr('disabled', false);
				btnMinusTemperature.attr('disabled', false);
				txtTemperature.attr('disabled', false);
			}else{
				sliderTemperature.slider('disable', true);
				btnPlusTemperature.attr('disabled', 'disabled');
				btnMinusTemperature.attr('disabled', 'disabled');
				txtTemperature.attr('disabled', 'disabled');
			};
		});
		
		btnPlusTemperature.unbind();
		btnPlusTemperature.click(function(e){
			sliderTemperature.slider('setValue', Number(sliderTemperature.val())+0.1);
			txtTemperature.val(sliderTemperature.val());
		});
		 
		btnMinusTemperature.unbind();
		btnMinusTemperature.click(function(e){
			sliderTemperature.slider('setValue', Number(sliderTemperature.val())-0.1);
			txtTemperature.val(sliderTemperature.val());
		});
		
		breathCheck.unbind();
		breathCheck.change(function(e){
			if(e.currentTarget.checked){
				sliderBreath.slider('enable', true);
				btnPlusBreath.attr('disabled', false);
				btnMinusBreath.attr('disabled', false);
				txtBreath.attr('disabled', false);
			}else{
				sliderBreath.slider('disable', true);
				btnPlusBreath.attr('disabled', 'disabled');
				btnMinusBreath.attr('disabled', 'disabled');
				txtBreath.attr('disabled', 'disabled');
			};
		});
		
		btnPlusBreath.unbind();
		btnPlusBreath.click(function(e){
			sliderBreath.slider('setValue', Number(sliderBreath.val())+1);
			txtBreath.val(sliderBreath.val());
		});
		
		btnMinusBreath.unbind();
		btnMinusBreath.click(function(e){
			sliderBreath.slider('setValue', Number(sliderBreath.val())-1);
			txtBreath.val(sliderBreath.val());
		});
		
		spO2Check.unbind();
		spO2Check.change(function(e){
			if(e.currentTarget.checked){
				sliderSpO2.slider('enable', true);
				btnPlusSpO2.attr('disabled', false);
				btnMinusSpO2.attr('disabled', false);
				txtSpO2.attr('disabled', false);
			}else{
				sliderSpO2.slider('disable', true);
				btnPlusSpO2.attr('disabled', 'disabled');
				btnMinusSpO2.attr('disabled', 'disabled');
				txtSpO2.attr('disabled', 'disabled');
			};
		});
		
		btnPlusSpO2.unbind();
		btnPlusSpO2.click(function(e){
			sliderSpO2.slider('setValue', Number(sliderSpO2.val())+1);
			txtSpO2.val(sliderSpO2.val());
		});
		
		btnMinusSpO2.unbind();
		btnMinusSpO2.click(function(e){
			sliderSpO2.slider('setValue', Number(sliderSpO2.val())-1);
			txtSpO2.val(sliderSpO2.val());
		});
		
		$('#btnVitalSubmit').unbind();
		$('#btnVitalSubmit').click(function(e){
			saveVitalInfo();
		});
	};
	
	var initVitalData = function(){
		// 최근 입력 값 셋팅
		// 전날까지 입력한 값이 없는 경우는 Default 값 셋팅
		var today = new Date();
		if( self.lastVital.length == 0 ) {
			$('#vitalSearch #vitalSearchDate').text(moment(today).add(-1, 'days').format('YYYY-MM-DD'));
			vitalDataSetting(true);
			if( self.lastVital.length == 0 ) {
				self.lastVital.push({
					'pulse': '-',
					'breath': '-',
					'temperature': '-',
					'minBps': '-',
					'maxBps': '-',
					'spO2': '-'
				});
			}
		}

		// 입력일시 셋팅
		$('#vitalInfo #vitalEnteredTm span.content').text(moment(today).format('YYYY년 MM월 DD일 HH시 mm분'));

		//입력일시 셋팅
		var minEnterTime = new Date();
		var maxEnterTime = new Date();
		minEnterTime.setHours(minEnterTime.getHours()-3);
		maxEnterTime.setHours(maxEnterTime.getHours()+3);
		$.datetimepicker.setLocale('ko');
		$('#enterDateTime').datetimepicker({
			value:new Date(),
			minDate:minEnterTime,
			maxDate:maxEnterTime,
			minTime:minEnterTime,
			maxTime:maxEnterTime,
			formatDate:'Y-m-d H:i',
			format:'Y-m-d H:i',
			step:5
		});
		
		var lastInputValue = 0;
		
		// 최고혈압
		lastInputValue = self.lastVital[0].maxBps;
		if( lastInputValue == '-' ) {
			sliderMaxBps.slider({ value: 120 });
			txtMaxBps.val('');
		} else {
			sliderMaxBps.slider({
				value: lastInputValue
			});
			txtMaxBps.val(lastInputValue);	
		}
		maxBpsCheck.prop('checked', false).trigger('change');
		
		// 최저혈압
		lastInputValue = self.lastVital[0].minBps;
		if( lastInputValue == '-' ) {
			sliderMinBps.slider({ value: 80	});
			txtMinBps.val('');
		} else {
			sliderMinBps.slider({
				value: lastInputValue
			});
			txtMinBps.val(lastInputValue);
		}
		minBpsCheck.prop('checked', false).trigger('change');
		
		// 맥박
		lastInputValue = self.lastVital[0].pulse;
		if( lastInputValue == '-' ) {
			sliderPulse.slider({ value: 80 });
			txtPulse.val('');
		} else {
			sliderPulse.slider({
				value: lastInputValue
			});
			txtPulse.val(lastInputValue);
		}
		pulseCheck.prop('checked', false).trigger('change');
		
		// 체온
		lastInputValue = self.lastVital[0].temperature;
		if( lastInputValue == '-' ) {
			sliderTemperature.slider({ value: 36.5,	percision: 1 });
			txtTemperature.val('');
		} else {
			sliderTemperature.slider({
				value: lastInputValue,
				percision: 1
			});
			txtTemperature.val(lastInputValue);
		}
		temperatureCheck.prop('checked', false).trigger('change');
		
		// 호흡
		lastInputValue = self.lastVital[0].breath;
		if( lastInputValue == '-' ) {
			sliderBreath.slider({ value: 20 });
			txtBreath.val('');
		} else {
			sliderBreath.slider({
				value: lastInputValue
			});
			txtBreath.val(lastInputValue);
		}
		breathCheck.prop('checked', false).trigger('change');
		
		// 산소포화도
		lastInputValue = self.lastVital[0].spO2;
		if( lastInputValue == '-' ) {
			sliderSpO2.slider({ value: 100 });
			txtSpO2.val('');
		} else {
			sliderSpO2.slider({
				value: lastInputValue
			});
			txtSpO2.val(lastInputValue);
		}
		spO2Check.prop('checked', false).trigger('change');
		
		// 슬라이더 이벤트 추가
		$('.slider').change(function(e) {
			syncSliderToTxt(e.currentTarget.id);
		});
		// 텍스트박스 이벤트 추가
		$('.vital-value').keyup(function(e) {
			if( e.keyCode != 8) {
				syncTxtToSlider(e.currentTarget.id);
			}
		});
		
	};
	
	var saveVitalInfo = function(){
		var patientInfo = JSON.parse(localStorage.patientInfo);
		var userId = JSON.parse(localStorage.user).userId;
		var today = new Date();
		
		var param = {vital: []};
		
		if($('.vital-checkbox input[type=checkbox]:checked').length==0){
			self.alert('임상관찰 데이터를 입력해주세요.');
			return;
		}
		
		for(var i=0; i<$('.vital-checkbox input[type=checkbox]:checked').length; i++){
			var itemCd = $('.vital-checkbox input[type=checkbox]:checked')[i].attributes['data-itemcd'].value;
			
			param.vital.push(
					{
						visitNo: patientInfo.visitNo, 
						//actTm: moment(today).format('YYYY-MM-DD HH:mm'), 
						actTm: $('#enterDateTime').val(),
						treatTyp: patientInfo.treatTyp, 
						itemCd: itemCd, 
						monitorVal: $('.vital-value[data-itemCd="'+itemCd+'"]').val(), 
						userId: userId
					}	
				);
		}
		
		var setVitalResult = self.nursing.setVitalList(param);
		
		var returnMsg = '';
		var returnState = 'Y';
		for(var j=0; j<setVitalResult.length; j++){
			if(setVitalResult[j].returnVal != 'OK'){
				returnState = 'N';
				if(setVitalResult[j].itemCd=='1000500001'){
					returnMsg = returnMsg + '맥박, ';
				}else if(setVitalResult[j].itemCd=='1000600001'){
					returnMsg = returnMsg + '호흡, ';
				}else if(setVitalResult[j].itemCd=='1000700001'){
					returnMsg = returnMsg + '체온, ';
				}else if(setVitalResult[j].itemCd=='1000900001'){
					returnMsg = returnMsg + 'DBP, ';
				}else if(setVitalResult[j].itemCd=='1000800001'){
					returnMsg = returnMsg + 'SBP, ';
				}else if(setVitalResult[j].itemCd=='2001100049'){
					returnMsg = returnMsg + 'SPO2, ';
				};
			};
		};
		if(returnState == 'Y'){
			returnMsg = '입력 완료 되었습니다';
		}else{
			returnMsg = '[ '+ (returnMsg.substr(0, returnMsg.length-2)) + ' ] 입력에 실패했습니다.';
		};
		self.alert(returnMsg);
	};
	
	var syncSliderToTxt = function(sliderId) {
		var value = $('input#' + sliderId).val();
		var txtId = sliderId.replace('slider', 'txt');
		$('input#' + txtId).val(value);
	};
	
	var syncTxtToSlider = function(txtId) {
		var value = $('input#' + txtId).val();
		var sliderId = txtId.replace('txt', 'slider');
		$('input#' + sliderId).slider('setValue', Number(value));
		// 범위 벗어난 경우에 대해 체크
		if( value.length > 0 && Number(value) > $('input#' + sliderId).val()) {
			$('input#' + txtId).val($('input#' + sliderId).val());
		}
	};
	
	//------------------------------------임상 탭 종료---------------------------------------
	
	//------------------------------------투약 탭 -----------------------------------------
	var injectInit = function() {
		$('#injectSearch #injectSearchDate').text(moment(new Date()).format('YYYY-MM-DD'));
		injectBinding();
		addEventInject();
		
		$('#tabInject').scrollTop(0);
	};
	
	var addEventInject = function(){
		$('#injectSearch .inject-prev-day').unbind();
		$('#injectSearch .inject-prev-day').click(function() {
			var currentDate = moment($('#injectSearch #injectSearchDate').text()).format('YYYY-MM-DD');
			
			$('#injectSearch #injectSearchDate').text(moment(currentDate).add(-1, 'days').format('YYYY-MM-DD'));
			injectBinding();
		});
		
		$('#injectSearch .inject-next-day').unbind();
		$('#injectSearch .inject-next-day').click(function() {
			var currentDate = moment($('#injectSearch #injectSearchDate').text()).format('YYYY-MM-DD');
			
			$('#injectSearch #injectSearchDate').text(moment(currentDate).add(1, 'days').format('YYYY-MM-DD'));
			injectBinding();
		});
	};
	
	var addEventInjectItem = function() {
		$('#injectDataList .list-group-item').unbind();
		$('#injectDataList .list-group-item').click(function(){
			var detailArea = $(this).find('.inject-data-detail');
			if( detailArea.hasClass('hidden')) {
				detailArea.removeClass('hidden');
			} else {
				detailArea.addClass('hidden');
			}
		});
	};
	
	var injectBinding = function(){
		var patientInfo = JSON.parse(localStorage.patientInfo);
		var searchDate = moment($('#injectSearchDate').text()).format('YYYYMMDD');
		var param = {
				'patientId': patientInfo.patientId,
				'startDt': searchDate,
				'endDt': searchDate,
		};
		
		var medicationList = self.nursing.getMedicationHistory(param);
		
		$('#injectDataList').empty();
		
		for(var i=0; i<medicationList.length; i++){
			var injectOuterRow = div.clone().addClass('list-group-item');
			var injectInnerRow = div.clone().addClass('list-row container');
			var wrapRow12 = div.clone().addClass('col-xs-12 col-sm-6 pd0');
			
			var numCol = div.clone().addClass('col-xs-2 col-sm-2 pdl5 pdr5').append(medicationList[i].OrdNo);
			var drugNmCol = div.clone().addClass('col-xs-10 col-sm-10 pdl5 pdr5 letter-control').append(medicationList[i].OrdNm);
			
			var execYnCol = div.clone().addClass('col-xs-2 col-sm-2 pdl5 pdr5').append(medicationList[i].ExecYn);
			var capacityCol = div.clone().addClass('col-xs-3 col-sm-3 pdl5 pdr5').append(Number(medicationList[i].Qty) + ' (' + Number(medicationList[i].TQty) + ')');
			var executeTmCol = div.clone().addClass('col-xs-4 col-sm-4 pdl5 pdr5').append(medicationList[i].DrgInjExecStrHms==null? '-': (moment(medicationList[i].DrgInjExecStrHms, 'HHmmss').format('HH:mm:ss')));
			var seqCol = div.clone().addClass('col-xs-3 col-sm-3 pdl5 pdr5').append((medicationList[i].DrgInjExecSeq==null?'-':medicationList[i].DrgInjExecSeq) + ' / ' + medicationList[i].Frq);
			
/*			var dsgCdCol = div.clone().addClass('col-xs-3 col-sm-3 pdl0 pdr5').append(medicationList[i].DsgCd);
 			var prescriptionDtCol = div.clone().addClass('col-xs-3 col-sm-3 pdl5 pdr5').append(medicationList[i].prescriptionDt==null? '-': (moment(medicationList[i].prescriptionDt).format('YYYY-MM-DD')));
			var prescriptionDeptNmCol = div.clone().addClass('col-xs-4 col-sm-4 pdl5 pdr5').append(medicationList[i].prescriptionDeptNm + '/'+ (medicationList[i].prescriptionNm==undefined? '': medicationList[i].prescriptionNm));
			var executeDtCol = div.clone().addClass('col-xs-4 col-sm-4 pdl5 pdr5').append((medicationList[i].executeDt==null? '-': (moment(medicationList[i].executeDt).format('YYYY-MM-DD'))) +'/'+  (medicationList[i].executeNm==null? '': medicationList[i].executeNm));
			var capacityCol = div.clone().addClass('col-xs-2 col-sm-2 pdl5 pdr5').append(medicationList[i].capacity);
			var doseQtyPerTimCol = div.clone().addClass('col-xs-2 col-sm-2 pdl5 pdr5').append(medicationList[i].doseQtyPerDay);
*/			

			var presDtItem = div.clone().append(span.clone().addClass('mp-dot')).append(span.clone().addClass('top-info-style')
					.append('처방일: ').append(medicationList[i].OrdYmd==null? '-': (moment(medicationList[i].OrdYmd).format('YYYY-MM-DD'))));
			var presDeptItem = div.clone().append(span.clone().addClass('mp-dot')).append(span.clone().addClass('top-info-style')
					.append('처방과: ').append(medicationList[i].ClnDeptCd));
			var presDoctorItem = div.clone().append(span.clone().addClass('mp-dot')).append(span.clone().addClass('top-info-style')
					.append('처방의: ').append('-'));
			var presExecuteDtItem = div.clone().append(span.clone().addClass('mp-dot')).append(span.clone().addClass('top-info-style')
					.append('시작일: ').append('-'));
			var presExecuteDeptItem = div.clone().append(span.clone().addClass('mp-dot')).append(span.clone().addClass('top-info-style')
					.append('시행부서: ').append('-'));
			var presExecuteNmItem = div.clone().append(span.clone().addClass('mp-dot')).append(span.clone().addClass('top-info-style')
					.append('시행자: ').append(medicationList[i].DrgInjExecId==null?'-':medicationList[i].DrgInjExecId));
			
			var detail = div.clone().addClass('inject-data-detail hidden').append(presDtItem).append(presDeptItem).append(presDoctorItem)
							.append(presExecuteDtItem).append(presExecuteDeptItem).append(presExecuteNmItem);
			
			
			var injectRow = li.clone().append(
												injectOuterRow.append(
																		injectInnerRow.append(wrapRow12.clone().append(numCol)
																											  .append(drugNmCol)
																					).append(wrapRow12.clone().append(execYnCol)
																							  .append(capacityCol)
																							  .append(executeTmCol)
																							  .append(seqCol)
																							)
																	).append(detail)
											);
			
			$('#injectDataList').append(injectRow);
		}
		
		addEventInjectItem();
		
	};
	//------------------------------------투약 탭 종료--------------------------------------
	
	//------------------------------------약실시 탭 ---------------------------------------
	var cureInit = function(){	
		var today = new Date();
		$('#sltTime').val(moment(today).format('HH'));
		$('#sltTimeType').val('current');
		$('#sltMedType').val('A01');
		addEventCure();
		$('#btnSearchCure').click();
	};
	
	var addEventCure = function(){		
		$('#sltTimeType').unbind();
		$('#sltTimeType').change(function(e){
			if(e.currentTarget.value=='special'){
				$('#sltTime').prop('disabled', false);
			}else{
				$('#sltTime').prop('disabled', true);
			}
		});
		
		$('#btnSearchCure').unbind();
		$('#btnSearchCure').click(function(e){
			getCureList();
		});
		
		$('#btnStartDrug').unbind();
		$('#btnStartDrug').click(function(){
			if($('input[type=checkbox][id*=chk_cureDetail_]:checked').length>0){
				$('#modalStartDrug').modal('show');
				/*$('#modalStartSap').modal('show');*/	
				$('input#sapNo').prop('checked', true).trigger('change');
			}else{
				self.alert('투약내역을 선택해주세요.');
				return;
			};
		});
		
		$('#btnChangeDrug').unbind();
		$('#btnChangeDrug').click(function(){
			if($('input[type=checkbox][id*=chk_cureDetail_]:checked').length>0){
				$('#modalChangeDrug').modal('show');	
				/*$('#modalStartSap').modal('show');*/	
				$('input#sapYes').prop('checked', true).trigger('change');
			}else{
				self.alert('투약내역을 선택해주세요.');
				return;
			};
		});
		
		$('#modalChangeDrug').on('show.bs.modal', function (e) {
			$('#dateChangeDrug')[0].value = self.util.toDatetimeLocal(new Date());
		});
					
		$('#btnStartSap').unbind();
		$('#btnStartSap').click(function(){//이 if문을 나중에 정상 실시, 변경후 실시 로직 안으로 옮기기
			if($('input[type=checkbox][id*=chk_cureDetail_]:checked').length>0){
				$('#modalStartSap').modal('show');	
				$('input#sapYes').prop('checked', true).trigger('change');
			}else{
				self.alert('투약내역을 선택해주세요.');
				return;
			};
			
		});
		
		$('#modalStartSap').on('show.bs.modal', function (e) {
			$('#dateStartSap')[0].value = self.util.toDatetimeLocal(new Date());
			$('#dateEndSap')[0].value = self.util.toDatetimeLocal(new Date());
			
			$('input[name="sapStatus"]').unbind();
			$('input[name="sapStatus"]').change(function(e){
				if(e.currentTarget.value=='N'){
					$('.disabled-sapYes').prop('disabled', true);
					$('.disabled-sapEnd').prop('disabled', true);
				}else if(e.currentTarget.value=='Y'){
					$('.disabled-sapYes').prop('disabled', false);
					$('.disabled-sapEnd').prop('disabled', true);
				}else{
					$('.disabled-sapYes').prop('disabled', true);
					$('.disabled-sapEnd').prop('disabled', false);
				};
			});
			
			$('#btnExecuteIvStart').unbind();
			$('#btnExecuteIvStart').click(function(){
				var actingData = actingList[$('input[type=checkbox][id*=chk_cureDetail_]:checked')[0].id.split('_')[2]];
				var patientInfo = JSON.parse(localStorage.patientInfo);
				
				var prepYn = '';
				if(actingData.OrdKindCd.trim()=='S' || actingData.OrdKindCd.trim()=='U' || actingData.OrdKindCd.trim()=='V' || actingData.OrdKindCd.trim()=='W'
					|| actingData.DrgOrdGb.trim()=='J' || actingData.DrgOrdGb.trim()=='R' || actingData.DrgOrdGb.trim()=='S' || actingData.DrgOrdGb.trim()=='D' || actingData.DrgOrdGb.trim()=='E'){
					if((actingData.OrdExecYmd==null || actingData.OrdExecYmd.trim()=='') && (actingData.OrdProgStus.trim()=='00' || actingData.OrdProgStus.trim()=='05')){
						prepYn = 'N';  
					}else if((actingData.OrdExecYmd!=null && actingData.OrdExecYmd.trim()!='') && (actingData.OrdProgStus.trim()=='00' || actingData.OrdProgStus.trim()=='05')){
						prepYn = 'Y';
					}else{
						prepYn = '';
					}
				}else{
					prepYn = '';
				};
				
				console.log({
					'userId': JSON.parse(localStorage.user).userId, 
					'chosNo': patientInfo.patientId,
					'grNo': actingData.OrdNo2 + '/'+actingData.DrgInjExecSeq + '/' + actingData.OrdYmd, //이게 맞는지?
					'actDt': moment($('#dateStartSap').val()).format('YYYYMMDD HHmm'),
					'msmtVal': $('#sapCapacity').val(),
					'RgtId': JSON.parse(localStorage.user).userId, 
					'patNm': patientInfo.patientNm,
					'ordYmd': actingData.OrdYmd,
					'ordSeq': actingData.OrdSeq,
					'ordNo': actingData.OrdNo,
					'drgInjExecSeq': actingData.DrgInjExecSeq,
					'injDuseQty': '0.000',
					'execStrYmd': moment($('#dateStartSap').val()).format('YYYYMMDD'),
					'execStrHm': moment($('#dateStartSap').val()).format('HHmm'),
					'ordTypCd': actingData.OrdTypCd2,
					'execYn': actingData.ExecGb,
					'hmChgResn': $('#sltChangeSap option:selected').val(),
					'basCapUnitNm': actingData.BasCapUnitNm,
					'drgInjExecQty': actingData.DrgInjExecQty,
					'drgInjExecQty1': '',
					'qty': actingData.Qty,
					'callLoc': '2',
					'chosGb': 'I',
					'ordProgLoc': localStorage.selectDeptCode,
					'cnYn': 'N',
					'prepYn': prepYn, 
					'vaccOrdCd': actingData.VaccOrdCd, 
					'vaccRegYn': actingData.VaccRegYn,
					'ordExecYmd': actingData.OrdExecYmd,
					'ordExecHms': '', //선택한 항목의 ordExecHms, OrdExecYmd밖에없는뎅????
					'execGb': actingData.ExecGb
				})
			});
		});
		
		$('#btnEndSap').unbind();
		$('#btnEndSap').click(function(){//이 if문을 나중에 정상 실시, 변경후 실시 로직 안으로 옮기기
			if($('input[type=checkbox][id*=chk_cureDetail_]:checked').length>0){
				/*$('#modalEndSap').modal('show');*/
				$('#modalStartSap').modal('show');
				$('input#sapEnd').prop('checked', true).trigger('change');
			}else{
				self.alert('투약내역을 선택해주세요.');
				return;
			};
			
		});
		
		$('#modalEndSap').on('show.bs.modal', function (e) {
			$('#dateEndSap')[0].value = self.util.toDatetimeLocal(new Date());
		});
	};
	
	var getCureList = function(duty){
		$('#cureDetailDataList').empty();
		
		var patientInfo = JSON.parse(localStorage.patientInfo);
		if(patientInfo.visitNo == undefined) return;
		var today = new Date();
		
		var startDt = '';
		var endDt = '';
		
		if($('#sltTimeType').val()=='current'){
			startDt = moment(today).format('HH')+'0000';
			endDt = moment(today).format('HH')+'5959';
		}else if($('#sltTimeType').val()=='special'){
			startDt = $('#sltTime').val()+'0000';
			endDt = $('#sltTime').val()+'5959';
		}else if($('#sltTimeType').val()=='noTime'){
			startDt = '000000';
			endDt = '235959';
		}else {
			if(6<=moment(today).format('HH')&& moment(today).format('HH')<=13){
				startDt = '060000';
				endDt = '135959';
			}else if(14<=moment(today).format('HH')&&moment(today).format('HH')<=21){
				startDt = '140000';
				endDt = '215959';
			}else{
				startDt = '220000';
				endDt = '055959';
			}
		}		
		
		var param = {
				'visitNo': patientInfo.visitNo,
				'ordSlipCd': $('#sltMedType').val(),
				'startDt': moment(today).format('YYYYMMDD'),
				'startTm':  startDt,
				'endDt': moment(today).format('YYYYMMDD'),
				'endTm': endDt,
				'userId': JSON.parse(localStorage.user).userId,
				'wardCd': patientInfo.wardCd
		};
		
		/*var param = {
				'visitNo': '90110301I00088',
				'ordSlipCd': 'A01',
				'startDt': '20180126',
				'startTm':  '120000',
				'endDt': '20180126',
				'endTm': '125959',
				'userId': '0722006',
				'wardCd': '63'
		};
		*/
		actingList = self.nursing.getActList(param);
		if( actingList.result != undefined ) {
			cureBinding(actingList.result, actingList.extraMsg);
		} else {
			self.alert('조회 실패');
		}
	};
	
	var cureBinding = function(actList, extraMsg){
		if( actList.length == 0 && extraMsg != 'null' ) {
			self.alert(extraMsg);
		}
		
		if(actList.length == 0) {
			$('#cureDetailDataList').append(li.clone().append(div.clone().addClass('text-center no-result').text('―')));
			return;
		}
		
		for(var i=0; i<actList.length; i++){
			var listGroupItem = div.clone().addClass('list-group-item not-active').attr('id', 'item_cureDetail_'+ i);
			var listRow = div.clone().addClass('list-row container');
			
			var divRow1 = div.clone().addClass('col-xs-12 col-sm-6 pd0');
			var divRow2 = div.clone().addClass('col-xs-12 col-sm-6 pd0');
			var listCheckboxWrap = div.clone().addClass('col-xs-1 col-sm-1 pdl5 pdr5');
			var actCheckbox = div.clone().addClass('checkbox3  checkbox-check checkbox-light pd0');
			var checkInput = input.clone().attr('type', 'checkbox').attr('id', 'chk_cureDetail_'+i);
			var checkLabel = label.clone().attr('for', 'chk_cureDetail_'+i);
			var listCheckbox = listCheckboxWrap.append(actCheckbox.append(checkInput).append(checkLabel));
			
			
			var executeTm = div.clone().addClass('col-xs-3 col-sm-2 pdl5 pdr5').append(actList[i].ExecHm);
			var no = div.clone().addClass('col-xs-3 col-sm-3 pd0 letter-control').append(actList[i].OrdNo + ' / '+actList[i].DrgInjExecSeq);
			var prtOrdNm = div.clone().addClass('col-xs-5 col-sm-6 pdl5 pdr5 letter-control').append(actList[i].PrtOrdNm);
			
			var row1 = divRow1.append(listCheckbox).append(executeTm).append(no).append(prtOrdNm);
			
			var empty = div.clone().addClass('col-xs-1 hidden-sm pdl5 pdr5').append('&nbsp;');
			var qty = div.clone().addClass('col-xs-3 col-sm-4 pdl5 pdr5').append(Number(actList[i].Qty) + actList[i].BasCapUnitNm +' ('+Number(actList[i].TQty)+')');
			var ordDsgCd = div.clone().addClass('col-xs-3 col-sm-3 pd0').append(actList[i].OrdDsgCd);
			var memo = div.clone().addClass('col-xs-5 col-sm-5 pdl5 pdr5 letter-control').append(actList[i].MedHmDesc  + actList[i].OrdDsgNm);
			
			var row2 = divRow2.append(empty).append(qty).append(ordDsgCd).append(memo);
			
			var actRow = li.clone().append(listGroupItem.append(listRow.append(row1).append(row2)));
			$('#cureDetailDataList').append(actRow);
		}
		
		$('#cureDetailDataList .list-group-item').unbind();
		$('#cureDetailDataList .list-group-item').click(function(e) {
			if( e.target.id.indexOf('chk_cureDetail') == 0 || (e.target.localName=='label' && e.target.htmlFor.indexOf('chk_cureDetail') == 0)) return;
			var targetId = e.currentTarget.id;
			targetId = targetId.replace('item', 'chk');
			$('#' + targetId).click();
		});
	};
	//------------------------------------약실시 탭 종료---------------------------------------
};
