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

chore: Validate completedAt for Event and Enrollment [DHIS2-18222] #18881

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented Oct 21, 2024

This PR fixes the logic around completion of enrollments and events.

Enrollments
A saved enrollment follows these rules:

  • When an enrollment has status COMPLETED, fields completedAt and completedBy must be populated
  • When an enrollment has status CANCELLED, fields completedAt must be populated and completedBy must be null
  • When an enrollment has status ACTIVE, fields completedAt and completedBy must be null

Events
A saved event follows these rules:

  • When an event has status COMPLETED, fields completedAt and completedBy must be populated
  • When an event has status that is not COMPLETED, fields completedAt and completedBy must be null

Fields logic

completedBy is always calculated by the system, if required by the status, and it will be set to current user.
completedAt is set by the client or calculated by the system if not present, only when the status required it. The use case for it is Android sync where an event/enrollment is completed on day X and the sync happens on day Y, we still want completedAt to be X.

completedBy and completedAt are set only if the status is changing. Otherwise, the value for those fields present in the DB will not be updated.

If the status do not require completedAt field to be set but the client set it, a validation error is returned.

@enricocolasante enricocolasante marked this pull request as ready for review October 22, 2024 08:30
@enricocolasante enricocolasante requested a review from a team as a code owner October 22, 2024 08:30
@teleivo
Copy link
Contributor

teleivo commented Oct 22, 2024

completedAt

Completed events/enrollments can transition to other states again right? Does this logic you describe then apply in the same way if an event was previously completed?

@enricocolasante
Copy link
Contributor Author

completedAt

Completed events/enrollments can transition to other states again right? Does this logic you describe then apply in the same way if an event was previously completed?

Yes, I updated the description to state that the completed fields are updated only if there is a transition.
So, if a completed event is updating one data element and it is not setting the completedAt field, the old completedAt previously calculated by the system will still be in the DB and it will not be updated.

@enricocolasante enricocolasante enabled auto-merge (squash) October 22, 2024 10:00
Copy link

@enricocolasante enricocolasante merged commit d2d5028 into master Oct 22, 2024
14 checks passed
@enricocolasante enricocolasante deleted the DHIS2-18222 branch October 22, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants