Skip to content

Commit

Permalink
Merge branch 'canned-analytics'
Browse files Browse the repository at this point in the history
  • Loading branch information
mahalakshme committed Nov 14, 2023
2 parents 233c37f + eeb01ae commit f971637
Show file tree
Hide file tree
Showing 17 changed files with 988 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ dependencies {
implementation 'org.keycloak:keycloak-admin-client:21.0.2'
implementation 'org.antlr:ST4:4.3.4'
implementation 'org.hibernate:hibernate-validator:7.0.5.Final'
implementation "joda-time:joda-time:2.9.4"
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.6'
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.6'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.6'
implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.12.6'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.12.6'
}

tasks.named('test') {
Expand Down
150 changes: 150 additions & 0 deletions src/main/java/org/avniproject/etl/controller/ReportController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package org.avniproject.etl.controller;

import org.avniproject.etl.domain.OrgIdentityContextHolder;
import org.avniproject.etl.dto.AggregateReportResult;
import org.avniproject.etl.dto.UserActivityDTO;
import org.avniproject.etl.repository.ReportRepository;
import org.avniproject.etl.util.ReportUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ReportController {

private final ReportRepository reportRepository;
private final ReportUtil reportUtil;

@Autowired
public ReportController(ReportRepository reportRepository, ReportUtil reportUtil) {
this.reportRepository = reportRepository;
this.reportUtil = reportUtil;
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/aggregate/summaryTable", method = RequestMethod.GET)
public List<UserActivityDTO> getSummaryTable(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds){
return reportRepository.generateSummaryTable(
OrgIdentityContextHolder.getDbSchema()
);
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "report/hr/userActivity", method = RequestMethod.GET)
public List<UserActivityDTO> getUserActivity(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds){
return reportRepository.generateUserActivity(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateDynamicWhere(startDate, endDate, "registration_date"),
reportUtil.getDateDynamicWhere(startDate, endDate, "encounter_date_time"),
reportUtil.getDateDynamicWhere(startDate, endDate, "enrolment_date_time"),
reportUtil.getDynamicUserWhere(userIds, "u.id")
);
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/syncFailures",method = RequestMethod.GET)
public List<UserActivityDTO> getUserWiseSyncFailures(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds){
return reportRepository.generateUserSyncFailures(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateDynamicWhere(startDate, endDate, "st.sync_start_time"),
reportUtil.getDynamicUserWhere(userIds, "u.id")
);
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/deviceModels", method = RequestMethod.GET)
public List<AggregateReportResult> getUserWiseDeviceModels(@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {

return reportRepository.generateUserDeviceModels(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDynamicUserWhere(userIds, "u.id"));
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/appVersions", method = RequestMethod.GET)
public List<AggregateReportResult> getUserWiseAppVersions(@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {

return reportRepository.generateUserAppVersions(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDynamicUserWhere(userIds, "u.id"));
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/userDetails", method = RequestMethod.GET)
public List<UserActivityDTO> getUserDetails(@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {

return reportRepository.generateUserDetails(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDynamicUserWhere(userIds, "u.id"));
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/latestSyncs", method = RequestMethod.GET)
public List<UserActivityDTO> getLatestSyncs(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {

return reportRepository.generateLatestSyncs(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateDynamicWhere(startDate, endDate, "st.sync_end_time"),
reportUtil.getDynamicUserWhere(userIds, "u.id"));
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/medianSync", method = RequestMethod.GET)
public List<UserActivityDTO> getMedianSync(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {

return reportRepository.generateMedianSync(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateSeries(startDate, endDate));
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/championUsers", method = RequestMethod.GET)
public List<AggregateReportResult> getChampionUsers(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {
return reportRepository.generateCompletedVisitsOnTimeByProportion(
">= 0.5",
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateDynamicWhere(startDate, endDate, "encounter_date_time"),
reportUtil.getDynamicUserWhere(userIds, "u.id"));
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/nonPerformingUsers", method = RequestMethod.GET)
public List<AggregateReportResult> getNonPerformingUsers(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {
return reportRepository.generateCompletedVisitsOnTimeByProportion(
"<= 0.5",
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateDynamicWhere(startDate, endDate, "encounter_date_time"),
reportUtil.getDynamicUserWhere(userIds, "u.id")
);
}

@PreAuthorize("hasAnyAuthority('analytics_user')")
@RequestMapping(value = "/report/hr/mostCancelled", method = RequestMethod.GET)
public List<AggregateReportResult> getUsersCancellingMostVisits(@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userIds", required = false, defaultValue = "") List<Long> userIds) {
return reportRepository.generateUserCancellingMostVisits(
OrgIdentityContextHolder.getDbSchema(),
reportUtil.getDateDynamicWhere(startDate, endDate, "encounter_date_time"),
reportUtil.getDynamicUserWhere(userIds, "u.id"));
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,54 @@ public List<TableMetadata> getAllSubjectTables() {
return tableMetadata.stream().filter(TableMetadata::isSubjectTable).toList();
}

public List<String> getAllSubjectTableNames() {
List<TableMetadata> subjectTables = getAllSubjectTables();
List<String> subjectTableNames = new ArrayList<>();
for(TableMetadata subject : subjectTables){
subjectTableNames.add(subject.getName());
}
return subjectTableNames;
}

public List<TableMetadata> getAllProgramEnrolmentTables() {
return tableMetadata.stream().filter(table -> table.getType() == TableMetadata.Type.ProgramEnrolment).toList();
}

public List<String> getAllProgramEnrolmentTableNames() {
List<TableMetadata> programEnrolmentTables = getAllProgramEnrolmentTables();
List<String> programEnrolmentTableNames = new ArrayList<>();
for(TableMetadata programEnrolment : programEnrolmentTables){
programEnrolmentTableNames.add(programEnrolment.getName());
}
return programEnrolmentTableNames;
}

public List<TableMetadata> getAllProgramEncounterTables() {
return tableMetadata.stream().filter(table -> table.getType() == TableMetadata.Type.ProgramEncounter).toList();
}

public List<String> getAllProgramEncounterTableNames() {
List<TableMetadata> programEncounterTables = getAllProgramEncounterTables();
List<String> programEncounterTableNames = new ArrayList<>();
for(TableMetadata programEncounter : programEncounterTables){
programEncounterTableNames.add(programEncounter.getName());
}
return programEncounterTableNames;
}

public List<TableMetadata> getAllEncounterTables() {
return tableMetadata.stream().filter(table -> table.getType() == TableMetadata.Type.Encounter).toList();
}

public List<String> getAllEncounterTableNames() {
List<TableMetadata> encounterTables = getAllEncounterTables();
List<String> encounterTableNames = new ArrayList<>();
for(TableMetadata encounter : encounterTables){
encounterTableNames.add(encounter.getName());
}
return encounterTableNames;
}

private List<Diff> findChanges(SchemaMetadata currentSchema, TableMetadata newTable) {
List<Diff> diffs = new ArrayList<>();
Optional<TableMetadata> optionalMatchingTable = currentSchema.findMatchingTable(newTable);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/avniproject/etl/dto/AggregateReportResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.avniproject.etl.dto;

public class AggregateReportResult {
private String label;
private Long value;
private String id;

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public Long getValue() {
return value;
}

public void setValue(Long value) {
this.value = value;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
Loading

0 comments on commit f971637

Please sign in to comment.