Smythe Smythee · Aug 10

How to read from Ens.StreamContainer


I am receiving a JSON File as Stream container Using  pRequest As Ens.StreamContainer and output as  Output pResponse As %Persistent in a Custom Business Operation 

Please find the code below

Method OnMessage(pRequest As Ens.StreamContainer, Output pResponse As %Persistent) As %Status
    Set tFilename=..Adapter.CreateFilename(##class(%File).GetFilename(pRequest.OriginalFilename),..Filename)
    Set tSC=..Adapter.PutStream(tFilename, pRequest.Stream)
    Quit tSC


Question:How can i extract name,DOB,SSN from the pRequest and save the same values in SQL persistant table?


Please find the JSON Output below

{"name":"PATID1234^5^M11^ADT1^MR^GOOD HEALTH HOSPITAL~123456789^^^USSSA^SS","DOB":"19610615","SSN":"ADT1"}




Product version: Ensemble 2016.1
$ZV: Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT
0 213
Discussion (5)1
Log in or sign up to continue

Just parse the stream  and save it

Hi ,

How can i get individual values from the stream like name,DOB,SSN

To parse the json, the below is a starting point for taking the content of the stream into a dynamic object, and then saving the value into its own variable.

Set DynamicObject=[].%FromJSON(pRequest.Stream)
Set Name =
Set DOB = DynamicObject.DOB
Set SSN = DynamicObject.SSN

You could then store these wherever you need to. If your SQL table is external, then you could have your Operation using the SQL Outbound Adapter to then write these in your external DB.

ETA: If you then need to pick out the values within the content of name (which I assume has come from a HL7 message) you could use $PIECE to pick out the data from the delimited string you're receiving.

Thank you i am able to change HL7 file to JSON by using custom Process and Custom Operation

But after the file is passed from the Business Process the file returning to the Business Process   from the Business operation  with a null Output. If you know why this Scenario happens please let me know

Your Process is most likely using ..SendRequestAsync() to send to the Operation and has "pResponseRequired" set to 1 (or not set at all, so it's using the default value of 1).

There's nothing inherently wrong with this, but if you just want to send to the Operation and not worry about the response going back to your process, you could change the "pResponseRequired" flag to 0 in your call. So it would look a little like this:

Set tSC = ..SendRequestAsync("TargetOperationName",ObjToSend,0)

However you may wish to consider if this approach is appropriate to your setup, or if you would be better off using "SendRequestSync()" and dealing with the response synchronously.