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:

digraph model_graph {
	graph [bb="0,0,357,190",
		fontname=Helvetica,
		fontsize=8,
		splines=true
	];
	node [fontname=Helvetica,
		fontsize=8,
		label="\N",
		shape=plaintext
	];
	edge [fontname=Helvetica,
		fontsize=8
	];
	apps_questionnaire_models_QuestionnaireRequest	 [height=0.5,
		label=<
    <TABLE BGCOLOR="palegoldenrod" BORDER="0" CELLBORDER="0" CELLSPACING="0">
    <TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="olivedrab4">
    <FONT FACE="Helvetica Bold" COLOR="white">
    QuestionnaireRequest<BR/>&lt;<FONT FACE="Helvetica Italic">AuditBaseModel</FONT>&gt;
    </FONT></TD></TR>
  
    </TABLE>
    >,
		pos="126,91",
		width=1.8333];
	_	 [height=0.5,
		pos="126,18",
		width=0.75];
	apps_questionnaire_models_QuestionnaireRequest -> _	 [pos="e,108.42,36.029 108.37,72.813 105.85,64.789 105.15,55.047 106.27,46.069"];
	apps_questionnaire_models_QuestionnaireRequest -> _	 [pos="e,120.14,36.029 120.12,72.813 119.28,64.789 119.05,55.047 119.42,46.069"];
	apps_questionnaire_models_QuestionnaireRequest -> _	 [pos="e,131.86,36.029 131.88,72.813 132.72,64.789 132.95,55.047 132.58,46.069"];
	apps_questionnaire_models_QuestionnaireRequest -> _	 [pos="e,143.58,36.029 143.63,72.813 146.15,64.789 146.85,55.047 145.73,46.069"];
	apps_questionnaire_models_RequestStep	 [height=0.5,
		label=<
    <TABLE BGCOLOR="palegoldenrod" BORDER="0" CELLBORDER="0" CELLSPACING="0">
    <TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="olivedrab4">
    <FONT FACE="Helvetica Bold" COLOR="white">
    RequestStep
    </FONT></TD></TR>
  
    </TABLE>
    >,
		pos="52,172",
		width=1.4444];
	apps_questionnaire_models_RequestStep -> apps_questionnaire_models_QuestionnaireRequest	 [arrowhead=none,
		arrowtail=dot,
		dir=both,
		label="questionnairerequest (requeststep)",
		lp="116,131.5",
		pos="s,48.38,153.89 48.024,145.81 48.161,139.26 49.445,132.51 53,127 57.726,119.68 64.445,113.85 71.914,109.22"];
	apps_questionnaire_models_WizardDatabaseStorage	 [height=0.5,
		label=<
    <TABLE BGCOLOR="palegoldenrod" BORDER="0" CELLBORDER="0" CELLSPACING="0">
    <TR><TD COLSPAN="2" CELLPADDING="4" ALIGN="CENTER" BGCOLOR="olivedrab4">
    <FONT FACE="Helvetica Bold" COLOR="white">
    WizardDatabaseStorage
    </FONT></TD></TR>
  
    </TABLE>
    >,
		pos="201,172",
		width=2.0278];
	apps_questionnaire_models_WizardDatabaseStorage -> apps_questionnaire_models_QuestionnaireRequest	 [arrowhead=none,
		arrowtail=dot,
		dir=both,
		label="questionnaire_request (wizarddatabasestorage)",
		lp="271,131.5",
		pos="s,194.91,153.86 191.42,146.22 188.11,139.53 183.97,132.6 179,127 173,120.23 165.41,114.21 157.86,109.15"];
}

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.AuditBaseModel

The 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.Model

The requeststep model is coupled to the QuestionnaireRequest and 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.Model

Wizard 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:
class apps.questionnaire.models.QuestionnaireBase(*args, **kwargs)[source]

Bases: core.models.AuditBaseModel

Abstract class which is the baseclass for every Questionnaire models. Couples to one and only one RequestStep

Parameters: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