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

API, HL7, JSON, Ensemble

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

  • 0
  • 0
  • 67
  • 2
  • 1

Answers

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()
// ...

Thanks Nicholai! I swear I tried this in some iteration (I've re-written this a dozen different ways it feels like) but if it's working for you, clearly I haven't! I'll give it a go and mark your answer as accepted once successful.

Appreciate it!

Edit: Yep it worked. Knew it was something simple. Thanks again.

Glad to hear!

Depending on the length of the incoming request, you may hit the length of the Stream Read Buffer. See my updated code for larger messages as you may need to loop your read() statement,

cheers :)