Question Soufiane Amroun · Sep 11, 2017

create a rule in programming

HI world , i want to creat my own rule in ensemble without rule editor , how can i do it?

thank's

Comments

Eduard Lebedyuk · Sep 11, 2017

Same as with modifying a rule:

Business Rule Definition is stored as XML in XData block named RuleDefinition inside rule class and can be (de)serialized as an object of Ens.Rule.Model.ruleDefinition class. Some utility methods are available there.

Here's an example of modifying Demo.ComplexMap.Rule.SemesterBatchRouting rule in ENSDEMO class. It modifies "when" condition from 1 to 0.

zn "ENSDEMO"
set ruleClass = "Demo.ComplexMap.Rule.SemesterBatchRouting"
set sc = ##class(Ens.Rule.Model.ruleDefinition).LoadFromClass(ruleClass, .rule)
set rule.ruleSets.GetAt(1).actions.GetAt(1).whens.GetAt(1).condition=0
w rule.SaveAs(ruleClass)
set sc=$system.OBJ.Compile(ruleClass,"k-d")

But instead of:

set sc = ##class(Ens.Rule.Model.ruleDefinition).LoadFromClass(ruleClass, .rule)

You need to create and fill rule object manually.

Relevant discussion.

0
Eduard Lebedyuk  Sep 11, 2017 to Soufiane Amroun

Why don't you want to do it in the rule editor?

0
Soufiane Amroun · Sep 11, 2017

Hi Eduard , i used this code to edit a rule fields and it functionnes very well, but in my program i take measure of the patient (for example temprature )and i want to creat a rule wich generat alert if temperature is higher than 39°C for example.

0