Respiratory-Diseases-Expert-System

An expert system for diagnosis of respiratory diseases, including the infamous COVID-19.

View the Project on GitHub

Respiratory Diseases Expert System

Ray Jasson
30/01/2021


Background

This is a simple expert system for diagnosis of respiratory diseases written in JavaScript. The expert system is developed using rools, a small rule engine for Node.js, and Handlebars.js, a semantic templating language for JavaScript. Try it here!

UI of the expert system


A total of 16 respiratory diseases have been selected for differential diagnosis:

The differential diagnosis is based on a set of 13 factors that are categorized into:


Build Decision Tree using ID3 Algorithm

The Iterative Dichotomiser 3 (ID3) algorithm is used to generate a decision tree for the expert system. The decision tree can be converted into a comparable rule set in which each rule corresponds to a possible path from the root node to any leaf node. The rule set is used as the rule engine for the expert system.

The decision tree


Note that only 9 out of 13 factors are used to extract the decision rules.

This is due to 2 rationales:


Implementation in JavaScript

The decision rules are transformed into JavaScript code using rools. For example:

const { Rools, Rule } = require('rools');
const rules = [];

rules[0] = new Rule({
    name: "pertussis and influenza diagnosis",
    when: [
        facts => facts.wheezing === "N",
        facts => facts.cough === "dry",
        facts => facts.coughingUpBlood === "N",
        facts => facts.chestPain === "N",
        facts => facts.rapidBreathing === "N",
        facts => facts.rapidHeartbeat === "N",
    ],
    then: facts => {
        facts.disease = ["pertussis", "influenza"];
        facts.percentage = [evaluate("pertussis", facts, data), 
                            evaluate("influenza", facts, data)];
    },
});

rules[1] = new Rule({
    name: "influenza diagnosis 2",
    when: [
        facts => facts.wheezing === "N",
        facts => facts.cough === "dry",
        facts => facts.coughingUpBlood === "N",
        facts => facts.chestPain === "N",
        facts => facts.rapidBreathing === "N",
        facts => facts.rapidHeartbeat === "Y",
    ],
    then: facts => {
        facts.disease = "influenza";
        facts.percentage = evaluate("influenza", facts, data);
    },
});


Program Execution

Run locally for development

Download the code, and from the root directory, run:

npm install
npm devstart

Open http://localhost:3000 to view it in the browser.

Deploy the app on cloud

This app is also deployed on Heroku.


References