Ciao Enrico, 

thanks for your response. However, I identified and solved the issue. It was a bit tricky to find because, basically, who developed this REST interface before, returned a response through the following statements:

Set ListaPrenotazioni   = ##class(%Library.ListOfDataTypes).%New()
 
 [... Populate the list of data types ...]
 
Do ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.jsonStream,ListaPrenotazioni,,,,"eu")
Do jsonStream.Rewind()
Do jsonStream.OutputToDevice() 

Since at first I put my statements after this code (before OutputToDevice()), I wasn't able to modify the status or the header. I found it out while reading the comment to the method SetHeader, which says:

All headers must be set before the HTTP headers are written (after OnPreHTTP() completes).

It was a bit unintuitive because I didn't expected that generating the stream will prevent any further header or status modification. Basically, I solved just moving all my statements before the code that creates the variable jsonStream:

Set ListaPrenotazioni   = ##class(%Library.ListOfDataTypes).%New()
 
 [... Populate the list of data types ...]

[ In case of error: ]
Do %response.SetHeader("totalcount",totalcount)
Set %response.Status = ..#HTTP400BADREQUEST
[ ... ]

Do ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.jsonStream,ListaPrenotazioni,,,,"eu")
Do jsonStream.Rewind()
Do jsonStream.OutputToDevice() 

Hi Hannah,

Thank you for your response. As you mentioned, the 'arrayref()' function is not available in IRIS 2023.1, as I suspected.

However, I managed to resolve this issue by developing a custom method to convert a Python dictionary into an ObjectScript dynamic object. I believe it works quite effectively.

I'll share the code here for anyone interested:

/// This class provides methods for working with embedded Python in various scenarios
Class Utility.Python Extends %RegisteredObject
{

/// ConvertPyDictToDynamicObject recursively converts a Python dictionary to an ObjectScript DynamicObject
/// 
/// Input:
/// - PythonDictionary: The Python dictionary to be converted
/// 
/// Output:
/// Returns a DynamicObject with similar structure and content of the parsed Python dictionary
ClassMethod ConvertPyDictToDynamicObject(PythonDictionary) [ Language = python ]
{
    import iris

    # This is a recursive function to parse a Python dictionary and convert it into an ObjectScript %DynamicObject
    # The method takes two parameters: 'data', which represents the current dictionary being parsed, and 'depth', which keeps track of the nesting level of the current data
    def parse_dictionary_to_dynamic_object(data, depth=0):
        # Create a new ObjectScript DynamicObject through iris module
        dynamic_object = iris.cls('%DynamicObject')._New()

        # If data is a dictionary, iterate through its key-value pairs
        if isinstance(data, dict):
            for key, value in data.items():
                # Recursively parse the value and set it in the DynamicObject
                parsed_value = parse_dictionary_to_dynamic_object(value, depth + 1)
                dynamic_object._Set(key, parsed_value)
        # If data is a list, create a %DynamicArray and parse each item of the list recursively
        elif isinstance(data, list):
            dynamic_array = iris.cls('%DynamicArray')._New()
            for item in data:
                parsed_item = parse_dictionary_to_dynamic_object(item, depth)
                dynamic_array._Push(parsed_item)
            return dynamic_array
        # If data is neither a dictionary nor a list, return the data itself
        else:
            return data

        return dynamic_object
    
    # Call the recursive parsing function with the input Python dictionary
    dynamic_object = parse_dictionary_to_dynamic_object(PythonDictionary)

    # Return the parsed DynamicObject
    return dynamic_object
}

}

You can easily test this method with complex dictionaries, like the one in the following example:

ClassMethod StartTestPyDictConverter()
{
    set dynObj = ##class(Python.MessageBuilder).TestPyDictConverter()
    w "dynObj tested",!
}

ClassMethod TestPyDictConverter() [ Language = python ]
{
    import iris

    data = {
        "person": {
            "name": "John Doe",
            "age": 30,
            "address": {
                "street": "123 Main St",
                "city": "Anytown",
                "zipcode": "12345"
            },
            "emails": ["john@example.com", "doe@example.com"],
            "phone_numbers": [
                {
                    "type": "home",
                    "number": "123-456-7890"
                },
                {
                    "type": "work",
                    "number": "987-654-3210"
                }
            ],
            "friends": [
                {
                    "name": "Alice",
                    "age": 28,
                    "address": {
                        "street": "456 Elm St",
                        "city": "Sometown",
                        "zipcode": "54321"
                    },
                    "emails": ["alice@example.com"],
                    "phone_numbers": [
                        {
                            "type": "mobile",
                            "number": "555-555-5555"
                        }
                    ],
                    "pets": [
                        {
                            "name": "Fluffy",
                            "species": "Cat",
                            "age": 5
                        },
                        {
                            "name": "Spot",
                            "species": "Dog",
                            "age": 3
                        }
                    ]
                },
                {
                    "name": "Bob",
                    "age": 35,
                    "address": {
                        "street": "789 Oak St",
                        "city": "Othertown",
                        "zipcode": "67890"
                    },
                    "emails": ["bob@example.com"],
                    "phone_numbers": [
                        {
                            "type": "mobile",
                            "number": "666-666-6666"
                        }
                    ]
                }
            ]
        },
        "company": {
            "name": "Acme Corporation",
            "address": {
                "street": "456 Business Ave",
                "city": "Bigcity",
                "zipcode": "54321"
            },
            "employees": [
                {
                    "name": "Jane Smith",
                    "position": "Manager",
                    "age": 40,
                    "emails": ["jane@example.com"],
                    "phone_numbers": [
                        {
                            "type": "work",
                            "number": "222-222-2222"
                        }
                    ]
                },
                {
                    "name": "Sam Johnson",
                    "position": "Developer",
                    "age": 35,
                    "emails": ["sam@example.com"],
                    "phone_numbers": [
                        {
                            "type": "work",
                            "number": "333-333-3333"
                        }
                    ]
                }
            ]
        }
    }

    dynObj = iris.cls('Utility.Python').ConvertPyDictToDynamicObject(data)

    return dynObj
}

I've tested it even with more complex dictionaries, like FHIR JSON, and it worked fine.

For example, this is a screenshot from my VSC Debugger: 

I know that answering a question and providing your own response may seem unusual, but I won't delete this question as it could be helpful to someone in the future.

The issue was related to the method "jsonFormatter.FormatToStream", which returned "ByRef" a pStream object that, for some reason, Postman and the other client software didn't handle well. 

A solution is to remove the jsonFormatter and to pass directly the OriginalStream to the function:

Set pResponse = ##class(EnsLib.HTTP.GenericMessage).%New(OriginalStream,,tHttpResponse)

If you prefer to keep the JSONFormatter, just declare the pStream as an object of %Stream.FileCharacter class before using the FormatToStream method:

// Format the newJson with the correct indentation
Set jsonFormatter = ##class(%JSON.Formatter).%New()
// Declare a new stream object
Set pStream = ##class(%Stream.FileCharacter).%New()
Set sc = jsonFormatter.FormatToStream(jsonACK, .pStream)

Now everything works fine.

I don't know if this can help, but in objectscript the command to extract some elements from a list is the following: 

SELECT * FROM <tableName> WHERE FOR SOME %ELEMENT (<listName>) (%VALUE = '<value>')

For example, if you have a persistent class like this: 

Class User.SQLtable Extends %Persistent
{
    Property propertyList As list Of %String(MAXLEN = 100) [ Required ];
    Index ListIdx On List(ELEMENTS);
}

You can extract information using: 
SELECT * FROM User.SQLtable WHERE FOR SOME %ELEMENT (propertyList) (%VALUE = '67')

In this way you can retrieve the row that contains the specific data value of interest with dynamic or static SQL and subsequently extract the list as a property of the SQL result object

Hi Pravin, 

You can use the syntax ./folderName in the files to include camp from the Search panel. 

Example

This is my workspace

I have 3 folders: 2 on a remote server and one in local.

If I would like to restrict the research only to a remote folder I can type: ./npri_server_fhir:OMR

As shown in the following picture:

Make sure you have followed the procedure outlined at this page (InterSystems ObjectScript extension for VS Code), under Enable proposed APIs, to enable the search across all folders.

To conclude this discussion, I've summarized the solutions that have been suggested:

  1. For Visual Studio Code (VSC) Users with IRIS 2020.1.1 or IRIS 2021.1.2: Users that have IRIS 2020.1.1 or IRIS 2021.1.2 and that are able to install external extensions, might find useful the Web Terminal extension for VSC. This extension enables to launch a web-based terminal directly from VSC. 
  2. For VSC Users with IRIS 2023.2: As suggested by @John Murray in a previous response, users of IRIS 2023.2 can take advantage of the new "WebSocket Terminal" feature included in the latest version of the VSC extensions and they don’t need for additional workarounds.
  3. For VSC Users with Docker-based IRIS: Those working with IRIS environments within Docker and using VSC can start a terminal session directly within the Docker environment, as suggested by @Evgeny Shvarov.  

Additionally, I've come across a few more solutions:

  1. For VSC users with IRIS Versions Prior to 2023.2 working on their local machine: In this case it’s possible to set up a dedicated IRIS terminal within VSC:
    1. Open the settings.json file.
    2. Add the following code under "terminal.integrated.profiles.windows":
"IRIS Terminal": {
    "path": [
        "C:\\InterSystems\\IRISHealth\\bin\\irissession.exe"
    ],
    "args": ["IRISHEALTH"],
    "icon": "terminal-cmd"
}

Note: Select the right path of irissession.exe.

c. Navigate to: Terminal > New Terminal > Launch Profile… > IRIS Terminal.

  1. For VSC Users Coding on IRIS based on a remote server using an SSH connection: For those who code on a remote server (e.g., a company server) accessible via SSH connection (e.g., using Putty) it is possible to use the Remote - SSH VSC extension to connect directly to the server. In order to do so:
    1. Install the Remote - SSH: Editing Configuration Files extension on VSC;
    2. Click on the “Remote Explorer icon in the sidebar;
    3. Select “Open Configuration Fileto open the “ssh_configfile.
    4. Insert the following code into the configuration file: 
Host my-putty-connection
    HostName < IP address or server name >
    User < username >
    IdentityFile < private key path on your local machine >
    Port < port >
    1. Save the file. After a few seconds the new connection should appear in the Remote Explorer panel;
    2. Click “Connect in New Window
    3. In the new window, navigato to: Terminal > New Terminal. You’re now connected to the remote machine and can use its IRIS terminal within VSC.