Skip to content

AMM-1266 and lmpDateformat corrected#59

Merged
helenKaryamsetty merged 5 commits intoPSMRI:developfrom
ravishanigarapu:develop
Apr 10, 2025
Merged

AMM-1266 and lmpDateformat corrected#59
helenKaryamsetty merged 5 commits intoPSMRI:developfrom
ravishanigarapu:develop

Conversation

@ravishanigarapu
Copy link
Copy Markdown
Contributor

@ravishanigarapu ravishanigarapu commented Apr 10, 2025

📋 Description

JIRA ID: AMM-1266

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

    • Enhanced the worklist API to deliver results as a formatted JSON response, ensuring consistent and clear output.
  • Bug Fixes

    • Refined call processing to correctly assign statuses based on user roles, improving overall reliability.
  • Chores

    • Updated configuration settings to support flexible dependency management and circular references, bolstering system stability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2025

Walkthrough

This pull request updates methods in two Java classes and the application configuration. The OutBoundWorklistController now returns a JSON string instead of a list by converting the result using an ObjectMapper with a custom date format. In CallClosureImpl, the logic in closeCall has been refined to conditionally set the call status based on the role name and the isHrp flag. Additionally, two Spring configuration properties have been added in application.properties to allow bean overriding and circular references.

Changes

File Path Change Summary
src/main/java/com/iemr/ecd/controller/outboundworklist/OutBoundWorklistController.java Modified getMotherWorklist method: Changed return type from ResponseEntity<List<FetchMotherOutboundWorklist>> to ResponseEntity<String>, implemented JSON conversion with an ObjectMapper, and added relevant imports.
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java Updated closeCall method: Refined isHrp handling by adding a condition that sets the call status to "Open" when receivedRoleName equals Constants.ANM and removed obsolete commented code.
src/main/resources/application.properties Added configuration properties: spring.main.allow-bean-definition-overriding=true and spring.main.allow-circular-references=true to adjust Spring's bean management behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as OutBoundWorklistController
    participant Service as outboundWorkListServiceImpl
    participant Mapper as ObjectMapper

    Client->>Controller: getMotherWorklist(userId)
    Controller->>Service: getMotherWorkList(userId)
    Service-->>Controller: List<FetchMotherOutboundWorklist>
    Controller->>Mapper: writeValueAsString(motherWorkList)
    Mapper-->>Controller: JSON String
    Controller->>Client: ResponseEntity(JSON String)
Loading
sequenceDiagram
    participant Caller
    participant CallClosure as CallClosureImpl

    Caller->>CallClosure: closeCall(request)
    alt if request.getIsHrp is true
      CallClosure->>CallClosure: Evaluate receivedRoleName
      alt if receivedRoleName == Constants.ANM
         CallClosure->>CallClosure: Set callStatus = "Open"
      end
    end
    CallClosure-->>Caller: Return call closure outcome
Loading

Possibly related PRs

Suggested reviewers

  • devikasuresh20
  • helenKaryamsetty

Poem

I'm a rabbit with hops so fleet,
Coding changes that feel so sweet.
JSON strings and bean config delight,
In Spring and Java, my heart takes flight.
With a twitch of my nose and a joyful glee,
Carrots and clean code, what a sight!
🐰🥕


📜 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 8b78ee6 and ab5b13d.

📒 Files selected for processing (1)
  • src/main/java/com/iemr/ecd/controller/outboundworklist/OutBoundWorklistController.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/main/java/com/iemr/ecd/controller/outboundworklist/OutBoundWorklistController.java (1)

24-24: New imports added for JSON processing and date formatting

These imports support the new implementation of the getMotherWorklist method to handle custom date formatting and JSON serialization.

Also applies to: 37-38

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown

@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 (2)
src/main/resources/application.properties (1)

53-54:

Details

❓ Verification inconclusive

Review the necessity of Spring configuration changes

These Spring configuration properties can introduce maintenance challenges:

  • allow-bean-definition-overriding=true allows later bean definitions to override earlier ones with identical names (disabled by default since Spring 5.1)
  • allow-circular-references=true permits circular dependencies between beans (typically considered an anti-pattern)

Rather than enabling these potentially problematic behaviors, consider refactoring the application to address the underlying design issues that necessitate these properties.


🏁 Script executed:

#!/bin/bash
# Check for potential circular dependencies in the codebase

echo "Searching for circular dependency patterns in the codebase..."
rg -A 2 -B 2 "@Autowired|@Inject" --type java | grep -A 5 -B 5 "private.*Service|private.*Repository|private.*Component|private.*Controller"

Length of output: 275


Action Required: Reevaluate Spring Configuration Settings

The configuration in src/main/resources/application.properties at lines 53–54 currently enables:

spring.main.allow-bean-definition-overriding=true
spring.main.allow-circular-references=true

Concerns:

  • Bean Overriding: Allows later bean definitions to override earlier ones, which can obscure configuration issues.
  • Circular References: Permits circular dependencies between beans—a practice that may hide underlying design problems and lead to maintenance challenges.

The automated scan for circular dependency patterns did not produce any output. However, this lack of findings does not conclusively rule out issues; the nature of such dependency problems often requires a deeper, manual inspection of bean wiring and application design.

Next Steps:

  • Manual Verification: Please review the bean configuration and dependency graph to confirm that these settings are truly necessary.
  • Consider Refactoring: Where possible, refactor your bean definitions to eliminate reliance on both overriding and circular references.
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (1)

209-214: Added conditional status processing for high-risk patients detected by ANM

The implementation properly sets high risk flag and conditionally updates call status to "Open" when the received role is ANM, ensuring these cases receive appropriate follow-up.

Consider adding a comment explaining the business rule that requires ANM-detected high-risk cases to be reopened, as this would improve code maintainability and make the domain logic more explicit.

if (request.getIsHrp() != null) {
    callObj.setIsHighRisk(request.getIsHrp());
+   // ANM-detected high-risk pregnancies require additional follow-up, so we keep the call status open
    if(obj.getReceivedRoleName().equalsIgnoreCase(Constants.ANM)){
        callObj.setCallStatus(Constants.OPEN);
    }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7da467c and 8b78ee6.

📒 Files selected for processing (3)
  • src/main/java/com/iemr/ecd/controller/outboundworklist/OutBoundWorklistController.java (3 hunks)
  • src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (1 hunks)
  • src/main/resources/application.properties (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/java/com/iemr/ecd/service/associate/CallClosureImpl.java (1)
src/main/java/com/iemr/ecd/utils/constants/Constants.java (1)
  • Constants (5-21)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/main/java/com/iemr/ecd/controller/outboundworklist/OutBoundWorklistController.java (1)

24-25: New imports added to support JSON serialization with custom date format

The newly added imports support the modified implementation of getMotherWorklist method.

Also applies to: 37-39

Comment on lines +66 to 73
public ResponseEntity<String> getMotherWorklist(@PathVariable int userId) throws JsonProcessingException {
List<FetchMotherOutboundWorklist> motherWorkList = outboundWorkListServiceImpl.getMotherWorkList(userId);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
String writeValueAsString = objectMapper.writeValueAsString(motherWorkList);

return new ResponseEntity<>(writeValueAsString,HttpStatus.OK);
}
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 10, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Standardize JSON response format with custom date formatting

The method now returns a JSON string with a consistent date format pattern, which should improve date handling on the client side. However, this approach differs from the getChildWorklist method that uses Spring's default serialization.

For better consistency and maintainability, consider:

  1. Using the same approach for both mother and child endpoints
  2. Configuring date formatting globally in your application
-public ResponseEntity<String> getMotherWorklist(@PathVariable int userId) throws JsonProcessingException {
-	List<FetchMotherOutboundWorklist> motherWorkList = outboundWorkListServiceImpl.getMotherWorkList(userId);
-	ObjectMapper objectMapper = new ObjectMapper();
-	objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
-	String writeValueAsString = objectMapper.writeValueAsString(motherWorkList);
-	
-	return  new ResponseEntity<>(writeValueAsString,HttpStatus.OK);
+public ResponseEntity<List<FetchMotherOutboundWorklist>> getMotherWorklist(@PathVariable int userId) {
+	return new ResponseEntity<>(outboundWorkListServiceImpl.getMotherWorkList(userId), HttpStatus.OK);
}

Then configure the date format globally in your application configuration:

@Configuration
public class JacksonConfig {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        return builder -> builder.dateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    }
}

🏁 Script executed:

#!/bin/bash
# Check if there's a global ObjectMapper configuration in the codebase

echo "Searching for existing Jackson configuration..."
rg -A 5 -B 5 "ObjectMapper|Jackson2ObjectMapperBuilder|@JsonFormat" --type java

Length of output: 8629


Refactor Serialization Approach for Consistency

We recommend updating the getMotherWorklist method to align with the serialization approach used in getChildWorklist. Rather than manually instantiating an ObjectMapper and setting a date format within the controller, return a typed response (i.e. ResponseEntity<List<FetchMotherOutboundWorklist>>) and centralize the date formatting through a global configuration.

Action Items:

  • Update the method’s signature to return the list directly.
  • Remove the manual creation of ObjectMapper and custom date formatting.
  • Configure global date formatting (e.g., via a JacksonConfig class with a Jackson2ObjectMapperBuilderCustomizer bean) so both endpoints share the same settings.

Diff Suggestion:

-public ResponseEntity<String> getMotherWorklist(@PathVariable int userId) throws JsonProcessingException {
-	List<FetchMotherOutboundWorklist> motherWorkList = outboundWorkListServiceImpl.getMotherWorkList(userId);
-	ObjectMapper objectMapper = new ObjectMapper();
-	objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
-	String writeValueAsString = objectMapper.writeValueAsString(motherWorkList);
-	
-	return  new ResponseEntity<>(writeValueAsString,HttpStatus.OK);
-}
+public ResponseEntity<List<FetchMotherOutboundWorklist>> getMotherWorklist(@PathVariable int userId) {
+	return new ResponseEntity<>(outboundWorkListServiceImpl.getMotherWorkList(userId), HttpStatus.OK);
+}

Global Configuration Example:

@Configuration
public class JacksonConfig {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        return builder -> builder.dateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    }
}

Copy link
Copy Markdown
Contributor Author

@ravishanigarapu ravishanigarapu Apr 10, 2025

Choose a reason for hiding this comment

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

@coderabbitai
if i tried JacksonConfig like above getting timestamp format wrong. so i keep my code only.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ravishanigarapu I understand completely. If you've already tested the global configuration approach and found issues with timestamp formatting, then keeping your current implementation makes perfect sense. Sometimes manual configuration is necessary to meet specific formatting requirements.

One small suggestion: consider renaming the variable writeValueAsString to something like jsonResponse since it represents the result rather than the action being performed. But that's just a minor readability improvement.

✏️ Learnings added
Learnt from: ravishanigarapu
PR: PSMRI/ECD-API#59
File: src/main/java/com/iemr/ecd/controller/outboundworklist/OutBoundWorklistController.java:0-0
Timestamp: 2025-04-10T06:29:26.020Z
Learning: In the ECD-API project, manual ObjectMapper configuration with specific date formatting (yyyy-MM-dd HH:mm:ss) is preferred over global Jackson configuration due to timestamp formatting issues experienced when using the global approach.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@sonarqubecloud
Copy link
Copy Markdown

@helenKaryamsetty helenKaryamsetty merged commit 14a571c into PSMRI:develop Apr 10, 2025
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