首页 > 解决方案 > 如何在不更改 xds 文件的情况下从 CDA 模式创建 POJO 类?

问题描述

我有一个用于生成 CDA xml 文档的大型 CDA 模式文件。我想在编译代码期间使用 xds 模式生成 POJO 类。我正在尝试使用 jaxb2-maven-plugin 执行此操作,如下所示:

           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>myDirectoryName</schemaDirectory>
                    <schemaFiles>myxsdFile</schemaFiles>
                </configuration>
            </plugin>

这似乎适用于简单的 xsd 文件。但是使用我的 CDA 会引发错误

未能执行目标 org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc 。. 尝试两次创建相同的字段:id

由于 id 既作为元素又作为属性存在,xsd 中产生问题的部分如下所示:

<xs:complexType name="POCD_MT000040.ObservationMedia">
        <xs:sequence>
            <xs:element name="realmCode" type="CS" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="typeId" type="POCD_MT000040.InfrastructureRoot.typeId" minOccurs="0" />
            <xs:element name="templateId" type="II" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="id" type="II" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="languageCode" type="CS" minOccurs="0" />
            <xs:element name="value" type="ED" />
            <xs:element name="subject" type="POCD_MT000040.Subject" minOccurs="0" />
            <xs:element name="specimen" type="POCD_MT000040.Specimen" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="performer" type="POCD_MT000040.Performer2" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="author" type="POCD_MT000040.Author" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="informant" type="POCD_MT000040.Informant12" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="participant" type="POCD_MT000040.Participant2" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="entryRelationship" type="POCD_MT000040.EntryRelationship" minOccurs="0"
                maxOccurs="unbounded" />
            <xs:element name="reference" type="POCD_MT000040.Reference" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="precondition" type="POCD_MT000040.Precondition" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="ID" type="xs:ID" />
        <xs:attribute name="nullFlavor" type="NullFlavor" use="optional" />
        <xs:attribute name="classCode" type="ActClassObservation" use="required" />
        <xs:attribute name="moodCode" type="ActMood" use="required" />
    </xs:complexType>

到目前为止,我可以找到解决方案(http://metro.1045641.n5.nabble.com/troubleshoot-quot-trying-to-create-the-same-field-twice-quot-error-td1059643。 html ) 建议对 xds 进行更改,这对我来说不是一个选项。除了更改 xds 或使用其他实用程序之外,还有其他方法吗?

标签: javaxsdmaven-jaxb2-plugincda

解决方案


不确定您的要求,但来自 HL7 的 CDA 模式不能用作典型 XML/java 技术的一部分 - 此外,序列化符合规范的 CDA(如 Consol)的能力并非微不足道

我建议使用支持 Consol 的 MDHT api

https://projects.eclipse.org/projects/modeling.mdht

https://github.com/mdht/mdht-models


推荐阅读