Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
2.1 kB
1
Indexable
Never
class Patient:
    def __init__(self, id, name, disease, date):
        self.id = id
        self.name = name
        self.disease = disease
        self.date = date

    def __str__(self):
        return f'Patient ID: {self.id} \nName: {self.name} \nDisease: {self.disease} \nDate: {self.date}\n'

class Hospital:
    def __init__(self, name):
        self.name = name
        self.patients = []
        self.last_id = 0

    def add_patient(self, name, disease, date):
        self.last_id += 1
        patient = Patient(self.last_id, name, disease, date)
        self.patients.append(patient)

    def display_patients(self):
        for patient in self.patients:
            print(patient)

    def get_patient(self, id):
        for patient in self.patients:
            if patient.id == id:
                return patient

    def delete_patient(self, id):
        for patient in self.patients:
            if patient.id == id:
                self.patients.remove(patient)
                print(f'Patient, id: {patient.id} - Name: {patient.name} deleted.\n')

    def update_patient(self, id, disease, new_id=None):
        patient = self.get_patient(id)
        if patient == None:
            print('Patient not found.\n')
            return None
        patient.disease = disease
        if new_id and self.get_patient(new_id)==None:
            patient.id = new_id
            self.last_id = max(self.last_id, new_id)

if __name__ == '__main__':
    hospital = Hospital("Blue Delta Hospital")
    hospital.add_patient('Saadman', 'Cancer', '12/12/2022')
    hospital.add_patient('Arban', 'Cancer', '13/12/2022')
    hospital.add_patient('Shetu', 'Cancer', '7/12/2022')
    hospital.add_patient('Ettasham', 'Cancer', '22/12/2022')

    hospital.display_patients()
    print('-------------------------')
    print(hospital.get_patient(2))
    print('-------------------------')
    hospital.delete_patient(2)
    hospital.display_patients()
    print('-------------------------')
    hospital.update_patient(3, 'Fever', 5)
    hospital.display_patients()