Question
· May 6

Converting an HL7 message input into a JSON string in a txt file

Hi everyone,

I’m new to this community and could really use some help with creating a production in InterSystems IRIS for Health Community 2024.3. I have deployed my instance using Docker.
Here’s what I’m trying to do:

  1. Input: I have an HL7 file that is processed by the standard EnsLib.HL7.Service.FileService.
  2. DTL Transformation: I’ve created a DTL to transform the HL7 content into a custom class like this:
Class Demo.MyApp.Messages.JSONEvent5 Extends (%Persistent, %JSON.Adaptor)
{
Property rawpatientid As %String;
Property rawpatientfamilyname As %String;
Property rawpatientgivenname As %String;
Property rawpatientbirthdate As %String;
Property rawpatientgender As %String;
Property rawlocalisation As %String;
Property rawencounternumber As %String;
Property rawpractitionnerid As %String;
Property rawsiteid As %String;
}

This setup allows me to create my DTL with Demo.MyApp.Messages.JSONEvent5 as the target class.

However, I’m stuck after this step. I need to take the result of the DTL transformation and export it into a .txt file using a Business Operation, which will export the file in a specified folder.

I've read a lot about the JSON Adaptor, but I’m having trouble applying it in my case. I tried to create a custom Business Process that applies the DTL and then converts the result to a string using %JSONExportToString, but it’s not working as expected.

Could anyone share an example or guide me on how to properly set up this production ? I’d really appreciate any insights or recommendations.

Feel free to ask if you need more details.

Kind regards,

Product version: IRIS 2024.3
Discussion (4)2
Log in or sign up to continue

Something along these lines should work.

ClassMethod ToEnsStream(obj As %RegisteredObject, Output req As Ens.StreamContainer) As %Status
{
	#dim sc As %Status = $$$OK
	try {
		set stream = ##class(%Stream.GlobalCharacter).%New()
		if obj.%Extends("%JSON.Adaptor") {
			$$$TOE(sc, obj.%JSONExportToStream(.stream))
		} elseif obj.%Extends(##class(%DynamicAbstractObject).%ClassName(1)) {
			do obj.%ToJSON(.stream)
		} else {
			/// try %ZEN.Auxiliary.altJSONProvider:%ObjectToAET?
			throw ##class(%Exception.General).%New("<JSON>")
		}
		set req = ##class(Ens.StreamContainer).%New(stream)
	} catch ex {
		set sc = ex.AsStatus()
	}
	quit sc
}

Hi Luis,
Thank you for your reply.

I tried to the following Business Process but I still does not work.
Did I understand well your reply ?

AgendaOut being my BO (EnsLib.File.PassthroughOperation ; EnsLib.File.OutboundAdapter)
FHIRINTEROPPKG.HL7toRawJSON2 being my DTL transforming a HL7 Input to a Demo.MyApp.Messages.JSONEvent5 target class.

I have tried to use my production with this Business Process but I am encountering an issue at the Business Operation step :

Eduard, I also tried to import your method and use it in my business process but it did not work as well... Maybe i'm using it wrong? That is why I tried to do as mentioned just above by using %JSONExportToStream since I knew that my DTL produces a target class that Extends JSON Adaptor.

Thank you four help,
Kind regards

Quick update on the situation.
Instead of using an assign to use %JSONExportToStream I used a code action :

Then I have dispatched the whole Ens.StreamContainer "context.streamContainer" instead of the stream itself context.streamContainer.stream

And I finally managed to write the in the output file !!!


I'm not sure i'm doing it the best way but it worked!

Should I improve my whole production or is it OK the way it is ?

Kind regards!