diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java b/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java index c652337ba2..1f49dc085e 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/config/Configuration.java @@ -41,6 +41,9 @@ public class Configuration { @Value("${egov.plan.search.endpoint}") private String planSearchEndPoint; + @Value("${egov.plan.facility.search.endpoint}") + private String planFacilitySearchEndPoint; + // Filestore @Value("${egov.filestore.service.host}") diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java b/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java index f13f37ceca..1dcb9bd1ae 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java @@ -54,6 +54,9 @@ public class ServiceConstants { public static final String NO_PLAN_FOUND_FOR_GIVEN_DETAILS_CODE = "NO_PLAN_FOUND_FOR_GIVEN_DETAILS"; public static final String NO_PLAN_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan records do not exists for the given details: "; + public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE = "NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS"; + public static final String NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE = "Plan facilities do not exists for the given details: "; + public static final String BOUNDARY_CODE = "HCM_ADMIN_CONSOLE_BOUNDARY_CODE"; public static final String TOTAL_POPULATION = "HCM_ADMIN_CONSOLE_TOTAL_POPULATION"; @@ -91,7 +94,8 @@ public class ServiceConstants { public static final String NAME = "name"; public static final String ERROR_WHILE_UPDATING_PLAN_CONFIG = "Exception occurred while updating plan configuration."; - public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while search plans."; + public static final String ERROR_WHILE_SEARCHING_PLAN = "Exception occurred while searching plans."; + public static final String ERROR_WHILE_SEARCHING_PLAN_FACILITY = "Exception occurred while searching plan facility."; public static final String VALIDATE_STRING_REGX = "^(?!\\d+$).+$"; public static final String VALIDATE_NUMBER_REGX = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; @@ -126,6 +130,7 @@ public class ServiceConstants { public static final String MICROPLAN_ID_KEY = "microplanId"; public static final String FACILITY_NAME = "facilityName"; public static final String HCM_MICROPLAN_SERVING_FACILITY = "HCM_MICROPLAN_SERVING_FACILITY"; + public static final String FIXED_POST = "fixedPost"; //Census additional field constants public static final String UPLOADED_KEY = "UPLOADED_"; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java b/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java index 26f7735067..018a2652b4 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java @@ -18,9 +18,14 @@ import org.egov.processor.web.models.campaignManager.Boundary; import org.egov.processor.web.models.campaignManager.CampaignResources; import org.egov.processor.web.models.campaignManager.CampaignResponse; +import org.egov.processor.web.models.planFacility.PlanFacility; +import org.egov.processor.web.models.planFacility.PlanFacilityResponse; +import org.egov.processor.web.models.planFacility.PlanFacilitySearchCriteria; +import org.egov.processor.web.models.planFacility.PlanFacilitySearchRequest; import org.egov.tracer.model.CustomException; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.io.File; import java.io.FileNotFoundException; @@ -30,6 +35,8 @@ import java.util.*; import java.util.stream.Collectors; +import static org.egov.processor.config.ServiceConstants.*; + @Slf4j @Service public class ExcelParser implements FileParser { @@ -62,9 +69,11 @@ public class ExcelParser implements FileParser { private OutputEstimationGenerationUtil outputEstimationGenerationUtil; + private PlanFacilityUtil planFacilityUtil; + public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, FilestoreUtil filestoreUtil, CalculationUtil calculationUtil, PlanUtil planUtil, CampaignIntegrationUtil campaignIntegrationUtil, - Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil) { + Configuration config, MdmsUtil mdmsUtil, BoundaryUtil boundaryUtil, LocaleUtil localeUtil, CensusUtil censusUtil, EnrichmentUtil enrichmentUtil, PlanConfigurationUtil planConfigurationUtil, OutputEstimationGenerationUtil outputEstimationGenerationUtil, PlanFacilityUtil planFacilityUtil) { this.objectMapper = objectMapper; this.parsingUtil = parsingUtil; this.filestoreUtil = filestoreUtil; @@ -79,6 +88,7 @@ public ExcelParser(ObjectMapper objectMapper, ParsingUtil parsingUtil, Filestore this.enrichmentUtil = enrichmentUtil; this.planConfigurationUtil = planConfigurationUtil; this.outputEstimationGenerationUtil = outputEstimationGenerationUtil; + this.planFacilityUtil = planFacilityUtil; } /** @@ -230,12 +240,62 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigUpdatePlanEstimatesIntoOutputFileStatus())) { + + // Create a Map of Boundary Code to Facility's fixed post detail. + Map boundaryCodeToFixedPostMap = fetchFixedPostDetails(request, excelWorkbook, fileStoreId); + enrichmentUtil.enrichsheetWithApprovedPlanEstimates(excelWorkbookSheet, request, fileStoreId, mappedValues); } } }); } + /** + * This method makes plan facility search call and creates a map of boundary code to it's fixed post facility details. + * + * @param request the plan configuration request. + * @param excelWorkbook the Excel workbook to be processed. + * @param fileStoreId the fileStore id of the file. + * @return returns a map of boundary code to it's fixed post facility details. + */ + private Map fetchFixedPostDetails(PlanConfigurationRequest request, Workbook excelWorkbook, String fileStoreId) { + PlanConfiguration planConfiguration = request.getPlanConfiguration(); + + // Create the map of boundary code to the facility assigned to that boundary. + Map boundaryCodeToFacilityNameMap = outputEstimationGenerationUtil.getBoundaryCodeToFacilityMap(excelWorkbook, request, fileStoreId); + + //Create plan facility search request + PlanFacilitySearchRequest searchRequest = PlanFacilitySearchRequest.builder() + .requestInfo(request.getRequestInfo()) + .planFacilitySearchCriteria(PlanFacilitySearchCriteria.builder() + .tenantId(planConfiguration.getTenantId()) + .planConfigurationId(planConfiguration.getId()) + .build()) + .build(); + + PlanFacilityResponse planFacilityResponse = planFacilityUtil.search(searchRequest); + + if (CollectionUtils.isEmpty(planFacilityResponse.getPlanFacility())) { + throw new CustomException(NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_CODE, NO_PLAN_FACILITY_FOUND_FOR_GIVEN_DETAILS_MESSAGE); + } + + // Create a Boundary Code to Facility's fixed post detail map. + Map boundaryCodeToFixedPostMap = new HashMap<>(); + + for (PlanFacility planFacility : planFacilityResponse.getPlanFacility()) { + // Find the boundary code corresponding to the facility name. + String boundaryCode = findByValue(boundaryCodeToFacilityNameMap, planFacility.getFacilityName()); + + // Extract the 'FIXED_POST' field from additional details. + String fixedPostValue = (String) parsingUtil.extractFieldsFromJsonObject(planFacility.getAdditionalDetails(), FIXED_POST); + + // Populate the map. + boundaryCodeToFixedPostMap.put(boundaryCode, fixedPostValue); + } + + return boundaryCodeToFixedPostMap; + } + /** * Processes rows of data in an Excel sheet, performs calculations, updates * campaign boundaries, and creates plans. diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java index 624d272888..cec7afccb0 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java @@ -137,7 +137,7 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ LinkedHashMap::new )); - // Get the map of boundary code to the facility assigned to that boundary. + // Create the map of boundary code to the facility assigned to that boundary. Map boundaryCodeToFacility = getBoundaryCodeToFacilityMap(workbook, request, fileStoreId); // Iterate through all sheets in the workbook. @@ -160,7 +160,7 @@ public void addAssignedFacility(Workbook workbook, PlanConfigurationRequest requ * @param fileStoreId the associated file store ID for filtering. * @return a map of boundary codes to their assigned facility names. */ - private Map getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { + public Map getBoundaryCodeToFacilityMap(Workbook workbook, PlanConfigurationRequest request, String fileStoreId) { List boundaryCodes = new ArrayList<>(); // Iterate through all sheets in the workbook. diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java new file mode 100644 index 0000000000..cd8bb70288 --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanFacilityUtil.java @@ -0,0 +1,57 @@ +package org.egov.processor.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.egov.processor.config.Configuration; +import org.egov.processor.config.ServiceConstants; +import org.egov.processor.repository.ServiceRequestRepository; +import org.egov.processor.web.models.planFacility.PlanFacilityResponse; +import org.egov.processor.web.models.planFacility.PlanFacilitySearchRequest; +import org.egov.tracer.model.CustomException; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import static org.egov.processor.config.ServiceConstants.*; + +@Slf4j +@Component +public class PlanFacilityUtil { + private Configuration config; + + private ServiceRequestRepository serviceRequestRepository; + + private ObjectMapper mapper; + + public PlanFacilityUtil(Configuration config, ServiceRequestRepository serviceRequestRepository, ObjectMapper mapper) { + this.config = config; + this.serviceRequestRepository = serviceRequestRepository; + this.mapper = mapper; + } + + /** + * Searches for plan facilities based on the provided search request. + * + * @param planfacilitySearchRequest The search request containing the search criteria. + * @return A response with a list of plan facilities that matches the search criteria. + */ + public PlanFacilityResponse search(PlanFacilitySearchRequest planfacilitySearchRequest) { + + PlanFacilityResponse planFacilityResponse = null; + try { + Object response = serviceRequestRepository.fetchResult(getPlanFacilitySearchUri(), planfacilitySearchRequest); + planFacilityResponse = mapper.convertValue(response, PlanFacilityResponse.class); + } catch (Exception e) { + log.error(ServiceConstants.ERROR_WHILE_SEARCHING_PLAN_FACILITY); + } + + return planFacilityResponse; + } + + /** + * Creates a search uri for plan facility search. + * @return + */ + private StringBuilder getPlanFacilitySearchUri() { + return new StringBuilder().append(config.getPlanConfigHost()).append(config.getPlanFacilitySearchEndPoint()); + } +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java new file mode 100644 index 0000000000..e9471ac84a --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacility.java @@ -0,0 +1,92 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.models.AuditDetails; +import org.springframework.validation.annotation.Validated; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Plan Facility + */ +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacility { + + @JsonProperty("id") + private String id = null; + + @JsonProperty("tenantId") + @NotNull + @Size(min = 2, max = 64) + private String tenantId = null; + + @JsonProperty("planConfigurationId") + @NotNull + @Size(max = 64) + private String planConfigurationId = null; + + @JsonProperty("planConfigurationName") + private String planConfigurationName = null; + + @JsonProperty("boundaryAncestralPath") + private String boundaryAncestralPath = null; + + @JsonProperty("facilityId") + @NotNull + @Size(max = 64) + private String facilityId = null; + + @JsonProperty("facilityName") + private String facilityName = null; + + @JsonProperty("residingBoundary") + @NotNull + @Size(min = 1, max = 64) + private String residingBoundary = null; + + @JsonProperty("serviceBoundaries") + @NotNull + @Valid + private List serviceBoundaries; + + @JsonIgnore + private List initiallySetServiceBoundaries; + + @JsonProperty("jurisdictionMapping") + private Map jurisdictionMapping; + + @JsonProperty("additionalDetails") + private Object additionalDetails = null; + + @JsonProperty("active") + @NotNull + private Boolean active = null; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails = null; + + public PlanFacility addServiceBoundariesItem(String serviceBoundariesItem) { + if (this.serviceBoundaries == null) { + this.serviceBoundaries = new ArrayList<>(); + } + this.serviceBoundaries.add(serviceBoundariesItem); + return this; + } + + + +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java new file mode 100644 index 0000000000..4b39c308b6 --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilityResponse.java @@ -0,0 +1,33 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.response.ResponseInfo; +import org.springframework.validation.annotation.Validated; +import java.util.List; + +/** + * PlanFacilityResponse + */ +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacilityResponse { + + @JsonProperty("ResponseInfo") + private ResponseInfo responseInfo = null; + + @JsonProperty("PlanFacility") + @Valid + private List planFacility = null; + + @JsonProperty("TotalCount") + @Valid + private Integer totalCount = null; +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java new file mode 100644 index 0000000000..e36e30f97e --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchCriteria.java @@ -0,0 +1,64 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.validation.annotation.Validated; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacilitySearchCriteria { + + @JsonProperty("ids") + private Set ids = null; + + @JsonProperty("tenantId") + @NotNull + private String tenantId = null; + + @JsonProperty("planConfigurationId") + @NotNull + private String planConfigurationId = null; + + @JsonProperty("planConfigurationName") + private String planConfigurationName = null; + + @JsonProperty("facilityName") + private String facilityName = null; + + @JsonProperty("facilityStatus") + private String facilityStatus = null; + + @JsonProperty("facilityType") + private String facilityType = null; + + @JsonProperty("residingBoundaries") + private List residingBoundaries = null; + + @JsonProperty("jurisdiction") + private List jurisdiction = null; + + @JsonProperty("facilityId") + private String facilityId = null; + + @JsonProperty("offset") + private Integer offset = null; + + @JsonProperty("limit") + private Integer limit = null; + + @JsonIgnore + private Map filtersMap = null; + +} diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java new file mode 100644 index 0000000000..91fd4fa17c --- /dev/null +++ b/health-services/resource-generator/src/main/java/org/egov/processor/web/models/planFacility/PlanFacilitySearchRequest.java @@ -0,0 +1,34 @@ +package org.egov.processor.web.models.planFacility; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +import javax.validation.constraints.NotNull; + +/** + * PlanFacilitySearchRequest + */ +@Validated +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PlanFacilitySearchRequest { + + @JsonProperty("RequestInfo") + @NotNull + @Valid + private RequestInfo requestInfo = null; + + @JsonProperty("PlanFacilitySearchCriteria") + @NotNull + @Valid + private PlanFacilitySearchCriteria planFacilitySearchCriteria = null; + +} diff --git a/health-services/resource-generator/src/main/resources/application.properties b/health-services/resource-generator/src/main/resources/application.properties index 45e36a74e5..ce74288a82 100644 --- a/health-services/resource-generator/src/main/resources/application.properties +++ b/health-services/resource-generator/src/main/resources/application.properties @@ -49,11 +49,6 @@ egov.mdms.host=https://unified-dev.digit.org egov.mdms.search.endpoint=/egov-mdms-service/v1/_search egov.mdms.search.v2.endpoint=/mdms-v2/v2/_search -#plan config -egov.plan.config.host=https://unified-dev.digit.org -#egov.plan.config.host=http://localhost:8080 -egov.plan.config.endpoint=/plan-service/config/_search - #file store #egov.filestore.host=https://unified-dev.digit.org egov.filestore.service.host=http://localhost:8084 @@ -64,10 +59,17 @@ egov.filestore.upload.endpoint=/filestore/v1/files plan.config.consumer.kafka.save.topic=plan-config-create-topic plan.config.consumer.kafka.update.topic=plan-config-update-topic -#Plan Create +#Plan Config +egov.plan.config.host=https://unified-dev.digit.org +egov.plan.config.endpoint=/plan-service/config/_search + +#Plan egov.plan.create.endpoint=/plan-service/plan/_create egov.plan.search.endpoint=/plan-service/plan/_search +#Plan Facility +egov.plan.facility.search.endpoint=/plan-service/plan/facility/_search + #Campaign Manager egov.project.factory.search.endpoint=/project-factory/v1/project-type/search egov.project.factory.update.endpoint=/project-factory/v1/project-type/update