Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e5c4280
added react page for biocontainment obs review
jallentxbiomed Sep 15, 2026
448c14c
Merge branch 'release26.3-SNAPSHOT' into 26.3_fb_createBiocontainment…
jallentxbiomed Sep 16, 2026
e19a751
Move snprc_ehr npm build to @labkey/build 7 and @labkey/eslint-config
labkey-martyp Sep 18, 2026
089501f
Lint snprc_ehr .jsx sources and skip generated and gradle trees
labkey-martyp Sep 18, 2026
c7cc0f6
changes to review page
jallentxbiomed Sep 21, 2026
644f3c9
fixed merge conflict
jallentxbiomed Sep 25, 2026
d752dc2
Merge branch '26.3_fb_snprc_ehr_npm_build' into 26.3_fb_createBiocont…
jallentxbiomed Sep 25, 2026
765174c
updated dev.tsx
jallentxbiomed Sep 28, 2026
be5d91f
fixed merge conflicts
jallentxbiomed Sep 28, 2026
f4e1ebc
implemented prior observation and clinical score, and added qc state …
jallentxbiomed Sep 28, 2026
deb8acb
Make carry-overs editable on the Biocontainment Observation review page
jallentxbiomed Sep 29, 2026
5bfeccb
performed self-review on code and added jest tests
jallentxbiomed Oct 6, 2026
8832749
Merge branch 'release26.3-SNAPSHOT' into 26.3_fb_createBiocontainment…
jallentxbiomed Nov 5, 2026
f42fd9a
addressed review comments
jallentxbiomed Nov 9, 2026
556c74b
addressed comments
jallentxbiomed Nov 10, 2026
102a807
addressed comments
jallentxbiomed Nov 11, 2026
f50ee09
addressed comments
jallentxbiomed Nov 12, 2026
1d9f9e9
Merge branch 'release26.3-SNAPSHOT' into 26.3_fb_createBiocontainment…
RameshRapa Nov 17, 2026
42c70e0
Updated the test folder dataset xml file with additional biocontainme…
RameshRapa Nov 17, 2026
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
5 changes: 5 additions & 0 deletions snprc_ehr/resources/etls/BiocontainmentObservations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<column source="createdBy" target="createdBy" transformClass="org.labkey.snprc_ehr.columnTransforms.UserTransform"/>
<column source="modifiedBy" target="modifiedBy" transformClass="org.labkey.snprc_ehr.columnTransforms.UserTransform"/>
</columnTransforms>
<!-- The dataset only takes a QC state from a column present in the source; without it every row lands as the
study default (Completed) and the trigger's Review Required is dropped. The trigger decides the final value. -->
<constants>
<column name="QCStateLabel" type="VARCHAR" value="Review Required"/>
</constants>
</destination>
</transform>
<transform id="step2" type="TaskrefTransformStep">
Expand Down
176 changes: 176 additions & 0 deletions snprc_ehr/resources/queries/study/BiocontainmentObservations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Copyright (c) 2026 SNPRC
*/
require("ehr/triggers").initScript(this);

// The 13 scored parameters on TXB 904-1 — each carries its own reason comment (9/1 decision 7)
var SCORED_FIELDS = ['WeightLoss', 'TemperatureChange', 'Responsiveness', 'HairCoat', 'Respiration', 'Petechia',
'Bleeding', 'NasalDischarge', 'FeedEaten', 'FoodEnrichment', 'Stool', 'FluidIntake', 'Dehydration'];

// Carry-over shares its parameter's reason column, so a carry-over change counts as a change to that parameter
var CARRY_OVER = {WeightLoss: 'WeightLossCO', TemperatureChange: 'TemperatureChangeCO', Petechia: 'PetechiaCO',
FeedEaten: 'FeedEatenCO', FoodEnrichment: 'FoodEnrichmentCO', Dehydration: 'DehydrationCO'};

var REVIEW_REQUIRED = 'Review Required';
var COMPLETED = 'Completed';

function sameValue(a, b){
return (a == null ? null : String(a)) === (b == null ? null : String(b));
}

// Trimmed text, with empty and blank both meaning "no value"
function trimmed(value){
var text = value == null ? '' : String(value).trim();
return text === '' ? null : text;
}

function sameNumber(a, b){
return (a == null || a === '' || b == null || b === '') ? sameValue(a, b) : Number(a) === Number(b);
}

function sameCarryOver(a, b){
return !!Number(a) === !!Number(b);
}

// Milliseconds for a date, a Java date, or LabKey's 'yyyy-MM-dd HH:mm:ss.SSS' string; NaN if it can't be read.
// Rhino 1.7R3 can't parse that string, and new Date(javaDate) drops the milliseconds, so neither is used.
function toMillis(value){
if (value == null)
return NaN;
if (typeof value.getTime === 'function')
return Number(value.getTime());
var m = /^(\d{4})[-\/](\d{1,2})[-\/](\d{1,2})[ T](\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?/.exec(String(value));
if (!m)
return NaN;
var ms = m[7] ? Number((m[7] + '00').substring(0, 3)) : 0;
return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Number(m[4]), Number(m[5]), Number(m[6] || 0), ms).getTime();
}

function changedFields(row, oldRow){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An approved record’s ID, date, location or reasons can still be changed without re-review. Only the 13 scored fields, their carry-overs and their comment are counted as changes. Need to include Id, date, Location and the comments fields in the change check.

return SCORED_FIELDS.filter(function(field){
var co = CARRY_OVER[field];
return !sameValue(row[field], oldRow[field]) || (co && !sameCarryOver(row[co], oldRow[co]));
});
}

// Compared to the second: EHR drops the milliseconds from row.date before this trigger runs, but oldRow.date keeps them
function sameDate(a, b){
var x = toMillis(a), y = toMillis(b);
return isNaN(x) || isNaN(y) ? sameValue(a, b) : Math.floor(x / 1000) === Math.floor(y / 1000);
}

// Everything else the approver signed for: the animal, date, location, comment and every reason
function recordChanged(row, oldRow){
return trimmed(row.Id) !== trimmed(oldRow.Id)
|| !sameDate(row.date, oldRow.date)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the sameDate() issue on line 58, this is always true for dates with milliseconds. Clicking Approve on such a record goes into the “changed” branch at line 116, which calls clearReview and returns without an error. The page says “Observation approved.”, but the record stays in Review Required with no signature. The ETL branch (line 107) is affected too: every re-merge resets the approval on those records.

|| !sameNumber(row.Location, oldRow.Location)
|| trimmed(row.Comment) !== trimmed(oldRow.Comment)
|| SCORED_FIELDS.some(function(field){
return trimmed(row[field + 'Comments']) !== trimmed(oldRow[field + 'Comments']);
});
}

var SIGNATURE_FIELDS = ['reviewedBy', 'reviewedByName', 'reviewedDate', 'reviewMeaning'];

// Copies the signature from another row, or clears it when from is null
function setSignature(row, from){
SIGNATURE_FIELDS.forEach(function(f){
row[f] = from ? from[f] : null;
});
}

function clearReview(row){
row.QCStateLabel = REVIEW_REQUIRED;
setSignature(row, null);
}

// Every scored parameter on the form must have a value (LabKey checks this as well as CAMP)
function requireValues(scriptErrors, row){
SCORED_FIELDS.forEach(function(field){
if (row[field] == null || row[field] === '')
EHR.Server.Utils.addError(scriptErrors, field, 'A value is required for ' + field, 'ERROR');
});
}

function onInsert(helper, scriptErrors, row){
requireValues(scriptErrors, row);
clearReview(row);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure that all the values from the form had some value. Even though camp already check this we want to make sure LabKey is also checking here. This will help us when we remove CAMP/DB from the equation.

}

function onUpdate(helper, scriptErrors, row, oldRow){
var changed = changedFields(row, oldRow);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, someone with edit access can change who signed off on a record without actually approving it, which may not meet GLP compliance requirements. The signature fields should only be set by the approval step and cleared when the record goes back for review.

// These need no reason of their own (the comment is free text, and a reason explains itself),
// but changing any of them is still a modification to approve
var otherChange = recordChanged(row, oldRow);

if (helper.isETL()){
// A re-merge with identical values (e.g. after the write-back export) must not undo an approval
if (changed.length || otherChange)
clearReview(row);
else
row.QCStateLabel = oldRow.QCStateLabel;
return;
}

requireValues(scriptErrors, row);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs on approval too. the page needs an empty option in the dropdown so the reviewer can see a value is missing and correct it. If not, skip this check when only the QC state is changing.


if (changed.length || otherChange){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the request asks for Completed and the record has changed, the trigger quietly downgrades it to Review Required and the update still succeeds. An approval should never quietly turn into “not approved”. When row.QCStateLabel === COMPLETED here, add an error instead, e.g. “This observation has changes that must be saved before it can be approved.” That way the caller finds out, whether the change is real or a bug like the one on line 58

// An approval must never quietly become "not approved": the reviewer is told, whether the change is real or a bug
if (row.QCStateLabel === COMPLETED && oldRow.QCStateLabel !== COMPLETED){
EHR.Server.Utils.addError(scriptErrors, 'QCStateLabel', 'This observation has changes that must be saved before it can be approved.', 'ERROR');
return;
}

// Trimmed, so a reason of only spaces is no reason, the same rule the page applies
changed.forEach(function(field){
var reason = trimmed(row[field + 'Comments']);
if (!reason)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!reason) accepts a reason that is empty spaces - " ". The page trims before checking, but the server doesn’t, so a blank reason can still be saved through the grid edit form or the API. Trim the reason before checking it (and before the “same reason” check on line 94), so the server enforces the same rule as the page.

EHR.Server.Utils.addError(scriptErrors, field + 'Comments', 'A reason is required for each changed value', 'ERROR');
else if (reason === trimmed(oldRow[field + 'Comments']))
EHR.Server.Utils.addError(scriptErrors, field + 'Comments', 'Enter a new reason; this one was given for an earlier change', 'ERROR');
else
row[field + 'Comments'] = reason;
});

// The approver approves the record and any modification (9/1 decision 6)
clearReview(row);
return;
}

// Not approved (sent back for review by hand, or any other state): the old signature no longer applies
if (row.QCStateLabel !== COMPLETED){
setSignature(row, null);
return;
}

// Already approved and still approved: the signature can't be edited
if (oldRow.QCStateLabel === COMPLETED){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An approved record’s ID, date, location or reasons can still be changed without re-review

setSignature(row, oldRow);
return;
}

// Approval: the only place the signature is set

// The reviewer must have seen the version being approved; EHR fills in modified, so it is sent under its own name
var viewed = toMillis(row.viewedModified);
if (isNaN(viewed) || viewed !== toMillis(oldRow.modified)){
EHR.Server.Utils.addError(scriptErrors, 'QCStateLabel', 'This observation changed after you opened it. Check the current version and approve again.', 'ERROR');
return;
}

var user = LABKEY.Security.currentUser;

if (sameValue(user.id, oldRow.createdBy)){
EHR.Server.Utils.addError(scriptErrors, 'QCStateLabel', 'This observation must be reviewed by someone other than its author', 'ERROR');
return;
}

// Printed name for the signature record (REQ-028), read in Java so approvers don't need permission to see user details
var triggerHelper = new org.labkey.snprc_ehr.query.SNPRC_EHRTriggerHelper(user.id, LABKEY.Security.currentContainer.id);
var printedName = String(triggerHelper.getPrintedName());

row.reviewedBy = user.id;
row.reviewedByName = printedName;
row.reviewedDate = new Date();
row.reviewMeaning = 'Reviewed and approved';
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<updateUrl/>
<deleteUrl/>
<columns>
<column columnName="date">
<formatString>MM/dd/yyyy HH:mm</formatString>
</column>
<column columnName="created">
<formatString>MM/dd/yyyy HH:mm</formatString>
</column>
<column columnName="reviewedDate">
<formatString>MM/dd/yyyy HH:mm</formatString>
</column>
<column columnName="diCreated">
<isHidden>true</isHidden>
</column>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView" hidden="true">
<columns>
<column name="Location"/>
<column name="Id"/>
<column name="date"/>
<column name="createdBy"/>
<column name="created"/>
</columns>
<sorts>
<sort column="Location"/>
<sort column="date"/>
<sort column="Id"/>
</sorts>
</customView>
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,29 @@
<scale>80</scale>
<columnTitle>Comment</columnTitle>
</column>
<column columnName="reviewedBy">
<datatype>integer</datatype>
<columnTitle>Reviewed By</columnTitle>
<fk>
<fkDbSchema>core</fkDbSchema>
<fkTable>Users</fkTable>
<fkColumnName>UserId</fkColumnName>
</fk>
</column>
<column columnName="reviewedByName">
<datatype>varchar</datatype>
<scale>128</scale>
<columnTitle>Reviewer Printed Name</columnTitle>
</column>
<column columnName="reviewedDate">
<datatype>timestamp</datatype>
<columnTitle>Reviewed Date</columnTitle>
</column>
<column columnName="reviewMeaning">
<datatype>varchar</datatype>
<scale>64</scale>
<columnTitle>Signature Meaning</columnTitle>
</column>
</columns>
</table>
</tables>
12 changes: 11 additions & 1 deletion snprc_ehr/resources/views/begin.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,17 @@
{ name: 'Enter Data', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/ehr-enterData.view' },
]

}
},
{
header: 'Biocontainment',
itemDefaults: {
linkCls: 'none',
style: 'font-weight: bold;'
},
items: [
{ name: 'Biocontainment Observation Review', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/snprc_ehr-BiocontainmentObservationReview.view' }
]
}
]
};

Expand Down
Loading
Loading