Skip to content

Check Patient's Allergies

In this example, we want to automatically check whether a patient is allergic to any medications from a predefined list. This is a very common operation in clinical decision support, for example, before prescribing a drug, we need to make sure the patient has no known allergies to it.

Lists

To store all of a patients allergies, we need lists. Lists in Arden Syntax are ordered collections of items that can hold strings, numbers, or even mixed data types. You create a list by separating items with commas:

arden-syntax
data:
    mixed_data := "Glucose", 5.6, true;  
    med_allergen := "Penicillin", "Aspirin", "Sulfonamides";
    patient_allergies := "Insulin", "Aspirin";

We define med_allergen as the medications we want to check against and patient_allergies is the list of the patient’s documented allergies.

While Loop

To check if a patient is allergic to any medication ingredient, we can iterate through a list of allergens:

arden-syntax
logic:
    // Checks each allergen in the medication and stops if patient is allergic to it
    while num <= (count med_allergen) do
        allergen := med_allergens[num];
        allergy_found := (patient_allergies = allergen);
        if any allergy_found then
            breakloop;              // execution of the while-loop will stop immediately 
        endif;
    num := num + 1 ;                // increments the counter
    enddo;

Lists in Arden start indexing at 1. The square brackets [] are called the element operator and are used to access a specific list item. In each loop cycle, we take the current allergen from the list and check whether it matches any of the patient’s allergies.

If a match is found, breakloop stops the loop immediately, which improves efficiency by avoiding unnecessary checks. If the loop is inside another loop, breakloop only stops the innermost one. The final result will be true if an allergy was found and false otherwise, and this can be returned to the calling MLM for further processing.

You can read more about loops and control structures here.

Parenthesis

Parentheses are not only used to help represent lists emptyList := (); but also can be used to override operator precedence. The order in which operators are executed is decided by using an operator property called precedence, if you aren't sure about it just put parentheses around the ones that need to be evaluated first. The whole precedence table can be found in the full Arden Standard text.

The loop condition while num <= (count med_allergen) do is equivalent to while num <= count med_allergen do and also while num <= count (med_allergen) do. Here, the parentheses do not change the meaning, they are just for clarity.

Aggregation Operators

Aggregation Operators are a convenient way to quickly extract a single, meaningful value from a collection without having to manually loop through its elements.

Here in this example we have used the following:

  • count, which counts all the elements in a list and
  • any, the any keyword checks if at least one true value is found in a list. You can optionally write any ... isTrue to make the statement easier to read.

More examples of such operators can be found here.

Full MLM

If we only care about we can be done with checking as soon as one match has been found, since we won't administer the medicine if the patient is allergic to at least one of the ingredients. Here we can use conclude true as soon as we found one conflicting ingredient, and execute the action slot immediately.

arden-syntax
maintenance:
    title:          Allergies;;
    mlmname:        allergies;;
    arden:          version 3;;
    version:        1.0;;
    institution:    Medexter Healthcare;;
    author:         Knowledge Engineering Team;;
    specialist:     Knowledge Engineering Team;;
    date:           2025-06-06;;
    validation:     production;;
library:
    purpose: returns if the patient is allergic to some medication;;
    explanation: loops through a list of known medication allergens and checks if any of them match the patient’s documented allergies;;
    keywords: allergy check;;
    citations: ;;
    links: ;;
knowledge:
    type: data_driven;;
    data: 
        num := 1;
        med_allergens := "Penicillin", "Aspirin", "Sulfa drugs";  
        patient_allergies := "Insulin", "Aspirin";  
        ;;
    priority: 50;;
    evoke: ;;
    logic:
        while num <= (count med_allergens) do
            allergen := med_allergens[num];
            allergy_found := (patient_allergies = allergen);
            if any allergy_found then
                conclude true;          // execution of logic section is done and jump to action slot 
            endif;
            num := num + 1;             // increments the counter
        enddo;
        conclude false;;
    action: 
        return warning || patient_allergies ;;
    urgency: 50;;
resources:
    default: en;;
    language: en
        'msg': "Caution, the patient has the following allergies documented: "
        ;;
    language: de
        'msg': "Vorsicht, zu diesem Patienten wurden die folgenden Allergien dokumentiert: "
        ;;
    end:

To test different language outputs we can use warning := LOCALIZED 'msg' by "de"; if by is omitted the systems standard language is used automatically.

This tutorial covered:

  • Lists containing strings
  • How to set up while loops
  • Using localized operator for language specific messages

You have finished all basic examples and are ready for some more advanced ones!