From 7dbb0922c77595acac9dc2b332c849b89b8ba606 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Mon, 15 Nov 2021 18:34:06 -0800 Subject: [PATCH 1/4] Issue 44283: Age is not calculated for new animals on snapshot --- .../labkey/ehr/demographics/EHRDemographicsServiceImpl.java | 2 +- ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 From 5c7047575088f3ad5f386e72694a335a5ddde2e3 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Tue, 16 Nov 2021 08:43:53 -0800 Subject: [PATCH 2/4] Avoid double-refreshing the demographics cache when we add a new study.demographics row --- ehr/resources/queries/study/Demographics.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ehr/resources/queries/study/Demographics.js b/ehr/resources/queries/study/Demographics.js index eacb7dd51..b97164df5 100644 --- a/ehr/resources/queries/study/Demographics.js +++ b/ehr/resources/queries/study/Demographics.js @@ -20,5 +20,11 @@ function onUpsert(helper, scriptErrors, row, oldRow){ if (!row.calculated_status && !helper.isETL()){ row.calculated_status = helper.getJavaHelper().getCalculatedStatusValue(row.Id); } + if (!oldRow) { + // If we're doing inserts in demographics (where we don't have an old row), don't fire the normal notifications + // of changes to refresh the demographics cache, as we have to do a special clearing after study has done its + // bookkeeping. See ticket 44283 and the clearing in TriggerScriptHelper.createDemographicsRecord() + helper.getExtraContext().skipAnnounceChangedParticipants = true; + } } \ No newline at end of file From c2cfd25569213dbf57a26bd1b8a6f4b24e978a1e Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Tue, 16 Nov 2021 18:25:16 -0800 Subject: [PATCH 3/4] Attempt 2 to minimize recaching --- ehr/resources/queries/study/Demographics.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ehr/resources/queries/study/Demographics.js b/ehr/resources/queries/study/Demographics.js index b97164df5..a15c75b87 100644 --- a/ehr/resources/queries/study/Demographics.js +++ b/ehr/resources/queries/study/Demographics.js @@ -14,17 +14,17 @@ function onInit(event, helper){ }); } -function onUpsert(helper, scriptErrors, row, oldRow){ +function onInsert(helper, scriptErrors, row) { + // If we're doing inserts in demographics (where we don't have an old row), don't fire the normal notifications + // of changes to refresh the demographics cache, as we have to do a special clearing after study has done its + // bookkeeping. See ticket 44283 and the clearing in TriggerScriptHelper.createDemographicsRecord() + helper.getExtraContext().skipAnnounceChangedParticipants = true; +} + +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); } - if (!oldRow) { - // If we're doing inserts in demographics (where we don't have an old row), don't fire the normal notifications - // of changes to refresh the demographics cache, as we have to do a special clearing after study has done its - // bookkeeping. See ticket 44283 and the clearing in TriggerScriptHelper.createDemographicsRecord() - helper.getExtraContext().skipAnnounceChangedParticipants = true; - } - } \ No newline at end of file From dcc43341088590ef6308f01ac598c3af555a12dc Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Wed, 17 Nov 2021 08:35:29 -0800 Subject: [PATCH 4/4] Accept the double-recaching perf hit to fix test cases --- ehr/resources/queries/study/Demographics.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ehr/resources/queries/study/Demographics.js b/ehr/resources/queries/study/Demographics.js index a15c75b87..38df4c5c3 100644 --- a/ehr/resources/queries/study/Demographics.js +++ b/ehr/resources/queries/study/Demographics.js @@ -14,13 +14,6 @@ function onInit(event, helper){ }); } -function onInsert(helper, scriptErrors, row) { - // If we're doing inserts in demographics (where we don't have an old row), don't fire the normal notifications - // of changes to refresh the demographics cache, as we have to do a special clearing after study has done its - // bookkeeping. See ticket 44283 and the clearing in TriggerScriptHelper.createDemographicsRecord() - helper.getExtraContext().skipAnnounceChangedParticipants = true; -} - 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