Class Varies

java.lang.Object
ca.uhn.hl7v2.model.Varies
All Implemented Interfaces:
Type, Variable, Visitable, Serializable

public class Varies extends Object implements Variable

Varies is a Type used as a placeholder for another Type in cases where the appropriate Type is not known until run-time (e.g. OBX-5). Parsers and validators may have logic that enforces restrictions on the Type based on other features of a segment.

If you want to set both the type and the values of a Varies object, you should set the type first by calling setData(Type t), keeping a reference to your Type, and then set values by calling methods on the Type. Here is an example:

CN cn = new CN();
variesObject.setData(cn);
cn.getIDNumber().setValue("foo");

Author:
Bryan Tripp (bryan_tripp@users.sourceforge.net), Andy Pardue
See Also:
  • Field Details

    • DEFAULT_OBX2_TYPE_PROP

      public static final String DEFAULT_OBX2_TYPE_PROP
      Deprecated.
      use FixFieldDataType#DEFAULT_OBX2_TYPE_PROP
      System property key: The value may be set to provide a default datatype ("ST", "NM", etc) for an OBX segment with a missing OBX-2 value.
      See Also:
    • INVALID_OBX2_TYPE_PROP

      public static final String INVALID_OBX2_TYPE_PROP
      Deprecated.
      use FixOBX5#INVALID_OBX2_TYPE_PROP
      System property key: The value may be set to provide a default datatype ("ST", "NM", etc) for an OBX segment with an invalid OBX-2 value type. In other words, if OBX-2 has a value of "ZYZYZ", which is not a valid value, but this property is set to "ST", then OBX-5 will be parsed as an ST.
      See Also:
    • ESCAPE_SUBCOMPONENT_DELIM_IN_PRIMITIVE

      Deprecated.
      use FixOBX5#ESCAPE_SUBCOMPONENT_DELIM_IN_PRIMITIVE

      System property key: If this is not set, or set to "true", and a subcomponent delimiter is found within the value of a Varies of a primitive type, this subcomponent delimiter will be treated as a literal character instead of a subcomponent delimiter, and will therefore be escaped if the message is re-encoded. This is handy when dealing with non-conformant sending systems which do not correctly escape ampersands in OBX-5 values.

      For example, consider the following OBX-5 segment:

          OBX||ST|||Apples, Pears & Bananas|||
       
      In this example, the data type is a primitive ST and does not support subcomponents, and the ampersand is obviously not intended to represent a subcomponent delimiter. If this property is set to true, the entire string will be treated as the value of OBX-5, and if the message is re-encoded the string will appear as "Apples, Pears \T\ Bananas".

      If this property is set to anything other than "true", the subcomponent delimiter is treated as a component delimiter, so the value after the ampersand is placed into an extra component.

      See Also:
  • Constructor Details

    • Varies

      public Varies(Message message)
      Creates new Varies.
      Parameters:
      message - message to which this type belongs
  • Method Details

    • getData

      public Type getData()
      Returns the data contained by this instance of Varies. Returns a GenericPrimitive unless setData() has been called.
      Specified by:
      getData in interface Variable
      Returns:
      the data contained by this instance of Varies
    • getName

      public String getName()
      Description copied from interface: Type
      Returns the name of the type (used in XML encoding and profile checking)
      Specified by:
      getName in interface Type
      Returns:
      the name of the type
    • setData

      public void setData(Type data) throws DataTypeException
      Sets the data contained by this instance of Varies. If a data object already exists, then its values are copied to the incoming data object before the old one is replaced. For example, if getData() returns an ST with the value "19901012" and you call setData(new DT()), then subsequent calls to getData() will return the same DT, with the value set to "19901012".
      Specified by:
      setData in interface Variable
      Parameters:
      data - the data to be set for this Varies instance
      Throws:
      DataTypeException - if the data could not be set
    • getExtraComponents

      Description copied from interface: Type
      Returns an object containing any extra (non-standard) components that have been added to this type at run-time. This object can also be used to add components.
      Specified by:
      getExtraComponents in interface Type
      Returns:
      an object containing any extra (non-standard) components
    • getMessage

      public Message getMessage()
      Specified by:
      getMessage in interface Type
      Returns:
      the message to which this Type belongs
    • fixOBX5

      public static void fixOBX5(Segment segment, ModelClassFactory factory) throws HL7Exception
      Deprecated.
      use FixOBX5#fixOBX5

      Sets the data type of field 5 in the given OBX segment to the value of OBX-2. The argument is a Segment as opposed to a particular OBX because it is meant to work with any version.

      Note that if no value is present in OBX-2, or an invalid value is present in OBX-2, this method will throw an error. This behaviour can be corrected by using the following system properties: DEFAULT_OBX2_TYPE_PROP and INVALID_OBX2_TYPE_PROP, or by using configuration in ParserConfiguration

      Parameters:
      segment - OBX segment instance to be modified
      factory - ModelClassFactory to be used
      Throws:
      HL7Exception - if the operation fails
    • fixOBX5

      public static void fixOBX5(Segment segment, ModelClassFactory factory, ParserConfiguration parserConfiguration) throws HL7Exception
      Deprecated.
      use FixOBX5#fixOBX5

      Sets the data type of field 5 in the given OBX segment to the value of OBX-2. The argument is a Segment as opposed to a particular OBX because it is meant to work with any version.

      Note that if no value is present in OBX-2, or an invalid value is present in OBX-2, this method will throw an error. This behaviour can be corrected by using the following system properties: DEFAULT_OBX2_TYPE_PROP and INVALID_OBX2_TYPE_PROP or by using configuration in ParserConfiguration

      Parameters:
      segment - OBX segment instance to be modified
      factory - ModelClassFactory to be used
      parserConfiguration - configuration that influences setting OBX-5
      Throws:
      HL7Exception - if the operation fails
    • parse

      public void parse(String string) throws HL7Exception

      Parses the string into this type and replaces the current contents with the parsed value. This method accepts HL7 encoded text and treats its input as such.

      Note that this method is subtly different from calling Primitive.setValue(String), but can be quite powerful. For example, using the argument of "milk&cookies" on an ST datatype:

      • If you are using Primitive.setValue(String), the ampersand is treated as an actual ampersand in the text, and the field will be treated as a single field which is encoded as "milk\T\cookies" (\T\ is the escape sequence for the subcomponent delimiter).
      • If you are using parse(String), the ampersand is treated as a subcomponent delimiter, meaning that the value is set to "milk", and a second component is added with the value of "cookies".

      This method makes use of the parser which is stored within the enclosing Message. At this time, only PipeParsers are supported.

      Specified by:
      parse in interface Type
      Parameters:
      string - the message to be parsed
      Throws:
      HL7Exception - if errors occurred while parsing
    • encode

      public String encode() throws HL7Exception
      Encodes this type using HL7 encoding.
      Specified by:
      encode in interface Type
      Returns:
      the encoded message
      Throws:
      HL7Exception - if errors occurred while encoding
    • clear

      public void clear()
      Clears all data from this type
      Specified by:
      clear in interface Type
    • isEmpty

      public boolean isEmpty() throws HL7Exception
      Returns true if this Visitable has actual content
      Specified by:
      isEmpty in interface Visitable
      Returns:
      true if Visitable is empty
      Throws:
      HL7Exception - if an error occurred while determining emptiness
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • accept

      public boolean accept(MessageVisitor visitor, Location currentLocation) throws HL7Exception
      Description copied from interface: Visitable
      Callback method for the visitor. This method is supposed to either directly call one of the visitors methods, passing this as parameter, or traverse through a hierarchical substructure and call accept(MessageVisitor) for each visited element.
      Specified by:
      accept in interface Visitable
      Parameters:
      visitor - MessageVisitor instance to be called back
      currentLocation - location of this object
      Returns:
      true if the visit process shall continue
      Throws:
      HL7Exception - if a problem occurred during visiting
    • provideLocation

      public Location provideLocation(Location location, int index, int repetition)
      Description copied from interface: Visitable
      Reusing the location of this object's parent, this method returns its own location within the message.
      Specified by:
      provideLocation in interface Visitable
      Parameters:
      location - the parents location
      index - index of this object
      repetition - repetition of this object
      Returns:
      this objects location