/**
 * consent
 */
var mplus_mobile_consent = function(){
	mcare_mobile.call(this);
	
	var div = $("<div></div>");
	var tr = $("<tr></tr>");
	var th = $("<th></th>");
	var td = $("<td></td>");
	var table = $("<table></table>");
	var li = $("<li></li>");
	var a = $("<a></a>");
	var span = $("<span></span>");
	
	
	var $ulPatientList = $('#ulPatientList');
	
	var self = this;
	
	$serviceBaseUrl = contextPath + "/mobile";
	$hospitalServiceBaseUrl = contextPath + "/mobile/hospital";
	$consentServiceBaseUrl = contextPath + "/mobile/consent";

	this.hospital = {
		//부서리스트
		getDeptList : function(request){
			var deptList = [];
			$.ajax ({
				  url : $hospitalServiceBaseUrl + '/getDeptList.json',
				  type : 'POST',
				  dataType: "json",
				  contentType: "application/json",
				  async: false,
				  data: JSON.stringify(request),
				  success: function(response){
					  deptList = response.result;
				  }
			});
			return deptList;
		},
		
		//의사리스트
		getDoctorList : function(request){
			var doctorList = [];
			$.ajax ({
				  url : $hospitalServiceBaseUrl + '/getDoctorList.json',
				  type : 'POST',
				  dataType: "json",
				  contentType: "application/json",
				  async: false,
				  data: JSON.stringify(request),
				  success: function(response){
					  doctorList = response.result;
				  }
			});
			return doctorList;
		},
		
		//병동리스트
		getWardList : function(){
			var wardList = [];
			$.ajax ({
				  url : $hospitalServiceBaseUrl + '/getWardList.json',
				  type : 'POST',
				  dataType: "json",
				  contentType: "application/json",
				  async: false,
				  data: JSON.stringify({}),
				  success: function(response){
					  wardList = response.result;
				  }
			});
			return wardList;
		},
	
		// 환자정보조회
		getPatientInfo : function(request){
			var patientInfoList = [];
			$.ajax ({
				  url : $hospitalServiceBaseUrl + '/getPatientInfo.json',
				  type : 'POST',
				  dataType: "json",
				  contentType: "application/json",
				  async: false,
				  data: JSON.stringify(request),
				  success: function(response){
					  if( response.msg != undefined ) {
						  self.alert(response.msg);
						  return;
					  } else {
						  patientInfoList = response.result;
					  }
				  }
			});
			return patientInfoList;
		}
	};
	
	this.patient = {
			//환자리스트 조회
			getPatientList : function(type, request, firstYn){
				var requestUrl = getPatientListUrl(type);
				// url이 안넘어왔을 때 (type을 잘못입력)
				if (requestUrl == undefined) {
					alert('잘못된 요청입니다.');
					return;
				};				
				patientList = [];
				$ulPatientList.empty();
				$.ajax ({
					  url : requestUrl,
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  beforeSend: function(){
							self.loading("show");  
					  },
					  data: JSON.stringify(request)
				  }).done(function(response){
					  self.loading("hide");
					  result = response.result
					  patientList = result;
					  if(firstYn!='Y'&&(result==undefined||result.length==0)) {
						  self.loading("hide");
						  self.alert('조회된 데이터가 없습니다.');
						  return;
					  };
					  self.patient.setPatientList(type, result, "", "");
				  });
			},
			setPatientList : function(type, list, sortKey, sortType, order){
				patientList = [];
				$ulPatientList.empty();
				
				result = sortKey==""? list: self.util.sortObj(list, sortKey, sortType, order);
				patientList = result;
				
				if(type=='I'){
					for(var i=0; i<result.length; i++){
						var aItem = a.clone().addClass("list-group-item").attr("seq", i);
						var divListRow = div.clone().addClass("list-row");
						var spanItem = span.clone().addClass("num").text(result[i].pid),
							spanItem2 = span.clone().addClass("name").text(result[i].deptnm),
							spanItem3 = span.clone().addClass("period").text(result[i].doctornm),
							divItem = divListRow.clone().html(spanItem).append(spanItem2).append(spanItem3);
						
						var spanItem4 = span.clone().addClass("num").text(result[i].sa),
							spanItem5 = span.clone().addClass("name").text(result[i].hngnm),
							spanItem6 = span.clone().addClass("period").text(result[i].roomcd),
							divItem2 = divListRow.clone().html(spanItem4).append(spanItem5).append(spanItem6);
						$ulPatientList.append(li.clone().html(aItem.clone().html(divItem).append(divItem2)).attr("id", "patient_"+i));
					};
				  }else if(type=='O'){
						for(var i=0; i<result.length; i++){
							var aItem = a.clone().addClass("list-group-item").attr("seq", i);
							var divListRow = div.clone().addClass("list-row");
							var spanItem = span.clone().addClass("num").text(result[i].pid),
								spanItem2 = span.clone().addClass("name").text(result[i].deptnm),
								spanItem3 = span.clone().addClass("period").text(result[i].doctornm),
								divItem = divListRow.clone().html(spanItem).append(spanItem2).append(spanItem3);
									
							var spanItem4 = span.clone().addClass("num").text(result[i].sa),
								spanItem5 = span.clone().addClass("name").text(result[i].hngnm),
								divItem2 = divListRow.clone().html(spanItem4).append(spanItem5);
							$ulPatientList.append(li.clone().html(aItem.clone().html(divItem).append(divItem2)).attr("id", "patient_"+i));
						};
				  }else if(type=='E'){
					  for(var i=0; i<result.length; i++){
							var aItem = a.clone().addClass("list-group-item").attr("seq", i);
							var divListRow = div.clone().addClass("list-row");
							var spanItem = span.clone().addClass("num").text(result[i].pid),
							spanItem2 = span.clone().addClass("name").text(result[i].erorddeptnm),
							spanItem3 = span.clone().addClass("period").text(result[i].ermedispclnm),
							divItem = divListRow.clone().html(spanItem).append(spanItem2).append(spanItem3);
	
							var spanItem4 = span.clone().addClass("num").text(result[i].sa),
							spanItem5 = span.clone().addClass("name").text(result[i].hngnm),
							spanItem6 = span.clone().addClass("period").text(result[i].badcd),
							divItem2 = divListRow.clone().html(spanItem4).append(spanItem5).append(spanItem6);
							$ulPatientList.append(li.clone().html(aItem.clone().html(divItem).append(divItem2)));
						};
				  }else if(type=='OP'){
					  for(var i=0; i<result.length; i++){
							var aItem = a.clone().addClass("list-group-item").attr("seq", i);
							var divListRow = div.clone().addClass("list-row");
							var spanItem = span.clone().addClass("num").text(result[i].pid),
							spanItem2 = span.clone().addClass("name").text(result[i].deptnm),
							spanItem3 = span.clone().addClass("period").text(moment(result[i].opcnfmdd).format('YYYY/MM/DD')),
							divItem = divListRow.clone().html(spanItem).append(spanItem2).append(spanItem3);
	
							var spanItem4 = span.clone().addClass("num").text(result[i].sa),
							spanItem5 = span.clone().addClass("name").text(result[i].hngnm),
							spanItem6 = span.clone().addClass("period").text(result[i].oproomnm),
							divItem2 = divListRow.clone().html(spanItem4).append(spanItem5).append(spanItem6);
							$ulPatientList.append(li.clone().html(aItem.clone().html(divItem).append(divItem2)));
						};
				  }else if(type=='SR'){
					  for(var i=0; i<result.length; i++){
							var aItem = a.clone().addClass("list-group-item").attr("seq", i);
							var divListRow = div.clone().addClass("list-row");
								var spanItem = span.clone().addClass("num").text(result[i].pid),
									spanItem2 = span.clone().addClass("name").text(result[i].deptnm),
									spanItem3 = span.clone().addClass("period").text(result[i].doctornm),
								divItem = divListRow.clone().html(spanItem).append(spanItem2).append(spanItem3);
							
								var spanItem4 = span.clone().addClass("num").text(result[i].sa),
									spanItem5 = span.clone().addClass("name").text(result[i].hngnm),
									spanItem6 = span.clone().addClass("period").text(result[i].indd),
								divItem2 = divListRow.clone().html(spanItem4).append(spanItem5).append(spanItem6);
								$ulPatientList.append(li.clone().html(aItem.clone().html(divItem).append(divItem2)).attr("id", "patient_"+i));
						};
				  };
				  $('#ulPatientList .list-group-item').on("click", function(e){
						$('#ulPatientList a').removeClass('active');
						$(this).addClass('active');
						
						// 환자 리스트에서 환자 변경 시, 우측의 동의서 찾기 또는 즐겨찾기에서 이전 환자 동의서 선택 해제 2017.04.13 고객요구사항반영
						$('#ulConsentList input[type="checkbox"]:checked').prop('checked', false);
						$('#ulConsentList li.checked').removeClass('checked');
						$('#ulSetList input[type="checkbox"]:checked').prop('checked', false);
						$('#ulSetList li.checked').removeClass('checked');
						
						getPatientInfo(e.currentTarget.attributes.seq.value);
				  });
			}
	};
	
	this.consent = {
			//동의서조회
			getConsentList : function(request){
				var consentList = [];
				$.ajax ({
					  url : $consentServiceBaseUrl + '/getConsentList.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  consentList = response.result;
					  }
				});
				return consentList;
			},
			
			//동의서 검색
			getConsentBySearch: function(request){
				var consentList = [];
				
				$.ajax ({
					  url : $consentServiceBaseUrl + '/getConsentBySearch.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  consentList = response.result;
					  }
				});
				
				return consentList;
			},
			//동의서 set조회
			getConsentSetList: function(request){
				var consentList = [];
				
				$.ajax ({
					  url : $consentServiceBaseUrl + '/set/getConsentSetList.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  consentList = response.result;
					  }
				});
				
				return consentList;
			},
			
			//동의서 즐겨찾기 추가
			setUserFormSetList: function(request){
				var result = {};
				$.ajax ({
					  url : $consentServiceBaseUrl + '/set/setUserFormSetList.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  result = response.result;
					  }
				});
				
				return result;
			},
			
			//동의서 즐겨찾기 삭제
			delUserFormSetList: function(request){
				var result = {};
				$.ajax ({
					  url : $consentServiceBaseUrl + '/set/delUserFormSetList.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  result = response.result;  
						  	
					  }
				});
				
				return result;
			},
			
			//동의서 삭제
			delConsent: function(request){
				var result = {};
				$.ajax ({
					  url : $consentServiceBaseUrl+'/save/saveDelete.json',
					  type : 'POST', 
					  contentType: "application/json", 
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  result = response.result;  	
					  }
				});
				return result;
			},
			
			//ocr Tag 할당
			getOcrTag: function(){
				var result = '';
				$.ajax ({
					  url : $consentServiceBaseUrl + '/getOcrTag.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  data: JSON.stringify({}),
					  async: false,
					  success: function(response){
						  result = response.result;  
					  }
				});
				
				return result;
			},
			
			//카테고리리스트 조회
			getCategoryForDropdown: function(request){
				var categoryList = [];
				
				$.ajax ({
					  url : $consentServiceBaseUrl + '/getCategoryForDropdown.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  categoryList = response.result;
					  }
				});
				
				return categoryList;
			},
			
			//주치의별 동의서 검색
			getUnfinishedListPerDoctor: function(request){
				var consentList = [];
				$.ajax ({
					  url : $consentServiceBaseUrl + '/getUnfinishedListPerDoctor.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  consentList = response.result;
					  }
				});
				
				return consentList;
			},
			
			// 동의서 이미지 정보 조회 
			getConsentImage: function(request){
				var consentImageList = [];
				
				$.ajax ({
					  url : $consentServiceBaseUrl + '/getConsentImage.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  consentImageList = response.result;
					  }
				});
				
				return consentImageList;
			},
			
			// 동의서 상태 체크
			checkConsentState: function(request){
				var state;
				
				$.ajax ({
					  url : $consentServiceBaseUrl + '/checkConsentState.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  state = response.result;
					  }
				});
				
				return state;
			},
			
			makeConsentStateParam: function() {
				// 체크된 박스들
				var checkedStatus = $('.consentSearchBox input:checked[id!="chkboxConsentSign"]');
				// 체크된게 없으면 일단 이렇게 처리
				if( checkedStatus.length == 0 ) {
					self.alert('동의서 상태 조건을 선택하세요!');
					return;
					// 더이상 동의서 조회가 진행되지 않도록 하기
				}
				var consentStatus = '';
				for(var i = 0; i < checkedStatus.length; i++) {
					// 전체가 체크된 경우 뒤도 돌아보지않고 ALL만 리턴하도록
					if( checkedStatus[i].value == 'ALL') {
						consentStatus = checkedStatus[i].value;
						return consentStatus;
					} else {
						consentStatus = consentStatus + checkedStatus[i].value;
					}
					// 콤마 구분자 추가
					if(i != checkedStatus.length - 1) {
						consentStatus = consentStatus + ',';
					}
				}
				return consentStatus;
			},
			
			// 앱으로 넘겨줄 동의서 리스트 파라메터 만들기 - 작성중 기준
			makeConsentParam: function(patientInfo, consentList, userName) {
				// 유효성 검사 추가하기
				var consent = [];

				for( var i = 0; i < consentList.length; i++ ) {
					var unfinishedConsent = false;
					if( consentList[i].consentState == 'UNFINISHED' ) {
						unfinishedConsent = true;
					} 
					
					var consentItem = {
							newConsent : unfinishedConsent? true: false,
							hospitalCretno: patientInfo.iocretNo,
							ward: patientInfo.ioward==null? "":patientInfo.ioward,
							roomNo: patientInfo.ioroomNo==null? "": patientInfo.ioroomNo,
							orderNo: consentList[i].orderNo,
							orderCd: consentList[i].orderCd==null?"":consentList[i].orderCd,
							IO_ocr_cd: consentList[i].ocrNumber==null?"":consentList[i].ocrNumber,
							consentCretno: consentList[i].cretno,
							outDate: patientInfo.iodschdd==null?"":patientInfo.iodschdd,
							mainDrId: patientInfo.iomaindrId==null?"":patientInfo.iomaindrId,
							consentState: consentList[i].consentState,
									
							rid: consentList[i].consentMstRid,
							IO_formname: consentList[i].consentName,
							IO_INPUTNM: userName,

							formCd: consentList[i].formCd,
							formRid: consentList[i].formRid,
							
							IO_Pt_ID: patientInfo.ioptID==null? "": patientInfo.ioptID,
							IO_sex_age_y_m: patientInfo.iosexAgeYM==null? "": patientInfo.iosexAgeYM,
							IO_Pt_name: patientInfo.ioptName==null? "": patientInfo.ioptName,
							IO_JuminNo: patientInfo.iojuminNo==null? "": patientInfo.iojuminNo,
							IO_PT_birthday: patientInfo.iojuminNo==null? "": patientInfo.iojuminNo.split('-')[0],
							IO_ADdate: patientInfo.ioaddate==null? "": moment(patientInfo.ioaddate).format('YYYY/MM/DD'),
							IO_Dept: patientInfo.iodeptNm==null? "": patientInfo.iodeptNm,
							//2017.07.03 병원요청으로 dept2데이터추가
							IO_Dept2: patientInfo.iodept2==null? "": patientInfo.iodept2,
							IO_DeptCd: patientInfo.iodeptCd==null? "": patientInfo.iodeptCd,
							IO_OPdept: patientInfo.ioopdeptNm==null? "": patientInfo.ioopdeptNm,
							IO_OPdr: patientInfo.ioopdrNm==null? "": patientInfo.ioopdrNm,
							IO_Dx: patientInfo.iodxNm==null? "": patientInfo.iodxNm,
							IO_bp: patientInfo.iobp==null? "": patientInfo.iobp,
							IO_dm: patientInfo.iodm==null? "": patientInfo.iodm,  
							IO_heart: patientInfo.ioheart==null? "": patientInfo.ioheart,
							IO_kidney: patientInfo.iokidney==null? "": patientInfo.iokidney,
							IO_respiration: patientInfo.iorespiration==null? "": patientInfo.iorespiration,
							IO_hx: patientInfo.iohx==null? "": patientInfo.iohx,
							IO_allergy: patientInfo.ioallergy==null? "": patientInfo.ioallergy,
							IO_drug: patientInfo.iodrug==null? "": patientInfo.iodrug,
							IO_smoking: patientInfo.iosmoking==null? "": patientInfo.iosmoking,
							IO_idio: patientInfo.ioidio==null? "": patientInfo.ioidio,
							IO_nacrotics: patientInfo.ionacrotics==null? "": patientInfo.ionacrotics,
							IO_airway: patientInfo.ioairway==null? "": patientInfo.ioairway,
							IO_hemorrhage: patientInfo.iohemorrhage==null? "": patientInfo.iohemorrhage,
							IO_status_etc: patientInfo.iostatusEtc==null? "": patientInfo.iostatusEtc
					}
					
					if( unfinishedConsent ) {
						consentItem.guid = consentList[i].formGuid;
					}
					
					if(consentItem.ward.length > 0 && consentItem.roomNo.length > 0) {
						consentItem.IO_roomNo = consentItem.ward + '/' + consentItem.roomNo;
					} else {
						consentItem.IO_roomNo = "";
					}
					
					// 외래>소화기내과인 경우 시술의,수술의 설정. 2017/1/3 고객요구사항
					if(patientInfo.iovisitType == 'O' && patientInfo.iodeptCd == '2010300000') {
						consentItem.IO_OPdr = patientInfo.iomaindrNm;
					}

					consent.push(consentItem);
				}
				
				return consent;
			},
			
			// 앱으로 넘겨줄 동의서 리스트 파라메터 만들기 - 신규 기준
			makeNewConsentParam: function(patientInfo, consentList, userName) {
				// 유효성 검사 추가하기
				var consent = [];
				//ocrTagYn체크해서 넣어주기
				for( var i = 0; i < consentList.length; i++ ) {
					var ocrtag = "";
					//if(consentList[i].printOnly=="N"){ //전부 N일테니 조건따위 필요하지않아!!*/
						ocrtag = this.getOcrTag().text;
					//} 
					var consentItem = {
							newConsent : true,
							hospitalCretno: patientInfo.iocretNo,
							ward: patientInfo.ioward==null? "":patientInfo.ioward,
							roomNo: patientInfo.ioroomNo==null? "": patientInfo.ioroomNo,
							IO_ocr_cd: ocrtag,
							outDate: patientInfo.iodschdd==null?"":patientInfo.iodschdd,
							mainDrId: patientInfo.iomaindrId==null?"":patientInfo.iomaindrId,

							guid: consentList[i].formGuid,
							IO_formname: consentList[i].formName,
							IO_INPUTNM: userName,
							
							formCd: consentList[i].formCd,
							formRid: consentList[i].formRid,
							
							IO_Pt_ID: patientInfo.ioptID==null? "": patientInfo.ioptID,
							IO_sex_age_y_m: patientInfo.iosexAgeYM==null? "": patientInfo.iosexAgeYM,
							IO_Pt_name: patientInfo.ioptName==null? "": patientInfo.ioptName,
							IO_JuminNo: patientInfo.iojuminNo==null? "": patientInfo.iojuminNo,
							IO_PT_birthday: patientInfo.iojuminNo==null? "": patientInfo.iojuminNo.split('-')[0],
							IO_roomNo: patientInfo.ioroomNo==null? "": patientInfo.ioroomNo,
							IO_ADdate: patientInfo.ioaddate==null? "": moment(patientInfo.ioaddate).format('YYYY/MM/DD'),
							IO_Dept: patientInfo.iodeptNm==null? "": patientInfo.iodeptNm,
							//2017.07.03 병원요청으로 dept2데이터추가 
							IO_Dept2: patientInfo.iodept2==null? "": patientInfo.iodept2,
							IO_DeptCd: patientInfo.iodeptCd==null? "": patientInfo.iodeptCd,
							IO_OPdept: patientInfo.ioopdeptNm==null? "": patientInfo.ioopdeptNm,
							IO_OPdr: patientInfo.ioopdrNm==null? "": patientInfo.ioopdrNm,
							IO_Dx: patientInfo.iodxNm==null? "": patientInfo.iodxNm,
							IO_bp: patientInfo.iobp==null? "": patientInfo.iobp,
							IO_dm: patientInfo.iodm==null? "": patientInfo.iodm,  
							IO_heart: patientInfo.ioheart==null? "": patientInfo.ioheart,
							IO_kidney: patientInfo.iokidney==null? "": patientInfo.iokidney,
							IO_respiration: patientInfo.iorespiration==null? "": patientInfo.iorespiration,
							IO_hx: patientInfo.iohx==null? "": patientInfo.iohx,
							IO_allergy: patientInfo.ioallergy==null? "": patientInfo.ioallergy,
							IO_drug: patientInfo.iodrug==null? "": patientInfo.iodrug,
							IO_smoking: patientInfo.iosmoking==null? "": patientInfo.iosmoking,
							IO_idio: patientInfo.ioidio==null? "": patientInfo.ioidio,
							IO_nacrotics: patientInfo.ionacrotics==null? "": patientInfo.ionacrotics,
							IO_airway: patientInfo.ioairway==null? "": patientInfo.ioairway,
							IO_hemorrhage: patientInfo.iohemorrhage==null? "": patientInfo.iohemorrhage,
							IO_status_etc: patientInfo.iostatusEtc==null? "": patientInfo.iostatusEtc
					}
					
					if(consentItem.ward.length > 0 && consentItem.roomNo.length > 0) {
						consentItem.IO_roomNo = consentItem.ward + '/' + consentItem.roomNo;
					} else {
						consentItem.IO_roomNo = "";
					}
					
					// 외래>소화기내과인 경우 시술의,수술의 설정. 2017/1/3 고객요구사항
					if(patientInfo.iovisitType == 'O' && patientInfo.iodeptCd == '2010300000') {
						consentItem.IO_OPdr = patientInfo.iomaindrNm;
					}
					
					consent.push(consentItem);
				}
				
				return consent;
			},
			
			// 앱으로 넘겨줄 global 파라메터 만들기
			makeGlobalParam: function(patientInfo, signDoctorId) {
				// 유효성 검사 추가하기
				if(patientInfo == undefined) return;
				
				// 현재 일시 계산
				var currentTime = new Date();
				var timeText = dateTimeFormat(currentTime);
				
				var param = {userid : signDoctorId};
				var result = this.getSignImage(param);
				var signImage = '';
				
				if(result != undefined) {
					if(result.signImage != null && result.signImage != '') {
						signImage = result.signImage;
					}
				}
				
				var global = {
						IO_device: "M",
						visitType: patientInfo.iovisitType,
						IO_signdate: timeText,
						IO_signtime: timeText,
						IO_printtime: timeText,
						IO_maindr: patientInfo.iomaindrNm==null? "": patientInfo.iomaindrNm,
						IO_SIGNIMG: signImage
				}
				
				// 2017.8.22 이전 작업)) 응급일 경우 ioerdrNm에 실제 주치의가 들어오기때문에 이걸로 변경해줌.
				// 2017.8.22 - 응급인 경우 조건 추가 (기존에 visitType 체크가 없어서 응급통해서 입원한경우(?) 문제됨)
				// 병원 담당자 확인 받고 작업한 내용임
				if( patientInfo.iovisitType == 'E' && patientInfo.ioerdrNm != null) {
					global.IO_maindr = patientInfo.ioerdrNm;
				}
				
				return global;
			},
			
			// 의사 서명 이미지 정보 조회
			getSignImage : function(request){
				var signImage;
				$.ajax ({
					  url : $hospitalServiceBaseUrl + '/getSignImage.json',
					  type : 'POST',
					  dataType: "json",
					  contentType: "application/json",
					  async: false,
					  data: JSON.stringify(request),
					  success: function(response){
						  signImage = response.result;
					  }
				});
				return signImage;
			}
	};
	
	// 환자리스트 URL 리턴
	// 입원: I, 외래: O, 응급: E, 수술: OP, 검색: SR
	function getPatientListUrl(type) {
		switch (type) {
		case 'I' :
			return $serviceBaseUrl + '/in/getInPatList.json';
		case 'O' :
			return $serviceBaseUrl + '/out/getOutPatList.json';
		case 'E' :
			return $serviceBaseUrl + '/er/getErPatList.json';
		case 'OP' :
			return $serviceBaseUrl + '/op/getOpPatList.json';
		case 'SR' :
			return $serviceBaseUrl + '/search/getSrPatList.json';
		default:
			return;
		}
	}
	
	function dateTimeFormat(date) {
		try{
			var yyyy = date.getFullYear().toString(),
				mm = (date.getMonth()+1).toString(),
				dd  = date.getDate().toString(),
				hh = date.getHours().toString(),
				mi = date.getMinutes().toString(),
				ss = date.getSeconds().toString(),
				
				text =  yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]) + " " 
					+ (hh[1]?hh:"0"+hh[0]) + ":" + (mi[1]?mi:"0"+mi[0]) + ":" + (ss[1]?ss:"0"+ss[0]) ; 
			
			
			return text;
		} catch(e) {
			self.log(e, "mcare_util_simpleDateFormat" );
		}
	}
};

//환자 나이정보 리턴
function editAgeToIdNum(idNum){
	var sex = '';
	var ageYm = '';
	var age = '';
	//성별과 나이 분리
	if(idNum.indexOf('/')>0){
		 sex = idNum.split('/')[0];
		 ageYm = idNum.split('/')[1];
	}else{
		ageYm = idNum;
	};
	//나이 가공
	if(ageYm.indexOf('y')>0){
		age = ageYm.split('y')[0];
	}else if(ageYm.indexOf('m')>0||ageYm.indexOf('d')>0){
		age = 0;
	}else{
		age = ageYm;
	};
	
	return sex + '/' + age;
};