Skip to content

Hand Written Signature Field #1007

Open

Description

@yassinebha

Description

Is it possible to a have a signature pad for consent like this one :
image

Estimated Difficulty

None

Priority

High

Activity

  1. added
    Feature
    on Oct 24, 2024
  2. added
    Priority: Medium
    Difficulty: High
    Area: Instruments
    Area: Shared
    Upstream
    Needs Decision
    on Sep 27, 2026
  3. joshunrau commented on Oct 26, 2026

    @joshunrau
    Collaborator

    Not implemented on main (d86740e), and upstream has nothing to build on yet. The latest @douglasneuroinformatics/libui-form-types is 1.5.0, and its only type change from our 1.4.0 is an optional variant: 'date' | 'datetime' on date fields. libui 6.18.0 has no signature component.

    What works today

    An INTERACTIVE instrument can draw on a <canvas> and call done({ signature: canvas.toDataURL('image/png') }) (render(done), packages/runtime-core/src/types/instrument.interactive.ts:40). Put it in a SERIES after the consent FORM. This also works for remote assignments, because the gateway forwards data for both series and scalar results (apps/gateway/src/Root.tsx:59-69). A form block cannot do this: Block.render receives only data and t and has no way to set a value.

    Options

    1. A new string variant, variant: 'signature', whose value is a PNG data URL. The value is a string, so both ScalarField conditional types (libui-form-types, and packages/runtime-core/src/types/instrument.form.ts:129-145) already map it to StringField. The record stays $Json and the gateway needs no change. 1.5.0's datetime follows the same pattern.
    2. A new kind: 'signature' with a structured value (strokes). This needs a new ScalarFieldValue member, a new arm in both ScalarField conditional types, a $StaticFieldKind entry, and a renderer wherever the value is shown. Much more work for little gain.
    3. The FILE path. FILE is an instrument kind, not a field, so the signature cannot sit in the consent form. It needs storage (apps/api/src/instrument-records/instrument-records.service.ts:93-97 returns 503 without it), and remote assignments drop files (File instruments can be assigned remotely, but the patient's files are discarded and the record stays pending forever #1708 proposes refusing them). Consent is a main use of remote assignments, so this does not fit.

    I recommend option 1.

    Gotchas with option 1

    • $$FormInstrumentStringField (packages/schemas/src/instrument/instrument.form.ts:30-42) must get the variant by hand. Its satisfies z.ZodType<...> cannot catch a missing union member, because ZodType is declared out Output. runtime-core derives its StringField from the upstream one, so the bump changes its types with no edit there and nothing points you at the schema. Without the variant, InstrumentsService.create rejects every instrument that uses it.
    • translateScalarField (packages/instrument-utils/src/translate.ts:63-97) ends in .exhaustive(), so the compiler flags it. Add 'signature' to the first arm.
    • apps/web/src/hooks/useInstrumentVisualization.ts:219-227 spreads record.data into every row, so the data URL lands in the subject table and in every export from it. xlsx 0.18.5 throws Text length must not exceed 32767 characters in write_ws_xml_cell, and a signature PNG at device resolution can exceed that. The Excel path needs a placeholder for these columns. feat: add the instrument hub and record provenance #1807 rewrites this hook and the subject table and builds the instrument-hub table on the same hook, so land this part after it.
    • The record view lists only measures, and packages/react-core/src/components/InstrumentSummary/InstrumentSummaryGroup.tsx:21-26 prints strings as text. Render signature fields from data as an <img> with a translated alt, found by walking instrument.content for variant: 'signature', including what a dynamic field's render returns. Don't tell authors to add a const measure for it: that copies the data URL into computedMeasures, and from there into the API export.
    • The pad needs pointer events and touch-action: none, or a finger scrolls the page instead of drawing. Breakout Task paddle does not follow a finger dragged across a touch screen #1672 is the same bug in Breakout.
    • runtime-core bundles libui-form-types into its .d.ts (packages/runtime-core/config/api-extractor.json:4), so external authors see the variant only after a @opendatacapture/runtime-v1 release.

    Plan

    1. Upstream: add the variant to libui-form-types. In libui, add a StringFieldSignature component, its arm in StringField.tsx, and a Clear label in libui.json. Plain pointer events and toDataURL are enough, so libui needs no new dependency. Indicate required vs optional fields #390 and Use the form type info to provide software keyboard hints #1586 also change libui's Form and could ship in the same release.
    2. ODC: bump both catalog entries, then update the schema and translate.ts. Put the field in a new demo form, not in DNP_GENERAL_CONSENT_FORM, which the happiness series and several e2e specs drive. Follow .agents/docs/playbooks/add-instrument.md, and also extend the exact instrument list asserted in apps/api/src/demo/__tests__/demo.service.test.ts. Update packages/instrument-guidelines/AGENTS.md (a release; its string section also lacks combobox).
    3. react-core and web: the image in the summary, and the export handling.

    Unit tests: packages/schemas/src/instrument/__tests__/instrument.form.test.ts, packages/instrument-utils/src/__tests__/translate.test.ts, packages/react-core/src/components/InstrumentSummary/__tests__/InstrumentSummary.test.tsx and apps/web/src/utils/__tests__/excel.test.ts. E2E: draw with page.mouse in a new spec modelled on testing/src/specs/form-block.spec.ts, check the image in subject-detail.spec.ts, and run one pass through gateway-assignment.spec.ts.

    Open questions

    • Is a drawn image enough, or must the signature be bound to an identity (signer name, timestamp, audit log entry)?
    • Should signature columns be left out of tabular exports by default? They are identifying, and the subject-table export includes raw data with no opt-out.
    • Should there be a typed-name fallback for keyboard-only users?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: InstrumentsArea: SharedDifficulty: HighFeatureNeeds DecisionPriority: MediumUpstream

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions