mercredi 11 septembre 2019

Appropriate design pattern for developing rules and outcomes

In the exercice i´m developing bellow, i´m applying the chain of responsibility pattern. The pattern works correctly but i don´t think it's the best approach. I think the rule design pattern should be a better fit but there´s no much good examples about it using python.

This is the example im working on: https://www.codepile.net/pile/lg53nPdr

My questions for you are:

  1. Do you think this could be done with other pattern?
  2. Is the chain of responsibility pattern acceptable for this?
  3. Should i study the Rule design (in other languages if i have to) to apply in python?

The exercice is the following:

Supose you have Patients with health conditions such as:

  1. F: Fever
  2. H: Healthy
  3. D: Diabetes
  4. T: Tuberculosis

In this exercice drugs are provided to all patients. It is not possible to target a specific patient. This is the list of available drugs:

  1. As: Aspirin
  2. An: Antibiotic
  3. Insulin
  4. Paracetamol

Drugs can change patients’ states. They can cure, cause side effects or even kill a patient if not properly prescribed. Drugs effects are described by the following rules:

  1. Aspirin cures Fever;
  2. Antibiotic cures Tuberculosis;
  3. A sick patient not receiving the right medicines remains sick, if not explicitly mentioned otherwise;
  4. Insulin prevents diabetic subject from dying, does not cure Diabetes;
  5. If insulin is mixed with antibiotic, healthy people catch Fever;
  6. Paracetamol cures Fever;
  7. Paracetamol kills subject if mixed with aspirin;

Input

Parameter 1

List of patients' health status codes, separated by a comma. e.g. “D,F,F” means we have 3 patients, one with diabetes and two with fever.

Parameter 2

List of drugs codes, separated by a comma, e.g. “As,I” means patients will be treated with Aspirin and Insulin.

Output

The result should be sent to stdout. It should be a comma separated string with number of patients with a given state, following the format: F:NP,H:NP,D:NP,T:NP,X:NP (NP:number of people)

Aucun commentaire:

Enregistrer un commentaire