Skip to content

Commit 8eeaa56

Browse files
committed
Add MCC hook to set demographics/colony after MCC transfer
1 parent 6d1ab8b commit 8eeaa56

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

MccColony/resources/queries/study/demographics/.qview.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<column name="Id/MostRecentWeight/MostRecentWeightGrams"/>
2525
<column name="Id/MostRecentWeight/MostRecentWeightDate"/>
2626
<column name="alternateIds"/>
27+
<column name="excludeFromCensus"/>
2728
</columns>
2829
<sorts>
2930
<sort column="Id" descending="false"/>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var console = require("console");
2+
var LABKEY = require("labkey");
3+
require("ehr/triggers").initScript(this);
4+
5+
var triggerHelper = new org.labkey.mcc.query.TriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
6+
7+
EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.ON_BECOME_PUBLIC, 'study', 'Departure', function(scriptErrors, helper, row, oldRow) {
8+
if (row.destination) {
9+
triggerHelper.updateDemographicsColony(row.Id, row.destination);
10+
}
11+
});

mcc/resources/web/mcc/window/MarkShippedWindow.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ Ext4.define('MCC.window.MarkShippedWindow', {
141141

142142
var commands = [];
143143
if (!row['Id/MostRecentDeparture/MostRecentDeparture']) {
144-
//TODO: make this update demographics.colony
145144
commands.push({
146145
command: 'insert',
147146
schemaName: 'study',

mcc/src/org/labkey/mcc/query/TriggerHelper.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
import javax.mail.Message;
4040
import java.sql.SQLException;
4141
import java.util.ArrayList;
42+
import java.util.Arrays;
4243
import java.util.Collection;
4344
import java.util.Collections;
4445
import java.util.Date;
45-
import java.util.HashMap;
4646
import java.util.HashSet;
4747
import java.util.List;
4848
import java.util.Map;
@@ -300,4 +300,28 @@ public int ensureMccAliasExists(Collection<String> ids)
300300
return 0;
301301
}
302302
}
303+
304+
public void updateDemographicsColony(String Id, String destination) throws Exception
305+
{
306+
TableInfo ti = QueryService.get().getUserSchema(_user, _container, "study").getTable("demographics");
307+
TableSelector ts = new TableSelector(ti, PageFlowUtil.set("lsid"), new SimpleFilter(FieldKey.fromString("Id"), Id, CompareType.EQUAL), null);
308+
String lsid = ts.getObject(String.class);
309+
if (lsid == null)
310+
{
311+
_log.error("Unknown ID in demographics: " + Id);
312+
return;
313+
}
314+
315+
Map<String, Object> toUpdate = new CaseInsensitiveHashMap<>();
316+
toUpdate.put("lsid", lsid);
317+
toUpdate.put("Id", Id);
318+
toUpdate.put("colony", destination);
319+
320+
BatchValidationException bve = new BatchValidationException();
321+
ti.getUpdateService().updateRows(_user, _container, Arrays.asList(toUpdate), Arrays.asList(Map.of("lsid", lsid)), null, null);
322+
if (bve.hasErrors())
323+
{
324+
throw bve;
325+
}
326+
}
303327
}

0 commit comments

Comments
 (0)