How to create POJO class from a CDA schema without changing the xds file?

280 views Asked by At

I have a large CDA schema file which is used in generation of a CDA xml document. I want to generate POJO classes using the xds schema during compiling of code. I am trying to do this with jaxb2-maven-plugin as below:

           <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>

This seems to work with simple xsd files. But with my CDA it throws error

Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc . . trying to create the same field twice: id

The part in xsd which is creating problem, due to id being present both as element as well as attribute..is as below:

<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>

The solutions for this, so far I could find, (http://metro.1045641.n5.nabble.com/troubleshoot-quot-trying-to-create-the-same-field-twice-quot-error-td1059643.html) suggest making changes to the xds which is not an option for me. Is there a way other than changing xds or using some other utility?

1

There are 1 answers

2
user2418114 On

Not sure your requirements but CDA schema from HL7 is not usable as part of typical XML/java technologies - Additionally the ability to serialize CDA that is conforms to spec such as Consol is not trivial

i would suggest using MDHT api which support Consol

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

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