Skip to content

Commit 4f0f95b

Browse files
committed
Allow MCC transfer workflow to work within one container
1 parent 8063c22 commit 4f0f95b

File tree

1 file changed

+81
-45
lines changed

1 file changed

+81
-45
lines changed

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

Lines changed: 81 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ Ext4.define('MCC.window.MarkShippedWindow', {
140140
var newId = win.down('#newId').getValue() || row.Id;
141141

142142
var commands = [];
143-
if (!row['Id/MostRecentDeparture/MostRecentDeparture']) {
143+
144+
var shouldAddDeparture = !row['Id/MostRecentDeparture/MostRecentDeparture'] || row['Id/MostRecentDeparture/MostRecentDeparture'] !== Ext4.Date.format(row.effectiveDate, 'Y-m-d') || row.Id !== newId;
145+
if (shouldAddDeparture) {
144146
commands.push({
145147
command: 'insert',
146148
schemaName: 'study',
@@ -149,59 +151,93 @@ Ext4.define('MCC.window.MarkShippedWindow', {
149151
Id: row.Id,
150152
date: effectiveDate,
151153
destination: centerName,
154+
description: row.colony ? 'Original center: ' + row.colony : null,
152155
qcstate: null,
153156
objectId: null,
154157
QCStateLabel: 'Completed'
155158
}]
156159
});
157160
}
158161

159-
commands.push({
160-
command: 'insert',
161-
containerPath: targetFolder,
162-
schemaName: 'study',
163-
queryName: 'Demographics',
164-
rows: [{
165-
Id: newId,
166-
date: effectiveDate,
167-
alternateIds: row.Id !== newId ? row.Id : null,
168-
gender: row.gender,
169-
species: row.species,
170-
birth: row.birth,
171-
death: row.death,
172-
dam: row.dam,
173-
sire: row.sire,
174-
colony: centerName,
175-
source: row.colony,
176-
calculated_status: 'Alive',
177-
skipMccAliasCreation: true,
178-
QCState: null,
179-
QCStateLabel: 'Completed',
180-
objectId: null
181-
}]
182-
});
162+
// If going to a new LK folder, we're creating a whole new record:
163+
if (targetFolder.toUpperCase() !== LABKEY.Security.currentContainer.id.toUpperCase() || newId !== row.Id) {
164+
commands.push({
165+
command: 'insert',
166+
containerPath: targetFolder,
167+
schemaName: 'study',
168+
queryName: 'Demographics',
169+
rows: [{
170+
Id: newId,
171+
date: effectiveDate,
172+
alternateIds: row.Id !== newId ? row.Id : null,
173+
gender: row.gender,
174+
species: row.species,
175+
birth: row.birth,
176+
death: row.death,
177+
dam: row.dam,
178+
sire: row.sire,
179+
colony: centerName,
180+
source: row.colony,
181+
calculated_status: 'Alive',
182+
skipMccAliasCreation: true,
183+
QCState: null,
184+
QCStateLabel: 'Completed',
185+
objectId: null
186+
}]
187+
});
183188

184-
commands.push({
185-
command: 'insert',
186-
containerPath: targetFolder,
187-
schemaName: 'mcc',
188-
queryName: 'animalMapping',
189-
rows: [{
190-
subjectname: newId,
191-
externalAlias: row['Id/mccAlias/externalAlias']
192-
}]
193-
});
189+
commands.push({
190+
command: 'update',
191+
containerPath: null, //Use current folder
192+
schemaName: 'study',
193+
queryName: 'Demographics',
194+
rows: [{
195+
Id: newId,
196+
excludeFromCensus: true
197+
}]
198+
});
199+
}
200+
else {
201+
// Otherwise update the existing:
202+
commands.push({
203+
command: 'update',
204+
containerPath: targetFolder,
205+
schemaName: 'study',
206+
queryName: 'Demographics',
207+
rows: [{
208+
Id: newId,
209+
date: effectiveDate,
210+
alternateIds: row.Id !== newId ? row.Id : null,
211+
gender: row.gender,
212+
species: row.species,
213+
birth: row.birth,
214+
death: row.death,
215+
dam: row.dam,
216+
sire: row.sire,
217+
colony: centerName,
218+
source: row.colony,
219+
calculated_status: 'Alive',
220+
skipMccAliasCreation: true,
221+
QCState: null,
222+
QCStateLabel: 'Completed',
223+
objectId: null
224+
}]
225+
});
226+
}
194227

195-
commands.push({
196-
command: 'update',
197-
containerPath: null, //Use current folder
198-
schemaName: 'study',
199-
queryName: 'Demographics',
200-
rows: [{
201-
Id: newId,
202-
excludeFromCensus: true
203-
}]
204-
});
228+
// Do this insert if we're using a new container, or if the animal is being assigned a new ID
229+
if (targetFolder.toUpperCase() !== LABKEY.Security.currentContainer.id.toUpperCase() || newId !== row.Id) {
230+
commands.push({
231+
command: 'insert',
232+
containerPath: targetFolder,
233+
schemaName: 'mcc',
234+
queryName: 'animalMapping',
235+
rows: [{
236+
subjectname: newId,
237+
externalAlias: row['Id/mccAlias/externalAlias']
238+
}]
239+
});
240+
}
205241

206242
LABKEY.Query.saveRows({
207243
commands: commands,

0 commit comments

Comments
 (0)