package com.docus.server.collection.xml.parsers;

import com.docus.core.util.XmlUtil;
import com.docus.server.collection.dto.DeptDto;
import com.docus.server.collection.dto.UserDto;
import org.w3c.dom.Node;

/**
 * 梅州中医 XML 解析
 * @author jishi
 */
public class MzZyParser {
    public static DeptDto parseCreateDept(String xml){
        XmlUtil xmlParseUtil = XmlUtil.of(xml);
        Node deptCodeNode = xmlParseUtil.getNode("/PRPM_IN401030UV01/controlActProcess/subject/registrationRequest/subject1/assignedEntity/id/item/@extension");
        Node deptNameNode = xmlParseUtil.getNode("/PRPM_IN401030UV01/controlActProcess/subject/registrationRequest/subject1/assignedEntity/assignedPrincipalOrganization/name/item[@use='OR']/part/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRPM_IN401030UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRPM_IN401030UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        DeptDto deptDto = new DeptDto();
        deptDto.setDeptCode(deptCodeNode.getNodeValue());
        deptDto.setDeptName(deptNameNode.getNodeValue());
        deptDto.setAuthorId(authorIdNode.getNodeValue());
        deptDto.setAuthorName(authorNameNode.getNodeValue());
        return deptDto;
    }

    public static DeptDto parseUpdateDept(String xml){
        XmlUtil xmlParseUtil = XmlUtil.of(xml);
        Node deptCodeNode = xmlParseUtil.getNode("/PRPM_IN403010UV01/controlActProcess/subject/registrationRequest/subject1/assignedEntity/id/item/@extension");
        Node deptNameNode = xmlParseUtil.getNode("/PRPM_IN403010UV01/controlActProcess/subject/registrationRequest/subject1/assignedEntity/assignedPrincipalOrganization/name/item[@use='OR']/part/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRPM_IN403010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRPM_IN403010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        DeptDto deptDto = new DeptDto();
        deptDto.setDeptCode(deptCodeNode.getNodeValue());
        deptDto.setDeptName(deptNameNode.getNodeValue());
        deptDto.setAuthorId(authorIdNode.getNodeValue());
        deptDto.setAuthorName(authorNameNode.getNodeValue());
        return deptDto;
    }

    public static UserDto parseCreateUser(String xml){
        XmlUtil xmlParseUtil = XmlUtil.of(xml);
        Node employeeCodeNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/id/item/@extension");
        Node employeeNameNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/name/item[@use='OR']/part/@value");
        Node deptCodeNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/asAffiliate/affiliatedPrincipalOrganization/id/item/@extension");
        Node positionNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/relatedTo/assignedEntity/relatedTo/assignedEntity/code[@codeSystem='2.16.156.10011.0.9.2.3.2.122']/displayName/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        UserDto userDto = new UserDto();
        userDto.setDeptId(deptCodeNode.getNodeValue());
        userDto.setUserName(employeeCodeNode.getNodeValue());
        userDto.setName(employeeNameNode.getNodeValue());
        userDto.setPosition(positionNode.getNodeValue());
        userDto.setAuthorId(authorIdNode.getNodeValue());
        userDto.setAuthorName(authorNameNode.getNodeValue());
        userDto.setRoleId(0L);
        return userDto;
    }


    public static UserDto parseUpdateUser(String xml){
        XmlUtil xmlParseUtil = XmlUtil.of(xml);
        Node employeeCodeNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/id/item/@extension");
        Node employeeNameNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/name/item[@use='OR']/part/@value");
        Node deptCodeNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/asAffiliate/affiliatedPrincipalOrganization/id/item/@extension");
        Node positionNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/relatedTo/assignedEntity/relatedTo/assignedEntity/code[@codeSystem='2.16.156.10011.0.9.2.3.2.122']/displayName/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        UserDto userDto = new UserDto();
        userDto.setDeptId(deptCodeNode.getNodeValue());
        userDto.setUserName(employeeCodeNode.getNodeValue());
        userDto.setName(employeeNameNode.getNodeValue());
        userDto.setPosition(positionNode.getNodeValue());
        userDto.setAuthorId(authorIdNode.getNodeValue());
        userDto.setAuthorName(authorNameNode.getNodeValue());
        userDto.setRoleId(0L);
        return userDto;
    }
}
