Skip to content

Commit 7624022

Browse files
authored
Expand import validation in MCC (#157)
* Expand import validation in MCC
1 parent 4d597ea commit 7624022

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed
1.54 KB
Binary file not shown.

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

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Ext4.define('MCC.panel.MccImportPanel', {
3333
allowRowSpan: false,
3434
alwaysShow: true,
3535
transform: 'animalId',
36-
allowBlank: false
36+
allowBlank: false,
37+
expectInImport: true
3738
},{
3839
name: 'alternateIds',
3940
labels: ['Alternate Ids', 'previous Ids'],
@@ -46,7 +47,8 @@ Ext4.define('MCC.panel.MccImportPanel', {
4647
labels: ['Source Colony', 'Source'],
4748
allowRowSpan: false,
4849
allowBlank: true,
49-
alwaysShow: true
50+
alwaysShow: true,
51+
expectInImport: true
5052
},{
5153
name: 'shippingDestination',
5254
labels: ['Shipping Destination'],
@@ -65,13 +67,15 @@ Ext4.define('MCC.panel.MccImportPanel', {
6567
labels: ['Birth', 'DOB', 'DOB (mm/dd/yyyy)'],
6668
allowRowSpan: false,
6769
allowBlank: true,
68-
transform: 'genericDate'
70+
transform: 'genericDate',
71+
expectInImport: true
6972
},{
7073
name: 'gender',
7174
labels: ['Sex'],
7275
allowRowSpan: false,
7376
allowBlank: true,
74-
transform: 'sex'
77+
transform: 'sex',
78+
expectInImport: true
7579
},{
7680
name: 'status',
7781
labels: ['Status'],
@@ -84,26 +88,32 @@ Ext4.define('MCC.panel.MccImportPanel', {
8488
labels: ['Dam', 'maternal ID'],
8589
allowRowSpan: false,
8690
allowBlank: true,
87-
transform: 'damOrSire'
91+
alwaysShow: true,
92+
transform: 'damOrSire',
93+
expectInImport: true
8894
},{
8995
name: 'sire',
9096
labels: ['Sire', 'paternal ID'],
9197
allowRowSpan: false,
9298
allowBlank: true,
93-
transform: 'damOrSire'
99+
alwaysShow: true,
100+
transform: 'damOrSire',
101+
expectInImport: true
94102
},{
95103
name: 'weight',
96104
labels: ['Weight (g)', 'Weight (grams)', 'current weight (g)', 'current weight (grams)'],
97105
allowRowSpan: false,
98106
allowBlank: true,
99-
transform: 'weight'
107+
transform: 'weight',
108+
expectInImport: true
100109
},{
101110
name: 'weightDate',
102111
labels: ['Date of Weight', 'date of weight', 'date of weight (mm/dd/yyyy)'],
103112
alwaysShow: true,
104113
allowRowSpan: false,
105114
transform: 'genericDate',
106-
allowBlank: true
115+
allowBlank: true,
116+
expectInImport: true
107117
},{
108118
name: 'date',
109119
labels: ['Observation Date', 'date'],
@@ -117,13 +127,15 @@ Ext4.define('MCC.panel.MccImportPanel', {
117127
alwaysShow: false,
118128
allowRowSpan: false,
119129
allowBlank: false,
120-
transform: 'u24'
130+
transform: 'u24',
131+
expectInImport: true
121132
},{
122133
name: 'availability',
123134
labels: ['Available to Transfer', 'available to transfer'],
124135
allowRowSpan: false,
125136
allowBlank: true,
126-
transform: 'available'
137+
transform: 'available',
138+
expectInImport: true
127139
},{
128140
name: 'breedingPartnerId',
129141
labels: ['Breeding Partner Id'],
@@ -134,25 +146,29 @@ Ext4.define('MCC.panel.MccImportPanel', {
134146
labels: ['Current Housing Status'],
135147
allowRowSpan: false,
136148
allowBlank: true,
137-
transform: 'housingStatus'
149+
transform: 'housingStatus',
150+
expectInImport: true
138151
},{
139152
name: 'infantHistory',
140153
labels: ['Infant History'],
141154
allowRowSpan: false,
142155
alwaysShow: true,
143-
transform: 'infantHistory'
156+
transform: 'infantHistory',
157+
expectInImport: true
144158
},{
145159
name: 'fertilityStatus',
146160
labels: ['Fertility Status'],
147161
allowRowSpan: false,
148162
alwaysShow: true,
149-
transform: 'fertilityStatus'
163+
transform: 'fertilityStatus',
164+
expectInImport: true
150165
},{
151166
name: 'medicalHistory',
152167
labels: ['Medical History'],
153168
allowRowSpan: false,
154169
allowBlank: true,
155-
transform: 'medicalHistory'
170+
transform: 'medicalHistory',
171+
expectInImport: true
156172
},{
157173
name: 'currentUsage',
158174
labels: ['Usage (Current)', 'usage (current)'],
@@ -437,6 +453,16 @@ Ext4.define('MCC.panel.MccImportPanel', {
437453

438454
var rows = LDK.Utils.CSVToArray(text, '\t');
439455
var colArray = this.parseHeader(rows.shift());
456+
var foundColsNames = colArray.map(x => x.name)
457+
var missingExpectedCols = this.COLUMNS.filter(x => x.expectInImport).map(x => x.name).filter(x => foundColsNames.indexOf(x) === -1)
458+
if (missingExpectedCols.length) {
459+
// now convert from name to label:
460+
var colNameToLabel = {}
461+
this.COLUMNS.forEach(x => colNameToLabel[x.name] = x.labels[0])
462+
Ext4.Msg.alert('Error', 'The following columns were expected but not found:<br>' + missingExpectedCols.map(x => colNameToLabel[x]).join('<br>'))
463+
return null;
464+
}
465+
440466
var errorsMsgs = [];
441467
var parsedRows = this.parseRows(colArray, rows, errorsMsgs);
442468

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testMccModule() throws Exception
6868
testAnimalImportAndTransfer();
6969
}
7070

71-
private static final String ANIMAL_DATA_HEADER = "animal ID\tprevious IDs\tsource\t\"DOB\n(MM/DD/YYYY)\"\tsex\tmaternal ID\tpaternal ID\t\"weight(grams)\"\t\"date of weight\n(MM/DD/YY)\"\tU24 status\tavailable to transfer\tcurrent housing status\tinfant history\tfertility status\tmedical history\n";
71+
private static final String ANIMAL_DATA_HEADER = "animal ID\tprevious IDs\tsource\t\"DOB\n(MM/DD/YYYY)\"\tsex\tmaternal ID\tpaternal ID\t\"weight (grams)\"\t\"date of weight\n(MM/DD/YY)\"\tU24 status\tavailable to transfer\tcurrent housing status\tinfant history\tfertility status\tmedical history\n";
7272

7373
private static final String ANIMAL_DATA1 = "12345\t\t\t7/10/2011\t0 - male\t23456\t23453\t382.8\t5/19/2021\t0 - not assigned to U24 breeding colony\t0 - not available for transfer\t1 - natal family unit\t3 - successful rearing of offspring\t2 - successful offspring produced\t0 - naive animal\n";
7474

0 commit comments

Comments
 (0)