Close

Type 2 diabetes risk assessment

A project log for Medical tricorder

Using artificial intelligence to identify a disease by its symptoms

m-bindhammerM. Bindhammer 04/16/2015 at 07:170 Comments

A risk assessment tool has been coded based on a short list of questions to assess the risk of developing type 2 diabetes over the next ten years. Example Arduino code below:

char incomingLetter;

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

void loop() {
  Serial.println("TYPE 2 DIABETES RISK ASSESSMENT"); 
  Serial.println("");
  int score = 0;
  char * a_to_d[] = {"a) ", "b) ", "c) ", "d) "};
  char * questionary[8][5] = 
  {
    {"1. AGE", "Under 45 years", "45-54 years", "55-64 years", "Over 64 years"},
    {"2. BODY-MASS INDEX, BMI = MASS [kg]/(HEIGHT [m])^2", "Lower than 25 kg/m^2", "25-30 kg/m^2", 
     "Higher than 30 kg/m^2"},
    {"3. WAIST CIRCUMFERENCE BELOW RIBS", "Men: Less than 94 cm, Women: Less than 80 cm", 
     "Men: 94-102 cm, Women: 80-88 cm", "Men: More than 102 cm, Women: More than 88 cm"},
    {"4. DAILY AT LEAST 30 MINUTES PHYSICAL ACTIVITY?", "Yes", "No"},
    {"5. HOW OFTEN DO YOU EAT VEGETABLES OR FRUITS?", "Every day", "Not every day"},
    {"6. HAVE YOU EVER TAKEN MEDICATION FOR HIGH BLOOD PRESSURE ON REGULARY BASIS?", "No", "Yes"},
    {"7. HAVE YOU EVER BEEN FOUND TO HAVE HIGH BLOOD GLUCOSE?", "No", "Yes"},
    {"8. HAVE ANY OF THE MEMBERS OF YOUR IMMEDIATE FAMILY BEEN DIAGNOSED WITH DIABETES TYPE 1 OR 2?", 
     "No", "Yes: grandparent, aunt, uncle, first cousin (but no own parent, sister, brother or child)", 
     "Yes: own parent, sister, brother or child"}
  };
  int questionary_col_index[] = {3, 2, 2, 1, 1, 1, 1, 2};
  int score_table[8][4] = 
  {
    {0, 2, 3, 4},
    {0, 1, 3},
    {0, 3, 4},
    {0, 2},
    {0, 1},
    {0, 2},
    {0, 5},
    {0, 3, 5}
  };
  for(int i = 0; i < 8; i ++) {
    for(int j = 0; j < questionary_col_index[i] + 2; j ++) {
      if(j > 0) Serial.print(a_to_d[j - 1]);
      Serial.println(questionary[i][j]);
    }
    Serial.println("");
    while(1) {
      user_input();
      if(incomingLetter == 'a') {
        score += score_table[i][0];
        reset_input();
        break;
      }
      if(incomingLetter == 'b') {
        score += score_table[i][1];
        reset_input();
        break;
      }
      if(questionary_col_index[i] > 1 && incomingLetter == 'c') {
        score += score_table[i][2];
        reset_input();
        break;
      }
      if(questionary_col_index[i] > 2 && incomingLetter == 'd') {
        score += score_table[i][3];
        reset_input();
        break;
      }
    } 
  } 
  char * risk_assessment[] = 
  {
    "estimated ",
    "LOW:",
    "1 in 100",
    "SLIGHTLY ELEVATED:",
    "1 in 25",
    "MODERATE:",
    "1 in 6",
    "HIGH:",
    "1 in 3",
    "VERY HIGH:",
    "1 in 2"
  };
  Serial.print("THE RISK OF DEVELOPING TYPE 2 DIABETES WITHIN 10 YEARS IS ");
  if(score < 7) {
    Serial.println(risk_assessment[1]);
    Serial.print(risk_assessment[0]);
    Serial.print(risk_assessment[2]);
  }
  if(score > 6 && score < 12) {
    Serial.println(risk_assessment[3]);
    Serial.print(risk_assessment[0]);
    Serial.print(risk_assessment[4]);
  }
  if(score > 11 && score < 15) {
    Serial.println(risk_assessment[5]);
    Serial.print(risk_assessment[0]);
    Serial.print(risk_assessment[6]);
  }
  if(score > 14 && score < 21) {
    Serial.println(risk_assessment[7]);
    Serial.print(risk_assessment[0]);
    Serial.print(risk_assessment[8]);
  }
  if(score > 20) {
    Serial.println(risk_assessment[9]);
    Serial.print(risk_assessment[0]);
    Serial.print(risk_assessment[10]);
  }
  Serial.println(" will develope disease");
  Serial.println("");
}

void user_input() {
  if(Serial.available()) {
    delay(50);
    while(Serial.available()) {
      incomingLetter = Serial.read();
    }
  }
}

void reset_input() {
  incomingLetter = ' ';
}

Discussions