Skip to content

[Eng-93] fix: Added start time in service_period on system generated accounts#3635

Merged
vigneshhari merged 1 commit intodevelopfrom
ENG-93-be-auto-created-accounts-dont-have-service-period-start-set
May 6, 2026
Merged

[Eng-93] fix: Added start time in service_period on system generated accounts#3635
vigneshhari merged 1 commit intodevelopfrom
ENG-93-be-auto-created-accounts-dont-have-service-period-start-set

Conversation

@nandkishorr
Copy link
Copy Markdown
Contributor

@nandkishorr nandkishorr commented May 6, 2026

Proposed Changes

  • Added start time in service_period for default generated accounts
  • ENG-93

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • New Features
    • Accounts now automatically receive a service period start timestamp upon creation.

@nandkishorr nandkishorr requested a review from a team as a code owner May 6, 2026 10:40
@nandkishorr nandkishorr self-assigned this May 6, 2026
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

The get_default_account function now assigns a service_period start timestamp to newly created accounts, capturing the current time via care_now() in ISO-like format. One line was added to the Account creation call; all other logic remains intact.

Changes

Account Service Period Initialization

Layer / File(s) Summary
Core Implementation
care/emr/resources/account/default_account.py
New service_period keyword argument added to Account.objects.create(), setting start to the result of care_now() in ISO format.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request description is missing the 'Associated Issue' section details and lacks an 'Architecture changes' section, though the latter is optional. Expand the 'Associated Issue' section to explain how adding the service_period start timestamp solves ENG-93, and clarify whether any architecture changes were made.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main change: adding a start time to the service_period for system-generated accounts, which matches the code modification described.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-93-be-auto-created-accounts-dont-have-service-period-start-set

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nandkishorr nandkishorr changed the title [ ENG-93 ] fix: Added start time in service_period on system generated accounts [ENG-93] fix: Added start time in service_period on system generated accounts May 6, 2026
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
care/emr/resources/account/default_account.py (1)

18-25: ⚡ Quick win

Consolidate care_now() to avoid redundant calls and inconsistent timestamps.

Two separate care_now() invocations on lines 23 and 24 — while unlikely to differ in practice, they could theoretically return different instants (e.g., at a date boundary), making service_period.start and the date in name inconsistent. Assigning it once is cleaner:

now = care_now()
return Account.objects.create(
    patient=patient,
    facility=facility,
    status=AccountStatusOptions.active.value,
    billing_status=AccountBillingStatusOptions.open.value,
    service_period={"start": now.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
    name=f"{patient.name} {now.strftime('%Y-%m-%d')}",
)

The hardcoded Z format is appropriate here (it's the correct ISO 8601 representation for UTC), so no change to the format string is needed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@care/emr/resources/account/default_account.py` around lines 18 - 25, Assign
care_now() to a local variable and reuse it when building the Account in
Account.objects.create so service_period["start"] and the name use the exact
same timestamp; i.e., capture now = care_now() before constructing the dict and
use now.strftime(...) for both service_period and the f"{patient.name} ..." name
to avoid redundant calls and potential timestamp inconsistencies.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@care/emr/resources/account/default_account.py`:
- Around line 18-25: Assign care_now() to a local variable and reuse it when
building the Account in Account.objects.create so service_period["start"] and
the name use the exact same timestamp; i.e., capture now = care_now() before
constructing the dict and use now.strftime(...) for both service_period and the
f"{patient.name} ..." name to avoid redundant calls and potential timestamp
inconsistencies.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0e81dbb8-5f7c-4195-a5ca-019f048f0da9

📥 Commits

Reviewing files that changed from the base of the PR and between 589baaa and 559fd4d.

📒 Files selected for processing (1)
  • care/emr/resources/account/default_account.py

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.56%. Comparing base (589baaa) to head (559fd4d).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3635   +/-   ##
========================================
  Coverage    75.55%   75.56%           
========================================
  Files          479      479           
  Lines        22958    22958           
  Branches      2369     2369           
========================================
+ Hits         17347    17349    +2     
+ Misses        5040     5039    -1     
+ Partials       571      570    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nandkishorr nandkishorr changed the title [ENG-93] fix: Added start time in service_period on system generated accounts [Eng-93] fix: Added start time in service_period on system generated accounts May 6, 2026
@vigneshhari vigneshhari merged commit 0f7990d into develop May 6, 2026
11 of 12 checks passed
@vigneshhari vigneshhari deleted the ENG-93-be-auto-created-accounts-dont-have-service-period-start-set branch May 6, 2026 17:12
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