Skip to content

feat(healthcare): add Birth Record DocType with newborn child table#972

Open
md-umair-21 wants to merge 5 commits into
earthians:developfrom
md-umair-21:birth-record
Open

feat(healthcare): add Birth Record DocType with newborn child table#972
md-umair-21 wants to merge 5 commits into
earthians:developfrom
md-umair-21:birth-record

Conversation

@md-umair-21

@md-umair-21 md-umair-21 commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a new Birth Record DocType in the Healthcare module along with a supporting Birth Newborn Detail child table.

1.Adds Birth Record DocType with Newborn Details child table
2.Supports single and multiple births (twins/triplets)
3.Captures patient and delivery related information
4.Applies filters for patient-linked inpatient and encounter records
5.Uses naming series HLC-BR-.YYYY.-

image

no-docs

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@md-umair-21 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 44 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 46 minutes and 44 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 80098cfb-a4b9-4f0c-8f70-3b2071799efa

📥 Commits

Reviewing files that changed from the base of the PR and between d41f6c0 and b8bacbe.

📒 Files selected for processing (3)
  • healthcare/healthcare/doctype/birth_record/birth_record.json
  • healthcare/healthcare/doctype/birth_record/birth_record.py
  • healthcare/healthcare/doctype/birth_record/test_birth_record.py

Walkthrough

Adds two Healthcare DocTypes: "Birth Newborn Detail" (table/istable) with fields for newborn ID, gender, birth time, live_birth/stillbirth flags, weight/length/head circumference, APGAR scores, blood_group, NICU flag, congenital_anomalies, and remarks; and "Birth Record" (submittable, naming series) capturing mother, delivery details, and a child table of Birth Newborn Detail. Includes client script to clear/filter inpatient_record and patient_encounter by mother_patient, server-side validation for birth outcome and APGAR scores, a minimal Document class, and a test module stub.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main feature being added: a new Birth Record DocType with a supporting newborn child table for the Healthcare module.
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.
Description check ✅ Passed The PR description accurately describes the changes, including the new Birth Record DocType, Birth Newborn Detail child table, support for multiple births, and the naming series used.

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


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (3)
healthcare/healthcare/doctype/birth_record/birth_record.js (1)

4-8: Remove the commented-out scaffold boilerplate.

Lines 4–8 are the default Frappe-generated placeholder and now duplicated below. Drop them to keep the file clean.

♻️ Proposed cleanup
-// frappe.ui.form.on("Birth Record", {
-// 	refresh(frm) {
-
-// 	},
-// });
-frappe.ui.form.on('Birth Record', {
+frappe.ui.form.on("Birth Record", {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@healthcare/healthcare/doctype/birth_record/birth_record.js` around lines 4 -
8, Remove the commented-out Frappe scaffold block (the lines containing
frappe.ui.form.on("Birth Record", { refresh(frm) { }, });) so the file does not
contain the duplicated placeholder; simply delete that commented snippet to keep
birth_record.js clean.
healthcare/healthcare/doctype/birth_record/birth_record.py (1)

8-9: LGTM — standard DocType stub.

Consider adding server-side validation in a follow-up (e.g., enforce multiple_birth_type is set when is_multiple_birth is checked, and that the number of rows in newborn_details matches the multiple-birth type such as 2 for Twin / 3 for Triplet). Not blocking.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@healthcare/healthcare/doctype/birth_record/birth_record.py` around lines 8 -
9, Add server-side validation inside the BirthRecord DocType by implementing a
validate(self) method on class BirthRecord that checks: when
self.is_multiple_birth is truthy ensure self.multiple_birth_type is set, and
validate len(self.newborn_details or []) matches the expected count for the
selected multiple_birth_type (e.g., "Twin" -> 2, "Triplet" -> 3). Use
frappe.throw or frappe.ValidationError with clear messages when checks fail so
the form cannot be saved; reference the class BirthRecord, method
validate(self), fields is_multiple_birth, multiple_birth_type, and
newborn_details when making the changes.
healthcare/healthcare/doctype/birth_record/birth_record.json (1)

160-165: Align fieldname reference_practitioner with module naming convention.

All other Healthcare DocTypes use practitioner as the fieldname for the linked Healthcare Practitioner. The reference_practitioner fieldname in this form is inconsistent with the established pattern across the module (patient_appointment, patient_encounter, lab_test, medication_request, clinical_procedure, clinical_note, diagnostic_report, and others all use practitioner). Rename to maintain consistency and avoid breaking fetch/filter conventions used elsewhere.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@healthcare/healthcare/doctype/birth_record/birth_record.json` around lines
160 - 165, The birth_record JSON defines a Link field named
reference_practitioner which should be renamed to practitioner to match the
module convention; update the "fieldname" value from reference_practitioner to
practitioner in the Birth Record doctype (birth_record.json) and then
search-and-replace all references to reference_practitioner across the codebase
(forms, hooks, controllers, reports, filters, fetch mappings, test fixtures, and
any server-side code) so they point to practitioner instead, and add a small
data migration or patch to move existing values from reference_practitioner to
practitioner if records exist.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@healthcare/healthcare/doctype/birth_newborn_detail/birth_newborn_detail.json`:
- Around line 69-86: Add range validation for the APGAR integer fields
(apgar_1_min, apgar_5_min, apgar_10_min) inside the
BirthNewbornDetail.validate() method: for each of these fields, check that the
value is not null and is an integer between 0 and 10 inclusive, and if not,
raise a validation error with a clear message identifying the offending field
and value; update BirthNewbornDetail.validate() to perform these checks before
save/submit so invalid APGAR values cannot be persisted.
- Around line 39-50: The live_birth and stillbirth Check fields are mutually
exclusive but current schema allows both or neither; update the code to enforce
exactly one choice by adding validation in BirthNewbornDetail.validate(): read
the boolean values of the live_birth and stillbirth fields and
raise/throw/return a validation error if both are true or both are false, with a
clear message; alternatively, you may replace the two Check fields with a single
Select field (e.g., birth_status with options "Live Birth" and "Stillbirth") in
birth_newborn_detail.json and migrate any code that reads live_birth/stillbirth
to use birth_status instead—pick one approach and implement the corresponding
changes in validate() and any consumers.
- Around line 51-68: The label unit format is inconsistent with the Vital Signs
doctype; update the field labels for birth_weight, birth_length, and
head_circumference to use the spelled-out unit pattern (e.g., change "Birth
Weight (kg)" to "Birth Weight (In Kilogram)" and change "Birth Length (cm)" and
"Head Circumference (cm)" to "Birth Length (In Centimeter)" and "Head
Circumference (In Centimeter)") so the labels follow the Vital Signs naming
convention while preserving the actual units stored.

In `@healthcare/healthcare/doctype/birth_record/birth_record.js`:
- Around line 1-37: The file has lint/format failures (trailing whitespace,
quote style and indentation) causing pre-commit errors; run the project's
pre-commit hooks locally (pre-commit run --all-files) and fix the issues in this
module by removing trailing whitespace (e.g., at the blank/comment lines around
the top of the file), normalizing string quotes and indentation to match project
style, and ensuring functions like mother_patient, onload, and calls to
frm.set_value and frm.set_query follow the repo formatter rules before
committing the result.

In `@healthcare/healthcare/doctype/birth_record/birth_record.json`:
- Around line 1-223: The JSON file (Birth Record doctype) has
trailing-whitespace and Prettier formatting issues; run pre-commit to normalize
and reformat this file (e.g., run `pre-commit run --all-files`) then commit the
changes — ensure the JSON for fields like "naming_series", "birth_facility", and
"newborn_details" is properly normalized (no trailing spaces, consistent
indentation/quoting) so the linter/Prettier checks pass.
- Around line 148-151: The field definition uses fieldname "birth_order_notes"
but label "Delivery Notes" — choose one intent and make them consistent: either
rename the fieldname to "delivery_notes" (and update all references/usages) if
the intent is delivery notes, or change the label to "Birth Order Notes" if the
intent is birth-order specific; also update the form's field_order array and any
report/doctype references, API fetches, or code that reads "birth_order_notes"
to match the new name.
- Around line 203-217: The birth_record.json permissions only grant access to
"System Manager", blocking clinical users; update the "permissions" array in
birth_record.json to add entries for clinical roles used by related DocTypes
(e.g., "Healthcare Administrator", "Physician", "Nursing User" and any other
relevant roles like "Patient" or "Reception User") with the appropriate flags
(read, write, create, submit, print, export, email, share, report, delete)
matching the pattern used in Inpatient Record and Patient Encounter; ensure each
new permission object mirrors the existing permission structure and includes the
same permission bits as the System Manager entry so clinical users can access
and manage birth records.

In `@healthcare/healthcare/doctype/birth_record/test_birth_record.py`:
- Around line 1-22: The file fails ruff-format due to whitespace/blank-line
issues; run the formatter (e.g., pre-commit run --all-files or ruff format) and
commit the formatted file so CI passes, ensuring the module-level spacing around
the import and the constants EXTRA_TEST_RECORD_DEPENDENCIES and
IGNORE_TEST_RECORD_DEPENDENCIES and the IntegrationTestBirthRecord class follow
the project's ruff/PEP8 rules (remove the extra blank line and normalize
surrounding whitespace).

---

Nitpick comments:
In `@healthcare/healthcare/doctype/birth_record/birth_record.js`:
- Around line 4-8: Remove the commented-out Frappe scaffold block (the lines
containing frappe.ui.form.on("Birth Record", { refresh(frm) { }, });) so the
file does not contain the duplicated placeholder; simply delete that commented
snippet to keep birth_record.js clean.

In `@healthcare/healthcare/doctype/birth_record/birth_record.json`:
- Around line 160-165: The birth_record JSON defines a Link field named
reference_practitioner which should be renamed to practitioner to match the
module convention; update the "fieldname" value from reference_practitioner to
practitioner in the Birth Record doctype (birth_record.json) and then
search-and-replace all references to reference_practitioner across the codebase
(forms, hooks, controllers, reports, filters, fetch mappings, test fixtures, and
any server-side code) so they point to practitioner instead, and add a small
data migration or patch to move existing values from reference_practitioner to
practitioner if records exist.

In `@healthcare/healthcare/doctype/birth_record/birth_record.py`:
- Around line 8-9: Add server-side validation inside the BirthRecord DocType by
implementing a validate(self) method on class BirthRecord that checks: when
self.is_multiple_birth is truthy ensure self.multiple_birth_type is set, and
validate len(self.newborn_details or []) matches the expected count for the
selected multiple_birth_type (e.g., "Twin" -> 2, "Triplet" -> 3). Use
frappe.throw or frappe.ValidationError with clear messages when checks fail so
the form cannot be saved; reference the class BirthRecord, method
validate(self), fields is_multiple_birth, multiple_birth_type, and
newborn_details when making the changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f60521d7-f266-4eea-9476-42a9072b9851

📥 Commits

Reviewing files that changed from the base of the PR and between f868b85 and 7ab04bc.

📒 Files selected for processing (8)
  • healthcare/healthcare/doctype/birth_newborn_detail/__init__.py
  • healthcare/healthcare/doctype/birth_newborn_detail/birth_newborn_detail.json
  • healthcare/healthcare/doctype/birth_newborn_detail/birth_newborn_detail.py
  • healthcare/healthcare/doctype/birth_record/__init__.py
  • healthcare/healthcare/doctype/birth_record/birth_record.js
  • healthcare/healthcare/doctype/birth_record/birth_record.json
  • healthcare/healthcare/doctype/birth_record/birth_record.py
  • healthcare/healthcare/doctype/birth_record/test_birth_record.py

Comment thread healthcare/healthcare/doctype/birth_record/birth_record.js Outdated
Comment thread healthcare/healthcare/doctype/birth_record/birth_record.json
Comment thread healthcare/healthcare/doctype/birth_record/birth_record.json Outdated
Comment thread healthcare/healthcare/doctype/birth_record/birth_record.json
Comment thread healthcare/healthcare/doctype/birth_record/test_birth_record.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
healthcare/healthcare/doctype/birth_record/birth_record.json (1)

8-34: Place naming_series before amended_from in field_order.

Frappe's convention is to show naming_series at the very top of the form, with amended_from either hidden or placed right after it (it is already read_only/print_hide). Currently amended_from precedes naming_series, which renders the "Amended From" field at the top of the unlabeled leading section instead of the naming dropdown shown in the PR screenshot.

♻️ Suggested reorder
  "field_order": [
   "section_break_liij",
-  "amended_from",
   "naming_series",
+  "amended_from",
   "mother_details",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@healthcare/healthcare/doctype/birth_record/birth_record.json` around lines 8
- 34, Reorder the field_order array in the Birth Record doctype so
"naming_series" appears before "amended_from": open the birth_record.json's
"field_order" array and move the "naming_series" entry to be immediately before
"amended_from" (ensure the keys "naming_series" and "amended_from" remain
unchanged and the array remains valid JSON); this will surface the naming
dropdown at the top of the form per Frappe conventions.
healthcare/healthcare/doctype/birth_record/birth_record.py (1)

22-37: APGAR validation can be simplified — the fields are already Int.

apgar_1_min, apgar_5_min, and apgar_10_min are declared as Int in birth_newborn_detail.json, so Frappe parses and stores them as Python int before validate() runs. The isinstance(value, bool) check, the string round-trip via str(value).strip() != str(int_value), and the int(value) coercion are unreachable in practice and make the validator harder to read. A simple range check with isinstance(value, int) is sufficient.

♻️ Possible simplification
 	def validate_apgar_scores(self, newborn_detail):
 		for fieldname in ("apgar_1_min", "apgar_5_min", "apgar_10_min"):
 			value = newborn_detail.get(fieldname)
 			if value is None:
 				continue
-
-			if isinstance(value, bool):
-				frappe.throw(f"Invalid {fieldname}: {value}. Expected an integer between 0 and 10.")
-
-			try:
-				int_value = int(value)
-			except (TypeError, ValueError):
-				frappe.throw(f"Invalid {fieldname}: {value}. Expected an integer between 0 and 10.")
-
-			if str(value).strip() != str(int_value) or not 0 <= int_value <= 10:
-				frappe.throw(f"Invalid {fieldname}: {value}. Expected an integer between 0 and 10.")
+			if not (isinstance(value, int) and not isinstance(value, bool) and 0 <= value <= 10):
+				frappe.throw(
+					_("Row #{0}: {1} must be an integer between 0 and 10.").format(
+						newborn_detail.idx, _(newborn_detail.meta.get_label(fieldname))
+					)
+				)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@healthcare/healthcare/doctype/birth_record/birth_record.py` around lines 22 -
37, The validate_apgar_scores method currently does unnecessary type coercion
and boolean checks for apgar fields; update validate_apgar_scores to, for each
field in ("apgar_1_min","apgar_5_min","apgar_10_min"), skip when
newborn_detail.get(fieldname) is None, assert the value is an int via
isinstance(value, int), and then ensure 0 <= value <= 10, calling frappe.throw
with the existing message if either check fails; remove the isinstance(...,
bool) branch, the int(value) conversion, and the string round-trip comparison to
simplify the validator.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@healthcare/healthcare/doctype/birth_record/birth_record.json`:
- Around line 149-155: The fetch_from on the Link field medical_department is
pointing at a non-existent parent field reference_practitioner; update the
fetch_from value to practitioner.department so Frappe can resolve and
auto-populate medical_department when the practitioner field is selected—locate
the medical_department field in birth_record.json and replace
"reference_practitioner.department" with "practitioner.department", then save
and validate the DocType in the app.
- Around line 213-224: The Healthcare Administrator permission block for the
Birth Record doctype is missing cancel permission while the doctype is
submittable (is_submittable: 1); update the Birth Record permissions JSON entry
for role "Healthcare Administrator" to include "cancel": 1 if the workflow
requires allowing this role to cancel submitted records, and do not add "amend"
(since "amend" is not used in this doctype's permission schema); ensure you only
modify the permission object that contains keys like "create", "submit",
"write", etc., and leave other roles/permissions unchanged.

In `@healthcare/healthcare/doctype/birth_record/birth_record.py`:
- Line 20: The validation error messages in birth_record.py are currently bare
strings; update each frappe.throw call to wrap the message with frappe._() for
translation and append the offending child row index (use newborn_detail.idx) to
the message so it reads like: frappe.throw(frappe._("... (Row
{0})").format(newborn_detail.idx)) or equivalent; update all four occurrences
(the throws at the Live/Stillbirth check and the three other validation throws)
to use frappe._() and include newborn_detail.idx for clear row context.

---

Nitpick comments:
In `@healthcare/healthcare/doctype/birth_record/birth_record.json`:
- Around line 8-34: Reorder the field_order array in the Birth Record doctype so
"naming_series" appears before "amended_from": open the birth_record.json's
"field_order" array and move the "naming_series" entry to be immediately before
"amended_from" (ensure the keys "naming_series" and "amended_from" remain
unchanged and the array remains valid JSON); this will surface the naming
dropdown at the top of the form per Frappe conventions.

In `@healthcare/healthcare/doctype/birth_record/birth_record.py`:
- Around line 22-37: The validate_apgar_scores method currently does unnecessary
type coercion and boolean checks for apgar fields; update validate_apgar_scores
to, for each field in ("apgar_1_min","apgar_5_min","apgar_10_min"), skip when
newborn_detail.get(fieldname) is None, assert the value is an int via
isinstance(value, int), and then ensure 0 <= value <= 10, calling frappe.throw
with the existing message if either check fails; remove the isinstance(...,
bool) branch, the int(value) conversion, and the string round-trip comparison to
simplify the validator.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 88f4a0e7-002d-494c-a13b-3d0169cdbcba

📥 Commits

Reviewing files that changed from the base of the PR and between 7ab04bc and d41f6c0.

📒 Files selected for processing (5)
  • healthcare/healthcare/doctype/birth_newborn_detail/birth_newborn_detail.json
  • healthcare/healthcare/doctype/birth_record/birth_record.js
  • healthcare/healthcare/doctype/birth_record/birth_record.json
  • healthcare/healthcare/doctype/birth_record/birth_record.py
  • healthcare/healthcare/doctype/birth_record/test_birth_record.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • healthcare/healthcare/doctype/birth_record/birth_record.js
  • healthcare/healthcare/doctype/birth_record/test_birth_record.py
  • healthcare/healthcare/doctype/birth_newborn_detail/birth_newborn_detail.json

Comment thread healthcare/healthcare/doctype/birth_record/birth_record.json
Comment thread healthcare/healthcare/doctype/birth_record/birth_record.json Outdated
Comment thread healthcare/healthcare/doctype/birth_record/birth_record.py Outdated
@github-actions

Copy link
Copy Markdown

This PR has had no activity for 30 days and is now marked stale. It will be closed in 14 days unless there is new activity.

@github-actions github-actions Bot added the stale label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant