models.py¶
This module contains the questionnaire model definitions which both includes the generic questionnaire parts as well as the disease specific questionnaire model definitions.
The main entry point for a control is the QuestionnaireRequest which
can have multiple related RequestStep instances. Every questionnaire
is a subclass of QuestionnaireBase which is coupled to a RequestStep.
The WizardDatabaseStorage model is used to temporarily store
the data. The relationships are shown in the following model diagram:
Questionnaires models and associated forms should be included into their own apps. For each added questionnaire model the PACKAGE_LOCATION dict needs to be updated. This dict is used by both the get_model_class method in this module as well as the get_forms_for method in the forms.py module.
Models can be defined as the following the example:
class IBDQuestionnaire(QuestionnaireBase):
#Make sure to subclass QuestionnaireBase
#Add this property to return a template that can be used
#to display all the filled in values, see other templates
#for the basic layout.
@property
def display_template(self):
return 'questionnaire/details/IBDQuestionnaire.html'
#Returns the graphic score to display in the graphic
# Currently only works for a couple predefined questionnaire
# categories: Ziekteactiviteit, kwaliteitvanleven, kwaliteitvanzorg
@property
def graphic_score_display(self):
return str(self.BMI).replace(',', '.')
#The axis maximum score for the graph
@property
def graphic_score_max(self):
return 40
#The axis minimum score for the graph
@property
def graphic_score_min(self):
return 10
#The axis score name to set for the graphic
@property
def graphic_score_name(self):
return _('BMI')
#The category of this questionnaire and also the name to display
display_name = _('Ziekteactiviteit')
#The lower case name of this questionnaire
lower_case_name = 'ibd_questionnaire'
Note
After adding new questionnaires make sure to update the PACKAGE_LOCATION dict in models.py
Class and function definitions:
-
apps.questionnaire.models.get_model_class(model_class_name)[source]¶ Get the model_class by the model_name, uses the PACKAGE_LOCATION list to get the package location.
- Args:
- model_class_name: the model class name (case sensitive)
- Returns:
- The model class for model_class_name
-
class
apps.questionnaire.models.QuestionnaireRequest(*args, **kwargs)[source]¶ Bases:
core.models.AuditBaseModelThe questionnaire request is the base for a periodic control. It couples the patient to the request steps which specify the questionnaire models that need to be filled in by the patient.
It also keeps tracks of the questionnaire status like the deadline, finished_date and read_on date.
Parameters: - id (AutoField) –
- patient_id (ForeignKey to
Patient) – - urgent (BooleanField) –
- practitioner_id (ForeignKey to
HealthProfessional) – - deadline_nr (IntegerField) –
- deadline (
DateField) – - created_on (DateField) –
- finished_on (DateField) –
- read_on (DateField) –
- patient_diagnose (CharField) – choices=[rheumatoid_arthritis, chron, colitis_ulcerosa, intestinal_transplantation]
- saved_finish_later (BooleanField) –
- last_filled_in_step (CharField) –
- last_filled_in_form_step (CharField) –
- handled_on (DateField) –
- handled_by_id (ForeignKey to
HealthProfessional) – - appointment_needed (BooleanField) –
- appointment_added_on (DateField) –
- appointment_added_by_id (ForeignKey to
Secretary) –
-
filled_in¶ - Returns:
- True if the finished_on is set else False
-
handled¶ - Returns:
- True if the handled_on is set else False
-
appointment_arranged¶ - Returns:
- Ja if the appointment is arranged else Nee
-
appointment_on_short_term¶ - Returns:
- True if the appointment is on short term else False
-
blood_taken¶ - Returns:
- True if blood taken question is answered postive or False
-
blood_taken_date¶ - Returns:
- The last blood taken date or None
-
patient_needs_appointment¶ - Returns:
- True if the patient needs to have an appointment else False
-
appointment_period_date¶ - Returns:
- The appointment period date or None
-
appointment_period¶ - Returns:
- The appointment period or None
-
class
apps.questionnaire.models.RequestStep(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelThe requeststep model is coupled to the
QuestionnaireRequestand is used to store the questionnaire steps of the control.Every step is coupled to one and only one Questionnaire model class. Which this model class the forms are initalized and displayed to the user with help of the wizard.
The step_nr field is used for sorting.
Parameters: - id (AutoField) –
- questionnairerequest_id (ForeignKey to
QuestionnaireRequest) – - step_nr (IntegerField) –
- model (CharField) – choices=[StartQuestionnaire, IBDQuestionnaire, RADAIQuestionnaire, QOLChronCUQuestionnaire, QOLQuestionnaire, RheumatismSF36, QOHCQuestionnaire, FinishQuestionnaire, StartUrgentQuestionnaire, UrgentProblemQuestionnaire]
-
model_class¶ - Returns:
- The model_class of associated with the model (name) attribute of this RequestStep
-
questionnaire¶ - Returns:
- The filled in questionnaire for this RequestStep or None
-
class
apps.questionnaire.models.WizardDatabaseStorage(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelWizard database storage, saves both clean and unclean data in the data field in json format. The wizard uses an instance of this model to temporarily store all filled in questionnaire data until all questionnaires are filled in correctly.
Parameters: - id (AutoField) –
- questionnaire_request_id (ForeignKey to
QuestionnaireRequest) – - data (TextField) –
- created_on (DateField) –
-
class
apps.questionnaire.models.QuestionnaireBase(*args, **kwargs)[source]¶ Bases:
core.models.AuditBaseModelAbstract class which is the baseclass for every Questionnaire models. Couples to one and only one
RequestStepParameters: request_step_id (ForeignKey to RequestStep) –-
patient¶ - Returns:
- The patient for the questionnaire request associated with the requeststep for this the questionnaire
-
finished_on¶ - Returns:
- The finished date of the questionnaire request or None
-
get_finished_on_timestamp¶ - Returns:
- The finished timestamp of the questionnaire request or None
-