How can I print the object and not the memory location to my list. I also added a patient Id generator to generator a patient records number for each patient that is created. It’s also shows as a memory location. Any advice on this or any of my code is welcome. Like do I need to have a default value of none for all my class variables in init?
master_patient_list = []
current_patient_list = []
iso_patient_list = []
iso_type_dict = {'covid': 'droplets', 'cdiff': 'contact', 'tuberculosis': 'airborne', 'influenza': 'droplets', 'reverse isolation': 'patient saftey'}
def count_patients(list):
return len(list)
class Patient (object):
def __init__(self, name='', age=None, room_number=None, assigned_doctor=None, assigned_nurse=None, illness=None, iso_status=None, patient_record_nunber=None,patient_medications=[]):
self.name = name
self.age = age
self.room_number = room_number
self.assigned_doctor = assigned_doctor
self.assigned_nurse = assigned_nurse
self.illness = illness
self.iso_status = iso_type_dict
self.patient_record_number = self.patient_id_gen()
self.patient_medications = list(patient_medications)
self.add_patient()
def add_patient(self):
master_patient_list.append(self)
current_patient_list.append(self)
def remove_patient():
pass
def move_patient(self, new_room):
self.room_number = new_room
def add_med(self, med):
if med not in self.patient_medications:
self.patient_medications.append(med)
def remove_med(self, med):
if med in self.patient_medications:
self.patient_medications.remove(med)
#generates patine records numbers
def patient_id_gen(self):
''' generates patient id one at a time as patient object is created '''
first_digit = 0
second_digit = 0
third_digit = 0
for i in range(201):
final_num = f'AD{third_digit}{second_digit}{first_digit}'
#print(final_num)
if first_digit < 10:
first_digit += 1
if first_digit == 10:
first_digit = 0
second_digit += 1
if second_digit == 10:
second_digit = 0
third_digit += 1
yield final_num
def __str__(self):
return f'Room: {self.room_number} \nName: {self.name} \nPhysician: {self.assigned_doctor} \nNurse: {self.assigned_nurse} \nIllness: {self.illness} \nIso status: {self.iso_status} \nPRN: {self.patient_record_number} \nMedication: {self.patient_medications}'
#patient info
patient1 = Patient()
patient1.name = 'Sally'
patient1.age = 35
patient1.room_number = 430
patient1.assigned_doctor = 'Dr. Seuss'
patient1.assigned_nurse = 'Jessica'
patient1.illness = 'Broken Leg'
patient1.iso_status = 'NONE'
#patient1.patient_reord_number = 'AD123456789'
patient1.add_med('norco')
patient2 = Patient()
patient2.name = 'Labrone'
patient2.age = 40
patient2.room_number = 46208
patient2.assigned_doctor = 'Dr. Patel'
patient2.assigned_nurse = 'Melissa'
patient2.illness = 'Broken Heart'
patient2.iso_status = '5150'
patient2.patient_record_number
patient2.add_med('norco')
#test code
print(patient1)
print()
print(patient2)
print()
print(f'Master list: \n{master_patient_list}')
print()
print(f'Current list: \n{current_patient_list}')
Here’s the output...
Room: 430
Name: Sally
Physician: Dr. Seuss
Nurse: Jessica
Illness: Broken Leg
Iso status: NONE
PRN:
Medication: ['norco']
Room: 46208
Name: Labrone
Physician: Dr. Patel
Nurse: Melissa
Illness: Broken Heart
Iso status: 5150
PRN:
Medication: ['norco']
Master list:
[<main.Patient object at 0x1154d8438>, <main.Patient object at 0x1154d86a0>]
Current list:
[<main.Patient object at 0x1154d8438>, <main.Patient object at 0x1154d86a0>]