Skip to content

Need a raw/formless instrument datatype #740

Open

Description

@gdevenyi

This is essentially form data (json with zod-enforced structure), but without a corresponding form or frontend interface.

This would be for data which would always be programmatically entered, from some other system via an API call.

Activity

  1. joshunrau commented on Sep 27, 2026

    @joshunrau
    Collaborator

    Closing this as stale as part of a backlog cleanup. It has had no activity since it was opened, and a dedicated instrument kind isn't planned. The kinds are still FILE | FORM | INTERACTIVE | SERIES (packages/runtime-core/src/types/instrument.base.ts).

    You can already enter schema-validated JSON programmatically. Define a FORM or INTERACTIVE instrument whose validationSchema describes the data, then create records through POST /v1/instrument-records (or bulk through POST /v1/instrument-records/upload). The API checks each payload against the instrument's schema before storing it (apps/api/src/instrument-records/instrument-records.service.ts).

    If a kind with no UI at all becomes necessary, feel free to reopen this or file a new issue.

  2. gdevenyi commented on Sep 27, 2026

    @gdevenyi
    ContributorAuthor

    Keeping this open for "no UI instrument"

  3. joshunrau commented on Oct 26, 2026

    @joshunrau
    Collaborator

    Still a design question on main (d86740e). Here is what a no-UI kind needs and what it is waiting on.

    What the workaround is missing

    Authoring is nearly free. FormInstrument.Content accepts an array of groups (packages/runtime-core/src/types/instrument.form.ts:289-290), so a FORM with content: [] type-checks and passes $$FormInstrumentContent. The CSV upload reads only validationSchema and internal (apps/web/src/utils/upload.ts:971-985).

    The gap is exposure. Nothing marks an instrument as "data arrives from elsewhere", so a field-less FORM is still offered by Administer Instrument and both remote-assignment pickers (selectAdministrableInstruments, apps/web/src/utils/administrable-instruments.ts:15-25). The API assigns it remotely too: the only instrument checks in apps/api/src/assignments/assignments.service.ts:88 and :279-284 are the group's opt-in list and archival. #1708 is the same gap for FILE. It proposes a per-kind refusal at those two places and in the remote pickers, so a no-UI kind should land after it, join that list, and also be dropped from Administer Instrument.

    Options

    1. Document the workaround. No code, and the exposure stays.
    2. A per-group "API only" switch in Manage Group. No runtime-core change, but it turns a property of the instrument into a setting of each group, and the instrument still has a blank UI.
    3. A new scalar kind with no content. This is my recommendation: the instrument says what it is, nothing can render it, and the API can refuse to assign it.

    Phase 1: one kind registry

    When FILE was added (21695b3), several hand-written kind lists missed it: #1774, #1783, the Kind filter in InstrumentKindDropdown.tsx:21-42 (no File option), the outreach JSON Schema pages (apps/outreach/src/lib/instrument-schemas.ts:9, no file), and SeriesInstrumentRenderer, which shows a FILE item as a blank step. A fifth kind added to the runtime-core types compiles and then fails at runtime:

    • packages/schemas/src/instrument/instrument.base.ts:28, :237 and :321 list the kinds by hand. satisfies accepts an enum narrower than the type, so tsc stays quiet, and then $InstrumentInfo.array() in apps/web/src/hooks/useInstrumentInfoQuery.ts:28 rejects the whole instrument list.
    • ScalarInstrumentRenderer.tsx:155 and SeriesInstrumentRenderer.tsx:225 end in .otherwise(() => null), a blank step.
    • translateInstrument (packages/instrument-utils/src/translate.ts:383-392) throws for a multilingual instrument of any other kind.
    • InstrumentIcon.tsx:23 logs and returns null. apps/web/src/routes/_app/admin/instruments.tsx:167-171 labels any other kind "Form".

    Fix: export a /** @public */ INSTRUMENT_KINDS from runtime-core src/constants.ts and derive InstrumentKind from it, as FileInstrument.FileType derives from FILE_TYPES. packages/schemas already imports that module, so $InstrumentKind = z.enum(INSTRUMENT_KINDS), with .exclude(['SERIES']) for the two scalar enums. Make both renderer matches exhaustive. Key the icon, the labels and the Manage Group sections by kind. PR #1807's useInstrumentKindLabels already returns { [K in InstrumentKind]: string }, which also covers part of #1769. #1783 stays a hand fix: the CLI has no link to packages/schemas (cli/AGENTS.md). Most of these steps fix a bug that exists today, so this phase is worth shipping, each step with its own unit and e2e test, even if the new kind never lands.

    Phase 2: the kind

    • runtime-core: a new types/instrument.<kind>.ts with content?: never, added to the unions in instrument.core.ts and to DiscriminatedInstrument in define.ts. This changes the published API, so packages/instrument-guidelines/AGENTS.md and the reference docs change with it, as part of a release.
    • schemas: a $$<Kind>Instrument, added to $$AnyInstrument (packages/schemas/src/instrument/instrument.core.ts:16-28, which the API parses every uploaded bundle against at instruments.service.ts:102) and to the outreach schema map.
    • instrument-utils: an is<Kind>Instrument guard and a translate<Kind> branch.
    • react-core: ScalarInstrumentRenderer shows a translated placeholder for it, which covers a direct /instruments/render/<id> link and the playground preview.
    • web: exclude it in selectAdministrableInstruments. If the data is form-shaped, also offer it on /upload (apps/web/src/routes/_app/upload/index.tsx:51 asks for FORM only) and in the subject graph (datahub/subjects/$subjectId/graph.tsx:29).
    • api: add it to the File instruments can be assigned remotely, but the patient's files are discarded and the record stays pending forever #1708 refusal. Also refuse it in validateSeriesInstrument (apps/api/src/instruments/instruments.service.ts:799), which checks that the items exist but not what kind they are.
    • playground: a template.

    Unit tests: define.test-d.ts (it infers and rejects content), a new instrument.<kind>.test.ts in packages/schemas, translate.test.ts, ScalarInstrumentRenderer.test.tsx (the placeholder), assignments.service.test.ts and instruments.service.test.ts (the refusals), instrument-records.service.test.ts (create and upload still work), and administrable-instruments.test.ts. E2E: seed a built-in example through apps/api/src/demo/demo.service.ts as FILE did. In datahub.spec.ts, send records with api.uploadRecords and check that they show. In accessible-instruments.spec.ts and remote-assignment.spec.ts, check that it is not offered and that POST /v1/assignments for it returns 422.

    Open questions

    1. The name. Every stored bundle carries it and runtime-core treats a rename as a breaking change, so it is picked once (EXTERNAL, DATA, HEADLESS?).
    2. The data shape: form data, as the body suggests, which keeps the CSV upload and the graph working, or any JSON, like INTERACTIVE?
    3. Credentials. Today a sending system logs in with a user's password and gets a 1h token (apps/api/src/auth/auth.service.ts:82-85), and odc-cli has no command to create or upload records. Is a long-lived token scoped to create InstrumentRecord part of this issue, or a separate one?

    Triage note written with Claude Code. Code references point at main @ d86740e.

  4. added
    Feature
    Priority: Low
    Difficulty: High
    Area: Instruments
    Area: API
    Area: Web
    Area: Shared
    Needs Decision
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: APIArea: InstrumentsArea: SharedArea: WebDifficulty: HighFeatureNeeds DecisionPriority: Low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions