Question
· Jun 1, 2021

Storing a %DynamicObject

I've been tasked with an interface that needs to supply some additional metadata for the indexing of HL7v2 messages. After toying with a couple of ideas, I thought that it would be useful to subclass EnsLib.HL7.Message, add a %DynamicObject property, and store the metadata in it (it ends up getting sent to the target in JSON form anyway).

And, well, it seems to work just fine ... so far.

I seem to remember that %DynamicObjects are not persistent, and for that reason not something you would normally stuff into a database. I was a little surprised when things worked as I had hoped. With ZWRITE, the literal name of the property doesn't show up in the list of attributes, but it does show with an i% prefix under swizzled references. It also shows up, along with assigned contents, in an SQL query of the projected table. I can modify it in a DTL and the values seem to persist.

I just have this odd feeling that what I'm doing is NOT OK. Can someone confirm one way or another?

Product version: HealthShare 2020.2
$ZV: 2020.2.0HC (Build 180U)
Discussion (4)2
Log in or sign up to continue

The %DynamicAbstractObject classes (%DynamicArray and %DynamicObject) are not %Persistent as they cannot be directly written into a database of class objects.  However, most %DynamicAbstractObject objects can be serialized with the %GetSerial method which produces a JSON string value or with the %GetSwizzleObject method which builds an OID containing the JSON string value.  And a Serial object can be the value of a Property internal to a %Persistent object.

The %DynamicAbstractObject objects can contain elements which are either JSON values or ObjectScript values. Any element which can be translated into a JSON value can be serialized with the %GetSerial/%GetSwizzleObject methods.  However, if a %Dynamic object contains ObjectScript values that are not representable in JSON then that %Dynamic object cannot be serialialized.  Examples of ObjectScript values that cannot be translated into JSON include $double("nan"), $double("infinity"), $double("-infinity") and any oref not a member of the %DynamicArray or %DynamicObject classes.  Also, the %DynamicArray and %DynamicObject classes can contain string element values much longer than the %String values supported by ObjectScript.  If the JSON translation of a %DynamicArray or a %DynamicObject results in a string longer than the ObjectScript maximum string length then the serialization of the object will fail.  However, the JSON translation of a large %Dynamic object can be stored into a class of the %Stream package that is abled to be swizzled.  Such a swizzled object can be a Property in a %Persistent object.  However, the %Stream property must be processed by the %FromJSON(stream) method in order to turn the %Stream into a %DynamicAbstractObject object.