Question
· Apr 24, 2018

Retrieving HL7 message from SQL field and then sending out

Hi, folks. I have an HL7 SIU message inbound that is missing a few fields, such as patient ID and provider ID. I insert this HL7 message and a few of the fields into a SQL database. My SQL team then runs a stored procedure to retrieve the patient ID and provider ID and insert the found values into fields in the table. I would like to then do a select from the table, load the HL7 message and add the fields that were found by the SQL stored procedure into the HL7 message. I'm attempting to use a DTL to accomplish this. My sourceclass is CustomEDI.SQLSIUInRequest and targetClass is EnsLib.HL7.Message

The first statement in my DTL is:

<code>
<![CDATA[ set SIUString = source.ImportFromString(source.SchedulingData,.tSC)
 if $$$ISERR(tSC) quit
 set target = SIUString]]></code>

Any subsequent references to the outbound HL7 fields causes an error.

I assume my problem is trying to copy a string to a fixed HL7 format. Anyone have an idea on how to accomplish what I'd like to do?

My issue is similar to a post titled SQL Store Procedure Output (String) into HL7 message   which provides a solution, but I'm not sure where I would put the code to cast the incoming string to an HL7 message.

Thank you.

Discussion (4)1
Log in or sign up to continue

you would need to give a lot more detail about  CustomEDI.SQLSIUInRequest and its ImportFromString method for anyone to tell you what is going wrong. What data type does the ImportFromString return, and have you tested it in isolation?

I think the 'normal' way to do this, would be to leave the HL7 message as an object. You could use a business process that extracts only the fields that are needed to retrieve the patient ID and send that to the SQL database. But i suspect you already have external logic that processes a whole serialized HL7 message.

The SQLSIUInRequest class just looks like this:

Property CounterID As %Integer;
Property Enumber As %String;
Property SourceIDType As %String;
Property EpicProviderID As %String;
Property EpicDepartmentID As %String;
Property SchedulingData As %String(MAXLEN = 2048);

Where the SchedulingData field contains the HL7 message which was inserted using a DTL with a code statement as follows:

 set SIUString = source.OutputToString("|^~\&",.tSC)
 if $$$ISERR(tSC) quit
 set target.SchedulingData = SIUString

I am not doing an ImportFromString yet. If I was to use the ImportFromString, would I put in in the OnProcessInput method in my inbound service?

Solved. I added a code statement as the first line of my DTL as follows:

 set target = ##class(EnsLib.HL7.Message).ImportFromString(source.SchedulingData)
 set target.DocType = ##class(EnsLib.HL7.Schema).ResolveSchemaTypeToDocType("2.3.1","SIU_S12",tSC)

This loaded my HL7 class with the message from my SQL table field.

Thanks to David for steering me in the right direction.