2024-08-26 21:05:34 +02:00
|
|
|
import locale
|
|
|
|
|
2024-08-28 17:01:17 +02:00
|
|
|
from flask import Flask, render_template, request, redirect
|
2024-08-26 21:05:34 +02:00
|
|
|
|
|
|
|
from forms.SearchForm import SearchForm
|
|
|
|
from arztapi.APIHandler import APIHandler
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
2024-10-14 19:58:24 +02:00
|
|
|
app.config.from_prefixed_env()
|
|
|
|
app.secret_key = app.config["THERAPY_SECRET"]
|
2024-08-26 21:05:34 +02:00
|
|
|
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def main_page():
|
2024-09-07 21:12:55 +02:00
|
|
|
"""
|
|
|
|
Show the main page, currently with the search form
|
|
|
|
"""
|
2024-08-26 21:05:34 +02:00
|
|
|
search_form = SearchForm()
|
|
|
|
return render_template("index.html", form=search_form)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/search", methods=["POST"])
|
|
|
|
def search_for_doctors_with_params():
|
2024-09-07 21:12:55 +02:00
|
|
|
"""
|
|
|
|
Use the search form with its data to parse and process it, show the results to the user.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Get the relevant data from the search form
|
2024-08-26 21:05:34 +02:00
|
|
|
search_form = SearchForm(request.form)
|
2024-09-07 21:12:55 +02:00
|
|
|
# Validate the form and its data as well as getting the relevant data
|
2024-08-26 21:05:34 +02:00
|
|
|
if search_form.validate():
|
|
|
|
location = search_form.location.data
|
2024-08-27 23:09:19 +02:00
|
|
|
distance = search_form.therapy_distance.data
|
2024-08-26 21:05:34 +02:00
|
|
|
therapy_types = search_form.therapy_type.data
|
|
|
|
therapy_age_range = search_form.therapy_age_range.data
|
|
|
|
therapy_setting = search_form.therapy_setting.data
|
2024-08-28 17:01:17 +02:00
|
|
|
amount_of_weeks = search_form.amount_of_weeks.data
|
2024-08-26 21:05:34 +02:00
|
|
|
|
2024-09-07 21:12:55 +02:00
|
|
|
# If errors in data -> redirect to index
|
2024-08-26 21:05:34 +02:00
|
|
|
else:
|
2024-08-28 17:01:17 +02:00
|
|
|
return redirect("/")
|
2024-08-26 21:05:34 +02:00
|
|
|
|
2024-09-07 21:12:55 +02:00
|
|
|
# Create an APIHandler to process the given data by gathering the desired phone times
|
2024-08-26 21:05:34 +02:00
|
|
|
api_handler = APIHandler()
|
2024-09-07 21:12:55 +02:00
|
|
|
# Get a list of locations
|
2024-09-01 18:22:01 +02:00
|
|
|
locations = api_handler.get_lat_lon_location_list(location)
|
2024-09-07 21:12:55 +02:00
|
|
|
# Location not found at Arztsuche API
|
2024-09-01 18:22:01 +02:00
|
|
|
if not locations:
|
|
|
|
return render_template("no_result.html")
|
2024-09-07 21:12:55 +02:00
|
|
|
# Use first location match TODO: find better solution than just using first best result lol
|
2024-09-01 18:22:01 +02:00
|
|
|
location_match = locations[0]
|
2024-09-07 21:12:55 +02:00
|
|
|
# Calculate the required base64 value why so ever
|
2024-09-01 18:22:01 +02:00
|
|
|
base64_value = api_handler.calculate_req_value_base64(float(location_match["lat"]), float(location_match["lon"]))
|
2024-09-07 21:12:55 +02:00
|
|
|
# Get the general list of doctors
|
2024-10-10 20:28:49 +02:00
|
|
|
api_handler.get_list_of_doctors(float(location_match["lat"]), float(location_match["lon"]), base64_value,
|
|
|
|
therapy_types, therapy_age_range, therapy_setting, amount_of_weeks)
|
2024-09-07 21:12:55 +02:00
|
|
|
# Get their information
|
2024-08-26 21:05:34 +02:00
|
|
|
api_handler.get_general_doctor_information()
|
2024-09-07 21:12:55 +02:00
|
|
|
# Filter for the distance
|
2024-08-27 23:09:19 +02:00
|
|
|
api_handler.filter_doctor_information_for_distance(distance*1000)
|
2024-09-07 21:12:55 +02:00
|
|
|
# Get the sorted phone times for showing them at the web page
|
2024-08-28 17:01:17 +02:00
|
|
|
sorted_doctor_phone_times = api_handler.get_doctor_phone_times_sorted(amount_of_weeks)
|
2024-08-26 21:05:34 +02:00
|
|
|
|
2024-09-07 21:12:55 +02:00
|
|
|
# Return the resulting data
|
2024-08-26 21:05:34 +02:00
|
|
|
return render_template("result.html", doctors=sorted_doctor_phone_times)
|
|
|
|
|
|
|
|
|
2024-10-12 20:13:27 +02:00
|
|
|
@app.route("/search", methods=["GET"])
|
|
|
|
def search_direct():
|
|
|
|
return redirect("/")
|
|
|
|
|
|
|
|
|
2024-10-10 20:28:49 +02:00
|
|
|
@app.route('/about')
|
|
|
|
def about():
|
|
|
|
return render_template("about.html")
|
2024-10-12 20:13:27 +02:00
|
|
|
|
|
|
|
|
2024-10-12 21:39:20 +02:00
|
|
|
# TODO: Fix layout of privacy
|
|
|
|
@app.route('/privacy')
|
|
|
|
def privacy():
|
|
|
|
return render_template("privacy.html")
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/impress')
|
|
|
|
def impress():
|
|
|
|
return render_template("impress.html")
|
|
|
|
|
|
|
|
|
2024-10-12 20:13:27 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|