Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
def square = { x ->
    x * x
}

def myString = [2, 4, 6].collect { "${ it } squared is ${ square(it) }" }.join("\n")

return new Result(myString)

A more useful rule, to fetch the patient's age, would be:

Code Block

return new Result(context.getPatient(patientId).getAge(context.indexDate))

Here's a verbose version of that same age logic

Code Block

/*
 * In order to add as little overhead as possible, allowing rules to be run relatively efficiently on very large
 * cohorts, the rule framework does not automatically provide us with a Patient object, but just a patientId.
 * This line fetches that Patient object. (It actually fetches all patients in the cohort the rule is being evaluated
 * on.)
 */
def patient = context.getPatient(patientId)

/*
 * We want this rule to work correctly if you evaluate it as-of some other date. So we fetch the index date from
 * the LogicContext. "context.indexDate" is groovy shorthand for "context.getIndexDate()"
 */
def age = patient.getAge(context.indexDate)

/*
 * We need to wrap our returned value in a logic Result.
 */
return new Result(age)

Java Rules

These "work", but are very hard to use. A later logic module release will make these easier to use. (But why not use Groovy instead? It's better...)

...