HL7 Delimiter Redefinition
Another example of where one should not let an edge case complicated a core design is HL7.
The Health Level Seven standard for electronic data transmission is a format which looks like this:
MSH|^~\&|EPIC|EPICADT|SMS|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5|
PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^O
NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC|||||||||||||||||||||||||||
PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||
The format consists of data “delimited” by characters like | & ^ and ~.
Foolishly in my humble opinion the standard is needlessly complicated by allowing implementations to re-define the delimiter characters in the header - so if you want to use # characters instead of | then this is legal:
MSH#^~\&#EPIC#EPICADT#SMS#SMSADT#199912271408#CHARRIS#ADT^A04#1817457#D#2.5#
PID##0493575^^^2^ID 1#454721##DOE^JOHN^^^^#DOE^JOHN^^^^#19480203#M##B#254 MYSTREET AVE^^MYTOWN^O
NK1##ROE^MARIE^^^^#SPO##(216)123-4567##EC###########################
PV1##O#168 ~219~C~PMA^^^^^^^^^####277^ALLEN MYLASTNAME^BONNIE^^^^########## ##2688684#######
Legal - but not smart in my opinion. The vast majority HL7 implementations use the standard characters. It’s just introducing friction and complexity for no good reason.
In Chameleon my first HL7 parser product I went to great effort to faithfully implement this part of the standard. What a waste of effort! Nowadays if I were to write an HL7 parser from scratch I wouldn’t implement this feature of HL7 as a core part of the parser.
Instead if a customer encountered the way that makes sense to solve the problem is just to preprocess the data with a normalization script like this:
function HL7Normalize(Msg)
local Result = Msg
-- Get the | delimiter
local D= Msg:sub(4,4)
Result:gsub(D, "|")
-- Repeat for the other 4 delimeters
return Result
end
Solve one off uncommon problems with one off simple solutions - see separation of concerns.
In Iguana X the normalization can be done in a ‘neuron’ to handle this special edge case.