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 bring_consensus_col_to_left Make sure the consensus column is the third top-level column.
Function color_boolean Color the boolean values in the table view.
Function get_institution_shortname Replace the institution names with their abbreviations.
Function help_view Simply display the dashboard help text.
Function make_csv_download Return a CSV file with the selected patients.
Function map_to_cell_classes Return a class for each cell of the patients table.
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 replace_nan_with_x Replace NaN values with 'X' in the table view.
Function smart_capitalize Only capitalize words that are not all caps (e.g. abbreviations).
Function split_and_capitalize Split the string on underscores and capitalize each word.
Function style_table Apply styles to the pandas.DataFrame for better readability.
Function update_data_stats AJAX view to update the dashboard statistics without reloading the page.
Variable logger Undocumented
def bring_consensus_col_to_left(patients: pd.DataFrame) -> pd.DataFrame:

Make sure the consensus column is the third top-level column.

def color_boolean(value: Any) -> str:

Color the boolean values in the table view.

def get_institution_shortname(value: str) -> str:

Replace the institution names with their abbreviations.

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 map_to_cell_classes(patients: pd.DataFrame) -> pd.DataFrame:

Return a class for each cell of the patients table.

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) -> HttpResponse:

Render the pandas.DataFrame currently displayed in the dashboard.

def replace_nan_with_x(value: Any) -> str:

Replace NaN values with 'X' in the table view.

def smart_capitalize(value: str) -> str:

Only capitalize words that are not all caps (e.g. abbreviations).

def split_and_capitalize(value: str) -> str:

Split the string on underscores and capitalize each word.

This is used to format the index of the pandas.DataFrame in the table view.

def style_table(patients: pd.DataFrame) -> Styler:

Apply styles to the pandas.DataFrame for better readability.

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.

logger =

Undocumented