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

Validation API for SDC #548

Merged
merged 23 commits into from
Jun 22, 2021
Merged

Validation API for SDC #548

merged 23 commits into from
Jun 22, 2021

Conversation

joiskash
Copy link
Collaborator

@joiskash joiskash commented Jun 14, 2021

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

  • I have read and acknowledged the Code of conduct
  • I have read How to Contribute
  • I have read the Developer's guide
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally
  • I have built and run the reference app(s) to verify my change fixes the issue and/or does not break the reference app(s)

@joiskash joiskash requested a review from jingtang10 June 16, 2021 11:18
@Tarun-Bhardwaj
Copy link

Hi @joiskash, it seems changes are pending for this PR. Is there an ETA by when these can be ready for review?

@joiskash
Copy link
Collaborator Author

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

@joiskash joiskash requested review from jingtang10 and removed request for jingtang10 June 18, 2021 07:25
@jingtang10
Copy link
Collaborator

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.

@joiskash
Copy link
Collaborator Author

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

@Tarun-Bhardwaj Tarun-Bhardwaj added this to the Q2 June 2021 milestone Jun 19, 2021
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.QuestionnaireResponse

object QuestionnaireValidator {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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()
Copy link
Collaborator

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

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

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.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertThat(validationResult.message?.equals("Maximum value allowed is:200000")).isTrue()
assertThat(validationResult.message!!).isEqualTo("Maximum value allowed is:200000")

Copy link
Collaborator Author

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use truth:

assertThat(...).isEqualTo()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@joiskash joiskash requested a review from jingtang10 June 21, 2021 18:06
@joiskash joiskash dismissed jingtang10’s stale review June 21, 2021 18:07

I have addressed the comments. It still shows as changes requested.

Copy link
Collaborator

@jingtang10 jingtang10 left a 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
Copy link
Collaborator

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!

Comment on lines 32 to 53
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
}
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

@joiskash joiskash enabled auto-merge (squash) June 22, 2021 09:41
Comment on lines +87 to +96
assertThat(result.get("a-question"))
.isEqualTo(
listOf(
ValidationResult(
false,
listOf("The maximum number of characters that are permitted in the answer is: 3")
)
)
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
)
)
}

@joiskash joiskash disabled auto-merge June 22, 2021 10:11
joiskash and others added 2 commits June 22, 2021 15:42
Co-authored-by: Jing Tang <jing.t86@gmail.com>
@jingtang10 jingtang10 enabled auto-merge (squash) June 22, 2021 10:47
@jingtang10 jingtang10 merged commit b6950ae into master Jun 22, 2021
@jingtang10 jingtang10 deleted the kj/validation-api branch June 22, 2021 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

API for validation in the sdc lib
3 participants