Skip to content

Basics

In this introductory example, we aim to determine whether a patient has a fever. While this is typically a simple check, we can automate the decision using an Arden Syntax script. This MLM accepts a temperature value, evaluates whether it is greater than or equal to 38°C, and returns the appropriate outcome: fever or no fever. To achieve this, we’ll use variables within the MLM.

Variables

Variables in Arden Syntax are loosely typed, meaning we don’t need to declare their types beforehand. A variable is created simply by assigning it a value. Arden supports two syntaxes for variable assignment:

arden-syntax
data:
    myString := "five"; 
    LET myNumber BE 5;                      // alternative assignment

When executing an MLM, input values, in our example the patient’s temperature, can be passed in as arguments. These arguments can be single values or lists, and they are accessed within the data slot.

arden-syntax
data:
    myArg := argument;                       // single argument
    (argOne, argTwo, argThree) := argument;  // multiple arguments

Let's apply this knowledge in a real-world scenario: determining whether a patient has a fever by specifying the input temperature.

arden-syntax
knowledge:
  type:		   data_driven;;
  data:        
    temperature := argument;                    
  ;;
  priority:    ;;
  evoke:       ;;

Comments

As you have seen, we already used some comments to explain code without affecting how it runs. There are two kinds:

  • Block comments start with /* and end with */. They can appear anywhere and don’t need surrounding spaces. Block comments do not nest: /* A /* */ is treated as one comment
  • Line comments start with // and run until the end of the line. Everything after // is ignored, even if it contains */.

Now that we've stored the patient's value in the temperature variable, we can use a basic if-else structure and comparison operators to evaluate it. You can learn more about these options by clicking the links and reading the corresponding section in the references.

In Arden Syntax, conditional logic works similarly to most programming languages. In this case, we’re using the >= operator to check if the temperature is equal to or above the fever threshold (38°C). If it is, we classify the patient as having a fever; otherwise, we determine that they do not.

arden-syntax
  logic:
    if temperature >= 38 then
      classification_long := "is above normal and is classified as fever.";
      classification_short := "Fever.";
    elseif temperature < 38 then
        classification_long := "is normal and is classified as no fever.";
        classification_short := "No fever.";
    endif;
	
    conclude true;
  ;;
  action:	 
    return temperature || "°C and " || classification_long;
  ;;
  urgency: 50;;
resources:
  default: en;;
  language: en;;
  end:

The action slot is where we define what the MLM should do with the results of the logic evaluation. In this example we write a message that includes the input temperature and the long-form classification. Then it returns the short classification ("Fever." or "No fever.").

String Concatenation

In Arden Syntax, the || operator is used to join (concatenate) strings together. It also automatically converts non-string values (like numbers or dates) into strings, so you can combine different data types in a single message.

This concludes our first MLM! Putting it all together, this is the full code:

arden-syntax
maintenance:
  title:       Fever;;
  mlmname:     fever;;
  arden:       Version 3;;
  version:     1.00;;
  institution: Medexter;;
  author:      Knowledge Engineering Team;;
  specialist:  Knowledge Engineering Team;;
  date:        2016-01-01;;
  validation:  testing;;
library:
  purpose:     returns if the patient has fever or not;;
  explanation: ;;
  keywords:    ;;
  citations:   ;;
  links:       ;;
knowledge:
  type:		   data_driven;;
  data:        
    temperature := 39;   // single input parameter                     
  ;;
  priority:    50;;
  evoke:       ;;
  logic:
    if temperature >= 38 then
      classification_long := "is above normal and is classified as fever.";
      classification_short := "Fever.";
    elseif temperature < 38 then
        classification_long := "is normal and is classified as no fever.";
        classification_short := "No fever.";
    endif;
    conclude true;
  ;;
  action:	 
    return temperature || "°C and " || classification_long;
  ;;
  urgency: 50;;
resources:
  default: en;;
  language: en;;
  end:

What we learned:

  • Accept input via the data slot
  • Use control structures and comparison operators
  • Output results using string concatenation

If you're ready to dive deeper, check out the guide on handling fuzzy fever thresholds here, or follow along with the next tutorial on checking allergies.