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
1 change: 1 addition & 0 deletions nbri_ehr/resources/queries/nbri_ehr/Conception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("ehr/triggers").initScript(this);
39 changes: 39 additions & 0 deletions nbri_ehr/resources/queries/nbri_ehr/Conception.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="Conception" tableDbType="TABLE" useColumnOrder="true">
<tableTitle>Conception Records</tableTitle>
<columns>
<column columnName="rowId">
<isHidden>true</isHidden>
</column>
<column columnName="ConceptId">
<columnTitle>Conception Id</columnTitle>
<required>true</required>
</column>
<column columnName="ConceptDate">
<columnTitle>Conception Date</columnTitle>
</column>
<column columnName="ConceptDate">
<columnTitle>Conception Date</columnTitle>
</column>
<column columnName="ConceptTermDate">
<columnTitle>Conception Term Date</columnTitle>
</column>
<column columnName="Dam">
<required>true</required>
</column>
<column columnName="Sire" />
<column columnName="QCState">
<columnTitle>Status</columnTitle>
<fk>
<fkDbSchema>core</fkDbSchema>
<fkTable>qcstate</fkTable>
<fkColumnName>rowid</fkColumnName>
</fk>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
21 changes: 21 additions & 0 deletions nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="ConceptionsByDam" tableDbType="TABLE">
<javaCustomizer class="org.labkey.nbri_ehr.table.NBRI_EHRCustomizer"/>
<tableTitle>Conceptions by Dam</tableTitle>
<columns>
<column columnName="Id">
<columnTitle>Dam</columnTitle>
</column>
<column columnName="ConceptId">
<columnTitle>Conception Id</columnTitle>
</column>
<column columnName="conceptionOutcome">
<columnTitle>Conception Outcome</columnTitle>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
23 changes: 23 additions & 0 deletions nbri_ehr/resources/queries/nbri_ehr/ConceptionsByDam.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
SELECT
c.Dam AS Id,
c.ConceptId,
c.ConceptDate,
c.ConceptTermDate,
c.Sire,
CASE
WHEN b.conceptId IS NOT NULL THEN 'Live Birth'
WHEN po.conceptId IS NOT NULL THEN COALESCE(po.result, 'Unknown')
ELSE 'Unknown'
END AS conceptionOutcome,
c.Remark,
c.QCState AS qcstate
FROM Conception c
LEFT JOIN (SELECT DISTINCT b.conceptId FROM study.birth b WHERE b.conceptId IS NOT NULL) b
ON b.conceptId = c.ConceptId
LEFT JOIN (SELECT p.conceptId, MAX(p.result.title) AS result FROM study.pregnancy p WHERE p.conceptId IS NOT NULL GROUP BY p.conceptId) po
ON po.conceptId = c.ConceptId
16 changes: 16 additions & 0 deletions nbri_ehr/resources/queries/study/birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
EHR.Server.Utils.addError(scriptErrors, 'Id', 'Birth record already exists for this Id, update existing record to change birth information', 'ERROR');
}

if (!helper.isETL() && row.conceptId) {
if (triggerHelper.totalRecords('nbri_ehr', 'Conception', 'ConceptId', row.conceptId) === 0) {
EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id does not match any conception record', 'WARN');
}

//when updating a record that already carries this conception id, the existing row accounts for one match
var conceptIdThreshold = (oldRow && oldRow.conceptId === row.conceptId) ? 1 : 0;
if (triggerHelper.totalRecords('study', 'birth', 'conceptId', row.conceptId) > conceptIdThreshold) {
EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id is already used by another birth record', 'INFO');
}

if (triggerHelper.totalRecords('study', 'pregnancy', 'conceptId', row.conceptId) > 0) {
EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id is already used by a pregnancy outcome record', 'INFO');
}
}

if (!helper.isETL()) {

if (row.QCStateLabel) {
Expand Down
8 changes: 8 additions & 0 deletions nbri_ehr/resources/queries/study/birth.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="conceptId">
<columnTitle>Conception Id</columnTitle>
<fk>
<fkDbSchema>nbri_ehr</fkDbSchema>
<fkTable>Conception</fkTable>
<fkColumnName>ConceptId</fkColumnName>
</fk>
</column>
<column columnName="remark"/>
<column columnName="performedby"/>
</columns>
Expand Down
19 changes: 19 additions & 0 deletions nbri_ehr/resources/queries/study/pregnancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
require("ehr/triggers").initScript(this);
EHR.Server.Utils = require("ehr/utils").EHR.Server.Utils;

var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'study', 'pregnancy', function(helper, scriptErrors, row, oldRow) {
if (!helper.isETL() && row.conceptId) {
if (triggerHelper.totalRecords('nbri_ehr', 'Conception', 'ConceptId', row.conceptId) === 0) {
EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id does not match any conception record', 'WARN');
}

//when updating a record that already carries this conception id, the existing row accounts for one match
var conceptIdThreshold = (oldRow && oldRow.conceptId === row.conceptId) ? 1 : 0;
if (triggerHelper.totalRecords('study', 'pregnancy', 'conceptId', row.conceptId) > conceptIdThreshold) {
EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id is already used by another pregnancy outcome record', 'INFO');
}

if (triggerHelper.totalRecords('study', 'birth', 'conceptId', row.conceptId) > 0) {
EHR.Server.Utils.addError(scriptErrors, 'conceptId', 'This conception Id is already used by a birth record', 'INFO');
}
}
});

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.ON_BECOME_PUBLIC, 'study', 'pregnancy', function(scriptErrors, helper, row, oldRow) {
if (!helper.isETL()) {

Expand Down
8 changes: 8 additions & 0 deletions nbri_ehr/resources/queries/study/pregnancy.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="conceptId">
<columnTitle>Conception Id</columnTitle>
<fk>
<fkDbSchema>nbri_ehr</fkDbSchema>
<fkTable>Conception</fkTable>
<fkColumnName>ConceptId</fkColumnName>
</fk>
</column>
</columns>
</table>
</tables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
<column columnName="birthProtocol">
<datatype>varchar</datatype>
</column>
<column columnName="conceptId">
<datatype>varchar</datatype>
</column>
</columns>
</table>
<table tableName="blood" tableDbType="TABLE">
Expand Down Expand Up @@ -1364,6 +1367,9 @@
<datatype>varchar</datatype>
<rangeURI>http://cpas.fhcrc.org/exp/xml#fileLink</rangeURI>
</column>
<column columnName="conceptId">
<datatype>varchar</datatype>
</column>
</columns>
</table>
<table tableName="notes" tableDbType="TABLE">
Expand Down
3 changes: 2 additions & 1 deletion nbri_ehr/resources/reports/additionalReports.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ behaviorRemarks Behavior query Behavior Remarks true study BehaviorClinRemarks
clinObsBehavior Behavior query Observations true study behaviorObservations date false false qcstate/publicdata This report contains one record for each encounter with each animal, including surergies, exams, procedures, etc.
clinremarks Clinical query Clinical Remarks true study ClinicalClinRemarks date false false qcstate/publicdata This report contains the clinical remarks entered about each animal
physicalExam Clinical query Exam History True study physicalExam date false false qcstate/publicdata This report displays physical exam data for the selected animal
historicalOther General query Historical True study historicalOther date false false qcstate/publicdata This report displays historical events from legacy systems
historicalOther General query Historical True study historicalOther date false false qcstate/publicdata This report displays historical events from legacy systems
conceptionsByDam Reproductive Management query Conceptions by Dam true nbri_ehr ConceptionsByDam ConceptDate false false qcstate/publicdata This report displays conception records where the selected animal is the dam
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
CREATE TABLE nbri_ehr.Conception
(
RowId SERIAL NOT NULL,
ConceptId VARCHAR(100),
ConceptDate TIMESTAMP,
ConceptTermDate TIMESTAMP,
Remark TEXT,
Dam VARCHAR(100),
Sire VARCHAR(100),
TaskId ENTITYID,
QCState INTEGER,
Container entityId NOT NULL,
Created TIMESTAMP,
CreatedBy USERID,
Modified TIMESTAMP,
ModifiedBy USERID,
CONSTRAINT PK_CONCEPTION PRIMARY KEY (RowId),
CONSTRAINT UQ_CONCEPTION_ConceptId UNIQUE (ConceptId),
CONSTRAINT FK_CONCEPTION_Container FOREIGN KEY (Container) REFERENCES core.Containers (EntityId)
);
CREATE INDEX IX_Nbri_Ehr_Conception_Container ON nbri_ehr.Conception (Container);
25 changes: 25 additions & 0 deletions nbri_ehr/resources/schemas/nbri_ehr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,29 @@
</columns>
</table>

<table tableName="Conception" tableDbType="TABLE">
<tableTitle>Conception</tableTitle>
<auditLogging>DETAILED</auditLogging>
<columns>
<column columnName="RowId"/>
<column columnName="ConceptId"/>
<column columnName="ConceptDate">
<formatString>Date</formatString>
</column>
<column columnName="ConceptTermDate">
<formatString>Date</formatString>
</column>
<column columnName="Remark"/>
<column columnName="Dam"/>
<column columnName="Sire"/>
<column columnName="TaskId"/>
<column columnName="QCState"/>
<column columnName="Container"/>
<column columnName="Created"/>
<column columnName="CreatedBy"/>
<column columnName="Modified"/>
<column columnName="ModifiedBy"/>
</columns>
</table>

</tables>
5 changes: 5 additions & 0 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ EHR.model.DataModelManager.registerMetadata('Birth', {
},
'Id/demographics/gender': {
allowBlank: false
},
conceptId: {
columnConfig: {
width: 150
}
}
}
}
Expand Down
66 changes: 66 additions & 0 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Conception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
EHR.model.DataModelManager.registerMetadata('Conception', {
allQueries: {

},
byQuery: {
'nbri_ehr.Conception': {
RowId: {
allowBlank: true,
nullable: true,
hidden: true
},
ConceptId: {
allowBlank: false,
nullable: false,
columnConfig: {
width: 200
},
},
ConceptDate: {
xtype: 'datefield',
extFormat: LABKEY.extDefaultDateFormat,
columnConfig: {
width: 200
},
},
ConceptTermDate: {
xtype: 'datefield',
extFormat: LABKEY.extDefaultDateFormat,
columnConfig: {
width: 200
},
},
Dam: {
xtype: 'ehr-animalfield',
lookups: false,
allowBlank: false,
nullable: false,
columnConfig: {
width: 200
},
},
Sire: {
xtype: 'ehr-animalfield',
lookups: false,
columnConfig: {
width: 200
},
},
Remark: {
height: 75,
editorConfig: {
resizeDirections: 's'
},
columnConfig: {
width: 300
},
}
},

}
});
5 changes: 5 additions & 0 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Pregnancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ EHR.model.DataModelManager.registerMetadata('Pregnancy', {
result: {
allowBlank: false,
nullable: false,
},
conceptId: {
columnConfig: {
width: 150
}
}
},

Expand Down
3 changes: 2 additions & 1 deletion nbri_ehr/src/org/labkey/nbri_ehr/NBRI_EHRModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String getName()
@Override
public @Nullable Double getSchemaVersion()
{
return 26.000;
return 26.001;
}

@Override
Expand Down Expand Up @@ -236,6 +236,7 @@ private void registerDataEntry()
EHRService.get().registerFormType(new DefaultDataEntryFormFactory(NBRIChemistryImportFormType.class, this));
EHRService.get().registerFormType(new DefaultDataEntryFormFactory(NBRISerologyImportFormType.class, this));
EHRService.get().registerFormType(new DefaultDataEntryFormFactory(NBRIRearrivalFormType.class, this));
EHRService.get().registerFormType(new DefaultDataEntryFormFactory(NBRIConceptionFormType.class, this));
}

@Override
Expand Down
Loading