getFieldKeys(TableInfo ti)
keys.add(10, FieldKey.fromString("Id/demographics/gender"));
keys.add(12, FieldKey.fromString("Id/demographics/geographic_origin"));
+ // the social code sits beside Initial Location, whose index the inserts above have shifted, so find it
+ keys.add(keys.indexOf(FieldKey.fromString("cage")) + 1, FieldKey.fromString("Id/demographics/socialCode"));
+
return keys;
}
}
diff --git a/nbri_ehr/src/org/labkey/nbri_ehr/dataentry/section/NBRIBirthFormSection.java b/nbri_ehr/src/org/labkey/nbri_ehr/dataentry/section/NBRIBirthFormSection.java
index ddecd53..326b540 100644
--- a/nbri_ehr/src/org/labkey/nbri_ehr/dataentry/section/NBRIBirthFormSection.java
+++ b/nbri_ehr/src/org/labkey/nbri_ehr/dataentry/section/NBRIBirthFormSection.java
@@ -37,8 +37,8 @@ public class NBRIBirthFormSection extends NewAnimalFormSection
FieldKey.fromString("Id/demographics/dam"),
FieldKey.fromString("Id/demographics/sire"),
FieldKey.fromString("cage"),
+ FieldKey.fromString("Id/demographics/socialCode"),
FieldKey.fromString("type"),
- FieldKey.fromString("cond"),
FieldKey.fromString("breedingType"),
FieldKey.fromString("remark"),
FieldKey.fromString("performedby")
diff --git a/nbri_ehr/src/org/labkey/nbri_ehr/query/NBRI_EHRTriggerHelper.java b/nbri_ehr/src/org/labkey/nbri_ehr/query/NBRI_EHRTriggerHelper.java
index 662ab54..893c53a 100644
--- a/nbri_ehr/src/org/labkey/nbri_ehr/query/NBRI_EHRTriggerHelper.java
+++ b/nbri_ehr/src/org/labkey/nbri_ehr/query/NBRI_EHRTriggerHelper.java
@@ -323,6 +323,103 @@ public boolean deathExists(String id)
return false;
}
+ /**
+ * Derives the denormalized birth/death values on study.demographics from the birth and deaths event records, which
+ * are authoritative, and returns only the animals whose stored values disagree. The result is intended to be handed
+ * straight to the shared trigger helper's updateDemographicsRecord(), so that lsid resolution and the demographics
+ * cache recache stay in the single place that already handles them.
+ *
+ * Only public (Completed) event records count, so a record still in data entry never overwrites a saved value.
+ *
+ * calculated_status is deliberately absent from the result. It belongs to the shared status recalc, which owns the
+ * death/departure/re-arrival precedence.
+ *
+ * Every lookup is set-based - one query per event dataset for the whole id list, not one per animal - because a
+ * bulk save can pass hundreds of ids and per-animal SQL in a trigger exhausts the script's wall-clock budget.
+ *
+ * @param ids animals touched by the current save
+ * @return rows ready for updateDemographicsRecord(); empty when nothing has drifted
+ */
+ public List