module documentation

Orchestrate the logic of the dashboard.

The views in this module are being called when the user sends a request to the server. Which view is called for which URL is defined in the urls module. The views process the data in the request and return a response. In between, the views delegate the creation of the DataexplorerForm, its validation and cleaning, then execute_query and compute the Statistics from the filtered dataset.

The way this typically plays out in detail is the following: The user navigates to the URL https://lyprox.org/dataexplorer/ and the render_data_stats is called. This view creates an instance of DataexplorerForm.from_initial with the default values and renders the dashboard HTML layout. The template that is used for this is defined in ./lyprox/dataexplorer/templates/dataexplorer/layout.html. The user can then interact with the dashboard and change the values of the form fields. Upon clicking the "Compute" button, an AJAX request is sent with the updated form data. In the update_data_stats, another DataexplorerForm instance is created, this time with the updated queries from the user. The form is validated and cleaned (using form.is_valid()) and the cleaned data (form.cleaned_data) is passed to the execute_query function. This function queries the dataset and returns the patients that match the query.

From the returned queried patients, the Statistics class is used to compute the statistics, which are then returned as JSON data to the frontend. The frontend then updates the dashboard with the new statistics without reloading the entire page.

Read more about how views work in Django, what responses they return and how to use the context they may provide in the Django documentation.

Function help_view Simply display the dashboard help text.
Function make_csv_download Return a CSV file with the selected patients.
Function render_data_stats Return the dashboard view when the user first accesses the dashboard.
Function render_data_table Render the pandas.DataFrame currently displayed in the dashboard.
Function update_data_stats AJAX view to update the dashboard statistics without reloading the page.
Type Alias FormAndPatients Undocumented
Variable logger Undocumented
Function _get_form_and_patients_from_request Prepare the form from the request and execute the query.
def help_view(request) -> HttpResponse:

Simply display the dashboard help text.

def make_csv_download(request: HttpRequest) -> HttpResponse:

Return a CSV file with the selected patients.

def render_data_stats(request: HttpRequest) -> HttpResponse:

Return the dashboard view when the user first accesses the dashboard.

This view handles GET requests, which typically only occur when the user first navigates to the dashboard. But it is also possible to query the dashboard with URL parameters (e.g. https://lyprox.org/dataexplorer/?t_stage=1&t_stage=2...).

The view creates a DataexplorerForm instance with the data from a GET request or with the default initial values. It then calls execute_query with form.cleaned_data and returns the Statistics from_dataset() using the queried dataset to the frontend.

def render_data_table(request: HttpRequest, page_idx: int) -> HttpResponse:

Render the pandas.DataFrame currently displayed in the dashboard.

def update_data_stats(request: HttpRequest) -> JsonResponse:

AJAX view to update the dashboard statistics without reloading the page.

This view is conceptually similar to the render_data_stats, but instead of rendering the entire HTML page, it returns only a JSON response with the updated statistics which are then handled by some JavaScript on the frontend.

It also doesn't receive a GET request, but a POST request with the DataexplorerForm fields as JSON data. The form is validated and cleaned as always (using form.is_valid()).

Some resources to learn more about AJAX requests in Django can be found in this article.

FormAndPatients =

Undocumented

Value
tuple[DataexplorerForm, pd.DataFrame]
logger =

Undocumented

def _get_form_and_patients_from_request(request: HttpRequest) -> FormAndPatients:

Prepare the form from the request and execute the query.