diff --git a/cohorts.py b/cohorts.py new file mode 100644 index 0000000000000000000000000000000000000000..fc20f7c853a9002677546780300f876c8980e823 --- /dev/null +++ b/cohorts.py @@ -0,0 +1,50 @@ +class Patient(object): + def __init__(self, name, region, age): + self.name = name + self.region = region + self.age = age + + def __repr__(self): + return f'Person({repr(self.name)}, {repr(self.region)}, {repr(self.age)})' + + +class Cohort(object): + def includes(self, patient): + raise NotImplementedError('The Cohort class\'s includes method must be overridden to be called.') + + def filter(self, patients): + result = [] + for patient in patients: + if self.includes(patient): + result.append(patient) + return result + + +class RegionalCohort(Cohort): + def __init__(self, region): + self.region = region + + def includes(self, patient): + return patient.region == self.region + + +class AgeCohort(Cohort): + def __init__(self, minimum, maximum): + self.minimum = minimum + self.maximum = maximum + + def includes(self, patient): + return self.minimum <= patient.age <= self.maximum + + +if __name__ == '__main__': + ada = Patient('Ada', 'UK', 203) + charles = Patient('Charles', 'UK', 227) + grace = Patient('Grace', 'US', 112) + patients = [ada, charles, grace] + uk_cohort: Cohort = RegionalCohort('UK') + young_cohort: Cohort = AgeCohort(0, 225) + print(f'Charles is in the UK region: {uk_cohort.includes(charles)}') + print(f'Charles is in the "young" age group: {young_cohort.includes(charles)}') + print(f'Everyone in the UK region: {uk_cohort.filter(patients)}') + print(f'Everyone in the "young" age group: {young_cohort.filter(patients)}') diff --git a/notes.py b/notes.py new file mode 100644 index 0000000000000000000000000000000000000000..a4b123e5e7ebd16bfa45f2f47a9c1cf734653989 --- /dev/null +++ b/notes.py @@ -0,0 +1,29 @@ +class Visit(object): + def __init__(self): + self.notes = [] + + def add_note(self, note): + self.notes.append(note) + + +class Appointment(object): + def __init__(self): + self.note = None + + def add_note(self, note): + self.note = note + + +def void(event): + event.add_note('Voided.') + + +if __name__ == '__main__': + visit = Visit() + appointment = Appointment() + number = 7 + void(visit) + print(visit.notes) + void(appointment) + print(appointment.note) + void(number) diff --git a/person_patient.py b/person_patient.py index 783f2884334ea05b24b591a0c6cd6a745d689556..a909d3afa1054c1677f860f5e004022b335f6b90 100644 --- a/person_patient.py +++ b/person_patient.py @@ -9,6 +9,9 @@ class Patient(Person): if __name__ == '__main__': - print(object()) - print(Person()) - print(Patient()) + example_object: object = object() + example_person: object = Person() + example_patient: object = Patient() + print(example_object) + print(example_person) + print(example_patient)