I have a class "patient":
class patient:
all_patients = []
def __init__(self, pat_id):
self.pat_id=pat_id
self.plans=[]
patient.all_patients.append(self)
I have to go through a log file with all therapy plans of all patients and I want to add each therapy plan to the correct patient.
My approach was this: (index is the current line of the log file)
if not any (x.pat_id == index[4] for x in patients):
patients.append(patient(index[4]))
for pat in patient.all_patients:
if (pat.pat_id == index[4]):
if (index[11] not in pat.plans):
total_plans+=1
pat.plans.append(index[11])
print(len(patient.all_patients))
print(total_plans)
i think it return the right numbers, but i do not think that it is a very efficient way to do so. The log files are huge and all plans are several times (for each appointment once) in the log files.
Can you help me please to optimize this code?