Skip to content

Commit

Permalink
Merge branch 'master' into TECH-1595
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-p-pickering authored Nov 17, 2023
2 parents 58899c8 + 07efe3d commit 91933fb
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 48 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/run-api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
branches:
- master
pull_request:
types: [ opened, labeled, synchronize ]
concurrency:
group: ${{ github.workflow}}-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -20,7 +19,6 @@ jobs:
CORE_IMAGE_NAME: "dhis2/core-pr:${{ github.event_name == 'pull_request' && github.event.number || 'local' }}"

runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'skip-api-tests')"
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ public void generateResourceTables(JobProgress progress) {
// -------------------------------------------------------------------------

private void generateResourceTablesInternal(JobProgress progress) {
final Date startTime = new Date();

resourceTableService.dropAllSqlViews(progress);

Map<String, Runnable> generators = new LinkedHashMap<>();
Expand Down Expand Up @@ -184,6 +182,6 @@ private void generateResourceTablesInternal(JobProgress progress) {
resourceTableService.createAllSqlViews(progress);

systemSettingManager.saveSystemSetting(
SettingKey.LAST_SUCCESSFUL_RESOURCE_TABLES_UPDATE, startTime);
SettingKey.LAST_SUCCESSFUL_RESOURCE_TABLES_UPDATE, new Date());
}
}
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 $$;
2 changes: 1 addition & 1 deletion dhis-2/dhis-test-e2e/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<gson.version>2.10.1</gson.version>
<log4j.version>2.21.1</log4j.version>
<rest-assured.version>5.3.2</rest-assured.version>
<jackson.version>2.15.3</jackson.version>
<jackson.version>2.16.0</jackson.version>
<guava.version>32.1.3-jre</guava.version>
<json-tree.version>0.10.3</json-tree.version>
<epam-reportportal.version>5.1.8</epam-reportportal.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ public void setUpTest() throws IOException, InterruptedException {

// We need to make sure that table generation start time is greater than
// lastUpdated on tables populated in the setup
Date oneSecondFromNow =
Date.from(LocalDateTime.now().plusSeconds(1).atZone(ZoneId.systemDefault()).toInstant());
Date tenSecondsFromNow =
Date.from(LocalDateTime.now().plusSeconds(10).atZone(ZoneId.systemDefault()).toInstant());

assertNull(
systemSettingManager.getSystemSetting(
Expand All @@ -265,7 +265,7 @@ public void setUpTest() throws IOException, InterruptedException {
processStartTime = new Date();
// Generate analytics tables
analyticsTableGenerator.generateTables(
AnalyticsTableUpdateParams.newBuilder().withStartTime(oneSecondFromNow).build(),
AnalyticsTableUpdateParams.newBuilder().withStartTime(tenSecondsFromNow).build(),
NoopJobProgress.INSTANCE);
}

Expand Down Expand Up @@ -1539,7 +1539,11 @@ void resourceTablesTimestampUpdated() {
systemSettingManager.getSystemSetting(
SettingKey.LAST_SUCCESSFUL_RESOURCE_TABLES_UPDATE, Date.class);
assertNotEquals(null, resourceTablesUpdated);
assertTrue(tableLastUpdated.compareTo(processStartTime) > 0);
assertTrue(resourceTablesUpdated.compareTo(processStartTime) > 0);
assertTrue(
tableLastUpdated.compareTo(processStartTime) > 0,
String.format("%s > %s", tableLastUpdated, processStartTime));
assertTrue(
resourceTablesUpdated.compareTo(processStartTime) > 0,
String.format("%s > %s", resourceTablesUpdated, processStartTime));
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.common.PrefixedDimension;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.program.ProgramStageDataElement;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TeiAnalyticsPrefixStrategy implements PrefixStrategy {

public static final PrefixStrategy INSTANCE = EnrollmentAnalyticsPrefixStrategy.INSTANCE;
public static final PrefixStrategy INSTANCE = new TeiAnalyticsPrefixStrategy();

@Override
public String apply(PrefixedDimension pDimension) {
throw new UnsupportedOperationException("This method should not be called for TEI analytics");
if (pDimension.getItem() instanceof DataElement
|| pDimension.getItem() instanceof ProgramStageDataElement) {
return pDimension.getPrefix();
}
return StringUtils.EMPTY;
}
}
Loading

0 comments on commit 91933fb

Please sign in to comment.