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

Extend enableWhen behavior in paperwork engine to handle date type items #1115

Open
imbenham opened this issue Feb 13, 2025 · 1 comment
Open
Assignees
Labels
dev-x developer experience enhancement New feature or request

Comments

@imbenham
Copy link
Contributor

imbenham commented Feb 13, 2025

We've run into a case where a user would like to conditionally enable fields based on wether some date-type field makes the patient older or younger than 18. This is a very reasonable use case that we should support. Currently we've only implemented the enableWhen handling on form values with string or boolean types. We can follow the existing pattern and extend the behavior to cover the date case (and dateTime case, for that matter) without much trouble. Let's do that.

(Note: we have actually implemented this sort of feature already, but in doing so took advantage of the fact that the Patient's dob was known prior to creating the QR, and simply pre-populated a hidden field with a boolean value (patient-over-18) to drive the conditional logic in the form component. This is a clever hack but doesn't really solve the legitimate case where the dob isn't known until some other field within the form is populated.)

@imbenham imbenham converted this from a draft issue Feb 13, 2025
@imbenham imbenham added enhancement New feature or request dev-x developer experience labels Feb 13, 2025
@szaccagni szaccagni assigned imbenham and unassigned szaccagni Feb 17, 2025
@imbenham imbenham moved this from Todo to Ready For Build in Ottehr Product Feb 18, 2025
@imbenham
Copy link
Contributor Author

This functionality has been added but isn't leveraged in any of the default paperwork at the moment. Instead of modifying the default paperwork I added a unit test suite covering the conditional behaviors defined in the paperwork between the built-in enableWhen prop and the custom Ottehr extensions.

In addition to enableWhen, a date-type condition can be used for any of the other existing conditional behaviors (requireWhen, textWhen, etc).

There are two ways a condition targeting a date field can be defined:

  1. using answerInteger - this will be interpreted as expressing a value in years, and the date value on the 'question' field will be evaluated by comparing the operator and a date {answerInteger} years from now. So given the example below, if the KEYS.triggers.date.primary field contains a date that is less than 18 years ago, the condition is satisfied, otherwise it is not satisfied.

{ question: KEYS.triggers.date.primary, operator: '<', answerInteger: 18, }

  1. using answerDate - this will be a straightforward comparison (using the operator in the operator field) of the trigger date and the date specified in answerDate. For instance, this condition will be true if the date store in KEYS.triggers.date.primary comes before Jan 1, 2021:

{ question: KEYS.triggers.date.primary, operator: '>=', answerDate: '2021-01-01', },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-x developer experience enhancement New feature or request
Projects
Status: Ready For Build
Development

No branches or pull requests

2 participants