Add week filter and already passed times today
This commit is contained in:
parent
9291018b3e
commit
50271d1607
7
app.py
7
app.py
@ -1,6 +1,6 @@
|
|||||||
import locale
|
import locale
|
||||||
|
|
||||||
from flask import Flask, render_template, request
|
from flask import Flask, render_template, request, redirect
|
||||||
|
|
||||||
from forms.SearchForm import SearchForm
|
from forms.SearchForm import SearchForm
|
||||||
from arztapi.APIHandler import APIHandler
|
from arztapi.APIHandler import APIHandler
|
||||||
@ -25,15 +25,18 @@ def search_for_doctors_with_params():
|
|||||||
therapy_types = search_form.therapy_type.data
|
therapy_types = search_form.therapy_type.data
|
||||||
therapy_age_range = search_form.therapy_age_range.data
|
therapy_age_range = search_form.therapy_age_range.data
|
||||||
therapy_setting = search_form.therapy_setting.data
|
therapy_setting = search_form.therapy_setting.data
|
||||||
|
amount_of_weeks = search_form.amount_of_weeks.data
|
||||||
|
|
||||||
print(f"Location: {location}")
|
print(f"Location: {location}")
|
||||||
print(f"Distance: {distance}")
|
print(f"Distance: {distance}")
|
||||||
print(f"Therapy Types: {therapy_types}")
|
print(f"Therapy Types: {therapy_types}")
|
||||||
print(f"Age Range: {therapy_age_range}")
|
print(f"Age Range: {therapy_age_range}")
|
||||||
print(f"Therapy Setting: {therapy_setting}")
|
print(f"Therapy Setting: {therapy_setting}")
|
||||||
|
print(f"Therapy Phone Types: {amount_of_weeks}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(search_form.errors)
|
print(search_form.errors)
|
||||||
|
return redirect("/")
|
||||||
|
|
||||||
api_handler = APIHandler()
|
api_handler = APIHandler()
|
||||||
locations = api_handler.get_lat_lon_location_list(location)[0]
|
locations = api_handler.get_lat_lon_location_list(location)[0]
|
||||||
@ -42,7 +45,7 @@ def search_for_doctors_with_params():
|
|||||||
therapy_age_range, therapy_setting)
|
therapy_age_range, therapy_setting)
|
||||||
api_handler.get_general_doctor_information()
|
api_handler.get_general_doctor_information()
|
||||||
api_handler.filter_doctor_information_for_distance(distance*1000)
|
api_handler.filter_doctor_information_for_distance(distance*1000)
|
||||||
sorted_doctor_phone_times = api_handler.get_doctor_phone_times_sorted()
|
sorted_doctor_phone_times = api_handler.get_doctor_phone_times_sorted(amount_of_weeks)
|
||||||
|
|
||||||
return render_template("result.html", doctors=sorted_doctor_phone_times)
|
return render_template("result.html", doctors=sorted_doctor_phone_times)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ from typing import List
|
|||||||
import requests
|
import requests
|
||||||
from requests import JSONDecodeError
|
from requests import JSONDecodeError
|
||||||
import base64
|
import base64
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from arztapi.ArztPraxisDatas import ArztPraxisDatas
|
from arztapi.ArztPraxisDatas import ArztPraxisDatas
|
||||||
from arztapi.DoctorInformation import DoctorInformation, PhoneTime
|
from arztapi.DoctorInformation import DoctorInformation, PhoneTime
|
||||||
from arztapi.DoctorPhoneTime import DoctorPhoneTime
|
from arztapi.DoctorPhoneTime import DoctorPhoneTime
|
||||||
@ -14,6 +14,7 @@ class APIHandler:
|
|||||||
self.base_api_url = "https://arztsuche.116117.de/api/"
|
self.base_api_url = "https://arztsuche.116117.de/api/"
|
||||||
self.phone_times = []
|
self.phone_times = []
|
||||||
self.general_information = []
|
self.general_information = []
|
||||||
|
self.processed_doctor_phone_times = []
|
||||||
|
|
||||||
def get_lat_lon_location_list(self, location):
|
def get_lat_lon_location_list(self, location):
|
||||||
api_path = self.base_api_url + "location"
|
api_path = self.base_api_url + "location"
|
||||||
@ -138,8 +139,7 @@ class APIHandler:
|
|||||||
self.general_information = [doctor_information for doctor_information in self.general_information
|
self.general_information = [doctor_information for doctor_information in self.general_information
|
||||||
if doctor_information.distance <= distance]
|
if doctor_information.distance <= distance]
|
||||||
|
|
||||||
def get_doctor_phone_times_sorted(self):
|
def get_doctor_phone_times_sorted(self, therapy_phone_weeks):
|
||||||
doctor_phone_times = []
|
|
||||||
for doctor_information in self.general_information:
|
for doctor_information in self.general_information:
|
||||||
for phone_time in doctor_information.telefonzeiten:
|
for phone_time in doctor_information.telefonzeiten:
|
||||||
doctor_phone_time_dict = {
|
doctor_phone_time_dict = {
|
||||||
@ -152,12 +152,32 @@ class APIHandler:
|
|||||||
"doctor_phone_number": doctor_information.tel
|
"doctor_phone_number": doctor_information.tel
|
||||||
}
|
}
|
||||||
doctor_phone_time = DoctorPhoneTime(**doctor_phone_time_dict)
|
doctor_phone_time = DoctorPhoneTime(**doctor_phone_time_dict)
|
||||||
doctor_phone_times.append(doctor_phone_time)
|
self.processed_doctor_phone_times.append(doctor_phone_time)
|
||||||
|
|
||||||
doctor_phone_times.sort(key=lambda dpt: dpt.phone_time.start)
|
self.filter_for_relevant_weeks(therapy_phone_weeks)
|
||||||
known_doctor_names_with_nr= {}
|
self.processed_doctor_phone_times.sort(key=lambda dpt: dpt.phone_time.start)
|
||||||
|
self.filter_for_already_passed_times_today()
|
||||||
|
self.assign_numbers_to_doctor_phone_times()
|
||||||
|
|
||||||
|
return self.processed_doctor_phone_times
|
||||||
|
|
||||||
|
def filter_for_relevant_weeks(self, therapy_phone_weeks):
|
||||||
|
current_date = datetime.now()
|
||||||
|
end_date = current_date + timedelta(weeks=therapy_phone_weeks)
|
||||||
|
self.processed_doctor_phone_times = [dpt for dpt in self.processed_doctor_phone_times
|
||||||
|
if current_date <= dpt.phone_time.start <= end_date]
|
||||||
|
|
||||||
|
def filter_for_already_passed_times_today(self):
|
||||||
|
current_datetime = datetime.now()
|
||||||
|
self.processed_doctor_phone_times = [dpt for dpt in self.processed_doctor_phone_times
|
||||||
|
if (dpt.phone_time.start.date() == current_datetime.date() and
|
||||||
|
dpt.phone_time.end > current_datetime)
|
||||||
|
or dpt.phone_time.start.date() != current_datetime.date()]
|
||||||
|
|
||||||
|
def assign_numbers_to_doctor_phone_times(self):
|
||||||
|
known_doctor_names_with_nr = {}
|
||||||
doctor_count = 1
|
doctor_count = 1
|
||||||
for doctor_phone_time in doctor_phone_times:
|
for doctor_phone_time in self.processed_doctor_phone_times:
|
||||||
if doctor_phone_time.doctor_name not in known_doctor_names_with_nr:
|
if doctor_phone_time.doctor_name not in known_doctor_names_with_nr:
|
||||||
doctor_phone_time.doctor_nr = doctor_count
|
doctor_phone_time.doctor_nr = doctor_count
|
||||||
known_doctor_names_with_nr[doctor_phone_time.doctor_name] = doctor_count
|
known_doctor_names_with_nr[doctor_phone_time.doctor_name] = doctor_count
|
||||||
@ -166,8 +186,6 @@ class APIHandler:
|
|||||||
known_doctor_count = known_doctor_names_with_nr[doctor_phone_time.doctor_name]
|
known_doctor_count = known_doctor_names_with_nr[doctor_phone_time.doctor_name]
|
||||||
doctor_phone_time.doctor_nr = known_doctor_count
|
doctor_phone_time.doctor_nr = known_doctor_count
|
||||||
|
|
||||||
return doctor_phone_times
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def calculate_req_value_base64(lat, lon):
|
def calculate_req_value_base64(lat, lon):
|
||||||
"""
|
"""
|
||||||
|
@ -10,13 +10,21 @@ def validate_therapy_types(form, field):
|
|||||||
raise validators.ValidationError("Invalid value in therapy types selection.")
|
raise validators.ValidationError("Invalid value in therapy types selection.")
|
||||||
|
|
||||||
|
|
||||||
|
def validate_therapy_phone_times(form, field):
|
||||||
|
valid_choices = {1, 2, 3, 4}
|
||||||
|
if not field.data:
|
||||||
|
raise validators.ValidationError("Please select at least one option.")
|
||||||
|
if not all(choice in valid_choices for choice in field.data):
|
||||||
|
raise validators.ValidationError("Invalid value in therapy phone types selection.")
|
||||||
|
|
||||||
|
|
||||||
class RangeInput(Input):
|
class RangeInput(Input):
|
||||||
input_type = "range"
|
input_type = "range"
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(Form):
|
class SearchForm(Form):
|
||||||
location = StringField("Standort", validators=[validators.InputRequired(), validators.Length(min=2, max=50),
|
location = StringField("Standort/PLZ", validators=[validators.InputRequired(), validators.Length(min=2, max=50),
|
||||||
validators.Regexp("^[a-zA-ZäöüßÄÖÜẞ]+$")])
|
validators.Regexp("^[a-zA-ZäöüßÄÖÜẞ]+$")])
|
||||||
therapy_distance = IntegerField(
|
therapy_distance = IntegerField(
|
||||||
"Distanz (in km)",
|
"Distanz (in km)",
|
||||||
widget=RangeInput(),
|
widget=RangeInput(),
|
||||||
@ -35,5 +43,10 @@ class SearchForm(Form):
|
|||||||
therapy_setting = RadioField("Therapiesetting", choices=[
|
therapy_setting = RadioField("Therapiesetting", choices=[
|
||||||
("E", "Einzeltherapie"),
|
("E", "Einzeltherapie"),
|
||||||
("G", "Gruppentherapie")], validators=[validators.InputRequired(), validators.any_of(["E", "G"])])
|
("G", "Gruppentherapie")], validators=[validators.InputRequired(), validators.any_of(["E", "G"])])
|
||||||
|
# TODO: find a better name for label
|
||||||
|
amount_of_weeks = IntegerField(
|
||||||
|
"Telefonzeiten für die nächsten Wochen",
|
||||||
|
widget=RangeInput(),
|
||||||
|
default=1,
|
||||||
|
validators=[validators.InputRequired(), validators.NumberRange(min=1, max=4)]
|
||||||
|
)
|
@ -8,7 +8,7 @@
|
|||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Suche</legend>
|
<legend>Suche</legend>
|
||||||
<div class="mb-3">
|
<div class="mb-2">
|
||||||
<label for="locationInput" class="form-label mt-4">{{ form.location.label }}</label>
|
<label for="locationInput" class="form-label mt-4">{{ form.location.label }}</label>
|
||||||
{{ form.location(class="form-control", id="locationInput", placeholder="Standort/PLZ eingeben") }}
|
{{ form.location(class="form-control", id="locationInput", placeholder="Standort/PLZ eingeben") }}
|
||||||
{% if form.location.errors %}
|
{% if form.location.errors %}
|
||||||
@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="mt-4">
|
<div class="mt-2">
|
||||||
<label for="distanceRange" class="form-label">{{ form.therapy_distance.label }}</label>
|
<label for="distanceRange" class="form-label">{{ form.therapy_distance.label }}</label>
|
||||||
{{ form.therapy_distance(class="form-range", id="distanceRange", min=0, max=50, step=1, oninput="this.nextElementSibling.value = this.value") }}
|
{{ form.therapy_distance(class="form-range", id="distanceRange", min=0, max=50, step=1, oninput="this.nextElementSibling.value = this.value") }}
|
||||||
<output>{{ form.therapy_distance.data or 25 }}</output>
|
<output>{{ form.therapy_distance.data or 25 }}</output>
|
||||||
@ -31,7 +31,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-2">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend class="mt-4">{{ form.therapy_type.label }}</legend>
|
<legend class="mt-4">{{ form.therapy_type.label }}</legend>
|
||||||
{% for subfield in form.therapy_type %}
|
{% for subfield in form.therapy_type %}
|
||||||
@ -50,7 +50,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-2">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend class="mt-4">{{ form.therapy_age_range.label }}</legend>
|
<legend class="mt-4">{{ form.therapy_age_range.label }}</legend>
|
||||||
{% for subfield in form.therapy_age_range %}
|
{% for subfield in form.therapy_age_range %}
|
||||||
@ -69,7 +69,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-2">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend class="mt-4">{{ form.therapy_setting.label }}</legend>
|
<legend class="mt-4">{{ form.therapy_setting.label }}</legend>
|
||||||
{% for subfield in form.therapy_setting %}
|
{% for subfield in form.therapy_setting %}
|
||||||
@ -88,6 +88,22 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-2">
|
||||||
|
<fieldset>
|
||||||
|
<div class="mt-2">
|
||||||
|
<label for="timeRange" class="form-label">{{ form.amount_of_weeks.label }}</label>
|
||||||
|
{{ form.amount_of_weeks(class="form-range", id="timeRange", min=1, max=4, step=1, oninput="this.nextElementSibling.value = this.value") }}
|
||||||
|
<output>{{ form.amount_of_weeks.data or 4 }}</output>
|
||||||
|
nächste(n) Woche(n)
|
||||||
|
{% if form.therapy_distance.errors %}
|
||||||
|
<div class="text-danger">
|
||||||
|
{{ form.amount_of_weeks.errors[0] }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">Suche</button>
|
<button type="submit" class="btn btn-primary">Suche</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-md-7 col-sm-6">
|
<div class="col-lg-12 col-md-11 col-sm-10">
|
||||||
<h2>Suchergebnisse</h2>
|
<h2>Suchergebnisse</h2>
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
@ -16,16 +16,24 @@
|
|||||||
<th scope="col">Adresse</th>
|
<th scope="col">Adresse</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{% set day_classes = {
|
||||||
|
"1": "table-secondary",
|
||||||
|
"2": "table-success",
|
||||||
|
"3": "table-info",
|
||||||
|
"4": "table-light",
|
||||||
|
"5": "table-primary",
|
||||||
|
} %}
|
||||||
{% for doctor in doctors %}
|
{% for doctor in doctors %}
|
||||||
<tr class="table-secondary">
|
<tr class="{{ day_classes.get(doctor.phone_time.start.strftime("%w")) }}">
|
||||||
<th scope="row">{{ doctor.doctor_nr }}</th>
|
<th scope="row">{{ doctor.doctor_nr }}</th>
|
||||||
<th scope="row">{{ doctor.doctor_name }}</th>
|
<th scope="row">{{ doctor.doctor_name }}</th>
|
||||||
<td>{{ doctor.phone_time.start.strftime("%A %d.%m") }}</td>
|
<td>{{ doctor.phone_time.start.strftime("%A %d.%m") }}</td>
|
||||||
<td>{{ doctor.phone_time.start.strftime("%H:%M") }} bis {{ doctor.phone_time.end.strftime("%H:%M") }}</td>
|
<td>{{ doctor.phone_time.start.strftime("%H:%M") }}
|
||||||
<td>{{ doctor.doctor_phone_number }}</td>
|
bis {{ doctor.phone_time.end.strftime("%H:%M") }}</td>
|
||||||
<td>{{ doctor.doctor_address }}</td>
|
<td>{{ doctor.doctor_phone_number }}</td>
|
||||||
</tr>
|
<td>{{ doctor.doctor_address }}</td>
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user