/* * This class is an auto-generated source file for a HAPI * HL7 v2.x standard structure class. * * For more information, visit: http://hl7api.sourceforge.net/ */ package ${basePackageName}segment; // import ${basePackageName}group.*; #foreach ( $datatypePackage in $datatypePackages ) import ${datatypePackage}.*; #end import ca.uhn.log.HapiLogFactory; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.parser.ModelClassFactory; import ca.uhn.hl7v2.parser.DefaultModelClassFactory; import ca.uhn.hl7v2.model.AbstractMessage; import ca.uhn.hl7v2.model.Group; import ca.uhn.hl7v2.model.Type; import ca.uhn.hl7v2.model.AbstractSegment; import ca.uhn.hl7v2.model.Varies; /** *

Represents an HL7 ${segmentName} message segment (${typeDescription}). * This segment has the following fields:

* */ public class ${segmentName} extends AbstractSegment { /** * Creates a new ${segmentName} segment */ public ${segmentName}(Group parent, ModelClassFactory factory) { super(parent, factory); init(factory); } private void init(ModelClassFactory factory) { #if ( $elements.size() > 0 ) try { #foreach ( $element in $elements) #if (${element.required}) #set ($reqd = "true") #else #set ($reqd = "false") #end #if ($element.repeating) #set ($rept = "true") #else #set ($rept = "false") #end #if (${element.idType}) #set ($constructorArgs = "new Object[]{ getMessage() }") #else #set ($constructorArgs = "new Object[]{ getMessage(), new Integer(${element.table}) }") #end this.add(${element.alternateType}.class, $reqd, ${element.repetitions}, ${element.length}, ${constructorArgs}, "${element.descEscaped}"); #end } catch(HL7Exception e) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating ${segmentName} - this is probably a bug in the source code generator.", e); } #end } #foreach ( $element in $elements ) #if ($element.repeating) /** * Returns all repetitions of ${element.desc} (${segmentName}-${velocityCount}). */ public ${element.alternateType}[] get${element.accessorName}() { ${element.alternateType}[] ret = null; try { Type[] t = this.getField(${velocityCount}); ret = new ${element.alternateType}[t.length]; for (int i = 0; i < ret.length; i++) { ret[i] = (${element.alternateType})t[i]; } } catch (ClassCastException cce) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", cce); throw new RuntimeException(cce); } catch (HL7Exception he) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", he); throw new RuntimeException(he); } return ret; } /** * Returns a specific repetition of * ${segmentName}-${velocityCount}: "${element.desc}" - creates it if necessary * * @param rep The repetition index (0-indexed) */ public ${element.alternateType} get${element.accessorName}(int rep) { $element.alternateType ret = null; try { Type t = this.getField(${velocityCount}, rep); ret = ($element.alternateType)t; } catch (ClassCastException cce) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", cce); throw new RuntimeException(cce); } catch (HL7Exception he) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", he); throw new RuntimeException(he); } return ret; } /** * Returns a specific repetition of * ${segmentName}-${velocityCount}: "${element.desc}" - creates it if necessary * * @param rep The repetition index (0-indexed) */ public ${element.alternateType} get${element.alternateAccessorName}(int rep) { $element.alternateType ret = null; try { Type t = this.getField(${velocityCount}, rep); ret = ($element.alternateType)t; } catch (ClassCastException cce) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", cce); throw new RuntimeException(cce); } catch (HL7Exception he) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", he); throw new RuntimeException(he); } return ret; } /** * Inserts a repetition of * ${segmentName}-${velocityCount}: "${element.desc}" at a specific index * * @param rep The repetition index (0-indexed) * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions) */ public ${element.alternateType} insert${element.accessorName}(int rep) throws HL7Exception { return ($element.alternateType) super.insertRepetition(${velocityCount}, rep); } /** * Inserts a repetition of * ${segmentName}-${velocityCount}: "${element.desc}" at a specific index * * @param rep The repetition index (0-indexed) * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions) */ public ${element.alternateType} insert${element.alternateAccessorName}(int rep) throws HL7Exception { return ($element.alternateType) super.insertRepetition(${velocityCount}, rep); } /** * Removes a repetition of * ${segmentName}-${velocityCount}: "${element.desc}" at a specific index * * @param rep The repetition index (0-indexed) * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions) */ public ${element.alternateType} remove${element.accessorName}(int rep) throws HL7Exception { return ($element.alternateType) super.removeRepetition(${velocityCount}, rep); } /** * Removes a repetition of * ${segmentName}-${velocityCount}: "${element.desc}" at a specific index * * @param rep The repetition index (0-indexed) * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions) */ public ${element.alternateType} remove${element.alternateAccessorName}(int rep) throws HL7Exception { return ($element.alternateType) super.removeRepetition(${velocityCount}, rep); } #else /** * Returns * ${segmentName}-${velocityCount}: "${element.desc}" - creates it if necessary */ public $element.alternateType get${element.accessorName}() { $element.alternateType ret = null; try { Type t = this.getField(${velocityCount}, 0); ret = ($element.alternateType)t; } catch (ClassCastException cce) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", cce); throw new RuntimeException(cce); } catch (HL7Exception he) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", he); throw new RuntimeException(he); } return ret; } /** * Returns * ${segmentName}-${velocityCount}: "${element.desc}" - creates it if necessary */ public $element.alternateType get${element.alternateAccessorName}() { $element.alternateType ret = null; try { Type t = this.getField(${velocityCount}, 0); ret = ($element.alternateType)t; } catch (ClassCastException cce) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", cce); throw new RuntimeException(cce); } catch (HL7Exception he) { HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value. This is a bug.", he); throw new RuntimeException(he); } return ret; } #end #end /** {@inheritDoc} */ protected Type createNewTypeWithoutReflection(int field) { switch (field) { #foreach ( $element in $elements ) #set ( $idx = ${velocityCount} - 1 ) #if ( $element.alternateType == "Varies" ) case ${idx}: return new Varies(getMessage()); #elseif ( $element.idType ) case ${idx}: return new ${element.alternateType}(getMessage(), new Integer( ${element.table} )); #else case ${idx}: return new ${element.alternateType}(getMessage()); #end #end default: return null; } } }