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 |
Make sure the consensus column is the third top-level column. |
Function | color |
Color the boolean values in the table view. |
Function | get |
Replace the institution names with their abbreviations. |
Function | help |
Simply display the dashboard help text. |
Function | make |
Return a CSV file with the selected patients. |
Function | map |
Return a class for each cell of the patients table. |
Function | render |
Return the dashboard view when the user first accesses the dashboard. |
Function | render |
Render the pandas.DataFrame currently displayed in the dashboard. |
Function | replace |
Replace NaN values with 'X' in the table view. |
Function | smart |
Only capitalize words that are not all caps (e.g. abbreviations). |
Function | split |
Split the string on underscores and capitalize each word. |
Function | style |
Apply styles to the pandas.DataFrame for better readability. |
Function | update |
AJAX view to update the dashboard statistics without reloading the page. |
Variable | logger |
Undocumented |
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.
Split the string on underscores and capitalize each word.
This is used to format the index of the pandas.DataFrame
in the table view.
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.