Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCMPRE:1817 - Bug Fix - validating plan employee assignments only for active update calls #1329

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

tanishi-egov
Copy link
Collaborator

@tanishi-egov tanishi-egov commented Jan 7, 2025

Bug link: https://digit-discuss.atlassian.net/browse/HCMPRE-1817?atlOrigin=eyJpIjoiZDQ5Yzk0MTJmNzBkNGRlMjk4NTVhMzY0MzBiNTNjZjQiLCJwIjoiaiJ9

Summary by CodeRabbit

  • New Features

    • Added support for additional fields in plans, allowing more flexible data storage and retrieval
    • Enhanced plan data model to include customizable additional information
  • Database Changes

    • Created new database table plan_additional_field to store supplementary plan details
  • Improvements

    • Updated repository, row mapping, and validation logic to handle new additional fields
    • Expanded data retrieval capabilities for plan-related queries

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

This pull request introduces a comprehensive enhancement to the plan service by adding support for additional fields across multiple components. The changes span from database schema modifications to data model updates, repository implementations, and validation logic. The primary focus is on extending the plan-related data structures to accommodate more flexible and dynamic information storage, specifically through the introduction of a new additionalFields property in various classes and a corresponding database table.

Changes

File Change Summary
.../PlanRepositoryImpl.java Added additionalFields to convertToPlanReqDTO method
.../PlanQueryBuilder.java Updated SQL query to include plan_additional_field table joins
.../PlanRowMapper.java Added method to extract and map additional fields from result set
.../PlanEnricher.java Enhanced UUID generation for additional fields in create and update methods
.../PlanFacilityEnricher.java Consolidated import statements
.../PlanEmployeeAssignmentValidator.java Conditional validation for active plan employee assignments
.../PlanFacilityValidator.java Refined boundary code retrieval and validation methods
.../AdditionalField.java Moved package from census to models
.../Plan.java Added additionalFields property
.../PlanDTO.java Added additionalFields field
.../Census.java Added additionalFields field
.../V20242112151500__plan_additional_field_create_ddl.sql Created new plan_additional_field database table

Sequence Diagram

sequenceDiagram
    participant Client
    participant PlanService
    participant PlanEnricher
    participant PlanRepository
    participant Database

    Client->>PlanService: Create/Update Plan
    PlanService->>PlanEnricher: Enrich Plan
    PlanEnricher-->>PlanService: Generate UUIDs for Additional Fields
    PlanService->>PlanRepository: Save Plan
    PlanRepository->>Database: Insert Plan and Additional Fields
    Database-->>PlanRepository: Confirm Insertion
    PlanRepository-->>PlanService: Return Saved Plan
    PlanService-->>Client: Return Plan Details
Loading

Possibly related PRs

Suggested reviewers

  • sathishp-eGov
  • kavi-egov
  • shashwat-egov

Poem

🐰 Hopping through code with glee,
Additional fields now set free!
From database to model's might,
Flexibility shines so bright!
A rabbit's dance of data delight! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9dbb1d7 and 518c1cf.

📒 Files selected for processing (12)
  • health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java (4 hunks)
  • health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java (2 hunks)
  • health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/service/validator/PlanEmployeeAssignmentValidator.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/web/models/Plan.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java (1 hunks)
  • health-services/plan-service/src/main/java/digit/web/models/census/Census.java (1 hunks)
  • health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql (1 hunks)
🧰 Additional context used
📓 Learnings (4)
health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java (1)
Learnt from: Saloni-eGov
PR: egovernments/health-campaign-services#906
File: health-services/plan-service/src/main/java/digit/web/models/PlanFacility.java:61-67
Timestamp: 2024-11-12T10:40:11.591Z
Learning: In the `addServiceBoundariesItem` method in `PlanFacility.java`, it's acceptable to initialize `serviceBoundaries` if it's null without adding a null check for `serviceBoundariesItem`.
health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java (1)
Learnt from: Priyanka-eGov
PR: egovernments/health-campaign-services#737
File: health-services/plan-service/src/main/java/digit/web/models/Plan.java:46-47
Timestamp: 2024-11-10T20:01:49.000Z
Learning: The `additionalDetails` field in the `Plan` class can be empty or null, as clarified by Priyanka-eGov.
health-services/plan-service/src/main/java/digit/web/models/Plan.java (1)
Learnt from: Priyanka-eGov
PR: egovernments/health-campaign-services#737
File: health-services/plan-service/src/main/java/digit/web/models/Plan.java:46-47
Timestamp: 2024-11-10T20:01:49.000Z
Learning: The `additionalDetails` field in the `Plan` class can be empty or null, as clarified by Priyanka-eGov.
health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql (1)
Learnt from: Taniya-eGov
PR: egovernments/health-campaign-services#914
File: health-services/plan-service/src/main/resources/db/migration/main/V20240923113045__plan_facility_create_ddl.sql:8-8
Timestamp: 2024-11-12T10:40:11.591Z
Learning: In the `plan_facility_linkage` table, the `service_boundaries` column is intentionally defined as `varchar(2048)` and does not need to be changed to an array or JSONB.
🔇 Additional comments (12)
health-services/plan-service/src/main/java/digit/web/models/Plan.java (1)

77-79: Clarify the distinction between additionalFields and additionalDetails

The class now has two similar-sounding fields for additional data:

  1. additionalDetails (Object)
  2. additionalFields (List)

This could lead to confusion about which field should be used for what purpose.

Could you clarify:

  1. The specific use case for additionalFields
  2. Why it's needed alongside additionalDetails
  3. How this relates to the PR objective of fixing employee assignment validation
health-services/plan-service/src/main/java/digit/web/models/PlanDTO.java (1)

62-64: Review data type inconsistency in assignee field

While adding additionalFields, I noticed that:

  • Plan.assignee is List<String>
  • PlanDTO.assignee is String

This type mismatch could cause issues during data transformation.

Could you verify if this is intentional? The current implementation in PlanRepositoryImpl.convertToPlanReqDTO joins the list with commas, but this approach:

  1. Makes it harder to validate individual assignees
  2. Could break if an assignee contains a comma
  3. Might cause issues when parsing back to a list
health-services/plan-service/src/main/java/digit/web/models/census/Census.java (1)

11-11: Clarify the relationship between Plan and Census models

The addition of additionalFields to both Plan and Census models suggests a relationship between them, but:

  1. They're in different packages
  2. The PR objective is about employee assignment validation
  3. Both models maintain separate additionalDetails fields

Could you explain:

  1. The relationship between Plan and Census models?
  2. Why both models need the same enhancement?
  3. How this relates to the employee assignment validation fix?

Also applies to: 62-64

health-services/plan-service/src/main/java/digit/repository/impl/PlanRepositoryImpl.java (1)

192-192: Missing validation for employee assignments

The PR objective mentions fixing employee assignment validation, but I don't see any changes related to validation logic. The only change here is adding additionalFields to the DTO conversion.

Could you clarify:

  1. Where is the employee assignment validation logic implemented?
  2. How does adding additionalFields help fix the validation issue?

Run this script to find relevant validation code:

health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java (1)

56-58: LGTM! UUID enrichment for additionalFields is properly implemented.

The implementation follows the existing pattern and includes proper null check using CollectionUtils.

health-services/plan-service/src/main/java/digit/repository/rowmapper/PlanRowMapper.java (2)

33-33: LGTM! Proper initialization and clearing of additionalFieldSet.

The implementation follows the existing pattern of using Sets for tracking unique IDs.

Also applies to: 47-47


241-273: LGTM! Well-implemented additionalField mapping method.

The implementation:

  • Has proper documentation
  • Includes null checks
  • Prevents duplicates
  • Follows existing patterns
health-services/plan-service/src/main/java/digit/repository/querybuilder/PlanQueryBuilder.java (1)

33-34: LGTM! SQL query properly extended for additional fields.

The changes:

  • Use consistent aliasing
  • Maintain proper formatting
  • Use appropriate LEFT JOIN

Also applies to: 39-40

health-services/plan-service/src/main/java/digit/service/validator/PlanFacilityValidator.java (2)

129-136: LGTM! Improved boundary validation logic.

The changes enhance clarity by properly separating lowest hierarchy and all boundary validations.


Line range hint 143-170: LGTM! Well-structured boundary code fetching methods.

The refactoring:

  • Separates concerns clearly
  • Has proper documentation
  • Uses streams effectively

However, consider adding unit tests for these new methods to ensure proper coverage.

Would you like me to help generate unit tests for these methods?

health-services/plan-service/src/main/resources/db/migration/main/V20242112151500__plan_additional_field_create_ddl.sql (1)

6-6: 🧹 Nitpick (assertive)

Consider using a more flexible data type for the value column.

The numeric(12,2) type might be restrictive for storing different types of values. Consider using text or jsonb if the values need to support different data types (strings, numbers, boolean, etc.).

-  "value"                       numeric(12,2) NOT NULL,
+  "value"                       text NOT NULL,

Likely invalid or redundant comment.

health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java (1)

1-1: LGTM! Package move is appropriate.

Moving the class to digit.web.models makes sense as it's now used by both Census and Plan entities.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tanishi-egov tanishi-egov changed the base branch from master to microplanning-v0.2 January 7, 2025 09:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
health-services/plan-service/src/main/java/digit/web/models/AdditionalField.java (1)

Line range hint 31-33: Consider making the value field type more flexible.

If the database column type is changed to text, consider updating this field to use String instead of BigDecimal to support different value types.

-    private BigDecimal value = null;
+    private String value = null;
🛑 Comments failed to post (3)
health-services/plan-service/src/main/java/digit/service/enrichment/PlanEnricher.java (1)

114-119: ⚠️ Potential issue

Add null check before forEach operation.

The code could throw NullPointerException if additionalFields is null.

Apply this diff to add null check:

-        body.getPlan().getAdditionalFields().forEach(additionalFields -> {
-            if(ObjectUtils.isEmpty(additionalFields.getId())) {
-                UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id");
-            }
-        });
+        if(!CollectionUtils.isEmpty(body.getPlan().getAdditionalFields())) {
+            body.getPlan().getAdditionalFields().forEach(additionalFields -> {
+                if(ObjectUtils.isEmpty(additionalFields.getId())) {
+                    UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id");
+                }
+            });
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        // Generate uuid for new additionalFields
        if(!CollectionUtils.isEmpty(body.getPlan().getAdditionalFields())) {
            body.getPlan().getAdditionalFields().forEach(additionalFields -> {
                if(ObjectUtils.isEmpty(additionalFields.getId())) {
                    UUIDEnrichmentUtil.enrichRandomUuid(additionalFields, "id");
                }
            });
        }
health-services/plan-service/src/main/java/digit/service/validator/PlanEmployeeAssignmentValidator.java (1)

320-322: 🧹 Nitpick (assertive)

LGTM! Consider adding braces for better readability.

The conditional validation for active records is logically correct and aligns with the PR objective. However, consider adding braces to the if statement for better readability and maintainability.

-        if(planEmployeeAssignment.getActive())
-            validateCampaignDetails(planConfigurations.get(0).getCampaignId(), rootTenantId, request);
+        if (planEmployeeAssignment.getActive()) {
+            validateCampaignDetails(planConfigurations.get(0).getCampaignId(), rootTenantId, request);
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        // Validate campaign id and employee jurisdiction for active records
        if (planEmployeeAssignment.getActive()) {
            validateCampaignDetails(planConfigurations.get(0).getCampaignId(), rootTenantId, request);
        }
health-services/plan-service/src/main/java/digit/service/enrichment/PlanFacilityEnricher.java (1)

6-6: 🧹 Nitpick (assertive)

Consider using individual imports instead of wildcard.

While wildcard imports reduce the number of import statements, individual imports are generally preferred as they:

  1. Make dependencies explicit
  2. Avoid potential naming conflicts
  3. Improve code readability and maintainability
-import digit.web.models.*;
+import digit.web.models.PlanFacility;
+import digit.web.models.PlanFacilityRequest;
+import digit.web.models.PlanFacilitySearchCriteria;
+import digit.web.models.PlanFacilitySearchRequest;

Committable suggestion skipped: line range outside the PR's diff.

@Priyanka-eGov Priyanka-eGov merged commit 1ba656a into microplanning-v0.2 Jan 9, 2025
4 of 6 checks passed
@Priyanka-eGov Priyanka-eGov deleted the HCMPRE-1817 branch January 9, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants