Repository navigation
Align device enableWhen with the pair rules for units, time zones, unknown sources and long chains - #180
Draft
PSchmiedmayer wants to merge 6 commits into
Conversation
A response exported from the device is now decided by the pair rules as the device decided it while the participant answered. Quantity conditions carry the unit identity of a FHIR answerQuantity (system, code, unit text). The device records an answer's unit with the rule the response export uses (RecordedQuantityUnit), and orders it against the condition with the pair rules' unit rule. A unit code without a system takes the question's system or counts as text (qty-3), also in the exported response. A dateTime condition keeps its time zone and fractional seconds on import and is exported with its zone; one with a time and no zone is not exported. Time values keep their fraction of a second on import and export. The device places every task occurrence from the stored responses in document order, as the pair rules place items, and evaluates the occurrences a condition depends on with an explicit stack, so long condition chains do not depend on the thread stack. The placement and the cycle set are kept on the root for one revision. Cycles are decided from the questionnaire structure over conditions that can be evaluated, as in the pair rules. The answers of a question whose enablement is unknown count as absent, as the export omits it. A follow-up task's enablement includes its choice task's, so a condition on a follow-up of a choice task that is disabled for good is settled.
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Conditions read occurrences through the readable index, so the flag on each occurrence was assigned and never read, which dead code analysis reports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
♻️ Current situation & Problem
#175 makes the form's enablement logic in
GroveQuestionnaireand the pair rules ofPairValidatorinGroveQuestionnaireFHIRevaluateenableWhenby FHIR R4. A response exported from the device should be decided by the pair rules exactly as the device decided it while the participant answered. Otherwise the device hides a required question that the server expects, or shows one the server rejects as disabled. Five cases still differed:Quantityrecords them: code and system, unit text where there is no code, and no unit only with no unit. The form reduced the condition to oneunitCodestring that mixed code and display text, and it dropped the system. A condition with the unit textkilogramtherefore never matched a question codedkgwith that display, and a condition in another system matched by code alone. A coded unit without a system was also exported as aQuantitywith a code and no system, which qty-3 forbids.dateTimecondition such as2024-03-05T10:00:00+05:00kept the wall-clock time and dropped the offset and the fraction of a second. The form then compared 10:00 in the device's own zone, while the pair rules compared the instant 05:00 UTC. AdateTimecondition with a time could not be exported at all.!= trueholds and= truedoes not.⚙️ Release Notes
Quantity unit identity as FHIR records it.
Questionnaire.Condition.Value.quantitycarries the parts of a FHIRanswerQuantity:A code without a system takes the system the question gives that unit; without one, it counts as unit text, since FHIR records a unit code only together with its system. The form records an answer's unit with the same rule the export uses (
RecordedQuantityUnit, shared by both), and orders it against the condition with the pair rules' unit rule: a condition with a code orders answers with that code and, where it names one, that system; one with only unit text orders answers with that text; one without a unit orders answers without a unit. Every other combination leaves the comparison open. A response and a condition with a code but no system are exported with the unit as text. TheNumberQuestionoperators compare in the question's unit, code and display text.Date-time conditions keep their offset. Importing a
dateTimecondition with a time keeps its time zone and fractional seconds in theDateComponents, so the form compares the same instant as the pair rules. Time values keep their fractional seconds on import and export, in conditions, answer options, initial values and answers. Exporting adateTimecondition writes the time with its zone; a condition with a time and without a zone is not exported, since the instant it names would be open.The answers of a question that is not enabled count as absent. This now also holds where the question's enablement cannot be evaluated, as the exported response omits the question:
As in the pair rules, a task or group whose enablement depends on itself, through the tasks its conditions reference, the groups enclosing it, or the choice task it follows up on, cannot be evaluated. This is decided once per questionnaire from its structure. A condition that cannot be evaluated, such as one with a value of a type the question's answers do not have, closes no cycle and adds no dependency; a custom question kind compares every value itself. A follow-up task's enablement now includes that of its choice task, as an item's includes its enclosing item's in the pair rules.
Evaluation without recursion over tasks. For each evaluation, the form places every occurrence of every task in document order, from the stored responses: a follow-up task beneath every selected option, or once without answers while the choice task has no selection. It then evaluates the occurrences the gated task depends on with an explicit stack, dependencies first, so the length of a chain of conditions does not depend on the thread's stack. The placement is kept on the root
QuestionnaireResponsesfor as long as its revision stays, so a render pass places the occurrences once per container. In the container of an unselected option, where a follow-up task's condition can still be evaluated, the follow-up tasks also occur once without answers, as they do in the response.Settled follow-ups. A condition on a follow-up task is settled when the follow-up task is disabled for good, for example beneath a choice task that a settled condition disables, so progress no longer counts the gated task. An answer stored beneath a choice task that is disabled, but could still become enabled, leaves the condition unsettled.
Source changes.
Condition.Value.quantity(value:unitCode:)isquantity(value:system:code:unit:), with defaults for everything but the value.📚 Documentation
The documentation of
Questionnaire.Condition.Value.quantitydescribes the unit rule. Code comments describe the occurrence placement, the cycle rule and the explicit evaluation stack.✅ Testing
EnableWhenTests:quantityUnitIdentityAgreesWithThePairRules: a coded question, a question whose unit code has no system, and a question with unit options, against conditions by code and system, by code alone, by unit text, in another system (also with!=), without a unit, and in another unit option; each target is answered where the form enables it, andPairValidatorreports no disabled item and no missing required item on the exported pair;dateTimeConditionsKeepTheirTimeZone: an answer at 05:30 UTC against conditions with a+05:00offset, in UTC, and with a fraction of a second, checked againstPairValidatorin the same way, and the exported condition's zone and time;sourcesWithUnknownEnablementAreDecidedAsThePairRulesDo:!=,=andexistson a question on a dependency cycle, checked againstPairValidator;followUpsOfAPermanentlyDisabledChoiceAreSettled: a condition on the follow-up task of a choice task, unsettled while the choice task can still be enabled, also with a stored selection and answer beneath it, and settled once it is disabled for good;conditionsInAnUnselectedOptionReadTheOccurrenceWithoutAnswers:!=andnot hasResponseon a follow-up task, evaluated in the container of an option that is not selected;conditionsThatCannotBeEvaluatedCloseNoCycle: a condition with a value of another type between two tasks that reference each other;conditionsThatCannotBeEvaluatedAddNoDependency: the same tasks with a third one in a group whose condition reads one of them, so the result does not depend on which task is evaluated first;customKindsCompareEveryValueThemselves: an ordered comparison on a string against a custom question kind that orders its responses;longConditionChainsDoNotDependOnTheThreadStackreplacesmanyConditionalChoiceTasksEvaluateQuickly: 100 chained conditional choice tasks with answered follow-ups, evaluated for enablement and settledness on a thread with a 128 KB stack, under a time limit;quantityQuestionOperatorsCompareInTheirUnitexpects the operators to carry the question's unit system, code and display text.FHIRConformanceTests.exportedQuantitiesCarryTheirUnitSystembuilds its condition with the newquantity(value:code:)case.Code of Conduct & Contributing Guidelines
By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: