User bio

Senior Software Engineer with over a decade of experience working with InterSystems Products.

Member since Apr 27, 2017
Replies:

Instead of using obj.%Get("property"), you can use %IsDefined("key"), which returns 1 if the key exists.

You can also use %Get("key",, "type"), where the optional type parameter specifies the expected return type. This helps prevent <MAXSTRING> errors when handling values near IRIS's maximum string length.

To enable native JSON support in a persistent class, extend %JSON.Adaptor. This provides built-in methods such as:

  • %JSONImport() — Imports a JSON or DAO directly into the object.
  • %JSONExport()— Export and display the value in the device
  • %JSONExportToString()— Export the value as a string.
  • %JSONExportToStream() — Export the value as a stream
Class Company.Employee Extends (%Persistent,%JSON.Adaptor) {
    Property Name As %String(MAXLEN=50);
    Property Age As %Integer;
    Property Department As %String(MAXLEN=50);

ClassMethod LoadData() As %Staus
{
    Set json = {"Name":"Test", "Age": 20, "Department": "IT"}
    Set obj = ..%New()
    Set sc = obj.%JSONImport(json)
    Set sc = obj.%Save()
    Return sc
}

ClassMethod ExportDataAsJSONString(Id) As %String
{
    Set obj = ..%OpenId(Id)
    Do obj.%JSONExportToString(.string)
    Return string
}

ClassMethod ExportDataAsJSONStream(Id) As %Steam.Object
{
    Set obj = ..%OpenId(Id)
    Do obj.%JSONExportToStream(.stream)
    Return stream
}
}

    If you're working with classes, it's recommended to use object-based or SQL-based data manipulation rather than directly using globals.

    Hi @Rutvik ISM 

    The FHIR binary resource data is exceeding the maximum length allowed by InterSystems IRIS. To store documents such as PDFs and other large data, you should use streams.

    • Use %Stream.GlobalBinary or %Stream.GlobalCharacter to store the data within the database.
    • Use %Stream.FileBinary or %Stream.FileCharacter to store the files on the file system.

    `Hi Rutvik

    You can handle this error with below code. Some sample code

    swt datatype "stream"
    While iter.%GetNext(.key, .value, .datatype) {
    }

    If you want to get the values as a stream from DynamicObject Use %Get(key,,"stream") 

    set stream = dao.%Get(key,,"stream")

    This 3rd parameter support in %GetNext() and %Get()  from 2022 version

    There is a specific reason for using this custom code instead of relying on the built-in %FromJSON() method. The third argument is currently not implemented in the following ##class(HS.FHIR.DTL.vR4.Model.Resource.Binary).%FromJSON(fhirresourceStream)

    ClassMethod SetBinaryR4(json As %DynamicObject) {
       Set obj = ##class(HS.FHIR.DTL.vR4.Model.Resource.Binary).%New()
       Set obj.contentType = json.contentType
       // Convert large data field to stream
       Set dataAsStrm = json.%Get("data",,"stream")
       Set obj.data = dataAsStrm
       Set obj.id = json.id
    }
    

    Thank you!

    Open Exchange applications:
    Certifications & Credly badges:
    Global Masters badges:
    Followers:
    Following: