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

Re populate questionnaire response ID when removing unanswered questions #3614

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@
)
?.let {
QuestionnaireResponse().apply {
id = it.id

Check warning on line 1166 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt#L1166

Added line #L1166 was not covered by tests
item = it.item.removeUnAnsweredItems()
// Clearing the text prompts the SDK to re-process the content, which includes HTML
clearText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,87 @@ class QuestionnaireViewModelTest : RobolectricTest() {
Assert.assertTrue(result.first!!.find("linkid-1") == null)
}

@Test
fun testThatPopulateQuestionnaireReturnsQuestionnaireResponseWithIdValue() = runTest {
val questionnaireViewModelInstance =
QuestionnaireViewModel(
defaultRepository = defaultRepository,
dispatcherProvider = dispatcherProvider,
fhirCarePlanGenerator = fhirCarePlanGenerator,
resourceDataRulesExecutor = resourceDataRulesExecutor,
transformSupportServices = mockk(),
sharedPreferencesHelper = sharedPreferencesHelper,
fhirOperator = fhirOperator,
fhirValidatorRequestHandlerProvider = fhirValidatorRequestHandlerProvider,
fhirPathDataExtractor = fhirPathDataExtractor,
configurationRegistry = configurationRegistry,
)
val questionnaireConfig1 =
questionnaireConfig.copy(
resourceType = ResourceType.Patient,
resourceIdentifier = patient.logicalId,
type = QuestionnaireType.EDIT.name,
)

val questionnaireWithInitialValue =
Questionnaire().apply {
id = questionnaireConfig1.id
addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "group-1"
type = Questionnaire.QuestionnaireItemType.GROUP
addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "linkid-1"
type = Questionnaire.QuestionnaireItemType.STRING
addInitial(Questionnaire.QuestionnaireItemInitialComponent(StringType("---")))
},
)
},
)

addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "linkid-2"
type = Questionnaire.QuestionnaireItemType.STRING
},
)
}
val qrId = "qr-id-1"
val questionnaireResponse =
QuestionnaireResponse().apply {
id = qrId
addItem(
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply {
linkId = "group-1"
addItem(
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply {
linkId = "linkid-1"
},
)
},
)
}
coEvery {
fhirEngine.get(questionnaireConfig1.resourceType!!, questionnaireConfig1.resourceIdentifier!!)
} returns patient

coEvery { fhirEngine.search<QuestionnaireResponse>(any<Search>()) } returns
listOf(
SearchResult(questionnaireResponse, included = null, revIncluded = null),
)

Assert.assertNotNull(questionnaireResponse.find("linkid-1"))
val result =
questionnaireViewModelInstance.populateQuestionnaire(
questionnaireWithInitialValue,
questionnaireConfig1,
emptyList(),
)
Assert.assertNotNull(result.first)
Assert.assertEquals(qrId, result.first!!.id)
}

@Test
fun testExcludeNestedItemFromQuestionnairePrepopulation() {
val item1 = QuestionnaireResponse.QuestionnaireResponseItemComponent().apply { linkId = "1" }
Expand Down
Loading