package com.dbs.mcare.web.controller;

import javax.validation.Valid;
import javax.xml.namespace.QName;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dbs.mcare.web.request.hospital.DelUserFormSetList;
import com.dbs.mcare.web.request.hospital.GetConsentSetList;
import com.dbs.mcare.web.request.hospital.GetDeptList;
import com.dbs.mcare.web.request.hospital.GetDiagNameList;
import com.dbs.mcare.web.request.hospital.GetDoctorList;
import com.dbs.mcare.web.request.hospital.GetErPatList;
import com.dbs.mcare.web.request.hospital.GetFileName;
import com.dbs.mcare.web.request.hospital.GetInPatList;
import com.dbs.mcare.web.request.hospital.GetOcrTag;
import com.dbs.mcare.web.request.hospital.GetOpPatList;
import com.dbs.mcare.web.request.hospital.GetOutPatList;
import com.dbs.mcare.web.request.hospital.GetPatientInfo;
import com.dbs.mcare.web.request.hospital.GetSignImage;
import com.dbs.mcare.web.request.hospital.GetSrPatList;
import com.dbs.mcare.web.request.hospital.GetSrchPatInfo;
import com.dbs.mcare.web.request.hospital.GetTrmtDateList;
import com.dbs.mcare.web.request.hospital.GetUserInfo;
import com.dbs.mcare.web.request.hospital.GetWardList;
import com.dbs.mcare.web.request.hospital.InsertPrintData;
import com.dbs.mcare.web.request.hospital.SetUserFormSetList;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfClnDateForDropdownVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfConsentSetVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfDeptListVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfDocListVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfPatInfoListVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfPatListVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfPatientVO;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfString;
import com.dbs.mplus.fatimadeagu.inf.ArrayOfUnFinishedListVO;
import com.dbs.mplus.fatimadeagu.inf.GetUnfinishedListPerDoctor;
import com.dbs.mplus.fatimadeagu.inf.HospitalSvc;
import com.dbs.mplus.fatimadeagu.inf.HospitalSvcSoap;
import com.dbs.mplus.fatimadeagu.inf.UpdateUserSetup;
import com.dbs.mplus.fatimadeagu.inf.UserSignImageVO;
import com.dbs.mplus.fatimadeagu.inf.UserVO;

@RestController
@RequestMapping("/hospital")
public class HospitalController {

	private final QName serviceName = new QName("http://tempuri.org/", "HospitalSvc");

	private final HospitalSvc hospitalSvc = new HospitalSvc(HospitalSvc.WSDL_LOCATION, serviceName);

	/**
	 * GetUserInfo	사용자 상세정보 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getUserInfo")
	public UserVO getUserInfo(@RequestBody @Valid GetUserInfo p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        UserVO user = port.getUserInfo(p.getUserNo());
        return user;
	}

	/**
	 * GetTrmtDateList	환자 진료일 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getTrmtDateList")
	public ArrayOfClnDateForDropdownVO getTrmtDateList(@RequestBody @Valid GetTrmtDateList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
		ArrayOfClnDateForDropdownVO arrayOfClnDateForDropdownVO = port.getTrmtDateList(p.getPatientNo(), p.getSearchClnDate(), p.getSearchType(), p.getOrddeptcd());
		return arrayOfClnDateForDropdownVO;
	}
	
	/**
	 * GetInPatList	입원탭 환자리스트 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getInPatList")
	public ArrayOfPatListVO getInPatList(@RequestBody @Valid GetInPatList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatListVO arrayOfPatListVO = port.getInPatList(p.getSrchdd(), p.getOrddeptcd(), p.getDoctorid(), p.getPid(), p.getWardcd(), p.getPatstat(), p.getJobkindcd());
        return arrayOfPatListVO;
	}
	
	/**
	 * GetOutPatList	외래탭 환자리스트 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getOutPatList")
	public ArrayOfPatListVO getOutPatList(@RequestBody @Valid GetOutPatList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatListVO arrayOfPatListVO = port.getOutPatList(p.getSrchdd(), p.getOrddeptcd(), p.getDoctorid(), p.getPid(), p.getPatstat());
        return arrayOfPatListVO;
	}
	
	/**
	 * GetOpPatList	수술탭 환자리스트 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getOpPatList")
	public ArrayOfPatListVO getOpPatList(@RequestBody @Valid GetOpPatList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatListVO arrayOfPatListVO = port.getOpPatList(p.getSrchdd(), p.getOrddeptcd(), p.getDoctorid(), p.getPid(), p.getPatstat());
        return arrayOfPatListVO;
	}

	/**
	 * GetErPatList	응급탭 환자 리스트 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getErPatList")
	public ArrayOfPatListVO getErPatList(@RequestBody @Valid GetErPatList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatListVO arrayOfPatListVO = port.getErPatList(p.getSrchdd(), p.getOrddeptcd(), p.getDoctorid(), p.getPid(), p.getPatstat(), p.getJobkindcd());
        return arrayOfPatListVO;
	}
	
	/**
	 * GetSrPatList	환자검색탭환자 리스트 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getSrPatList")
	public ArrayOfPatListVO getSrPatList(@RequestBody @Valid GetSrPatList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatListVO arrayOfPatListVO = port.getSrPatList(p.getSrchdd(), p.getOrddeptcd(), p.getDoctorid(), p.getPid(), p.getOrdtype());
        return arrayOfPatListVO; 
	}
	
	/**
	 * GetDeptList	환자리스트 조회조건 중 진료과 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getDeptList")
	public ArrayOfDeptListVO getDeptList(@RequestBody @Valid GetDeptList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfDeptListVO arrayOfDeptListVO = port.getDeptList(p.getOrdtype());
        return arrayOfDeptListVO;
        
	}
	
	/**
	 * GetWardList	환자리스트 조회조건 중 병동 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getWardList")
	public ArrayOfDeptListVO getWardList(@RequestBody @Valid GetWardList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
		ArrayOfDeptListVO arrayOfDeptListVO = port.getWardList();
		return arrayOfDeptListVO;
	}
	
	/**
	 * GetDoctorList	환자리스트 조회조건 중 의사 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getDoctorList")
	public ArrayOfDocListVO getDoctorList(@RequestBody @Valid GetDoctorList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfDocListVO arrayOfDocListVO = port.getDoctorList(p.getSrchdd(), p.getOrddeptcd());
        return arrayOfDocListVO;
	}
	
	/**
	 * GetSrchPatInfo	환자리스트 조회조건 중 환자 검색 팝업
	 * @param p
	 * @return
	 */
	@RequestMapping("/getSrchPatInfo")
	public ArrayOfPatInfoListVO getSrchPatInfo(@RequestBody @Valid GetSrchPatInfo p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatInfoListVO arrayOfPatInfoListVO = port.getSrchPatInfo(p.getSrchcond(), p.getPid(), p.getHngnm(), p.getRrgstno1(), p.getRrgstno2());
        return arrayOfPatInfoListVO;
	}

	/**
	 * GetPatientInfo	환자 선택시 수진일자별 진단 데이터 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getPatientInfo")
	public ArrayOfPatientVO getPatientInfo(@RequestBody @Valid GetPatientInfo p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfPatientVO arrayOfPatientVO = port.getPatientInfo(p.getPid(), p.getOrddd(), p.getOrdtype(), p.getOrddeptcd(), p.getCretno());
        return arrayOfPatientVO;
	}
	
	/**
	 * GetConsentSetList	동의서 SET 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getConsentSetList")
	public ArrayOfConsentSetVO getConsentSetList(@RequestBody @Valid GetConsentSetList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfConsentSetVO arrayOfConsentSetVO = port.getConsentSetList(p.getUserNo());
        return arrayOfConsentSetVO;
	}

	/**
	 * SetUserFormSetList	사용자 즐겨찾기 추가
	 * @param p
	 */
	@RequestMapping("/setUserFormSetList")
	public SetUserFormSetList setUserFormSetList(@RequestBody @Valid SetUserFormSetList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        port.setUserFormSetList(p.getUserid(), p.getFormcd());
        
        SetUserFormSetList setUserFormSetList = new SetUserFormSetList();
        setUserFormSetList.setFormcd(p.getFormcd());
        setUserFormSetList.setUserid(p.getUserid());
        return setUserFormSetList;
        
	}

	/**
	 * DelUserFormSetList	사용자 즐겨찾기 삭제
	 * @param p
	 */
	@RequestMapping("/delUserFormSetList")
	public DelUserFormSetList delUserFormSetList(@RequestBody @Valid DelUserFormSetList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        port.delUserFormSetList(p.getUserid(), p.getFormcd());
        
        DelUserFormSetList delUserFormSetList = new DelUserFormSetList();
        delUserFormSetList.setFormcd(p.getFormcd());
        delUserFormSetList.setUserid(p.getUserid());
        return delUserFormSetList;
	}

	/**
	 * GetOcrTag	OCRTAG 할당
	 * @param p
	 * @return
	 */
	@RequestMapping("/getOcrTag")
	public String getOcrTag(@RequestBody @Valid GetOcrTag p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
		String octTag = port.getOcrTag();
		return octTag;
	}

	/**
	 * GetSignImage	사용자의 서명이미지 조회
	 * @param p
	 * @return
	 */
	@RequestMapping("/getSignImage")
	public UserSignImageVO getSignImage(@RequestBody @Valid GetSignImage p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        UserSignImageVO userSignImageVO = port.getSignImage(p.getUserid());
        if( userSignImageVO == null ) {
        	userSignImageVO = new UserSignImageVO();
        }
        return userSignImageVO;
	}

	/**
	 * GetDiagNameList	주,부 진단명 리스트 조회(진단명 팝업)
	 * @param p
	 * @return
	 */
	@RequestMapping("/getDiagNameList")
	public ArrayOfString getDiagNameList(@RequestBody @Valid GetDiagNameList p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        ArrayOfString arrayOfString = port.getDiagNameList(p.getPid(), p.getOrddd());
        return arrayOfString;
	}

	/**
	 * insertPrintData	출력시 insert 시키는 함수
	 * @param p
	 */
	/*@RequestMapping("/insertPrintData")
	public void insertPrintData(@RequestBody @Valid InsertPrintData p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        port.insertPrintData(p.getOcrtag(), p.getPid(), p.getOrdtype(), p.getOrddd(), p.getCretno(), p.getOrddrid(), p.getOrddeptcd(), p.getFormcd(), p.getFstprntdt(), p.getFstprntdeptcd(), p.getFstprntid(), p.getPrntcnt());
	}*/
	
	/**
	 * updateUserSetup 로그인 후 첫 화면 코드 셋팅 - 외래: O 입원: I 응급: E 수술: P
	 * @param p
	 */
	@RequestMapping("/updateUserSetup")
	public UpdateUserSetup updateUserSetup(@RequestBody @Valid UpdateUserSetup p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
        port.updateUserSetup(p.getUserid(), p.getStatus());
        return p;
	}
	
	/**
	 * GetUnfinishedListPerDoctor 주치의별 동의서 리스트
	 * @param p
	 * @return
	 */
	@RequestMapping("/getUnfinishedListPerDoctor")
	public ArrayOfUnFinishedListVO getUnfinishedListPerDoctor(@RequestBody @Valid GetUnfinishedListPerDoctor p) {
		HospitalSvcSoap port = hospitalSvc.getHospitalSvcSoap12();
		ArrayOfUnFinishedListVO arrayOfUnfinishedListVo = port.getUnfinishedListPerDoctor(p.getUserid(), p.getStatus(), p.getFromdd(), p.getTodd());
		return arrayOfUnfinishedListVo;
	}
}