org.vmdb.hl7
Class HL7Element

java.lang.Object
  |
  +--org.vmdb.hl7.HL7Object
        |
        +--org.vmdb.hl7.HL7Element
Direct Known Subclasses:
CEElement, CM_ERRElement, CXElement, DRElement, EIElement, FCElement, FNElement, HDElement, MSGElement, PLElement, PTElement, RepeatElement, SimpleElement, SNElement, TSElement, VIDElement, XADElement, XCNElement, XPNElement

public abstract class HL7Element
extends HL7Object

Abstract Base Class for HL7 Data Type Elements.

Description: HL7 Network Connectivity For VMDB.

Copyright: Copyright (c) 2002-2003.

Company: Veterinary Medical Database (VMDB).

HL7 uses data elements in a nested structure of fields sometimes composed of components sometimes composed of subcomponents. The Generic HL7Element class forms the base of all our data type elements. It adds to knowledge of its own level (field, component, or subcomponent) and the machinery to build itself by parsing HL7 input under the direction of a RuleParser.


Constructor Summary
HL7Element()
          Construct an Element using the name and type specified in its sNm and sRl constants.
HL7Element(int iLevel)
          Construct an Element using the name and type specified in its sNm and sRl constants.
HL7Element(java.lang.String sName, java.lang.String sType)
          Construct an Element of given name and type.
 
Method Summary
 void clear()
          Return this element to its empty state.
 boolean empty()
          Is this Element empty?
 HL7Element getComponent(int iLoc)
          Get component based on one based index position.
 int getLevel()
          Get this Elements level.
 java.lang.String getType()
          Get the HL7 data type of this element.
 java.lang.String getValue()
          Get the first component value.
 void initialize()
           
 java.util.Iterator iterator()
          Get an Iterator over all the components in this element.
static HL7Element makeElement(int iLevel, java.lang.String sSeparators, java.lang.String sType, java.lang.String sName)
          Factory method to make an element of an appropriate subclass for the type specified.
 void setComponent(HL7Element element, int iLoc)
          Set component based on one based index position.
 void setLevel(int iLevel)
          Set this Element to a specified level.
 void setType(java.lang.String sType)
          Set the HL7 data type of this element.
 void setValue(java.lang.String sValue)
          Populate the first component with the value supplied.
 int size()
          How many components are in this element?
 java.lang.String toHL7String()
          Return the element as an HL7String.
 java.lang.String toString()
          Return the element as an HL7String.
 java.lang.String toXML(int iDepth)
          Output the element as XML.
 
Methods inherited from class org.vmdb.hl7.HL7Object
getRule
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HL7Element

public HL7Element(int iLevel)
Construct an Element using the name and type specified in its sNm and sRl constants.

Parameters:
iLevel - One of the constants for specifying level as FIELD, COMPONENT, or SUBCOMPONENT. Default FIELD.

HL7Element

public HL7Element()
Construct an Element using the name and type specified in its sNm and sRl constants. And at the level of a Field.


HL7Element

public HL7Element(java.lang.String sName,
                  java.lang.String sType)
Construct an Element of given name and type.

Parameters:
sName - The name of this element relative to its container. Example: "PID.1" for the segquenceID in the pid segment.
sType - The HL7 data type abbreviation. Example "ST" for string or "NM" for numeric. Note: Both of these would be instatiated as SimpleElement objects in this library.
Method Detail

clear

public void clear()
Return this element to its empty state. Either emptying its collection of components or setting its value to an empty string.


makeElement

public static HL7Element makeElement(int iLevel,
                                     java.lang.String sSeparators,
                                     java.lang.String sType,
                                     java.lang.String sName)
Factory method to make an element of an appropriate subclass for the type specified.

It will either be a specific subclass of type TYPE + Element or a SimpleElement if the specified type is either any of the single string types or not yet defined.

Parameters:
iLevel - the FIELD, COMPONENT, or SUBCOMPONENT constant to define the level for this element
sSeparators - the separators for this message
sType - the type name (CE, XAD, ST, etc. for this Element)
sName - the name of the new element such as PID.3

setLevel

public void setLevel(int iLevel)
Set this Element to a specified level.

Parameters:
iLevel - One of the constants for specifying level as FIELD, COMPONENT, or SUBCOMPONENT. Default FIELD.

getLevel

public int getLevel()
Get this Elements level.

Returns:
One of the constants for specifying level as FIELD, COMPONENT, or SUBCOMPONENT. Default FIELD.

empty

public boolean empty()
Is this Element empty?

Returns:
true if this element has no components (and no value in the special derived case of SimpleElement).

size

public int size()
How many components are in this element?

Includes all components up to the last required or populated one.

Returns:
integer number of component objects present.

setValue

public void setValue(java.lang.String sValue)
Populate the first component with the value supplied.

Many complex element types are commonly populated in only the first component. This method allows them to be set as if they were a simple element.

Parameters:
sValue - String value to set.

getValue

public java.lang.String getValue()
Get the first component value.

Many complex element types are commonly populated in only the first component. This method allows them to be accessed as if they were a simple element.

Returns:
String value from first component.

setComponent

public void setComponent(HL7Element element,
                         int iLoc)
                  throws java.lang.ArrayIndexOutOfBoundsException,
                         MalformedFieldException
Set component based on one based index position.

Parameters:
element - HL7Element derived object to set at location
iLoc - location in element to set (one based index).
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iLoc points to a field less than one or greater than the number of components allowed in the message rule.
MalformedFieldException - if the HL7Element provided as element does not have the type required by rule for this component.

getComponent

public HL7Element getComponent(int iLoc)
Get component based on one based index position.

Parameters:
iLoc - location in element to get (one based index).
Returns:
Reference to the HL7Element derived object at the specified location or null if the location does not yet exist.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if iLoc points to a field less than one or greater than the number of components allowed in the message rule.

iterator

public java.util.Iterator iterator()
Get an Iterator over all the components in this element.

Returns:
Iterator over zero or more components.

setType

public void setType(java.lang.String sType)
Set the HL7 data type of this element.

Parameters:
sType - The HL7 data type abbreviation. Example "ST" for string or "NM" for numeric. Note: Both of these would be instatiated as SimpleElement objects in this library.

getType

public java.lang.String getType()
Get the HL7 data type of this element.

Returns:
The HL7 data type abbreviation. Example "ST" for string or "NM" for numeric. Note: Both of these would be instatiated as SimpleElement objects in this library.

initialize

public void initialize()

toString

public java.lang.String toString()
Return the element as an HL7String.

This should probably be renamed toHL7() but for now the only logical string representation is the raw HL7.

Overrides:
toString in class java.lang.Object
Returns:
HL7 string of this element.

toHL7String

public java.lang.String toHL7String()
Return the element as an HL7String.

This should probably be renamed toHL7() but for now the only logical string representation is the raw HL7.

Returns:
HL7 string of this element.

toXML

public java.lang.String toXML(int iDepth)
Output the element as XML.

Outputs the DOM element for this element and all its contained objects.

Overrides:
toXML in class HL7Object
Parameters:
iDepth - int value for the number of spaces to indent this object. Used just to make the XML easier to read as unformatted text.
Returns:
foratted XML text.

SourceForge.net Logo