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:
then, depending on the content of
or
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
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?
{
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()
}
}
> 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:
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:
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.
Thanks for your helpful reply.
Regards,
Martin
Hi Martin
Instead of using ToXML() method you can use XMLExportToString(.str) or XMLExportToStream(.stm)
It works fine for me.