HL7 with a JavaScript Class

HL7 is the standard that enables healthcare systems to rapidly agree on data transmission format. One may be surprised to learn the large number systems in a given hospital or laboratory that use HL7 to communicate either internally or externally with admissions, orders, results, billing or other records.

The structure of HL7 is intended to be human readable. Typically one will see a message where there are lines of text that begin like:

MSH|^~\&|…
PID|1|…|…||patient lastname^firstname|…
PV1|1|…
ORC|RE|…
OBR|1|…
OBX|1|…
OBX|2|…
etc.

The lines are called segments and typically the segments are broken into fields with the vertical bar (|).

The first field in a segment is a standard code which identifies the segment type so that the receiving system can know what fields are expected to be found in that segment.

When people talk about HL7 messages, they might say “Last name is in PID 5.1 and first name is in PID 5.2”. Thus fields may be broken into components typically with an up carat (^).

Some segments may need to repeat with additional information. In this case the second field may be a series of numbers, such as OBX 1, OBX 2 etc.

I recently took on a programming challenge asking how might one parse an HL7 message and how might one write an HL7 object class with constructor, get and set methods. Given that, how might one write functions using that class to do a series of operations on the message such as read a field or component within a field, write a field with components, read a field in a repeating segment and finally (not that one is likely to do this in real life) delete the odd segments of a repeating segment type.

The web page (see link below) is a solution to this challenge that I wrote in a day. Actually I finished around midnight and was practically cross eyed by then. In order to get the website and my browsers to work with JavaScript Classes whose support is supposed to be in future versions of JavaScript, I had to use some odd ball directives. You’ll see those at the top of the JavaScript panel on the left. The Console panel on the right contains the output of my test program.

At the time I wrote this web page (July 19th 2016) the website worked under Chrome, Fire Fox, Microsoft Edge on Windows 10, Android or Mac, but not Safari on a Mac or Internet Explorer on Windows. So try the Chrome browser if you get an error opening the web page.

https://bseaver.jsbin.com/puyule/edit?js,console

Thanks for looking!

Leave a Reply