Appropriate design pattern for developing rules and outcomes

by Andre Garcia   Last Updated September 12, 2019 00:05 AM

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.

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;


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.


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)

Related Questions

Design patterns for machine learning as a service?

Updated August 11, 2019 10:05 AM

Using singletons in Python (Django)

Updated November 15, 2016 08:02 AM

Global request context - anti-pattern?

Updated December 13, 2016 08:02 AM