Skip to content

chore: compute event statistics using IdentifiableObjectManager DHIS2-17638 #17950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

teleivo
Copy link
Contributor

@teleivo teleivo commented Jul 2, 2024

Big picture

Tracker has multiple services for each entity like tracked entity, enrollment and event. One is in dhis-api and one in dhis-service-tracker. Our goal is to provide one API (service) per entity that is part of the tracker domain/team.

Trackers architecture splits read/write into exporter services and an importer. So if you want to get data you use an exporter. If you want to insert, update or delete you have to go through the importer. Only then can we ensure integrity of tracker data.

Another goal is that code that provides tracker functionality and is thus owned by the tracker team lives in ideally one maven module (We can settle on a name later on maybe dhis-service-tracker or dhis-tracker).

This is a big task that we are going to implement in many small steps.

This PR

There are a couple of issues with how the event/data value statistics are computed in the backend and shown in the data management app. There is a lengthy discussion on it in https://dhis2.slack.com/archives/CPGUFVC56/p1719906006918859. We could not settle on a way forward. We will discuss this in a dedicated meeting.

This PR keeps the behavior as is while getting us closer to our big picture described above. We can/will adapt once we come to an agreement with the platform team.

The logic of computing the last updated dates is extracted from

Calendar cal = PeriodType.createCalendarInstance();
cal.add(Calendar.DAY_OF_YEAR, (days * -1));
return eventStore.getEventCountLastUpdatedAfter(cal.getTime());

(It is also the same for the data value counts)

The query that was previously part of our dhis-service-core HibernateEventStore

public long getEventCountLastUpdatedAfter(Date time) {
CriteriaBuilder builder = getCriteriaBuilder();
return getCount(
builder,
newJpaParameters()
.addPredicate(root -> builder.greaterThanOrEqualTo(root.get("lastUpdated"), time))
.count(builder::countDistinct));
}

is replaced by

public int getCountGeLastUpdated(@Nonnull Date lastUpdated) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param =
new JpaQueryParameters<T>()
.addPredicates(getSharingPredicates(builder))
.addPredicate(
root -> builder.greaterThanOrEqualTo(root.get("lastUpdated"), lastUpdated))
.count(root -> builder.countDistinct(root.get("id")));
return getCount(builder, param).intValue();
}

@teleivo teleivo requested a review from a team July 2, 2024 10:55
Copy link

sonarqubecloud bot commented Jul 2, 2024

@teleivo teleivo marked this pull request as ready for review July 2, 2024 11:01
@teleivo teleivo enabled auto-merge (squash) July 2, 2024 11:02
@enricocolasante enricocolasante requested a review from a team July 2, 2024 12:38
@teleivo teleivo merged commit 82e5015 into master Jul 2, 2024
15 checks passed
@teleivo teleivo deleted the DHIS2-17638-4 branch July 2, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants