RunMED is a rule-based expert system that diagnoses muscle injuries caused by indirect trauma in runners. It is written in CLIPS and runs on a CLIPS 6.30 build extended with custom C functions.
It was developed as the final project for the Knowledge Engineering and Expert Systems course (BSc in Computer Science, Department of Computer Science, University of Bari, academic year 2017/2018).
Warning
RunMED is an academic project and not a medical device. Its diagnoses are only a first, quick indication. Always see a specialist (sports physician, physiotherapist) for a real diagnosis and rehabilitation plan.
Note
The user interface (questions, answers, diagnoses) is in Italian.
- Overview
- Diagnostic process
- Features
- Certainty factors
- Diagnosable injuries
- Repository structure
- Building
- Running
- Example sessions
- Knowledge base
- Knowledge acquisition
- Limitations
- Credits
RunMED is aimed at people who run, whether competitively or for fitness. It only covers the muscles most involved in running, which are the muscles of the lower limbs (thigh and leg).
Athletes often diagnose themselves when they feel a muscle problem. They may misread their symptoms and treat the injury as more serious than it is, or underestimate it. Self-diagnosis is risky, especially for inexperienced people, because a wrong diagnosis can greatly lengthen recovery. RunMED offers a quick and reasonably reliable first assessment, because it encodes knowledge from human experts in the field. Use it before seeing a specialist, who will then give a complete clinical picture.
The system reasons with uncertain knowledge. In sports medicine you cannot give a certain diagnosis from a partial clinical picture. RunMED therefore can propose several diagnoses, each with its own certainty factor.
A RunMED session feels much like a visit to a human therapist. The final diagnoses come from three phases:
- General anamnesis. RunMED collects the patient's personal details and physiological traits (gender, age, weight, height, resting heart rate, past vascular conditions) to check for physical predispositions to certain injuries. The questions come in random order to make the interaction more realistic. From the answers the system works out:
- the body-weight condition from the BMI: underweight (< 19), normal weight (19–25), overweight (> 25);
- the resting heart rate: bradycardia (< 60 bpm), normal (60–100 bpm), tachycardia (> 100 bpm);
- the age group: young (< 30), over-30 (30–40), over-40 (> 40).
- Specific anamnesis. This phase extends the general anamnesis and is the first look at the muscle problem itself. RunMED asks where the pain is (thigh or leg; anterior, posterior, lateral or internal) and how many kilometres the athlete ran in the week before the problem started.
- Medical observation. RunMED evaluates the patient's signs and symptoms: when the pain started, the type of pain, visible structural lesions, loss of function, response to stretching, and effect on walking. This is the most important phase for the diagnoses. The patient can also retract answers here, and the system then reasons again from scratch.
- Patient medical record management. RunMED creates a medical record the first time a patient uses it. On later visits it loads the record and skips the general anamnesis. Patients can also update their record when some of the stored information is out of date. Patients identify themselves by first and last name. Records are saved as plain
.clpfiles inclips/clp/, so they persist between sessions. - Built-in help. If a question is unclear, or the user doesn't know a medical term, they can answer
?to see an explanation of the question or a glossary of the terms. - Certainty factor for each diagnosis. Many signs and symptoms are shared by several injuries, so the certainty of each diagnosis builds up as evidence comes in (see below).
- Diagnosis retraction. If patients realise they gave a wrong answer, they can change it. The system then reasons again and updates the diagnoses and their certainty factors.
- Rehabilitation programmes. Each diagnosis comes with a simple rehabilitation programme. You should still consult a physiotherapist for a complete programme tailored to you.
RunMED computes certainty cumulatively. At any point during the run, the certainty factor of a hypothesis h is:
CF[h, e'] = MB[h, e''] − MD[h, e''']
where:
- CF[h, e'] is how much confidence the conclusion deserves, given the available information (between 0 and 1);
- MB[h, e''] (measure of belief) is how strongly the evidence e'' supports hypothesis h;
- MD[h, e'''] (measure of disbelief) is how strongly the evidence e''' counts against hypothesis h.
For two independent sources of evidence S1 and S2 about hypothesis h:
MB = MB[h, S1] + MB[h, S2] · (1 − MB[h, S1])
MD = MD[h, S1] + MD[h, S2] · (1 − MD[h, S1])
RunMED can diagnose 7 muscle injuries:
| Injury | Description |
|---|---|
| DOMS (Delayed Onset Muscle Soreness) | Pain and discomfort that appear within 24 hours after training or a race, last 48–72 hours and go away on their own. The athlete feels it when the muscle contracts and when the relaxed muscle is pressed, and the muscle can't perform at its usual level. DOMS comes from micro-damage to individual muscle fibres in people who are not trained enough for the effort. |
| Muscle cramp | A sudden, painful, involuntary contraction that always goes away on its own within a few minutes. It is often caused by fatigue, an imbalance of water and electrolytes, or a lack of energy. |
| Muscle contracture | An involuntary contraction that does not go away on its own. It causes a dull, poorly localised pain that starts after the activity stops, a few hours later or in the following days. It nearly always comes from muscle fatigue after too intense or too long an effort. Ultrasound shows no damage to the muscle, and it heals within at most ten days. |
| Muscle strain (elongation) | There is no real damage to the fibres, but a marked, localised change in muscle tone caused by pulling the fibres too hard. The pain is immediate and sharp, well localised about 2/3 of the time, and may force the athlete to stop. With proper rehabilitation, running can resume in 15–21 days. |
| Grade I lesion (distraction) | Less than 5% of the fibres are torn. The pain is sudden and sharp: stabbing, cramp-like or bruise-like. Return to competition after about 21 days. |
| Grade II lesion | The muscle is partially torn and the fibres swell. The athlete feels an intense stabbing pain, loses function immediately and cannot go on. Return to competition after about 5–6 weeks. |
| Grade III lesion | The muscle is totally or almost totally torn. Ultrasound shows the two muscle ends pulled apart, with a large haematoma between them. Function is completely lost. Return to competition takes 2–3 months and needs a gradual rehabilitation programme. |
Muscle tears (lesions) usually cause an acute, stabbing, violent pain during activity. The pain is well localised and stops the athlete from going on. Torn fibres bleed, so a haematoma forms, larger or smaller depending on how big the tear is and where it is.

How DOMS develops over time. The x-axis shows hours and the y-axis the level of DOMS.
Phases: A) onset, B) peak, C) decrease, D) disappearance, E) full recovery.
RunMED/
├── clips/ CLIPS 6.30 source code, extended with RunMED's functions
│ ├── userfunctions.c custom C functions added to CLIPS (see below)
│ ├── main.c CLIPS entry point
│ ├── makefile.gcc makefile for GCC / MinGW
│ ├── makefile.win makefile for Visual C++ (nmake)
│ └── clp/
│ ├── RunMED.clp the expert system (rules, templates, functions)
│ └── MarioRossi.clp example patient medical record
└── docs/images/ images used in this README
The CLIPS environment was extended with user-defined external functions in clips/userfunctions.c and then recompiled:
| Function | Description | Parameters |
|---|---|---|
creacartella |
Creates (or overwrites) the patient's medical record in clp/<FirstName><LastName>.clp. |
first name, last name, gender, age, resting heart rate, weight, height, past vascular condition |
imc |
Computes the patient's Body Mass Index (indice di massa corporea). | weight (kg), height (m) |
certezza |
Computes the final certainty of a diagnosis (MB − MD). |
final MB, final MD |
incr_mb |
Updates the measure of belief of an injury with new independent evidence. | current MB, MB of the new evidence |
incr_md |
Updates the measure of disbelief of an injury with new independent evidence. | current MD, MD of the new evidence |
You need a C compiler. The examples below use GCC; on Windows you can use MinGW-w64, MSYS2 or Strawberry Perl's toolchain.
Linux / macOS
cd clips
make -f makefile.gccWindows (MinGW)
cd clips
mingw32-make -f makefile.gccEither command produces the clips executable (clips.exe on Windows) in the clips/ folder. You can also import the clips/ folder into Eclipse CDT as an existing project.
RunMED reads and writes medical records in clp/, a path relative to the working directory. Start CLIPS from the clips/ folder:
cd clips
./clips # clips.exe on WindowsThen load and start the expert system at the CLIPS prompt:
CLIPS> (load clp/RunMED.clp)
CLIPS> (reset)
CLIPS> (run)To see how a returning patient is handled, answer no to the first question and enter Mario / Rossi. RunMED then loads the example record clp/MarioRossi.clp.
Mario Rossi is using the system for the first time and has a muscle problem in the back of the thigh. He creates his medical record and goes through the general anamnesis:
The general anamnesis ends with a summary, and the specific anamnesis begins. Answering ? shows the help for the current question:
After the medical observation, RunMED shows the diagnoses with their certainty factors and rehabilitation programmes:
A few months later Mario Rossi uses the system again, this time for a muscle problem in his leg. His medical record already exists, so RunMED loads it and skips the general anamnesis:
The help explains the possible types of pain:
RunMED proposes its diagnoses. Mario realises he gave a wrong answer and asks to retract the diagnoses:
He picks the answer to change, and RunMED reasons again from the corrected evidence:
The knowledge base in RunMED.clp has 105 rules. They fall into two groups:
- Control rules (1–34) run the interaction. They ask the general anamnesis questions while data is missing, classify BMI, heart rate and age, create and summarise the medical record, ask the specific anamnesis questions, and choose which observation question to ask next from the previous answers. When the observation is complete, they compute the certainty factors, show the diagnoses and offer retraction.
- Evidence rules (35–105) update each injury's measure of belief (or disbelief) when a sign or symptom is observed. They are summarised below.
Evidence rules: increment of the measure of belief (MB) for each injury
| Evidence | DOMS | Cramp | Contracture | Strain | Grade I | Grade II | Grade III |
|---|---|---|---|---|---|---|---|
| Patient is over-40 | 0.1 | 0.1 | 0.1 | 0.1 | |||
| < 30 km run in the previous week | 0.2 | ||||||
| > 60 km in the previous week and normal weight or overweight | 0.2 | 0.2 | |||||
| Past vascular conditions | 0.2 | ||||||
| Onset during training | 0.2 | 0.1 | 0.2 | 0.2 | 0.2 | 0.2 | |
| Onset right after training | 0.3 | ||||||
| Onset the day after training | 0.4 | 0.1 | |||||
| Pain type: sharp twinge (fitta) | 0.2 | 0.2 | |||||
| Pain type: throbbing (pulsorio) | 0.2 | 0.2 | |||||
| Pain type: burning (bruciore) | 0.2 | ||||||
| Pain type: pinpoint (puntorio) | 0.2 | ||||||
| Pain type: muscle cannot be stretched | 0.2 | 0.2 | 0.1 | ||||
| Non-traumatic cause | 0.2 | 0.2 | 0.2 | 0.2 | |||
| Traumatic cause | 0.2 | 0.2 | 0.2 | ||||
| Pain is spread out | 0.2 | 0.2 | 0.2 | 0.2 | 0.1 | ||
| Pain is localised | 0.2 | 0.2 | 0.2 | ||||
| No visible structural lesions | 0.1 | 0.1 | 0.2 | 0.1 | MD +0.1 | MD +0.1 | |
| Visible bruising (ecchimosi) | 0.2 | 0.4 | |||||
| Visible haematoma | 0.4 | ||||||
| No loss of function | 0.2 | 0.2 | |||||
| Loss of function | 0.2 | 0.2 | 0.2 | 0.2 | 0.2 | ||
| Pain decreases with stretching | 0.2 | 0.2 | |||||
| Pain partially decreases with stretching | 0.2 | 0.2 | |||||
| Pain does not decrease with stretching | 0.2 | 0.2 | 0.2 | ||||
| No effect on walking | 0.1 | 0.1 | 0.1 | 0.1 | |||
| Pain affects walking | 0.2 | 0.2 | 0.2 |
MD +0.1 means the evidence raises the measure of disbelief for that injury.
Two human experts gave essential support in building the system:
- Dr. Antonio Giuseppe Esposito, MSc in Sport Sciences;
- Dr. Michele Roberto Ninivaggi, physiotherapist.
The knowledge came from a series of interviews. Both experts were interested in the project from the start and were available for clarifications and revisions. They also provided material for studying the medical domain, and printed material they had prepared to make the interaction more realistic. A medical encyclopedia was consulted as well.
A varied group of runners tested the system, including the two experts, who are professional athletes.
The system draws on a large amount of medical knowledge and on constant input from human experts, but it cannot fully replace a therapist. As the experts pointed out many times, a certain enough diagnosis and a full recovery plan need clinical and imaging tests, such as ultrasound or MRI depending on how serious the injury is.
RunMED reaches a possible diagnosis quickly through a short but detailed interaction. It is even quicker when the patient's medical record is already stored, and the domain experts helped make the interaction realistic. Medical software often has to work under time constraints, and RunMED strikes a good balance between speed and reliability.
- Author: costa961
- Course: Ingegneria della Conoscenza e Sistemi Esperti (Knowledge Engineering and Expert Systems), Prof. Floriana Esposito, University of Bari, a.y. 2017/2018
- License: RunMED's own code is released under the MIT License.
- CLIPS: the CLIPS 6.30 source code in
clips/was originally developed at NASA and is distributed under its own permissive license (see the header of each source file). More information at clipsrules.net.









