Level 2 : Project 8


We want to develop software to computerize the care pathway in a hospital. A programmer wrote the following code, but had to stop its development.


enum Disease {

  // assume that all diseases are listed here

  Stroke,

  Traacbea,

  Alzheimer,

  Tuberculosis,

  Cirrhosis

}

 

class Diagnostic {

  String caregiver;

  DateTime date;

  Disease disease;

  int validity; //diagnostic reliability, between 0 and 100%

  Diagnostic(this.caregiver, this.date, this.disease, this.validity);

}



Patients must be represented in the software, with their last name, first name, date of birth, sex and the medical acts they have undergone.

These acts can be Diagnostic or Treatment. A treatment is performed by a nursing staff, at a certain date and produces a certain improvement in the patient's condition (in percentage).

Note:

We can represent dates with the DateTime class. It must be possible to retrieve the age of a patient and add a medical procedure.

1) Propose object code to represent patients and acts (we have the right to modify the Diagnosis class).

Among all the possible treatments, there is the taking of medications, with a dosage (whole quantity) and a frequency (number of times the drug is taken per day).

2) Suggest object code to represent medication taken. Add a method of knowing how much medication a patient should take per day




Solution:


enum Disease {

  // assume that all diseases are listed here

  Stroke,

  Traacbea,

  Alzheimer,

  Tuberculosis,

  Cirrhosis

}

enum Sex { MaleFemale }

 

class Act {

  String _caregiver;

  DateTime _date;

  Act(this._caregiver, this._date);

}

 

class Diagnostic extends Act {

  Disease _disease;

  int _validity; //between 0 and 100 %

  Diagnostic(String cg, DateTime d, Disease ds, int v) : super(cg, d) {

    _disease = ds;

    _validity = v;

  }

}

 

class Treatment extends Act {

  int _improvement; //improvement rate between 0 and 100%

  Treatment(String cg, DateTime d, int a) : super(cg, d) {

    _improvement = a;

  }

}

 

class Patient {

  String _firstName, _lastName;

  DateTime _birthDay;

  Sex _sex;

  List<Act> _acts;

  Patient(

      this._firstName, this._lastName, this._birthDay, this._sex, this._acts);

  int getAge() {

    return (DateTime.now().difference(_birthDay).inDays) ~/ 365;

  }

 

  void addAct(Act a) {

    this._acts.add(a);

  }

 

  int nbMedDaily() {

    int n = 0;

    for (var a in _acts) {

      if (a.runtimeType == Medication) {

        Medication aux = a;

        n += aux._frequency;

      }

    }

    return n;

  }

}

 

class Medication extends Treatment {

  int _dosage, _frequency;

  Medication(String cg, DateTime d, int a, int dos, int f) : super(cg, d, a) {

    _dosage = dos;

    _frequency = f;

  }

}

 

void main() {

  var p1 = Patient("Velvel""Adalwin"DateTime(1980423), Sex.Male, [

    Diagnostic("Barrfind Piripi"DateTime(20201203), Disease.Stroke98),

    Treatment("Qillaq Ingo"DateTime(20210315), 70)

  ]);

  print(p1.getAge());

  print(p1.nbMedDaily());

  p1.addAct(Medication("Gohar Hamlet"DateTime(20210511), 5023));

  print(p1.nbMedDaily());

  p1.addAct(Medication("Ani Rouben"DateTime(2021072), 2012));

  print(p1.nbMedDaily());

}



40
0
3
5