package thyyxxk.webserver.service.jiekou;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.dao.his.jiekou.DuiWaiJieKouDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.jiekou.GetPatientInformationParam;
import thyyxxk.webserver.entity.jiekou.PatientInformation;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 描述： 对深圳博英接口文档
 * </p>
 *
 * @author xc
 * @date 2021-07-13 08:08
 */
@Slf4j
@Service
public class DuiWaiJieKouService {
    private final DuiWaiJieKouDao dao;


    public DuiWaiJieKouService(DuiWaiJieKouDao dao) {
        this.dao = dao;
    }

    public ResultVo<List<PatientInformation>> getPatientInformation(GetPatientInformationParam param) {
        log.info("查询：{}", param);
        if (StringUtil.notBlank(param.getSource()) && param.getSource().equals("SZBY")) {
            List<PatientInformation> list = new ArrayList<>();
            if (param.getFlag() == 1) {
                list = dao.getMzPatient(param.getPatient(), "2030000");
            } else if (param.getFlag() == 2) {
                list = dao.getYzPatient(param.getPatient(), "2030000");
            }
            if (list.size() > 0) {
                return ResultVoUtil.success(list);
            }
        } else {
            return ResultVoUtil.fail(ExceptionEnum.BAD_REQUEST, "未知来源。");
        }
        return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
    }
}
