Closed hmpf closed 1 year ago
One way: instead of having a magical BooleanQuestion in position 0, have a question type (subtype of BooleanQuestion?) that can only be used once per section (maybe with a fancy constraint?) that always is in position 1 if it exists. Then have section-skipping code that does not reuse the question-branching code, allowing for section.branching = False
. (This will complicate the question reordering code.)
Whether a section is skipped can be stored on an answerset in a separate field, maybe in addition to on AnswerSet.data, for speedier lookups.
Another way: decouple questions so that optional question parameters/attributes are stored in a separate table from ordinary questions: have an abstract model with two non-abstract children: the regular Question and an OptionalSectionQuestion that is positionless and has a one-to-one key to its section instead of a foreign key. (The existence of such a question would then mark the section as optional.) Perhaps instead the section could have a one-to-one key to the OptionalSectionQuestion.
Again: the skipped-status can be stored on the AnswerSet.
Adding a skipped-field to AnswerSet has already proven very useful, so it might be possible to do the rest equally stepwise. Next step is probably to disentangle optional sections from branching.
Considering repeatable sections, having a magic question is probably wrong regardless, since some sections can be answered more than once. Latest plan: drop the magical question from the template and replace it with buttons for "make another" if repeatable, "skip" or similar for optional. There is always at least one answerset, and this records whether an answerset is skipped or not.
Potential tricky-ness: only one skipped answerset per section per plan, so do the skipped as a "date that can be null" trick again? Also, if a repeatable section with n non-skipped answerset, ensure there is no skipped answerset for the same section.
Closed by v1.27.0. Old system removed in 1.26.0, it wasn't in use in production templates.
Currently, optional sections abuse branching and positioning: a magical BooleanQuestion with position 0 has its answer stored in
data
as usual, on a section that is branching. This gets rather complex. It also means that if there are no other branches in the section (so an optional linear section), the full branching machinery will still be used.With answersets and the newest additions to the positioning-system there are multiple ways to improve this.