Repository navigation
Create Biocontainment Observation Review Page - #1021
Conversation
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.
…ainmentObsReviewPage
…default value to ETL definition
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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)}> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) : []; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 ''; |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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> => |
There was a problem hiding this comment.
modified is optional in the type. If it’s ever missing, the user sees the misleading “changed after you opened it” error.
…nt observation fields added as part of this PR.
New React page (src/client/BiocontainmentObservationReview/)
Trigger script (queries/study/BiocontainmentObservations.js, new)
Java
Dataset and query metadata
ETL
Styles
Tests (tests/)