All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.uhn.hl7v2.model.primitive.AbstractTextPrimitive Maven / Gradle / Ivy

/**
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
 * specific language governing rights and limitations under the License.
 *
 * The Original Code is "".  Description:
 * ""
 *
 * The Initial Developer of the Original Code is University Health Network. Copyright (C)
 * 2005.  All Rights Reserved.
 *
 * Contributor(s): ______________________________________.
 *
 * Alternatively, the contents of this file may be used under the terms of the
 * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
 * applicable instead of those above.  If you wish to allow use of your version of this
 * file only under the terms of the GPL and not to allow others to use your version
 * of this file under the MPL, indicate your decision by deleting  the provisions above
 * and replace  them with the notice and other provisions required by the GPL License.
 * If you do not delete the provisions above, a recipient may use your version of
 * this file under either the MPL or the GPL.
 */

package ca.uhn.hl7v2.model.primitive;

import ca.uhn.hl7v2.model.AbstractPrimitive;
import ca.uhn.hl7v2.model.Message;

/**
 * Base class for a textual primitive datatypes such as FT, TX, ST.
 * 
 * @author James Agnew
 */
@SuppressWarnings("serial")
public abstract class AbstractTextPrimitive extends AbstractPrimitive {

	/**
	 * Constructor
	 */
	public AbstractTextPrimitive(Message theMessage) {
		super(theMessage);
	}

	/**
	 * 

* Returns the value of this type with HL7 defined formatting codes replaced * by their HTML equivalent. *

*

* For example, if this type contained the string:
* *

	 * ABC \.ce\MIDDLE\.br\
	 * 
* *
* This would be returned as:
* *
	 * ABC <center>MIDDLE<center><br>
	 * 
* *

*

* The following codes are handled (note that contrary to the HL7 * specification, codes are interpreted in a case-insensitive manner): *

    *
  • \.br\ (converted to <br>) *
  • \.ce\ (converted to <center>) *
  • \.sk\ (converted to &nbsp;) *
  • \.sp\ (converted to <br> and then multiple &nbsp;) *
  • \.sp ###\ (converted to multiple <br> and then multiple * &nbsp;) *
  • \.fi\ (cancels \.nf\) *
  • \.nf\ (converted to <nobr> ... </nobr> around each line) *
  • \.in ###\ (converted to <div style="margin-left: ###em;"> ... * </div> around each line) *
  • \.ti ###\ (treated the same as \.in ###\ but only affects the current * line, and the numeric value is added to the value provided by \.in ###\. * See section 2.7 of the HL7 specification for more details.) *
  • \H\ (converted to <b>) *
  • \N\ (converted to </b>) *
  • Ampersands (&) are converted to their HTML equivalent (&amp;) *
  • Chars over ASCII 160 are HTML encoded (e.g. &#199;) *
*

*

* Note that the returned value from this method is an HTML snippet, not a * complete HTML document. *

* * @see FormattedTextEncoder */ public String getValueAsHtml() { return FormattedTextEncoder.getInstanceHtml().encode(getValue()); } /** * Returns the value of the datatype as returned by {@link #getValue()} but * returns an empty string ("") if the value is null. This * method is mostly provided as a convenience in code which maps from one * format to another, since it avoids the need for some null checks. */ public String getValueOrEmpty() { String retVal = getValue(); if (retVal == null) { retVal = ""; } return retVal; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy