class DataexplorerForm(FormLoggerMixin, forms.Form):
Constructor: DataexplorerForm(*args, user, **kwargs)
Form for querying the database.
It is supposed to be called with the GET or POST data to be cleaned as the first
argument. The user argument is necessary to determine which datasets the user
may or may not have access to. If the user isn't logged in, the form will use the
update_dataset_options
method to only show public datasets.
Via add_subsite_choice_fields
and add_lnl_toggle_buttons
, the form is
dynamically extended with the buttons and selection for subsites and LNLs. Beyond
that, all fields mirror the fields in the Statistics
class in the query
module
pretty closely.
The form class also has the classmethod from_initial
, which creates a bound
form from the initial field data. This is useful as the form isn't used like a
typical Django form that is rendered empty and unbound, waiting for user input.
Instead, the form is always bound (either with the initial data or with the user's
input), validated, and only then rendered.
Class Method | from |
Return a bound form filled with the default values for each field. |
Static Method | generate |
Generate all subsite ICD codes from the cleaned_data. |
Method | __init__ |
Extend default initialization. |
Method | add |
Add all LNL toggle buttons to the form. |
Method | add |
Add all Subsites choice fields to the form. |
Method | check |
Ensure that LNLs I, II, and V are not in conflict with their sublevels. |
Method | clean |
Clean the form data. |
Method | get |
Return the names of the subsite checkboxes. |
Method | update |
Update the DatasetModel choices based on the user's permissions. |
Class Variable | central |
Filter by whether the tumor is central or not. |
Class Variable | datasets |
Patients from which datasets to include in the query. |
Class Variable | hpv |
Select patients that are HPV positive, negative, or unknown. |
Class Variable | is |
Select patients with N+ or N0 status. |
Class Variable | midext |
Filter by whether the tumor crosses the mid-sagittal plane. |
Class Variable | modalities |
Which modalities to combine into a consensus diagnosis. |
Class Variable | modality |
Method to use to combine the modalities' LNL involvement diagnoses. |
Class Variable | show |
Show the statistics after querying as percentages or absolute numbers. |
Class Variable | smoke |
Select patients that are smokers, non-smokers, or unknown. |
Class Variable | surgery |
Did the patient undergo neck dissection? |
Class Variable | t |
Only include patients with the selected T-stages. |
Return a bound form filled with the default values for each field.
This uses the form_from_initial
helper function to create the form with the
initial data. This helper function is also used at other places in the code
to create forms filled with initial data.
Generate all subsite ICD codes from the cleaned_data.
In the cleaned_data up to this point, the ICD codes are still grouped by
Subsites
. E.g., there would be a key subsite_larynx in the
cleaned_data with a list of selected ICD codes as value. This method
extracts and concatenates all these lists of selected ICD codes into a single
generator of selected ICD codes.
Extend default initialization.
After calling the parent constructor, the selectable datasets are populated
based on the user's permissions. I.e., a logged-in user can see private
datasets, while an anonymous user can only see public datasets. This is handled
by the update_dataset_options
method.
Then, the defined Subsites
as separate EasySubsiteChoiceField
fields are
added to the form. We do this dynamically via the add_subsite_choice_fields
method, because we want to render the subsites separately in the frontend.
Also, the LNL toggle buttons are added to the form dynamically, because it would be cumbersome to add them manually for each LNL and side.
Note that the form contains the user input or initial values already upon initialization. But it is OK to add fields even after that, because the form only goes through its fields and tries to validate its data for each of then when form.is_valid() is called.
Ensure that LNLs I, II, and V are not in conflict with their sublevels.
This is already handled in the frontend using JavaScript, but it is technically possible to e.g. provide a GET request with the URL parameters that would still violate the sub- and superlevel constraints.
One example would be that the superlevel II is selected to be healthy, but sublevel IIa is selected to be involved. That's a violation, because by definition, superlevel II is involved as soon as one of the sublevels harbors disease.
Clean the form data.
The default cleaning provided by Django is extended to deal with some special cases that arise from our data. On the one hand, this involved casting the t_stage list of values to integers, but more importantly, it also ensures that the sub- and superlevel involvement of the LNLs I, II, and V are not in conflict.
Further, it extracts a list of ICD codes from the subsite checkboxes via the
generate_icd_codes
method.