Ashok Kumar T · Aug 10, 2023 go to post

Hello Scott,

As of m understanding, If your dynObject is actually the expected JSON format. Create a instance for class response class and load the dynObject into object by method  obj.%JSONImport(dynObject)

Ashok Kumar T · Aug 10, 2023 go to post

If you're receiving unexpected fields(key value pairs) as part of the JSON and the properties are not included in the class definition. You need to add the below parameter in your class definition(%JSON.Adaptor extended class). This will ignore loading the unexpected field.

Parameter%JSONIGNOREINVALIDFIELDAs BOOLEAN = 1

In addition, The JSON key-value pair data type should match with class definition property datatype. 

Ashok Kumar T · Aug 11, 2023 go to post

Hello Pierre,

You can Override the method OnPreDispatch from the %CSP.REST in your dispatcher class and capture your user connect information in application log.

ClassMethod OnPreDispatch(pUrl As%String, pMethod As%String, ByRef pContinue As%Boolean) As%Status
{
    set^Pierre(pUrl)=""/// your implementationreturn$$$OK
}
Ashok Kumar T · Aug 11, 2023 go to post

Thanks Vitaliy for the suggestion, %ScrollableResultSet  is works for the Cache SQL. We are actually fetching multiple Resultsets and not working as expected for language=tsql.

ClassMethod tt() [ Language = tsql, SqlName = mycls, SqlProc ]
{
    SELECT Name FROM sample_SQL.NewClass4
    SELECT Name, Age FROM sample_SQL.NewClass5
}

 set results=##class(%ScrollableResultSet).%New()
 set tsc = results.Prepare("call sample_SQL.MYCLS()")
 if$$$ISERR(tsc) W$SYSTEM.OBJ.DisplayError(tsc)
 do results.Execute()
 
 ERROR #6048: Invalid Statement Type: 'CALL'1
Ashok Kumar T · Aug 11, 2023 go to post

Hi Pierre 

Can you try with below. And try Create a subclass of %CSP.SessionEvents and try override OnStartRequestOnEndRequest .

ClassMethod Page(skipheader As%Boolean = 1) As%Status [ ProcedureBlock = 0 ]
{
	set^Pierre("login")="on login (by overrided method Page)"return##super(skipheader)
}
Ashok Kumar T · Aug 15, 2023 go to post

Hello @Elijah Cotterrell 

Thanks for the suggestion, I need to verify whether the property is modified while saving for opened object and Generally I do some verification with the mentioned piece of code. So, I thought to generate a method like getter and setter method in some cases.

Class Samples.Person Extends%Persistent
{

Property Name As%String;Property Age As%String;ClassMethod ValidateObject()
{
    Set obj =##Class(Sample.Person).%OpenId(1)
    w"before: ",obj.PropertyIsModified("Age"),!
    Set obj.Age=12Write"after: ",obj.PropertyIsModified("Age"),!
}

Method PropertyIsModified(Property)
{
    Return$Select(Property'="":$Property($THIS,"m%"_Property), 1:0)
}

}
Ashok Kumar T · Aug 16, 2023 go to post

Hi @Sakthivel Perumal 

Can you try the below sample to download file from the directory

Class Samples.CSPFileDownload Extends%CSP.Page
{
Parameter CONTENTTYPE As STRING = "application/text";ClassMethod OnPage() As%Status
{
    do%stream.OutputToDevice()
    return$$$OK
}
ClassMethod OnPreHTTP() As%Boolean
{
    #; your directory and fileset file="C:\Users\readmyfile.txt"set stream=##class(%Stream.FileCharacter).%New()
    set sc=stream.LinkToFile(file)
    set%stream = stream
    set%response.ContentType = ..#CONTENTTYPE
    set%fileName = file
    set%response.ContentLength=stream.Size
    return$$$OK
}
}
Ashok Kumar T · Aug 18, 2023 go to post

Hello @ARTHUR.LASILVA 

You create a your custom task and schedule this task in task manager if it's required. Follow the below steps to schedule the task.

  1. Create a new class definition with extends of %SYS.Task.Definition. Override the OnTask() method and necessary logic inside the method
  2. Goto System Management portal > System Operation>Task Manager>NewTask
    1. Add unique task name
    2. Select namespace
    3. Assign the task type ( which is your class definition)
    4. Select output file when task running
    5. Provide your ouputfile.csv in the output file
    6. schedule the execution date and time.
    7. Finish the task
Class Samples.TaskMgr.SQLExportTask Extends%SYS.Task.Definition
{

Parameter TaskName As STRING = "ExportQueryToCSV";

Method OnTask() As%Status
{
    set statement = ##class(%SQL.Statement).%New()
    /// Place your sql queryset sql = "Select Name,dob,Phone From Samples_DB.Person"set tSC = statement.%Prepare(sql)
    if$$$ISERR(tSC) Q$$$OKset result = statement.%Execute()
    #dim meta As%SQL.StatementMetadata= result.%GetMetadata()
    for i=1:1:meta.columnCount {
        if i>1w","write meta.columns.GetAt(i).colName
    }
    write$$$NLwhile result.%Next()
    {
        write result.Name,",",result.dob,",",result.Phone,$$$NL
    }
    return$$$OK
}
}

Task scheduler

Ashok Kumar T · Aug 20, 2023 go to post

Hello Pierre,

You have two options to get query parameters

  1. You can merge the entire %request.Data into local array and use string function.
  2. User %request.Next(data) method to loop the %request.Data one by one and get query parameter values

ClassMethod GetQueryParams()
{
	set data=""For {
		set data  = %request.Next(data) quit:data=""write data,!
	}
}
OUTPUT
Bottom
Name
Top

For cgiEnvs. You can follow same merge option to get all values. Otherwise use %request.NextCgiEnv(cgi) to get the list of available values.

ClassMethod GetcgiEnvs()
{
    set cgi=""for {
        set cgi  = %request.NextCgiEnv(cgi) quit:cgi=""write cgi,!
    }
}
Ashok Kumar T · Aug 20, 2023 go to post

Nice article. However, there is a minor problem while setting the trailing zero values in %Set() of dynamicobject. But, It's not happening in literal constructor {} syntax. Due to objectscript not keep the trailing zeros. But json number do.

set json = { "decimal": 12.000}
    zw json
    set json1= ##Class(%DynamicObject).%New()
    do json1.%Set("decimal", 12.000) ; this is consider as stringdo json1.%Set("decimal1", $FN(12,,2), "number")	
    zw json1
    
    #;output
    json={"decimal":12.000}  ; <DYNAMIC OBJECT>
    json1={"decimal":12,"decimal1":12}  ; <DYNAMIC OBJECT>
Ashok Kumar T · Aug 21, 2023 go to post

Hello Pierre,

No problem. You can use the merge command(sorry not a string function) to take a copy of entire global node and subtree

merge queryparam = %request.Datazwrite queryparam ;print the entire node and subtree
Ashok Kumar T · Aug 23, 2023 go to post

Hello Smythe,

I agree with @Robert Cemper points. The %Date datatype is for +$H which means numeric date value. Not an string. You should modify the datatype of the property or use string functions.

IRISMYDEV>s obj = ##Class(CSVtoHL7.Inputfile.Record).%New()
IRISMYDEV>s obj.DOB="12/12/1993"
IRISMYDEV>zw##Class(%Date).IsValid(obj.DOB)
"0 "_$lb($lb(7207,"12/12/1993",,,,,,,,$lb(,"IRISMYDEV",$lb("e^IsValid+1^%Library.Date.1^1","e^^^0"))))/* ERROR #7207: Datatype value '12/12/1993' is not a valid number */
 
IRISMYDEV>w$SYSTEM.OBJ.DisplayError()
ERROR #7207: Datatype value '12/12/1993' is not a valid number1
IRISMYDEV>s obj = ##Class(CSVtoHL7.Inputfile.Record).%New()
IRISMYDEV>s obj.DOB=$ZDateH("12/12/1993")
IRISMYDEV>zw##Class(%Date).IsValid(obj.DOB)
1
Ashok Kumar T · Aug 23, 2023 go to post

Hello @Joel Solon 

  • The %ValidateObject() method is used to validate the property. Not to find out the property is modified in the opened object
IRISMYDEV>set obj = ##Class(Samples.NewClass2).%OpenId(1)
IRISMYDEV>write obj.Name
Test
IRISMYDEV>zwrite obj.%ValidateObject()
1
IRISMYDEV>set obj.Name="newname"
IRISMYDEV>zwrite obj.%ValidateObject()
1
  • m%_Property is used to verify whether the property is modified before save. Incase If we need to verify
Class Samples.NewClass2 Extends%Persistent
{
Property Name As%String;
Method modified()
{
    write"Property modifed : ",$Property(,"m%Name")
}
}
IRISMYDEV>set obj = ##Class(Samples.NewClass2).%OpenId(1)
IRISMYDEV>do obj.modified()
Property modifed : 0
IRISMYDEV>set obj.Name="test"
IRISMYDEV>do obj.modified()
Property modifed : 1
IRISMYDEV>
  • I hope, we don't have any built in method like "propertyIsModified" to verify the property is modified 
Ashok Kumar T · Aug 23, 2023 go to post

Hello Scott,

I had created ZAUTHENTICATE.mac in %SYS namespace. Implemented the GetCredentials and validated the authentication for delegated user. It works for me without any issues.

Ashok Kumar T · Aug 24, 2023 go to post

As we mentioned above the DOB should have +$H value instead of MM/DD/YYYY. However you can try the below

If DOB is date format

IRISMYDEV>set dob="12/01/1993"
IRISMYDEV>write$translate($ZDT($ZDTH(dob),3)," ","T")_"Z"1993-12-01T00:00:00Z

If DOB is +$H value

IRISMYDEV>set dob=+$H
IRISMYDEV>write$translate($ZDT(d_",00000",3)," ","T")_"Z"2023-08-24T00:00:00Z
Ashok Kumar T · Aug 24, 2023 go to post

Exactly. Thanks for the samples. This will helps to figure out the property is modified or not. 

Ashok Kumar T · Aug 24, 2023 go to post

I'm not sure why the request class CSVtoHL7.Inputfile.Record inherits from right. All the request and response are required persistent object. This will be used to display the entire flow in the visual trace section. I have attached some sample below.

You can add a property setter method for property DOB and modify the value from MM/DD/YYYY to +$H value. This will keep the internal date format in database.

Class CSVtoHL7.Inputfile.Record Extends (Ens.Request, %XML.Adaptor, EnsLib.RecordMap.Base) [ ProcedureBlock ]
{
Property ID As%Integer;Property LastName As%String;Property FirstName As%String;Property MiddleName As%String;Property DOB As%Date;
Method DOBSet(pDate) As%Status
{
    Set i%DOB= $ZDH(pDate)
    Quit$$$OK
}
Property Gender As%String;ClassMethod createObj() As CSVtoHL7.Inputfile.Record
{
    Set obj = ##class(CSVtoHL7.Inputfile.Record).%New()
    Set obj.DOB="12/30/2001"Set obj.FirstName="Test"Set obj.ID=12345Set obj.MiddleName = "middle"Set obj.Gender="M"return obj
}
}

Create a object for the request class and send to Transformation. you can use the logic $translate($ZDT(source.DOB_",0",3)," ","T")_"Z" in DTL to convert the internal date format to required output 2023-08-24T00:00:00Z. You can refer the DTL sample below

Class CSVtoHL7.DTL.Record Extends Ens.DataTransformDTL [ DependsOn = (CSVtoHL7.Inputfile.Record, EnsLib.HL7.Message) ]
{

Parameter IGNOREMISSINGSOURCE = 1;Parameter REPORTERRORS = 1;Parameter TREATEMPTYREPEATINGFIELDASNULL = 0;

XData DTL [ XMLNamespace = "http://www.intersystems.com/dtl" ]
{
<transform sourceClass='CSVtoHL7.Inputfile.Record' targetClass='EnsLib.HL7.Message' targetDocType='2.5:ADT_A01' create='new' language='objectscript' >
<assign value='source.ID' property='target.{PID:SetIDPID}' action='set' />
<assign value='source.FirstName' property='target.{PID:PatientName().FamilyName}' action='set' />
<assign value='source.MiddleName' property='target.{PID:PatientName().GivenName}' action='set' />
<assign value='source.Gender' property='target.{PID:AdministrativeSex}' action='set' />
<assign value='$translate($ZDT(source.DOB_",0",3)," ","T")_"Z"' property='target.{PID:DateTimeofBirth.Time}' action='set' />
</transform>
}

}

output

Ashok Kumar T · Aug 24, 2023 go to post

Hello @Hannah Sullivan 
If you need to delete the list of object while deleting the parent object. You can override the %OnDelete method and add the delete implementation refer below code logic. Once you call the ##Class(package.class).%DeleteId(id). It will trigger the %OnDelete Method and delete the list of persistent object as well.

ClassMethod%OnDelete(oid As%ObjectIdentity) As%Status [ Private, ServerOnly = 1 ]
{
    set object = ..%Open(oid,,.status)
    If$$$ISERR(status) quit status
    If$IsObject(object.Organizations) {
        set org= object.OrganizationsGetSwizzled()
        while org.GetNext(.key){
            do object.Organizations.GetAt(key).%DeleteId(key)
        }
    }
    Quit$$$OK
}

You can create these object with Parent-child relationship as well.

Ashok Kumar T · Aug 28, 2023 go to post

Thank you @Daniel.Pasco. It's a wonderful detailed clarification for the property and member type class

Ashok Kumar T · Aug 29, 2023 go to post

%JSON.Adaptor default manner is rid out the null value properties when %JSONExport method invokes. There is some default parameter are used to achieve this while exporting. You need to enable parameter in your class definition. The %JSONNULL parameter is used to export all the field and display even the property has null values. Once you have added the parameter and try export the itemdetails object

Parameter %JSONNULL As BOOLEAN = 1;
Class Samples.AllItems Extends (%JSON.Adaptor, Ens.Response)
{

Parameter%JSONNULLAs BOOLEAN = 1;Property ItemtId As%String;Property itemName As%String(MAXLEN = 100);Property itemStockNumber As%String(MAXLEN = 150);Property itemType As%String;Property itemPriority As%String;Property itemDetailData As%String(MAXLEN = 10000);
}
{
    "ItemId": "test",
    "Item": [
        {
            "ItemtId": null,
            "itemName": null,
            "itemStockNumber": 123,
            "itemType": "test",
            "itemPriority": "High",
            "itemDetailData": null
        }
    ]
}
Ashok Kumar T · Aug 29, 2023 go to post

As per your code. Couple of things. Firstly, the item is list of object so you should use Insert method. You're inserting item.ItemName instead item object. Property Item As list Of AllItemsexpects object. Not a string.

Do AllItem.Item.Insert(Item)
Ashok Kumar T · Aug 31, 2023 go to post

The reason behind the conversion is Cache identifies/assume from 1900 - 1999 year if you send two digit for year. So, You should send four digit year. attached the documentation "Two or four digits may be specified for years in the range 1900 to 1999. Four digits must be specified for years before 1900 or after 1999."

Ashok Kumar T · Aug 31, 2023 go to post

You need to call. If it's was declared as method. I tried the below and it works.  

<script language=cache method="montaDDList" arguments="">
    Set listaPropriedades=$SYSTEM.SQL.Execute("SELECT * from Sample.Person")
</script>

	#(..montaDDList())#
Ashok Kumar T · Sep 2, 2023 go to post

AFAIK No. There is no straightforward way to import JSON from FHIR discrete resources to SDA3 objects by %JSONImport(). Basically, there are various stages involved in converting the FHIR to HL7 and vice versa. To achieve this, Intersystems created an intermediary format called SDA. However, there are more processes involved whenever convert the bundle or discrete resource.
for example

  1. In some instances, the FHIR resource data element name (property) is not the same as the SDA property.
  2. Lots of internal DTL's are invoked or invoked at the conversion time, and an SDA object is created based on that output. Typically it's common for SDA to FHIR and vice versa. 
  3. DTL's are crucial to accomplish this conversion. Some of the data elements are not mapped in the standard FHIR to SDA or SDA to FHIR DTL transformation. HS.FHIR.DTL.vR4.SDA3.AllergyIntolerance.Allergy in this DTL the "criticality" data element is not mapped with SDA object In this case you should create your custom DTL from the already implemented DTL to convert the values to object. So If you haven't added this type of additional properties in the SDA extension class, it won't work.
  4. Metadata values and lookup tables vary from SDA to FHIR. SDA has 'A' in the lookup tables for some fields, while FHIR has 'Active'. There is a internal validation runs against every data element to verify the generated FHIR resource Every time
Ashok Kumar T · Sep 5, 2023 go to post

Hello @Smythe Smythee 

There is no difference between ensemble and IRIS instance. In your case, the source.MemberDOB is an date( ex 01/01/2000) and the conversion is working perfectly. Can you check the input of the memberDOB before conversion and just take a quick look of the previous samples.

USER>write $ZV
IRIS for Windows (x86-64) 2023.1 (Build 229) Fri Apr 14 2023 17:36:18 EDT
USER>set DOB="01/01/1999"
 
USER>write $translate($ZDT($ZDTH(DOB),3)," ","T")_"Z"
1999-01-01T00:00:00Z

The same code is works in IRIS Interoperability DTL as well.

<assign value='$translate($ZDT($ZDTH(source.DOB),3)," ","T")_"Z"' property='target.{PID:DateTimeofBirth}' action='set' />