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:
- Do you think this could be done with other pattern?
- Is the chain of responsibility pattern acceptable for this?
- 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:
- F: Fever
- H: Healthy
- D: Diabetes
- 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:
- As: Aspirin
- An: Antibiotic
- Insulin
- 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:
- Aspirin cures Fever;
- Antibiotic cures Tuberculosis;
- A sick patient not receiving the right medicines remains sick, if not explicitly mentioned otherwise;
- Insulin prevents diabetic subject from dying, does not cure Diabetes;
- If insulin is mixed with antibiotic, healthy people catch Fever;
- Paracetamol cures Fever;
- 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