Skip to content

Commit

Permalink
#749 | Default dashboard names, uuids etc as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed Aug 27, 2024
1 parent 4330194 commit c0dba66
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.avni.server.mapper.dashboard;

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

public class DefaultDashboardConstants {
public static final String SCHEDULED_VISITS_CARD = "Scheduled visits";
public static final String OVERDUE_VISITS_CARD = "Overdue visits";
public static final String TOTAL_CARD = "Total";
public static final String RECENT_REGISTRATIONS_CARD = "Recent registrations";
public static final String RECENT_ENROLMENTS_CARD = "Recent enrolments";
public static final String RECENT_VISITS_CARD = "Recent visits";
public static final String DUE_CHECKLIST_CARD = "Due checklist";
public static final 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");
}};

public static final String DEFAULT_DASHBOARD = "Default Dashboard";
public static final Map<String, String> DASHBOARD_NAME_UUID_MAPPING = new HashMap<String, String>() {{
put(DEFAULT_DASHBOARD, "c4d3bc0a-027e-4a6a-87dd-85e5b7285523");
}};

public static final String VISIT_DETAILS_SECTION = "Visit Details";
public static final String RECENT_STATISTICS_SECTION = "Recent Statistics";
public static final String REGISTRATION_OVERVIEW_SECTION = "Registration Overview";
public static final Map<String, String> SECTION_NAME_UUID_MAPPING = new HashMap<String, String>() {{
put(VISIT_DETAILS_SECTION, "741711ef-df17-4884-8928-20dee701479e");
put(RECENT_STATISTICS_SECTION, "fb302038-25a1-4cd6-9f56-80ef67b21103");
put(REGISTRATION_OVERVIEW_SECTION, "2ce712c2-3fa3-4ca4-9703-95766ef512c2");
}};

public static final 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");
}};

public static final String SUBJECT_TYPE_FILTER = "Subject Type";
public static final String AS_ON_DATE_FILTER = "As On Date";
public static final Map<String, String> FILTER_NAME_UUID_MAPPING = new HashMap<String, String>() {{
put(SUBJECT_TYPE_FILTER, "20367018-a168-43ff-a28f-64cd46ad3e2c");
put(AS_ON_DATE_FILTER, "efea5b8d-d621-47d0-a02c-c9b1a667b680");
}};

public static final String WHITE_BG_COLOUR = "#ffffff";
public static final String RED_BG_COLOUR = "#d32f2f";
public static final String GREEN_BG_COLOUR = "#388e3c";

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 Down Expand Up @@ -188,7 +189,7 @@ public void saveCards(ReportCardBundleRequest[] cardContracts) {
}

public Map<String, ReportCard> createDefaultDashboardCards(Organisation organisation) {
Map<String, String> defaultDashboardCards = getDefaultDashboardCardNamesAndUuids();
Map<String, String> defaultDashboardCards = DefaultDashboardConstants.CARD_NAME_UUID_MAPPING;
List<StandardReportCardType> standardReportCardTypes = standardReportCardTypeRepository.findAllByNameIn(defaultDashboardCards.keySet());
Map<String, ReportCard> savedCards = new HashMap<>();
standardReportCardTypes.forEach(standardReportCardType -> {
Expand All @@ -197,33 +198,21 @@ public Map<String, ReportCard> createDefaultDashboardCards(Organisation organisa
reportCard.setStandardReportCardType(standardReportCardType);
reportCard.setOrganisationId(organisation.getId());
reportCard.setName(standardReportCardType.getName());
reportCard.setColour("#ffffff");
reportCard.setColour(DefaultDashboardConstants.WHITE_BG_COLOUR);
reportCard.setStandardReportCardInputPrograms(Collections.emptyList());
reportCard.setStandardReportCardInputEncounterTypes(Collections.emptyList());
reportCard.setStandardReportCardInputSubjectTypes(Collections.emptyList());
if (isRecentStandardReportCard(standardReportCardType.getName())) {
reportCard.setStandardReportCardInputRecentDuration(new ValueUnit("1", "days"));
}
if (standardReportCardType.getName().equals("Overdue visits")) {
reportCard.setColour("#d32f2f");
if (standardReportCardType.getName().equals(DefaultDashboardConstants.OVERDUE_VISITS_CARD)) {
reportCard.setColour(DefaultDashboardConstants.RED_BG_COLOUR);
}
if (standardReportCardType.getName().equals("Scheduled visits")) {
reportCard.setColour("#388e3c");
if (standardReportCardType.getName().equals(DefaultDashboardConstants.SCHEDULED_VISITS_CARD)) {
reportCard.setColour(DefaultDashboardConstants.GREEN_BG_COLOUR);
}
savedCards.put(reportCard.getName(), cardRepository.save(reportCard));
});
return savedCards;
}

private static Map<String, String> getDefaultDashboardCardNamesAndUuids() {
Map<String, String> defaultDashboardStandardCardTypeNamesAndUuids = new HashMap<>();
defaultDashboardStandardCardTypeNamesAndUuids.put("Scheduled visits", "6085c2f4-52e7-4b08-85b6-d6b2612b4cf5");
defaultDashboardStandardCardTypeNamesAndUuids.put("Overdue visits", "85ce7239-e8b5-4e57-b07d-66c18cee47b2");
defaultDashboardStandardCardTypeNamesAndUuids.put("Total", "a1673f8a-c394-4bcf-8b6f-63d83a5443e2");
defaultDashboardStandardCardTypeNamesAndUuids.put("Recent registrations", "f366f35a-5c4f-4ff7-b510-2dc9f5f88847");
defaultDashboardStandardCardTypeNamesAndUuids.put("Recent enrolments", "e1036b69-df46-4351-9916-10cd4cfcb6bd");
defaultDashboardStandardCardTypeNamesAndUuids.put("Recent visits", "dd961ee1-9d4e-4ec9-99f0-99b36672be7c");
defaultDashboardStandardCardTypeNamesAndUuids.put("Due checklist", "9b7632dd-4e98-429a-8e42-67a947bf9ece");
return defaultDashboardStandardCardTypeNamesAndUuids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 Down Expand Up @@ -215,34 +216,34 @@ public void saveDashboards(DashboardBundleContract[] dashboardContracts) {

public Dashboard createDefaultDashboard(Organisation organisation) {
Map<String, ReportCard> defaultDashboardCards = cardService.createDefaultDashboardCards(organisation);
Dashboard defaultDashboard = createDashboard(organisation, "Default Dashboard", "c4d3bc0a-027e-4a6a-87dd-85e5b7285523");
Dashboard defaultDashboard = createDashboard(organisation, DefaultDashboardConstants.DEFAULT_DASHBOARD);

DashboardSection visitDetailsSection = createDashboardSection(organisation, "Visit Details", "741711ef-df17-4884-8928-20dee701479e", 1.0);
DashboardSectionCardMapping scheduledVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, "4d139c45-1854-46ec-ad80-40725f7b9b8a", defaultDashboardCards.get("Scheduled visits"), visitDetailsSection, 1.0);
DashboardSection visitDetailsSection = createDashboardSection(organisation, DefaultDashboardConstants.VISIT_DETAILS_SECTION, 1.0);
DashboardSectionCardMapping scheduledVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(DefaultDashboardConstants.SCHEDULED_VISITS_CARD), visitDetailsSection, 1.0);
visitDetailsSection.addDashboardSectionCardMapping(scheduledVisitsToVisitDetailsMapping);
DashboardSectionCardMapping overdueVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, "4dff9285-88b3-43de-a90b-9823ab32e433", defaultDashboardCards.get("Overdue visits"), visitDetailsSection, 2.0);
DashboardSectionCardMapping overdueVisitsToVisitDetailsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(DefaultDashboardConstants.OVERDUE_VISITS_CARD), visitDetailsSection, 2.0);
visitDetailsSection.addDashboardSectionCardMapping(overdueVisitsToVisitDetailsMapping);
defaultDashboard.addSection(visitDetailsSection);

DashboardSection recentStatisticsSection = createDashboardSection(organisation, "Recent Statistics", "fb302038-25a1-4cd6-9f56-80ef67b21103", 2.0);
DashboardSectionCardMapping recentRegistrationsToStatisticsMapping = createDashboardSectionCardMapping(organisation, "8afecd6c-741c-4871-86f1-bce171f8bfd8", defaultDashboardCards.get("Recent registrations"), recentStatisticsSection, 1.0);
DashboardSection recentStatisticsSection = createDashboardSection(organisation, DefaultDashboardConstants.RECENT_STATISTICS_SECTION, 2.0);
DashboardSectionCardMapping recentRegistrationsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(DefaultDashboardConstants.RECENT_REGISTRATIONS_CARD), recentStatisticsSection, 1.0);
recentStatisticsSection.addDashboardSectionCardMapping(recentRegistrationsToStatisticsMapping);
DashboardSectionCardMapping recentEnrolmentsToStatisticsMapping = createDashboardSectionCardMapping(organisation, "383b8df8-93d8-43d9-bc96-545e1176fe63", defaultDashboardCards.get("Recent enrolments"), recentStatisticsSection, 2.0);
DashboardSectionCardMapping recentEnrolmentsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(DefaultDashboardConstants.RECENT_ENROLMENTS_CARD), recentStatisticsSection, 2.0);
recentStatisticsSection.addDashboardSectionCardMapping(recentEnrolmentsToStatisticsMapping);
DashboardSectionCardMapping recentVisitsToStatisticsMapping = createDashboardSectionCardMapping(organisation, "9fb198b6-ae10-4c3f-a8e6-652b7d1b7e9c", defaultDashboardCards.get("Recent visits"), recentStatisticsSection, 3.0);
DashboardSectionCardMapping recentVisitsToStatisticsMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(DefaultDashboardConstants.RECENT_VISITS_CARD), recentStatisticsSection, 3.0);
recentStatisticsSection.addDashboardSectionCardMapping(recentVisitsToStatisticsMapping);
defaultDashboard.addSection(recentStatisticsSection);

DashboardSection registrationOverviewSection = createDashboardSection(organisation, "Registration Overview", "2ce712c2-3fa3-4ca4-9703-95766ef512c2",3.0);
DashboardSectionCardMapping totalToRegistrationOverviewMapping = createDashboardSectionCardMapping(organisation, "e02a68ed-c02b-4cba-a5b5-6a5c71ab5eb8", defaultDashboardCards.get("Total"), registrationOverviewSection, 1.0);
DashboardSection registrationOverviewSection = createDashboardSection(organisation, DefaultDashboardConstants.REGISTRATION_OVERVIEW_SECTION,3.0);
DashboardSectionCardMapping totalToRegistrationOverviewMapping = createDashboardSectionCardMapping(organisation, defaultDashboardCards.get(DefaultDashboardConstants.TOTAL_CARD), registrationOverviewSection, 1.0);
registrationOverviewSection.addDashboardSectionCardMapping(totalToRegistrationOverviewMapping);
defaultDashboard.addSection(registrationOverviewSection);

DashboardFilter subjectTypeFilter = createDashboardFilter(organisation, "Subject Type", "20367018-a168-43ff-a28f-64cd46ad3e2c", new JsonObject()
DashboardFilter subjectTypeFilter = createDashboardFilter(organisation, DefaultDashboardConstants.SUBJECT_TYPE_FILTER, new JsonObject()
.with(DashboardFilter.DashboardFilterConfig.TypeFieldName, String.valueOf(DashboardFilter.FilterType.SubjectType)));
defaultDashboard.addUpdateFilter(subjectTypeFilter);

DashboardFilter asOnDateFilter = createDashboardFilter(organisation, "As On Date", "efea5b8d-d621-47d0-a02c-c9b1a667b680", new JsonObject()
DashboardFilter asOnDateFilter = createDashboardFilter(organisation, DefaultDashboardConstants.AS_ON_DATE_FILTER, new JsonObject()
.with(DashboardFilter.DashboardFilterConfig.TypeFieldName, String.valueOf(DashboardFilter.FilterType.AsOnDate)));
defaultDashboard.addUpdateFilter(asOnDateFilter);

Expand All @@ -255,35 +256,35 @@ private OrganisationAwareEntity setDefaults(OrganisationAwareEntity entity, Orga
return entity;
}

private Dashboard createDashboard(Organisation organisation, String name, String uuid) {
private Dashboard createDashboard(Organisation organisation, String name) {
Dashboard dashboard = new Dashboard();
setDefaults(dashboard, organisation, uuid);
setDefaults(dashboard, organisation, DefaultDashboardConstants.DASHBOARD_NAME_UUID_MAPPING.get(name));
dashboard.setName(name);
return dashboard;
}

private DashboardSection createDashboardSection(Organisation organisation, String name, String uuid, Double displayOrder) {
private DashboardSection createDashboardSection(Organisation organisation, String name, Double displayOrder) {
DashboardSection dashboardSection = new DashboardSection();
setDefaults(dashboardSection, organisation, uuid);
setDefaults(dashboardSection, organisation, DefaultDashboardConstants.SECTION_NAME_UUID_MAPPING.get(name));
dashboardSection.setName(name);
dashboardSection.setDescription("");
dashboardSection.setViewType(DashboardSection.ViewType.Tile);
dashboardSection.setDisplayOrder(displayOrder);
return dashboardSection;
}

private DashboardSectionCardMapping createDashboardSectionCardMapping(Organisation organisation, String uuid, ReportCard reportCard, DashboardSection dashboardSection, Double displayOrder) {
private DashboardSectionCardMapping createDashboardSectionCardMapping(Organisation organisation, ReportCard reportCard, DashboardSection dashboardSection, Double displayOrder) {
DashboardSectionCardMapping dashboardSectionCardMapping = new DashboardSectionCardMapping();
setDefaults(dashboardSectionCardMapping, organisation, uuid);
setDefaults(dashboardSectionCardMapping, organisation, DefaultDashboardConstants.SECTION_CARD_MAPPING.get(dashboardSection.getName().concat(reportCard.getName())));
dashboardSectionCardMapping.setCard(reportCard);
dashboardSectionCardMapping.setDashboardSection(dashboardSection);
dashboardSectionCardMapping.setDisplayOrder(displayOrder);
return dashboardSectionCardMapping;
}

private DashboardFilter createDashboardFilter(Organisation organisation, String name, String uuid, JsonObject filterConfig) {
private DashboardFilter createDashboardFilter(Organisation organisation, String name, JsonObject filterConfig) {
DashboardFilter dashboardFilter = new DashboardFilter();
setDefaults(dashboardFilter, organisation, uuid);
setDefaults(dashboardFilter, organisation, DefaultDashboardConstants.FILTER_NAME_UUID_MAPPING.get(name));
dashboardFilter.setName(name);
dashboardFilter.setFilterConfig(filterConfig);
return dashboardFilter;
Expand Down

0 comments on commit c0dba66

Please sign in to comment.