Skip to content

Commit 1f59a3b

Browse files
authored
Refine MCC process to mark status of missing census IDs (#95)
* Refine MCC process to mark status of missing census IDs
1 parent afb78aa commit 1f59a3b

File tree

5 files changed

+247
-37
lines changed

5 files changed

+247
-37
lines changed

mcc/resources/data/death_cause.tsv

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
value title category description sort_order date_disabled
2+
Spontaneous Death 1
3+
Sudden Infant Death 5
4+
Accidental Death 13
5+
Death Due to Fight 14
6+
Acute Surgical Death 6
7+
Postoperative Death 7
8+
Dead On Arrival 15
9+
Unplanned Experimental Death 8
10+
Perinatal Death 2
11+
Postpartum Death 9
12+
Death in Quarantine 12
13+
Undetermined Cause 10
14+
Unclassified Cause 11
15+
Abortion ( < 130 days gestation ) 17
16+
Spontaneous Death, Experimental subject 22
17+
Neonatal death (<28 days of age, breathed once) 28
18+
Spontaneous Death in quarantine 24
19+
Stillbirth ( > 130 days gestation, never breathed) 16
20+
Cause of Death Unknown 99
21+
EUTHANASIA, EXPERIMENTAL 3
22+
EUTHANASIA, NONEXPERIMENTAL 4
23+
EUTHANASIA, QUARANTINE 3
24+
Medical Termination 30
25+
Miscarriage 32
26+
Biochemical Pregnancy 35

mcc/resources/referenceStudy/study/datasets/datasets_manifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<dataset name="transfers" id="1001" category="Colony Management" type="Standard">
3838
<tags/>
3939
</dataset>
40-
<dataset name="deaths" id="1048" showByDefault="false" category="Colony Management" demographicData="true" type="Standard">
40+
<dataset name="deaths" id="1048" showByDefault="true" category="Colony Management" demographicData="true" type="Standard">
4141
<tags/>
4242
</dataset>
4343
<dataset name="demographics" id="1012" category="Colony Management" demographicData="true" type="Standard">

mcc/resources/views/populateData.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@
178178
schemaName: 'ehr_lookups',
179179
queryName: 'conc_units',
180180
pk: 'rowid'
181+
},{
182+
label: 'Death Cause',
183+
populateFn: 'populateFromFile',
184+
moduleName: 'mcc',
185+
schemaName: 'ehr_lookups',
186+
queryName: 'death_cause',
187+
pk: 'rowid'
181188
},{
182189
label: 'Dosage Units',
183190
populateFn: 'populateFromFile',

mcc/resources/web/mcc/panel/MccImportPanel.js

Lines changed: 192 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -713,62 +713,133 @@ Ext4.define('MCC.panel.MccImportPanel', {
713713
if (missingIds.length) {
714714
Ext4.create('Ext.window.Window', {
715715
bodyStyle: 'padding: 5px;',
716-
width: 500,
716+
width: 600,
717717
modal: true,
718718
title: 'Reconcile Census with Existing IDs',
719+
effectiveDate: config.rowData.panel.IMPORT_DATE,
719720
defaults: {
720721
labelWidth: 200,
721-
width: 450,
722+
width: 575,
722723
},
723724
items: [{
724725
html: 'The following IDs are listed for the indicated colony, but were not in your census. Choose any status updates and hit submit:',
725726
border: false,
726727
style: 'padding-bottom: 10px;'
727728
},{
728-
layout: 'table',
729+
layout: {
730+
type: 'table',
731+
columns: 4
732+
},
729733
border: false,
730-
columns: 2,
731734
defaults: {
732-
border: false
735+
border: false,
736+
bodyStyle: 'padding: 5px'
733737
},
734738
items: config.rowData.panel.getAnimalRows(missingIds)
735739
}],
736740
buttons: [{
737741
text: 'Update IDs',
738742
scope: this,
739743
handler: function(btn) {
740-
var updates = []
741-
btn.up('window').query('combo').forEach(function(f){
744+
var demographicsUpdates = [];
745+
var deathInserts = [];
746+
var departureInserts = [];
747+
var win = btn.up('window');
748+
749+
var missingValues = false;
750+
win.query('combo[dataIndex="status_code"]').forEach(function(f){
742751
if (f.getValue() && f.getValue() !== f.sourceRecord.calculated_status) {
743-
updates.push({
744-
Id: f.sourceRecord.Id,
745-
calculated_status: f.getValue(),
746-
lsid: f.sourceRecord.lsid,
747-
objectid: f.sourceRecord.objectid
748-
});
752+
var fields = win.query('field[recordIdx=' + f.recordIdx + ']');
753+
LDK.Assert.assertEquality('Incorrect number of MccImportPanel fields', 3, fields.length);
754+
755+
var dateVal = fields[1].getValue();
756+
var otherVal = fields[2].getValue();
757+
if (!dateVal || !otherVal) {
758+
missingValues = true;
759+
return false;
760+
}
761+
762+
if (f.getValue() === 'Dead') {
763+
deathInserts.push({
764+
Id: f.sourceRecord.Id,
765+
objectId: null,
766+
QCStateLabel: 'Completed',
767+
QCState: null,
768+
date: dateVal,
769+
cause: otherVal
770+
});
771+
} else if (f.getValue() === 'Shipped') {
772+
departureInserts.push({
773+
Id: f.sourceRecord.Id,
774+
objectId: null,
775+
QCStateLabel: 'Completed',
776+
QCState: null,
777+
date: dateVal,
778+
destination: otherVal
779+
});
780+
} else {
781+
// Handle unknown:
782+
demographicsUpdates.push({
783+
Id: f.sourceRecord.Id,
784+
calculated_status: f.getValue(),
785+
lsid: f.sourceRecord.lsid,
786+
objectid: f.sourceRecord.objectid
787+
});
788+
}
749789
}
750790
});
751791

752-
if (updates.length) {
753-
Ext4.Msg.wait('Saving...');
754-
LABKEY.Query.updateRows({
792+
if (missingValues) {
793+
Ext4.Msg.alert('Error', 'One or more fields is missing a value');
794+
return;
795+
}
796+
797+
var commands = [];
798+
if (demographicsUpdates.length) {
799+
commands.push({
800+
command: 'update',
755801
schemaName: 'study',
756802
queryName: 'demographics',
757-
rows: updates,
803+
rows: demographicsUpdates
804+
});
805+
}
806+
807+
if (departureInserts.length) {
808+
commands.push({
809+
type: 'insert',
810+
schemaName: 'study',
811+
queryName: 'departure',
812+
rows: departureInserts
813+
});
814+
}
815+
816+
if (deathInserts.length) {
817+
commands.push({
818+
command: 'insert',
819+
schemaName: 'study',
820+
queryName: 'deaths',
821+
rows: deathInserts
822+
});
823+
}
824+
825+
if (!commands.length) {
826+
Ext4.Msg.alert('No updates', 'No changes, nothing to do');
827+
btn.up('window').close();
828+
}
829+
else {
830+
Ext4.Msg.wait('Saving rows...');
831+
LABKEY.Query.saveRows({
832+
commands: commands,
758833
scope: this,
759-
failure: LDK.Utils.getErrorCallback(),
760-
success: function (results) {
834+
success: function() {
761835
Ext4.Msg.hide();
762836
Ext4.Msg.alert('Success', 'Records updated', function(){
763837
btn.up('window').close();
764838
}, this);
765-
}
839+
},
840+
failure: LDK.Utils.getErrorCallback()
766841
});
767842
}
768-
else {
769-
Ext4.Msg.alert('No updates', 'No changes, nothing to do');
770-
btn.up('window').close();
771-
}
772843
}
773844

774845
},{
@@ -786,22 +857,110 @@ Ext4.define('MCC.panel.MccImportPanel', {
786857
},
787858

788859
getAnimalRows: function(missingIds) {
789-
var ret = [];
790-
Ext4.Array.forEach(missingIds, function(r){
860+
var ret = [{
861+
xtype: 'displayfield',
862+
width: 125,
863+
value: 'Animal Id'
864+
}, {
865+
xtype: 'displayfield',
866+
width: 100,
867+
value: 'Status'
868+
}, {
869+
xtype: 'displayfield',
870+
width: 100,
871+
value: 'Date'
872+
},{
873+
xtype: 'displayfield',
874+
width: 125,
875+
value: 'Destination/Cause'
876+
}];
877+
878+
Ext4.Array.forEach(missingIds, function(r, idx){
791879
ret = ret.concat([{
792880
xtype: 'displayfield',
793881
width: 125,
794882
value: r.Id + ' / ' + r.colony
795-
},{
796-
xtype: 'ldk-simplelabkeycombo',
797-
schemaName: 'ehr_lookups',
798-
queryName: 'calculated_status_codes',
799-
displayField: 'code',
800-
valueField: 'code',
883+
}, {
884+
xtype: 'ldk-simplecombo',
885+
storeValues: Ext4.Array.unique([r.calculated_status, 'Alive', 'Dead', 'Shipped', 'Unknown']),
886+
recordIdx: idx,
887+
dataIndex: 'status_code',
801888
forceSelection: true,
802889
sourceRecord: r,
803890
width: 100,
804-
value: r.calculated_status
891+
style: 'margin-right: 5px',
892+
value: r.calculated_status,
893+
listeners: {
894+
render: function (f) {
895+
if (f.getValue()) {
896+
f.fireEvent('change', f, f.getValue());
897+
}
898+
},
899+
change: function (field, val) {
900+
var target1 = field.up('panel').down('container[recordIdx=' + field.recordIdx + '][areaType="date"]');
901+
target1.removeAll();
902+
903+
var target2 = field.up('panel').down('container[recordIdx=' + field.recordIdx + '][areaType="other"]');
904+
target2.removeAll();
905+
906+
var effectiveDate = field.up('window').effectiveDate;
907+
908+
if (val === 'Shipped') {
909+
target1.add({
910+
xtype: 'datefield',
911+
dataIndex: 'date',
912+
labelAlign: 'top',
913+
recordIdx: field.recordIdx,
914+
style: 'margin-right: 5px',
915+
value: effectiveDate
916+
});
917+
918+
target2.add({
919+
xtype: 'ldk-simplelabkeycombo',
920+
dataIndex: 'destination',
921+
labelAlign: 'top',
922+
recordIdx: field.recordIdx,
923+
schemaName: 'ehr_lookups',
924+
queryName: 'source',
925+
valueField: 'code',
926+
displayField: 'code',
927+
forceSelection: true,
928+
plugins: ['ldk-usereditablecombo']
929+
});
930+
}
931+
else if (val === 'Dead') {
932+
target1.add({
933+
xtype: 'datefield',
934+
dataIndex: 'date',
935+
labelAlign: 'top',
936+
recordIdx: field.recordIdx,
937+
style: 'margin-right: 5px',
938+
value: effectiveDate
939+
});
940+
941+
target2.add({
942+
xtype: 'ldk-simplelabkeycombo',
943+
dataIndex: 'cause',
944+
labelAlign: 'top',
945+
recordIdx: field.recordIdx,
946+
schemaName: 'ehr_lookups',
947+
queryName: 'death_cause',
948+
valueField: 'value',
949+
displayField: 'value',
950+
forceSelection: true,
951+
plugins: ['ldk-usereditablecombo']
952+
});
953+
}
954+
}
955+
}
956+
},{
957+
xtype: 'container',
958+
recordIdx: idx,
959+
areaType: 'date'
960+
},{
961+
xtype: 'container',
962+
recordIdx: idx,
963+
areaType: 'other'
805964
}]);
806965
});
807966

mcc/test/src/org/labkey/test/tests/mcc/MccTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,17 @@ private void testAnimalImportAndTransfer() throws Exception
200200

201201
waitAndClick(getButton("Process Missing IDs"));
202202
new Window.WindowFinder(getDriver()).withTitle("Reconcile Census with Existing IDs").waitFor();
203-
String comboQuery = "combo[queryName='calculated_status_codes']";
203+
204+
String comboQuery = "combo[dataIndex='status_code']";
204205
Ext4ComboRef.waitForComponent(this, comboQuery);
205206
Ext4ComboRef statusCombo = _ext4Helper.queryOne(comboQuery, Ext4ComboRef.class);
206-
statusCombo.setComboByDisplayValue("Unknown");
207+
statusCombo.setComboByDisplayValue("Dead");
208+
209+
String comboQuery2 = "combo[dataIndex='cause']";
210+
Ext4ComboRef.waitForComponent(this, comboQuery2);
211+
Ext4ComboRef causeCombo = _ext4Helper.queryOne(comboQuery2, Ext4ComboRef.class);
212+
causeCombo.setComboByDisplayValue("Cause of Death Unknown");
213+
207214
waitAndClick(Ext4Helper.Locators.ext4Button("Update IDs"));
208215
sleep(100);
209216
new Window.WindowFinder(getDriver()).withTitle("Success").waitFor();
@@ -213,7 +220,14 @@ private void testAnimalImportAndTransfer() throws Exception
213220
sr.setColumns(Arrays.asList("Id", "calculated_status"));
214221
sr.setFilters(Arrays.asList(new Filter("Id", "Animal3")));
215222
srr = sr.execute(createDefaultConnection(), getProjectName() + "/Colonies/SNPRC");
216-
Assert.assertEquals("Incorrect status", "Unknown", srr.getRows().get(0).get("calculated_status"));
223+
Assert.assertEquals("Incorrect status", "Dead", srr.getRows().get(0).get("calculated_status"));
224+
225+
sr = new SelectRowsCommand("study", "deaths");
226+
sr.setColumns(Arrays.asList("Id", "cause"));
227+
sr.setFilters(Arrays.asList(new Filter("Id", "Animal3")));
228+
srr = sr.execute(createDefaultConnection(), getProjectName() + "/Colonies/SNPRC");
229+
Assert.assertEquals("No death record", 1, srr.getRowCount().intValue());
230+
Assert.assertEquals("Incorrect cause", "Cause of Death Unknown", srr.getRows().get(0).get("cause"));
217231
}
218232

219233
private static class FormElement
@@ -849,6 +863,10 @@ private void populateLookups(String name)
849863
{
850864
beginAt(getProjectName() + "/Colonies/" + name + "/project-begin.view");
851865
waitAndClickAndWait(Locator.tagWithText("a", "Populate Lookups"));
866+
waitAndClick(Ext4Helper.Locators.ext4Button("Populate Lookup Sets"));
867+
waitForElement(Locator.tagWithText("div", "Populating lookup_sets..."));
868+
waitForElement(Locator.tagWithText("div", "Populate Complete"));
869+
852870
waitAndClick(Ext4Helper.Locators.ext4Button("Populate All"));
853871
waitForElement(Locator.tagWithText("div", "Populate Complete"));
854872
}

0 commit comments

Comments
 (0)