Thanks Marc, unfortunately we are using an older version of Healthshare (2017) and the %Get method doesnt include the type parameter and only has the key. The method listed in the system is as follows:

Method %Get(key) As %CacheString
{
    
    try {
set ans = $zu(210,10, .key)
    catch do $$$APPERROR1($$$LASTERROR) }
    ans
}

Are there any other methods that can be used?

Thanks!

Hi Julius,

I may have posed my question incorrectly but if I leave the HL7 part out, the issue I have is for the repeated array objects like NOKName . An example of pData is as follows:

[
  {
    "patient":
      {
        "guid":"12345",
        "id":12345,
        "forename":"Joe",
        "surname":"Bloggs",
        "dateOfBirth":"2002-12-10T00:00:00Z",
        "NOK":[
                {
                   "NOKname":"Alison Bloggs",
                   "NOKrelationship":"Wife",
                   "telephone":"02081234567",
                   "email":"alison@bloggs.com"
                }
                {
                   "NOKname":"Peter Bloggs",
                   "NOKrelationship":"Father",
                   "telephone":"02081234567",
                   "email":"Peter@bloggs.com"
                }
              ]
      }
  }
]

The code I have used is:

Method GetDataFromStream(pData As %Stream)
{

    set object={}.%FromJSON(pData)
    set size1=object.%Size()
    set i=0
    for i=0:1:size1-1
    {
        
        set MyGuid=object.%Get(i).patient.guid
        set Myid=object.%Get(i).patient.id
        set MyForename=object.%Get(i).patient.forename
        set MySurname=object.%Get(i).patient.surname
        set MyDOB=object.%Get(i).patient.dateOfBirth
    
        set j=0
        set NOK = object.%Get(i).NOK
        for j=0:1:ref.NOK.%Size()-1  
        {
            set MyNOKname=NOK.%Get(j).NOKname
        }
    }
}

The problem is the variable "MyNOKName" only stores last value i.e. "Peter Bloggs". I would like to be able to store every instance of the "NOKName"  in a seperate variable based on the index(j) and use all of them at a later stage in the method. For instance MyNOKName(1) = "Alison Bloggs", MyNOKName(2)="Peter Bloggs"

Are you able to let me know if there is a way to do that?

Hi Vic,

Thank you for this. I used the code that Eduard had referenced for the Iterate method and was able to use a Trace to see all the relevant values and keys. The code I have used so far is as follows including the traces are:

Method Iterate(object As %DynamicAbstractObject, level = 0, path = "object")
{     set iterator = object.%GetIterator()
        set indent = $j("", level * 4)
    #dim iterator As %Iterator.Array
    set iterator = object.%GetIterator()
    
    while iterator.%GetNext(.key, .value) {
        set type = object.%GetTypeOf(key)
        set key=key
        
        $$$TRACE("key: "_key)
        
        set type=type
        
        $$$TRACE("type: "_type)
        
        if $classname(object) = "%Library.DynamicArray" {
            set newPath = path _ ".%GetAt(" _ key _ ")"
        else {
            if $zname(key, 6) = 1 {
                set newPath = path _ "." _ key
            else {
                set newPath = path _ ".""" _ key _ """"
            }
        }
        
        set path1=newPath
        
        $$$TRACE("path: "_path1)
        
        if $isObject(value) {
   
            
            do ..Iterate(value, level + 1, newPath)
        else {
            set value=value
            
            $$$TRACE("Value: "_value)
        }
    }
}

I have come across some problems with the HL7 message generation within the iterate method. I am unsure as to where to place the code to generate message and how to code the relevant keys/value in the relevant segments.  I tried to place the code as below :

while iterator.%GetNext(.key, .value) {

 Set RefMess = ##class(EnsLib.HL7.Message).%New()
Set RefMess.DocType="2.4Epic:REF_I12"

but this code caused for multiple messages to be created and I was unsure what the trigger was. I have tried to place the code outside the while loop and it still produced less than expected messages as I would expect a message to be triggered for each patient within my response. Do you have any suggestions on where the message generation code should go and also how to set the value from the response into a particular segment?

Hey Julius,

Sorry I have another query related to this so not sure if I should post it here or as another question so putting here for now.

We have done the extractions and loops and used it to set to some variables. The variables are then used to create a HL7 message. For the values which are extracted from the loop we find they are over-writing the value from> The coding so far:
NOK name - We are doing the following to set the value to a variable:

set NOKName = object.%Get(i).referral.nextOfKin.%Get(k).name

we are then setting the NOKname into a HL7 segment as follows as part of the same loop:

d RefMessage.SetValueAt("1", "NK1:SetIDNK1")
d RefMessage.SetValueAt(NOKname, "NK1(1):Name")

With this code we would like it whereby each time there is a new NOKname then a new segment value or a new segment is added to the HL7 message rather than over-writing the first value from the loop. Do you have any ideas how that would be possible?

Sorry I have one more question as I've come across a problem again:

I have a property called "NOK" which is part of the "patient" object, however the "NOK" has its own individual properties too - "NOKname", "NOKrelationship", "NOKemail", "NOKtelephone". NOK is also an array as you could have multiple instances of NOK. I understand I can use the loop suggestion to retrieve the arrays but I am struggling to extract the  initial properties of NOKname etc. An example of the patient section is below:

[
 {
  "patient":{
   "guid":"12345",
   "id":12345,
   "forename":"Joe",
   "surname":"Bloggs",
   "dateOfBirth":"2002-12-10T00:00:00Z",
   "NOK": [
                    {
                      "NOKname": "Alison Bloggs",
                      "NOKrelationship": "Wife",
                      "telephone": "02081234567",
                      "email": "alison@bloggs.com",

      }
  ],
 },

I have tried the following an either get an empty value or an undefined value:

set firstArrayItem = {}.%FromJSON(pData) 

set patient = firstArrayItem.patient

set NOK=patient.NOK

set NOKName=NOK.NOKname

which gives me a value like :  29@Library.DynamicObject

If I try not including the patient and going straight to NOK and then NOKName it gives me a blank response

Any suggestions on how I get the values for NOKname etc?

 

Sorry - I manually created the sample of pData I shared with you as I couldn't use the original API response so the typo's are all my mistake. Thanks for your tool to check the JSON string - I have been able to confirm that my version of pData is a JSON string.

Any other suggestions as to how I can figure out what the issue is?

Thanks all for your suggestions so far! I have tried your suggestions and still not ale to output the values.

A sample of structure of pData is below:

[{"patient":{"guid":"12345","id":12345,"forename":"Joe","surname":"Bloggs","dateOfBirth":"2002-12-10T00:00:00Z"},"visit":[{"guid":45678", "date": "2020-01-10", "reason":"other"}{"guid": 45679, "date": "2020-01-11", "reason": "routine"}],"documentAttachments": [{"guid": "23432","id": 152,"catergory": "notes"}{"guid":"23433","id":153,"catergory": "summary"}]}
{"patient":{"guid":"12332","id":12332,"forename":"Jack","surname":"Evans","dateOfBirth":"2000-01-13T00:00:00Z"},"visit":[{"guid":45600", "date": "2020-02-11", "reason":"routine"}],"documentAttachments": [{"guid": "23411","id": 167,"catergory": "notes"}]}
]

pData may have one or more instances of patient data and within each patient record, there are multiple subsections like Visit and Document attachments which can also have multiple instances.

In all of your suggestions you have suggested to use the WRITE function, but as I am doing this in Studio I am not sure how I can use this to set it to a property within my other class message. Any suggestions on other commands I can use instead of the WRITE?