diff --git a/core-services/service-request/src/main/java/org/egov/servicerequest/web/models/AttributeDefinition.java b/core-services/service-request/src/main/java/org/egov/servicerequest/web/models/AttributeDefinition.java index 62616b6b67..649421350a 100644 --- a/core-services/service-request/src/main/java/org/egov/servicerequest/web/models/AttributeDefinition.java +++ b/core-services/service-request/src/main/java/org/egov/servicerequest/web/models/AttributeDefinition.java @@ -62,9 +62,7 @@ public enum DataTypeEnum { MULTIVALUELIST("MultiValueList"), - FILE("File"), - - BOOLEAN("Boolean"); + FILE("File"); private String value; diff --git a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java index 99e4b9487d..90cdb199bf 100644 --- a/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java +++ b/health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java @@ -189,6 +189,7 @@ private PlanRequestDTO convertToPlanReqDTO(PlanRequest planRequest) { .assignee(assignee) .additionalDetails(plan.getAdditionalDetails()) .jurisdictionMapping(plan.getJurisdictionMapping()) + .additionalFields(plan.getAdditionalFields()) .activities(plan.getActivities()) .resources(plan.getResources()) .targets(plan.getTargets()) diff --git a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java index 4ae958aa9d..27c53bb9cc 100644 --- a/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java +++ b/health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java @@ -30,12 +30,14 @@ public PlanQueryBuilder(Configuration config, QueryUtil queryUtil) { "\t plan_activity.id as plan_activity_id, plan_activity.code as plan_activity_code, plan_activity.description as plan_activity_description, plan_activity.planned_start_date as plan_activity_planned_start_date, plan_activity.planned_end_date as plan_activity_planned_end_date, plan_activity.dependencies as plan_activity_dependencies, plan_activity.plan_id as plan_activity_plan_id, plan_activity.created_by as plan_activity_created_by, plan_activity.created_time as plan_activity_created_time, plan_activity.last_modified_by as plan_activity_last_modified_by, plan_activity.last_modified_time as plan_activity_last_modified_time,\n" + "\t plan_activity_condition.id as plan_activity_condition_id, plan_activity_condition.entity as plan_activity_condition_entity, plan_activity_condition.entity_property as plan_activity_condition_entity_property, plan_activity_condition.expression as plan_activity_condition_expression, plan_activity_condition.activity_id as plan_activity_condition_activity_id, plan_activity_condition.is_active as plan_activity_condition_is_active, plan_activity_condition.created_by as plan_activity_condition_created_by, plan_activity_condition.created_time as plan_activity_condition_created_time, plan_activity_condition.last_modified_by as plan_activity_condition_last_modified_by, plan_activity_condition.last_modified_time as plan_activity_condition_last_modified_time,\n" + "\t plan_resource.id as plan_resource_id, plan_resource.resource_type as plan_resource_resource_type, plan_resource.estimated_number as plan_resource_estimated_number, plan_resource.plan_id as plan_resource_plan_id, plan_resource.activity_code as plan_resource_activity_code, plan_resource.created_by as plan_resource_created_by, plan_resource.created_time as plan_resource_created_time, plan_resource.last_modified_by as plan_resource_last_modified_by, plan_resource.last_modified_time as plan_resource_last_modified_time,\n" + - "\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time\n" + + "\t plan_target.id as plan_target_id, plan_target.metric as plan_target_metric, plan_target.metric_value as plan_target_metric_value, plan_target.metric_comparator as plan_target_metric_comparator, plan_target.metric_unit as plan_target_metric_unit, plan_target.plan_id as plan_target_plan_id, plan_target.activity_code as plan_target_activity_code, plan_target.created_by as plan_target_created_by, plan_target.created_time as plan_target_created_time, plan_target.last_modified_by as plan_target_last_modified_by, plan_target.last_modified_time as plan_target_last_modified_time, \n" + + "\t paf.id as plan_additional_field_id, paf.plan_id as plan_additional_field_plan_id, paf.key as plan_additional_field_key, paf.value as plan_additional_field_value, paf.show_on_ui as plan_additional_field_show_on_ui, paf.editable as plan_additional_field_editable, paf.order as plan_additional_field_order \n" + "\t FROM plan \n" + "\t LEFT JOIN plan_activity ON plan.id = plan_activity.plan_id\n" + "\t LEFT JOIN plan_activity_condition ON plan_activity.id = plan_activity_condition.activity_id\n" + "\t LEFT JOIN plan_resource ON plan.id = plan_resource.plan_id\n" + - "\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id"; + "\t LEFT JOIN plan_target ON plan.id = plan_target.plan_id\n" + + "\t LEFT JOIN plan_additional_field paf ON plan.id = paf.plan_id"; private static final String BULK_PLAN_UPDATE_QUERY = "UPDATE plan SET status = ?, assignee = ?, last_modified_by = ?, last_modified_time = ? WHERE id = ?"; diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java index aa00207a74..b37561fbc3 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java @@ -30,6 +30,7 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep Set conditionSet = new HashSet<>(); Set resourceSet = new HashSet<>(); Set targetSet = new HashSet<>(); + Set additionalFieldSet = new HashSet<>(); // Traverse through result set and create plan objects while (rs.next()) { @@ -43,6 +44,7 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep conditionSet.clear(); resourceSet.clear(); targetSet.clear(); + additionalFieldSet.clear(); // Prepare audit details AuditDetails auditDetails = AuditDetails.builder() @@ -72,6 +74,7 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExcep addActivities(rs, planEntry, activityMap, conditionSet); addResources(rs, planEntry, resourceSet); addTargets(rs, planEntry, targetSet); + addAdditionalField(rs, planEntry, additionalFieldSet); planMap.put(planId, planEntry); } @@ -234,4 +237,39 @@ private void addTargets(ResultSet rs, Plan planEntry, Set targetSet) thr targetSet.add(target.getId()); } + + /** + * Adds a AdditionalField object to the plan entry based on the result set. + * + * @param rs The ResultSet containing the data. + * @param additionalFieldSet A set to keep track of added AdditionalField objects. + * @param planEntry The Plan entry to which the AdditionalField object will be added. + * @throws SQLException If an SQL error occurs. + */ + private void addAdditionalField(ResultSet rs, Plan planEntry, Set additionalFieldSet) throws SQLException { + String additionalFieldId = rs.getString("plan_additional_field_id"); + + if (ObjectUtils.isEmpty(additionalFieldId) || additionalFieldSet.contains(additionalFieldId)) { + return; + } + + AdditionalField additionalField = new AdditionalField(); + additionalField.setId(rs.getString("plan_additional_field_id")); + additionalField.setKey(rs.getString("plan_additional_field_key")); + additionalField.setValue(rs.getBigDecimal("plan_additional_field_value")); + additionalField.setShowOnUi(rs.getBoolean("plan_additional_field_show_on_ui")); + additionalField.setEditable(rs.getBoolean("plan_additional_field_editable")); + additionalField.setOrder(rs.getInt("plan_additional_field_order")); + + if (CollectionUtils.isEmpty(planEntry.getAdditionalFields())) { + List additionalFields = new ArrayList<>(); + additionalFields.add(additionalField); + planEntry.setAdditionalFields(additionalFields); + } else { + planEntry.getAdditionalFields().add(additionalField); + } + + additionalFieldSet.add(additionalFieldId); + } + } diff --git a/health-services/plan-service/src/main/java/digit/service/PlanService.java b/health-services/plan-service/src/main/java/digit/service/PlanService.java index 4acaf58218..dad7e8b7d8 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanService.java +++ b/health-services/plan-service/src/main/java/digit/service/PlanService.java @@ -1,13 +1,13 @@ package digit.service; import digit.repository.PlanRepository; +import digit.service.enrichment.PlanEnricher; +import digit.service.validator.PlanValidator; import digit.service.workflow.WorkflowService; import digit.web.models.*; -import org.egov.common.contract.response.ResponseInfo; import org.egov.common.utils.ResponseInfoUtil; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; diff --git a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java similarity index 95% rename from health-services/plan-service/src/main/java/digit/service/PlanEnricher.java rename to health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java index 9ed16aa593..2670c13574 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java @@ -1,4 +1,4 @@ -package digit.service; +package digit.service.enrichment; import digit.web.models.*; import digit.web.models.boundary.BoundaryTypeHierarchy; @@ -54,6 +54,10 @@ public void enrichPlanCreate(PlanRequest body) { // Generate id for targets body.getPlan().getTargets().forEach(target -> UUIDEnrichmentUtil.enrichRandomUuid(target, "id")); + // Generate id for additional fields + if(!CollectionUtils.isEmpty(body.getPlan().getAdditionalFields())) + body.getPlan().getAdditionalFields().forEach(additionalField -> UUIDEnrichmentUtil.enrichRandomUuid(additionalField, "id")); + // Enrich audit details body.getPlan().setAuditDetails(AuditDetailsEnrichmentUtil .prepareAuditDetails(body.getPlan().getAuditDetails(), body.getRequestInfo(), Boolean.TRUE)); @@ -108,6 +112,13 @@ public void enrichPlanUpdate(PlanRequest body) { } }); + // Generate uuid for new additionalFields + body.getPlan().getAdditionalFields().forEach(additionalFields -> { + if(ObjectUtils.isEmpty(additionalFields.getId())) { + UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id"); + } + }); + // Enriching last modified time for update body.getPlan().getAuditDetails().setLastModifiedTime(System.currentTimeMillis()); } diff --git a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java index a07530dbfd..fccb2de96d 100644 --- a/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java +++ b/health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java @@ -3,10 +3,7 @@ import digit.util.BoundaryUtil; import digit.util.CensusUtil; import digit.util.CommonUtil; -import digit.web.models.PlanFacility; -import digit.web.models.PlanFacilityRequest; -import digit.web.models.PlanFacilitySearchCriteria; -import digit.web.models.PlanFacilitySearchRequest; +import digit.web.models.*; import digit.web.models.boundary.BoundarySearchResponse; import digit.web.models.boundary.EnrichedBoundary; import digit.web.models.census.*; diff --git a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java b/health-services/plan-service/src/main/java/digit/service/validator/PlanValidator.java similarity index 99% rename from health-services/plan-service/src/main/java/digit/service/PlanValidator.java rename to health-services/plan-service/src/main/java/digit/service/validator/PlanValidator.java index aa1656c00b..1fd98c823b 100644 --- a/health-services/plan-service/src/main/java/digit/service/PlanValidator.java +++ b/health-services/plan-service/src/main/java/digit/service/validator/PlanValidator.java @@ -1,9 +1,11 @@ -package digit.service; +package digit.service.validator; import com.jayway.jsonpath.JsonPath; import digit.config.Configuration; import digit.repository.PlanConfigurationRepository; import digit.repository.PlanRepository; +import digit.service.PlanEmployeeService; +import digit.service.enrichment.PlanEnricher; import digit.util.BoundaryUtil; import digit.util.CampaignUtil; import digit.util.CommonUtil; diff --git a/health-services/plan-service/src/main/java/digit/web/models/census/AdditionalField.java b/health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java similarity index 96% rename from health-services/plan-service/src/main/java/digit/web/models/census/AdditionalField.java rename to health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java index 65ae422283..10351283cd 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/census/AdditionalField.java +++ b/health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java @@ -1,4 +1,4 @@ -package digit.web.models.census; +package digit.web.models; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.validation.Valid; diff --git a/health-services/plan-service/src/main/java/digit/web/models/Plan.java b/health-services/plan-service/src/main/java/digit/web/models/Plan.java index 3ff0e8ce87..f39dcfa676 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/Plan.java +++ b/health-services/plan-service/src/main/java/digit/web/models/Plan.java @@ -74,6 +74,10 @@ public class Plan { @JsonProperty("jurisdictionMapping") private Map jurisdictionMapping; + @JsonProperty("additionalFields") + @Valid + private List additionalFields = null; + @JsonIgnore private String boundaryAncestralPath = null; diff --git a/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java b/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java index f56569c134..d7adb85ece 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java +++ b/health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java @@ -59,6 +59,10 @@ public class PlanDTO { @JsonProperty("jurisdictionMapping") private Map jurisdictionMapping; + @JsonProperty("additionalFields") + @Valid + private List additionalFields = null; + @JsonProperty("activities") @Valid private List activities; diff --git a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java index e8f384d1e9..2b989edb10 100644 --- a/health-services/plan-service/src/main/java/digit/web/models/census/Census.java +++ b/health-services/plan-service/src/main/java/digit/web/models/census/Census.java @@ -8,6 +8,7 @@ import java.util.List; +import digit.web.models.AdditionalField; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; diff --git a/health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql b/health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql new file mode 100644 index 0000000000..764ee79bb2 --- /dev/null +++ b/health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql @@ -0,0 +1,12 @@ +-- Table: plan_additional_field +CREATE TABLE plan_additional_field ( + id character varying(64) NOT NULL, + plan_id character varying(64) NOT NULL, + "key" character varying(64) NOT NULL, + "value" numeric(12,2) NOT NULL, + show_on_ui boolean DEFAULT true NOT NULL, + editable boolean DEFAULT true NOT NULL, + "order" bigint NOT NULL, + CONSTRAINT uk_plan_additional_field_id PRIMARY KEY (id), + FOREIGN KEY (plan_id) REFERENCES plan(id) +); diff --git a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/MasterDataService.java b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/MasterDataService.java index 7afa7bc092..c812f7c502 100644 --- a/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/MasterDataService.java +++ b/health-services/referralmanagement/src/main/java/org/egov/referralmanagement/service/MasterDataService.java @@ -13,10 +13,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import digit.models.coremodels.mdms.MasterDetail; -import digit.models.coremodels.mdms.MdmsCriteria; -import digit.models.coremodels.mdms.MdmsCriteriaReq; -import digit.models.coremodels.mdms.ModuleDetail; import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.request.RequestInfo; import org.egov.common.http.client.ServiceRequestClient; 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 6f5f9c5a69..09013ace23 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 @@ -77,6 +77,8 @@ public class ServiceConstants { public static final String BOUNDARY = "boundary"; public static final String DOT_SEPARATOR = "."; public static final String MICROPLAN_PREFIX = "MP-"; + public static final String ACCESSIBILITY_DETAILS = "accessibilityDetails"; + public static final String SECURITY_DETAILS = "securityDetails"; //MDMS field Constants public static final String DATA = "data"; 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 e711a31c82..7648edc22b 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 @@ -215,11 +215,11 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, excelWorkbook.forEach(excelWorkbookSheet -> { if (isSheetAllowedToProcess(request, excelWorkbookSheet.getSheetName(), localeResponse)) { if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerPlanEstimatesStatus())) { - Map BCodeToFacilityDetails = new HashMap<>(); + Map BCodeToCensusAdditionalDetails = new HashMap<>(); - enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToFacilityDetails); + enrichmentUtil.enrichsheetWithApprovedCensusRecords(excelWorkbookSheet, request, fileStoreId, mappedValues, BCodeToCensusAdditionalDetails); processRows(request, excelWorkbookSheet, dataFormatter, fileStoreId, - campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); + campaignBoundaryList, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToCensusAdditionalDetails); } else if (request.getPlanConfiguration().getStatus().equals(config.getPlanConfigTriggerCensusRecordsStatus())) { processRowsForCensusRecords(request, excelWorkbookSheet, fileStoreId, attributeNameVsDataTypeMap, boundaryCodeList, campaign.getCampaign().get(0).getHierarchyType()); @@ -248,9 +248,9 @@ private void processSheets(PlanConfigurationRequest request, String fileStoreId, * @param boundaryCodeList List of boundary codes. * @throws IOException If an I/O error occurs. */ - private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { + private void processRows(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToCensusAdditionalDetails) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); - performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToFacilityDetails); + performRowLevelCalculations(planConfigurationRequest, sheet, dataFormatter, fileStoreId, campaignBoundaryList, planConfig, attributeNameVsDataTypeMap, boundaryCodeList, BCodeToCensusAdditionalDetails); } private void processRowsForCensusRecords(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, String fileStoreId, Map attributeNameVsDataTypeMap, List boundaryCodeList, String hierarchyType) { @@ -341,7 +341,7 @@ private Map prepareAttributeVsIndexMap(PlanConfigurationRequest */ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurationRequest, Sheet sheet, DataFormatter dataFormatter, String fileStoreId, List campaignBoundaryList, - PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToFacilityDetails) { + PlanConfiguration planConfig, Map attributeNameVsDataTypeMap, List boundaryCodeList, Map BCodeToCensusAdditionalDetails) { Row firstRow = null; Map mappedValues = planConfig.getResourceMapping().stream() .filter(f -> f.getFilestoreId().equals(fileStoreId)) @@ -371,8 +371,7 @@ private void performRowLevelCalculations(PlanConfigurationRequest planConfigurat if (config.isIntegrateWithAdminConsole()) campaignIntegrationUtil.updateCampaignBoundary(planConfig, feature, assumptionValueMap, mappedValues, mapOfColumnNameAndIndex, campaignBoundaryList, resultMap); - planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToFacilityDetails)); - + planUtil.create(planConfigurationRequest, feature, resultMap, mappedValues, Optional.of(BCodeToCensusAdditionalDetails)); } } diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java index 49f85c1f5f..09e68b5cc0 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java @@ -89,7 +89,7 @@ public void enrichResourceMapping(PlanConfigurationRequest request, LocaleRespon } - public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues, Map BCodeToFacilityDetails) { + public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationRequest planConfigurationRequest, String fileStoreId, Map mappedValues, Map BCodeToCensusAdditionalDetails) { List boundaryCodes = getBoundaryCodesFromTheSheet(sheet, planConfigurationRequest, fileStoreId); Map mapOfColumnNameAndIndex = parsingUtil.getAttributeNameIndexFromExcel(sheet); @@ -144,9 +144,7 @@ public void enrichsheetWithApprovedCensusRecords(Sheet sheet, PlanConfigurationR } } - String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(census.getAdditionalDetails(), FACILITY_NAME); - if(facilityName != null && !facilityName.isEmpty()) - BCodeToFacilityDetails.put(boundaryCode, facilityName); + BCodeToCensusAdditionalDetails.put(boundaryCode, census.getAdditionalDetails()); } log.info("Successfully update file with approved census data."); diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java index cc33356b95..eaf7b673ac 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java @@ -442,6 +442,8 @@ public Object extractFieldsFromJsonObject(Object additionalDetails, String field return node.asBoolean(); } else if (node.isTextual()) { return node.asText(); + } else if (node.isObject()) { + return objectMapper.convertValue(node, Map.class); // Return the object node as a Map } } return null; diff --git a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java index cc990136e7..eb4e34cdcb 100644 --- a/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java +++ b/health-services/resource-generator/src/main/java/org/egov/processor/util/PlanUtil.java @@ -51,8 +51,8 @@ public PlanUtil(ServiceRequestRepository serviceRequestRepository, Configuration * @param mappedValues The mapped values. */ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Optional> BCodeToFacilityDetails) { - PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, BCodeToFacilityDetails.orElse(Collections.emptyMap())); + Map resultMap, Map mappedValues, Optional> BCodeToCensusAdditionalDetails) { + PlanRequest planRequest = buildPlanRequest(planConfigurationRequest, feature, resultMap, mappedValues, BCodeToCensusAdditionalDetails.orElse(Collections.emptyMap())); try { producer.push(config.getResourceMicroplanCreateTopic(), planRequest); } catch (Exception e) { @@ -71,7 +71,7 @@ public void create(PlanConfigurationRequest planConfigurationRequest, JsonNode f * @return The constructed PlanRequest object. */ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationRequest, JsonNode feature, - Map resultMap, Map mappedValues, Map BCodeToFacilityDetails) { + Map resultMap, Map mappedValues, Map BCodeToCensusAdditionalDetails) { PlanConfiguration planConfig = planConfigurationRequest.getPlanConfiguration(); String boundaryCodeValue = getBoundaryCodeValue(ServiceConstants.BOUNDARY_CODE, feature, mappedValues); @@ -93,23 +93,34 @@ private PlanRequest buildPlanRequest(PlanConfigurationRequest planConfigurationR .targets(new ArrayList()) .workflow(Workflow.builder().action(WORKFLOW_ACTION_INITIATE).build()) .isRequestFromResourceEstimationConsumer(true) - .additionalDetails(enrichAdditionalDetials(BCodeToFacilityDetails, boundaryCodeValue)) + .additionalDetails(enrichAdditionalDetials(BCodeToCensusAdditionalDetails, boundaryCodeValue)) .build()) .build(); } - private Object enrichAdditionalDetials(Map BCodeToFacilityDetails, String boundaryCodeValue) { - if(!CollectionUtils.isEmpty(BCodeToFacilityDetails)) { + private Object enrichAdditionalDetials(Map BCodeToCensusAdditionalDetails, String boundaryCodeValue) { + if(!CollectionUtils.isEmpty(BCodeToCensusAdditionalDetails)) { - // Iterate over each boundary and add facility details in plan additional details - String facilityName = BCodeToFacilityDetails.get(boundaryCodeValue); + Object censusAdditionalDetails = BCodeToCensusAdditionalDetails.get(boundaryCodeValue); - if(facilityName != null && !facilityName.isEmpty()) { - Map fieldsToBeUpdated = new HashMap<>(); + // Extract required details from census additional details object. + String facilityName = (String) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, FACILITY_NAME); + Object accessibilityDetails = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, ACCESSIBILITY_DETAILS); + Object securityDetials = (Object) parsingUtil.extractFieldsFromJsonObject(censusAdditionalDetails, SECURITY_DETAILS); + + // Creating a map of fields to be added in plan additional details with their key. + Map fieldsToBeUpdated = new HashMap<>(); + if(facilityName != null && !facilityName.isEmpty()) fieldsToBeUpdated.put(FACILITY_NAME, facilityName); + if(accessibilityDetails != null) + fieldsToBeUpdated.put(ACCESSIBILITY_DETAILS, accessibilityDetails); + + if(securityDetials != null) + fieldsToBeUpdated.put(SECURITY_DETAILS, securityDetials); + + if(!CollectionUtils.isEmpty(fieldsToBeUpdated)) return parsingUtil.updateFieldInAdditionalDetails(new Object(), fieldsToBeUpdated); - } } return null; }