Skip to content

Commit

Permalink
feat: add support for dependent answers
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedykori committed Nov 19, 2021
1 parent f03e5e1 commit 082c089
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
4 changes: 3 additions & 1 deletion fahari/sims/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.9 on 2021-11-16 18:06
# Generated by Django 3.2.9 on 2021-11-19 10:00

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -28,6 +28,7 @@ class Migration(migrations.Migration):
('updated_by', models.UUIDField(blank=True, null=True)),
('precedence_display_type', models.CharField(blank=True, choices=[('bullet', 'Bullets'), ('numbered_td', 'Numbered with a trailing dot, E.g. 1., 2., 3.'), ('lower_case_letters_tcb', 'Lower case letter with trailing closing bracket, E.g. a), b), c)')], help_text='The precedence display type of a "container". This sets the precedence display type for all the child elements of this container but not the container itself.', max_length=150, null=True)),
('query', models.TextField(verbose_name='Question')),
('question_code', models.CharField(editable=False, help_text='A simple code that can be used to uniquely identify a question. This is mostly useful in the context of dependent question answers.', max_length=100, unique=True)),
('answer_type', models.CharField(choices=[('true_false', 'True/False'), ('yes_no', 'Yes/No'), ('number', 'Whole Number'), ('fraction', 'Fractional Number'), ('short_answer', 'Short Answer'), ('radio_option', 'Select One'), ('select_list', 'Select Multiple'), ('dependent', 'Dependent on Another Answer'), ('ratio', 'Ratio'), ('none', 'Not Applicable')], default='short_answer', help_text='Expected answer type', max_length=15)),
('precedence', models.PositiveSmallIntegerField(help_text='The rank of a question within it\'s "container". Used to position the question when rendering a questionnaire.')),
('metadata', models.JSONField(blank=True, default=dict)),
Expand Down Expand Up @@ -120,6 +121,7 @@ class Migration(migrations.Migration):
('created_by', models.UUIDField(blank=True, null=True)),
('updated', models.DateTimeField(default=django.utils.timezone.now)),
('updated_by', models.UUIDField(blank=True, null=True)),
('is_not_applicable', models.BooleanField(default=False, help_text='Indicates that answer is not applicable for the attached question.')),
('response', models.JSONField(default=dict)),
('answered_on', models.DateTimeField(auto_now=True)),
('comments', models.TextField(blank=True, null=True)),
Expand Down
18 changes: 0 additions & 18 deletions fahari/sims/migrations/0002_questionanswer_is_not_applicable.py

This file was deleted.

23 changes: 20 additions & 3 deletions fahari/sims/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ class QuestionAnswerResponse(TypedDict):
"""This is the actual content of the answer."""


class QuestionMetadata(TypedDict):
"""The structure of a question metadata dictionary."""
class QuestionConstraints(TypedDict):
"""The structure of a question's constraints metadata dictionary."""

max_length: Optional[Number]
max_value: Optional[Number]
min_length: Optional[Number]
min_value: Optional[Number]
optional: Optional[bool]
ratio_lower_bound: Optional[int]
ratio_upper_bound: Optional[int]


class QuestionMetadata(TypedDict):
"""The structure of a question metadata dictionary."""

constraints: Optional[QuestionConstraints]
depends_on: Optional[str]
optional: Optional[bool]
select_list_options: Optional[Sequence[str]]


Expand Down Expand Up @@ -305,6 +312,16 @@ class AnswerType(models.TextChoices):
)

query = models.TextField(verbose_name="Question")
question_code = models.CharField(
max_length=100,
editable=False,
help_text=(
"A simple code that can be used to uniquely identify a question. "
"This is mostly useful in the context of dependent question "
"answers."
),
unique=True,
)
answer_type = models.CharField(
max_length=15,
choices=AnswerType.choices,
Expand Down

0 comments on commit 082c089

Please sign in to comment.