SuperStructureGen Plugin - Usage

The superstructuregen plugin is used to create a set of HAPI structure classes which combine multiple message structures into a single class.

See the SuperStructures example page for more information on their usage.

Using the Plugin

Usage of the plusing is as follows:

<plugin>
   <groupId>ca.uhn.hapi</groupId>
   <artifactId>hapi-sourcegen</artifactId>
   <version>2.2</version>
   <executions>
      <execution>
         <id>superstructure_adt</id>
         <goals>
            <goal>superstructuregen</goal>
         </goals>
         <configuration>
         
            <!-- The directory to place the generated files in -->
            <targetDirectory>${basedir}/target/generated-sources/superstructuregen</targetDirectory>
            
            <!-- The name for the genrated strcuture -->
            <targetStructureName>ADT_AXX</targetStructureName>
            
            <!-- This is the HL7 version to base the superstructure on -->
            <version>2.5</version>
            
            <!-- 
            And finally, a list of structures to combine. This list
            supports regex, so the following are all valid 
            -->
            <structures>
               <structure>ADT_A0[1-3]</structure>
               <structure>ADT_A17</structure>
               <structure>ORU.*</structure>
            </structures>
            
         </configuration>
      </execution>
   </executions>
   <dependencies>
      
      <!-- Make sure to include the appropriate HAPI version as a dependency -->
      <dependency>
         <groupId>ca.uhn.hapi</groupId>
         <artifactId>hapi-structures-v25</artifactId>
         <version>${hapi.version.structures}</version>
      </dependency>
      
   </dependencies>
</plugin>

Using the Generated Sources

Once you have completed the source generation, you have a set of classes you can use in your application.

The following examples assume you have created a custom structure called "ADT_AXX" and generated classes using the confgen plugin.

Sending Custom Structures

To send messages out using your custom structures:

// Create a new instance of the message and initialize it
ADT_AXX outMsg = new ADT_AXX();
outMsg.initQuickstart("ZDT", "A01", "T");

// .. populate other segments ..
// e.g. outMsg.getPID().getPid3_PatientIdentifierList(0).......

// Create a hapi context and send the message
DefaultHapiContext ctx = new DefaultHapiContext();
Connection conn = ctx.newClient("someserver.com", 8888, false);

// Send the message
Message response = conn.getInitiator().sendAndReceive(outMsg);

Receiving Custom Structures

The easiest way to receive messages and have them parsed into a custom structure is to use a CanonicalModelClassFactory and configure it to always use your custom structure.

DefaultHapiContext ctx = new DefaultHapiContext();
ModelClassFactory mcf = new CanonicalModelClassFactory(ADT_AXX.class);
ctx.setModelClassFactory(mcf);

HL7Service server = ctx.newServer(8888, false);
server.start();