Question
· Feb 2, 2022

Creating FHIR XML response results in Exception

Hello community,

on my first steps with processing FHIR requests, I tried to create a capability statement resource an returning its content JSON or XML, depending on what is requested by the client.

I create a CapabilityStatement object by parsing a JSON file with:

#dim tCapStat as HS.FHIR.DTL.vR4.Model.Resource.CapabilityStatement = ##class(HS.FHIR.DTL.vR4.Model.Resource.CapabilityStatement).FromJSONFile("/opt/home/data/fhir/UkerQsCapabilityStatement.json","vR4")

then, depending on the content of  pRequest.Request.ResponseFormatCode I create a HS.SDA3.QuickStream Object with

do tStream.CopyFrom(tCapStat.ToJSON())

or

do tStream.CopyFrom(tCapStat.ToXML())

In the first case everythin works quite fine as expected,

in the second case an exception occurres:

An exception occurred: <FUNCTION> zToXMLHelper+5^HS.FHIR.DTL.vR4.Model.Resource.CapabilityStatement.1
With an event text saying: ERROR <Ens>ErrException: <FUNCTION>zToXMLHelper+5^HS.FHIR.DTL.vR4.Model.Resource.CapabilityStatement.1 -- logged as '-' number - @' if (r%id)&&(..id '= "") {'

I'd really appreciate, if I could get a hint what goes wrong here.

Thanks and regards,

Martin 

Product version: IRIS 2021.1
$ZV: IRIS for UNIX (SUSE Linux Enterprise Server for x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:48:27 EDT
Discussion (4)2
Log in or sign up to continue

Hello community,

I'm trying to break it down to the core problem: why does this function return the following output when trying to create a XML stream - is this a bug?

Class HOME.ms.MsFunctionSet Extends Ens.Rule.FunctionSet
{

ClassMethod FhirToXmlExample() As %Status
  {
    #dim tCapStat as HS.FHIR.DTL.vR4.Model.Resource.CapabilityStatement;
    set tCapStat = ##class(HS.FHIR.DTL.vR4.Model.Resource.CapabilityStatement).%New()
    w tCapStat.ToJSON()
    w tCapStat.ToXML()
  }
}

> do ##class(HOME.ms.MsFunctionSet).FhirToXmlExample()
> 426@%Stream.TmpCharacter
> do ##class(HOME.ms.MsFunctionSet).FhirToXmlExample() - Error <FUNCTION>

Regards,

Martin

The ToXML function is broken. This is a known bug (I've reported it mid-Januari).

It is possible to fix it, but it requires patching system code, class HS.FHIR.DTL.Util.XML.Adapter to be precise.

In that class, at (on my system, 2021.2) line 359 (in method ToXMLHelper), there is this statement:

set isprimitive = ($extract(propType)="%")

This basically assumes all properties are objects, except those that start with a %-sign. This is obviously wrong. The code will work if you replace that statement with this:

set isprimitive = ($extract(propType)="%") || (propType="") || ($$$classIsDataType(propType))

Here we additionally check for properties without a type (DomainResource has one: property id), and typed properties that are datatypes. With this change, the ToXML() method works for me.

HTH,
Gertjan.