Skip to content

Commit

Permalink
chore: Rename incidentdate to occurreddate in DB [TECH-1655] (#15700)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante authored Nov 16, 2023
1 parent 31009f8 commit a1af060
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public JdbcEnrollmentAnalyticsTableManager(
List.of(
new AnalyticsTableColumn(quote("pi"), CHARACTER_11, NOT_NULL, "pi.uid"),
new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.occurreddate"),
new AnalyticsTableColumn(
quote("completeddate"),
TIMESTAMP,
Expand Down Expand Up @@ -228,7 +228,7 @@ protected void populateTable(
+ "and pi.lastupdated <= '"
+ getLongDateString(params.getStartTime())
+ "' "
+ "and pi.incidentdate is not null "
+ "and pi.occurreddate is not null "
+ "and pi.deleted is false ";

populateTableInternal(partition, getDimensionColumns(program), fromClause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public JdbcEventAnalyticsTableManager(
new AnalyticsTableColumn(quote("ps"), CHARACTER_11, NOT_NULL, "ps.uid"),
new AnalyticsTableColumn(quote("ao"), CHARACTER_11, NOT_NULL, "ao.uid"),
new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.occurreddate"),
new AnalyticsTableColumn(quote("occurreddate"), TIMESTAMP, "psi.occurreddate"),
new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"),
new AnalyticsTableColumn(quote("completeddate"), TIMESTAMP, "psi.completeddate"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public JdbcTeiEnrollmentsAnalyticsTableManager(
new AnalyticsTableColumn(quote("programinstanceuid"), CHARACTER_11, NULL, "pi.uid"),
new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"),
new AnalyticsTableColumn(quote("enddate"), TIMESTAMP, "pi.completeddate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.occurreddate"),
new AnalyticsTableColumn(quote("enrollmentstatus"), VARCHAR_50, "pi.status"),
new AnalyticsTableColumn(quote("pigeometry"), GEOMETRY, "pi.geometry")
.withIndexType(GIST),
Expand Down Expand Up @@ -256,7 +256,7 @@ protected void populateTable(
+ " and psi.status in ("
+ join(",", EXPORTABLE_EVENT_STATUSES)
+ "))")
.append(" and pi.incidentdate is not null ")
.append(" and pi.occurreddate is not null ")
.append(" and pi.deleted is false");

invokeTimeAndLog(sql.toString(), partition.getTempTableName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public Enrollment prepareEnrollment(
Program program,
ProgramStatus programStatus,
Date enrollmentDate,
Date incidentDate,
Date occurredDate,
OrganisationUnit organisationUnit,
String uid) {
if (program.getTrackedEntityType() != null
Expand All @@ -356,8 +356,8 @@ public Enrollment prepareEnrollment(
enrollment.setEnrollmentDate(new Date());
}

if (incidentDate != null) {
enrollment.setOccurredDate(incidentDate);
if (occurredDate != null) {
enrollment.setOccurredDate(occurredDate);
} else {
enrollment.setOccurredDate(new Date());
}
Expand All @@ -373,13 +373,13 @@ public Enrollment enrollTrackedEntity(
TrackedEntity trackedEntity,
Program program,
Date enrollmentDate,
Date incidentDate,
Date occurredDate,
OrganisationUnit organisationUnit) {
return enrollTrackedEntity(
trackedEntity,
program,
enrollmentDate,
incidentDate,
occurredDate,
organisationUnit,
CodeGenerator.generateUid());
}
Expand All @@ -390,7 +390,7 @@ public Enrollment enrollTrackedEntity(
TrackedEntity trackedEntity,
Program program,
Date enrollmentDate,
Date incidentDate,
Date occurredDate,
OrganisationUnit organisationUnit,
String uid) {
// ---------------------------------------------------------------------
Expand All @@ -403,7 +403,7 @@ public Enrollment enrollTrackedEntity(
program,
ProgramStatus.ACTIVE,
enrollmentDate,
incidentDate,
occurredDate,
organisationUnit,
uid);
addEnrollment(enrollment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Event createEvent(
Enrollment enrollment,
ProgramStage programStage,
Date enrollmentDate,
Date incidentDate,
Date occurredDate,
OrganisationUnit organisationUnit) {
Event event = null;
Date currentDate = new Date();
Expand All @@ -169,7 +169,7 @@ public Event createEvent(
if (programStage.getGeneratedByEnrollmentDate()) {
dateCreatedEvent = enrollmentDate;
} else {
dateCreatedEvent = incidentDate;
dateCreatedEvent = occurredDate;
}

Date dueDate = DateUtils.addDays(dateCreatedEvent, programStage.getMinDaysFromStart());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
public class vIncidentDate extends ProgramDateVariable {
@Override
public Object getSql(CommonExpressionVisitor visitor) {
return "incidentdate";
return "occurreddate";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -953,14 +953,14 @@ private String getFromSubQueryEnrollmentConditions(

if (params.hasProgramIncidentStartDate()) {
program
.append("AND EN.incidentdate >= '")
.append("AND EN.occurreddate >= '")
.append(getLongDateString(params.getProgramIncidentStartDate()))
.append("' ");
}

if (params.hasProgramIncidentEndDate()) {
program
.append("AND EN.incidentdate <= '")
.append("AND EN.occurreddate <= '")
.append(getLongDateString(params.getProgramIncidentEndDate()))
.append("' ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<property name="lastUpdatedByUserInfo" type="jbUserInfoSnapshot" column="lastupdatedbyuserinfo"/>

<property name="occurredDate" column="incidentDate"/>
<property name="occurredDate" column="occurreddate"/>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void testEventDate() {
@Test
void testIncidentDate() {
String sql = castString(test("V{incident_date}", new DefaultLiteral(), eventIndicator));
assertThat(sql, is("incidentdate"));
assertThat(sql, is("occurreddate"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ private String getEventSelectQuery(

return selectBuilder
.append(
"pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, pi.enrollmentdate as pi_enrollmentdate, pi.incidentdate as pi_incidentdate, ")
"pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, pi.enrollmentdate as pi_enrollmentdate, pi.occurreddate as pi_incidentdate, ")
.append("p.type as p_type, ps.uid as ps_uid, ou.name as ou_name, ")
.append(
"tei.trackedentityid as tei_id, tei.uid as tei_uid, teiou.uid as tei_ou, teiou.name as tei_ou_name, tei.created as tei_created, tei.inactive as tei_inactive ")
Expand Down Expand Up @@ -1171,13 +1171,13 @@ private StringBuilder getFromWhereClause(
"enrollmentOccurredBefore", params.getEnrollmentOccurredBefore(), Types.TIMESTAMP);
fromBuilder
.append(hlp.whereAnd())
.append(" (pi.incidentdate <= :enrollmentOccurredBefore ) ");
.append(" (pi.occurreddate <= :enrollmentOccurredBefore ) ");
}

if (params.getEnrollmentOccurredAfter() != null) {
mapSqlParameterSource.addValue(
"enrollmentOccurredAfter", params.getEnrollmentOccurredAfter(), Types.TIMESTAMP);
fromBuilder.append(hlp.whereAnd()).append(" (pi.incidentdate >= :enrollmentOccurredAfter ) ");
fromBuilder.append(hlp.whereAnd()).append(" (pi.occurreddate >= :enrollmentOccurredAfter ) ");
}

if (params.getDueDateStart() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public enum COLUMNS {
.put(COLUMNS.LAST_UPDATED_BY, new TableColumn("pi", "lastupdatedbyuserinfo"))
.put(COLUMNS.STATUS, new TableColumn("pi", "status"))
.put(COLUMNS.ENROLLMENTDATE, new TableColumn("pi", "enrollmentdate"))
.put(COLUMNS.INCIDENTDATE, new TableColumn("pi", "incidentdate"))
.put(COLUMNS.INCIDENTDATE, new TableColumn("pi", "occurreddate"))
.put(COLUMNS.FOLLOWUP, new TableColumn("pi", "followup"))
.put(COLUMNS.COMPLETED, new TableColumn("pi", "completeddate"))
.put(COLUMNS.COMPLETEDBY, new TableColumn("pi", "completedby"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ private String getEventSelectQuery(
+ COLUMN_ENROLLMENT_FOLLOWUP
+ ", en.enrollmentdate as "
+ COLUMN_ENROLLMENT_DATE
+ ", en.incidentdate as en_incidentdate, ")
+ ", en.occurreddate as en_occurreddate, ")
.append("p.type as p_type, ")
.append("te.trackedentityid as te_id, te.uid as ")
.append(COLUMN_TRACKEDENTITY_UID)
Expand Down Expand Up @@ -914,13 +914,13 @@ private StringBuilder getFromWhereClause(
"enrollmentOccurredBefore", params.getEnrollmentOccurredBefore(), Types.TIMESTAMP);
fromBuilder
.append(hlp.whereAnd())
.append(" (en.incidentdate <= :enrollmentOccurredBefore ) ");
.append(" (en.occurreddate <= :enrollmentOccurredBefore ) ");
}

if (params.getEnrollmentOccurredAfter() != null) {
mapSqlParameterSource.addValue(
"enrollmentOccurredAfter", params.getEnrollmentOccurredAfter(), Types.TIMESTAMP);
fromBuilder.append(hlp.whereAnd()).append(" (en.incidentdate >= :enrollmentOccurredAfter ) ");
fromBuilder.append(hlp.whereAnd()).append(" (en.occurreddate >= :enrollmentOccurredAfter ) ");
}

if (params.getScheduleAtStartDate() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,14 +786,14 @@ private String getFromSubQueryEnrollmentConditions(

if (params.hasProgramIncidentStartDate()) {
program
.append("AND EN.incidentdate >= '")
.append("AND EN.occurreddate >= '")
.append(getLongDateString(params.getProgramIncidentStartDate()))
.append("' ");
}

if (params.hasProgramIncidentEndDate()) {
program
.append("AND EN.incidentdate <= '")
.append("AND EN.occurreddate <= '")
.append(getLongDateString(params.getProgramIncidentEndDate()))
.append("' ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private Enrollment getEnrollment(ResultSet rs) throws SQLException {
enrollment.setEnrollmentDate(
rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.ENROLLMENTDATE)));
enrollment.setOccurredDate(
rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.INCIDENTDATE)));
rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.OCCURREDDATE)));
enrollment.setCompletedDate(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.COMPLETED)));
enrollment.setCompletedBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.COMPLETEDBY)));
enrollment.setStoredBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.STOREDBY)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum COLUMNS {
STATUS,
GEOMETRY,
ENROLLMENTDATE,
INCIDENTDATE,
OCCURREDDATE,
FOLLOWUP,
COMPLETED,
COMPLETEDBY,
Expand All @@ -74,7 +74,7 @@ public enum COLUMNS {
.put(COLUMNS.LAST_UPDATED_BY, new TableColumn("en", "lastupdatedbyuserinfo"))
.put(COLUMNS.STATUS, new TableColumn("en", "status"))
.put(COLUMNS.ENROLLMENTDATE, new TableColumn("en", "enrollmentdate"))
.put(COLUMNS.INCIDENTDATE, new TableColumn("en", "incidentdate"))
.put(COLUMNS.OCCURREDDATE, new TableColumn("en", "occurreddate"))
.put(COLUMNS.FOLLOWUP, new TableColumn("en", "followup"))
.put(COLUMNS.COMPLETED, new TableColumn("en", "completeddate"))
.put(COLUMNS.COMPLETEDBY, new TableColumn("en", "completedby"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- rename enddate in enrollment

do $$
begin
if exists(select 1
from information_schema.columns
where table_schema != 'information_schema' and table_name='enrollment' and column_name='incidentdate')
then
alter table enrollment rename column incidentdate to occurreddate;
end if;
end $$;
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void testGetAnalyticsSQl() {

@Test
void testGetAnalyticsSQl2() {
String expected = "((cast(incidentdate as date) - cast(enrollmentdate as date))) / 7.0";
String expected = "((cast(occurreddate as date) - cast(enrollmentdate as date))) / 7.0";
assertEquals(
expected,
programIndicatorService.getAnalyticsSql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ void testScheduledDate() {

@Test
void testIncidentDate() {
assertEquals("incidentdate", getSql("V{incident_date}"));
assertEquals("incidentdate", getSqlEnrollment("V{incident_date}"));
assertEquals("occurreddate", getSql("V{incident_date}"));
assertEquals("occurreddate", getSqlEnrollment("V{incident_date}"));
}

@Test
Expand Down

0 comments on commit a1af060

Please sign in to comment.