-
Notifications
You must be signed in to change notification settings - Fork 4
/
report.py
57 lines (41 loc) · 1.9 KB
/
report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from datetime import datetime
class Report:
@staticmethod
def __generate_report(all_terms: []) -> {}:
terms = []
overall_count = 0
for term in all_terms:
visits_in_clinics = Report.__group_visits_by_clinic(term)
date = term["date"]
count = len(term["visits"])
term = {"date": date, "count": count, "visits": term["visits"], "visits_in_clinics": visits_in_clinics}
terms.append(term)
overall_count += count
return {"overall_count": overall_count, "terms": terms}
@staticmethod
def __group_visits_by_clinic(visits: []) -> []:
visits_in_clinics = []
raw_grouped_visits = {}
for visit in visits["visits"]:
clinic_name = visit["clinic_name"]
raw_grouped_visits[clinic_name] = raw_grouped_visits.get(clinic_name, [])
raw_grouped_visits[clinic_name].append(visit)
for clinic_name in raw_grouped_visits:
old_visit_definitions = raw_grouped_visits[clinic_name]
new_visits_definitions = []
for definition in old_visit_definitions:
doctor_name = definition["doctor_name"]
time = definition["time"]
visit_details = {"doctor_name": doctor_name, "time": time}
new_visits_definitions.append(visit_details)
visits_in_clinic_count = len(new_visits_definitions)
visit_details = {"clinic_name": clinic_name, "count": visits_in_clinic_count,
"visits": new_visits_definitions}
visits_in_clinics.append(visit_details)
return visits_in_clinics
def __init__(self, all_terms):
self._report = Report.__generate_report(all_terms)
def get_report(self) -> {}:
return self._report
def is_any_visit_available(self) -> bool:
return self._report["overall_count"] > 0