Skip to content

Commit

Permalink
Add qbank question counts in LeafGroup and Questionnaire Node
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Sep 28, 2023
1 parent b1c6d91 commit eea8c11
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions apps/questionnaire/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]:
Expand Down
3 changes: 3 additions & 0 deletions apps/questionnaire/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
16 changes: 15 additions & 1 deletion apps/questionnaire/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
11 changes: 5 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -871,7 +867,9 @@ type QuestionLeafGroupType {
category4Display: String
createdBy: UserType!
modifiedBy: UserType!
qbankLeafGroupId: ID
questionnaireId: ID!
totalQbankQuestions: Int
totalQuestions: QuestionCount!
type: QuestionLeafGroupTypeEnum!
typeDisplay: String!
Expand Down Expand Up @@ -1073,6 +1071,7 @@ type QuestionnaireType {
priorityLevelsDisplay: [String!]!
projectId: ID!
qbank: QuestionBankType!
totalQbankQuestions: Int!
totalQuestions: QuestionCount!
}

Expand Down

0 comments on commit eea8c11

Please sign in to comment.