feat: add Death Record doctype with patient and death details fields#974
feat: add Death Record doctype with patient and death details fields#974md-umair-21 wants to merge 2 commits intoearthians:developfrom
Conversation
WalkthroughThis pull request introduces a new "Death Record" DocType to the Healthcare module. The change includes a JSON schema definition with fields for patient details, death details (date, time, place, facility, type, manner), cause of death conditions, and informant information. A Python class implementation provides the server-side behavior, while client-side form logic filters related records by patient and clears dependent fields on patient selection changes. Integration test infrastructure is also added. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
healthcare/healthcare/doctype/death_record/death_record.json (1)
196-228: Addtitle_fieldandsearch_fieldsfor usability.Without a
title_field, list/link views display only the autoname (e.g.HLC-DR-2026-00001), which is not human-identifiable. Settingtitle_fieldtopatient_name(already fetched read-only frompatient.patient_name) plussearch_fieldscoveringpatient,patient_name, anddate_of_deathwill make lookups and list browsing far more useful.✨ Suggested additions
"sort_field": "creation", "sort_order": "DESC", + "title_field": "patient_name", + "search_fields": "patient,patient_name,date_of_death", "states": []🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@healthcare/healthcare/doctype/death_record/death_record.json` around lines 196 - 228, Add a title_field and search_fields to the Death Record doctype JSON so list/link views show a human-readable label and enable lookups: set "title_field" to "patient_name" (the existing fetched read-only field) and add a "search_fields" array containing "patient", "patient_name", and "date_of_death"; update the death_record doctype JSON (Death Record) to include these keys at the top-level alongside existing metadata.healthcare/healthcare/doctype/death_record/test_death_record.py (1)
1-20: Empty integration test scaffold — acceptable as a starting point.Given this DocType touches legally/clinically significant data, consider adding at least a smoke test covering: creation with required fields,
patient_name/medical_departmentfetch_from population, and submit/amend flow. Can be deferred to a follow-up.Want me to draft a minimal
IntegrationTestDeathRecordcovering create + submit + fetch_from assertions?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@healthcare/healthcare/doctype/death_record/test_death_record.py` around lines 1 - 20, Add a minimal integration test inside IntegrationTestDeathRecord that creates a DeathRecord with required fields, ensures any linked fixtures are listed in EXTRA_TEST_RECORD_DEPENDENCIES, saves/inserts the doc, asserts that fetch_from-populated fields like patient_name and medical_department are populated after save, then exercises submit/amend flow by calling the document submit and amend/cancel methods and asserting docstatus transitions and persisted field values; implement this as a single test method (e.g., test_create_submit_and_fetch_from) using the DeathRecord doctype class and standard IntegrationTestCase helpers.
🤖 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/death_record/death_record.js`:
- Around line 16-34: The onload callback's link filters for inpatient_record and
patient_encounter use frm.doc.patient lazily and can become {patient:
undefined}; update the set_query callbacks in the onload function so they use
frm.doc.patient || "" to force empty results until a patient is chosen, add a
status filter for inpatient_record limiting to ["in", ["Admitted", "Discharge
Scheduled", "Discharged"]], and add docstatus: 1 for patient_encounter so only
submitted encounters are returned; change the two frm.set_query handlers (the
one for "inpatient_record" and the one for "patient_encounter") to include these
guarded filters.
In `@healthcare/healthcare/doctype/death_record/death_record.json`:
- Line 3: The Death Record doctype currently allows post-creation renames via
the "allow_rename" flag; change this to disallow renaming by setting
allow_rename to 0 (or removing the flag) in the death_record.json so identifiers
remain immutable and consistent with the naming_series "HLC-DR-.YYYY.-" and
audit requirements; update any tests or fixtures that assume renaming is allowed
and ensure migration/data scripts handle existing documents if needed.
- Around line 18-27: The column break is in the wrong place causing mis-paired
fields; move the "column_break_unnq" entry in death_record.json to immediately
before "medical_department" so the order becomes ... "practitioner",
"column_break_unnq", "medical_department", ... which will render the Death
Details as the PR screenshot intends (Date of Death │ Death Facility, Time of
Death │ Death Type, Place of Death │ Manner of Death, Healthcare Practitioner │
Medical Department).
- Around line 206-223: Update the Death Record DocType permissions block in
death_record.json to include healthcare roles used by peer DocTypes: add entries
for "Physician" with permissions
amend,cancel,create,delete,email,export,print,read,report,share,submit,write;
"Healthcare Administrator" with permissions
amend,cancel,create,delete,email,export,print,read,report,share,submit,write;
and "Nursing User" with permissions
create,delete,email,export,print,read,report,share,write; keep the existing
System Manager entry unchanged and ensure each new entry follows the same
permissions object shape as the current permission items so the DocType
permission array is consistent.
---
Nitpick comments:
In `@healthcare/healthcare/doctype/death_record/death_record.json`:
- Around line 196-228: Add a title_field and search_fields to the Death Record
doctype JSON so list/link views show a human-readable label and enable lookups:
set "title_field" to "patient_name" (the existing fetched read-only field) and
add a "search_fields" array containing "patient", "patient_name", and
"date_of_death"; update the death_record doctype JSON (Death Record) to include
these keys at the top-level alongside existing metadata.
In `@healthcare/healthcare/doctype/death_record/test_death_record.py`:
- Around line 1-20: Add a minimal integration test inside
IntegrationTestDeathRecord that creates a DeathRecord with required fields,
ensures any linked fixtures are listed in EXTRA_TEST_RECORD_DEPENDENCIES,
saves/inserts the doc, asserts that fetch_from-populated fields like
patient_name and medical_department are populated after save, then exercises
submit/amend flow by calling the document submit and amend/cancel methods and
asserting docstatus transitions and persisted field values; implement this as a
single test method (e.g., test_create_submit_and_fetch_from) using the
DeathRecord doctype class and standard IntegrationTestCase helpers.
🪄 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: 27d5cd9e-1eff-4c1a-a405-c87904689dac
📒 Files selected for processing (5)
healthcare/healthcare/doctype/death_record/__init__.pyhealthcare/healthcare/doctype/death_record/death_record.jshealthcare/healthcare/doctype/death_record/death_record.jsonhealthcare/healthcare/doctype/death_record/death_record.pyhealthcare/healthcare/doctype/death_record/test_death_record.py
| onload(frm) { | ||
| // Filter Inpatient Record | ||
| frm.set_query("inpatient_record", function () { | ||
| return { | ||
| filters: { | ||
| patient: frm.doc.patient, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| // Filter Patient Encounter | ||
| frm.set_query("patient_encounter", function () { | ||
| return { | ||
| filters: { | ||
| patient: frm.doc.patient, | ||
| }, | ||
| }; | ||
| }); | ||
| }, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
fd -a 'inpatient_record.json' | xargs -I{} sh -c 'echo "== {} =="; cat "{}"' | rg -n -A2 '"fieldname": "status"'Repository: earthians/marley
Length of output: 146
🏁 Script executed:
fd -a 'inpatient_record.json' -x cat {} | jq '.fields[] | select(.fieldname == "status")'Repository: earthians/marley
Length of output: 299
🏁 Script executed:
fd -a 'patient_encounter.json' -x cat {} | jq '.fields[] | select(.fieldname == "docstatus")'Repository: earthians/marley
Length of output: 42
🏁 Script executed:
fd -a 'patient_encounter.json' -x cat {}Repository: earthians/marley
Length of output: 11903
🏁 Script executed:
rg -A 5 '"fieldname": "docstatus"' --type jsonRepository: earthians/marley
Length of output: 42
🏁 Script executed:
rg -A 10 'set_query.*function' --type js | head -50Repository: earthians/marley
Length of output: 3021
🌐 Web query:
Frappe set_query undefined filter behavior empty dropdown
💡 Result:
In Frappe Framework, when using frm.set_query to filter options in a Link field dropdown, if the filters result in no matching documents, the dropdown will appear empty (no options shown). This is the expected behavior when the query returns zero results. Common causes for an empty dropdown include: - Filters are too restrictive: No documents match the specified criteria (e.g., filters={"status": "some_status"} where no records have that status). - Undefined or null/empty filter values: If the filter function returns {filters: {field: undefined}} or uses empty lists/IN empty arrays, the backend query may return no results. Recent fixes (e.g., for empty IN lists) ensure empty lists don't match everything but may result in zero rows. - Permissions: User lacks read access to matching documents, causing zero results. - Conditional logic errors: In dynamic set_query (e.g., based on another field), if the condition leads to overly strict filters or no filters applied correctly. To handle cases where you want options only when a condition is met (e.g., parent field set), use conditional returns: frappe.ui.form.on("YourDoctype", { parent_field: function(frm) { if (frm.doc.parent_field) { frm.set_query("link_field", {filters: {"parent": frm.doc.parent_field}}); } else { // Option 1: Return empty filters to show all (default behavior if no set_query) frm.set_query("link_field", {filters: {}}); // Or Option 2: Don't call set_query, falls back to unfiltered // Or Option 3: Custom query that always returns something } } }); If filters are undefined, explicitly return {filters: {}} or validate values before applying. Check browser console for JS errors and server logs for query errors. Forum threads report similar issues resolved by verifying data exists matching filters and correct syntax per official docs.
Citations:
- 1: https://frappeframework.com/docs/user/en/guides/app-development/overriding-link-query-by-custom-script
- 2: https://docs.frappe.io/erpnext/user/manual/en/filter-options-in-select-field
- 3: Change the link fields filter dynamically via script (without the need of a manual full page refresh) frappe/erpnext#40656
- 4: https://finbyz.tech/erpnext/wiki/contact-query-filter
- 5: https://discuss.frappe.io/t/issue-with-using-set-query-to-filter-a-link-field/135232
- 6: https://discuss.frappe.io/t/set-query-not-working-for-link-field/53135
- 7: "IN" filter in frappe.get_all feels unintuitive. This may lead to huge bugs downstream frappe/frappe#18840
🏁 Script executed:
rg -B 5 -A 10 'if.*frm.doc\.' --type js | grep -A 10 'set_query' | head -40Repository: earthians/marley
Length of output: 3086
🏁 Script executed:
rg 'set_query.*function.*{' -A 15 --type js | grep -B 5 -A 10 'if'Repository: earthians/marley
Length of output: 168
🏁 Script executed:
cat healthcare/healthcare/doctype/therapy_session/therapy_session.js | sed -n '/frm.set_query.*code_value/,/^[[:space:]]*}\);/p'Repository: earthians/marley
Length of output: 110
🏁 Script executed:
grep -A 20 'set_query.*code_value' healthcare/healthcare/doctype/therapy_session/therapy_session.jsRepository: earthians/marley
Length of output: 637
Guard the link filters when patient is unset.
frm.doc.patient is captured lazily inside the set_query callbacks. If the user opens the lookup before selecting a patient, the filter becomes { patient: undefined }, which Frappe treats as no filter and exposes every record across all patients—making it easy to pick the wrong record.
Use frm.doc.patient || "" to force an empty result set until a patient is chosen. Additionally, add status constraints for Inpatient Record (["in", ["Admitted", "Discharge Scheduled", "Discharged"]]) and docstatus: 1 for Patient Encounter to show only relevant records.
♻️ Suggested tightening of filters
onload(frm) {
// Filter Inpatient Record
frm.set_query("inpatient_record", function () {
return {
filters: {
- patient: frm.doc.patient,
+ patient: frm.doc.patient || "",
+ status: ["in", ["Admitted", "Discharge Scheduled", "Discharged"]],
},
};
});
// Filter Patient Encounter
frm.set_query("patient_encounter", function () {
return {
filters: {
- patient: frm.doc.patient,
+ patient: frm.doc.patient || "",
+ docstatus: 1,
},
};
});
},🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@healthcare/healthcare/doctype/death_record/death_record.js` around lines 16 -
34, The onload callback's link filters for inpatient_record and
patient_encounter use frm.doc.patient lazily and can become {patient:
undefined}; update the set_query callbacks in the onload function so they use
frm.doc.patient || "" to force empty results until a patient is chosen, add a
status filter for inpatient_record limiting to ["in", ["Admitted", "Discharge
Scheduled", "Discharged"]], and add docstatus: 1 for patient_encounter so only
submitted encounters are returned; change the two frm.set_query handlers (the
one for "inpatient_record" and the one for "patient_encounter") to include these
guarded filters.
| @@ -0,0 +1,229 @@ | |||
| { | |||
| "actions": [], | |||
| "allow_rename": 1, | |||
There was a problem hiding this comment.
Disable allow_rename for an audit-sensitive record.
A Death Record is a legal/clinical artifact; allowing users to rename the document identifier post-creation undermines auditability and breaks external references (reports, linked documents). Since naming is already controlled by naming_series (HLC-DR-.YYYY.-), renames shouldn't be permitted.
🔒 Suggested change
- "allow_rename": 1,
+ "allow_rename": 0,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "allow_rename": 1, | |
| "allow_rename": 0, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@healthcare/healthcare/doctype/death_record/death_record.json` at line 3, The
Death Record doctype currently allows post-creation renames via the
"allow_rename" flag; change this to disallow renaming by setting allow_rename to
0 (or removing the flag) in the death_record.json so identifiers remain
immutable and consistent with the naming_series "HLC-DR-.YYYY.-" and audit
requirements; update any tests or fixtures that assume renaming is allowed and
ensure migration/data scripts handle existing documents if needed.
| "section_death_details", | ||
| "date_of_death", | ||
| "time_of_death", | ||
| "place_of_death", | ||
| "practitioner", | ||
| "medical_department", | ||
| "column_break_unnq", | ||
| "death_facility", | ||
| "death_type", | ||
| "manner_of_death", |
There was a problem hiding this comment.
Column break is misplaced — layout won't match the PR screenshot.
With column_break_unnq positioned after medical_department, the Death Details section renders with 5 fields on the left (date_of_death, time_of_death, place_of_death, practitioner, medical_department) and 3 on the right (death_facility, death_type, manner_of_death). Per the PR description screenshot, the intended pairing is:
- Date of Death │ Death Facility
- Time of Death │ Death Type
- Place of Death │ Manner of Death
- Healthcare Practitioner │ Medical Department
Move the column break to immediately before medical_department so medical_department lands in the right column and pairs with practitioner.
🪄 Proposed field_order fix
"section_death_details",
"date_of_death",
"time_of_death",
"place_of_death",
"practitioner",
- "medical_department",
"column_break_unnq",
"death_facility",
"death_type",
"manner_of_death",
+ "medical_department",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "section_death_details", | |
| "date_of_death", | |
| "time_of_death", | |
| "place_of_death", | |
| "practitioner", | |
| "medical_department", | |
| "column_break_unnq", | |
| "death_facility", | |
| "death_type", | |
| "manner_of_death", | |
| "section_death_details", | |
| "date_of_death", | |
| "time_of_death", | |
| "place_of_death", | |
| "practitioner", | |
| "column_break_unnq", | |
| "death_facility", | |
| "death_type", | |
| "manner_of_death", | |
| "medical_department", |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@healthcare/healthcare/doctype/death_record/death_record.json` around lines 18
- 27, The column break is in the wrong place causing mis-paired fields; move the
"column_break_unnq" entry in death_record.json to immediately before
"medical_department" so the order becomes ... "practitioner",
"column_break_unnq", "medical_department", ... which will render the Death
Details as the PR screenshot intends (Date of Death │ Death Facility, Time of
Death │ Death Type, Place of Death │ Manner of Death, Healthcare Practitioner │
Medical Department).
| "permissions": [ | ||
| { | ||
| "amend": 1, | ||
| "cancel": 1, | ||
| "create": 1, | ||
| "delete": 1, | ||
| "email": 1, | ||
| "export": 1, | ||
| "print": 1, | ||
| "read": 1, | ||
| "report": 1, | ||
| "role": "System Manager", | ||
| "select": 1, | ||
| "share": 1, | ||
| "submit": 1, | ||
| "write": 1 | ||
| } | ||
| ], |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect permissions blocks on similar Healthcare doctypes
for f in $(fd -e json . healthcare/healthcare/doctype/inpatient_record healthcare/healthcare/doctype/patient_encounter healthcare/healthcare/doctype/clinical_procedure 2>/dev/null); do
echo "== $f =="
python - "$f" <<'PY'
import json, sys
d = json.load(open(sys.argv[1]))
for p in d.get("permissions", []):
print(p)
PY
doneRepository: earthians/marley
Length of output: 1676
Add healthcare-appropriate roles to death_record permissions.
Permissions currently restrict this DocType to System Manager only, but Death Records will be authored by clinical/registration staff. Peer DocTypes in this module (clinical_procedure, inpatient_record, patient_encounter) consistently grant roles such as Healthcare Administrator, Physician, and Nursing User. Add these roles with appropriately scoped permissions:
- Physician: amend, cancel, create, delete, email, export, print, read, report, share, submit, write
- Nursing User: create, delete, email, export, print, read, report, share, write
- Healthcare Administrator: amend, cancel, create, delete, email, export, print, read, report, share, submit, write
Without these roles, either sites must widen System Manager (security regression) or the feature is blocked for intended users.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@healthcare/healthcare/doctype/death_record/death_record.json` around lines
206 - 223, Update the Death Record DocType permissions block in
death_record.json to include healthcare roles used by peer DocTypes: add entries
for "Physician" with permissions
amend,cancel,create,delete,email,export,print,read,report,share,submit,write;
"Healthcare Administrator" with permissions
amend,cancel,create,delete,email,export,print,read,report,share,submit,write;
and "Nursing User" with permissions
create,delete,email,export,print,read,report,share,write; keep the existing
System Manager entry unchanged and ensure each new entry follows the same
permissions object shape as the current permission items so the DocType
permission array is consistent.
This PR adds the Death Record DocType in the Healthcare module.
no-docs