feat: suggest custom subject ids from a dedicated endpoint instead of the full subject list - #1566
Merged
joshunrau merged 6 commits intoSep 27, 2026
Conversation
david-roper
force-pushed
the
feat/subject-custom-ids-endpoint
branch
from
September 25, 2026 18:16
b97bfda to
b271908
Compare
david-roper
force-pushed
the
feat/subject-custom-ids-endpoint
branch
from
September 25, 2026 19:39
b271908 to
4b4b13e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1536
Why
The start-session form's identifier combobox was built from
GET /v1/subjects?groupId=, whichreturns every subject in the group, including names, dates of birth and sex. The page kept only the
ids of subjects without full personal information. That meant:
though the page never showed it.
and it refetched on every visit and whenever the tab became visible again.
groupIdwas optional, so an admin with no current group received every subject inthe instance.
What changed
GET /v1/subjects/groups/:groupId/custom-ids(
@RouteAccess({ action: 'read', subject: 'Subject' }),groupIdthroughValidObjectIdPipe).SubjectsService.findCustomIdsfilters in MongoDB and returns only ids (select: { id: true }).Its
wherehas three parts:accessibleQuery(ability, 'read', 'Subject'), so callers only see subjects they may read;{ groupIds: { has: groupId } };ORmatching a subject where any ofdateOfBirth,firstName,lastNameorsexisnullor
{ isSet: false }. On MongoDB a Prismanullfilter does not match a missing field, anda custom-id subject's name fields are missing, not null.
$SubjectCustomIds, derived from$Subject.shape.id.useSubjectCustomIdsQueryandsubjectCustomIdsQueryOptions, keyed on['subjects', 'custom-ids', groupId]. The start-session route and its loader use them in place ofuseSubjectsQuery. With no current group, the hook makes no request and there are no suggestions.The new route has three segments, so
@Get(':id')cannot shadow it even thougheslint --fixorders it after that handler.
Tests
API unit tests (
apps/api/src/subjects/__tests__/subjects.service.spec.ts,findCustomIds): only ids are selected and returned; the ability's filter is applied (checkedwith a conditional rule); the group is filtered on; the
null/isSet: falseclause covers allfour fields.
Web unit tests (
apps/web/src/hooks/__tests__/useSubjectCustomIdsQuery.test.ts): the endpointURL; no request without a group; a response that is not a list of ids is rejected; switching
groups does not reuse another group's cached list.
E2E (
testing/src/specs/start-session.spec.ts,custom identifier suggestions):birth and sex;
[].These use a new
findSubjectCustomIdsmethod intesting/src/support/api-client.ts. Theexisting test that picks a suggested id in the UI still passes.
Checked against broken code: with the
isSet: falseclause removed, the first e2e test fails.With the ability dropped, the group-manager test fails.
pnpm lintandpnpm testpass.pnpm test:e2epasses exceptsubject-detail.spec.ts › should plot a selected measure on the graph tab…, which is flaky andunrelated to this change. It also failed on another branch before this work, and passed on reruns.
Not in scope
The data hub still loads the full subject list with the same query, plus a second list filtered by
hasRecord. This change does not touch it.