Skip to content

Commit

Permalink
chore: Rename duedate to scheduleddate in DB [TECH-1615]
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante committed Nov 10, 2023
1 parent dae3308 commit 92d14ee
Show file tree
Hide file tree
Showing 30 changed files with 89 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum TimeField {
ENROLLMENT_DATE("enrollmentdate"),
INCIDENT_DATE("incidentdate"),
// Not a typo, different naming convention between FE and database
SCHEDULED_DATE("duedate"),
SCHEDULED_DATE("scheduleddate"),
COMPLETED_DATE("completeddate"),
CREATED("created"),
LAST_UPDATED("lastupdated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class AnalyticsPeriodBoundary extends BaseIdentifiableObject implements E

public static final String DB_INCIDENT_DATE = "incidentdate";

public static final String DB_SCHEDULED_DATE = "duedate";
public static final String DB_SCHEDULED_DATE = "scheduleddate";

public static final String DB_QUOTE = "\"";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class DefaultEventDataQueryService implements EventDataQueryService {

private static final String COL_NAME_INCIDENTDATE = "incidentdate";

private static final String COL_NAME_DUEDATE = "duedate";
private static final String COL_NAME_DUEDATE = "scheduleddate";

private final ProgramService programService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ protected String getColumn(QueryItem item, String suffix) {
&& !item.getRepeatableStageParams().simpleStageValueExpected()) {
return "(select json_agg(t1) from (select "
+ colName
+ ", incidentdate, duedate, executiondate "
+ ", incidentdate, scheduleddate, executiondate "
+ " from "
+ eventTableName
+ " where "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected String getSelectClause(EventQueryParams params) {
"createdbydisplayname",
"lastupdatedbydisplayname",
"lastupdated",
"duedate");
"scheduleddate");

if (params.getProgram().isRegistration()) {
cols.add("enrollmentdate", "incidentdate", "tei", "pi");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public JdbcEventAnalyticsTableManager(
new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"),
new AnalyticsTableColumn(quote("executiondate"), TIMESTAMP, "psi.executiondate"),
new AnalyticsTableColumn(quote("duedate"), TIMESTAMP, "psi.duedate"),
new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"),
new AnalyticsTableColumn(quote("completeddate"), TIMESTAMP, "psi.completeddate"),

/*
Expand Down Expand Up @@ -262,7 +262,7 @@ public List<AnalyticsTable> getAnalyticsTables(AnalyticsTableUpdateParams params
* status
*/
static String getDateLinkedToStatus() {
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.duedate ELSE psi.executiondate END";
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.executiondate END";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public JdbcTeiEventsAnalyticsTableManager(
new AnalyticsTableColumn(quote("executiondate"), TIMESTAMP, "psi.executiondate"),
new AnalyticsTableColumn(quote("lastupdated"), TIMESTAMP, "psi.lastupdated"),
new AnalyticsTableColumn(quote("created"), TIMESTAMP, "psi.created"),
new AnalyticsTableColumn(quote("duedate"), TIMESTAMP, "psi.duedate"),
new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"),
new AnalyticsTableColumn(quote("status"), VARCHAR_50, "psi.status"),
new AnalyticsTableColumn(quote("psigeometry"), GEOMETRY, "psi.geometry")
.withIndexType(GIST),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTy
is(
"(select json_agg(t1) from (select \""
+ dataElementA.getUid()
+ "\", incidentdate, duedate, executiondate from analytics_event_"
+ "\", incidentdate, scheduleddate, executiondate from analytics_event_"
+ programB.getUid()
+ " where analytics_event_"
+ programB.getUid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class EventAnalyticsManagerTest extends EventAnalyticsTest {
+ "createdbydisplayname"
+ ","
+ "lastupdatedbydisplayname"
+ ",lastupdated,duedate,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,longitude,latitude,ouname,ounamehierarchy,"
+ ",lastupdated,scheduleddate,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,longitude,latitude,ouname,ounamehierarchy,"
+ "oucode,pistatus,psistatus";

@BeforeEach
Expand Down Expand Up @@ -157,7 +157,7 @@ void verifyGetEventSqlWithProgramWithNoRegistration() {
+ "createdbydisplayname"
+ ","
+ "lastupdatedbydisplayname"
+ ",lastupdated,duedate,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,"
+ ",lastupdated,scheduleddate,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,"
+ "longitude,latitude,ouname,ounamehierarchy,oucode,pistatus,psistatus,ax.\"quarterly\",ax.\"ou\" from "
+ getTable(programA.getUid())
+ " as ax where (ax.\"quarterly\" in ('2000Q1') ) and ax.\"uidlevel1\" in ('ouabcdefghA') limit 101";
Expand Down Expand Up @@ -218,7 +218,7 @@ void verifyGetEventSqlWithOrgUnitTypeDataElement() {
+ "createdbydisplayname"
+ ","
+ "lastupdatedbydisplayname"
+ ",lastupdated,duedate,enrollmentdate,"
+ ",lastupdated,scheduleddate,enrollmentdate,"
+ "incidentdate,tei,pi,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,longitude,latitude,ouname,ounamehierarchy,oucode,pistatus,"
+ "psistatus,ax.\"quarterly\",ax.\"ou\",\""
+ dataElement.getUid()
Expand Down Expand Up @@ -334,7 +334,7 @@ void verifyGetEventsWithScheduledDateTimeFieldParam() {
String expected =
"ps.\"quarterly\",ax.\"ou\" from "
+ getTable(programA.getUid())
+ " as ax left join _dateperiodstructure as ps on cast(ax.\"duedate\" as date) = ps.\"dateperiod\" "
+ " as ax left join _dateperiodstructure as ps on cast(ax.\"scheduleddate\" as date) = ps.\"dateperiod\" "
+ "where (ps.\"quarterly\" in ('2000Q1') ) and ax.\"uidlevel1\" "
+ "in ('ouabcdefghA') and pistatus in ('ACTIVE','COMPLETED') limit 101";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ void testRenderEnrollmentTimeFieldSqlWhenNoContinuousMonthlyPeriodWithTimeFieldA
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();

assertEquals(
"((ax.\"duedate\" >= '2022-03-01' and ax.\"duedate\" < '2022-04-01') "
+ "or (ax.\"duedate\" >= '2022-09-01' and ax.\"duedate\" < '2022-10-01')) ",
"((ax.\"scheduleddate\" >= '2022-03-01' and ax.\"scheduleddate\" < '2022-04-01') "
+ "or (ax.\"scheduleddate\" >= '2022-09-01' and ax.\"scheduleddate\" < '2022-10-01')) ",
timeFieldSqlRenderer.renderPeriodTimeFieldSql(params));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,6 @@ private String getYearQueryForCurrentYear(
}

private String getDateLinkedToStatus() {
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.duedate ELSE psi.executiondate END";
return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.executiondate END";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void addSafetyBuffer(List<Integer> years, int buffer) {
*/
private List<Integer> fetchAvailableYears() {
String dueDateOrExecutionDate =
"(case when 'SCHEDULE' = ev.status then ev.duedate else ev.executiondate end)";
"(case when 'SCHEDULE' = ev.status then ev.scheduleddate else ev.executiondate end)";

String sql =
"( select distinct (extract(year from pe.startdate)) as datayear from period pe )"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public Object getSql(CommonExpressionVisitor visitor) {
ProgramExpressionParams params = visitor.getProgParams();

if (AnalyticsType.EVENT == params.getProgramIndicator().getAnalyticsType()) {
return "duedate";
return "scheduleddate";
}

return visitor
.getStatementBuilder()
.getProgramIndicatorEventColumnSql(
null,
"duedate",
"scheduleddate",
params.getReportingStartDate(),
params.getReportingEndDate(),
params.getProgramIndicator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public Object getSql(CommonExpressionVisitor visitor) {
.getStatementBuilder()
.getProgramIndicatorEventColumnSql(
null,
"duedate",
"scheduleddate",
params.getReportingStartDate(),
params.getReportingEndDate(),
params.getProgramIndicator());

return maybeAppendEventStatusFilterIntoWhere(sqlStatement);
}

return "duedate";
return "scheduleddate";
}

private String maybeAppendEventStatusFilterIntoWhere(String sqlStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class HibernateTrackedEntityStore extends SoftDeleteHibernateObjectStore<

private static final String EV_EXECUTIONDATE = "EV.executiondate";

private static final String EV_DUEDATE = "EV.duedate";
private static final String EV_DUEDATE = "EV.scheduleddate";

private static final String IS_NULL = "IS NULL";

Expand Down Expand Up @@ -1035,7 +1035,7 @@ private String getFromSubQueryEvent(TrackedEntityQueryParams params) {
.append(SPACE)
.append(IS_NULL)
.append(whereHlp.whereAnd())
.append("date(now()) <= date(EV.duedate) ");
.append("date(now()) <= date(EV.scheduleddate) ");
} else if (params.isEventStatus(EventStatus.OVERDUE)) {
events
.append(getQueryDateConditionBetween(whereHlp, EV_DUEDATE, start, end))
Expand All @@ -1048,7 +1048,7 @@ private String getFromSubQueryEvent(TrackedEntityQueryParams params) {
.append(SPACE)
.append(IS_NULL)
.append(whereHlp.whereAnd())
.append("date(now()) > date(EV.duedate) ");
.append("date(now()) > date(EV.scheduleddate) ");
} else if (params.isEventStatus(EventStatus.SKIPPED)) {
events
.append(getQueryDateConditionBetween(whereHlp, EV_DUEDATE, start, end))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<many-to-one name="program" class="org.hisp.dhis.program.Program"
column="programid" not-null="true" foreign-key="fk_programinstance_programid" lazy="false" />

<set name="events" order-by="executionDate,duedate" inverse="true">
<set name="events" order-by="executionDate,scheduleddate" inverse="true">
<key column="enrollmentid"/>
<one-to-many class="org.hisp.dhis.program.Event"/>
</set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<property name="storedBy" />

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void testCurrentDateForEvent() {
@Test
void testDueDate() {
String sql = castString(test("V{due_date}", new DefaultLiteral(), eventIndicator));
assertThat(sql, is("duedate"));
assertThat(sql, is("scheduleddate"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ private String getEventSelectQuery(
.append(
"psi.eventid as psi_id, psi.status as psi_status, psi.executiondate as psi_executiondate, ")
.append(
"psi.eventdatavalues as psi_eventdatavalues, psi.duedate as psi_duedate, psi.completedby as psi_completedby, psi.storedby as psi_storedby, ")
"psi.eventdatavalues as psi_eventdatavalues, psi.scheduleddate as psi_duedate, psi.completedby as psi_completedby, psi.storedby as psi_storedby, ")
.append(
"psi.created as psi_created, psi.createdbyuserinfo as psi_createdbyuserinfo, psi.lastupdated as psi_lastupdated, psi.lastupdatedbyuserinfo as psi_lastupdatedbyuserinfo, ")
.append("psi.completeddate as psi_completeddate, psi.deleted as psi_deleted, ")
Expand Down Expand Up @@ -1185,15 +1185,15 @@ private StringBuilder getFromWhereClause(

fromBuilder
.append(hlp.whereAnd())
.append(" (psi.duedate is not null and psi.duedate >= :startDueDate ) ");
.append(" (psi.scheduleddate is not null and psi.scheduleddate >= :startDueDate ) ");
}

if (params.getDueDateEnd() != null) {
mapSqlParameterSource.addValue("endDueDate", params.getDueDateEnd(), Types.TIMESTAMP);

fromBuilder
.append(hlp.whereAnd())
.append(" (psi.duedate is not null and psi.duedate <= :endDueDate ) ");
.append(" (psi.scheduleddate is not null and psi.scheduleddate <= :endDueDate ) ");
}

if (params.getFollowUp() != null) {
Expand Down Expand Up @@ -1242,7 +1242,7 @@ private StringBuilder getFromWhereClause(
.append(hlp.whereAnd())
.append(" (psi.executiondate >= ")
.append(":startDate")
.append(" or (psi.executiondate is null and psi.duedate >= ")
.append(" or (psi.executiondate is null and psi.scheduleddate >= ")
.append(":startDate")
.append(" )) ");
}
Expand All @@ -1254,7 +1254,7 @@ private StringBuilder getFromWhereClause(
.append(hlp.whereAnd())
.append(" (psi.executiondate < ")
.append(":endDate")
.append(" or (psi.executiondate is null and psi.duedate < ")
.append(" or (psi.executiondate is null and psi.scheduleddate < ")
.append(":endDate")
.append(" )) ");
}
Expand Down Expand Up @@ -1531,7 +1531,7 @@ private String getFromWhereClause(
.append(hlp.whereAnd())
.append(" (psi.executiondate >= ")
.append(":startDate")
.append(" or (psi.executiondate is null and psi.duedate >= ")
.append(" or (psi.executiondate is null and psi.scheduleddate >= ")
.append(":startDate")
.append(" )) ");
}
Expand All @@ -1543,7 +1543,7 @@ private String getFromWhereClause(
.append(hlp.whereAnd())
.append(" (psi.executiondate < ")
.append(":endDate ")
.append(" or (psi.executiondate is null and psi.duedate < ")
.append(" or (psi.executiondate is null and psi.scheduleddate < ")
.append(":endDate")
.append(" )) ");
}
Expand All @@ -1568,7 +1568,7 @@ private String getFromWhereClause(

sqlBuilder
.append(hlp.whereAnd())
.append(" psi.duedate is not null and psi.duedate >= ")
.append(" psi.scheduleddate is not null and psi.scheduleddate >= ")
.append(":dueDate")
.append(" ");
}
Expand All @@ -1578,7 +1578,7 @@ private String getFromWhereClause(

sqlBuilder
.append(hlp.whereAnd())
.append(" psi.duedate is not null and psi.duedate <= ")
.append(" psi.scheduleddate is not null and psi.scheduleddate <= ")
.append(":endDueDate")
.append(" ");
}
Expand Down Expand Up @@ -1637,7 +1637,7 @@ private String eventStatusSql(

stringBuilder
.append(hlp.whereAnd())
.append(" date(now()) > date(psi.duedate) and psi.status = ")
.append(" date(now()) > date(psi.scheduleddate) and psi.status = ")
.append(":" + PSI_STATUS)
.append(" ");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Map<String, Event> get(

final String sql =
"select psi.enrollmentid, psi.programstageid, psi.eventid, "
+ "psi.uid, psi.status, psi.deleted, psi.eventdatavalues, psi.duedate, psi.executiondate, "
+ "psi.uid, psi.status, psi.deleted, psi.eventdatavalues, psi.scheduleddate, psi.executiondate, "
+ "psi.completeddate, psi.attributeoptioncomboid, psi.geometry, "
+ "ou.organisationunitid, ou.uid, ou.code, ou.name, psi.attributeoptioncomboid, c.uid as coc_uid "
+ "from event psi join organisationunit ou on psi.organisationunitid = ou.organisationunitid "
Expand All @@ -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.setScheduledDate(rs.getTimestamp("duedate"));
psi.setScheduledDate(rs.getTimestamp("scheduleddate"));
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 @@ -50,7 +50,7 @@ public enum COLUMNS {
UID(new TableColumn("psi", "uid")),
STATUS(new TableColumn("psi", "status")),
EXECUTION_DATE(new TableColumn("psi", "executiondate")),
DUE_DATE(new TableColumn("psi", "duedate")),
DUE_DATE(new TableColumn("psi", "scheduleddate")),
STOREDBY(new TableColumn("psi", "storedby")),
COMPLETEDBY(new TableColumn("psi", "completedby")),
COMPLETEDDATE(new TableColumn("psi", "completeddate")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum COLUMNS {
UID(new TableColumn("ev", "uid")),
STATUS(new TableColumn("ev", "status")),
EXECUTION_DATE(new TableColumn("ev", "executiondate")),
DUE_DATE(new TableColumn("ev", "duedate")),
SCHEDULED_DATE(new TableColumn("ev", "scheduleddate")),
STOREDBY(new TableColumn("ev", "storedby")),
COMPLETEDBY(new TableColumn("ev", "completedby")),
COMPLETEDDATE(new TableColumn("ev", "completeddate")),
Expand Down
Loading

0 comments on commit 92d14ee

Please sign in to comment.