Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into TECH-1517-41
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyen committed Nov 15, 2023
2 parents 3b49c68 + 928fd9c commit 7ca34ed
Show file tree
Hide file tree
Showing 55 changed files with 228 additions and 128 deletions.
22 changes: 11 additions & 11 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Enrollment.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Enrollment extends SoftDeletableObject {

@AuditAttribute private OrganisationUnit organisationUnit;

private Date incidentDate;
private Date occurredDate;

private Date enrollmentDate;

Expand Down Expand Up @@ -104,9 +104,9 @@ public class Enrollment extends SoftDeletableObject {
public Enrollment() {}

public Enrollment(
Date enrollmentDate, Date incidentDate, TrackedEntity trackedEntity, Program program) {
Date enrollmentDate, Date occurredDate, TrackedEntity trackedEntity, Program program) {
this.enrollmentDate = enrollmentDate;
this.incidentDate = incidentDate;
this.occurredDate = occurredDate;
this.trackedEntity = trackedEntity;
this.program = program;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public int hashCode() {
final int prime = 31;
int result = super.hashCode();

result = prime * result + ((incidentDate == null) ? 0 : incidentDate.hashCode());
result = prime * result + ((occurredDate == null) ? 0 : occurredDate.hashCode());
result = prime * result + ((enrollmentDate == null) ? 0 : enrollmentDate.hashCode());
result = prime * result + ((trackedEntity == null) ? 0 : trackedEntity.hashCode());
result = prime * result + ((program == null) ? 0 : program.hashCode());
Expand All @@ -174,7 +174,7 @@ public boolean equals(Object obj) {
}

private boolean objectEquals(Enrollment other) {
return Objects.equals(incidentDate, other.incidentDate)
return Objects.equals(occurredDate, other.occurredDate)
&& Objects.equals(enrollmentDate, other.enrollmentDate)
&& Objects.equals(trackedEntity, other.trackedEntity)
&& Objects.equals(program, other.program);
Expand Down Expand Up @@ -218,12 +218,12 @@ public Enrollment setOrganisationUnit(OrganisationUnit organisationUnit) {

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getIncidentDate() {
return incidentDate;
public Date getOccurredDate() {
return occurredDate;
}

public void setIncidentDate(Date incidentDate) {
this.incidentDate = incidentDate;
public void setOccurredDate(Date occurredDate) {
this.occurredDate = occurredDate;
}

@JsonProperty
Expand Down Expand Up @@ -405,7 +405,7 @@ public String toString() {
+ ", organisationUnit="
+ (organisationUnit != null ? organisationUnit.getUid() : "null")
+ ", incidentDate="
+ incidentDate
+ occurredDate
+ ", enrollmentDate="
+ enrollmentDate
+ ", entityInstance="
Expand Down Expand Up @@ -439,7 +439,7 @@ private static void setShallowCopyValues(
copy.setEvents(new HashSet<>());
copy.setFollowup(original.getFollowup());
copy.setGeometry(original.getGeometry());
copy.setIncidentDate(original.getIncidentDate());
copy.setOccurredDate(original.getOccurredDate());
copy.setLastUpdatedAtClient(original.getLastUpdatedAtClient());
copy.setLastUpdatedByUserInfo(original.getLastUpdatedByUserInfo());
copy.setMessageConversations(ObjectUtils.copyOf(original.getMessageConversations()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testCopyOfWithPropertyValuesSet() {
assertEquals(original.getStatus(), copy.getStatus());
assertEquals(original.getNotes(), copy.getNotes());
assertEquals(original.getName(), copy.getName());
assertEquals(original.getIncidentDate(), copy.getIncidentDate());
assertEquals(original.getOccurredDate(), copy.getOccurredDate());
assertEquals(original.getEnrollmentDate(), copy.getEnrollmentDate());
assertEquals(original.getFollowup(), copy.getFollowup());
assertEquals(original.getGeometry(), copy.getGeometry());
Expand All @@ -90,7 +90,7 @@ void testCopyOfWithNullPropertyValues() {
assertEquals(original.getEnrollmentDate(), copy.getEnrollmentDate());
assertEquals(original.getFollowup(), copy.getFollowup());
assertEquals(original.getGeometry(), copy.getGeometry());
assertEquals(original.getIncidentDate(), copy.getIncidentDate());
assertEquals(original.getOccurredDate(), copy.getOccurredDate());
assertEquals(original.getName(), copy.getName());
assertEquals(original.getOrganisationUnit(), copy.getOrganisationUnit());
assertEquals(original.getStatus(), copy.getStatus());
Expand Down Expand Up @@ -121,7 +121,7 @@ private Enrollment getNewEnrollmentWithNoNulls() {
e.setEnrollmentDate(new Date());
e.setEvents(Set.of());
e.setFollowup(true);
e.setIncidentDate(new Date());
e.setOccurredDate(new Date());
e.setMessageConversations(List.of(new MessageConversation()));
e.setName("Enrollment 1");
e.setOrganisationUnit(new OrganisationUnit("org1"));
Expand All @@ -141,7 +141,7 @@ private Enrollment getNewEnrollmentWithNulls() {
e.setCompletedDate(null);
e.setEnrollmentDate(null);
e.setEvents(null);
e.setIncidentDate(null);
e.setOccurredDate(null);
e.setMessageConversations(null);
e.setOrganisationUnit(null);
e.setProgram(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public JdbcEnrollmentAnalyticsTableManager(
new AnalyticsTableColumn(
quote("completeddate"),
TIMESTAMP,
"case pi.status when 'COMPLETED' then pi.enddate end"),
"case pi.status when 'COMPLETED' then pi.completeddate end"),
new AnalyticsTableColumn(quote("lastupdated"), TIMESTAMP, "pi.lastupdated"),
new AnalyticsTableColumn(quote("storedby"), VARCHAR_255, "pi.storedby"),
new AnalyticsTableColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,32 @@ private void populateTableInternal(AnalyticsTablePartition partition, String sql
List<String> columnNames =
getDimensionColumns().stream().map(AnalyticsTableColumn::getName).collect(toList());

MappingBatchHandler batchHandler =
try (MappingBatchHandler batchHandler =
MappingBatchHandler.builder()
.jdbcConfiguration(jdbcConfiguration)
.tableName(partition.getTempTableName())
.columns(columnNames)
.build();

batchHandler.init();

JdbcOwnershipWriter writer = JdbcOwnershipWriter.getInstance(batchHandler);
AtomicInteger queryRowCount = new AtomicInteger();

jdbcTemplate.query(
sql,
resultSet -> {
writer.write(getRowMap(columnNames, resultSet));
queryRowCount.getAndIncrement();
});

log.info(
"OwnershipAnalytics query row count was {} for {}",
queryRowCount,
partition.getTempTableName());
batchHandler.flush();
.build()) {
batchHandler.init();

JdbcOwnershipWriter writer = JdbcOwnershipWriter.getInstance(batchHandler);
AtomicInteger queryRowCount = new AtomicInteger();

jdbcTemplate.query(
sql,
resultSet -> {
writer.write(getRowMap(columnNames, resultSet));
queryRowCount.getAndIncrement();
});

log.info(
"OwnershipAnalytics query row count was {} for {}",
queryRowCount,
partition.getTempTableName());
batchHandler.flush();
} catch (Exception ex) {
log.error("Failed to alter table ownership: ", ex);
}
}

private String getInputSql(Program program) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public JdbcTeiEnrollmentsAnalyticsTableManager(
new AnalyticsTableColumn(quote("programuid"), CHARACTER_11, NULL, "p.uid"),
new AnalyticsTableColumn(quote("programinstanceuid"), CHARACTER_11, NULL, "pi.uid"),
new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"),
new AnalyticsTableColumn(quote("enddate"), TIMESTAMP, "pi.enddate"),
new AnalyticsTableColumn(quote("enddate"), TIMESTAMP, "pi.completeddate"),
new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"),
new AnalyticsTableColumn(quote("enrollmentstatus"), VARCHAR_50, "pi.status"),
new AnalyticsTableColumn(quote("pigeometry"), GEOMETRY, "pi.geometry")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ProgramNotificationMessageRenderer
e -> e.getOrganisationUnit().getDisplayName())
.put(ProgramTemplateVariable.CURRENT_DATE, e -> formatDate(new Date()))
.put(ProgramTemplateVariable.ENROLLMENT_DATE, e -> formatDate(e.getEnrollmentDate()))
.put(ProgramTemplateVariable.INCIDENT_DATE, e -> formatDate(e.getIncidentDate()))
.put(ProgramTemplateVariable.INCIDENT_DATE, e -> formatDate(e.getOccurredDate()))
.put(
ProgramTemplateVariable.DAYS_SINCE_ENROLLMENT_DATE,
e -> daysSince(e.getEnrollmentDate()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ public Enrollment prepareEnrollment(
}

if (incidentDate != null) {
enrollment.setIncidentDate(incidentDate);
enrollment.setOccurredDate(incidentDate);
} else {
enrollment.setIncidentDate(new Date());
enrollment.setOccurredDate(new Date());
}

enrollment.setStatus(programStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private String toDateProperty(NotificationTrigger trigger) {
if (trigger == NotificationTrigger.SCHEDULED_DAYS_ENROLLMENT_DATE) {
return "enrollmentDate";
} else if (trigger == NotificationTrigger.SCHEDULED_DAYS_INCIDENT_DATE) {
return "incidentDate";
return "occurredDate";
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected void register(
if (enrollments.isEmpty()) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollmentDate(new Date());
enrollment.setIncidentDate(new Date());
enrollment.setOccurredDate(new Date());
enrollment.setProgram(smsCommand.getProgram());
enrollment.setStatus(ProgramStatus.ACTIVE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected SmsResponse postProcess(IncomingSms sms, SmsSubmission submission)
enrollment = enrollmentService.getEnrollment(enrollmentid.getUid());
// Update these dates in case they've changed
enrollment.setEnrollmentDate(enrollmentDate);
enrollment.setIncidentDate(incidentDate);
enrollment.setOccurredDate(incidentDate);
} else {
enrollment =
enrollmentService.enrollTrackedEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected SmsResponse postProcess(IncomingSms sms, SmsSubmission submission)
if (enrollments.isEmpty()) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollmentDate(new Date());
enrollment.setIncidentDate(new Date());
enrollment.setOccurredDate(new Date());
enrollment.setProgram(program);
enrollment.setStatus(ProgramStatus.ACTIVE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void initTest() {
enrollment.setProgram(programA);
enrollment.setOrganisationUnit(organisationUnitA);
enrollment.setEnrollmentDate(new Date());
enrollment.setIncidentDate(new Date());
enrollment.setOccurredDate(new Date());
enrollment.setTrackedEntity(tei);

event = new Event();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public ImportSummary saveCompleteDataSetRegistrationsJson(
private ImportSummary saveCompleteDataSetRegistrations(
ImportOptions importOptions,
Callable<CompleteDataSetRegistrations> deserializeRegistrations) {
BatchHandler<CompleteDataSetRegistration> batchHandler =
batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class);
try {

try (BatchHandler<CompleteDataSetRegistration> batchHandler =
batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class)) {
CompleteDataSetRegistrations completeDataSetRegistrations = deserializeRegistrations.call();
ImportSummary summary =
saveCompleteDataSetRegistrations(
Expand All @@ -256,7 +256,7 @@ private ImportSummary saveCompleteDataSetRegistrations(

return summary;
} catch (Exception ex) {
batchHandler.flush();
log.error("Complete data set registrations could not be saved.");
return handleImportError(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,13 @@ private ImportSummary importDataValueSet(
ImportOptions options, JobConfiguration id, Callable<DataValueSetReader> createReader) {
options = ObjectUtils.firstNonNull(options, ImportOptions.getDefaultImportOptions());

BatchHandler<DataValue> dvBatch =
batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class);
BatchHandler<DataValueAudit> dvaBatch =
batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class);

notifier.clear(id);

try (DataValueSetReader reader = createReader.call()) {
try (BatchHandler<DataValue> dvBatch =
batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class);
BatchHandler<DataValueAudit> dvaBatch =
batchHandlerFactory.createBatchHandler(DataValueAuditBatchHandler.class);
DataValueSetReader reader = createReader.call()) {
ImportSummary summary = importDataValueSet(options, id, reader, dvBatch, dvaBatch);

dvBatch.flush();
Expand All @@ -640,8 +639,6 @@ private ImportSummary importDataValueSet(

return summary;
} catch (Exception ex) {
dvBatch.flush();
dvaBatch.flush();
log.error(DebugUtils.getStackTrace(ex));
notifier.notify(id, ERROR, "Process failed: " + ex.getMessage(), true);
return new ImportSummary(ImportStatus.ERROR, "The import process failed: " + ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public org.hisp.dhis.dxf2.deprecated.tracker.enrollment.Enrollment getEnrollment
enrollment.setProgram(programInstance.getProgram().getUid());
enrollment.setStatus(EnrollmentStatus.fromProgramStatus(programInstance.getStatus()));
enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
enrollment.setIncidentDate(programInstance.getIncidentDate());
enrollment.setIncidentDate(programInstance.getOccurredDate());
enrollment.setFollowup(programInstance.getFollowup());
enrollment.setCompletedDate(programInstance.getCompletedDate());
enrollment.setCompletedBy(programInstance.getCompletedBy());
Expand Down Expand Up @@ -668,20 +668,20 @@ private ImportSummary validateProgramInstance(
return importSummary;
}

if (program.getDisplayIncidentDate() && programInstance.getIncidentDate() == null) {
if (program.getDisplayIncidentDate() && programInstance.getOccurredDate() == null) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription("DisplayIncidentDate is true but IncidentDate is null ");
importSummary.incrementIgnored();

return importSummary;
}

if (programInstance.getIncidentDate() != null
if (programInstance.getOccurredDate() != null
&& !DateUtils.dateIsValid(
DateUtils.getMediumDateString(programInstance.getIncidentDate()))) {
DateUtils.getMediumDateString(programInstance.getOccurredDate()))) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription(
"Invalid enollment incident date: " + programInstance.getIncidentDate());
"Invalid enollment incident date: " + programInstance.getOccurredDate());
importSummary.incrementIgnored();

return importSummary;
Expand Down Expand Up @@ -936,7 +936,7 @@ private ImportSummary updateEnrollment(
programInstance.setProgram(program);

if (enrollment.getIncidentDate() != null) {
programInstance.setIncidentDate(enrollment.getIncidentDate());
programInstance.setOccurredDate(enrollment.getIncidentDate());
}

if (enrollment.getEnrollmentDate() != null) {
Expand All @@ -951,7 +951,7 @@ private ImportSummary updateEnrollment(

programInstance.setFollowup(enrollment.getFollowup());

if (program.getDisplayIncidentDate() && programInstance.getIncidentDate() == null) {
if (program.getDisplayIncidentDate() && programInstance.getOccurredDate() == null) {
return new ImportSummary(
ImportStatus.ERROR, "DisplayIncidentDate is true but IncidentDate is null")
.incrementIgnored();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public enum COLUMNS {
.put(COLUMNS.ENROLLMENTDATE, new TableColumn("pi", "enrollmentdate"))
.put(COLUMNS.INCIDENTDATE, new TableColumn("pi", "incidentdate"))
.put(COLUMNS.FOLLOWUP, new TableColumn("pi", "followup"))
.put(COLUMNS.COMPLETED, new TableColumn("pi", "enddate"))
.put(COLUMNS.COMPLETED, new TableColumn("pi", "completeddate"))
.put(COLUMNS.COMPLETEDBY, new TableColumn("pi", "completedby"))
.put(COLUMNS.STOREDBY, new TableColumn("pi", "storedby"))
.put(COLUMNS.DELETED, new TableColumn("pi", "deleted"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void addProgramInstance(Program program) {
if (getProgramInstancesCount(program) == 0 && program.isWithoutRegistration()) {
Enrollment pi = new Enrollment();
pi.setEnrollmentDate(new Date());
pi.setIncidentDate(new Date());
pi.setOccurredDate(new Date());
pi.setProgram(program);
pi.setStatus(ProgramStatus.ACTIVE);
pi.setStoredBy("system-process");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void verifyProgramInstanceIsSavedForEventProgram() {
verify(enrollmentService).addEnrollment(argument.capture());

assertThat(argument.getValue().getEnrollmentDate(), is(notNullValue()));
assertThat(argument.getValue().getIncidentDate(), is(notNullValue()));
assertThat(argument.getValue().getOccurredDate(), is(notNullValue()));
assertThat(argument.getValue().getProgram(), is(programA));
assertThat(argument.getValue().getStatus(), is(ProgramStatus.ACTIVE));
assertThat(argument.getValue().getStoredBy(), is("system-process"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public RuleEnrollment toMappedRuleEnrollment(
}
return RuleEnrollment.create(
enrollment.getUid(),
enrollment.getIncidentDate(),
enrollment.getOccurredDate(),
enrollment.getEnrollmentDate(),
RuleEnrollment.Status.valueOf(enrollment.getStatus().toString()),
orgUnit,
Expand Down
Loading

0 comments on commit 7ca34ed

Please sign in to comment.