Skip to content
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
72 changes: 43 additions & 29 deletions nbri_ehr/resources/queries/study/arrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,49 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even

helper.registerArrival(row.Id, row.date);

// These records are created for rearrivals too: the animal's departure closed the ones it had.
if (!helper.isETL() && !helper.isGeneratedByServer() && !helper.isValidateOnly()) {

if (row.QCStateLabel) {
row.qcstate = helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId();
}

// A rearrival reuses the existing demographics record, so its status is written directly; drafts get the same interim status an arrival draft does.
// The update refreshes the server-side animal cache, so the records opened below validate against this status rather than the departure's.
if (row.rearrival && row.Id && row.QCStateLabel) {
row.calculated_status = (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' || row.QCStateLabel.toUpperCase() === 'REVIEW REQUIRED') ? 'Alive - In Progress' : 'Alive';
helper.getJavaHelper().updateDemographicsRecord([{
Id: row.Id,
calculated_status: row.calculated_status
}]);
}

// an animal arrives already assigned to a project, a protocol and a group, all entered on the arrival row
if (row.Id && row.date) {
createAssignment(scriptErrors, 'assignment', 'project', row.project, row);
createAssignment(scriptErrors, 'protocolAssignment', 'protocol', row.arrivalProtocol, row);
createAssignment(scriptErrors, 'animal_group_members', 'groupId', row.groupId, row);
}

// if 'cage', labeled as "Initial Location" is provided, then insert into housing.
if (row.cage && row.Id && row.date) {
var housingRec = {
Id: row.Id,
date: row.date,
cage: row.cage,
taskid: row.taskid,
qcstate: row.qcstate,
reason: row.arrivalType,
performedby: row.performedby
}

var housingErrors = triggerHelper.createHousingRecord(row.Id, housingRec, "arrival");
if (housingErrors) {
EHR.Server.Utils.addError(scriptErrors, 'Id', housingErrors, 'ERROR');
}
}
}

//Insert or update demographic and birth records
if (!row.rearrival && !helper.isETL() && !helper.isGeneratedByServer() && !helper.isValidateOnly()) {

Expand All @@ -81,10 +124,6 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
row.socialCode = row['Id/demographics/socialCode'] || null;
row.generation = isBlankGeneration(row['Id/demographics/generation']) ? null : parseInt(row['Id/demographics/generation'], 10);

if (row.QCStateLabel) {
row.qcstate = helper.getJavaHelper().getQCStateForLabel(row.QCStateLabel).getRowId();
}

if (row.birth) {
var birthInfo = {
Id: row.Id,
Expand All @@ -100,31 +139,6 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
}
}

// an animal arrives already assigned to a project, a protocol and a group, all entered on the arrival row
if (row.Id && row.date) {
createAssignment(scriptErrors, 'assignment', 'project', row.project, row);
createAssignment(scriptErrors, 'protocolAssignment', 'protocol', row.arrivalProtocol, row);
createAssignment(scriptErrors, 'animal_group_members', 'groupId', row.groupId, row);
}

// if 'cage', labeled as "Initial Location" is provided, then insert into housing.
if (row.cage && row.Id && row.date) {
var housingRec = {
Id: row.Id,
date: row.date,
cage: row.cage,
taskid: row.taskid,
qcstate: row.qcstate,
reason: row.arrivalType,
performedby: row.performedby
}

var housingErrors = triggerHelper.createHousingRecord(row.Id, housingRec, "arrival");
if (housingErrors) {
EHR.Server.Utils.addError(scriptErrors, 'Id', housingErrors, 'ERROR');
}
}

row.calculated_status = (row.QCStateLabel.toUpperCase() === 'IN PROGRESS' || row.QCStateLabel.toUpperCase() === 'REVIEW REQUIRED') ? 'Alive - In Progress' : 'Alive';

if(!oldRow) {
Expand Down
76 changes: 57 additions & 19 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Rearrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ EHR.model.DataModelManager.registerMetadata('Rearrival', {
width: 150
},
},
// a rearrival is a return, not a fresh acquisition, so neither field applies to it
acquisitionType: {
allowBlank: false,
columnConfig: {
fixed: true,
width: 150
},
allowBlank: true,
hidden: true,
showInGrid: false
},
CITES: {
allowBlank: true,
hidden: true,
showInGrid: false
},
arrivalType: {
allowBlank: false,
Expand All @@ -43,26 +47,60 @@ EHR.model.DataModelManager.registerMetadata('Rearrival', {
}
},
'cage': {
allowBlank: true,
hidden: true,
showInGrid: false
allowBlank: false,
nullable: false,
columnConfig: {
fixed: true,
width: 200
},
},
// the animal's departure closed its project, protocol and group assignments, so each is opened again here
project: {
allowBlank: true,
hidden: true,
showInGrid: false
xtype: 'combo',
allowBlank: false,
nullable: false,
columnConfig: {
fixed: true,
width: 150
},
lookup: {
schemaName: 'ehr',
queryName: 'project',
keyColumn: 'project',
columns: 'project,name',
filterArray: [
LABKEY.Filter.create('isActive', true, LABKEY.Filter.Types.EQUAL),
]
}
},
arrivalProtocol: {
allowBlank: true,
hidden: true,
showInGrid: false
xtype: 'combo',
allowBlank: false,
nullable: false,
columnConfig: {
fixed: true,
width: 150
},
// set displayColumn: ehr.protocol's title column (displayName) is not returned by this query
lookup: {
schemaName: 'ehr',
queryName: 'activeProtocols',
keyColumn: 'protocol',
displayColumn: 'protocol',
columns: 'protocol,title'
}
},
// a rearriving animal keeps the assignments it already had; new ones are made on the Assignment forms
groupId: {
allowBlank: true,
hidden: true,
showInGrid: false
allowBlank: false,
nullable: false,
columnConfig: {
width: 200
},
lookup: {
// the shared default filters on a date column that the breeding type lookup does not have
filterArray: []
}
},
}
}
});
});