-
Notifications
You must be signed in to change notification settings - Fork 251
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
Migrating Validation Result logic from View factory to QuestionnaireViewModel #1468
Conversation
@jingtang10 can you please review. As discussed last week I had created a separate PR for the validationResult changes, removed validation being instantiated on View Factory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just a small comment, Is there a unit test you can write to verify that validation is takes place in getQuestionnaireState function?
… should not be null when instantiating questionnaireItemViewItem
Did update one of the unit tests where list of questionnaireItemViewItem is getting generated |
please fix the failing tests |
…e it gets created from the view model
I tried to fix some of the unit tests by triggering validation for the first time in the view factory* (in bind method), the problem is we need to fix #1427 first so on each interaction (when onAnswerChanged calls) there will be a new list of questionnaireItemViewItem along with the validationResult that gets generated by the View Model (in the getQuestionnaireState method) and we need to refresh the list so new validationResult can be reflected on the views. @jingtang10 @f-odhiambo |
.../google/android/fhir/datacapture/views/QuestionnaireItemAutoCompleteViewHolderFactoryTest.kt
Show resolved
Hide resolved
With the patch in #1486 collect gets triggered as expected. The two issues raised by @aurangzaibumer are , please add any details that I missed:
cc : @jingtang10 |
Thanks @joiskash, you have covered everything. So these are the issues i'm currently facing which is kind of a blocker to #1301 as well because that PR needs a validation in order to work for a PRIOR_EDIT Pagination (one of the entry mode). So we need to keep the state of the modified field and to reflect the ValidationResult (that was captured from the QuestionnaireViewModel) to the UI level without refreshing the whole screen |
This turned out to be major rewrite of the library. In order for questionnaire item comparison to actually work, the way we create See documentation in the The ansers are then used for comparison with what's already in the questionnaire to decide how the recycler view UI should be updated. This results in changes in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial feedback
datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireViewModel.kt
Outdated
Show resolved
Hide resolved
datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireViewModel.kt
Show resolved
Hide resolved
datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireViewModelTest.kt
Outdated
Show resolved
Hide resolved
.../google/android/fhir/datacapture/views/QuestionnaireItemAutoCompleteViewHolderFactoryTest.kt
Show resolved
Hide resolved
...capture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemViewItem.kt
Outdated
Show resolved
Hide resolved
...java/com/google/android/fhir/datacapture/views/QuestionnaireItemEditTextViewHolderFactory.kt
Outdated
Show resolved
Hide resolved
...capture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemViewItem.kt
Outdated
Show resolved
Hide resolved
...capture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemViewItem.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is 👌👌👌👌👌👌👌👌👌
return questionnaireResponse | ||
.item | ||
.map { it.getQuestionnaireResponseItemComponent(linkId) } | ||
.firstOrNull() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jingtang10 I could not figure out the recursion here when finding the item by linkId. Could you please confirm that this method would find the item even at 10th level inside hierarchy.
item[index]: {
linkId: 1
answer.value -> value
answer.item -> list of another nested 'item' with answer and items
}
So lets say inside linkId:1 there is item linkId=1.1.1.1 at fourth level .. would it find it with this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this function does is to look for the first item (DFS) in the questionnaire response with a certain link id. it doesn't concat the string or anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #1496
return this | ||
} | ||
|
||
val child = item.firstOrNull { it.linkId == linkId } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jingtang10 , I think @maimoonak wanted to add a comment on this method.
Here we are checking only one level down in the descendants but there is no recursion to check for all the levels down in the hierarchy (Let's say if we have 10 levels of nesting). What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah you're right.
will send a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #1496
I was testing the behavior after the latest changes, the validation error shows (if applicable) when focus is switched to next UI element. I did test on emulator (Pixel 5 API 31). Previously it used to be running like runtime (while we have focus on the same view). Is this the final desired behavior or please correct me If I'm wrong? Thanks cc @jingtang10 @f-odhiambo @maimoonak @shoaibmushtaq25 latestchange.mp4 |
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Description
Clear and concise code change description.
Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?
Type
Choose one: Improvement
Screenshots (if applicable)
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project../gradlew check
and./gradlew connectedCheck
to test my changes locally.