package com.dbs.consentServer.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

import com.dbs.consentServer.mapper.HospitalMapper;
import com.dbs.consentServer.DTO.hospitalDTO.PatientInfoDTO;
import com.dbs.consentServer.DTO.hospitalDTO.PatientListDTO;
import com.dbs.consentServer.VO.hospitalVO.ConsentFormCategoryVO;
import com.dbs.consentServer.VO.hospitalVO.GetDoctorVO;
import com.dbs.consentServer.VO.hospitalVO.GetPatientInfoVO;
import com.dbs.consentServer.VO.hospitalVO.GetPatientVO;
import com.dbs.consentServer.VO.hospitalVO.GetUserDeptVO;
import com.dbs.consentServer.VO.hospitalVO.GetWardDeptVO;

@Service
public class HospitalService {
  private final Logger logger = LoggerFactory.getLogger(this.getClass());
  
  @Autowired
  public HospitalMapper hospitalMapper;

  public String getBaseData(String instCd) {
    return hospitalMapper.getBaseData(instCd);
  }
  
  public String userPw(String userId) {
    return hospitalMapper.doLogin(userId); 
  }

  public ArrayList<GetUserDeptVO> getUserDeptList(HashMap<String, String> params){
    return hospitalMapper.getUserDeptList(params);
  }

  public ArrayList<GetWardDeptVO> getWardList(String instCd) {
    return hospitalMapper.getWardList(instCd);
  }

  public ArrayList<GetWardDeptVO> getDeptList(HashMap<String, String> params) {
    return hospitalMapper.getDeptList(params);
  }

  public ArrayList<GetDoctorVO> getDoctorList(HashMap<String, String> params){
    return hospitalMapper.getDoctorList(params);
  }

  public ArrayList<GetPatientVO> getPatientList(PatientListDTO patientListDTO) {
    String selectFlag = patientListDTO.getSelectFlag();

    if (selectFlag == null) {
      selectFlag = "";
    }

    if (selectFlag.equals("I")) {
      return hospitalMapper.getInPatientList(patientListDTO);
    } else if (selectFlag.equals("O")) {
      return hospitalMapper.getOutPatientList(patientListDTO);
    } else if (selectFlag.equals("OP")) {
      return hospitalMapper.getOpPatientList(patientListDTO);
    } else if (selectFlag.equals("E")) {
      return hospitalMapper.getErPatientList(patientListDTO);
    } else {
      return hospitalMapper.getInPatientList(patientListDTO);
    }
    
  }

  public ArrayList<GetPatientInfoVO> getPatientInfo(PatientInfoDTO patientInfoDTO) {
    String ordType = patientInfoDTO.getOrdType();
    if (ordType.equals("I") || ordType.equals("E") || ordType.equals("D") || ordType.equals("OP")) {
      return hospitalMapper.getPatientInfoIn(patientInfoDTO);
    } else {
      return hospitalMapper.getPatientInfoOut(patientInfoDTO);
    }
  }

  public Integer setUserFormSet(HashMap<String, String> params) {
    return hospitalMapper.setUserFormSet(params);
  }

  public Integer delUserFormSet(HashMap<Object, Object> params) {
    return hospitalMapper.delUserFormSet(params);
  }

  public ArrayList<ConsentFormCategoryVO> getConsentFormCategory() {
    return hospitalMapper.getConsentFormCategory();
  }

  public Integer updateUserSetUp(HashMap<String, String> params) {
    return hospitalMapper.updateUserSetUp(params);
  }


}
