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
6 changes: 0 additions & 6 deletions nbri_ehr/resources/data/death_reason.tsv

This file was deleted.

18 changes: 9 additions & 9 deletions nbri_ehr/resources/data/death_type.tsv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
value title sort_order
A Experimental 1
value title sort_order date_disabled
A Experimental 1 2026-09-03
D Spontaneous/Normal 2
F Fetal 3
FD Fetal Death 4
FL Fetal Live 5
FN Fetal found at necropsy 6
FX Fetal experimental 7
F Fetal 3 2026-09-03
FD Fetal Death 4 2026-09-03
FL Fetal Live 5 2026-09-03
FN Fetal found at necropsy 6 2026-09-03
FX Fetal experimental 7 2026-09-03
K Cull (scheduled) 8
M Medical cull (non-scheduled) 9
ND Non-vaginal (C-section) dead 10
NT Not pregnant at assessment 11
ND Non-vaginal (C-section) dead 10 2026-09-03
NT Not pregnant at assessment 11 2026-09-03
S Cull 12
X Experimental 13
1 change: 0 additions & 1 deletion nbri_ehr/resources/data/editable_lookups.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ ehr_lookups country Colony Management Country
ehr_lookups country_category Colony Management Country Category
ehr_lookups daily_enrich_codes Behavior Daily enrichment codes.
ehr_lookups data_category Clinical Data Categories Used in datasets.
ehr_lookups death_reason Colony Management Death Reason
ehr_lookups death_type Colony Management Death Type Death type codes.
ehr_lookups delivery_mode Colony Management Delivery Mode
ehr_lookups delivery_state Colony Management Delivery State
Expand Down
1 change: 0 additions & 1 deletion nbri_ehr/resources/data/lookup_sets.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ country Country value title
country_category Country Category value title
daily_enrich_codes Daily Enrichment Codes value
data_category Data Category Field Values value
death_reason Death Reason value
death_type Death Type value title
delivery_mode Delivery Mode value title
delivery_state Delivery State value title
Expand Down
1 change: 0 additions & 1 deletion nbri_ehr/resources/data/lookupsManifest.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ country
country_category
daily_enrich_codes
data_category
death_reason
death_type
delivery_mode
delivery_state
Expand Down
1 change: 0 additions & 1 deletion nbri_ehr/resources/data/lookupsManifestTest.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ country
country_category
daily_enrich_codes
data_category
death_reason
death_type
delivery_mode
delivery_state
Expand Down
17 changes: 17 additions & 0 deletions nbri_ehr/resources/queries/study/arrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ require("ehr/triggers").initScript(this);
var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
var idsToSync = [];

// generation 0 is a real value, so emptiness cannot be tested by truthiness the way the other demographics fields test it
function isBlankGeneration(value) {
return value === null || value === undefined || value === '';
}

// opens one assignment record against the animal being entered; each dataset carries the assignment under its own field
function createAssignment(scriptErrors, dataset, fieldName, value, row) {
if (!value)
Expand Down Expand Up @@ -46,6 +51,11 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
EHR.Server.Utils.addError(scriptErrors, 'Id', 'Animal Id ' + row.Id + ' is already in use. Please use a different Id.', 'ERROR');
}

// only a form entry can be held to a generation: the form seeds it to 0, while a study import has no such column to carry
if (!row.rearrival && !helper.isETL() && helper.isEHRDataEntry() && helper.getEvent() == 'insert' && isBlankGeneration(row['Id/demographics/generation'])) {
EHR.Server.Utils.addError(scriptErrors, 'Id/demographics/generation', 'Generation is required', 'ERROR');
}

if (row.eventDate) {
row.date = row.eventDate;
}
Expand All @@ -69,6 +79,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
row.gender = row['Id/demographics/gender'] || null;
row.geographic_origin = row['Id/demographics/geographic_origin'] || null;
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();
Expand Down Expand Up @@ -152,6 +163,12 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
hasUpdates = true;
}

if (!isBlankGeneration(row.generation) && row.generation !== data.generation)
{
obj.generation = row.generation;
hasUpdates = true;
}

if (row.sire && row.sire !== data.sire)
{
obj.sire = row.sire;
Expand Down
24 changes: 24 additions & 0 deletions nbri_ehr/resources/queries/study/birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ var idsToSync = [];
// study.birth yet when each one is checked, so this is the only way the one-birth-per-conception rule can see them.
var conceptIdsInSave = [];

// generation 0 is a real value, so emptiness cannot be tested by truthiness the way the other demographics fields test it
function isBlankGeneration(value) {
return value === null || value === undefined || value === '';
}

// opens one assignment record against the animal being entered; each dataset carries the assignment under its own field
function createAssignment(scriptErrors, dataset, fieldName, value, row) {
if (!value)
Expand Down Expand Up @@ -146,6 +151,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
birth: row.date || null,
gender: row['Id/demographics/gender'] || null,
socialCode: row['Id/demographics/socialCode'] || null,
generation: isBlankGeneration(row['Id/demographics/generation']) ? null : parseInt(row['Id/demographics/generation'], 10),
taskid: row.taskid,
remark: row.remark,
QCStateLabel: row.QCStateLabel,
Expand All @@ -161,6 +167,19 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
obj.species = helper.getJavaHelper().getSpecies(obj.dam);
}

// the conception window fills this in, so a blank one means a save that bypassed the form
if (isBlankGeneration(obj.generation)) {
var damGeneration = obj.dam ? triggerHelper.getGeneration(obj.dam) : null;
if (damGeneration === null) {
var generationWarning = obj.dam
? 'No generation is recorded for dam ' + obj.dam + ', so this birth was recorded as generation 1'
: 'This birth record has no dam, so it was recorded as generation 1';
EHR.Server.Utils.addError(scriptErrors, 'Id/demographics/generation', generationWarning, 'WARN');
}

obj.generation = (damGeneration === null ? 0 : damGeneration) + 1;
}

if (!oldRow) {
//if not already present, we insert into demographics
helper.getJavaHelper().createDemographicsRecord(row.Id, obj, extraDemographicsFieldMappings);
Expand Down Expand Up @@ -198,6 +217,11 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
hasUpdates = true;
}

if (!isBlankGeneration(obj.generation) && obj.generation !== data.generation) {
record.generation = obj.generation;
hasUpdates = true;
}

if (obj.performedby && obj.performedby !== data.performedby) {
record.performedby = obj.performedby;
hasUpdates = true;
Expand Down
3 changes: 1 addition & 2 deletions nbri_ehr/resources/queries/study/deathNotification.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ SELECT
Id,
date,
taskid,
performedBy.DisplayName AS performedBy,
reason.title AS reason
performedBy.DisplayName AS performedBy
FROM study.deaths
9 changes: 0 additions & 9 deletions nbri_ehr/resources/queries/study/deaths.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="reason">
<columnTitle>Disposition</columnTitle>
<fk>
<fkDbSchema>ehr_lookups</fkDbSchema>
<fkTable>death_reason</fkTable>
<fkColumnName>value</fkColumnName>
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="deathWeight">
<columnTitle>Death Weight (kg)</columnTitle>
</column>
Expand Down
1 change: 0 additions & 1 deletion nbri_ehr/resources/queries/study/deaths/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<column name="Id/Demographics/species"/>
<column name="date"/>
<column name="type"/>
<column name="reason"/>
<column name="deathWeight"/>
<column name="remark"/>
<column name="performedBy"/>
Expand Down
3 changes: 3 additions & 0 deletions nbri_ehr/resources/queries/study/demographics.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="generation">
<columnTitle>Generation</columnTitle>
</column>
<column columnName="cites">
<columnTitle>CITES</columnTitle>
</column>
Expand Down
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/study/demographics/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<column name="dam"/>
<column name="sire"/>
<column name="socialCode"/>
<column name="generation"/>
<column name="disposition"/>
<column name="termination"/>
<column name="implantNumber"/>
Expand Down
10 changes: 10 additions & 0 deletions nbri_ehr/resources/queries/study/pregnancy.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
<fkColumnName>ConceptId</fkColumnName>
</fk>
</column>
<column columnName="type">
<columnTitle>Delivery Mode</columnTitle>
<required>false</required>
<fk>
<fkDbSchema>ehr_lookups</fkDbSchema>
<fkTable>delivery_mode</fkTable>
<fkColumnName>value</fkColumnName>
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
</columns>
</table>
</tables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@
<column columnName="socialCode">
<datatype>varchar</datatype>
</column>
<column columnName="generation">
<datatype>integer</datatype>
</column>
<column columnName="CITES">
<datatype>varchar</datatype>
</column>
Expand Down Expand Up @@ -561,9 +564,6 @@
<propertyURI>http://cpas.labkey.com/Study#VisitDate</propertyURI>
<conceptURI>http://cpas.labkey.com/Study#VisitDate</conceptURI>
</column>
<column columnName="reason">
<datatype>varchar</datatype>
</column>
<column columnName="deathWeight">
<datatype>double</datatype>
</column>
Expand Down Expand Up @@ -1367,7 +1367,6 @@
<conceptURI>http://cpas.labkey.com/Study#VisitDate</conceptURI>
</column>
<column columnName="type">
<columnTitle>Type</columnTitle>
<datatype>varchar</datatype>
</column>
<column columnName="result">
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/views/necropsy.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
schemaName: 'study',
queryName: 'deaths',
filterArray: filterArray,
columns: 'Id,Id/demographics/species,Id/demographics/gender,date,reason,deathWeight,Id/lastProtocol/protocol,Id/lastProject/project',
columns: 'Id,Id/demographics/species,Id/demographics/gender,date,deathWeight,Id/lastProtocol/protocol,Id/lastProject/project',
},
title: 'Death',
renderTo: 'animalDeath',
Expand Down
18 changes: 17 additions & 1 deletion nbri_ehr/resources/web/nbri_ehr/model/sources/Arrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ EHR.model.DataModelManager.registerMetadata('Arrival', {
byQuery: {
'study.arrival': {
'cage': {
// allowBlank: false,
allowBlank: false,
nullable: false,
columnConfig: {
fixed: true,
width: 200
Expand Down Expand Up @@ -55,6 +56,21 @@ EHR.model.DataModelManager.registerMetadata('Arrival', {
width: 200
}
},
// an arriving animal establishes its own lineage, so it starts at generation 0
'Id/demographics/generation': {
allowBlank: false,
nullable: false,
getInitialValue: function(v) {
return Ext4.isEmpty(v) ? 0 : v;
},
editorConfig: {
minValue: 0
},
columnConfig: {
fixed: true,
width: 120
}
},
// an animal joins the colony already assigned to a project, a protocol and a group; the trigger script
// opens the matching assignment record for each one
project: {
Expand Down
14 changes: 13 additions & 1 deletion nbri_ehr/resources/web/nbri_ehr/model/sources/Birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ EHR.model.DataModelManager.registerMetadata('Birth', {
}
},
'cage': {
// allowBlank: false,
allowBlank: false,
nullable: false,
columnConfig: {
fixed: true,
width: 200
Expand Down Expand Up @@ -145,6 +146,17 @@ EHR.model.DataModelManager.registerMetadata('Birth', {
columnConfig: {
width: 200
}
},
// derived from the dam by the conception window, but left editable so it can be corrected by hand
'Id/demographics/generation': {
allowBlank: false,
nullable: false,
editorConfig: {
minValue: 0
},
columnConfig: {
width: 120
}
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Death.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ EHR.model.DataModelManager.registerMetadata('Death', {
nullable: false,
columnConfig: {
width: 160
}
},
reason: {
columnConfig: {
width: 160
},
lookup: {
filterArray: [LABKEY.Filter.create('date_disabled', null, LABKEY.Filter.Types.ISBLANK)]
}
},
remark: {
Expand Down
12 changes: 9 additions & 3 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Pregnancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ EHR.model.DataModelManager.registerMetadata('Pregnancy', {
project: {
hidden: true,
},
type: {
hidden: true,
},
diagnosis: {
hidden: true,
},
Expand All @@ -26,9 +23,18 @@ EHR.model.DataModelManager.registerMetadata('Pregnancy', {
nullable: false,
},
conceptId: {
allowBlank: false,
nullable: false,
columnConfig: {
width: 150
}
},
// shares the delivery_mode lookup with study.birth, but is optional here: an outcome can be recorded
// before the delivery mode is known
type: {
columnConfig: {
width: 200
}
}
},

Expand Down
Loading