package com.docus.server.message.converters;

import com.docus.core.util.DateUtil;
import com.docus.infrastructure.core.exception.BaseException;
import com.docus.server.message.dto.WsNurseSubmitDTO;
import com.docus.server.message.util.XmlUtil;
import org.w3c.dom.Node;

import java.util.Date;

public class WsNurseSubmitMessageConvert {
    public static WsNurseSubmitDTO convert(String str) {
        String inHospNo=null;
        String inHospIndexNo=null;
        Integer visitNo=null;
        String name=null;
        Date submitTime=null;
        Integer fileCount=null;
        // 质控护士
        String qcNurse;
        // 责任护士
        String dutyNurse;

        XmlUtil xmlUtil = XmlUtil.of(str);

        try {
            // 文件数量
            Node fileCountNode = xmlUtil.getNode("/Request/Msg/FILES_NUMBER");
            fileCount=Integer.parseInt(fileCountNode.getTextContent());
        } catch (Exception ex) {
            throw new BaseException("解析 文件数量 出错！");
        }
        try {
            // 住院流水号
            Node inHospNoNode = xmlUtil.getNode("/Request/Msg/INHOSP_NO");
            inHospNo=inHospNoNode.getTextContent();
        } catch (Exception ex) {
            throw new BaseException("解析 住院流水号 出错！");
        }

        try {
            // 住院号
            Node inHospIndexNoNode = xmlUtil.getNode("/Request/Msg/INHOSP_INDEX_NO");
            inHospIndexNo=inHospIndexNoNode.getTextContent();
        } catch (Exception ex) {
            throw new BaseException("解析 住院号 出错！");
        }
        try {
            // 住院次数
            Node visitNoNode = xmlUtil.getNode("/Request/Msg/VISIT_NO");
            visitNo=Integer.parseInt(visitNoNode.getTextContent());
        } catch (Exception ex) {
            throw new BaseException("解析 住院次数 出错！");
        }
        try {
            // 患者姓名
            Node nameNode = xmlUtil.getNode("/Request/Msg/NAME");
            name=nameNode.getTextContent();
        } catch (Exception ex) {
            throw new BaseException("解析 姓名 出错！");
        }
        try {
            // 提交时间
            Node submitTimeNode = xmlUtil.getNode("/Request/Msg/SUBMIT_TIME");
            submitTime= DateUtil.parse(submitTimeNode.getTextContent(), DateUtil.PATTERN_DATETIME);
        } catch (Exception ex) {
            throw new BaseException("解析 提交时间 出错！");
        }

        try {
            // 提交时间
            Node qcNurseNode = xmlUtil.getNode("/Request/Msg/QC_NURSE");
            qcNurse = qcNurseNode.getTextContent();
        } catch (Exception ex) {
            throw new BaseException("解析 质控护士 出错！");
        }

        try {
            // 提交时间
            Node dutyNurseNode = xmlUtil.getNode("/Request/Msg/DUTY_NURSE");
            dutyNurse = dutyNurseNode.getTextContent();
        } catch (Exception ex) {
            throw new BaseException("解析 责任护士 出错！");
        }

        WsNurseSubmitDTO nurseSubmitDTO = new WsNurseSubmitDTO();
        nurseSubmitDTO.setInHospNo(inHospNo);
        nurseSubmitDTO.setVisitNo(visitNo);
        nurseSubmitDTO.setFilesCount(fileCount);
        nurseSubmitDTO.setName(name);
        nurseSubmitDTO.setInHospIndexNo(inHospIndexNo);
        nurseSubmitDTO.setSubmitTime(submitTime);
        nurseSubmitDTO.setQcNurse(qcNurse);
        nurseSubmitDTO.setDutyNurse(dutyNurse);
        return nurseSubmitDTO;
    }

}
