aehrc / smart-forms

React-based form renderer implementing Structured Data Capture (SDC) FHIR specification
https://smartforms.csiro.au
Apache License 2.0
35 stars 14 forks source link

Response validity feedback from renderer #622

Closed nielmdrec closed 1 month ago

nielmdrec commented 8 months ago

When we receive the QuestionnaireResponse from the renderer (e.g. via getResponse()), it would be quite helpful to know if the response form is valid in terms of having answers for each of the questions (items) which are required in the Questionnaire.

For example, if our Questionnaire has 5 questions and 4 of those questions have item.required = true, we would like to know if those 4 required questions (at least) are answered before saving the QuestionnaireResponse to our database.

In theory we could do this by adding our own variable in the Questionnaire and setting it to 'true' ourselves when all required questions are answered. However this would mean each of our Questionnaires needs to support this variable (and it becomes a proprietary feature for our Questionnaires only).

fongsean commented 7 months ago

Hi Niel, that's definitely a good feature to have and honestly should have been included early. I'll start working on it and hope it can be delivered before the end of the week.

nielmdrec commented 7 months ago

Thanks, Sean. We look forward to having this feature. Glad you think it would be useful too.

nielmdrec commented 7 months ago

BTW, Sean, for this feature would it be possible to have the mandatory questions marked by say an asterisk (*)? (Or should I raise that in a separate item?)

fongsean commented 7 months ago

Hi Niel, that's definitely a part of my consideration! I'm trying to think of a best way to present visual cues. No need to raise in a separate item.

To extend my thoughts further.... instead of retrieving the "validated" status via getResponse(), I think it will be more robust if it an be exposed via the state event listeners i.e. const isValid = useQuestionnaireResponseStore.use.isValid(). That way, it won't be tied to a button click.

I might also expose a listener to see what linkIds are failing validation if that is beneficial. Might also help verify if the required check is working properly on all items (it can get a bit complicated when working with repeat groups with further nested items)

fongsean commented 7 months ago

Feel free to refer to https://github.com/aehrc/smart-forms/pull/634#issue-2141636314 for changes up until now. It's deployed as @aehrc/smart-forms-renderer v0.13.1.

Any thoughts on the bugs + future tasks?

adha-admin commented 5 months ago

Hi Sean, Been chatting with Brian and he suggests you return the linkIds are failing validation using an OperationOutcome Resource. Code example here:

https://github.com/brianpos/fhir-net-web-api/blob/develop/src/Hl7.Fhir.StructuredDataCapture/QuestionnaireResponseValidator.cs

Cheers Philip Wilford ADHA

fongsean commented 5 months ago

Hi Phil,

Thanks for that. That definitely is a good idea to align more with FHIR.

Will replace the invalid items array with an array of operationOutcomes. I'll have to track down which business rules/validation errors the UI is currently enforcing and get that in as well i.e regex, minLength, maxLength, etc

adha-admin commented 5 months ago

Hi Sean,

1) Can we have a <- Previous Tab button? 2) Do you do any validation on decimals?

                        "extension": [
                            {
                                "url": "http://hl7.org/fhir/StructureDefinition/maxDecimalPlaces",
                                "valueInteger": 2
                            },
                            {
                                "url": "http://hl7.org/fhir/StructureDefinition/minValue",
                                "valueInteger": 0
                            },
                            {
                                "url": "http://hl7.org/fhir/StructureDefinition/maxValue",
                                "valueInteger": 300
                            }
                        ],
                        "linkId": "group-1-check-1",
                        "text": "Height (cm)",
                        "type": "decimal"

Cheers Philip Wilford ADHA

fongsean commented 5 months ago

Hi Phil,

  1. Yes, I'll add that to the feature list. It should be using the same logic as next tab, except going for a -1 instead of a +1.
  2. I don't think there is validation for maxDecimalPlaces. Happy to add that as another upcoming feature.

Cheers Sean

fongsean commented 5 months ago

Hi all, made a few changes over the past week + weekend:

@nielmdrec if you are consuming the invalidItems for validation, you might need to tweak up your implementation for a bit. Old invalidItems is a key value pair of <linkId, type-of-error (string)> where type of error can be "required", "regex", "maxLength" or "minLength". It's now <linkId, OperationOutcome>.

Will continue to make progress on other feature requests/bugs early this week.

fongsean commented 1 month ago

Closing this issue given that all of the items are resolved.