Question
· Sep 30, 2019

Parse HL7 Content from JSON Request into EnsLib.HL7.Message Object

Good morning -

I am attempting to pass some HL7 content (say, a complete ADT message) from one server to another via REST/JSON - for reasons. 

I can get the data across but when I try to create an EnsLib.HL7.Message object from the message in the JSON body, I end up with just the start of an HL7 msg in the resulting object. Looks like: MSH|^~\&

The start of the code accepting the data looks like this:

tReq = {}.%FromJSON(%request.Content.Read())
tInput = tReq.Message

tMsg = ##class(EnsLib.HL7.Message).%New()
tMsg.ImportFromString(tInput)
tMsg.DocType = "2.3.1:ADT_A01"

So now if I take that tMsg and try to send it to an Adapterless Business Service and/or simply try to output what it receives to a file, I get basically nothing. I've tried multiple methods to get the string HL7 Content (from the JSON body) into the EnsLib.HL7.Message object to no avail. I feel like I'm missing something quite simple so tossing this out there in hopes I can move past this on to better things. Thanks,

Craig R

Discussion (3)2
Log in or sign up to continue

Hi Craig,

ImportFromString returns an HL7 Message, it does not populate an existing instance of EnsLib.HL7.Message.

Moreover, make sure that you are reading the entire message with %request.Content.Read, you'll probably want to wrap that in a loop.

Here is the code I get to work on my instance (2017.1)
 

SET tContent = %request.Content.Read()
WHILE '%request.Content.AtEnd {
SET tContent = tContent + %request.Content.Read()
}
SET tReq = {}.%FromJSON(tContent)
SET tInput = tReq.Message
// Remove your %New() statement and set tMsg like this
SET tMsg = ##class(EnsLib.HL7.Message).ImportFromString(tInput)
// Then you can either set the doctype manually or use PokeDocType()
// ...