Skip to content

Commit

Permalink
#749 | Use StandardReportCardType type while creating default dashboa…
Browse files Browse the repository at this point in the history
…rd / cards
  • Loading branch information
1t5j0y committed Sep 5, 2024
1 parent 6009a3a commit 8416033
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.avni.server.dao;

import org.avni.server.domain.StandardReportCardType;
import org.avni.server.domain.StandardReportCardTypeType;
import org.joda.time.DateTime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -28,5 +29,5 @@ Page<StandardReportCardType> findByLastModifiedDateTimeIsBetweenOrderByLastModif

boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime);

List<StandardReportCardType> findAllByNameIn(Set<String> defaultDashboardStandardCardTypeNames);
List<StandardReportCardType> findAllByTypeIn(Set<StandardReportCardTypeType> defaultDashboardStandardCardTypeTypes);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package org.avni.server.mapper.dashboard;

import org.avni.server.domain.StandardReportCardTypeType;

import java.util.HashMap;
import java.util.Map;

import static org.avni.server.domain.StandardReportCardTypeType.*;

public interface DefaultDashboardConstants {
String SCHEDULED_VISITS_CARD = "Scheduled visits";
String OVERDUE_VISITS_CARD = "Overdue visits";
String TOTAL_CARD = "Total";
String RECENT_REGISTRATIONS_CARD = "Recent registrations";
String RECENT_ENROLMENTS_CARD = "Recent enrolments";
String RECENT_VISITS_CARD = "Recent visits";
String DUE_CHECKLIST_CARD = "Due checklist";
Map<String, String> CARD_NAME_UUID_MAPPING = new HashMap<String, String>() {{
put(SCHEDULED_VISITS_CARD, "6085c2f4-52e7-4b08-85b6-d6b2612b4cf5");
put(OVERDUE_VISITS_CARD, "85ce7239-e8b5-4e57-b07d-66c18cee47b2");
put(TOTAL_CARD, "a1673f8a-c394-4bcf-8b6f-63d83a5443e2");
put(RECENT_REGISTRATIONS_CARD, "f366f35a-5c4f-4ff7-b510-2dc9f5f88847");
put(RECENT_ENROLMENTS_CARD, "e1036b69-df46-4351-9916-10cd4cfcb6bd");
put(RECENT_VISITS_CARD, "dd961ee1-9d4e-4ec9-99f0-99b36672be7c");
put(DUE_CHECKLIST_CARD, "9b7632dd-4e98-429a-8e42-67a947bf9ece");
Map<StandardReportCardTypeType, String> CARD_TYPE_UUID_MAPPING = new HashMap<StandardReportCardTypeType, String>() {{
put(ScheduledVisits, "6085c2f4-52e7-4b08-85b6-d6b2612b4cf5");
put(OverdueVisits, "85ce7239-e8b5-4e57-b07d-66c18cee47b2");
put(Total, "a1673f8a-c394-4bcf-8b6f-63d83a5443e2");
put(RecentRegistrations, "f366f35a-5c4f-4ff7-b510-2dc9f5f88847");
put(RecentEnrolments, "e1036b69-df46-4351-9916-10cd4cfcb6bd");
put(RecentVisits, "dd961ee1-9d4e-4ec9-99f0-99b36672be7c");
put(DueChecklist, "9b7632dd-4e98-429a-8e42-67a947bf9ece");
}};

String DEFAULT_DASHBOARD = "Default Dashboard";
Expand All @@ -36,12 +33,12 @@ public interface DefaultDashboardConstants {
}};

Map<String, String> SECTION_CARD_MAPPING = new HashMap<String, String>() {{
put(VISIT_DETAILS_SECTION.concat(SCHEDULED_VISITS_CARD), "4d139c45-1854-46ec-ad80-40725f7b9b8a");
put(VISIT_DETAILS_SECTION.concat(OVERDUE_VISITS_CARD), "4dff9285-88b3-43de-a90b-9823ab32e433");
put(RECENT_STATISTICS_SECTION.concat(RECENT_REGISTRATIONS_CARD), "8afecd6c-741c-4871-86f1-bce171f8bfd8");
put(RECENT_STATISTICS_SECTION.concat(RECENT_ENROLMENTS_CARD), "383b8df8-93d8-43d9-bc96-545e1176fe63");
put(RECENT_STATISTICS_SECTION.concat(RECENT_VISITS_CARD), "9fb198b6-ae10-4c3f-a8e6-652b7d1b7e9c");
put(REGISTRATION_OVERVIEW_SECTION.concat(TOTAL_CARD), "e02a68ed-c02b-4cba-a5b5-6a5c71ab5eb8");
put(VISIT_DETAILS_SECTION.concat(ScheduledVisits.name()), "4d139c45-1854-46ec-ad80-40725f7b9b8a");
put(VISIT_DETAILS_SECTION.concat(OverdueVisits.name()), "4dff9285-88b3-43de-a90b-9823ab32e433");
put(RECENT_STATISTICS_SECTION.concat(RecentRegistrations.name()), "8afecd6c-741c-4871-86f1-bce171f8bfd8");
put(RECENT_STATISTICS_SECTION.concat(RecentEnrolments.name()), "383b8df8-93d8-43d9-bc96-545e1176fe63");
put(RECENT_STATISTICS_SECTION.concat(RecentVisits.name()), "9fb198b6-ae10-4c3f-a8e6-652b7d1b7e9c");
put(REGISTRATION_OVERVIEW_SECTION.concat(Total.name()), "e02a68ed-c02b-4cba-a5b5-6a5c71ab5eb8");
}};

String SUBJECT_TYPE_FILTER = "Subject Type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.avni.server.common.BulkItemSaveException;
import org.avni.server.dao.*;
import org.avni.server.domain.*;
import org.avni.server.mapper.dashboard.DefaultDashboardConstants;
import org.avni.server.util.BadRequestError;
import org.avni.server.util.ObjectMapperSingleton;
import org.avni.server.web.contract.ReportCardContract;
Expand All @@ -16,10 +15,17 @@
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.avni.server.domain.StandardReportCardTypeType.OverdueVisits;
import static org.avni.server.domain.StandardReportCardTypeType.ScheduledVisits;
import static org.avni.server.mapper.dashboard.DefaultDashboardConstants.*;

@Service
public class CardService implements NonScopeAwareService, DefaultDashboardConstants {
public class CardService implements NonScopeAwareService {
private final CardRepository cardRepository;
private final StandardReportCardTypeRepository standardReportCardTypeRepository;
private final SubjectTypeRepository subjectTypeRepository;
Expand Down Expand Up @@ -186,13 +192,13 @@ public void saveCards(ReportCardBundleRequest[] cardContracts) {
}
}

public Map<String, ReportCard> createDefaultDashboardCards(Organisation organisation) {
Map<String, String> defaultDashboardCards = CARD_NAME_UUID_MAPPING;
List<StandardReportCardType> standardReportCardTypes = standardReportCardTypeRepository.findAllByNameIn(defaultDashboardCards.keySet());
Map<String, ReportCard> savedCards = new HashMap<>();
public Map<StandardReportCardTypeType, ReportCard> createDefaultDashboardCards(Organisation organisation) {
Map<StandardReportCardTypeType, String> defaultDashboardCards = CARD_TYPE_UUID_MAPPING;
List<StandardReportCardType> standardReportCardTypes = standardReportCardTypeRepository.findAllByTypeIn(defaultDashboardCards.keySet());
Map<StandardReportCardTypeType, ReportCard> savedCards = new HashMap<>();
standardReportCardTypes.forEach(standardReportCardType -> {
ReportCard reportCard = new ReportCard();
reportCard.setUuid(defaultDashboardCards.get(standardReportCardType.getName()));
reportCard.setUuid(defaultDashboardCards.get(standardReportCardType.getType()));
reportCard.setStandardReportCardType(standardReportCardType);
reportCard.setOrganisationId(organisation.getId());
reportCard.setName(standardReportCardType.getDescription());
Expand All @@ -203,13 +209,13 @@ public Map<String, ReportCard> createDefaultDashboardCards(Organisation organisa
if (standardReportCardType.getType().isRecentStandardReportCardType()) {
reportCard.setStandardReportCardInputRecentDuration(ValueUnit.getDefaultRecentDuration());
}
if (standardReportCardType.getName().equals(OVERDUE_VISITS_CARD)) {
if (standardReportCardType.getType().equals(OverdueVisits)) {
reportCard.setColour(RED_BG_COLOUR);
}
if (standardReportCardType.getName().equals(SCHEDULED_VISITS_CARD)) {
if (standardReportCardType.getType().equals(ScheduledVisits)) {
reportCard.setColour(GREEN_BG_COLOUR);
}
savedCards.put(reportCard.getName(), cardRepository.save(reportCard));
savedCards.put(standardReportCardType.getType(), cardRepository.save(reportCard));
});
return savedCards;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.avni.server.dao.*;
import org.avni.server.domain.*;
import org.avni.server.domain.app.dashboard.DashboardFilter;
import org.avni.server.mapper.dashboard.DefaultDashboardConstants;
import org.avni.server.util.BadRequestError;
import org.avni.server.util.ReactAdminUtil;
import org.avni.server.web.contract.reports.*;
Expand All @@ -21,8 +20,12 @@
import java.util.Map;
import java.util.Set;

import static org.avni.server.domain.StandardReportCardTypeType.*;
import static org.avni.server.mapper.dashboard.DefaultDashboardConstants.*;


@Service
public class DashboardService implements NonScopeAwareService, DefaultDashboardConstants {
public class DashboardService implements NonScopeAwareService {
private final DashboardRepository dashboardRepository;
private final CardRepository cardRepository;
private final DashboardSectionRepository dashboardSectionRepository;
Expand Down Expand Up @@ -215,27 +218,27 @@ public void saveDashboards(DashboardBundleContract[] dashboardContracts) {
}

public Dashboard createDefaultDashboard(Organisation organisation) {
Map<String, ReportCard> defaultDashboardCards = cardService.createDefaultDashboardCards(organisation);
Map<StandardReportCardTypeType, ReportCard> defaultDashboardCards = cardService.createDefaultDashboardCards(organisation);
Dashboard defaultDashboard = createDashboard(organisation, DEFAULT_DASHBOARD);

DashboardSection visitDetailsSection = createDashboardSection(organisation, VISIT_DETAILS_SECTION, 1.0);
DashboardSectionCardMapping scheduledVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(SCHEDULED_VISITS_CARD), visitDetailsSection, 1.0);
DashboardSectionCardMapping scheduledVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(ScheduledVisits), visitDetailsSection, 1.0);
visitDetailsSection.addDashboardSectionCardMapping(scheduledVisitsToVisitDetailsMapping);
DashboardSectionCardMapping overdueVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(OVERDUE_VISITS_CARD), visitDetailsSection, 2.0);
DashboardSectionCardMapping overdueVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(OverdueVisits), visitDetailsSection, 2.0);
visitDetailsSection.addDashboardSectionCardMapping(overdueVisitsToVisitDetailsMapping);
defaultDashboard.addSection(visitDetailsSection);

DashboardSection recentStatisticsSection = createDashboardSection(organisation, RECENT_STATISTICS_SECTION, 2.0);
DashboardSectionCardMapping recentRegistrationsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(RECENT_REGISTRATIONS_CARD), recentStatisticsSection, 1.0);
DashboardSectionCardMapping recentRegistrationsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(RecentRegistrations), recentStatisticsSection, 1.0);
recentStatisticsSection.addDashboardSectionCardMapping(recentRegistrationsToStatisticsMapping);
DashboardSectionCardMapping recentEnrolmentsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(RECENT_ENROLMENTS_CARD), recentStatisticsSection, 2.0);
DashboardSectionCardMapping recentEnrolmentsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(RecentEnrolments), recentStatisticsSection, 2.0);
recentStatisticsSection.addDashboardSectionCardMapping(recentEnrolmentsToStatisticsMapping);
DashboardSectionCardMapping recentVisitsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(RECENT_VISITS_CARD), recentStatisticsSection, 3.0);
DashboardSectionCardMapping recentVisitsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(RecentVisits), recentStatisticsSection, 3.0);
recentStatisticsSection.addDashboardSectionCardMapping(recentVisitsToStatisticsMapping);
defaultDashboard.addSection(recentStatisticsSection);

DashboardSection registrationOverviewSection = createDashboardSection(organisation, REGISTRATION_OVERVIEW_SECTION,3.0);
DashboardSectionCardMapping totalToRegistrationOverviewMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(TOTAL_CARD), registrationOverviewSection, 1.0);
DashboardSectionCardMapping totalToRegistrationOverviewMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(Total), registrationOverviewSection, 1.0);
registrationOverviewSection.addDashboardSectionCardMapping(totalToRegistrationOverviewMapping);
defaultDashboard.addSection(registrationOverviewSection);

Expand Down Expand Up @@ -275,7 +278,7 @@ private DashboardSection createDashboardSection(Organisation organisation, Strin

private DashboardSectionCardMapping createDashboardSectionCardMapping(Organisation organisation, ReportCard reportCard, DashboardSection dashboardSection, Double displayOrder) {
DashboardSectionCardMapping dashboardSectionCardMapping = new DashboardSectionCardMapping();
setDefaults(dashboardSectionCardMapping, organisation, SECTION_CARD_MAPPING.get(dashboardSection.getName().concat(reportCard.getName())));
setDefaults(dashboardSectionCardMapping, organisation, SECTION_CARD_MAPPING.get(dashboardSection.getName().concat(reportCard.getStandardReportCardType().getType().name())));
dashboardSectionCardMapping.setCard(reportCard);
dashboardSectionCardMapping.setDashboardSection(dashboardSection);
dashboardSectionCardMapping.setDisplayOrder(displayOrder);
Expand Down

0 comments on commit 8416033

Please sign in to comment.