-
Notifications
You must be signed in to change notification settings - Fork 249
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
Validation API for SDC #548
Conversation
0da4fd1
to
a9f7bf3
Compare
datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt
Outdated
Show resolved
Hide resolved
datacapture/src/main/java/com/google/android/fhir/datacapture/validation/ConstraintValidator.kt
Outdated
Show resolved
Hide resolved
...in/java/com/google/android/fhir/datacapture/validation/QuestionnaireResponseItemValidator.kt
Outdated
Show resolved
Hide resolved
…validation/ConstraintValidator.kt Co-authored-by: Jing Tang <jing.t86@gmail.com>
Hi @joiskash, it seems changes are pending for this PR. Is there an ETA by when these can be ready for review? |
I have actually requested a review after the last round of review. Not sure if its not showing up properly |
Thanks @joiskash Not sure if you need to dismiss or approve the previous review etc. Odd. |
Yea.. i maybe doing something wrong. Ill pay more attention next time. Sorry for the inconvenience |
import org.hl7.fhir.r4.model.Questionnaire | ||
import org.hl7.fhir.r4.model.QuestionnaireResponse | ||
|
||
object QuestionnaireValidator { |
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.
Questionnaire Response Validator maybe? Since it's validating the response.
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.
done
@@ -66,6 +66,9 @@ class QuestionnaireFragment : Fragment() { | |||
// Returns the current questionnaire response | |||
fun getQuestionnaireResponse() = viewModel.getQuestionnaireResponse() | |||
|
|||
// Returns the current questionnaire | |||
fun getQuestionnaire() = viewModel.getQuestionnaire() |
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.
feel this can be a property ie
val questionnaire = viewModel.questionnaire
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.
done
@@ -88,6 +88,9 @@ internal class QuestionnaireViewModel(state: SavedStateHandle) : ViewModel() { | |||
internal val questionnaireItemViewItemListFlow: Flow<List<QuestionnaireItemViewItem>> = | |||
modificationCount.map { questionnaireItemViewItemList } | |||
|
|||
/** The current [Questionnaire] . */ | |||
fun getQuestionnaire(): Questionnaire = questionnaire |
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.
just change the property to internal?
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.
done
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.
you can remove this getter function altogether!
QuestionnaireResponseItemValidator.validate(questionnaireItem, questionnaireResponseItem) | ||
) | ||
if (questionnaireItem.hasNestedItemsWithinAnswers) { | ||
// TODO(https://github.com/google/android-fhir/issues/487): Validates all answers. |
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 doesn't seem very difficult to do in this PR? can you just do 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.
Well the issue is that I am reusing the validators which are used in QuestionnaireResponseItemValidator
which all handle only single answer. I can make those changes in this PR if you want.
eg: Have a look at ValueConstraintExtensionValidator
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.
oh yeah that's right -- sure this makes sense.
@@ -55,7 +55,7 @@ class MaxValueConstraintValidatorTest { | |||
MaxValueConstraintValidator.validate(questionnaireItem, questionnaireResponseItem) | |||
|
|||
assertThat(validationResult.isValid).isFalse() | |||
assertThat(validationResult.message.equals("Maximum value allowed is:200000")).isTrue() | |||
assertThat(validationResult.message?.equals("Maximum value allowed is:200000")).isTrue() |
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.
assertThat(validationResult.message?.equals("Maximum value allowed is:200000")).isTrue() | |
assertThat(validationResult.message!!).isEqualTo("Maximum value allowed is:200000") |
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.
done
) | ||
) | ||
val result = QuestionnaireValidator.validate(questionnaire.item, questionnaireResponse.item) | ||
assertEquals( |
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.
use truth:
assertThat(...).isEqualTo()
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.
done
I have addressed the comments. It still shows as changes requested.
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.
Thanks @joiskash! 🎉
@@ -88,6 +88,9 @@ internal class QuestionnaireViewModel(state: SavedStateHandle) : ViewModel() { | |||
internal val questionnaireItemViewItemListFlow: Flow<List<QuestionnaireItemViewItem>> = | |||
modificationCount.map { questionnaireItemViewItemList } | |||
|
|||
/** The current [Questionnaire] . */ | |||
fun getQuestionnaire(): Questionnaire = questionnaire |
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.
you can remove this getter function altogether!
fun validate( | ||
questionnaireItemList: List<Questionnaire.QuestionnaireItemComponent>, | ||
questionnaireResponseItemList: List<QuestionnaireResponse.QuestionnaireResponseItemComponent> | ||
): Map<String, List<ValidationResult>> { | ||
val questionnaireItemListIterator = questionnaireItemList.iterator() | ||
val questionnaireResponseItemListIterator = questionnaireResponseItemList.iterator() | ||
while (questionnaireItemListIterator.hasNext() && | ||
questionnaireResponseItemListIterator.hasNext()) { | ||
val questionnaireItem = questionnaireItemListIterator.next() | ||
val questionnaireResponseItem = questionnaireResponseItemListIterator.next() | ||
linkIdToValidationResultMap[questionnaireItem.linkId] = mutableListOf() | ||
linkIdToValidationResultMap[questionnaireItem.linkId]?.add( | ||
QuestionnaireResponseItemValidator.validate(questionnaireItem, questionnaireResponseItem) | ||
) | ||
if (questionnaireItem.hasNestedItemsWithinAnswers) { | ||
// TODO(https://github.com/google/android-fhir/issues/487): Validates all answers. | ||
validate(questionnaireItem.item, questionnaireResponseItem.answer[0].item) | ||
} | ||
validate(questionnaireItem.item, questionnaireResponseItem.item) | ||
} | ||
return linkIdToValidationResultMap | ||
} |
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.
don't have to do this in this PR - but you can probably create an iterator for questionnaire item + questionnaire response item. this logic is repeated in the questionnaire view model as well.
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.
sure ill put a comment so that it is done while handling repeated answers
assertThat(result.get("a-question")) | ||
.isEqualTo( | ||
listOf( | ||
ValidationResult( | ||
false, | ||
listOf("The maximum number of characters that are permitted in the answer is: 3") | ||
) | ||
) | ||
) | ||
} |
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.
assertThat(result.get("a-question")) | |
.isEqualTo( | |
listOf( | |
ValidationResult( | |
false, | |
listOf("The maximum number of characters that are permitted in the answer is: 3") | |
) | |
) | |
) | |
} | |
assertThat(result.get("a-question")) | |
.containsExactly( | |
ValidationResult( | |
false, | |
listOf("The maximum number of characters that are permitted in the answer is: 3") | |
) | |
) | |
} |
...st/java/com/google/android/fhir/datacapture/validation/QuestionnaireResponseValidatorTest.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jing Tang <jing.t86@gmail.com>
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Fixes #374
Description
Expose external api for developers to validate the questionnaire response using the SDC library
Type
Feature
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