Iterating HS.SDA3.Container container twice
I initialize a HS.SDA3.Container from a XML stream and I need to iterate over it twice. What is a correct way of doing it? Is it enough to adjust StreamPos/StreamOref?
The optimal solution would be to use one loop, but it's not possible to combine the processing logic.
set oSDA = ##class(HS.SDA3.Container).%New()
do oSDA.InitializeXMLParse(.tQuickStream)
while oSDA.GetNextSDA(.tType, .tPatient) {
// processing logic A
}
set oSDA.StreamPos = 1
do oSDA.StreamOref.Rewind()
while oSDA.GetNextSDA(.tType, .tPatient) {
// processing logic B
}
Product version: IRIS 2022.1
is the stream modified during logic A; I mean, why not to apply logicA & logicB at the same time? where is the restriction for that?
It is unfortunately impossible.
InitializeXMLParse does a lot of necessary things including the following:
This is a lot of overhead. Also, "do oSDA.StreamOref.Rewind()" and "oSDA.StreamPos = 1" fails to re-initialize the ..StreamBuffer.
My suggestion would be to declare a MultiDimensional property in your class:
Property %sdaclass [ MultiDimensional, Private ];
Then follwing any call to GetNextSDA, save the SDA class in the MultiDimensional:
set ..%sdaclass($increment(%sdaclass))=tPatient // replace tPatient with variable returned by GetNextSDA
Your second pass can simply iterate over the MultiDimensional:
set subscript=""
for {
set subscript=$order(..%sdaclass(subscript))
quit:subscript=""
set sdaclass=..%sdaclass(subscript)
... processing logic B
}
Thanks for that detailed reply, @Michael Cronin.
That (StreamBuffer reinitialization by calling FillBuffer) is the first thing GetNextSDA does, so I thought it's okay? Is it not?