Simple rule engine example
The purpose of this repository is to provide an example of how a Rule Engine can be implemented in InterSystems Caché using Object Generators.
set path="C:\Temp\cache-iat-ruleengine-master\cache"
do $system.OBJ.ImportDir(path,"*.inc","ck",.error,1)
do $system.OBJ.ImportDir(path,"*.xml","ck",.error,1)
Class IAT.S01.Rules.Test.Example Extends %RegisteredObject {
ClassMethod Run() As %Status
{
set ret = $$$OK
try {
// create a patient
set p = ##class(Patient).%New()
set p.MRN="1234", p.Name="John", p.Surname="Snow", p.DOB=$zdh("1975-05-07",3)// create a rule context, set data set context = ##class(PatientContext).%New() set context.Patient = p // evaluate Patient Alerts Rule set ruleEngine = ##class(IAT.S01.Rules.Engine).%New() $$$TOE(sc, ruleEngine.Evaluate("IAT.S01.Rules.Test.PatientAlertsRule", context, .log)) // print log write !,"Rule log:",! zwrite log
} catch ex {
set ret = ex.AsStatus()
do $system.Status.DisplayError(ret)
}
quit ret
}
}
Execute the method from a Terminal session:
do ##class(IAT.RuleEngine.Test.Example).Run()
=======================
SendEmail
To:test@server.com
Body:
Patient is so old!=======================
ShowObject
+----------------- general information ---------------
| oref value: 1
| class name: IAT.RuleEngine.Test.Patient
| reference count: 3
+----------------- attribute values ------------------
| DOB = 49069
| MRN = 1234
| Name = "John"
| Surname = "Snow"
Rule log:
log=4
log(1)="[2016-02-22 16:29:44] Rule: Not young anymore!"
log(2)="[2016-02-22 16:29:44] Action: 1"
log(3)="[2016-02-22 16:29:44] Action: 2"
log(4)="[2016-02-22 16:29:44] Action: 3"
Have a look at InterSystems Developer Community to learn about InterSystems technology, sharing solutions and staying up-to-date on the latest developments.
This example was published in https://community.intersystems.com/post/object-generators-homemade-ruleengine
Dmitry Maslennikov (https://github.com/daimor) has uploaded a very interesting alternative approach which uses %XGEN.AbstractDocument class to process the XData.
The code is available in /pr/xgen branch.
Additional information is available here:
https://community.intersystems.com/post/xdata-studio-asist
do ##class(IAT.RuleEngine.Test.Example).Run()
Container build and start runs ALL installation steps.
It is immedeatly ready for use as decsribed
Make sure you have git and Docker desktop installed.
Clone/git pull the repo into any local directory
$ git clone https://github.com/rcemper/PR_iat-ruleengine.git
$ docker compose up -d && docker compose logs -f
Quick REST access to MASTER:
http://localhost:42773/synchmaster/rest/v1/customers
Quick REST access to CLIENT:
http://localhost:42773/synchclient/rest/v1/employees
To open IRIS Terminal do:
$ docker-compose exec iris iris session iris
USER>do ##class(IAT.RuleEngine.Test.Example).Run()
- - - -
or using WebTerminal
http://localhost:42773/terminal/
To access IRIS System Management Portal
http://localhost:42773/csp/sys/UtilHome.csp