Nova postagem

Pesquisar

Artigo
· Ago. 30, 2024 3min de leitura

IRIS Native Python

Hello Community

I have previously experimented with embedded Python in IRIS; however, I have not yet had the opportunity to implement IRIS using native Python. In this article, I aim to outline the steps I took to begin learning and implementing IRIS within the Python source. I would also like thank to @Guillaume Rongier and @Luis Angel Pérez Ramos for their help in resolving the issues I encountered during my recent PIP installation of IRIS in Python, which ultimately enabled it to function properly.

Let's begin to write IRIS in python.

First comes First, You have to install the intersystems_irispython-3.2.0-py3-none-any.whl file from the github repo. I downloaded and installed in my windows machine.

py -m pip install intersystems_irispython-3.2.0-py3-none-any.whl

Verified the packages are installed in my machine by executing py -m pip list

intersystems-irispython 3.2.0
iris                    0.0.5

 

Now ready to start writing the python. I've created a .py file and import iris package on top of the class.

Now let's establish the connection to IRIS by using connection method and create use the connection object to instantiate the iris.IRIS object by using "createIRIS" and this is the crucial step to proceed further operations.

import iris
impor time

args = {'hostname':'127.0.0.1', 'port':1972,'namespace':'LEARNING', 'username':'_SYSTEM', 'password':'SYS'}

try:
    """
    some other ways instead of kwargs
    conn = iris.connect(hostname='127.0.0.1', port=1972, namespace='LEARNING',username='_SYSTEM',password='SYS')
    """
    conn = iris.connect(**args)
    # A new IRIS object that uses the given connection.
    irispy = iris.createIRIS(conn)

    print('connected!')
except Exception as e:
    # Handling the exception and printing the error
    print(f"An error occurred: {e}")
    

 

Now let's talk about the Methods for COS and global

Once you had successfully created an IRIS object. Now it's ready to use various operations

set : This function is used to define the global values in to the IRIS database

1. fist parameter is set value 

2. second parameter is global name

3. *args - third parameter is subscript(s)

def set_global(value=None,gbl=None,*args):
    #set method is in _IRIS from iris package
    irispy.set('set from irispy','mygbl','a',str(time.time()))
    print('global set done!')

set_global()

 

kill This function is used to delete the global from database

def kill_global():
    irispy.kill('mygbl')
    print('global kill done!')

IsDefined: equals to $data : verify it exist

def data_isDefined():
    # equal to $data
    print(irispy.isDefined('mygbl','a')) # o/p 10
    print(irispy.isDefined('mygbl','a','1724996313.480835')) # o/p 1

nextSubscript: Equals to $Order

irispy.nextSubscript(0,'mygbl','a')

tStart, tCommit and tRollback: same as TStart, TCommit, TRollback

def global_transaction_commit():
    irispy.tStart()
    print(irispy.getTLevel())
    irispy.set('set from irispy','mygbl','trans',str(time.time()))
    irispy.tCommit()

def global_transaction_rollback():
    irispy.tStart()
    print(irispy.getTLevel())
    irispy.set('set from irispy','mygbl','trans1',str(time.time()))
    irispy.tRollback() # tRollbackOne()

 

lock and unlock: by default incremental lock/exclusive lock

def global_lock():
    #default exclusive lock
    s = irispy.lock('',1,'^mygbl')
    time.sleep(10) # verify the lock in locktab
    irispy.unlock('','^mygbl')
    
def global_shared_lock():
    s = irispy.lock('S',1,'^mygbl')
    time.sleep(10)
    irispy.unlock('S','^mygbl')

node: subscript level traversal same as $Order

def node_traversal():
    # subscript level traversal like $Order
    for mrn in irispy.node('^mygbl'):
         for phone in irispy.node('^mygbl',mrn):
            print(f'patient mrn {mrn} and phone number: {phone}')
            
"""
o/p
patient mrn 912 and phone number: 3166854791
patient mrn 991 and phone number: 78050314
patient mrn 991 and phone number: 9128127353
"""

The node, value traversal and class definitions and it members are covered in the next article.

You can refer the IRIS documentation  for all the functions.

Discussão (0)1
Entre ou crie uma conta para continuar
Pergunta
· Ago. 30, 2024

Only load part of XML/ SQL Snapshot in visual trace- portal loads too slow

As part of fully decoupling code we send a snapshot from a business service (running a SQL statement). 

sql service                         Processor                                File Out

This is picked up by a processer and puts it into a file .txt. 

Issue is if you open it up via the SQL.snapshot message as this is 46,819 rows it'll take too long to respond to opening up the sql.snapshot in the message viewer when viewing the session if looking from the business service 

Is there any way to not have this xml open up in full in the portal? I.e. have a see more? 

I am aware this could just be in the BP but for me this is the correct integration setup- SQL service to pick up the data- process to do something with it (passed in the correct message type for it) and then sent to a file/ downstream. 

3 Comments
Discussão (3)2
Entre ou crie uma conta para continuar
Pergunta
· Ago. 30, 2024

Changing a Setting value on a schedule?

I can START and STOP a business process via its Schedule setting.

Is it possible to change the value of another Setting in an analogous way?

I can imagine a SettingSchedule that could look like 

action:YYYY-MM-DDThh:mm:ss[,action:YYYY-MM-DDThh:mm:ss]

But rather than just START or STOP, action could be "SET Setting = value", overriding whatever the normal value is.

Is there an existing way of achieving this kind of functionality?

I've got a business process that triggers from a scheduled task, and sends documents to a downstream system according to business requirements. At certain times of the day there will be more documents in the queue than the downstream system can cope with - I'd like to say:

  • between time XXXX and time YYYY never send more than NN documents at a time, even if there are more in the queue
  • at other times send as many as are in the queue.

Then the code in the business process would pick up the (current value at the point of execution, according to the schedule) and send that many documents.

(We are currently planning on achieving this by adding another Property to the scheduled task, and adding that to the trigger message, but wondered whether there was another way of doing it.)

4 Comments
Discussão (4)2
Entre ou crie uma conta para continuar
Artigo
· Ago. 30, 2024 2min de leitura

Recorrer roles de forma recursiva

Recientemente me encontré en una situación en la que un usuario tenía algunos roles, que le otorgaban roles adicionales, y así sucesivamente.

Como no entendía de dónde venía un permiso en particular, escribí este código que obtiene un conjunto inicial de roles y los recorre recursivamente, teniendo en cuenta cualquier repetición.

/// Recursively unwraps roleset.
/// Accounts for circular dependencies and repeats.
Class Utils.Roles
{

/// roles: comma-separated string of roles
/// showResources: show resources in addition to roles.
/// do ##class(Utils.Roles).Display
ClassMethod Display(roles As %String, showResources As %Boolean = {$$$NO})
{
	new $namespace
	set $namespace = "%SYS"
	set roles = $lfs(roles)
	set i=0
	while i<$ll(roles) {
		do $i(i)
		set role = $lg(roles, i)
		continue:$d(processed(role))=1
		write "Current role: ", role,!
		
		write "Grants roles: "
		set sc = ##class(Security.Roles).Get(role, .p)
		for j=1:1:$l($g(p("GrantedRoles")),",") {
			set grantedrole = $p(p("GrantedRoles"),",", j)
			continue:grantedrole=""
			continue:$lf(roles, grantedrole)
			
			write grantedrole, ", "
			set roles = roles _ $lb(grantedrole)
		}
		
		write:showResources !, "Grants resources: ", p("Resources")
		write !
	}
}

}
 
Spoiler

Code.

Discussão (0)1
Entre ou crie uma conta para continuar
Artigo
· Ago. 30, 2024 1min de leitura

QuinielaML - Predicciones de la 4ª jornada de la Quiniela

¡Venga con la nueva jornada de la Quiniela, que ya estamos a viernes! Y nuevamente con partidos de 1ª y 2ª División.

Estas son las predicciones para Primera:

Y para Segunda:

Esto nos deja la siguiente predicción:

Pues listo, ¡disfrutad de la jornada!

Discussão (0)1
Entre ou crie uma conta para continuar