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 (2)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
}