Project objects to XML - flatten a property collection
I'm attempting to build a fairly complicated object graph, with nested objects and collections, in order to create a FHIR bundle.
In its most basic form there is a <bundle></bundle> element that represents the root, and there can be a number of nested <entry></entry> child elements.
I'm attempting to represent this as such:
class Bundle (%RegisteredObject, %XML.Adaptor)
{
Property Entries As List Of Entry;
}The problem is when this is projected it nests each Entry object within an Entries container, which makes sense but I don't want this. Is there a way to "flatten" or ignore the container? I can't find anything in the docs relating to this, nor any parameter values that would achieve it.
The XML should look like this instead:
<Bundle><Entry>
...
</Entry><Entry>
...
</Entry><Entry>
...
</Entry></Bundle>Comments
Class DC.Bundle Extends (%RegisteredObject, %XML.Adaptor)
{
Property Entries As list Of Entry(XMLNAME = "Entry", XMLPROJECTION = "ELEMENT");ClassMethod Test()
{
s bnd=..%New()
s ent=##class(Entry).%New(),ent.Name="John",ent.Age=40d bnd.Entries.Insert(ent) k ent
s ent=##class(Entry).%New(),ent.Name="Paul",ent.Age=45d bnd.Entries.Insert(ent) k ent
d bnd.XMLExportToString(.xx) q xx
}
}
Class DC.Entry Extends (%RegisteredObject, %XML.Adaptor)
{
Property Name As%String;Property Age As%Integer;
}
The test output is:
USER>set xml=##class(DC.Bundle).Test()
USER>write xml
<Bundle><Entry><Name>John</Name><Age>40</Age></Entry><Entry><Name>Paul</Name><Age>45</Age></Entry></Bundle>
USER>
USER>zzxs xml
<Bundle>
<Entry>
<Name>John</Name>
<Age>40</Age>
</Entry>
<Entry>
<Name>Paul</Name>
<Age>45</Age>
</Entry>
</Bundle>
USER>
That's great thank you very much for your help
You can, this way:
Property Entry As list Of Entry(XMLPROJECTION = "ELEMENT");
Note that the tag is the name of the list property, not the list item.
Perfect, thank you, that works. I overlooked this because the docs said "ELEMENT" is the default behaviour so I assumed this was also the case for collection properties.
Hi, while others have already addressed your specific XML projection question, I'm wondering why you aren't considering to use IRIS' built-in support for Bulk FHIR exports: https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.U…
We're still using Healthshare 2017.2 unfortunately. Do you know if there is anything similar for our version?
Unfortunately, no. 2017.2 is indeed rather vintage.
💡 This question is considered a Key Question. More details here.