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

API Changes for FLW created ABHA IDs data sync #63

Merged
merged 24 commits into from
Feb 27, 2025

Conversation

helenKaryamsetty
Copy link
Member

@helenKaryamsetty helenKaryamsetty commented Feb 26, 2025

πŸ“‹ Description

JIRA ID: AMM-1262

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • New Features

    • Introduced new endpoints for mapping health accounts to beneficiaries and adding health ID records.
  • Bug Fixes

    • Removed outdated mapping functionality for health IDs to beneficiaries.
  • Refactor

    • Enhanced the data model by including additional fields to capture more user details.
    • Improved record creation logic with strengthened verification and error handling for more reliable processing.

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request removes the mapHealthIDToBeneficiary method from the CreateHealthIDWithMobileOTP class and introduces a new controller, CreateHealthIdRecord, containing two POST endpoints: one for mapping an ABHA to a beneficiary and another for adding a health ID record. The data model in HealthIDRequestAadhar is refactored to use Lombok’s @Data annotation, removing manual getters/setters and adding new fields. Additionally, a new method is added to the HealthIDService interface, with a corresponding implementation update in HealthIDServiceImpl that includes repository integration.

Changes

File(s) Change Summary
src/.../CreateHealthIDWithMobileOTP.java Removed mapHealthIDToBeneficiary method responsible for mapping ABHA to beneficiary.
src/.../CreateHealthIdRecord.java Added new controller class with two POST endpoints: mapHealthIDToBeneficiary and addRecordToHealthIdTable to handle ABHA mapping and record creation.
src/.../HealthIDRequestAadhar.java Modified to use Lombok’s @Data annotation; removed explicit getter/setter methods; added new fields isNew and dob.
src/.../HealthIDService.java Added a new method addRecordToHealthIdTable(String request) throws FHIRException; to the service interface.
src/.../HealthIDServiceImpl.java Injected HealthIDRepo; updated mapHealthIDToBeneficiary to check health ID existence; added addRecordToHealthIdTable method for creating new records.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant CR as CreateHealthIdRecord
    participant HS as HealthIDServiceImpl
    participant HR as HealthIDRepo

    C->>+CR: POST /mapHealthIDToBeneficiary (request, Authorization)
    CR->>+HS: mapHealthIDToBeneficiary(request, Authorization)
    HS->>+HR: Check if health ID exists in t_healthId
    HR-->>-HS: Return health ID count
    HS-->>-CR: Construct HealthIDResponse or error
    CR-->>-C: Return response

    C->>+CR: POST /addHealthIdRecord (request, Authorization)
    CR->>+HS: addRecordToHealthIdTable(request, Authorization)
    HS->>+HR: Check for existing health ID
    HR-->>-HS: Return health ID count
    HS-->>-CR: Save record and return status
    CR-->>-C: Return response
Loading

Possibly related PRs

  • Abdm M1 V3 ChangesΒ #52: Addresses similar functionality by introducing a new mapHealthIDToBeneficiary method in a different controller.

Suggested reviewers

  • ravishanigarapu

Poem

I'm a rabbit with hops so spry,
Celebrating changes that reach the sky.
Methods move and code gets new light,
With endpoints fresh, our path is bright.
Bugs beware – I'm on the run! πŸ‡βœ¨
CodeRabbit leads the way, fun!
Happy coding till the break of dawn.


πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between d9201ff and 43d6b48.

πŸ“’ Files selected for processing (1)
  • src/main/java/com/wipro/fhir/data/healthID/HealthIDRequestAadhar.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/wipro/fhir/data/healthID/HealthIDRequestAadhar.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)

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.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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: 1

🧹 Nitpick comments (5)
src/main/java/com/wipro/fhir/service/healthID/HealthIDService.java (1)

29-29: Consider documenting the new interface method more thoroughly.
While the signature is self-explanatory, adding JavaDoc or method-level comments about the expected JSON format, usage context, and concurrency considerations will enhance maintainability and help prevent misuse.

src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (1)

109-111: Avoid overly broad exception handling.
Catching all exceptions under Exception e obscures the specific causes of errors. Prefer catching narrower exceptions or rethrowing the original exception to preserve diagnostic information.

src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIdRecord.java (2)

37-54: Improve request validation.
mapHealthIDToBeneficiary directly accepts a raw JSON string, leaving validation to deeper service layers. Consider binding to a typed DTO or adding validation checks to guard against malformed JSON or incomplete fields.


59-76: Enhance error handling and logging.
While you log the encountered exception, consider using logger.error("Error mapping health ID", e) or a similar pattern to include stack trace details. Also, ensure that error codes follow a consistent scheme across the application to facilitate debugging.

src/main/java/com/wipro/fhir/data/healthID/HealthIDRequestAadhar.java (1)

41-42: Consider using a date-specific type for the dob field.

The dob field is currently defined as a String, which might not be the most type-safe approach for handling dates. Consider using Java's date types like LocalDate or Date to ensure proper date validation and formatting.

 	String password;
 	String profilePhoto;
 	Boolean isNew;
-	String dob;
+	LocalDate dob;

You would also need to add the import:

import java.time.LocalDate;
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b47be0f and d9201ff.

πŸ“’ Files selected for processing (5)
  • src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java (0 hunks)
  • src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIdRecord.java (1 hunks)
  • src/main/java/com/wipro/fhir/data/healthID/HealthIDRequestAadhar.java (2 hunks)
  • src/main/java/com/wipro/fhir/service/healthID/HealthIDService.java (1 hunks)
  • src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (5 hunks)
πŸ’€ Files with no reviewable changes (1)
  • src/main/java/com/wipro/fhir/controller/healthID/CreateHealthIDWithMobileOTP.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (5)
src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java (4)

60-75: Validate request fields early.
Within mapHealthIDToBeneficiary, the code references several request fields (e.g., beneficiaryRegId, beneficiaryID, healthIdNumber) but lacks explicit field-level validation for JSON segments like ABHAProfile. Ensure the request includes all required fields to avoid future NullPointerExceptions.


76-107: Address potential concurrency issue when creating new ABHA records.
The check if (healthIdCount < 1) may lead to race conditions if multiple simultaneous requests arrive with the same ABHA details. Consider adding a unique constraint at the database layer or employing a locking strategy to guarantee data integrity.


131-132: Concurrency concern repeats here.
The same race condition identified in mapHealthIDToBeneficiary applies to the if (healthIdCount < 1) check. A unique DB constraint or locking mechanism can help ensure correctness.


163-164: Broad catch block repeats here.
This exception-handling pattern is the same as above. Narrowing the catch scope makes debugging and error handling more precise.

src/main/java/com/wipro/fhir/data/healthID/HealthIDRequestAadhar.java (1)

24-26: Good use of Lombok to reduce boilerplate code.

Using Lombok's @Data annotation is a great improvement that eliminates the need for manually writing getters, setters, equals, hashCode, and toString methods. This makes the code more maintainable and concise.

Comment on lines +123 to +166

@Override
public String addRecordToHealthIdTable(String request) throws FHIRException {
JsonObject jsonRequest = JsonParser.parseString(request).getAsJsonObject();
JsonObject abhaProfileJson = jsonRequest.getAsJsonObject("ABHAProfile");
HealthIDResponse healthID = InputMapper.gson().fromJson(abhaProfileJson, HealthIDResponse.class);
String res = null;
try {
Integer healthIdCount = healthIDRepo.getCountOfHealthIdNumber(healthID.getHealthIdNumber());
if(healthIdCount < 1) {
healthID.setHealthIdNumber(abhaProfileJson.get("ABHANumber").getAsString());
JsonArray phrAddressArray = abhaProfileJson.getAsJsonArray("phrAddress");
StringBuilder abhaAddressBuilder = new StringBuilder();

for (int i = 0; i < phrAddressArray.size(); i++) {
abhaAddressBuilder.append(phrAddressArray.get(i).getAsString());
if (i < phrAddressArray.size() - 1) {
abhaAddressBuilder.append(", ");
}
}
healthID.setHealthId(abhaAddressBuilder.toString());
healthID.setName(
abhaProfileJson.get("firstName").getAsString() + " " + abhaProfileJson.get("middleName").getAsString() + " " + abhaProfileJson.get("lastName").getAsString());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = simpleDateFormat.parse(abhaProfileJson.get("dob").getAsString());
SimpleDateFormat year = new SimpleDateFormat("yyyy");
SimpleDateFormat month = new SimpleDateFormat("MM");
SimpleDateFormat day = new SimpleDateFormat("dd");
healthID.setYearOfBirth(year.format(date));
healthID.setMonthOfBirth(month.format(date));
healthID.setDayOfBirth(day.format(date));
healthID.setCreatedBy(jsonRequest.get("createdBy").getAsString());
healthID.setProviderServiceMapID(jsonRequest.get("providerServiceMapId").getAsInt());
healthID.setIsNewAbha(jsonRequest.get("isNew").getAsBoolean());
healthIDRepo.save(healthID);
res = "Data Saved Successfully";
} else {
res = "Data already exists";
}
} catch (Exception e) {
throw new FHIRException("Error in saving data");
}
return res;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

Refactor to reduce duplicate JSON parsing logic.
This method mirrors much of the JSON parsing and entity population performed in mapHealthIDToBeneficiary. Consider extracting a private utility method to parse and populate HealthIDResponse so both methods can reuse it, reducing maintenance overhead.

Copy link

sonarqubecloud bot commented Feb 27, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
3 Security Hotspots
37.1% Duplication on New Code (required ≀ 3%)

See analysis details on SonarQube Cloud

Copy link
Member

@ravishanigarapu ravishanigarapu left a comment

Choose a reason for hiding this comment

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

looks ok

@ravishanigarapu ravishanigarapu merged commit f55149d into PSMRI:develop Feb 27, 2025
6 of 7 checks passed
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