Article
· Sep 2 4m read

IRIS Native Python Part-2

In the preceding section, we explored the installation process and initiated the writing of the IRIS in native Python. We will now proceed to examine global traversal and engage with IRIS class objects.

 get: this function is used to get values from the traversal node.

def traversal_firstlevel_subscript():
    """
    ^mygbl(235)="test66,62" and ^mygbl(912)="test118,78"
    """
    for  i in irispy.node('^mygbl'):
        print(i, gbl_node.get(i,''))

 

node and items: single level traversal with node and get the values same as $Order(^mygbl(subscript), direction, data)

#single level traversal
def traversal_dollar_order_single_level():
    for  sub,val in irispy.node('^mygbl').items():
         print('subscript:',sub,' value:', val)
# multi level traversal
def traversal_dollar_order_multi_level():
    for  sub,val in irispy.node('^mygbl').items():
         print(f'sub type is: {type(sub)} {sub} and val type is {type(val)}')
         for sub1,val1 in irispy.node('^mygbl',sub).items():
            print('subscript:',sub1,' value:', val1)
        

 

nextsubscript: unlike above code you can use nextsubscript to get the next subscript easily

def traversal_dollar_order_use_nextsubscript():
      direction = 0
      next_sub = ''
      while next_sub != None:
            next_sub = irispy.nextSubscript(direction,'^mygbl', next_sub)
            print(f'next subscript = {next_sub}' )
            next_sub1=''
            if next_sub == None:return
            while next_sub1 != None:
                next_sub1 = irispy.nextSubscript(direction,'^mygbl',next_sub,next_sub1)
                print(f'1st subscript = {next_sub} next subscript {next_sub1}' )

 

Classes and Objects

You can call the classmethods, methods from the class definition by using the specific function. As  I mentioned earlier Typecast Methods are crucial to get the proper response from IRIS

Prior to this, it is important to note that, Unlike IRIS datatypes, which we can treat everything as strings, Python data types such as int, str, bool, and list are classified as objects. Each of these types possesses its own attributes and methods; for instance, the Python string type includes functions such as .upper() and .lower(), which are not applicable to other data types. Consequently, IRIS is equipped with the ability to convert IRIS string values into Python-supported datatype objects through the use of Typecast Methods. This functionality is similarly applicable to class methods, user-defined functions, and procedures. Alternatively, one must utilize Python's type conversion functions to achieve the desired data type.

 

classMethodValue: Call the Classmethod from python without initiate the object same as ( ex: Do ##Class(Test.MYTest).FirstNameGetStored(1) ) and get "string" default value in python. There are different typecast method available for expected return value instead of string. Please refer below.

def get_clsmethod_value():
    print(irispy.classMethodValue('Test.MYTest','FirstNameGetStored',1)) #return string 
    date_horolog = irispy.classMethodInteger('Test.MYTest','GetHorolog') #return +$H value
    print(irispy.classMethodVoid('Test.MYTest','SetTestGlobal','test')) # no return resposne

classMethodObject: Important function to Instantiate a new IRIS object or open the existing object. Set the properties and invoke instance methods etc...

New IRIS object: Initiate the class object for Test.MYTest and set the properties.

def cls_object_new():
    """
    initiate new object and store
    """
    iris_proxy_obj = irispy.classMethodObject('Test.MYTest','%New','ashok','kumar')

    birthdate_horolog = irispy.classMethodInteger('Test.MYTest','GetHorolog','12/12/1990')
    horolog = irispy.classMethodInteger('Test.MYTest','GetHorolog')
    iris_proxy_obj.set('BirthDate',birthdate_horolog) #set birthdate property
    iris_proxy_obj.set('RegisteredDate',horolog) #set the RegisteredDate property
    status = iris_proxy_obj.invoke('%Save') #call instance method
    return status


Open IRIS Object: In the below code. Open Test.MyTest class object and get both Birthdate and RegisteredDate values from the objectid "2" and convert RegisteredDate as python list 

def cls_object_open():
    iris_proxy_obj = irispy.classMethodObject('Test.MYTest','%OpenId',2)
    birth_date = iris_proxy_obj.get('BirthDate')
    full_name iris_proxy_obj.InvokeString("GetFullName")
    data = [birth_date, iris_proxy_obj.get('RegisteredDate')]
    return data

IRIS Class definition which I used for the class and object python code demo

 
Spoiler

 

Typecast methods:

these are few type cast method for retrieve proper return values from IRIS

classMethodValue()   - for call general classmethods

classMethodInteger - Return integer value
classMethodVoid - No return value
classMethodValue - default string
classMethodFloat - float return value

invoke() - is used to call the instance methods. You have to initiate the object for call this invoke functions

invokeString  - default string
invokeFloat - float return value
invokeInteger  -  return integer value

 

Will cover the functions, procedure calls in routines and other functionality in the upcoming article.

Discussion (0)1
Log in or sign up to continue