diff --git a/apps/questionnaire/dataloaders.py b/apps/questionnaire/dataloaders.py index 00d32c8..8c3bc90 100644 --- a/apps/questionnaire/dataloaders.py +++ b/apps/questionnaire/dataloaders.py @@ -10,7 +10,7 @@ from apps.questionnaire.types import QuestionCount -def total_questions_by_questionnare(keys: list[int]) -> list[QuestionCount]: +def total_questions_by_questionnaire(keys: list[int]) -> list[QuestionCount]: qs = ( Question.objects .filter(questionnaire__in=keys) @@ -78,8 +78,8 @@ def load_choices(keys: list[int]) -> list[list[Choice]]: class QuestionnaireDataLoader(): @cached_property - def total_questions_by_questionnare(self) -> list[QuestionCount]: - return DataLoader(load_fn=sync_to_async(total_questions_by_questionnare)) + def total_questions_by_questionnaire(self) -> list[QuestionCount]: + return DataLoader(load_fn=sync_to_async(total_questions_by_questionnaire)) @cached_property def total_questions_by_leaf_group(self) -> list[QuestionCount]: diff --git a/apps/questionnaire/models.py b/apps/questionnaire/models.py index 2a3f67f..9838235 100644 --- a/apps/questionnaire/models.py +++ b/apps/questionnaire/models.py @@ -155,6 +155,9 @@ class QuestionLeafGroup(BaseQuestionLeafGroup, UserResource): questionnaire = models.ForeignKey(Questionnaire, on_delete=models.CASCADE) is_hidden = models.BooleanField(default=False) + # Type + qbank_leaf_group_id: int + class Meta: unique_together = [ ('questionnaire', 'name'), diff --git a/apps/questionnaire/types.py b/apps/questionnaire/types.py index deb2b00..cbda21b 100644 --- a/apps/questionnaire/types.py +++ b/apps/questionnaire/types.py @@ -61,6 +61,16 @@ def get_queryset(_, queryset: models.QuerySet | None, info: Info): return qs.filter(questionnaire__project=info.context.active_project.project) return qs.none() + @strawberry.field + def qbank_leaf_group_id(self) -> strawberry.ID | None: + if self.qbank_leaf_group_id: + return strawberry.ID(str(self.qbank_leaf_group_id)) + + @strawberry.field + def total_qbank_questions(self, info: Info) -> int | None: + if self.qbank_leaf_group_id: + return info.context.dl.qbank.total_questions_by_leaf_group.load(self.qbank_leaf_group_id) + @strawberry.field def total_questions(self, info: Info) -> QuestionCount: return info.context.dl.questionnaire.total_questions_by_leaf_group.load(self.id) @@ -106,7 +116,7 @@ async def choice_collections(self, info: Info) -> list['QuestionChoiceCollection @strawberry.field def total_questions(self, info: Info) -> QuestionCount: - return info.context.dl.questionnaire.total_questions_by_questionnare.load(self.id) + return info.context.dl.questionnaire.total_questions_by_questionnaire.load(self.id) @strawberry.field def qbank(self, info: Info) -> QuestionBankType: @@ -116,6 +126,10 @@ def qbank(self, info: Info) -> QuestionBankType: info.context.dl.questionnaire.load_qbank.load, ) + @strawberry.field + def total_qbank_questions(self, info: Info) -> int: + return info.context.dl.qbank.total_questions_by_qbank.load(self.qbank_id) + @strawberry_django.type(Choice) class QuestionChoiceType(ClientIdMixin): diff --git a/schema.graphql b/schema.graphql index b2351d9..4ebd8b4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -517,13 +517,9 @@ type QBQuestionTypeCountList { } enum QberDataCollectionMethodTypeEnum { - DIRECT - FOCUS_GROUP - ONE_ON_ONE_INTERVIEW - OPEN_ENDED_SURVEY - CLOSED_ENDED_SURVEY KEY_INFORMANT_INTERVIEW - AUTOMATIC + DIRECT_OBSERVATION + ATOMIC_OBSERVATION } enum QberEnumeratorSkillTypeEnum { @@ -871,7 +867,9 @@ type QuestionLeafGroupType { category4Display: String createdBy: UserType! modifiedBy: UserType! + qbankLeafGroupId: ID questionnaireId: ID! + totalQbankQuestions: Int totalQuestions: QuestionCount! type: QuestionLeafGroupTypeEnum! typeDisplay: String! @@ -1073,6 +1071,7 @@ type QuestionnaireType { priorityLevelsDisplay: [String!]! projectId: ID! qbank: QuestionBankType! + totalQbankQuestions: Int! totalQuestions: QuestionCount! }