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

Update Customize-how-a-Questionnaire-is-displayed.md #2577

Closed
wants to merge 2 commits into from

Conversation

MJ1998
Copy link
Collaborator

@MJ1998 MJ1998 commented Jun 20, 2024

Update documentation for custom widget support.

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #[issue number]

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: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • 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 demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

Update documentation for custom widget support.
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 jajoo for fixing our doc!

@aditya-07 made some changes to the custom widget mechanism. @aditya-07 can you also review this doc change? thanks

3. When rendering your questionnaire, use your custom implementation of
<code>QuestionnaireFragment</code> instead.
### 1. Create a factory of custom ViewHolderFactoryMatchersProvider
Develop a class that implements the [QuestionnaireItemViewHolderFactoryMatchersProviderFactory](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt#L563) interface. This class acts as a registry for associating custom widgets with their corresponding view holder factories. ([example](https://github.com/google/android-fhir/blob/master/catalog/src/main/java/com/google/android/fhir/catalog/ContribQuestionnaireItemViewHolderFactoryMatchersProviderFactory.kt))
Copy link
Collaborator

Choose a reason for hiding this comment

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

your first link goes to QuestionnaireItemViewHolderFactoryMatchersProvider instead of QuestionnaireItemViewHolderFactoryMatchersProviderFactory. please correct it.

this class actually doesn't act as a registry. it just produces matchers. the registry bit is in the next step.

### 2. Register the above factory with datacapture library via DataCaptureConfig
Within your [DataCaptureConfig](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/datacapture/src/main/java/com/google/android/fhir/datacapture/DataCaptureConfig.kt#L35) object, assign the custom factory matchers provider to the `questionnaireItemViewHolderFactoryMatchersProviderFactory` property. This step makes your provider available for resolving view holders during questionnaire rendering. ([example](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/catalog/src/main/java/com/google/android/fhir/catalog/CatalogApplication.kt#L42C5-L47C8))

### 3. Configure the QuestionnaireFragment Builder
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
### 3. Configure the QuestionnaireFragment Builder
### 3. Use the custom matcher in the QuestionnaireFragment

Within your [DataCaptureConfig](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/datacapture/src/main/java/com/google/android/fhir/datacapture/DataCaptureConfig.kt#L35) object, assign the custom factory matchers provider to the `questionnaireItemViewHolderFactoryMatchersProviderFactory` property. This step makes your provider available for resolving view holders during questionnaire rendering. ([example](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/catalog/src/main/java/com/google/android/fhir/catalog/CatalogApplication.kt#L42C5-L47C8))

### 3. Configure the QuestionnaireFragment Builder
When constructing your QuestionnaireFragment using the builder pattern, utilize the `setCustomQuestionnaireItemViewHolderFactoryMatchersProvider` method. Provide the appropriate string identifier to specify which custom widgets to use. ([example](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/catalog/src/main/java/com/google/android/fhir/catalog/DemoQuestionnaireFragment.kt#L142C13-L150C23))
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
When constructing your QuestionnaireFragment using the builder pattern, utilize the `setCustomQuestionnaireItemViewHolderFactoryMatchersProvider` method. Provide the appropriate string identifier to specify which custom widgets to use. ([example](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/catalog/src/main/java/com/google/android/fhir/catalog/DemoQuestionnaireFragment.kt#L142C13-L150C23))
When constructing your QuestionnaireFragment using the builder pattern, call the `setCustomQuestionnaireItemViewHolderFactoryMatchersProvider` method with the appropriate string identifier to specify which custom widgets to use. ([example](https://github.com/google/android-fhir/blob/ced8527a5481972591615ad4364487e89130fb6e/catalog/src/main/java/com/google/android/fhir/catalog/DemoQuestionnaireFragment.kt#L142C13-L150C23))

2. matches: A predicate function which, given a
[`Questionnaire.QuestionnaireItemComponent`](https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-r4/org/hl7/fhir/r4/model/Questionnaire.QuestionnaireItemComponent.html), returns true if the factory should apply to that item.

### 2. Register the above factory with datacapture library via DataCaptureConfig
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
### 2. Register the above factory with datacapture library via DataCaptureConfig
### 2. Register the factory with datacapture library

@MJ1998
Copy link
Collaborator Author

MJ1998 commented Jun 20, 2024

Closing this as the PR is moved to #2580

@MJ1998 MJ1998 closed this Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

2 participants