Skip to content

Commit

Permalink
#749 | Convert DefaultDashboardConstants to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Aug 28, 2024
1 parent 4c1c056 commit 7317a2d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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>() {{
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");
Expand All @@ -21,21 +21,21 @@ public class DefaultDashboardConstants {
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>() {{
String DEFAULT_DASHBOARD = "Default Dashboard";
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>() {{
String VISIT_DETAILS_SECTION = "Visit Details";
String RECENT_STATISTICS_SECTION = "Recent Statistics";
String REGISTRATION_OVERVIEW_SECTION = "Registration Overview";
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>() {{
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");
Expand All @@ -44,15 +44,15 @@ public class DefaultDashboardConstants {
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>() {{
String SUBJECT_TYPE_FILTER = "Subject Type";
String AS_ON_DATE_FILTER = "As On Date";
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";
String WHITE_BG_COLOUR = "#ffffff";
String RED_BG_COLOUR = "#d32f2f";
String GREEN_BG_COLOUR = "#388e3c";

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.*;

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

public Map<String, ReportCard> createDefaultDashboardCards(Organisation organisation) {
Map<String, String> defaultDashboardCards = DefaultDashboardConstants.CARD_NAME_UUID_MAPPING;
Map<String, String> defaultDashboardCards = CARD_NAME_UUID_MAPPING;
List<StandardReportCardType> standardReportCardTypes = standardReportCardTypeRepository.findAllByNameIn(defaultDashboardCards.keySet());
Map<String, ReportCard> savedCards = new HashMap<>();
standardReportCardTypes.forEach(standardReportCardType -> {
Expand All @@ -198,18 +198,18 @@ public Map<String, ReportCard> createDefaultDashboardCards(Organisation organisa
reportCard.setStandardReportCardType(standardReportCardType);
reportCard.setOrganisationId(organisation.getId());
reportCard.setName(standardReportCardType.getName());
reportCard.setColour(DefaultDashboardConstants.WHITE_BG_COLOUR);
reportCard.setColour(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(DefaultDashboardConstants.OVERDUE_VISITS_CARD)) {
reportCard.setColour(DefaultDashboardConstants.RED_BG_COLOUR);
if (standardReportCardType.getName().equals(OVERDUE_VISITS_CARD)) {
reportCard.setColour(RED_BG_COLOUR);
}
if (standardReportCardType.getName().equals(DefaultDashboardConstants.SCHEDULED_VISITS_CARD)) {
reportCard.setColour(DefaultDashboardConstants.GREEN_BG_COLOUR);
if (standardReportCardType.getName().equals(SCHEDULED_VISITS_CARD)) {
reportCard.setColour(GREEN_BG_COLOUR);
}
savedCards.put(reportCard.getName(), cardRepository.save(reportCard));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Set;

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

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

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

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

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

DashboardFilter subjectTypeFilter = createDashboardFilter(organisation, DefaultDashboardConstants.SUBJECT_TYPE_FILTER, new JsonObject()
DashboardFilter subjectTypeFilter = createDashboardFilter(organisation, SUBJECT_TYPE_FILTER, new JsonObject()
.with(DashboardFilter.DashboardFilterConfig.TypeFieldName, String.valueOf(DashboardFilter.FilterType.SubjectType)));
defaultDashboard.addUpdateFilter(subjectTypeFilter);

DashboardFilter asOnDateFilter = createDashboardFilter(organisation, DefaultDashboardConstants.AS_ON_DATE_FILTER, new JsonObject()
DashboardFilter asOnDateFilter = createDashboardFilter(organisation, AS_ON_DATE_FILTER, new JsonObject()
.with(DashboardFilter.DashboardFilterConfig.TypeFieldName, String.valueOf(DashboardFilter.FilterType.AsOnDate)));
defaultDashboard.addUpdateFilter(asOnDateFilter);

Expand All @@ -258,14 +258,14 @@ private OrganisationAwareEntity setDefaults(OrganisationAwareEntity entity, Orga

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

private DashboardSection createDashboardSection(Organisation organisation, String name, Double displayOrder) {
DashboardSection dashboardSection = new DashboardSection();
setDefaults(dashboardSection, organisation, DefaultDashboardConstants.SECTION_NAME_UUID_MAPPING.get(name));
setDefaults(dashboardSection, organisation, SECTION_NAME_UUID_MAPPING.get(name));
dashboardSection.setName(name);
dashboardSection.setDescription("");
dashboardSection.setViewType(DashboardSection.ViewType.Tile);
Expand All @@ -275,7 +275,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, DefaultDashboardConstants.SECTION_CARD_MAPPING.get(dashboardSection.getName().concat(reportCard.getName())));
setDefaults(dashboardSectionCardMapping, organisation, SECTION_CARD_MAPPING.get(dashboardSection.getName().concat(reportCard.getName())));
dashboardSectionCardMapping.setCard(reportCard);
dashboardSectionCardMapping.setDashboardSection(dashboardSection);
dashboardSectionCardMapping.setDisplayOrder(displayOrder);
Expand All @@ -284,7 +284,7 @@ private DashboardSectionCardMapping createDashboardSectionCardMapping(Organisati

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

0 comments on commit 7317a2d

Please sign in to comment.