Skip to content

Commit

Permalink
chore: Rename endDate to completedDate in service layer [TECH-1665] (#…
Browse files Browse the repository at this point in the history
…15652)

* chore: Rename endDate to completedDate in service layer [TECH-1665]

* Fix tests
  • Loading branch information
enricocolasante authored Nov 13, 2023
1 parent 21d1572 commit 270ca56
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Enrollment extends SoftDeletableObject {

private Date enrollmentDate;

private Date endDate;
private Date completedDate;

private UserInfoSnapshot createdByUserInfo;

Expand Down Expand Up @@ -238,12 +238,12 @@ public void setEnrollmentDate(Date enrollmentDate) {

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getEndDate() {
return endDate;
public Date getCompletedDate() {
return completedDate;
}

public void setEndDate(Date endDate) {
this.endDate = endDate;
public void setCompletedDate(Date completedDate) {
this.completedDate = completedDate;
}

@JsonProperty
Expand Down Expand Up @@ -434,7 +434,7 @@ private static void setShallowCopyValues(
copy.setCompletedBy(original.getCompletedBy());
copy.setCreatedAtClient(original.getCreatedAtClient());
copy.setCreatedByUserInfo(original.getCreatedByUserInfo());
copy.setEndDate(original.getEndDate());
copy.setCompletedDate(original.getCompletedDate());
copy.setEnrollmentDate(original.getEnrollmentDate());
copy.setEvents(new HashSet<>());
copy.setFollowup(original.getFollowup());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void testCopyOfWithPropertyValuesSet() {
assertEquals(original.getFollowup(), copy.getFollowup());
assertEquals(original.getGeometry(), copy.getGeometry());
assertEquals(original.getOrganisationUnit(), copy.getOrganisationUnit());
assertEquals(original.getEndDate(), copy.getEndDate());
assertEquals(original.getCompletedDate(), copy.getCompletedDate());
assertEquals(original.getRelationshipItems(), copy.getRelationshipItems());
assertEquals(original.getCreatedByUserInfo(), copy.getCreatedByUserInfo());
assertEquals(original.getMessageConversations(), copy.getMessageConversations());
Expand All @@ -86,7 +86,7 @@ void testCopyOfWithNullPropertyValues() {
assertNotEquals(original.getProgram(), copy.getProgram());

assertEquals(original.getCreatedByUserInfo(), copy.getCreatedByUserInfo());
assertEquals(original.getEndDate(), copy.getEndDate());
assertEquals(original.getCompletedDate(), copy.getCompletedDate());
assertEquals(original.getEnrollmentDate(), copy.getEnrollmentDate());
assertEquals(original.getFollowup(), copy.getFollowup());
assertEquals(original.getGeometry(), copy.getGeometry());
Expand Down Expand Up @@ -117,7 +117,7 @@ private Enrollment getNewEnrollmentWithNoNulls() {
e.setAutoFields();
e.setNotes(List.of(new Note("note", "amin")));
e.setCompletedBy("admin");
e.setEndDate(new Date());
e.setCompletedDate(new Date());
e.setEnrollmentDate(new Date());
e.setEvents(Set.of());
e.setFollowup(true);
Expand All @@ -138,7 +138,7 @@ private Enrollment getNewEnrollmentWithNulls() {
e.setName(null);
e.setNotes(null);
e.setCompletedBy(null);
e.setEndDate(null);
e.setCompletedDate(null);
e.setEnrollmentDate(null);
e.setEvents(null);
e.setIncidentDate(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void cancelEnrollmentStatus(Enrollment enrollment) {
// Set status as skipped for overdue events, or delete
// -------------------------------------------------------------

if (event.getScheduledDate().before(enrollment.getEndDate())) {
if (event.getScheduledDate().before(enrollment.getCompletedDate())) {
event.setStatus(EventStatus.SKIPPED);
eventStore.update(event);
} else {
Expand Down Expand Up @@ -501,7 +501,7 @@ public void incompleteEnrollmentStatus(Enrollment enrollment) {
// -----------------------------------------------------------------

enrollment.setStatus(ProgramStatus.ACTIVE);
enrollment.setEndDate(null);
enrollment.setCompletedDate(null);

updateEnrollment(enrollment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<property name="enrollmentDate" column="enrollmentdate" not-null="true"/>

<property name="endDate" column="enddate"/>
<property name="completedDate" column="enddate"/>

<property name="followup" column="followup"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public org.hisp.dhis.dxf2.deprecated.tracker.enrollment.Enrollment getEnrollment
enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
enrollment.setIncidentDate(programInstance.getIncidentDate());
enrollment.setFollowup(programInstance.getFollowup());
enrollment.setCompletedDate(programInstance.getEndDate());
enrollment.setCompletedDate(programInstance.getCompletedDate());
enrollment.setCompletedBy(programInstance.getCompletedBy());
enrollment.setStoredBy(programInstance.getStoredBy());
enrollment.setCreatedByUserInfo(programInstance.getCreatedByUserInfo());
Expand Down Expand Up @@ -598,7 +598,7 @@ private ImportSummary addEnrollment(
}

programInstance.setCompletedBy(user);
programInstance.setEndDate(date);
programInstance.setCompletedDate(date);
}

programInstance.setCreatedByUserInfo(UserInfoSnapshot.from(importOptions.getUser()));
Expand Down Expand Up @@ -973,11 +973,11 @@ private ImportSummary updateEnrollment(
}

if (EnrollmentStatus.CANCELLED == enrollment.getStatus()) {
programInstance.setEndDate(endDate);
programInstance.setCompletedDate(endDate);

enrollmentService.cancelEnrollmentStatus(programInstance);
} else if (EnrollmentStatus.COMPLETED == enrollment.getStatus()) {
programInstance.setEndDate(endDate);
programInstance.setCompletedDate(endDate);
programInstance.setCompletedBy(user);

enrollmentService.completeEnrollmentStatus(programInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ private void validateProgramInstance(ImmutableEvent event, WorkContext ctx, List

referenceDate = removeTimeStamp(referenceDate);

if (referenceDate.after(removeTimeStamp(enrollment.getEndDate()))) {
if (referenceDate.after(removeTimeStamp(enrollment.getCompletedDate()))) {
errors.add(
"Not possible to add event to a completed enrollment. Event created date ( "
+ referenceDate
+ " ) is after enrollment completed date ( "
+ removeTimeStamp(enrollment.getEndDate())
+ removeTimeStamp(enrollment.getCompletedDate())
+ " ).");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void verifyErrorOnEventWithDateNewerThanCompletedProgramInstance() {
Enrollment enrollment = new Enrollment();
enrollment.setStatus(ProgramStatus.COMPLETED);
// Set enrollment end date to NOW - one month
enrollment.setEndDate(Date.from(ZonedDateTime.now().minusMonths(1).toInstant()));
enrollment.setCompletedDate(Date.from(ZonedDateTime.now().minusMonths(1).toInstant()));
programInstanceMap.put(event.getUid(), enrollment);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
when(workContext.getImportOptions()).thenReturn(importOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Enrollment getEnrollment(
result.setEnrollmentDate(enrollment.getEnrollmentDate());
result.setIncidentDate(enrollment.getIncidentDate());
result.setFollowup(enrollment.getFollowup());
result.setEndDate(enrollment.getEndDate());
result.setCompletedDate(enrollment.getCompletedDate());
result.setCompletedBy(enrollment.getCompletedBy());
result.setStoredBy(enrollment.getStoredBy());
result.setCreatedByUserInfo(enrollment.getCreatedByUserInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class HibernateEnrollmentStore extends SoftDeleteHibernateObjectStore<Enrollment
*/
private static final Set<String> ORDERABLE_FIELDS =
Set.of(
"endDate",
"completedDate",
"created",
"createdAtClient",
"enrollmentDate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private Enrollment getEnrollment(ResultSet rs) throws SQLException {
rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.ENROLLMENTDATE)));
enrollment.setIncidentDate(
rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.INCIDENTDATE)));
enrollment.setEndDate(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.COMPLETED)));
enrollment.setCompletedDate(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.COMPLETED)));
enrollment.setCompletedBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.COMPLETEDBY)));
enrollment.setStoredBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.STOREDBY)));
enrollment.setDeleted(rs.getBoolean(EnrollmentQuery.getColumnName(COLUMNS.DELETED)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ private Enrollment from(

if (previousStatus != dbEnrollment.getStatus()) {
if (dbEnrollment.isCompleted()) {
dbEnrollment.setEndDate(now);
dbEnrollment.setCompletedDate(now);
dbEnrollment.setCompletedBy(preheat.getUsername());
} else if (dbEnrollment.getStatus().equals(ProgramStatus.CANCELLED)) {
dbEnrollment.setEndDate(now);
dbEnrollment.setCompletedDate(now);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void testUpdateEnrollment() throws IOException {
enrollments.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
compareEnrollmentBasicProperties(enrollment, enrollmentParams.getEnrollments().get(0));
assertNull(enrollment.getCompletedBy());
assertNull(enrollment.getEndDate());
assertNull(enrollment.getCompletedDate());

org.hisp.dhis.tracker.imports.domain.Enrollment updatedEnrollment =
enrollmentParams.getEnrollments().get(0);
Expand All @@ -194,7 +194,7 @@ void testUpdateEnrollment() throws IOException {
enrollment = enrollments.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get();
compareEnrollmentBasicProperties(enrollment, updatedEnrollment);
assertNotNull(enrollment.getCompletedBy());
assertNotNull(enrollment.getEndDate());
assertNotNull(enrollment.getCompletedDate());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface EnrollmentMapper
*/
Map<String, String> ORDERABLE_FIELDS =
Map.ofEntries(
entry("completedAt", "endDate"),
entry("completedAt", "completedDate"),
entry("createdAt", "created"),
entry("createdAtClient", "createdAtClient"),
entry("enrolledAt", "enrollmentDate"),
Expand All @@ -77,7 +77,7 @@ public interface EnrollmentMapper
@Mapping(target = "enrolledAt", source = "enrollmentDate")
@Mapping(target = "occurredAt", source = "incidentDate")
@Mapping(target = "followUp", source = "followup")
@Mapping(target = "completedAt", source = "endDate")
@Mapping(target = "completedAt", source = "completedDate")
@Mapping(target = "createdBy", source = "createdByUserInfo")
@Mapping(target = "updatedBy", source = "lastUpdatedByUserInfo")
@Mapping(target = "relationships", source = "relationshipItems")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ interface RelationshipItemMapper
@Mapping(target = "enrolledAt", source = "enrollmentDate")
@Mapping(target = "occurredAt", source = "incidentDate")
@Mapping(target = "followUp", source = "followup")
@Mapping(target = "completedAt", source = "endDate")
@Mapping(target = "completedAt", source = "completedDate")
@Mapping(target = "createdBy", source = "createdByUserInfo")
@Mapping(target = "updatedBy", source = "lastUpdatedByUserInfo")
@Mapping(target = "attributes", source = "trackedEntity.trackedEntityAttributeValues")
Expand Down

0 comments on commit 270ca56

Please sign in to comment.