Calculations you can rely on

Write clinical formulas Rhazes runs identically every time, showing their working for audit and banding the result into categories you can branch on.

Updated

Why this step exists

A model is good at reading a consultation and poor at multiplying. Asked for a BMI it is usually right. Asked for a creatinine clearance it is sometimes off. And it never shows its working.

A Calculate step is the one step no model touches. The formula is evaluated the same way on every run, and the sum it did is recorded, so a score on the audit trail is a number the clinician can check rather than one they have to trust.

For anything that feeds a clinical decision, that difference is the whole point. Usually right is not a standard you can practise to.

Writing a formula

The formula is written the way you would write it on paper: numbers, values from earlier steps, and ordinary arithmetic.

weight / (height * height)

Values from earlier steps go in as references, so a formula reads from the run rather than from fixed numbers. See Passing values between steps.

You have +, -, *, / and ^ for powers, and brackets to control the order.

Functions

FunctionWhat it does
abs(x)x without its sign
sqrt(x)Square root
ln(x)Natural logarithm
log(x)Logarithm, base 10
exp(x)e to the power x
pow(x, y)x to the power y, the same as x ^ y
min(a, b, ...)The smallest
max(a, b, ...)The largest
round(x, places)Rounded; places is optional
floor(x)Rounded down
ceil(x)Rounded up
if(test, a, b)a when the test holds, otherwise b

Additive scores

Comparisons read as 1 or 0, which is what makes an additive score straightforward to write. A criterion that scores 2 for age 75 or over is:

if(age >= 75, 2, 0)

Add the criteria together and you have the score, with every criterion visible on one line rather than buried in a prompt.

Bands

A result can be sorted into bands, so a number becomes a category you can act on. Bands are read in the order you give them, each with an upper limit, and a final open-ended one catches everything above.

The band lands in category, which means you can branch on it directly rather than re-testing the number. See Branching on a condition.

Keep bands in ascending order. They are matched in the order written, so a list out of order will not do what the builder looks like it does.

The working is kept

The step records the sum it performed and the values it read, one line each. That is what makes the result checkable afterwards, and what makes it defensible in an audit: not just the answer, but how it was reached and what went into it.

Try it before you rely on it

The builder can check a formula and run it against sample values as you write, so a mistake shows up while you are typing rather than on a patient.

Test the edges: a missing value, a zero, an implausible extreme. A formula that divides by a value which is sometimes absent will behave differently on the patient where it is absent.

Put every number here

If a workflow produces a score, a dose calculation or a threshold check, it belongs in a Calculate step rather than in a reasoning step. That is the single most useful habit in building workflows you can trust.

Related articles