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

Prefill the questionnaire with an optional questionnaire response as an argument to the questionnaire fragment #189

Closed
jingtang10 opened this issue Jan 27, 2021 · 12 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed type:enhancement New feature or request

Comments

@jingtang10
Copy link
Collaborator

This can be used to pre-fill the questionnaire while generating the UI.

@jingtang10 jingtang10 added the type:enhancement New feature or request label Jan 27, 2021
@jingtang10 jingtang10 added this to To do in Data capture library via automation Jan 27, 2021
@jingtang10 jingtang10 added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 6, 2021
@joiskash
Copy link
Collaborator

joiskash commented Feb 9, 2021

#227

@jingtang10 jingtang10 changed the title Add an optional questionnaire response to the questionnaire fragment Prefill the questionnaire with an optional questionnaire response as an argument to the questionnaire fragment Feb 9, 2021
@joiskash joiskash self-assigned this Feb 10, 2021
@joiskash joiskash moved this from To do to In progress in Data capture library Feb 10, 2021
@joiskash
Copy link
Collaborator

The order of questions within groups, groups within groups and groups within questions is relevant and must be retained for display and capture. The hierarchy items within the Questionnaire SHALL mirror the hierarchy of the corresponding Questionnaire (if any).

This allows us to assume that the QuestionnaireResponse structure will be corresponding to the Questionnaire from which it is derived. If there is a mismatch in the hierarchy the SDK will throw an error since in the context of SDC, the QuestionnaireResponse will always have a corresponding Questionnaire

@joiskash
Copy link
Collaborator

joiskash commented Feb 12, 2021

@jingtang10 so the plan is to

  1. Introduce val questionnaireResponseJson in the gallery\QuestionnaireViewModel
  2. Pass the questionnaireResponseJson as String? since it is optional to the Fragment arguments
  3. In datacapture\QuestionnaireViewModel introduce a private fun Questionnaire.validateQuestionnaireResponse( questionnaireResponse : QuestionnaireResponse ) which will check and make sure that the hierarchy items within the Questionnaire SHALL mirror the hierarchy of the corresponding Questionnaire.
    What exception should be thrown if there is a mismatch in the structure?
  4. In the second init block in datacapture\QuestionnaireViewModel I will introduce a check and see if state["QuestionnaireFragment.BUNDLE_KEY_QUESTIONNAIRE_RESPONSE"] not null then parse the questionnaireResponseJson and get the object questionnaireResponse
  5. questionnaireResponseBuilder.addAllItem(questionnaireResponseJson.itemList) instead of the foreach block

Let me know if this is fine, I will start coding after your comments

@jingtang10
Copy link
Collaborator Author

thanks @joiskash.

so in step 4 you will use the validate method if a questionnnaire response is provided right?

So basically, if there is a questionnaire respoonse provided, validate it, if not, create a new one mirroring the structure (existing code).

@joiskash
Copy link
Collaborator

thanks @joiskash.

so in step 4 you will use the validate method if a questionnnaire response is provided right?

So basically, if there is a questionnaire respoonse provided, validate it, if not, create a new one mirroring the structure (existing code).

Yes that's right

@joiskash
Copy link
Collaborator

@jingtang10 If the structure of the questionnaire response provided does not match the questionnaire then should the library throw an error? or just warn the user?
And what error should be thrown if any?

@jingtang10
Copy link
Collaborator Author

I would rather for the library to throw an illegal argument exception than to swallow that issue.

@joiskash
Copy link
Collaborator

While validating is it fair to say that the order of the occurrence of item in the questionnaire will be the same in the questionnaire response?
eg if in the json string of the questionnaire linkid 1 is followed by 2 and in the json string of the questionnaire response linkid 2 is followed by 1. Should this throw an error or is this acceptable?

@jingtang10
Copy link
Collaborator Author

jingtang10 commented Feb 19, 2021 via email

@jingtang10
Copy link
Collaborator Author

@joiskash can this be closed or is there something else you're still working on?

@joiskash
Copy link
Collaborator

This can be closed thanks :)

@jingtang10
Copy link
Collaborator Author

thanks and well done for resolving this issue.

Data capture library automation moved this from In progress to Done Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed type:enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

2 participants