Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand import validation in MCC #157

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified mcc/resources/web/mcc/exampleData/MCC_Data_Template.xlsx
Binary file not shown.
54 changes: 40 additions & 14 deletions mcc/resources/web/mcc/panel/MccImportPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Ext4.define('MCC.panel.MccImportPanel', {
allowRowSpan: false,
alwaysShow: true,
transform: 'animalId',
allowBlank: false
allowBlank: false,
expectInImport: true
},{
name: 'alternateIds',
labels: ['Alternate Ids', 'previous Ids'],
Expand All @@ -46,7 +47,8 @@ Ext4.define('MCC.panel.MccImportPanel', {
labels: ['Source Colony', 'Source'],
allowRowSpan: false,
allowBlank: true,
alwaysShow: true
alwaysShow: true,
expectInImport: true
},{
name: 'shippingDestination',
labels: ['Shipping Destination'],
Expand All @@ -65,13 +67,15 @@ Ext4.define('MCC.panel.MccImportPanel', {
labels: ['Birth', 'DOB', 'DOB (mm/dd/yyyy)'],
allowRowSpan: false,
allowBlank: true,
transform: 'genericDate'
transform: 'genericDate',
expectInImport: true
},{
name: 'gender',
labels: ['Sex'],
allowRowSpan: false,
allowBlank: true,
transform: 'sex'
transform: 'sex',
expectInImport: true
},{
name: 'status',
labels: ['Status'],
Expand All @@ -84,26 +88,32 @@ Ext4.define('MCC.panel.MccImportPanel', {
labels: ['Dam', 'maternal ID'],
allowRowSpan: false,
allowBlank: true,
transform: 'damOrSire'
alwaysShow: true,
transform: 'damOrSire',
expectInImport: true
},{
name: 'sire',
labels: ['Sire', 'paternal ID'],
allowRowSpan: false,
allowBlank: true,
transform: 'damOrSire'
alwaysShow: true,
transform: 'damOrSire',
expectInImport: true
},{
name: 'weight',
labels: ['Weight (g)', 'Weight (grams)', 'current weight (g)', 'current weight (grams)'],
allowRowSpan: false,
allowBlank: true,
transform: 'weight'
transform: 'weight',
expectInImport: true
},{
name: 'weightDate',
labels: ['Date of Weight', 'date of weight', 'date of weight (mm/dd/yyyy)'],
alwaysShow: true,
allowRowSpan: false,
transform: 'genericDate',
allowBlank: true
allowBlank: true,
expectInImport: true
},{
name: 'date',
labels: ['Observation Date', 'date'],
Expand All @@ -117,13 +127,15 @@ Ext4.define('MCC.panel.MccImportPanel', {
alwaysShow: false,
allowRowSpan: false,
allowBlank: false,
transform: 'u24'
transform: 'u24',
expectInImport: true
},{
name: 'availability',
labels: ['Available to Transfer', 'available to transfer'],
allowRowSpan: false,
allowBlank: true,
transform: 'available'
transform: 'available',
expectInImport: true
},{
name: 'breedingPartnerId',
labels: ['Breeding Partner Id'],
Expand All @@ -134,25 +146,29 @@ Ext4.define('MCC.panel.MccImportPanel', {
labels: ['Current Housing Status'],
allowRowSpan: false,
allowBlank: true,
transform: 'housingStatus'
transform: 'housingStatus',
expectInImport: true
},{
name: 'infantHistory',
labels: ['Infant History'],
allowRowSpan: false,
alwaysShow: true,
transform: 'infantHistory'
transform: 'infantHistory',
expectInImport: true
},{
name: 'fertilityStatus',
labels: ['Fertility Status'],
allowRowSpan: false,
alwaysShow: true,
transform: 'fertilityStatus'
transform: 'fertilityStatus',
expectInImport: true
},{
name: 'medicalHistory',
labels: ['Medical History'],
allowRowSpan: false,
allowBlank: true,
transform: 'medicalHistory'
transform: 'medicalHistory',
expectInImport: true
},{
name: 'currentUsage',
labels: ['Usage (Current)', 'usage (current)'],
Expand Down Expand Up @@ -437,6 +453,16 @@ Ext4.define('MCC.panel.MccImportPanel', {

var rows = LDK.Utils.CSVToArray(text, '\t');
var colArray = this.parseHeader(rows.shift());
var foundColsNames = colArray.map(x => x.name)
var missingExpectedCols = this.COLUMNS.filter(x => x.expectInImport).map(x => x.name).filter(x => foundColsNames.indexOf(x) === -1)
if (missingExpectedCols.length) {
// now convert from name to label:
var colNameToLabel = {}
this.COLUMNS.forEach(x => colNameToLabel[x.name] = x.labels[0])
Ext4.Msg.alert('Error', 'The following columns were expected but not found:<br>' + missingExpectedCols.map(x => colNameToLabel[x]).join('<br>'))
return null;
}

var errorsMsgs = [];
var parsedRows = this.parseRows(colArray, rows, errorsMsgs);

Expand Down
2 changes: 1 addition & 1 deletion mcc/test/src/org/labkey/test/tests/mcc/MccTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testMccModule() throws Exception
testAnimalImportAndTransfer();
}

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";
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";

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";

Expand Down