I have a %GlobalBinaryStream object that I'm trying to save as a local file after being received through a SOAP Web Service.

To do this, I created a %Stream.FileBinary object and wanted to set where the stream copied to this object would be saved by using either the DefaultStreamDir() ClassMethod or the NewFileName() ClassMethod. However, the documentation isn't very helpful on how to use these ClassMethods.

Right now, I have the below code:

1 4
0 197

First of all thanks for your help and time

We would need to find inside PID:3 which one meets the following condition:

PID 3.4.1 = "CAC" and PID 3.5 = "JHN"

We have been investigating how could we do it

We have achieved to get single fields in a call request as follows:

request.GetValueAt("ORCgrp(1).ORC:OrderingProvider(1).IDNumber")

##class(Ens.Util.Time).ConvertDateTime(request.GetValueAt("PID:DateTimeofBirth"),"%Y%m%d","%Y-%m-%d")

1 2
0 350

Hi Team,

I have a requirement to delete the Ensemble interfaces , as per User request. I would like to write a routine for that and once I execute, it should remove the interface components through code.
Could you please provide code samples for the following actions ?

  • Deleting an individual rule from a rule class
  • Deleting a class from Ensemble
  • Deleting a Host (Service/Operation/Process) from the Production.

Appreciate the help.

Thanks,

Purushothaman.T

1 6
0 289

I have a requirement to update the Ensemble Host Settings Programmatically. Mainly the "AlertOnError,QueueCountAlert,QueueWaitAlert,InactivityTimeout" settings.

I used Ens_Config.Item (persistent) class to get the settings (list object) and then update it. But for some of the Business Host's, I dont see the above settings in the table, but present in Settings of that particular Host in Ensemble Management Portal. So my logic is not working.

1 11
0 468

Hello,

We would need some help,

Our aim is to send an image as binary data using a REST Service

Currently we do the following:

1 We get from the external system a binary image in our REST Operation

2 We encode it to Base64

set linea=""
    while (tResponse.Data.AtEnd = 0) {
        set linea = linea_$system.Encryption.Base64Encode(tResponse.Data.Read(57))
    }

3 We send it to the Process in a Response Message:

1 4
0 844

(Originally posted by @Ben Spead on June 25, 2014)

This code snippet generates a list of Ensemble Lookup Tables and Schema documents in the user's current namespace. Run the code by running the class method "test":


Class benspead.EnsTablesSchema
{
    classmethod test() {
        If ##class(%Dictionary.CompiledClass).%ExistsId("Ens.Util.LookupTableDocument") {
            // only supported in Ensemble 2012.1+
            Write !,!,"Exporting Ensemble Lookup Tables..."
            Set sc = $$$OK
            Set rs = ##class(%ResultSet).%New("Ens.Util.LookupTableDocument:List")
            Do rs.Execute()
            While rs.Next() {
                Set item=rs.Data("name")
                Write "document found: "_ item,!
            }
            Do rs.Close()
            Set rs=""
        }
        If ##class(%Dictionary.CompiledClass).%ExistsId("EnsLib.HL7.SchemaDocument") {
            Write !,!,"Exporting Ensemble HL7 Schemas..."
            Set sc = $$$OK
            Set rs = ##class(%ResultSet).%New("EnsLib.HL7.SchemaDocument:List")
            Do rs.Execute()
            While rs.Next() {
                Set item=rs.Data("name")
                Continue:$listfind($lb("2.1.HL7","2.2.HL7","2.3.HL7","2.4.HL7","2.5.HL7","2.6.HL7","2.7.HL7","2.3.1.HL7","2.5.1.HL7","2.7.1.HL7","ITK.HL7")
                                    ,item)
                Write "document found: "_ item,!
            }
            Do rs.Close()
            Set rs=""
        }
    }
}

Here's a link to the code on GitHub: https://github.com/intersystems-community/code-snippets/blob/master/src/...

1 3
0 773

I needed to know programmatically if last ran failed or not.

After some exploring, here's the code:

ClassMethod isLastTestOk() As %Boolean
{
  set in = ##class(%UnitTest.Result.TestInstance).%OpenId(^UnitTest.Result)
  for i=1:1:in.TestSuites.Count() {
    #dim suite As %UnitTest.Result.TestSuite
    set suite = in.TestSuites.GetAt(i)
    return:suite.Status=0 $$$NO
  }
  quit $$$YES
}

1 4
1 580

Recently I needed a classmethod that returns annotation value based on a name of a activity.

As doing it at runtime seemed inefficient, I wrote compile-time utility that iterates over all business process activities and generates relevant code.

This code could be used in a variety of situations when you need to iterate over business process activities, just add it as a secondary superclass to your BPL processes.

1 2
1 364

This code snippet sends an XML request to a server and saves the response to a file. The class method "test" runs the code:


Class objectscript.postXML
{
    classmethod test() {
        Set HTTPRequest = ##class(%Net.HttpRequest).%New()
        Set HTTPRequest.ContentType = "text/xml"
        Set HTTPRequest.NoDefaultContentCharset = 1
        Set HTTPRequest.Location = "ITOMCZ"
        Set HTTPRequest.Server = "wph.foactive.com"
        Do HTTPRequest.RemoveHeader("User-Agent")  
        Do HTTPRequest.RemoveHeader("Accept-Encoding") 
        Do HTTPRequest.RemoveHeader("Connection")
        Do HTTPRequest.SetHeader("Expect","100-continue")
     
        Set RequestXML = ##class(%Library.File).%New("c:\test.xml")
        Do RequestXML.Open("RS")
        Do HTTPRequest.EntityBody.CopyFrom(RequestXML)
        Do RequestXML.%Close()
     
        Do HTTPRequest.Post(HTTPRequest.Location)
     
        Do $System.OBJ.Dump(HTTPRequest)
        Do $System.OBJ.Dump(HTTPRequest.HttpResponse)
     
        Write HTTPRequest.HttpResponse.Data.Size
        Write HTTPRequest.ContentLength
     
        Set ResponseStream = ##class(%Stream.FileBinary).%New()
        // Second part is typically the file extension, i.e.: application/pdf -> pdf
        Set FileType = $Piece(HTTPRequest.HttpResponse.GetHeader("CONTENT-TYPE"),"/",2)
        Set ResponseStream.Filename = "C:\test."_FileType
     
        Write ResponseStream.CopyFrom(HTTPRequest.HttpResponse.Data)
     
        Write ResponseStream.%Save()
        Do ResponseStream.%Close()
    }
}

Here's a link to the code on GitHub

1 0
0 792
Article
· Dec 27, 2018 2m read
Use %XML.Node to walk a DOM

The following code walks a DOM using %XML.Node. It also prevents %XML.Writer to change whitespace. Run the code using the class method "test":


Class objectscript.walkDOM Extends %Persistent
{
    ClassMethod dfs(node As %XML.Node)
    {
        s entrynode=node.NodeId
        do {
        //element nodes with one whitespacetyped child are the ones we want to change
        if (node.NodeType=$$$xmlELEMENTNODE){
            s snode=node.NodeId     
            if (node.MoveToFirstChild())            
                {
                    i ('node.MoveToNextSibling()){
                        i (node.NodeType=$$$xmlWHITESPACENODE){
                            s node.NodeType=$$$xmlTEXTNODE
                            s node.NodeId=snode
                        }
                    }
            }
            s node.NodeId=snode     
        }   
        if (node.HasChildNodes()){
            d node.MoveToFirstChild()
            d ..dfs(node)
        }
        } while (node.NodeType'="" && node.MoveToNextSibling())
        s node.NodeId=entrynode
         
    }
     
    ClassMethod test()
    {
      set xml = "abcdefg"
     
      s reader=##class(%XML.Reader).%New()
      do reader.OpenString(xml)  
      set writer = ##class(%XML.Writer).%New()
      //do some magic
      d ..dfs(reader.Document)
       
      w !,"with indent=1:",!
      set writer.Indent = 1
      do writer.OutputToString()
      do writer.Document(reader.Document)
      w writer.GetXMLString()
      set writer.Indent = 0
      w !,"with indent=0:",!
      do writer.OutputToString()
      do writer.Document(reader.Document)
      w writer.GetXMLString()
    }
}

Here's a link to the code on GitHub: https://github.com/intersystems-community/code-snippets/blob/master/src/...

1 0
0 314

(Originally posted on Intersystems CODE by @Eduard Lebedyuk, 10/12/15) The following code snippet outputs all filenames in the file path "dir" in the Cache/IRIS terminal. The class method "test" runs the code:


Class eduardlebedyuk.filenamesInDir Extends %RegisteredObject
{
	classmethod test() {
		// replace dir with file path you want
		set dir = "D:\directory" 
		set dir = ##class(%File).NormalizeDirectory(dir)
		set file=$ZSEARCH(dir_"*")
		while file'="" {
			write !,file
			set file=$ZSEARCH("")
		}
	}
}

1 3
2 1.7K
Article
· Oct 26, 2018 1m read
Send an HTML Email

This code snippet contains the class method "test" which sends an HTML email. Change the literal strings in the method to customize the email's from address, to address, subject, and body:


Class objectscript.sendEmail Extends %RegisteredObject
{
    classmethod test() {
        set m=##class(%Net.MailMessage).%New()
        set m.From="user@company.com"
         
        set m.IsHTML=1
         
        do m.To.Insert("user@company.com")
        set m.Subject="Sent by IRIS mail"
        set m.Charset="iso-8859-1"
        do m.TextData.Write("<HTML><HEAD><TITLE></TITLE>"_$char(13,10))
        do m.TextData.Write("<META http-equiv=Content-Type content=""text/html; charset=iso-8859-2""></HEAD>"_$char(13,10))
        do m.TextData.Write("<BODY><FONT face=Arial size=2>Test <B>Test</B></FONT></BODY></HTML>")
        set s=##class(%Net.SMTP).%New()
        set s.smtpserver="mail.company.com"
        set status=s.Send(m)
    }
}

Here's a link to the code on GitHub

1 0
1 1K

This code snippet uses %ZEN.Auxiliary.jsonSQLProvider. The namespace and string of SQL can be edited for different situations. The class method "test" runs the code:


Class eduardlebedyuk.passQuestionParams
{
    classmethod test(pValue = 50) {
        s ns = $Namespace
        zn "samples"
        s tSQL = "SELECT ID, Name FROM Sample.Person WHERE Id > ?"
        s tPR = ##class(%ZEN.Auxiliary.jsonSQLProvider).%New()
        s tPR.sql = tSQL
        s tPR.%Format = "tw"
        s tPR.maxRows = 100
     
        s tParam = ##class(%ZEN.Auxiliary.parameter).%New()
        s tParam.value = pValue
        d tPR.parameters.SetAt(tParam,1)
      
        d tPR.%DrawJSON() 
        //d ##class(%ZEN.Auxiliary.jsonSQLProvider).%WriteJSONFromSQL(,,,,,tPR)  //same thing
        zn ns
    }
}

(Originally posted to Intersystems CODE by @Eduard Lebedyuk, 5/13/15)

Here's a link to the code on GitHub

1 0
0 251
Article
· Sep 27, 2018 2m read
Method to Create a Class

The following class method "test" contains code that can create a new class, create new properties for classes, or create new methods for classes. "test" runs all three of these processes once, and the code that performs each action is labelled by comments in the method:


ClassMethod test() As %Status
{
    set sc = $$$OK
    
    // Create a class
    set class = ##class(%ClassDefinition).%New("MyClass")
    set class.Description = "This is my test class"_$c(13,10)_"testing %ClassDefinition"
    set class.Super = "%Persistent"

    // Create a property and add it
    set property = ##class(%PropertyDefinition).%New("MyClass.MyProperty")
    set property.Type = "%String"
    set property.Description="This is a property"
    set sc1 = class.Properties.Insert(property)
    do:$$$ISERR(sc1) $system.Status.DisplayError(sc1)
    set sc = $$$ADDSC(sc, sc1)
    
    // Create a method and add it
    set method = ##class(%MethodDefinition).%New("MyClass.MyMethod")
    set method.ReturnType = "%Integer"
    set method.FormalSpec = "x:%Integer,y:%Integer=10"
    set method.Description = "Return product of x and y"
    set method.CodeMode = "code"
    set method.Code = " new result"_$c(13,10)_" set result=x*y"_$c(13,10)_" quit result"
    set sc2 = class.Methods.Insert(method)
    do:$$$ISERR(sc2) $system.Status.DisplayError(sc2)
    set sc = $$$ADDSC(sc, sc2)
    
    // Save the class definition
    set sc3 = class.%Save()
    do:$$$ISERR(sc3) $system.Status.DisplayError(sc3)
    set sc = $$$ADDSC(sc, sc3)
    
    return sc
}

Here's a link to the code on GitHub

1 1
0 554

Hi, Community!

Have a question for general discussion.

In ObjectScript we have cls for classes and mac code, which both compile into int code.

Is there any reason when you use mac instead of cls for non-persistent classes?

For me the benefits for cls are:

1. Inheritance and other OOP features

2. Auto-documented code

For mac one visible benefit is easier call in terminal:

do method^Utils(p1,p2)

vs

1 43
1 2.6K