/**
 * Created by Tomasz Gabrysiak @ Infermedica on 03/02/2017.
 */

import _ from 'lodash';

export default class Patient {
  constructor () {
    this.symptoms = {};
    this.sex = 'male';
    this.age = 30;
  }

  setSex (sex) {
    this.sex = sex;
  }

  setAge (age) {
    this.age = age;
  }

  addSymptomsGroup (group) {
    Object.assign(this.symptoms, group);
  }

  removeSymptom (id) {
    delete this.symptoms[id];
  }

  toDiagnosis () {
    let res = {
      sex: this.sex,
      age: this.age,
      evidence: []
    };
    res.evidence = _.map(this.symptoms, (v, k) => {
      const choice = (c) => {
        if (c === true) {
          return 'present';
        }
        if (_.isUndefined(c)) {
          return 'unknown';
        }
        if (c === false) {
          return 'absent';
        }
      };

      let e = {
        id: k,
        choice_id: choice(v.reported)
      };

      if (v.initial) {
        Object.assign(e, {
          initial: true
        });
      }

      if (v.related) {
        Object.assign(e, {
          related: true
        });
      }

      return e;
    });
    return res;
  }

  toSuggest () {
    return {
      sex: this.sex,
      age: this.age,
      selected: _.filter(_.keys(this.symptoms), (key) => {
        return this.symptoms[key].reported === true;
      })
    };
  }

  reset () {
    this.symptoms = {};
  }
}

@@ -528,16 +528,17 @@
 %0A    %7D;%0A
+%0A
     res.
@@ -574,12 +574,26 @@
 s, (
-v, k
+symptom, symptomId
 ) =%3E
@@ -611,19 +611,29 @@
 nst 
-c
+getC
 hoice
+Id
  = (c
+hoice
 ) =%3E
@@ -644,24 +644,29 @@
        if (c
+hoice
  === true) %7B
@@ -731,16 +731,21 @@
 efined(c
+hoice
 )) %7B%0A   
@@ -792,16 +792,21 @@
    if (c
+hoice
  === fal
@@ -868,17 +868,32 @@
     let 
-e
+diagnosisSymptom
  = %7B%0A   
@@ -901,17 +901,25 @@
     id: 
-k
+symptomId
 ,%0A      
@@ -935,16 +935,27 @@
 id: 
-c
+getC
 hoice
-(v
+Id(symptom
 .rep
@@ -981,17 +981,23 @@
     if (
-v
+symptom
 .initial
@@ -1014,33 +1014,48 @@
   Object.assign(
-e
+diagnosisSymptom
 , %7B%0A          in
@@ -1097,17 +1097,23 @@
     if (
-v
+symptom
 .related
@@ -1138,17 +1138,32 @@
 .assign(
-e
+diagnosisSymptom
 , %7B%0A    
@@ -1216,17 +1216,32 @@
  return 
-e
+diagnosisSymptom
 ;%0A    %7D)

Change variable names