Ashok Kumar T · Oct 13, 2025 go to post

Hi @Lucrezia Puntorieri 
Yes you can create a method and classmethod programmatically.

Set clsmethodObj = ##class(%Dictionary.MethodDefinition).%New()
Set clsmethodObj.Name="TestClsMethod"
Set clsmethodObj.ClassMethod=1
Do clsmethodObj.Implementation.WriteLine($C(9)_"Set ^test=""Test"" ")
Do clsmethodObj.Implementation.WriteLine($C(9)_"Quit ^test ")

Set methodObj = ##class(%Dictionary.MethodDefinition).%New()
Set methodObj.Name="TestMethod"
Set methodObj.ClassMethod=0
Do methodObj.Implementation.WriteLine($C(9)_"For I=1:1:10 { S ^test(i)=i} ")
Do methodObj.Implementation.WriteLine($C(9)_"Quit ^test ")

Do clsObj.Methods.Insert(clsmethodObj)
Do clsObj.Methods.Insert(methodObj)
Ashok Kumar T · Oct 11, 2025 go to post

Hi Jack

IRIS does not provide built-in functionality to generate classes directly from a JSON Schema, unlike the support available for XML Schema (XSD). However, you can programmatically create and compile classes at runtime using the %Dictionary.ClassDefinition API.

Here is the sample code to generate a class.

ClassMethod CreateClass()
{	
	Set clsObj = ##class(%Dictionary.ClassDefinition).%New()
	Set clsObj.Name="Test.NewClass"
	Set clsObj.Super="%RegisteredObject,%JSON.Adaptor"
	Set clsObj.Description="Class created via code"
	Set clsObj.DdlAllowed = 1
	Set clsObj.Inheritance="left"
	
	Set propObj = ##class(%Dictionary.PropertyDefinition).%New()
	Set propObj.Name="Name"
	Set propObj.Type="%String"
	Set propObj.SqlColumnNumber=2
	Do propObj.Parameters.SetAt(70,"MAXLEN")
	
	Set indexObj = ##class(%Dictionary.IndexDefinition).%New()
	Set indexObj.Name="NameIdx"
	Set indexObj.Properties="Name"
	Do clsObj.Properties.Insert(propObj)
	Do clsObj.Indices.Insert( indexObj)
	Set st=  clsObj.%Save()
	D $SYSTEM.OBJ.Compile("Test.NewClass","ckb")
	If $$$ISERR(st) w $SYSTEM.OBJ.DisplayError(st)
}
Ashok Kumar T · Sep 28, 2025 go to post

Hello @Julius Kavay 

Thanks for pointing that out — you're absolutely right. The generator method for property initialization is missing. However, we are able to create an instance of %CSP.Page

Ashok Kumar T · Sep 4, 2025 go to post

Hello @Matheus Augusto 

%Stream.TmpCharacter is used to temporarily hold stream data in IRIS for application usage, typically in-memory and not persisted to the database.

Ashok Kumar T · Aug 21, 2025 go to post

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.

    Ashok Kumar T · Aug 21, 2025 go to post

    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.
    Ashok Kumar T · Aug 21, 2025 go to post

    `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!

    Ashok Kumar T · Aug 21, 2025 go to post

    Kudos to You! 🎉 Your efforts have made a real difference. The passion and commitment you bring have not only contributed greatly but also sparked meaningful change.

    Thank you

    Ashok Kumar T · Aug 5, 2025 go to post

    The %BuildIndices class method is used to rebuild all indices on the class. To run it asynchronously, use the following:

    Do ##class(Ens.Util.Log).%BuildIndices()
    Do ##class(Ens.Util.Log).%BuildIndicesAsync()
    

    To rebuild a specific index, pass the index name as a list value:

    Do ##class(Ens.Util.Log).%BuildIndices($LB("TimeLogged"))

    You can also rebuild indices using SQL from 2021 version

    Rebuild all indices

    BUILD INDEX FOR TABLE Ens_Util.Log

    Rebuild a specific index

    BUILD INDEX FOR TABLE Ens_Util.Log INDEX TimeLogged
    Ashok Kumar T · Aug 5, 2025 go to post

    Hi @shima Avakh 

    Ens.Queue class provides various methods for working with queues. Queue-related information is stored in the global ^Ens.QueueTo abort messages from a specific queue, you can use the following class method

    Do ##class(Ens.Queue).AbortQueue(pQueueName) 

    Replace pQueueName with the name of the queue you want to abort. This method allows you to target and abort messages in a specific queue.

    Ashok Kumar T · Jul 23, 2025 go to post

    Thank you for the explantaion @Steven Hobbs .In the subroutine ETNMINIM, the date is retrieved solely from $H (S h=$H). Given that, why are the errors recorded under the date 01/06/1841 ($ZDH=6) in ^ERRORS instead of the actual date on which the error occurred?

    Ashok Kumar T · Jul 21, 2025 go to post

    You can use the Log() method  or do LOG^%ETN(ErrorMessage) inside the Try{} Catch ex{} block and routine to capture the error on Application Errors.

    Ashok Kumar T · Jul 17, 2025 go to post

    Hello @PhoebeK 

    If emailAttachmentList is a DynamicArray, then the following property declaration is correct:

    Attempt 2 // 
    Property emailAttachmentList As List of Request.EmailAttachment(%JSONFIELDNAME = "emailAttachmentList");

    It looks like you're trying to set the value directly like:
        callrequest.emailAttachmentList.attachmentClass = "application/xml"

    However, since emailAttachmentList is a list, you need to either:
    - Use %JSONImport(response) to populate the list properly (e.g., `callrequest.%JSONImport(response)`), or
    - Loop through the list and set the property on each individual item, like this:

    For i=1:1:callrequest.emailAttachmentList.Count() {
      Set callrequest.emailAttachmentList.GetAt(i).attachmentClass = "application/xml"
    }
    Ashok Kumar T · Jul 14, 2025 go to post

    The name property is  Property name As HS.FHIRModel.R4.SeqOfHumanNameand the SeqOfHumanName class have  Property list As %Library.DynamicArray;
    This list property holds the object of  HS.FHIRModel.R4.HumanName

    Ashok Kumar T · Jul 11, 2025 go to post

    Hello @Scott Roth 
    I hope the target is a object reference of  HS.FHIRModel.R4.Patientand the "name" property in in R4.Patient is an object property(HS.FHIRModel.R4.SeqOfHumanName ) and thisSeqOfHumanName stores the %DynamicArray of  HS.FHIRModel.R4.HumanName object values into property called "list" 

    So, First we have to check the name is  $IsObject(r4Patient.name)&&(r4Patient.name.%IsA("HS.FHIRModel.R4.SeqOfHumanName")) and if it's true you can iterate the list (%DynamicArray)   Set iter = r4Patient.name.list.%GetIterator()

    You can directly copy and run this example directly and it works for me.

    ClassMethod ParseHumanName()
    {
        Set r4Patient = ##class(HS.FHIRModel.R4.Patient).%New()
        ;
        Set seqHuman = ##class(HS.FHIRModel.R4.SeqOfHumanName).%New()
        ; create human name for seqHuman
        Set human = ##class(HS.FHIRModel.R4.HumanName).%New()
        Set human.family="pil"
        Set human.text="Ashok,kumar"
        ;
        ;push the HumanName into SeqOfHumanName
        Do seqHuman.add(human)
        
        ; Set SeqOfHumanName into Patient.name
        Set r4Patient.name = seqHuman
        
        If $IsObject(r4Patient.name)&&(r4Patient.name.%IsA("HS.FHIRModel.R4.SeqOfHumanName")) {
            Set iter = r4Patient.name.list.%GetIterator()
            #;
            while iter.%GetNext(,.humanName) {
                zw humanName.toDao()
            }
        }
        quit
    }
    Ashok Kumar T · Jul 9, 2025 go to post

    I have full access and permissions for the directory and %All is my role. I'm able to connect to the %SYS and USER namespaces, but I'm unable to access the namespaces mapped the HS package( c:\intersystems\irishealthcomm\mgr\hscustom\) hscustom db.

    Ashok Kumar T · Jul 8, 2025 go to post

    The HS.FHIRModel.R4.Patient class in  IRIS directly represents the FHIR R4 Patient resource as defined. When a FHIR Bundle is loaded using HS.FHIRModel.R4.Bundle.fromDao(), each resource in the bundle's entry.resource is automatically mapped to the correct HS.FHIRModel.R4.* subclass (e.g., Patient, Encounter, AllergyIntolerance) based on its resourceType. There’s no need for manual casting — the object model handles the typing internally.

    here is the sample code

    Set bundle={"resourceType":"Bundle","type":"searchset","total":3,"entry":[{"fullUrl":"https://example.org/fhir/Patient/patient-1","resource":{"resourceType":"Patient","id":"patient-1","name":[{"family":"Doe","given":["John"]}],"gender":"male","birthDate":"1985-02-15"},"search":{"mode":"match"}},{"fullUrl":"https://example.org/fhir/Encounter/encounter-1","resource":{"resourceType":"Encounter","id":"encounter-1","status":"finished","class":{"system":"http://terminology.hl7.org/CodeSystem/v3-ActCode","code":"AMB","display":"ambulatory"},"subject":{"reference":"Patient/patient-1"},"period":{"start":"2023-07-01T10:00:00Z","end":"2023-07-01T10:30:00Z"}},"search":{"mode":"include"}},{"fullUrl":"https://example.org/fhir/AllergyIntolerance/allergy-1","resource":{"resourceType":"AllergyIntolerance","id":"allergy-1","clinicalStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical","code":"active"}]},"verificationStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-verification","code":"confirmed"}]},"type":"allergy","category":["food"],"criticality":"high","code":{"coding":[{"system":"http://snomed.info/sct","code":"227493005","display":"Cashew nuts"}],"text":"Allergy to cashews"},"patient":{"reference":"Patient/patient-1"},"reaction":[{"manifestation":[{"coding":[{"system":"http://snomed.info/sct","code":"271807003","display":"Skin rash"}]}],"severity":"moderate"}]},"search":{"mode":"include"}}]}                                                                                             
    set fhirModelBundle = ##class(HS.FHIRModel.R4.Bundle).fromDao(bundle)  
    ;
    Zwrite fhirModelBundle.entry.list.size()
    3
    ;
    Zwrite fhirModelBundle.entry.list.get(0).toDao() ; patient
    {"fullUrl":"https://example.org/fhir/Patient/patient-1","resource":{"resourceType":"Patient","id":"patient-1","name":[{"family":"Doe","given":["John"]}],"gender":"male","birthDate":"1985-02-15"},"search":{"mode":"match"}}  ; <DYNAMIC OBJECT>                        
    ;
    Zwrite fhirModelBundle.entry.list.get(1).toDao() ; encounter
    {"fullUrl":"https://example.org/fhir/Encounter/encounter-1","resource":{"resourceType":"Encounter","id":"encounter-1","status":"finished","class":{"system":"http://terminology.hl7.org/CodeSystem/v3-ActCode","code":"AMB","display":"ambulatory"},"subject":{"reference":"Patient/patient-1"},"period":{"start":"2023-07-01T10:00:00Z","end":"2023-07-01T10:30:00Z"}},"search":{"mode":"include"}}  ; <DYNAMIC OBJECT>                                                                                                                         
    ;
    Zwrite fhirModelBundle.entry.list.get(2).toDao() ; Allergy
    {"fullUrl":"https://example.org/fhir/AllergyIntolerance/allergy-1","resource":{"resourceType":"AllergyIntolerance","id":"allergy-1","clinicalStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical","code":"active"}]},"verificationStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-verification","code":"confirmed"}]},"type":"allergy","category":["food"],"criticality":"high","code":{"coding":[{"system":"http://snomed.info/sct","code":"227493005","display":"Cashew nuts"}],"text":"Allergy to cashews"},"patient":{"reference":"Patient/patient-1"},"reaction":[{"manifestation":[{"coding":[{"system":"http://snomed.info/sct","code":"271807003","display":"Skin rash"}]}],"severity":"moderate"}]},"search":{"mode":"include"}}  ; <DYNAMIC OBJECT>
    Ashok Kumar T · Jul 8, 2025 go to post

    Hello @Scott Roth 

    I directly import JSON via fromDao method and It works for me. Did you get any errors while importing?

    Set patient = {"resourceType":"Patient","id":"example","text":{"status":"generated","div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">John Doe</div>"},"identifier":[{"use":"usual","type":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/v2-0203","code":"MR","display":"Medical Record Number"}]},"system":"http://hospital.smarthealth.org","value":"123456"}],"active":true,"name":[{"use":"official","family":"Doe","given":["John"]}],"telecom":[{"system":"phone","value":"+1 555-123-4567","use":"mobile"},{"system":"email","value":"john.doe@example.com","use":"home"}],"gender":"male","birthDate":"1980-01-01","address":[{"use":"home","line":["123 Main Street"],"city":"Anytown","state":"CA","postalCode":"90210","country":"USA"}]}
    Set r4Patient = ##class(HS.FHIRModel.R4.Patient).fromDao(patient)
    Write r4Patient.toString()
    Ashok Kumar T · Jul 4, 2025 go to post

    Thank you, I use the same query to differentiate between system web application APIs and user-defined web applications. It's much easier if there's a distinct column for this purpose.