-
Notifications
You must be signed in to change notification settings - Fork 299
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
Matching of the correct pair of qItem and qrItem fails for repeated groups #2655
Comments
@allan-on could you share the questionnaire, questionnaire response, and the exception to the ticket? |
Here's additional context for the bug observed: Exception Stack tracejava.lang.IllegalArgumentException: Failed requirement.
at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:202)
at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:226)
at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:217)
at com.google.android.fhir.datacapture.extensions.MoreQuestionnairesKt.forEachItemPair(MoreQuestionnaires.kt:190)
at com.google.android.fhir.datacapture.QuestionnaireViewModel.initializeCalculatedExpressions(QuestionnaireViewModel.kt:630)
at com.google.android.fhir.datacapture.QuestionnaireViewModel.access$initializeCalculatedExpressions(QuestionnaireViewModel.kt:90)
at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$2.invokeSuspend(QuestionnaireViewModel.kt:609)
at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$2.invoke(Unknown Source:8)
at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$2.invoke(Unknown Source:4) Questionnaire used{
"resourceType": "Questionnaire",
"language": "en-GB",
"id": "dc-clinic-medicines",
"name": "DC Clinic Medicines",
"title": "Medicines",
"description": "Patient medicines",
"version": "0.0.1",
"status": "active",
"publisher": "ONA",
"contact": [
{
"name": "http://www.smartregister.org/"
}
],
"subjectType": [
"Patient"
],
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
"valueCanonical": "https://smartregister.org/fhir/StructureMap/dc-patient-medicines-sm"
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-entryMode",
"valueCode": "prior-edit"
}
],
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page 1"
}
],
"text": "Page 1"
}
}
],
"linkId": "page-1",
"type": "group",
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden",
"valueBoolean": true
}
],
"linkId": "has-hypertension",
"type": "boolean",
"readOnly": true,
"required": false
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden",
"valueBoolean": true
}
],
"linkId": "has-diabetes",
"type": "boolean",
"readOnly": true,
"required": false
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat",
"valueString": "d/M/yy"
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "today()"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/maxValue",
"valueDate": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-calculatedValue",
"valueExpression": {
"language": "text/fhirpath",
"expression": "today()"
}
}
]
}
}
],
"linkId": "visit-date",
"text": "Visit date",
"type": "date",
"required": true,
"item": [
{
"linkId": "visit-date-hint",
"text": "Visit date",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover",
"display": "Fly-over"
}
],
"text": "Flyover"
}
}
]
}
]
},
{
"linkId": "medicines-repeated-group",
"type": "group",
"text": "Medicine",
"item": [
{
"linkId": "medicine",
"type": "reference",
"required": true,
"item": [
{
"linkId": "medicine-hint",
"text": "Medicine",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover",
"display": "Fly-over"
}
],
"text": "Flyover"
}
}
]
}
],
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "drop-down",
"display": "Drop down"
}
],
"text": "Drop down"
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression",
"valueExpression": {
"expression": "Medication",
"language": "application/x-fhir-query"
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn",
"extension": [
{
"url": "path",
"valueString": "Medication.code.coding.display"
},
{
"url": "forDisplay",
"valueBoolean": true
}
]
}
]
},
{
"linkId": "dosage",
"type": "choice",
"required": true,
"item": [
{
"linkId": "dosage-hint",
"text": "Dosage (mg)",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover",
"display": "Fly-over"
}
],
"text": "Flyover"
}
}
]
}
],
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "drop-down",
"display": "Drop down"
}
],
"text": "Drop down"
}
}
],
"answerOption": [
{
"valueCoding": {
"id": "3_mg",
"system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
"code": "3_mg",
"display": "3 mg"
}
},
{
"valueCoding": {
"id": "3_5_mg",
"system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
"code": "3_5_mg",
"display": "3.5 mg"
}
}
],
"enableWhen": [
{
"question": "medicine",
"operator": "=",
"answerReference": {
"reference": "Medication/dc-med-00206501"
}
},
{
"question": "medicine",
"operator": "=",
"answerReference": {
"reference": "Medication/dc-med-00202901"
}
}
],
"enableBehavior": "any"
},
{
"linkId": "insulin-dosage",
"type": "integer",
"required": true,
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/minValue",
"valueInteger": 1
},
{
"url": "http://hl7.org/fhir/StructureDefinition/maxValue",
"valueInteger": 500
}
],
"item": [
{
"linkId": "insulin-dosage-hint",
"text": "Dosage (IU)",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover",
"display": "Fly-over"
}
],
"text": "Flyover"
}
}
]
}
],
"enableWhen": [
{
"question": "medicine",
"operator": "=",
"answerReference": {
"reference": "Medication/dc-med-00700701"
}
},
{
"question": "medicine",
"operator": "=",
"answerReference": {
"reference": "Medication/dc-med-00700801"
}
},
{
"question": "medicine",
"operator": "=",
"answerReference": {
"reference": "Medication/dc-med-00700601"
}
}
],
"enableBehavior": "any"
},
{
"linkId": "frequency",
"type": "choice",
"required": true,
"item": [
{
"linkId": "frequency-hint",
"text": "Frequency",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover",
"display": "Fly-over"
}
],
"text": "Flyover"
}
}
]
}
],
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "drop-down",
"display": "Drop down"
}
],
"text": "Drop down"
}
}
],
"answerOption": [
{
"valueCoding": {
"id": "od_mane",
"code": "od_mane",
"system": "http://smartregister.org/",
"display": "OD Mane"
}
},
{
"valueCoding": {
"id": "od_nocte",
"code": "od_nocte",
"system": "http://smartregister.org/",
"display": "OD Nocte"
}
}
]
},
{
"linkId": "notes",
"type": "string",
"required": false,
"item": [
{
"linkId": "notes-hint",
"text": "Notes",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover",
"display": "Fly-over"
}
],
"text": "Flyover"
}
}
]
}
]
}
],
"repeats": true
}
]
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page 2"
}
],
"text": "Page 2"
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "(%resource.descendants().where(linkId='has-hypertension').answer.value.exists() and %resource.descendants().where(linkId='has-hypertension').answer.value = false) or (%resource.descendants().where(linkId='has-diabetes').answer.value.exists() and %resource.descendants().where(linkId='has-diabetes').answer.value = false) or (%resource.descendants().where(linkId='has-hypertension').answer.exists().not()) or (%resource.descendants().where(linkId='has-diabetes').answer.exists().not())"
}
}
],
"linkId": "page-2",
"type": "group",
"item": [
{
"linkId": "hypertension-diagnosis",
"type": "choice",
"text": "Add diagnosis for hypertension?",
"required": true,
"answerOption": [
{
"valueCoding": {
"id": "hypertension-choice",
"code": "hypertension",
"system": "http://smartregister.org/",
"display": "Hypertension"
}
},
{
"valueCoding": {
"id": "no-diagnosis",
"code": "no-diagnosis",
"system": "http://smartregister.org/",
"display": "No diagnosis"
}
}
],
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "(%resource.descendants().where(linkId='has-hypertension').answer.value.exists() and %resource.descendants().where(linkId='has-hypertension').answer.value = false) or (%resource.descendants().where(linkId='has-hypertension').answer.exists().not())"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/ValueSet/questionnaire-item-control",
"code": "radio-button"
}
]
}
}
]
},
{
"linkId": "diabetes-diagnosis",
"type": "choice",
"text": "Add diagnosis for diabetes?",
"required": true,
"answerOption": [
{
"valueCoding": {
"id": "diabetes-type-1-choice",
"system": "http://smartregister.org/",
"code": "diabetes-type-1",
"display": "Diabetes Type 1"
}
},
{
"valueCoding": {
"id": "diabetes-type-2-choice",
"system": "http://smartregister.org/",
"code": "diabetes-type-2",
"display": "Diabetes Type 2"
}
},
{
"valueCoding": {
"id": "no-diagnosis",
"code": "no-diagnosis",
"system": "http://smartregister.org/",
"display": "No diagnosis"
}
}
],
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "(%resource.descendants().where(linkId='has-diabetes').answer.value.exists() and %resource.descendants().where(linkId='has-diabetes').answer.value = false) or (%resource.descendants().where(linkId='has-diabetes').answer.exists().not())"
}
},
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/ValueSet/questionnaire-item-control",
"code": "radio-button"
}
]
}
}
]
}
]
}
]
} a. QuestionnaireResponse where a Questionnaire has a repeated group with one set of repeated items/fieldsThe {
"resourceType": "QuestionnaireResponse",
"id": "41664149-90b7-4cce-a874-2120bae9ca24",
"meta": {
"lastUpdated": "2024-08-13T12:10:37.965+03:00"
},
"questionnaire": "Questionnaire/dc-clinic-medicines",
"status": "completed",
"subject": {
"reference": "Patient/f5f86091-0ccf-47c1-89a3-15547740a967"
},
"authored": "2024-08-13T12:10:35+03:00",
"author": {
"reference": "Practitioner/a21decb7-ac90-43e1-926a-0579a46816ed"
},
"item": [
{
"linkId": "page-1",
"item": [
{
"linkId": "has-hypertension",
"answer": [
{
"valueBoolean": false
}
]
},
{
"linkId": "has-diabetes",
"answer": [
{
"valueString": "false"
}
]
},
{
"linkId": "visit-date",
"text": "Visit date",
"answer": [
{
"valueDate": "2024-08-13",
"item": [
{
"linkId": "visit-date-hint",
"text": "Visit date"
}
]
}
]
},
{
"linkId": "medicines-repeated-group",
"text": "Medicine",
"item": [
{
"linkId": "medicine",
"answer": [
{
"valueReference": {
"reference": "Medication/dc-med-00202901",
"display": "Losartan"
},
"item": [
{
"linkId": "medicine-hint",
"text": "Medicine"
}
]
}
]
},
{
"linkId": "dosage",
"answer": [
{
"valueCoding": {
"id": "20_mg",
"system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
"code": "20_mg",
"display": "20 mg"
},
"item": [
{
"linkId": "dosage-hint",
"text": "Dosage (mg)"
}
]
}
]
},
{
"linkId": "frequency",
"answer": [
{
"valueCoding": {
"id": "eod",
"system": "http://smartregister.org/",
"code": "eod",
"display": "EOD"
},
"item": [
{
"linkId": "frequency-hint",
"text": "Frequency"
}
]
}
]
},
{
"linkId": "notes",
"answer": [
{
"valueString": "To be followed upon",
"item": [
{
"linkId": "notes-hint",
"text": "Notes"
}
]
}
]
}
]
}
]
},
{
"linkId": "page-2",
"item": [
{
"linkId": "hypertension-diagnosis",
"text": "Add diagnosis for hypertension?",
"answer": [
{
"valueCoding": {
"id": "hypertension-choice",
"system": "http://smartregister.org/",
"code": "hypertension",
"display": "Hypertension"
}
}
]
},
{
"linkId": "diabetes-diagnosis",
"text": "Add diagnosis for diabetes?",
"answer": [
{
"valueCoding": {
"id": "diabetes-type-2-choice",
"system": "http://smartregister.org/",
"code": "diabetes-type-2",
"display": "Diabetes Type 2"
}
}
]
}
]
}
]
} b. QuestionnaireResponse where a Questionnaire has a repeated group with several repeated items/fieldsThe qItems were seen to be 4 while the qrItems were 0 (zero) when iterating through the {
"resourceType": "QuestionnaireResponse",
"id": "63f318a9-e10b-434d-b7c9-1e8137433042",
"meta": {
"lastUpdated": "2024-08-14T09:48:07.815+03:00"
},
"questionnaire": "Questionnaire/dc-clinic-medicines",
"status": "completed",
"subject": {
"reference": "Patient/5a88dce4-38f7-41a9-bd39-eb41142ae98e"
},
"authored": "2024-08-14T09:48:07+03:00",
"author": {
"reference": "Practitioner/a21decb7-ac90-43e1-926a-0579a46816ed"
},
"item": [
{
"linkId": "page-1",
"item": [
{
"linkId": "has-hypertension",
"answer": [
{
"valueBoolean": false
}
]
},
{
"linkId": "has-diabetes",
"answer": [
{
"valueBoolean": false
}
]
},
{
"linkId": "visit-date",
"text": "Visit date",
"answer": [
{
"valueDate": "2024-08-14",
"item": [
{
"linkId": "visit-date-hint",
"text": "Visit date"
}
]
}
]
},
{
"linkId": "medicines-repeated-group",
"answer": [
{
"item": [
{
"linkId": "medicine",
"answer": [
{
"valueReference": {
"reference": "Medication/dc-med-00202901",
"display": "Losartan"
},
"item": [
{
"linkId": "medicine-hint",
"text": "Medicine"
}
]
}
]
},
{
"linkId": "dosage",
"answer": [
{
"valueCoding": {
"id": "10_mg",
"system": "https://smartregister.org/fhir/CodeSystem/dc-medication-dosage",
"code": "10_mg",
"display": "10 mg"
},
"item": [
{
"linkId": "dosage-hint",
"text": "Dosage (mg)"
}
]
}
]
},
{
"linkId": "frequency",
"answer": [
{
"valueCoding": {
"id": "tds",
"system": "http://smartregister.org/",
"code": "tds",
"display": "TDS"
},
"item": [
{
"linkId": "frequency-hint",
"text": "Frequency"
}
]
}
]
},
{
"linkId": "notes"
}
]
},
{
"item": [
{
"linkId": "medicine",
"answer": [
{
"valueReference": {
"reference": "Medication/dc-med-00700601",
"display": "Mixtard insulin"
},
"item": [
{
"linkId": "medicine-hint",
"text": "Medicine"
}
]
}
]
},
{
"linkId": "insulin-dosage",
"answer": [
{
"valueInteger": 280,
"item": [
{
"linkId": "insulin-dosage-hint",
"text": "Dosage (IU)"
}
]
}
]
},
{
"linkId": "frequency",
"answer": [
{
"valueCoding": {
"id": "bd",
"system": "http://smartregister.org/",
"code": "bd",
"display": "BD"
},
"item": [
{
"linkId": "frequency-hint",
"text": "Frequency"
}
]
}
]
},
{
"linkId": "notes"
}
]
}
]
}
]
},
{
"linkId": "page-2",
"item": [
{
"linkId": "hypertension-diagnosis",
"text": "Add diagnosis for hypertension?",
"answer": [
{
"valueCoding": {
"id": "no-diagnosis",
"system": "http://smartregister.org/",
"code": "no-diagnosis",
"display": "No diagnosis"
}
}
]
},
{
"linkId": "diabetes-diagnosis",
"text": "Add diagnosis for diabetes?",
"answer": [
{
"valueCoding": {
"id": "diabetes-type-1-choice",
"system": "http://smartregister.org/",
"code": "diabetes-type-1",
"display": "Diabetes Type 1"
}
}
]
}
]
}
]
} |
@jingtang10 @allan-on What that function does is, if a response item is missing (because it's disabled by skip logic) the function should add an empty response item to ensure that the questionnaire item has it's corresponding response item. This function is executed when the questionnaire response is initially passed to the QuestionnaireViewModel. That way the above exception should not happen. |
@jingtang10 @MJ1998 implementers shouldn't be able to get the QR with packed repeated groups right(?) See QR example in point 2. I checked the latest code, it's not possible. It will always unpack. android-fhir/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireViewModel.kt Lines 458 to 469 in 603792f
@allan-on I'm not sure how you get a packed response, I'd say it's a malformed response. packed = nested items are in the |
The second issue is a bug on the OpenSRP side, and it has been fixed |
Describe the bug
This newly introduced requirement through #2618, fails and throws a
java.lang.IllegalArgumentException: Failed requirement
when loading a Questionnaire that has repeated groups, and populating it with values from the latest QuestionnaireResponse.The exception is thrown because when matching qItem and qrItem, the number of questionnaire items isn't equal to the number of questionnaire response items.
For repeated groups this observed in the following scenarios:
a. If a Questionnaire has a repeated group with one set of repeated items/fields:
If a field didn't have an answer because it was optional or it was hidden by an
enableWhen
expression then it is excluded from the Questionnaire response resulting in the QR with less itemsb. If a Questionnaire has a repeated group with several repeated items/fields:
The repeated group items are put in the answerItems in the QR and when iterating and pairing the qItems will have a size of the number of fields in the group while it appears in the iteration, the repeated group qrItems aren't being correctly retrieved
Component
SDC library
To Reproduce
Steps to reproduce the behavior:
See additional context in comments below
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
Would you like to work on the issue?
Please state if this issue should be assigned to you or who you think could help to solve this issue.
The text was updated successfully, but these errors were encountered: