Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Grand Calculated Summary Value Source Type #229

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/validators/routing/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def resolve_value_source_json_type(value_source, schema):
answer_type = schema.answers_with_context[answer_id]["answer"]["type"]
return ANSWER_TYPE_TO_JSON_TYPE[answer_type]

if source == "grand_calculated_summary":
katie-gardner marked this conversation as resolved.
Show resolved Hide resolved
block = schema.get_block(value_source["identifier"])
first_calculated_summary_source = block["calculation"]["operation"]["+"][0]
return resolve_value_source_json_type(first_calculated_summary_source, schema)

if source == "list":
if selector := value_source.get("selector"):
return LIST_SELECTOR_TO_JSON_TYPE[selector]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,370 @@
{
"mime_type": "application/json/ons/eq",
"language": "en",
"schema_version": "0.0.1",
"data_version": "0.0.3",
"survey_id": "0",
"title": "Grand Calculated Summary with overlapping answers",
"theme": "default",
"description": "A schema to showcase grand calculated summaries which include multiple calculated summaries using the same answers.",
"metadata": [
{
"name": "user_id",
"type": "string"
},
{
"name": "period_id",
"type": "string"
},
{
"name": "ru_name",
"type": "string"
}
],
"questionnaire_flow": {
"type": "Hub",
"options": {
"required_completed_sections": ["introduction-section"]
}
},
"sections": [
{
"id": "introduction-section",
"title": "Introduction",
"show_on_hub": false,
"groups": [
{
"id": "introduction-group",
"title": "Introduction",
"blocks": [
{
"type": "Introduction",
"id": "introduction-block",
"primary_content": [
{
"id": "about",
"contents": [
{
"title": "About",
"list": [
"This survey tests that when you re-use answers between calculated summaries, the grand calculated summary still resolves to the correct value"
]
},
{
"title": "How to test this schema",
"list": [
"Ensure that the grand calculated summary section does not show unless all dependent calculated summaries in section-1 have been confirmed.",
"Your answer to the third question, may unlock an additional calculated summary which re-use your answers to the first two questions",
"If you do not select to buy extra food, verify no additional calculated summary occurs, and that the grand calculated summary is correct",
"If you choose to buy any food items twice, verify that they are included twice in the grand calculated summary, one for each calculated summary",
"Verify that if you have the extra calculated summary, and change the cost of bread for example <strong>using either of the calculated summary change links which include it</strong> that you are routed to each calculated summary first, and only then the grand calculated summary"
]
}
]
}
]
}
]
}
]
},
{
"id": "section-1",
"title": "Weekly shop",
"summary": {
"show_on_completion": true
},
"groups": [
{
"id": "group-1",
"title": "Weekly shopping",
"blocks": [
{
"type": "Question",
"id": "block-1",
"question": {
"type": "General",
"id": "question-1",
"title": "How much do you spend on the following in a typical weekly shop?",
"answers": [
{
"id": "q1-a1",
"label": "Money on milk",
"type": "Currency",
"currency": "GBP",
"mandatory": false,
"decimal_places": 2
},
{
"id": "q1-a2",
"label": "Money on eggs",
"type": "Currency",
"currency": "GBP",
"mandatory": false,
"decimal_places": 2
}
]
}
},
{
"type": "Question",
"id": "block-2",
"question": {
"type": "General",
"id": "question-2",
"title": "How much do you spend on these items in a typical week?",
"answers": [
{
"id": "q2-a1",
"label": "Money on bread",
"type": "Currency",
"currency": "GBP",
"mandatory": false,
"decimal_places": 2
},
{
"id": "q2-a2",
"label": "Money on cheese",
"type": "Currency",
"currency": "GBP",
"mandatory": false,
"decimal_places": 2
}
]
}
},
{
"type": "CalculatedSummary",
"id": "calculated-summary-1",
"title": "Total of milk and bread is calculated to be %(total)s. Is this correct?",
"calculation": {
"title": "milk + bread",
"operation": {
"+": [
{
"source": "answers",
"identifier": "q1-a1"
},
{
"source": "answers",
"identifier": "q2-a1"
}
]
}
}
},
{
"type": "CalculatedSummary",
"id": "calculated-summary-2",
"title": "Total of eggs and cheese is calculated to be %(total)s. Is this correct?",
"calculation": {
"title": "eggs + cheese",
"operation": {
"+": [
{
"source": "answers",
"identifier": "q1-a2"
},
{
"source": "answers",
"identifier": "q2-a2"
}
]
}
}
},
{
"type": "Question",
"id": "block-3",
"question": {
"type": "General",
"id": "question-3",
"title": "Do you want to buy extra of anything this week?",
"guidance": {
"contents": [
{
"description": "If you select the first option, all your answers so far will be reused in a new calculated summary for extra shopping. If you select the second option, only your answers for bread and cheese will be reused."
}
]
},
"answers": [
{
"type": "Radio",
"id": "radio-extra",
"mandatory": true,
"options": [
{
"label": "Yes, I am going to buy two of everything",
"value": "Yes, I am going to buy two of everything"
},
{
"label": "Yes, extra bread and cheese",
"value": "Yes, extra bread and cheese"
},
{
"label": "No",
"value": "No"
}
]
}
]
}
},
{
"skip_conditions": {
"when": {
"!=": [
{
"source": "answers",
"identifier": "radio-extra"
},
"Yes, I am going to buy two of everything"
]
}
},
"type": "CalculatedSummary",
"id": "calculated-summary-3",
"title": "Total extra items purchased is calculated to be %(total)s. Is this correct? This reuses your answers to question 1 and 2",
"calculation": {
"title": "(extra) milk + eggs + bread + cheese",
"operation": {
"+": [
{
"source": "answers",
"identifier": "q1-a1"
},
{
"source": "answers",
"identifier": "q1-a2"
},
{
"source": "answers",
"identifier": "q2-a1"
},
{
"source": "answers",
"identifier": "q2-a2"
}
]
}
}
},
{
"skip_conditions": {
"when": {
"!=": [
{
"source": "answers",
"identifier": "radio-extra"
},
"Yes, extra bread and cheese"
]
}
},
"type": "CalculatedSummary",
"id": "calculated-summary-4",
"title": "Total extra items cost is calculated to be %(total)s. Is this correct? This is reusing your bread and cheese answers",
"calculation": {
"title": "(extra) bread + cheese",
"operation": {
"+": [
{
"source": "answers",
"identifier": "q2-a1"
},
{
"source": "answers",
"identifier": "q2-a2"
}
]
}
}
}
]
}
]
},
{
"id": "section-3",
"title": "Grand calculated summary",
"enabled": {
"when": {
"==": [
{
"source": "progress",
"selector": "section",
"identifier": "section-1"
},
"COMPLETED"
]
}
},
"groups": [
{
"id": "group-2",
"title": "Grand calculated summary",
"blocks": [
{
"type": "GrandCalculatedSummary",
"id": "grand-calculated-summary-shopping",
"title": "Grand Calculated Summary of purchases this week comes to %(total)s. Is this correct?.",
"calculation": {
"title": "Weekly shopping cost",
"operation": {
"+": [
{
"source": "calculated_summary",
"identifier": "calculated-summary-1"
},
{
"source": "calculated_summary",
"identifier": "calculated-summary-2"
},
{
"source": "calculated_summary",
"identifier": "calculated-summary-3"
},
{
"source": "calculated_summary",
"identifier": "calculated-summary-4"
}
]
}
}
}
]
}
]
},
{
"id": "section-4",
"title": "Conditional Section",
"enabled": {
"when": {
">": [
{
"source": "grand_calculated_summary",
"identifier": "grand-calculated-summary-shopping"
},
500
]
}
},
"groups": [
{
"id": "group-3",
"title": "Conditional Group",
"blocks": [
{
"type": "Interstitial",
"id": "grand-calculated-summary-piping",
"content": {
"title": "This section is only showing because the grand calculated summary exceeded £500."
}
}
]
}
]
}
]
}