Understanding HL7 Data Types

One of the more complicated aspects of the HL7 specification is that it chooses to not use standard variable “types” and invents its own (while, to some extent, that choice reflects the fact that the work on the HL7 specification began in 1995, there has been no move to try to rectify that choice. Unfortunately, the HL7 standards community cannot come to agreement about whether or not the HL7 types are features or bugs.)

For example, HL7 defines the type called “BL” which can have one of the following values: “true” or “false” or “null”. This is clearly equivalent to a java.lang.Booleanclass.

Here’s a general mapping of various HL7 types to Java types:

HL7 Type HL7 Name Java Type Notes
AD Postal Address
BAG Bag java.util.Collection
BL Boolean java.lang.Boolean
ED Encapsulated Data Typically used for things like attachments
II Instance Identifier
INT Integer Number java.lang.Integer
IVL Interval
LIST Sequence java.util.List
PN Person Name
SET Set java.util.Set
ST Character String java.lang.String
TEL Telecommunications Number Includes e-mail and other electronic addresses
TS Point in time java.util.Date

The complete list of HL7 types is over here.

The consequence of these types is that classes become much more complicated. For example, imagine a Comment class. A comment might include two properties: the comment text and the date the comment was added. It’d probably look like this:

public class Comment {
  private ED text;
  private TS date;

  public ED getText() {
    return this.text;
  public void setText(ED text) {
    this.text = text;
  public TS getDate() {
    return this.date;
  public void setDate(TS date) {
    this.date = date;

This is clearly a level of abstractness that makes code more complicated than if the type was defined based on Strings and Dates.

Using these type definitions usually introduces additional complexity to any standard code. Consider the following example.

Comment comment = new Comment();
comment.setText(STjlStringAdapter.valueOf("This is my comment text"));

compared to:

Comment comment = new Comment();
comment.setText("This is my comment text");

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply