Skip to content

Commit

Permalink
chore: Rename dueDate to scheduledDate in service layer [TECH-1615] (#…
Browse files Browse the repository at this point in the history
…15617)

* chore: Rename dueDate to scheduledDate in service layer [TECH-1615]

* fix: Remove org unit in user scope from flaky test [DHIS2-16130]

* Fix tests

* Fix tests

---------

Co-authored-by: muilpp <[email protected]>
  • Loading branch information
enricocolasante and muilpp authored Nov 8, 2023
1 parent 46d6ca1 commit 6a47df8
Show file tree
Hide file tree
Showing 41 changed files with 97 additions and 92 deletions.
10 changes: 5 additions & 5 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class Event extends SoftDeletableObject {

private UserInfoSnapshot lastUpdatedByUserInfo;

private Date dueDate;
private Date scheduledDate;

private Date occurredDate;

Expand Down Expand Up @@ -216,12 +216,12 @@ public void setCompletedBy(String completedBy) {

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getDueDate() {
return dueDate;
public Date getScheduledDate() {
return scheduledDate;
}

public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
public void setScheduledDate(Date scheduledDate) {
this.scheduledDate = scheduledDate;
}

@JsonProperty("eventDate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
public class EventVisitDateComparator implements Comparator<Event> {
@Override
public int compare(Event event1, Event event2) {
Date d1 = (event1.getOccurredDate() != null) ? event1.getOccurredDate() : event1.getDueDate();
Date d2 = (event2.getOccurredDate() != null) ? event2.getOccurredDate() : event2.getDueDate();
Date d1 =
(event1.getOccurredDate() != null) ? event1.getOccurredDate() : event1.getScheduledDate();
Date d2 =
(event2.getOccurredDate() != null) ? event2.getOccurredDate() : event2.getScheduledDate();
if (d1.before(d2)) {
return -1;
} else if (d1.after(d2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public class ProgramStageNotificationMessageRenderer
.put(
ProgramStageTemplateVariable.ORG_UNIT_CODE,
event -> event.getOrganisationUnit().getCode())
.put(ProgramStageTemplateVariable.DUE_DATE, event -> formatDate(event.getDueDate()))
.put(ProgramStageTemplateVariable.DUE_DATE, event -> formatDate(event.getScheduledDate()))
.put(
ProgramStageTemplateVariable.EVENT_DATE, event -> formatDate(event.getOccurredDate()))
.put(
ProgramStageTemplateVariable.DAYS_SINCE_DUE_DATE,
event -> daysSince(event.getDueDate()))
event -> daysSince(event.getScheduledDate()))
.put(
ProgramStageTemplateVariable.DAYS_UNTIL_DUE_DATE,
event -> daysUntil(event.getDueDate()))
event -> daysUntil(event.getScheduledDate()))
.put(ProgramStageTemplateVariable.CURRENT_DATE, event -> formatDate(new Date()))
.put(
ProgramStageTemplateVariable.EVENT_ORG_UNIT_ID,
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.getDueDate().before(enrollment.getEndDate())) {
if (event.getScheduledDate().before(enrollment.getEndDate())) {
event.setStatus(EventStatus.SKIPPED);
eventStore.update(event);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Event createEvent(
event.setEnrollment(enrollment);
event.setProgramStage(programStage);
event.setOrganisationUnit(organisationUnit);
event.setDueDate(dueDate);
event.setScheduledDate(dueDate);
event.setStatus(EventStatus.SCHEDULE);

if (programStage.getOpenAfterEnrollment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ public List<Event> getWithScheduledNotifications(
"select distinct ev from Event as ev "
+ "inner join ev.programStage as ps "
+ "where :notificationTemplate in elements(ps.notificationTemplates) "
+ "and ev.dueDate is not null "
+ "and ev.scheduledDate is not null "
+ "and ev.occurredDate is null "
+ "and ev.status != :skippedEventStatus "
+ "and cast(:targetDate as date) = ev.dueDate "
+ "and cast(:targetDate as date) = ev.scheduledDate "
+ "and ev.deleted is false";

return getQuery(hql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected void register(
event.setProgramStage(smsCommand.getProgramStage());
event.setEnrollment(enrollment);
event.setOccurredDate(sms.getSentDate());
event.setDueDate(sms.getSentDate());
event.setScheduledDate(sms.getSentDate());
event.setAttributeOptionCombo(dataElementCategoryService.getDefaultCategoryOptionCombo());
event.setCompletedBy("DHIS 2");
event.setStoredBy(currentUserInfo.getUsername());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected List<Object> saveNewEvent(
event.setProgramStage(programStage);
event.setEnrollment(enrollment);
event.setOccurredDate(eventDate);
event.setDueDate(dueDate);
event.setScheduledDate(dueDate);
event.setAttributeOptionCombo(aoc);
event.setStoredBy(user.getUsername());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<property name="storedBy" />

<property name="dueDate" column="duedate" />
<property name="scheduledDate" column="duedate" />

<property name="occurredDate" column="executiondate" type="timestamp" index="programstageinstance_executiondate" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void initTest() {
event.setOrganisationUnit(organisationUnitA);
enrollment.setEnrollmentDate(new Date());
event.setOccurredDate(new Date());
event.setDueDate(new Date());
event.setScheduledDate(new Date());
event.setEnrollment(enrollment);

dataValue = new EventDataValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public org.hisp.dhis.dxf2.deprecated.tracker.event.Event getEvent(
EnrollmentStatus.fromProgramStatus(programStageInstance.getEnrollment().getStatus()));
event.setStatus(programStageInstance.getStatus());
event.setEventDate(DateUtils.getIso8601NoTz(programStageInstance.getOccurredDate()));
event.setDueDate(DateUtils.getIso8601NoTz(programStageInstance.getDueDate()));
event.setDueDate(DateUtils.getIso8601NoTz(programStageInstance.getScheduledDate()));
event.setStoredBy(programStageInstance.getStoredBy());
event.setCompletedBy(programStageInstance.getCompletedBy());
event.setCompletedDate(DateUtils.getIso8601NoTz(programStageInstance.getCompletedDate()));
Expand Down Expand Up @@ -806,7 +806,8 @@ public void updateEventForEventDate(org.hisp.dhis.dxf2.deprecated.tracker.event.
executionDate = DateUtils.parseDate(event.getEventDate());
}

Date eventDate = executionDate != null ? executionDate : programStageInstance.getDueDate();
Date eventDate =
executionDate != null ? executionDate : programStageInstance.getScheduledDate();

validateAttributeOptionComboDate(programStageInstance.getAttributeOptionCombo(), eventDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,7 @@ private void bindEventParamsForInsert(PreparedStatement ps, Event event)
throws SQLException, JsonProcessingException {
ps.setLong(1, event.getEnrollment().getId());
ps.setLong(2, event.getProgramStage().getId());
ps.setTimestamp(3, JdbcEventSupport.toTimestamp(event.getDueDate()));
ps.setTimestamp(3, JdbcEventSupport.toTimestamp(event.getScheduledDate()));
ps.setTimestamp(4, JdbcEventSupport.toTimestamp(event.getOccurredDate()));
ps.setLong(5, event.getOrganisationUnit().getId());
ps.setString(6, event.getStatus().toString());
Expand Down Expand Up @@ -1980,7 +1980,7 @@ private MapSqlParameterSource getSqlParametersForUpdate(org.hisp.dhis.program.Ev
.addValue("programstageid", event.getProgramStage().getId())
.addValue(
EventQuery.COLUMNS.DUE_DATE.getColumnName(),
JdbcEventSupport.toTimestamp(event.getDueDate()))
JdbcEventSupport.toTimestamp(event.getScheduledDate()))
.addValue(
EventQuery.COLUMNS.EXECUTION_DATE.getColumnName(),
JdbcEventSupport.toTimestamp(event.getOccurredDate()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Map<String, Event> get(
psi.setDeleted(rs.getBoolean("deleted"));
psi.setProgramStage(getProgramStage(importOptions, rs.getLong("programstageid")));
psi.setOrganisationUnit(getOu(rs));
psi.setDueDate(rs.getTimestamp("duedate"));
psi.setScheduledDate(rs.getTimestamp("duedate"));
psi.setOccurredDate(rs.getTimestamp("executiondate"));
psi.setCompletedDate(rs.getTimestamp("completeddate"));
psi.setAttributeOptionCombo(getCatOptionCombo(rs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private Event mapForUpdate(org.hisp.dhis.dxf2.deprecated.tracker.event.Event eve
psi.setEventDataValues(workContext.getEventDataValueMap().get(event.getUid()));

if (event.getDueDate() != null) {
psi.setDueDate(parseDate(event.getDueDate()));
psi.setScheduledDate(parseDate(event.getDueDate()));
}

setExecutionDate(event, psi);
Expand Down Expand Up @@ -182,7 +182,7 @@ public Event mapForInsert(org.hisp.dhis.dxf2.deprecated.tracker.event.Event even
dueDate = parseDate(event.getDueDate());
}

psi.setDueDate(dueDate);
psi.setScheduledDate(dueDate);
setCompletedDate(event, psi);
// Note that execution date can be null
setExecutionDate(event, psi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,9 @@ public RuleEvent toMappedRuleEvent(Event eventToEvaluate) {
eventToEvaluate.getUid(),
eventToEvaluate.getProgramStage().getUid(),
RuleEvent.Status.valueOf(eventToEvaluate.getStatus().toString()),
ObjectUtils.defaultIfNull(eventToEvaluate.getOccurredDate(), eventToEvaluate.getDueDate()),
eventToEvaluate.getDueDate(),
ObjectUtils.defaultIfNull(
eventToEvaluate.getOccurredDate(), eventToEvaluate.getScheduledDate()),
eventToEvaluate.getScheduledDate(),
orgUnit,
orgUnitCode,
eventToEvaluate.getEventDataValues().stream()
Expand All @@ -449,7 +450,7 @@ public RuleEvent toMappedRuleEvent(Event eventToEvaluate) {
dv ->
RuleDataValue.create(
ObjectUtils.defaultIfNull(
eventToEvaluate.getOccurredDate(), eventToEvaluate.getDueDate()),
eventToEvaluate.getOccurredDate(), eventToEvaluate.getScheduledDate()),
eventToEvaluate.getProgramStage().getUid(),
dv.getDataElement(),
dv.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,13 @@ private void setUpProgramRules() {

eventA.setOrganisationUnit(organisationUnit);
eventA.setAutoFields();
eventA.setDueDate(new Date());
eventA.setScheduledDate(new Date());
eventA.setOccurredDate(new Date());
eventA.setEventDataValues(Sets.newHashSet(eventDataValueA));

eventB.setOrganisationUnit(organisationUnit);
eventB.setAutoFields();
eventB.setDueDate(new Date());
eventB.setScheduledDate(new Date());
eventB.setOccurredDate(new Date());
eventB.setEventDataValues(Sets.newHashSet(eventDataValueB));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Event getEvent(@Nonnull Event event, EventParams eventParams) throws Forb

result.setStatus(event.getStatus());
result.setOccurredDate(event.getOccurredDate());
result.setDueDate(event.getDueDate());
result.setScheduledDate(event.getScheduledDate());
result.setStoredBy(event.getStoredBy());
result.setCompletedBy(event.getCompletedBy());
result.setCompletedDate(event.getCompletedDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public EventQueryParams map(EventOperationParams operationParams)
operationParams.getAssignedUserMode(), user, operationParams.getAssignedUsers()))
.setOccurredStartDate(operationParams.getOccurredAfter())
.setOccurredEndDate(operationParams.getOccurredBefore())
.setScheduleAtStartDate(operationParams.getScheduledAfter())
.setScheduleAtEndDate(operationParams.getScheduledBefore())
.setScheduledStartDate(operationParams.getScheduledAfter())
.setScheduledEndDate(operationParams.getScheduledBefore())
.setUpdatedAtStartDate(operationParams.getUpdatedAfter())
.setUpdatedAtEndDate(operationParams.getUpdatedBefore())
.setUpdatedAtDuration(operationParams.getUpdatedWithin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public Date getScheduleAtStartDate() {
return scheduleAtStartDate;
}

public EventQueryParams setScheduleAtStartDate(Date scheduleAtStartDate) {
public EventQueryParams setScheduledStartDate(Date scheduleAtStartDate) {
this.scheduleAtStartDate = scheduleAtStartDate;
return this;
}
Expand All @@ -334,7 +334,7 @@ public Date getScheduleAtEndDate() {
return scheduleAtEndDate;
}

public EventQueryParams setScheduleAtEndDate(Date scheduleAtEndDate) {
public EventQueryParams setScheduledEndDate(Date scheduleAtEndDate) {
this.scheduleAtEndDate = scheduleAtEndDate;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class JdbcEventStore implements EventStore {
entry("occurredDate", COLUMN_EVENT_EXECUTION_DATE),
entry("enrollment.followUp", COLUMN_ENROLLMENT_FOLLOWUP),
entry("status", COLUMN_EVENT_STATUS),
entry("dueDate", COLUMN_EVENT_DUE_DATE),
entry("scheduledDate", COLUMN_EVENT_DUE_DATE),
entry("storedBy", COLUMN_EVENT_STORED_BY),
entry("lastUpdatedBy", COLUMN_EVENT_LAST_UPDATED_BY),
entry("createdBy", COLUMN_EVENT_CREATED_BY),
Expand Down Expand Up @@ -326,7 +326,7 @@ private List<Event> fetchEvents(EventQueryParams queryParams, PageParams pagePar
event.setAttributeOptionCombo(coc);

event.setStoredBy(resultSet.getString(COLUMN_EVENT_STORED_BY));
event.setDueDate(resultSet.getTimestamp(COLUMN_EVENT_DUE_DATE));
event.setScheduledDate(resultSet.getTimestamp(COLUMN_EVENT_DUE_DATE));
event.setOccurredDate(resultSet.getTimestamp(COLUMN_EVENT_EXECUTION_DATE));
event.setCreated(resultSet.getTimestamp(COLUMN_EVENT_CREATED));
event.setCreatedByUserInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private Event getEvent(ResultSet rs) throws SQLException {

event.setStatus(EventStatus.valueOf(rs.getString(EventQuery.getColumnName(COLUMNS.STATUS))));
event.setOccurredDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.EXECUTION_DATE)));
event.setDueDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.DUE_DATE)));
event.setScheduledDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.DUE_DATE)));
event.setStoredBy(rs.getString(EventQuery.getColumnName(COLUMNS.STOREDBY)));
event.setCompletedBy(rs.getString(EventQuery.getColumnName(COLUMNS.COMPLETEDBY)));
event.setCompletedDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.COMPLETEDDATE)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<org.hisp.dhis.tracker.imports.domain.Event> to(List<Event> events) {

e.setStatus(event.getStatus());
e.setOccurredAt(DateUtils.instantFromDate(event.getOccurredDate()));
e.setScheduledAt(DateUtils.instantFromDate(event.getDueDate()));
e.setScheduledAt(DateUtils.instantFromDate(event.getScheduledDate()));
e.setStoredBy(event.getStoredBy());
e.setCompletedBy(event.getCompletedBy());
e.setCompletedAt(DateUtils.instantFromDate(event.getCompletedDate()));
Expand Down Expand Up @@ -212,7 +212,7 @@ private Event from(
result.setProgramStage(programStage);
result.setOrganisationUnit(organisationUnit);
result.setOccurredDate(DateUtils.fromInstant(event.getOccurredAt()));
result.setDueDate(DateUtils.fromInstant(event.getScheduledAt()));
result.setScheduledDate(DateUtils.fromInstant(event.getScheduledAt()));

if (event.getAttributeOptionCombo().isNotBlank()) {
result.setAttributeOptionCombo(
Expand Down Expand Up @@ -241,9 +241,9 @@ private Event from(
}

if (program.isRegistration()
&& result.getDueDate() == null
&& result.getScheduledDate() == null
&& result.getOccurredDate() != null) {
result.setDueDate(result.getOccurredDate());
result.setScheduledDate(result.getOccurredDate());
}

for (DataValue dataValue : event.getDataValues()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface EventMapper extends PreheatMapper<Event> {
@Mapping(target = "created")
@Mapping(target = "eventDataValues")
@Mapping(target = "notes")
@Mapping(target = "dueDate")
@Mapping(target = "scheduledDate")
@Mapping(target = "occurredDate")
@Mapping(target = "completedDate")
@Mapping(target = "completedBy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void shouldMapOrderInGivenOrder() throws BadRequestException, ForbiddenException
.orderBy(UID.of(TEA_1_UID), SortDirection.ASC)
.orderBy("programStage.uid", SortDirection.DESC)
.orderBy(UID.of(DE_1_UID), SortDirection.DESC)
.orderBy("dueDate", SortDirection.ASC)
.orderBy("scheduledDate", SortDirection.ASC)
.build();

EventQueryParams params = mapper.map(operationParams);
Expand All @@ -376,7 +376,7 @@ void shouldMapOrderInGivenOrder() throws BadRequestException, ForbiddenException
new Order(tea1, SortDirection.ASC),
new Order("programStage.uid", SortDirection.DESC),
new Order(de1, SortDirection.DESC),
new Order("dueDate", SortDirection.ASC)),
new Order("scheduledDate", SortDirection.ASC)),
params.getOrder());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void setUpTest() {
event.setOrganisationUnit(organisationUnit);
event.setProgramStage(programStage);
event.setEventDataValues(Sets.newHashSet());
event.setDueDate(null);
event.setScheduledDate(null);
event.setCompletedDate(null);
event.setStoredBy(user.getUsername());
event.setLastUpdatedByUserInfo(UserInfoSnapshot.from(user));
Expand Down
Loading

0 comments on commit 6a47df8

Please sign in to comment.