diff --git a/health-services/census-service/src/main/java/digit/repository/impl/CensusRepositoryImpl.java b/health-services/census-service/src/main/java/digit/repository/impl/CensusRepositoryImpl.java index c6dec4b4d1..105dbef742 100644 --- a/health-services/census-service/src/main/java/digit/repository/impl/CensusRepositoryImpl.java +++ b/health-services/census-service/src/main/java/digit/repository/impl/CensusRepositoryImpl.java @@ -72,7 +72,7 @@ public List search(CensusSearchCriteria censusSearchCriteria) { if(censusSearchCriteria.getAreaCodes() != null && censusSearchCriteria.getAreaCodes().isEmpty()) return new ArrayList<>(); - // Fetch census ids from database + // Fetch census ids from database based on the provided search criteria List censusIds = queryDatabaseForCensusIds(censusSearchCriteria); // Return empty list back as response if no census ids are found @@ -94,6 +94,12 @@ private List searchCensusByIds(List censusIds) { } + /** + * Based on the provided census search criteria, it fetches the corresponding census ids from the database. + * + * @param censusSearchCriteria census search criteria from the search request. + * @return returns a list of census ids. + */ private List queryDatabaseForCensusIds(CensusSearchCriteria censusSearchCriteria) { List preparedStmtList = new ArrayList<>(); String query = queryBuilder.getCensusSearchQuery(censusSearchCriteria, preparedStmtList); diff --git a/health-services/census-service/src/main/java/digit/repository/rowmapper/CensusRowMapper.java b/health-services/census-service/src/main/java/digit/repository/rowmapper/CensusRowMapper.java index 7edac5005d..8ebe978e4d 100644 --- a/health-services/census-service/src/main/java/digit/repository/rowmapper/CensusRowMapper.java +++ b/health-services/census-service/src/main/java/digit/repository/rowmapper/CensusRowMapper.java @@ -49,7 +49,12 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExc additionalFieldSet.clear(); // Prepare audit details - AuditDetails auditDetails = AuditDetails.builder().createdBy(rs.getString("census_created_by")).createdTime(rs.getLong("census_created_time")).lastModifiedBy(rs.getString("census_last_modified_by")).lastModifiedTime(rs.getLong("census_last_modified_time")).build(); + AuditDetails auditDetails = AuditDetails.builder() + .createdBy(rs.getString("census_created_by")) + .createdTime(rs.getLong("census_created_time")) + .lastModifiedBy(rs.getString("census_last_modified_by")) + .lastModifiedTime(rs.getLong("census_last_modified_time")) + .build(); String commaSeparatedAssignee = rs.getString("census_assignee"); List assignee = !ObjectUtils.isEmpty(commaSeparatedAssignee) ? Arrays.asList(commaSeparatedAssignee.split(",")) : null; @@ -91,10 +96,12 @@ public List extractData(ResultSet rs) throws SQLException, DataAccessExc private void addAdditionalField(ResultSet rs, Set additionalFieldSet, Census censusEntry) throws SQLException { String additionalFieldId = rs.getString("additional_field_id"); + // Skip processing if the additionalField Id is empty or already processed if (ObjectUtils.isEmpty(additionalFieldId) || additionalFieldSet.contains(additionalFieldId)) { return; } + // Create and populate the AdditionalField object AdditionalField additionalField = new AdditionalField(); additionalField.setId(rs.getString("additional_field_id")); additionalField.setKey(rs.getString("additional_field_key")); @@ -103,6 +110,7 @@ private void addAdditionalField(ResultSet rs, Set additionalFieldSet, Ce additionalField.setEditable(rs.getBoolean("additional_field_editable")); additionalField.setOrder(rs.getInt("additional_field_order")); + // Creates a new additionalField list if it is not already initialized in censusEntry and adds the additionalField object. if (CollectionUtils.isEmpty(censusEntry.getAdditionalFields())) { List additionalFields = new ArrayList<>(); additionalFields.add(additionalField); @@ -111,6 +119,7 @@ private void addAdditionalField(ResultSet rs, Set additionalFieldSet, Ce censusEntry.getAdditionalFields().add(additionalField); } + // Mark this additionalFieldId as processed additionalFieldSet.add(additionalFieldId); } @@ -126,15 +135,18 @@ private void addAdditionalField(ResultSet rs, Set additionalFieldSet, Ce private void addPopulationByDemographic(ResultSet rs, Set populationByDemographicSet, Census censusEntry) throws SQLException { String populationByDemographicId = rs.getString("population_by_demographics_id"); + // Skip processing if the populationByDemographic Id is empty or already processed if (ObjectUtils.isEmpty(populationByDemographicId) || populationByDemographicSet.contains(populationByDemographicId)) { return; } + // Create and populate the PopulationByDemographic object PopulationByDemographic populationByDemographic = new PopulationByDemographic(); populationByDemographic.setId(rs.getString("population_by_demographics_id")); populationByDemographic.setDemographicVariable(PopulationByDemographic.DemographicVariableEnum.fromValue(rs.getString("population_by_demographics_demographic_variable"))); populationByDemographic.setPopulationDistribution(queryUtil.parseJson((PGobject) rs.getObject("population_by_demographics_population_distribution"))); + // Creates a new populationByDemographic list if it is not already initialized in censusEntry and adds the populationByDemographic object. if (CollectionUtils.isEmpty(censusEntry.getPopulationByDemographics())) { List populationByDemographicList = new ArrayList<>(); populationByDemographicList.add(populationByDemographic); @@ -143,6 +155,7 @@ private void addPopulationByDemographic(ResultSet rs, Set populationByDe censusEntry.getPopulationByDemographics().add(populationByDemographic); } + // Mark this populationByDemographicId as processed populationByDemographicSet.add(populationByDemographicId); } } diff --git a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java index 4645ce10b5..b5a7d68b73 100644 --- a/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java +++ b/health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanConfigRowMapper.java @@ -78,16 +78,20 @@ public List extractData(ResultSet rs) throws SQLException, Da private void addFiles(ResultSet rs, PlanConfiguration planConfigEntry, Set fileSet) throws SQLException { String fileId = rs.getString("plan_configuration_files_id"); + // Skip processing if the fileId is empty or already processed if (ObjectUtils.isEmpty(fileId) || fileSet.contains(fileId)) { return; } + // Create and populate the File object File file = new File(); file.setId(fileId); file.setFilestoreId(rs.getString("plan_configuration_files_filestore_id")); file.setInputFileType(File.InputFileTypeEnum.valueOf(rs.getString("plan_configuration_files_input_file_type").toUpperCase())); file.setTemplateIdentifier(rs.getString("plan_configuration_files_template_identifier")); file.setActive(rs.getBoolean("plan_configuration_files_active")); + + // Creates a new file list if it is not already initialized in planConfigEntry and adds the file object. if (CollectionUtils.isEmpty(planConfigEntry.getFiles())) { List fileList = new ArrayList<>(); fileList.add(file); @@ -96,6 +100,7 @@ private void addFiles(ResultSet rs, PlanConfiguration planConfigEntry, Set assumptionSet) throws SQLException { String assumptionId = rs.getString("plan_configuration_assumptions_id"); + // Skip processing if the assumptionId is empty or already processed if (ObjectUtils.isEmpty(assumptionId) || assumptionSet.contains(assumptionId)) { return; } + // Create and populate the Assumption object Assumption assumption = new Assumption(); assumption.setId(assumptionId); assumption.setKey(rs.getString("plan_configuration_assumptions_key")); @@ -123,6 +130,7 @@ private void addAssumptions(ResultSet rs, PlanConfiguration planConfigEntry, Set assumption.setSource(Source.valueOf(rs.getString("plan_configuration_assumptions_source"))); assumption.setCategory(rs.getString("plan_configuration_assumptions_category")); + // Creates a new assumption list if it is not already initialized in planConfigEntry and adds the assumption object. if (CollectionUtils.isEmpty(planConfigEntry.getAssumptions())) { List assumptionList = new ArrayList<>(); assumptionList.add(assumption); @@ -131,6 +139,7 @@ private void addAssumptions(ResultSet rs, PlanConfiguration planConfigEntry, Set planConfigEntry.getAssumptions().add(assumption); } + // Mark this assumptionId as processed assumptionSet.add(assumptionId); } @@ -145,10 +154,12 @@ private void addAssumptions(ResultSet rs, PlanConfiguration planConfigEntry, Set private void addOperations(ResultSet rs, PlanConfiguration planConfigEntry, Set operationSet) throws SQLException { String operationId = rs.getString("plan_configuration_operations_id"); + // Skip processing if the operationId is empty or already processed if (ObjectUtils.isEmpty(operationId) || operationSet.contains(operationId)) { return; } + // Create and populate the Operation object Operation operation = new Operation(); operation.setId(operationId); operation.setInput(rs.getString("plan_configuration_operations_input")); @@ -161,6 +172,7 @@ private void addOperations(ResultSet rs, PlanConfiguration planConfigEntry, Set< operation.setCategory(rs.getString("plan_configuration_operations_category")); operation.setExecutionOrder(rs.getInt("plan_configuration_execution_order")); + // Creates a new operation list if it is not already initialized in planConfigEntry and adds the operation object. if (CollectionUtils.isEmpty(planConfigEntry.getOperations())) { List operationList = new ArrayList<>(); operationList.add(operation); @@ -169,6 +181,7 @@ private void addOperations(ResultSet rs, PlanConfiguration planConfigEntry, Set< planConfigEntry.getOperations().add(operation); } + // Mark this operationId as processed operationSet.add(operationId); } @@ -183,10 +196,12 @@ private void addOperations(ResultSet rs, PlanConfiguration planConfigEntry, Set< private void addResourceMappings(ResultSet rs, PlanConfiguration planConfigEntry, Set resourceMappingSet) throws SQLException { String mappingId = rs.getString("plan_configuration_mapping_id"); + // Skip processing if the mappingId is empty or already processed if (ObjectUtils.isEmpty(mappingId) || resourceMappingSet.contains(mappingId)) { return; } + // Create and populate the ResourceMapping object ResourceMapping mapping = new ResourceMapping(); mapping.setId(mappingId); mapping.setFilestoreId(rs.getString("plan_configuration_mapping_filestore_id")); @@ -194,6 +209,7 @@ private void addResourceMappings(ResultSet rs, PlanConfiguration planConfigEntry mapping.setMappedTo(rs.getString("plan_configuration_mapping_mapped_to")); mapping.setActive(rs.getBoolean("plan_configuration_mapping_active")); + // Creates a new ResourceMapping list if it is not already initialized in planConfigEntry and adds the ResourceMapping object. if (CollectionUtils.isEmpty(planConfigEntry.getResourceMapping())) { List mappingList = new ArrayList<>(); mappingList.add(mapping); @@ -202,6 +218,7 @@ private void addResourceMappings(ResultSet rs, PlanConfiguration planConfigEntry planConfigEntry.getResourceMapping().add(mapping); } + // Mark this mappingId as processed resourceMappingSet.add(mappingId); } 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..25c8a783de 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 @@ -111,6 +111,7 @@ private void addActivities(ResultSet rs, Plan plan, addActivityConditions(rs, activity, conditionSet); + // Creates a new Activity list if it is not already initialized in Plan object and adds the Activity object. if (CollectionUtils.isEmpty(plan.getActivities())) { List activityList = new ArrayList<>(); activityList.add(activity); @@ -119,6 +120,7 @@ private void addActivities(ResultSet rs, Plan plan, plan.getActivities().add(activity); } + // Mark this activityId as processed activityMap.put(activity.getId(), activity); } @@ -146,6 +148,7 @@ private void addActivityConditions(ResultSet rs, Activity activity, Set .expression(rs.getString("plan_activity_condition_expression")) .build(); + // Creates a new Condition list if it is not already initialized in activity object and adds the Condition object. if (CollectionUtils.isEmpty(activity.getConditions())) { List conditionList = new ArrayList<>(); conditionList.add(condition); @@ -154,6 +157,7 @@ private void addActivityConditions(ResultSet rs, Activity activity, Set activity.getConditions().add(condition); } + // Mark this conditionId as processed conditionSet.add(condition.getId()); } @@ -182,6 +186,7 @@ private void addResources(ResultSet rs, Plan planEntry, Set resourceSet) .activityCode(rs.getString("plan_resource_activity_code")) .build(); + // Creates a new Resource list if it is not already initialized in planEntry and adds the Resource object. if (CollectionUtils.isEmpty(planEntry.getResources())) { List resourceList = new ArrayList<>(); resourceList.add(resource); @@ -190,6 +195,7 @@ private void addResources(ResultSet rs, Plan planEntry, Set resourceSet) planEntry.getResources().add(resource); } + // Mark this resourceId as processed resourceSet.add(resource.getId()); } @@ -223,6 +229,7 @@ private void addTargets(ResultSet rs, Plan planEntry, Set targetSet) thr .activityCode(rs.getString("plan_target_activity_code")) .build(); + // Creates a new Target list if it is not already initialized in planEntry and adds the Target object. if (CollectionUtils.isEmpty(planEntry.getTargets())) { List targetList = new ArrayList<>(); targetList.add(target); @@ -231,6 +238,7 @@ private void addTargets(ResultSet rs, Plan planEntry, Set targetSet) thr planEntry.getTargets().add(target); } + // Mark this targetId as processed targetSet.add(target.getId()); }