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

Feature hcmpre 1611 update target template #1289

Open
wants to merge 6 commits into
base: console
Choose a base branch
from

Conversation

ashish-egov
Copy link
Collaborator

@ashish-egov ashish-egov commented Dec 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new functions for processing target calculations and handling campaign data.
    • Enhanced localization handling in boundary data processing.
  • Bug Fixes

    • Improved validation logic for campaign-related data, with more descriptive error messages.
  • Documentation

    • Updated function signatures to reflect changes in parameters and logic.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

This pull request introduces significant enhancements to the campaign-related services in the project factory, focusing on target calculation, data processing, and validation logic. The changes span multiple files in the server-side implementation, introducing new utility functions for processing campaign data, refining target validation mechanisms, and improving the overall modularity of the code. The modifications aim to streamline how campaign targets are calculated, validated, and processed across different levels of granularity.

Changes

File Change Summary
health-services/project-factory/src/server/api/genericApis.ts - Added processDataForTargetCalculation to import from campaignUtils
- Modified getTargetSheetDataAfterCode to use new processing function
- Updated getJsonData with additional parameters
health-services/project-factory/src/server/utils/campaignUtils.ts - Added new functions: processDataForTargetCalculation, calculateTargetsAtParentLevel, calculateTargetsAtCurrentLevel
- Updated getDataFromGeoJson and addBoundaryCodeToGeoJsonData with localization support
health-services/project-factory/src/server/validators/campaignValidators.ts - Updated validateTargetForNormalCampaigns to accept schema parameter
- Modified validation logic with more descriptive error handling
health-services/project-factory/src/server/validators/microplanValidators.ts - Renamed validateTargetsForMicroplanCampaigns to validateRequiredTargetsForMicroplanCampaigns

Sequence Diagram

sequenceDiagram
    participant Client
    participant GenericApis
    participant CampaignUtils
    participant Validators

    Client->>GenericApis: Request target sheet data
    GenericApis->>CampaignUtils: processDataForTargetCalculation
    CampaignUtils-->>GenericApis: Processed data
    GenericApis->>Validators: Validate targets
    Validators-->>GenericApis: Validation result
    GenericApis-->>Client: Return processed and validated data
Loading

Possibly Related PRs

Poem

🐰 Targets dance, data's delight,
Code refactored, validation's might!
Modules sing their modular tune,
Campaign logic leaps like a rabbit's boon 🌟
Efficiency blooms, errors take flight!

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

@ashish-egov
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Actionable comments posted: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b69ba14 and 3c58171.

📒 Files selected for processing (5)
  • health-services/project-factory/src/server/api/campaignApis.ts (0 hunks)
  • health-services/project-factory/src/server/api/genericApis.ts (3 hunks)
  • health-services/project-factory/src/server/utils/campaignUtils.ts (9 hunks)
  • health-services/project-factory/src/server/validators/campaignValidators.ts (3 hunks)
  • health-services/project-factory/src/server/validators/microplanValidators.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • health-services/project-factory/src/server/api/campaignApis.ts
🧰 Additional context used
🪛 Biome (1.9.4)
health-services/project-factory/src/server/utils/campaignUtils.ts

[error] 1716-1716: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 1708-1708: This let declares a variable that is only assigned once.

'totalTargetValue' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 2364-2364: This let declares a variable that is only assigned once.

'targets' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 2366-2366: This let declares a variable that is only assigned once.

'targetNo' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 2366-2366: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 2367-2367: This let declares a variable that is only assigned once.

'beneficiaryType' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 3035-3035: This let declares a variable that is only assigned once.

'rowData' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

🔇 Additional comments (8)
health-services/project-factory/src/server/utils/campaignUtils.ts (1)

28-28: New import looks good.
This addition correctly imports the searchMDMS function, improving modularity and reusability.

health-services/project-factory/src/server/api/genericApis.ts (3)

7-7: Importing processDataForTargetCalculation is well-structured.
This helps in keeping the processing logic decoupled and maintainable.


211-211: Data fetching with row & sheet name metadata
This change, adding true,true in getJsonData(), ensures row numbers and sheet names are preserved. It can be helpful for debugging & error reporting.


227-227: Delegating target calculation
Invoking processDataForTargetCalculation(...) here centralizes the logic, improving readability and maintainability.

health-services/project-factory/src/server/validators/campaignValidators.ts (3)

25-25: Renamed import for microplan validation
Replacing validateTargetsForMicroplanCampaigns with validateRequiredTargetsForMicroplanCampaigns clarifies intent, aligning with the usage in microplan scenarios.


91-133: Refining target validation for normal campaigns
This block now checks for required columns, data ranges, and integer values. It enhances error details for better user feedback. Make sure to cover edge cases (e.g., extremely large inputs or negative numbers).


160-164: Segregated flow for microplan vs. normal campaigns
Having a distinct path for microplan validations reduces confusion. Just ensure that shared logic doesn't diverge unnecessarily to avoid code duplication.

health-services/project-factory/src/server/validators/microplanValidators.ts (1)

131-131: Renamed to validateRequiredTargetsForMicroplanCampaigns
This clearly indicates that the function enforces minimum required targets for each column, improving code readability. The numeric and integer checks are thorough.

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.

1 participant