Close

Framingham risk score

A project log for Medical tricorder

Using artificial intelligence to identify a disease by its symptoms

m-bindhammerM. Bindhammer 05/01/2015 at 14:220 Comments

The Framingham risk score is an algorithm to estimate the 10-year risk of developing coronary heart disease (CHD). I want to combine the diabetes type 2 risk calculator with this algorithm because many of the input data are the same. Furthermore I want to research if total/HDL cholesterol as well as systolic blood pressure can be estimated from simple to obtain numerical data (e.g. BMI) or Boolean data (e.g. on high blood pressure medication? - yes, no) in case the user has no access to laboratory diagnosis and blood pressure monitor.

Code snippet of Framingham risk score algorithm below:

// Framingham Risk Score

void setup() {
  Serial.begin(9600);
}

void loop() {
  // user input data
  boolean gender = true; // false: female, true: male
  boolean smoker = true;
  boolean medication = true; // high blood pressure medication
  int age = 60;
  int total_cholesterol = 200; // mg/dL
  int HDL_cholesterol = 20; // mg/dL
  int systolic_blood_pressure = 200; // mm Hg
  
  int CHD_score;
  // look-up tables obtained from http://en.wikipedia.org/wiki/Framingham_Risk_Score
  int score_age_women_men[10][4] =
  {
    {20, 34, -7, -9},
    {35, 39, -3, -4},
    {40, 44, 0, 0},
    {45, 49, 3, 3},
    {50, 54, 6, 6},
    {55, 59, 8, 8},
    {60, 64, 10, 10},
    {65, 69, 12, 11},
    {70, 74, 14, 12},
    {75, 79, 16, 13}
  };
  int tot_cholesterol_women_men[5][12] =
  {
    {130, 159,  0, 0, 0, 0, 0,  0, 0, 0, 0, 0},
    {160, 199,  4, 3, 2, 1, 1,  4, 3, 2, 1, 0},
    {200, 239,  8, 6, 4, 2, 1,  7, 5, 3, 1, 0},
    {240, 279,  11, 8, 5, 3, 2,  9, 6, 4, 2, 1},
    {280, 320,  13, 10, 7, 4, 2,  11, 8, 5, 3, 1}
  };
  int smoker_women_men[5][2] =
  {
    {9, 8},
    {7, 5},
    {4, 3},
    {2, 1},
    {1, 1}
  };
  int HDL_cholesterol_women_men[4][3] =
  {
    {60, 100, -1},
    {50, 59, 0},
    {40, 49, 1},
    {20, 39, 2}
  };
  int blood_pressure_women_men[5][6] =
  {
    {90, 119,  0, 0,  0, 0},
    {120, 129,  1, 3,  0, 1},
    {130, 139,  2, 4,  1, 2},
    {140, 159,  3, 5,  1, 2},
    {160, 200,  4, 6,  2, 3}
  };
  int CHD_risk_score[14][6] =
  {
    {-10, 8,  -10, 0,  1, 1},
    {9, 12,  1, 4,  1, 1},
    {13, 14,  5, 6,  2, 2},
    {15, 15,  7, 7,  3, 3},
    {16, 16,  8, 8,  4, 4},
    {17, 17,  9, 9,  5, 5},
    {18, 18,  10, 10,  6, 6},
    {19, 19,  11, 11,  8, 8},
    {20, 20,  12, 12,  11, 10},
    {21, 21,  13, 13,  14, 12},
    {22, 22,  14, 14,  17, 16},
    {23, 23,  15, 15,  22, 20},
    {24, 24,  16, 16,  27, 25},
    {25, 46,  17, 46,  30, 30}
  };
  // compute age score
  for(int i = 0; i < 10; i++) {
    if(gender == false && age >= score_age_women_men[i][0] && age <= score_age_women_men[i][1]) {
      CHD_score = score_age_women_men[i][2];
      break;
    }
    if(gender == true && age >= score_age_women_men[i][0] && age <= score_age_women_men[i][1]) {
      CHD_score = score_age_women_men[i][3];
      break;
    }
  }
  // get age index for cholesterol and smoker score
  int j;
  for(j = 0; j < 9; j += 2) {
    if(age >= score_age_women_men[j][0] && age <= score_age_women_men[j+1][1]) {
      j = j/2;
      break;
    }
  }
  // compute cholesterol and smoker score
  for(int i = 0; i < 5; i++) {
    if(total_cholesterol >= tot_cholesterol_women_men[i][0] && total_cholesterol <= tot_cholesterol_women_men[i][1]) {
      if(gender == false) {
        CHD_score += tot_cholesterol_women_men[i][j+2];
        if(smoker == true) CHD_score += smoker_women_men[j][0];
      }
      if(gender == true) {
        CHD_score += tot_cholesterol_women_men[i][j+7];
        if(smoker == true) CHD_score += smoker_women_men[j][1];
      }
      break; 
    }
  }
  // compute HDL cholesterol score
  for(int i = 0; i < 4; i++) {
    if(HDL_cholesterol >= HDL_cholesterol_women_men[i][0] && HDL_cholesterol <= HDL_cholesterol_women_men[i][1]) {
      CHD_score += HDL_cholesterol_women_men[i][2];
      break;
    }
  }
  // compute blood pressure score
  for(int i = 0; i < 5; i++) {
    if(systolic_blood_pressure >= blood_pressure_women_men[i][0] && systolic_blood_pressure <= blood_pressure_women_men[i][1]) {
      if(gender == false) {
        if(medication == false) CHD_score += blood_pressure_women_men[i][2];
        if(medication == true) CHD_score += blood_pressure_women_men[i][3];
      }
      if(gender == true) {
        if(medication == false) CHD_score += blood_pressure_women_men[i][4];
        if(medication == true) CHD_score += blood_pressure_women_men[i][5];
      }
    }
  }
  // compute 10 year CHD risk
  for(int i = 0; i < 14; i++) {
    if(gender == false) {
      if(CHD_score >= CHD_risk_score[i][0] && CHD_score <= CHD_risk_score[i][1]) {
        if(i == 0) Serial.print("< ");
        if(i == 13) Serial.print("> ");
        Serial.print(CHD_risk_score[i][4]);
        break;
      }
    }
    if(gender == true) {
      if(CHD_score >= CHD_risk_score[i][2] && CHD_score <= CHD_risk_score[i][3]) {
        if(i == 0) Serial.print("< ");
        if(i == 13) Serial.print("> ");
        Serial.print(CHD_risk_score[i][5]);
        break;
      }
    }
  }
  Serial.println(" of 100 people with this level of risk will have a heart attack in the next 10 years");
  while(1) {
  } 
}

Discussions