diff --git a/arztapi/APIHandler.py b/arztapi/APIHandler.py index 28575d2..1d08127 100644 --- a/arztapi/APIHandler.py +++ b/arztapi/APIHandler.py @@ -144,6 +144,8 @@ class APIHandler: for phone_time in doctor_information.telefonzeiten: doctor_phone_time_dict = { "phone_time": phone_time, + # workaround until properly assigned in sort + "doctor_nr": 0, "doctor_name": doctor_information.name, "doctor_address": f"{doctor_information.plz} {doctor_information.ort} " f"{doctor_information.strasse} {doctor_information.hausnummer}", @@ -151,7 +153,20 @@ class APIHandler: } doctor_phone_time = DoctorPhoneTime(**doctor_phone_time_dict) doctor_phone_times.append(doctor_phone_time) - return sorted(doctor_phone_times, key=lambda dpt: dpt.phone_time.start) + + doctor_phone_times.sort(key=lambda dpt: dpt.phone_time.start) + known_doctor_names_with_nr= {} + doctor_count = 1 + for doctor_phone_time in doctor_phone_times: + if doctor_phone_time.doctor_name not in known_doctor_names_with_nr: + doctor_phone_time.doctor_nr = doctor_count + known_doctor_names_with_nr[doctor_phone_time.doctor_name] = doctor_count + doctor_count += 1 + else: + known_doctor_count = known_doctor_names_with_nr[doctor_phone_time.doctor_name] + doctor_phone_time.doctor_nr = known_doctor_count + + return doctor_phone_times @staticmethod def calculate_req_value_base64(lat, lon): diff --git a/arztapi/DoctorInformation.py b/arztapi/DoctorInformation.py index 39dbe48..6bedbe4 100644 --- a/arztapi/DoctorInformation.py +++ b/arztapi/DoctorInformation.py @@ -10,6 +10,7 @@ class PhoneTime(BaseModel): class DoctorInformation(BaseModel): + nr: Optional[int] = 0 name: str tel: str fax: Optional[str] = None diff --git a/arztapi/DoctorPhoneTime.py b/arztapi/DoctorPhoneTime.py index 493bca0..2b1c2d1 100644 --- a/arztapi/DoctorPhoneTime.py +++ b/arztapi/DoctorPhoneTime.py @@ -4,6 +4,7 @@ from arztapi.DoctorInformation import PhoneTime class DoctorPhoneTime(BaseModel): phone_time: PhoneTime + doctor_nr: int doctor_name: str doctor_address: str doctor_phone_number: str diff --git a/templates/index.html b/templates/index.html index 17682ff..ddd0a41 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,7 +10,7 @@ Suche
- {{ form.location(class="form-control", id="locationInput", placeholder="Standort eingeben") }} + {{ form.location(class="form-control", id="locationInput", placeholder="Standort/PLZ eingeben") }} {% if form.location.errors %}
{{ form.location.errors[0] }} diff --git a/templates/result.html b/templates/result.html index 35f2d8f..358f8e8 100644 --- a/templates/result.html +++ b/templates/result.html @@ -8,6 +8,7 @@ + @@ -18,6 +19,7 @@ {% for doctor in doctors %} +
Index Name Nächster Telefontag Nächste Telefonzeit
{{ doctor.doctor_nr }} {{ doctor.doctor_name }} {{ doctor.phone_time.start.strftime("%A %d.%m") }} {{ doctor.phone_time.start.strftime("%H:%M") }} bis {{ doctor.phone_time.end.strftime("%H:%M") }}