Skip to content

Tighten birth and conception entry and drop legacy nbri_ehr tables - #20

Merged
labkey-martyp merged 19 commits into
release26.7-SNAPSHOTfrom
26.7_fb_ehr_birth_conception_cleanup
Aug 23, 2026
Merged

Tighten birth and conception entry and drop legacy nbri_ehr tables#20
labkey-martyp merged 19 commits into
release26.7-SNAPSHOTfrom
26.7_fb_ehr_birth_conception_cleanup

Conversation

@labkey-martyp

@labkey-martyp labkey-martyp commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Rationale

Make the forms that open and close an animal's record agree on who owns each piece of its demographics, and finish the birth and conception cleanup this branch started with. The birth, arrival and death forms each wrote the animal's birth and death dates for themselves, so the three could disagree, and the death form additionally hand-set a status that the shared EHR recalculation already owns. Separately, the nbri_ehr schema still carried tables inherited from the legacy system that nothing reads, and several data entry forms exposed fields that are either derived or closed automatically and so were never meant to be typed by hand.

Related Pull Requests

None.

Changes

  • Derive an animal's birth and death dates from its birth and death records, and leave calculated status to the shared EHR recalculation. Adds a drift query for reconciling values the old paths left stale.
  • Tighten birth and conception entry: conception date is now required, term date and birth condition are gone, and the birth fields the Start with Conception window fills can no longer be edited away from the conception record they came from.
  • Drop the legacy tables from the nbri_ehr schema along with the queries, custom views, lookups and referencing columns that existed only to serve them. Conception is the only table left in the schema.
  • Let an animal be put in a group as it arrives or is born, rather than through a separate form, and give the EHR roles access to the group membership data so the assignment can be closed when the animal dies.
  • Block recording a death against an animal whose demographics record is still in data entry, since that would publish unreviewed arrival or birth data. Admins can override.
  • Record a social code once per animal on the birth and arrival forms, and store it on demographics so it is available for animal selection and search.
  • Hide the end dates on the project and group assignment forms, which are always closed automatically rather than entered by hand, and rename the Bulk Deaths form to Deaths so it follows the same availability rules as every other data entry form.
  • Treat animals as cagemates when they share a location, which covers a group pen and a cage alike.
  • Stop reloading flag values from the production lookups manifest, so values configured at a site are no longer overwritten.

Conception is the only table left in the nbri_ehr schema — the rest were carried over from the legacy system and nothing reads them, so their queries, lookups and referencing columns go too. On the entry side, birth condition and conception term date are gone, conception date is now required, and the fields the Start with Conception window populates are read-only.
The birth, arrival and death forms each wrote demographics.birth and demographics.death independently, and the death form also hand-set calculated_status. One trigger helper now derives both dates from the saved event records, and status is left to the shared recalc that owns the death/departure precedence. Adds a drift query for reconciling values the old paths left stale.
Adds a test for deleting a death record, which has to hand the status back to the shared recalc rather than assume the animal is alive, and asserts the birth and death dates reach demographics on the arrival, birth and death forms. The birth and deaths sample data disagreed with demographics on nine rows and now matches, leaving only the animals that legitimately have no birth record.
The code is entered once per animal, on the birth and arrival forms, and stored on demographics so it is available for animal selection and search. A new ehr_lookups.social_code lookup supplies the five codes.
A new project assignment already closes the animal's open one, so the end date is never entered by hand. The arrival and birth key is lowercased to match the actual field name, which it did not match before.
Drops Bulk from the class, form name and label. Also removes the admin-only isAvailable check and the canInsert override, so the form follows the same availability rules as the other data entry forms.
A new group membership already closes the animal's open one through datasetsToCloseOnNewEntry, so the end date is never entered by hand.

@labkey-bpatel labkey-bpatel 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.

Approving, but please see my comment below plus other Claude medium to low findings.

*/
public List<Map<String, Object>> computeDemographicsSync(List<String> ids)
{
if (ids == null || ids.isEmpty())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use ids.size() == 0, isEmpty() might not be reliable as per Claude.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

An animal can now be put in a group as it arrives or is born rather than through a separate form. The section allows any Id because neither form's animal has a demographics record yet, and the arrival and birth tests cover it.
EHR metadata keys are merged case-sensitively but applied case-insensitively, so performedBy and qcstate replaced the shared performedby and QCState config rather than merging with it. That dropped the performed-by default of the current user, which made Group Assignments fail the submit-final check, along with the QC state initial value and editor config.
A demographics record still in data entry is provisional, so recording a death against it would publish unreviewed arrival or birth data. Admins can override.
Re-checking it on update let a later regression of the demographics state trap a death record that was already in the necropsy workflow.
A NativeArray inherits an isEmpty() that is always true, so the early-return guard skipped every sync.
Hard-coded indices broke whenever the arrival metadata changed which columns the insert view shows. Also reorders the demographics block to species, gender, birth, dam, sire.
The dataset was configured on two layers not to collect performedBy, but the shared dataset trigger rejects any record saved as Completed without one, so the Group Assignments section failed the Arrival and Birth forms. It stays hidden; the value is now seeded from the current user.
The study uses per-dataset security, so a dataset with no role assignments is readable only by administrators. Closing an animal's group memberships on death therefore failed for every other user, and took the whole save down with it.
Housing has no room of its own: room is derived from the location id and is read-only, so the room these tests posted was discarded and the penned animals landed with no location at all.
The room fallback could never fire: room is derived from the location id, so it is null exactly when the id is, and the branch required both. Dropping it leaves the equality that was already deciding every case.

@labkey-martyp labkey-martyp left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One flaky test failure not related to this PR.

@labkey-martyp
labkey-martyp merged commit 37afdd0 into release26.7-SNAPSHOT Aug 23, 2026
2 of 3 checks passed
@labkey-martyp
labkey-martyp deleted the 26.7_fb_ehr_birth_conception_cleanup branch August 23, 2026 22:58
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