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

fix: Skip mandatory data value validation for UPDATE [DHIS2-17560] #17835

Merged
merged 7 commits into from
Jul 2, 2024

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented Jun 19, 2024

Event update was failing when mandatory data values were not present in the payload even though they were already present in the DB.
Now tracker importer is validating mandatory data values only when creating an event.
Same logic is applied to SetMandatoryField rule action that is dynamically adding a mandatory check on a data value.

To resume, when strategy is create:
- If a mandatory data element is not provided, a validation error is returned
- If a mandatory data element is removed (set to null), a validation error is return. This is covered even if it doesn't really make sense to remove a data value when creating an event.

When strategy is update:
- If a mandatory data element is not provided, validation passes
- If a mandatory data element is removed (set to null), a validation error is return.

Statuses that allow to define data values are ACTIVE, COMPLETED or VISITED.
Statuses that DO NOT allow to define data values are SCHEDULE, SKIPPED or OVERDUE.

To resume, when strategy is create:

  • If a mandatory data element is not provided and the status allows data values, a validation error is returned
  • If a mandatory data element is removed (set to null) and the status allows data value, a validation error is returned.

When strategy is update:

  • If a mandatory data element is not provided and the status is being updated between a status that do not allow data values to one that allows them, a validation error is returned.
  • If a mandatory data element is not provided and the status is being updated between a status that allow data values to another one that allows them (also the same exact status), validation passes.
  • If a mandatory data element is removed (set to null) and the status allows data value, a validation error is return.

@enricocolasante enricocolasante requested a review from a team June 19, 2024 12:10
@enricocolasante enricocolasante marked this pull request as ready for review June 19, 2024 12:10
if (!needsToValidateDataValues(event, programStage)) {
return notPresentMandatoryDataElements;
return List.of();
Copy link
Contributor

Choose a reason for hiding this comment

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

out of the scope of this PR, but why do we skip the validation if the event status is SCHEDULE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A SCHEDULE event is created at some point in time but it is meant to happen later at some point, so when it is created it is kind of empty and it doesn't make sense to require mandatory data values at that point.

Copy link
Contributor

@muilpp muilpp Jun 20, 2024

Choose a reason for hiding this comment

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

and in that case, are we covered if I create and event this way, and then I provide the values later on?
what I mean by that is, at the moment I provide the values, do we treat it as an import strategy CREATE again to make sure all mandatory fields are set?

if it's something different than CREATE, then I guess I could have mandatory values set to null, couldn't I?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no, you are right.
At the moment if you create a schedule event without the mandatory datavalues and later you just change the status of the event then you can have an empty mandatory datavalues were they are meant to be present.

Will need to check how we manage the transition from a status to another

@enricocolasante enricocolasante requested a review from a team June 20, 2024 06:49
@muilpp muilpp self-requested a review June 20, 2024 08:51
Copy link
Contributor

@muilpp muilpp left a comment

Choose a reason for hiding this comment

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

waiting for the scheduled events implementation

@enricocolasante enricocolasante marked this pull request as draft July 2, 2024 10:58
@enricocolasante enricocolasante marked this pull request as ready for review July 2, 2024 12:26
@enricocolasante enricocolasante enabled auto-merge (squash) July 2, 2024 12:39
Copy link

sonarcloud bot commented Jul 2, 2024

}

return notPresentMandatoryDataElements;
EventStatus savedStatus = bundle.getPreheat().getEvent(event.getUid()).getStatus();
return EventStatus.STATUSES_WITHOUT_DATA_VALUES.contains(savedStatus)
Copy link
Contributor

Choose a reason for hiding this comment

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

do the event statuses OVERDUE and SKIPPED also need to be considered here? or SCHEDULE would be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they do. They have the exact same behaviour as SCHEDULE events, so we need to check them to be sure we are in a consistent state

@enricocolasante enricocolasante merged commit 59e8956 into master Jul 2, 2024
15 checks passed
@enricocolasante enricocolasante deleted the DHIS2-17560 branch July 2, 2024 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants