package com.docus.server.collect.medical.record;

import com.docus.core.util.XmlUtil;
import com.docus.server.collect.service.IParseService;
import com.docus.server.record.pojo.entity.MedicalRecord;
import com.docus.server.sys.common.pojo.dto.DeptDTO;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;

@Service
public class ParseServiceImpl implements IParseService {

    @Override
    public MedicalRecord parseHandNumbness(String handNumbness) {
        //TODO： 根据协议进行解析。
        return null;
    }


    /**
     * 新增/修改 科室解析 webservice 例子
     *
     * @param deptXml
     * @return
     */
    @Override
    public DeptDTO parseDeptXml(String deptXml) {
        //TODO： 根据协议进行解析。
        XmlUtil xmlParseUtil = XmlUtil.of(deptXml);
        Node msgIdNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/id/@extension");
        Node receiverNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/receiver/device/id/item/@extension");
        Node operateTypeNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/subject1/valueSet/valueSetItems/@operateType");
        Node deptCodeNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/subject1/valueSet/valueSetItems/DEPT_CODE/@value");
        Node deptNameNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/subject1/valueSet/valueSetItems/DEPT_NAME/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        DeptDTO deptDto = new DeptDTO();
        deptDto.setMessageId(msgIdNode.getNodeValue());
        deptDto.setReceiver(receiverNode.getNodeValue());
        deptDto.setOperateType(operateTypeNode.getNodeValue());
        deptDto.setDeptCode(deptCodeNode.getNodeValue());
        deptDto.setDeptName(deptNameNode.getNodeValue());
        deptDto.setAuthorId(authorIdNode.getNodeValue());
        deptDto.setAuthorName(authorNameNode.getNodeValue());
        return deptDto;
    }
}
