User bio
404 bio not found
Member since Oct 28, 2021

We identified how to resolve this issue, and I wanted to post the method we implemented.

I welcome any suggestions or ideas that may improve our logic so that we may gain further understanding of the entire process.

I’ll give a high-level explanation of what we did, and then I’ll include the method we used.

  1. Add parent-child relationship properties to the 2 class definitions.

This will leave the parent class untouched, but it will immediately clear out any records that exist in the child class from displaying in a SQL query window.


Start of UpdateRelationship() method:

  1. Loop through the class definition to identify all the properties that exist including their sequence in the storage definition.
  2. Create a new child object
  3. Loop through the data global and populate the child properties from data within this global entry.
  4. Open a parent object and set the relationship by calling the Insert() function from the parent passing in the child object.
  5. Save the parent object.

End of UpdateRelationship() method.


  1. Run the UpdateRelationship() method manually from the Output panel within Studio.

There are a few more checks to verify the objects are valid, and the child has no existing parent object.

We are also deleting the old Index Global entry, as well as logging various information to a global.

The method we used to populate the relationship is outlined below.

Hopefully this will help if you are facing the same issue we were, or at least give you some additional ideas to try.

ClassMethod UpdateRelationshipOrders() As %Status



                #define GW(%w)             Set ^UpdateRelationship($$$CurrentMethod,$I(^UpdateRelationship($$$CurrentMethod)),%w)=$ZDT($H,3,1)


                                s tempcount=0

                                s tSC=1

                                s tSuccessfulRows =0,tFailedRows = 0, tParentExist=0, tNoParent=0

                                s tKey="", tPropertyName="", tPropertyListLocation=""

                                s tDel=",", tDelSub=":"


                                s tStorageName="Default"

                                //Pull oddCOM storage order information

                                s tStorageNameKey="", tStorage=""

                                //Grab the First Storage Definition Name (Usually 'Default')

                                //Grab DefaultData identifier

                                set tStorageNameKey = $O(^oddCOM($classname(),$$$cCLASSstorage,tStorageNameKey))

                                set:tStorageNameKey'="" tStorageName = tStorageNameKey

                                set tStorage = ^oddCOM($classname(),$$$cCLASSstorage,tStorageName,$$$cSDEFdatalocation)

                                set tStorageDefaultData = ^oddCOM($classname(),$$$cCLASSstorage,tStorageName,$$$cSDEFdefaultdata)


                                //Create list of Property names and their correlated storage subscript location

                                For {

                                                set tKey = $O(^oddCOM($classname(),$$$cCLASSstorage,tStorageName,$$$cSDEFdata,tStorageDefaultData,$$$cSDEFDATAvalue,tKey))


                                                set tPropertyName = ^oddCOM($classname(),$$$cCLASSstorage,tStorageName,$$$cSDEFdata,tStorageDefaultData,$$$cSDEFDATAvalue,tKey,$$$cSDEFDATAVALvalue)


                                                //Add to Delimited List

                                                set tPropertyListLocation = $S(tPropertyListLocation="":tPropertyName_tDelSub_tKey,1:tPropertyListLocation_tDel_tPropertyName_tDelSub_tKey)




                                //w $L(tPropertyListLocation,tDel)_" <-- How many items in this list",!


                                s tKey="",tValue="",j=0

                                For {


                                                s tKey= $O(@tStorage@(tKey),1,tValue)


                                                s j=j+1

                                                //W i_": "_tValue

                                                //Confirm this Global is not already a Child of another Parent

                                                s tChildKey="", tChildValue=""

                                                s tChildValue = $O(@tStorage@(tKey,tChildKey))

                                                If tChildValue'=""


                                                                s tParentExist=tParentExist+1



                                                s tData = $LISTTOSTRING(tValue)

                                                //w tData,!



                                                s tOBJ = $CLASSMETHOD($$$CurrentClass,"%New")

                                                //Loops through the List of Properties of the Object

                                                For i=1:1:$L(tPropertyListLocation,tDel) {

                                                                s tFieldProperty = $P(tPropertyListLocation,tDel,i)

                                                                s tProperty = $P(tFieldProperty,tDelSub,1)

                                                                s tLocation = $P(tFieldProperty,tDelSub,2)

                                                                                //first %%CLASSNAME we can ignore


                                                                s tLocationValue = $P(tData,tDel,tLocation)

                                                                //w tProperty_" = "_tLocationValue_" "_tLocation,!


                                                                //Set the Objects Property from the stored Global

                                                                s $PROPERTY(tOBJ,tProperty)=tLocationValue





                                                //zw tOBJ



                                //Open Parent

                                set tParentOBJ = ##class(Package.Class for Parent).%OpenId(tOBJ.ParentID)

                                $$$GW(j_": "_$ISOBJECT(tParentOBJ)_": "_tOBJ.PatientRecordID_" <-- "_tKey)

                                If '$ISOBJECT(tParentOBJ)


                                                s tNoParent=tNoParent+1



                                S tCheckID=""

                                &sql(SELECT ID into :tCheckID FROM Schema_Table for Child WHERE PatientRecordID = :tOBJ.PatientRecordID

                                AND SiteCode = :tOBJ.SiteCode

                                AND OrderID = :tOBJ.OrderID)

                                $$$GW(tCheckID_" "_SQLCODE)

                                If '(tCheckID="")


                                                //W "Exists already: "_tCheckID,!

                                                //Kill Existing Data Global, it's already in the parent child relationship




                                //Follow Parent-Child process, Insert Child into Parent object and save parent

                                Do tParentOBJ.[Relationship Property].Insert(tOBJ)

                                //W $D(^Global for Child Index("PatOrdersIdx"," "_tOBJ.PatientRecordID," "_tOBJ.SiteCode," "_tOBJ.OrderID))

                                //W " <--Data Results",!

                                Kill ^Global for Child Index("PatOrdersIdx"," "_tOBJ.PatientRecordID," "_tOBJ.SiteCode," "_tOBJ.OrderID)

                                s tSC = tParentOBJ.%Save()

                                s tempcount=tempcount+1

                                If tSC {

                                                s tSuccessfulRows=tSuccessfulRows+1  

                                } else {

                                                                $$$GW("Failed on Patient Record ID of ID: "_tOBJ.PatientRecordID_"|"_tOBJ.SiteCode_"|"_tOBJ.OrderID_" | "_tSC)

                                                                s tFailedRows=tFailedRows+1                   






                Catch e


                                s tSC = e.AsStatus()

                                W "Not Right: "_tSC,!    


                W "Encounter Completed",!

                                W "Success: "_tSuccessfulRows_" | Failed: "_tFailedRows_" | ParentExist: "_tParentExist_" | NoParent: "_tNoParent,!

                                $$$GW("Success: "_tSuccessfulRows_" | Failed: "_tFailedRows_" | ParentExist: "_tParentExist_" | NoParent: "_tNoParent)



                                Quit tSC


Craig has no followers yet.
Craig has not followed anybody yet.
Global Masters badges: