Skip to content

Create Biocontainment Observation Review Page - #1021

Merged
RameshRapa merged 19 commits into
release26.3-SNAPSHOTfrom
26.3_fb_createBiocontainmentObsReviewPage
Nov 17, 2026
Merged

RameshRapa merged 19 commits into
release26.3-SNAPSHOTfrom
26.3_fb_createBiocontainmentObsReviewPage

Conversation

@jallentxbiomed

Copy link
Copy Markdown
Contributor

New React page (src/client/BiocontainmentObservationReview/)

  • Added a review page, registered in entryPoints.js and linked from a new Biocontainment section on the EHR landing page (begin.html).
  • Observations Awaiting Review grid: shows Review Required rows, uses single selection, and pages at 100 rows. The new hidden Review.qview.xml view sorts it by location, date and animal.
  • Detail panel for the selected observation:
    • shows all 13 scored parameters next to the animal's prior observation at the same location, with a link to its history;
    • shows the clinical score and the prior score.
  • Edit Values mode:
    • lets the reviewer correct scored values and carry-overs;
    • requires a reason for each changed parameter;
    • lets the reviewer edit the comment (80-character limit, no reason needed).
  • Approve observation button: approves one record at a time and shows server rejections (for example, author approving their own record) on the page.
  • Footer link to observations approved in the last 7 days.
  • Supporting files: api/observation.ts (fetch, approve, correct, prior lookup), constants/fields.ts (scored fields and their allowed values from TXB 904-1), services/clinicalScore.ts, services/formatDate.ts, page styles.

Trigger script (queries/study/BiocontainmentObservations.js, new)

  • New records start as Review Required, however they arrive.
  • Changing a scored value, a carry-over or the comment sends an approved record back to Review Required.
  • Manual corrections require a reason for each changed parameter.
  • An ETL re-merge with identical values keeps the existing approval.
  • Approving checks that the approver isn't the record's author. It then records:
    • reviewedBy;
    • reviewedByName, the printed name;
    • reviewedDate;
    • reviewMeaning.

Java

  • SNPRC_EHRTriggerHelper.getPrintedName() returns the user's first and last name, or their display name if either is missing. It runs server-side, so approvers don't need permission to see user details.

Dataset and query metadata

  • datasets_metadata.xml adds reviewedBy, reviewedByName, reviewedDate and reviewMeaning to the dataset.
  • BiocontainmentObservations.query.xml formats date, created and reviewedDate as MM/dd/yyyy HH:mm.

ETL

  • etls/BiocontainmentObservations.xml adds a QCStateLabel constant. Without it, rows from CAMP default to Completed, and the trigger can't set Review Required.

Styles

  • Moved the shared grid-panel styles out of sndLookupsManagement.scss into Shared/styles/components/_labkeyGridPanel.scss, so SND Lookups and the review page both use them. The rules themselves are unchanged.

Tests (tests/)

  • 57 React Testing Library tests: the page, the detail panel, the API calls, the clinical score, the field definitions and date formatting.

jallentxbiomed and others added 12 commits September 15, 2026 09:32
Replaces the module's own eslint 7 and airbnb config with @labkey/eslint-config, drops the react-hot-loader entry wrappers that @labkey/build no longer supports, pins cheerio so the lock can be regenerated from package.json, and regenerates the lock.
The shared config only names ts/tsx, so the module's .jsx components were skipped, and linting from the module root walked resources/ and .gradle/ for minutes.
Carry-over is a Yes/No dropdown next to each value that has one. It shares
its parameter's reason for change, and the trigger counts a carry-over
change as a change to that parameter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWzj7SGx4GZBcu9V5GsPgW
}

function onInsert(helper, 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.

return;
}

if (row.QCStateLabel === COMPLETED && 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.

Approval doesn’t check that the reviewer saw the current version, so i think we need to send modified with the approval, and in the trigger reject it if it doesn’t match oldRow.modified. approveObservations sends only {lsid, QCStateLabel}. EHR fills in the other fields from the database, so the server approves whatever is stored at that moment.

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 an administrative user manually reverts row.QCStateLabel from Completed to Review Required without changing any scored parameter or comment, changedFields and commentChanged will evaluate to false. As a result, clearReview(row) will not be called, leaving the previous reviewedBy, reviewedByName, and reviewedDate values attached to a row in Review Required state So need to add a condition to clear review fields if QCStateLabel is explicitly changed back to Review Required


const record = focused && focused.lsid === focusedLsid ? focused : undefined;

const onApprove = async (lsid: string) => {

@RameshRapa RameshRapa Nov 9, 2026 •

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.

The Approve button stays enabled while the detail panel has unsaved changes. Clicking it approves the stored values, closes the panel and loses the edits. Either disable Approve button or ask for confirmation. Consider passing an isEditing / hasChanges state back to BiocontainmentObservationReview or prompting the user before switching selections if unsaved corrections exist.

const lsid = model.selections?.size === 1 ? Array.from(model.selections)[0] : undefined;
return (
<div className="manage-buttons">
<Button bsStyle="success" disabled={!lsid} onClick={() => onApprove(lsid)}>

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.

The Approve button stays enabled while the detail panel has unsaved changes. Clicking it approves the stored values, closes the panel and loses the edits. Either disable Approve or ask for confirmation.

{prior && <td className="prior-value">{prior[f.name] ?? '-'}</td>}
<td>
{isEditing ? (
<select

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.

When a scored field is empty, the dropdown in edit mode shows 0 (the first option) instead of blank, so the reviewer may think the value is 0. Picking 0 also doesn’t register as a change, so a missing value can’t be set to 0 without picking another value first. Add an empty so missing values show as blank.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At this point in development scored fields cannot be blank or empty. Null implementation on the CAMP side has not been fully decided yet, and will need to be covered in a future story, so there are no blank values.

// Single selection, as in SndLookupsManagement's TableGridPanel: ticking a second row replaces the first.
// The detail pane follows the one selected row.
useEffect(() => {
const selected = model.selections ? Array.from(model.selections) : [];

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.

runtime Error can occuur when model is undefined on initial mount. model is retrieved as queryModels[MODEL_ID]. Before the injected query model is fully registered by withQueryModels, model can be undefined

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With the way withQueryModels currently works, it creates its model in its constructor, so it always exists on first render. There should never be an instance where model is undefined for this implementation.

* The name printed on an electronic signature: first and last name, or the display name if either is missing.
* Read from the User object so approvers don't need the "See User and Group Details" role that core.Users requires.
*/
public String getPrintedName()

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.

Null checks for this method

let isCurrent = true;
fetchPriorObservation(row)
.then(p => isCurrent && setPrior(p))
.catch(e => isCurrent && setErrorMessage(e?.exception ?? 'Could not load the prior observation'));

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.

In BiocontainmentObservationReview.tsx (line 21), errorText is defined as error?.exception ?? error?.message ?? 'Unexpected error' because LabKey JavaScript APIs and network errors may populate message instead of exception. Here, only exception is checked, which can mask standard network or JavaScript exception messages.

setIsEditing(false);
onSaved();
} catch (error) {
setErrorMessage(error?.exception ?? 'Save failed');

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.

In BiocontainmentObservationReview.tsx (line 21), errorText is defined as error?.exception ?? error?.message ?? 'Unexpected error' because LabKey JavaScript APIs and network errors may populate message instead of exception. Here, only exception is checked, which can mask standard network or JavaScript exception messages.

setIsEditing(false);
}}
>
Cancel

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 a save attempt fails and sets errorMessage, clicking "Cancel" currently exits edit mode but leaves the stale error message displayed on the read-only view

'modified',
].concat(...SCORED_FIELDS.map(f => [f.name, `${f.name}Comments`].concat(f.carryOver ? [f.carryOver] : [])));

export type ObservationRow = Record<string, any>;

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.

Record<string, any> is completely open and permits typos when accessing core properties (row.Id, row.Location, row.date, row['createdBy/DisplayName'], row.QCStateLabel, etc.)

@labkey-bpatel labkey-bpatel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi! Could you please review this support ticket related to the TC test failure? I'm mentioning it here since it's related to BiocontainmentObservations, and it looks like this PR includes additional changes related to it.

carryOver: co ? row[co] : undefined,
reason: '',
...edits[field],
...patch,

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.

When the new reason matches the old one, the error says “A reason is required”, which is confusing. This needs to be “must differ from the previous reason”

const pad = (n: number) => String(n).padStart(2, '0');

export const formatDateTime = (value: Date | string): string => {
if (!value) return '';

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 can return it returns NaN for a date it can’t parse. It is better to guard this with isNaN(d.getTime()) before returning.

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.

}

// 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

reloadGrid(true);
} catch (e) {
// Author-as-approver and missing-role rejections arrive here from the server
setError(errorText(e));

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.

When the trigger rejects an approval because the record changed after the reviewer opened it, the page shows the error but keeps the old copy. Clicking Approve again fails the same way until the reviewer deselects and reselects the row or reloads the page, and the message doesn’t say how to reload. we need to refetch/reload the record so the panel shows the current version.

changed.forEach(function(field){
var reason = row[field + 'Comments'];
if (!reason || sameValue(reason, oldRow[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.


function sameDate(a, b){
var x = toMillis(a), y = toMillis(b);
return isNaN(x) || isNaN(y) ? sameValue(a, b) : x === y;

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.

sameDate() compares milliseconds, but EHR drops the milliseconds from row.date before onUpdate runs . oldRow.date keeps them, so any record whose date has milliseconds always looks like its date changed, even when nobody touched it.

// 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.


requireValues(scriptErrors, row);

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

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', 'ERROR');

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.

The error doesn’t say which field is missing. just add the field name here so it gives the exact field which needs to be required.

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.

);
// The comment is free text, so it is its own reason; changing it still sends the record back for approval
const commentChanged = comment !== undefined && comment.trim() !== (row.Comment ?? '');
const hasChanges = changed.length > 0 || commentChanged;

@RameshRapa RameshRapa Nov 11, 2026 •

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.

A correction can be saved while another value is still missing, and then fails. this hasChanges only looks at edited fields. If a record is missing Bleeding and the reviewer corrects Stool, Save is enabled, but the server rejects the save with “A value is required for Bleeding” (.js:115). Keep Save disabled until every missing value has been filled in.

<Row className="observation-review__panels">
<Col className="observation-review__grid" lg={5} xs={12}>
<ReviewGridPanel
canApprove={!!record && !isEditing}

@RameshRapa RameshRapa Nov 11, 2026 •

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.

Approve is still enabled for a record with missing values. The page now shows Missing, but Approve still sends the request, and the server rejects it. Disable Approve when any scored value is missing.


const reloadGrid = (clearSelections: boolean) => setReload(r => ({ key: r.key + 1, clearSelections }));

useEffect(() => {

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.

the Loaded errors stay on screen after you pick another record. Clear the error whenever focusedLsid changes.

});

// Sends the version the reviewer saw; the trigger rejects the approval if the record has changed since
export const approveObservation = (lsid: string, viewedModified: string): Promise<any> =>

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.

modified is optional in the type. If it’s ever missing, the user sees the misleading “changed after you opened it” error.

@RameshRapa
RameshRapa self-requested a review November 17, 2026 21:50
@RameshRapa
RameshRapa merged commit 9f86703 into release26.3-SNAPSHOT Nov 17, 2026
7 of 8 checks passed
@RameshRapa
RameshRapa deleted the 26.3_fb_createBiocontainmentObsReviewPage branch November 17, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants