Giter Club home page Giter Club logo

respiratory-diseases-expert-system's Introduction

Respiratory Diseases Expert System

Hits

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:

  • Acute bronchitis
  • Asthma
  • Bronchiectasis
  • Bronchiolitis
  • Chronic Obstructive Pulmonary Disease (COPD)
  • Common cold
  • COVID-19
  • Croup
  • Cystic fibrosis
  • Influenza
  • Lung cancer
  • Occupational lung diseases
  • Pertussis
  • Pneumonia
  • Rhinosinusitis
  • Tuberculosis

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

  • Epidemiological factors
    • Age group
    • Gender
    • Family history
    • Smoking history
  • Clinical factors
    • Duration
    • Chest pain
    • Cough
    • Coughing up blood (Hemoptysis)
    • Fever
    • Rapid breathing (Tachypnea)
    • Rapid heartbeat (Tachycardia)
    • Shortness of breath (dyspnea)
    • Wheezing

๐ŸŒฒ Building 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:

  • The 9 included factors: smoking history, chest pain, cough, coughing up blood, fever, rapid breathing, rapid heartbeat, shortness of breath and wheezing are the primary predictors or indicators of respiratory diseases. These predictors are symptoms that are caused directly by a particular respiratory disease. Smoking history is an exception here. It is not a symptom, but it is the leading cause of most respiratory diseases.
  • The 4 excluded factors: age group, gender, family history and duration are considered as risk factors of respiratory diseases. Risk factors are correlational and not necessarily causal, and correlation does not imply causation. These risk factors may increase the risk of developing respiratory diseases, but they are not the direct or leading causes for the diseases.

๐Ÿ’ฌ 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

respiratory-diseases-expert-system's People

Contributors

imgbotapp avatar jhhom avatar rayjasson98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

deeola

respiratory-diseases-expert-system's Issues

Wrong output from the "diagnosis" function in the es.js module

async function diagnose(facts) {
const rools = new Rools();
await rools.register(rules);
await rools.evaluate(facts);
return facts;

What's the problem:
The diagnose function returns the old facts without the disease and percentage properties

What's expected:
The diagnose function should return facts with disease and percentage

What I've tried:
I tried to follow the original rools documentation

async function diagnose(facts) {
    const rools = new Rools();
    await rools.register(rules);
    return await rools.evaluate(facts);
};

But the output doesn't seem to be correct either:

{
  updated: [
    'disease',           'ageGroup',
    'gender',            'familyHistory',
    'smokingHistory',    'duration',
    'chestPain',         'cough',
    'coughingUpBlood',   'fever',
    'rapidBreathing',    'rapidHeartbeat',
    'shortnessOfBreath', 'wheezing',
    'percentage'
  ],
  fired: 1,
  elapsed: 2
}

What I expect:

{
  disease: ...,
  percentage: ...,
  gender: ....,
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.