diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java index ecb62a024e64..0e180643f1b9 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java @@ -138,7 +138,7 @@ public class DataSet extends BaseDimensionalItemObject private int expiryDays; /** Days after period end to qualify for timely data submission */ - private int timelyDays; + private double timelyDays; /** User group which will receive notifications when data set is marked complete, can be null. */ private UserGroup notificationRecipients; @@ -631,11 +631,11 @@ public void setExpiryDays(int expiryDays) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public int getTimelyDays() { + public double getTimelyDays() { return timelyDays; } - public void setTimelyDays(int timelyDays) { + public void setTimelyDays(double timelyDays) { this.timelyDays = timelyDays; } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/DateUtils.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/DateUtils.java index 1070c6dc67ff..3b95df5d508d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/DateUtils.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/util/DateUtils.java @@ -160,6 +160,8 @@ public class DateUtils { private static final long MS_PER_S = 1000; + public static final long SECONDS_PER_DAY = 86400; + private static final Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)(d|h|m|s)$"); private static final Map TEMPORAL_MAP = diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java index 6b78ce891c22..cdc326959008 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java @@ -33,9 +33,9 @@ import static org.hisp.dhis.commons.util.TextUtils.replace; import static org.hisp.dhis.db.model.DataType.BOOLEAN; import static org.hisp.dhis.db.model.DataType.CHARACTER_11; -import static org.hisp.dhis.db.model.DataType.DATE; import static org.hisp.dhis.db.model.DataType.INTEGER; import static org.hisp.dhis.db.model.DataType.TEXT; +import static org.hisp.dhis.db.model.DataType.TIMESTAMP; import static org.hisp.dhis.db.model.constraint.Nullable.NOT_NULL; import static org.hisp.dhis.util.DateUtils.toLongDate; @@ -256,7 +256,8 @@ private String getPartitionClause(AnalyticsTablePartition partition) { private List getColumns() { String idColAlias = "concat(ds.uid,'-',ps.iso,'-',ous.organisationunituid,'-',ao.uid) as id "; - String timelyDateDiff = "cast(cdr.date as date) - ps.enddate"; + String timelyDateDiff = + "extract(epoch from (cdr.date - ps.enddate)) / ( " + DateUtils.SECONDS_PER_DAY + " )"; String timelyAlias = "((" + timelyDateDiff + ") <= ds.timelydays) as timely"; List columns = new ArrayList<>(); @@ -281,7 +282,7 @@ private List getColumns() { columns.add( AnalyticsTableColumn.builder() .name("value") - .dataType(DATE) + .dataType(TIMESTAMP) .valueType(FACT) .selectExpression("cdr.date as value") .build()); @@ -304,7 +305,7 @@ select distinct(extract(year from pe.startdate)) \ sql += replace( "and pe.startdate >= '${fromDate}'", - Map.of("fromDate", DateUtils.toMediumDate(params.getFromDate()))); + Map.of("fromDate", DateUtils.toLongDate(params.getFromDate()))); } return jdbcTemplate.queryForList(sql, Integer.class); diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_20__Update_dataset_timliness_to_double.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_20__Update_dataset_timliness_to_double.sql new file mode 100644 index 000000000000..cef0ecad0cd2 --- /dev/null +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_20__Update_dataset_timliness_to_double.sql @@ -0,0 +1 @@ +ALTER TABLE dataset ALTER COLUMN timelydays TYPE DOUBLE PRECISION USING timelydays::DOUBLE PRECISION; \ No newline at end of file