Skip to content

Commit 44093d4

Browse files
committed
MOdified pairing observation xtype controls.
1 parent 41e5bfc commit 44093d4

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

onprc_ehr/resources/queries/study/Pairings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
require("ehr/triggers").initScript(this);
88

9+
var ONPRC_triggerHelper = new org.labkey.onprc_ehr.query.ONPRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
10+
911
function onInit(event, helper) {
1012
helper.setScriptOptions({
1113
errorSeverityForImproperHousing: 'INFO'

onprc_ehr/src/org/labkey/onprc_ehr/query/ONPRC_EHRTriggerHelper.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,12 +2626,14 @@ public void exec(ResultSet object) throws SQLException
26262626
demographics.getUpdateService().updateRows(_user, _container, toUpdate, oldKeys, null, getExtraContext());
26272627
}
26282628
}
2629+
26292630
public void closeActivePairingsRecords(List<Map<String, Object>> records) throws Exception
26302631
{
26312632
TableInfo housing = getTableInfo("study", "pairings");
26322633
List<Map<String, Object>> toUpdate = new ArrayList<>();
26332634
List<Map<String, Object>> oldKeys = new ArrayList<>();
26342635

2636+
26352637
//sort on date
26362638
records = new ArrayList<>(records);
26372639
records.sort(new Comparator<Map<String, Object>>()
@@ -2652,7 +2654,56 @@ public int compare(Map<String, Object> o1, Map<String, Object> o2)
26522654
}
26532655
}
26542656
});
2657+
2658+
Set<String> encounteredLsids = new HashSet<>();
2659+
for (Map<String, Object> row : records)
2660+
{
2661+
Date date = dateTimeFormat.parse(row.get("date").toString());
2662+
if (date.getHours() == 0 && date.getMinutes() == 0)
2663+
{
2664+
Exception e = new Exception();
2665+
_log.error("Attempting to terminate study details records with a rounded date. This might indicate upstream code is rounding the date: " + dateTimeFormat.format(date), e);
2666+
}
2667+
2668+
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("Id"), row.get("Id"));
2669+
filter.addCondition(FieldKey.fromString("enddate"), null, CompareType.ISBLANK);
2670+
2671+
//we want to only close those records starting prior to this record
2672+
filter.addCondition(FieldKey.fromString("date"), date, CompareType.LTE);
2673+
filter.addCondition(FieldKey.fromString("objectid"), row.get("objectid"), CompareType.NEQ_OR_NULL);
2674+
if (!encounteredLsids.isEmpty())
2675+
{
2676+
filter.addCondition(FieldKey.fromString("lsid"), encounteredLsids, CompareType.NOT_IN);
2677+
}
2678+
2679+
TableSelector ts = new TableSelector(housing, Collections.singleton("lsid"), filter, null);
2680+
List<String> ret = ts.getArrayList(String.class);
2681+
if (!ret.isEmpty())
2682+
{
2683+
encounteredLsids.addAll(ret);
2684+
for (String lsid : ret)
2685+
{
2686+
Map<String, Object> r = new CaseInsensitiveHashMap<>();
2687+
r.put("lsid", lsid);
2688+
r.put("enddate", date);
2689+
toUpdate.add(r);
2690+
2691+
Map<String, Object> keyMap = new CaseInsensitiveHashMap<>();
2692+
keyMap.put("lsid", lsid);
2693+
oldKeys.add(keyMap);
2694+
}
2695+
}
2696+
}
2697+
2698+
if (!toUpdate.isEmpty())
2699+
{
2700+
_log.info("closing study pairing records: " + toUpdate.size());
2701+
Map<String, Object> context = getExtraContext();
2702+
context.put("skipAnnounceChangedParticipants", true);
2703+
housing.getUpdateService().updateRows(getUser(), getContainer(), toUpdate, oldKeys, null, context);
2704+
}
26552705
}
2706+
26562707
public void recalculateAllVetAssignmentRecords()
26572708
{
26582709
EHRDemographicsService.get().recalculateForAllIdsInCache(_container, "onprc_ehr", "vet_assignment", true);

0 commit comments

Comments
 (0)