def get_score_for_patient(p): total = 0 count = 0 for m in Medicine.objects.filter(treatments__patient=p).distinct(): r = RecurringTreatment.objects.get(patient = p, medicine = m) pt = PillTaken.objects.filter(patient = p, medicine = m) s = Score() total = total + s.translate(r, pt) count = count + 1 total = ceil(total / count)if count > 0 else 0 return total