Skip to content

Commit

Permalink
Add multiple choice for QberMeta in Questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Sep 27, 2023
1 parent 5c2715c commit 50b1881
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 24 deletions.
6 changes: 3 additions & 3 deletions apps/questionnaire/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
get_enum_name_from_django_field(field): enum
for field, enum in (
# Questionnaire
(Questionnaire.priority_level, QberPriorityLevelTypeEnum),
(Questionnaire.enumerator_skill, QberEnumeratorSkillTypeEnum),
(Questionnaire.data_collection_method, QberDataCollectionMethodTypeEnum),
(Questionnaire.priority_levels, QberPriorityLevelTypeEnum),
(Questionnaire.enumerator_skills, QberEnumeratorSkillTypeEnum),
(Questionnaire.data_collection_methods, QberDataCollectionMethodTypeEnum),
# Question
(Question.type, QuestionTypeEnum),
(Question.priority_level, QberPriorityLevelTypeEnum),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.5 on 2023-09-27 10:05

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questionnaire', '0002_alter_questionleafgroup_category_1_and_more'),
]

operations = [
migrations.RemoveField(
model_name='questionnaire',
name='priority_level',
),
migrations.AddField(
model_name='questionnaire',
name='data_collection_methods',
field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveSmallIntegerField(choices=[(1, 'Direct observation'), (2, 'Focus group'), (3, '1-on-1 interviews'), (4, 'Open-ended survey'), (5, 'Closed-ended survey'), (6, 'Key Informant Interview'), (7, 'Automatic')]), blank=True, default=list, size=None),
),
migrations.AddField(
model_name='questionnaire',
name='enumerator_skills',
field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveSmallIntegerField(choices=[(1, 'Basic'), (2, 'Intermediate'), (3, 'Advanced')]), blank=True, default=list, size=None),
),
migrations.AddField(
model_name='questionnaire',
name='priority_levels',
field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveSmallIntegerField(choices=[(1, 'High'), (2, 'Medium'), (3, 'Low')]), blank=True, default=list, size=None),
),
]
22 changes: 22 additions & 0 deletions apps/questionnaire/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing
from django.db import models
from django.contrib.postgres.fields import ArrayField

from utils.common import get_queryset_for_model
from apps.user.models import User
Expand Down Expand Up @@ -33,6 +34,27 @@ class Questionnaire(QberMetaData, UserResource):
related_name='+',
)

# QberMetaData
priority_level = None
enumerator_skills = None
data_collection_methods = None
# -- Multiple
priority_levels = ArrayField(
models.PositiveSmallIntegerField(choices=QberMetaData.PriorityLevel.choices),
blank=True,
default=list,
)
enumerator_skills = ArrayField(
models.PositiveSmallIntegerField(choices=QberMetaData.EnumeratorSkill.choices),
blank=True,
default=list,
)
data_collection_methods = ArrayField(
models.PositiveSmallIntegerField(choices=QberMetaData.DataCollectionMethod.choices),
blank=True,
default=list,
)

project_id: int
qbank_id: int
question_set: models.QuerySet['Question']
Expand Down
6 changes: 3 additions & 3 deletions apps/questionnaire/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Meta:
fields = (
'title',
# Qber Metadata
'priority_level',
'enumerator_skill',
'data_collection_method',
'priority_levels',
'enumerator_skills',
'data_collection_methods',
'required_duration',
)

Expand Down
13 changes: 7 additions & 6 deletions apps/questionnaire/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ class QuestionnaireType(UserResourceTypeMixin):
id: strawberry.ID
title: strawberry.auto
# Qber Metadata
priority_level = enum_field(Questionnaire.priority_level)
priority_level_display = enum_display_field(Questionnaire.priority_level)
enumerator_skill = enum_field(Questionnaire.enumerator_skill)
enumerator_skill_display = enum_display_field(Questionnaire.enumerator_skill)
data_collection_method = enum_field(Questionnaire.data_collection_method)
data_collection_method_display = enum_display_field(Questionnaire.data_collection_method)
priority_levels = enum_field(Questionnaire.priority_levels)
priority_levels_display = enum_display_field(Questionnaire.priority_levels)
enumerator_skills = enum_field(Questionnaire.enumerator_skills)
enumerator_skills_display = enum_display_field(Questionnaire.enumerator_skills)
data_collection_methods = enum_field(Questionnaire.data_collection_methods)
data_collection_methods_display = enum_display_field(Questionnaire.data_collection_methods)

required_duration: strawberry.auto

@staticmethod
Expand Down
24 changes: 12 additions & 12 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,9 @@ input QuestionUpdateInput {

input QuestionnaireCreateInput {
title: String!
priorityLevel: QberMetaDataPriorityLevelTypeEnum
enumeratorSkill: QberEnumeratorSkillTypeEnum
dataCollectionMethod: QberDataCollectionMethodTypeEnum
priorityLevels: [QberMetaDataPriorityLevelTypeEnum!]
enumeratorSkills: [QberEnumeratorSkillTypeEnum!]
dataCollectionMethods: [QberDataCollectionMethodTypeEnum!]
requiredDuration: Int
}

Expand Down Expand Up @@ -1062,14 +1062,14 @@ type QuestionnaireType {
requiredDuration: Int
choiceCollections: [QuestionChoiceCollectionType!]!
createdBy: UserType!
dataCollectionMethod: QberDataCollectionMethodTypeEnum
dataCollectionMethodDisplay: String
enumeratorSkill: QberEnumeratorSkillTypeEnum
enumeratorSkillDisplay: String
dataCollectionMethods: [QberDataCollectionMethodTypeEnum!]!
dataCollectionMethodsDisplay: [String!]!
enumeratorSkills: [QberEnumeratorSkillTypeEnum!]!
enumeratorSkillsDisplay: [String!]!
leafGroups: [QuestionLeafGroupType!]!
modifiedBy: UserType!
priorityLevel: QberMetaDataPriorityLevelTypeEnum
priorityLevelDisplay: String
priorityLevels: [QberMetaDataPriorityLevelTypeEnum!]!
priorityLevelsDisplay: [String!]!
projectId: ID!
qbank: QuestionBankType!
totalQuestions: QuestionCount!
Expand All @@ -1090,9 +1090,9 @@ type QuestionnaireTypeMutationResponseType {

input QuestionnaireUpdateInput {
title: String
priorityLevel: QberMetaDataPriorityLevelTypeEnum
enumeratorSkill: QberEnumeratorSkillTypeEnum
dataCollectionMethod: QberDataCollectionMethodTypeEnum
priorityLevels: [QberMetaDataPriorityLevelTypeEnum!]
enumeratorSkills: [QberEnumeratorSkillTypeEnum!]
dataCollectionMethods: [QberDataCollectionMethodTypeEnum!]
requiredDuration: Int
}

Expand Down

0 comments on commit 50b1881

Please sign in to comment.