diff --git a/ehr/resources/queries/study/Demographics.js b/ehr/resources/queries/study/Demographics.js index eacb7dd51..38df4c5c3 100644 --- a/ehr/resources/queries/study/Demographics.js +++ b/ehr/resources/queries/study/Demographics.js @@ -14,11 +14,10 @@ function onInit(event, helper){ }); } -function onUpsert(helper, scriptErrors, row, oldRow){ +function onUpsert(helper, scriptErrors, row, oldRow) { //NOTE: this should be getting set by the birth, death, arrival & departure tables //ALSO: it should be rare to insert directly into this table. usually this record will be created by inserting into either birth or arrival if (!row.calculated_status && !helper.isETL()){ row.calculated_status = helper.getJavaHelper().getCalculatedStatusValue(row.Id); } - } \ No newline at end of file diff --git a/ehr/src/org/labkey/ehr/demographics/EHRDemographicsServiceImpl.java b/ehr/src/org/labkey/ehr/demographics/EHRDemographicsServiceImpl.java index e3550f613..c8cc042b3 100644 --- a/ehr/src/org/labkey/ehr/demographics/EHRDemographicsServiceImpl.java +++ b/ehr/src/org/labkey/ehr/demographics/EHRDemographicsServiceImpl.java @@ -233,7 +233,7 @@ else if (existing.getProps().isEmpty() && record.getProps().isEmpty()) _cache.put(key, record); } - private void recacheRecords(Container c, List ids) + public void recacheRecords(Container c, List ids) { for (String id : ids) { diff --git a/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java b/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java index df0605eb7..ea07f2515 100644 --- a/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java +++ b/ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java @@ -826,7 +826,11 @@ public void createDemographicsRecord(String id, Map props) throw if (errors.hasErrors()) throw errors; - EHRDemographicsServiceImpl.get().getAnimal(getContainer(), id); + // The normal (re)caching of demographics providers runs before the study module has done its bookkeeping and + // inserted a row into study.participant, which means that calculated lookup values like the animal's current + // age won't resolve until AFTER the call to insertRows() has completed. Thus, refresh the cache for this new + // animal an extra time. See ticket 44283. + EHRDemographicsServiceImpl.get().recacheRecords(getContainer(), Collections.singletonList(id)); } public void updateDemographicsRecord(List> updatedRows) throws QueryUpdateServiceException, SQLException, BatchValidationException, InvalidKeyException