fix(clinician-share): a document share exposes only the document

Sharing a single document from the vault minted a full-record share: the
create form always defaulted `resourceTypes` to ["Patient","Observation"]
and never signalled a documents-only intent, so the served /c/<token> view
aggregated the whole doctor report — every vital, lab, medication and
wellness figure — alongside the attached file. An empty section blob was
indistinguishable from "defaults", so the report always resolved to the
full record.

Introduce an explicit documents-only share:

- add a `documentOnly` flag to the create payload; when set the server
  forces an empty report scope (all-off sections, no FHIR resource types,
  FHIR API off) and requires at least one document, so a document link can
  never widen into a record — whatever the body sends.
- gate the clinician-view aggregation on an enabled section: a share with
  no section on never calls the report aggregator, so no health metric
  leaves the database. The recipient sees only the attached document(s).
- the document detail Share action opens the create form in documents-only
  mode: hide the FHIR toggle, the FHIR resource-type checkboxes and the
  history-range selector, keep the picker/label/expiry/passphrase, and
  always carry the launched document into the created link.
- Settings sharing keeps the full record-share form unchanged.

Extract the create-payload builder as a pure function and cover the scope
contract, the empty-scope data load, and the served-view metric-free
guarantee with tests; refresh the share e2e and regenerate the OpenAPI
contract.
This commit is contained in:
Marc-André Bombeck committed 2026-07-10 00:18:57 +02:00
1 parent fa42c8bc0b
commit d4965033c2
13 files changed
+503 -92

No files matched your search

@@ -25,11 +25,15 @@ vi.mock("@tanstack/react-query", () => ({
}));
import { I18nProvider } from "@/lib/i18n/context";
import { ShareLinkCreateForm } from "../share-link-create-form";
import {
ShareLinkCreateForm,
buildShareLinkCreatePayload,
} from "../share-link-create-form";
import type { PickedDocument } from "../share-document-picker";
function render(
props: {
documentOnly?: boolean;
initialDocuments?: PickedDocument[];
initialLabel?: string;
} = {},
@@ -81,4 +85,74 @@ describe("<ShareLinkCreateForm> — shared create flow", () => {
// A seeded set surfaces the EXIF note the picker path also shows.
expect(html).toContain("Camera metadata");
});
it("document-only mode hides every record-scope control but keeps expiry + the doc", () => {
const html = render({
documentOnly: true,
initialDocuments: [{ id: "doc-1", title: "Blood panel 2026" }],
initialLabel: "Blood panel 2026",
});
// No record-scope UI: no FHIR toggle, no FHIR resource-type checkboxes, no
// history-range selector — none of those apply to a document link.
expect(html).not.toContain('id="share-fhir"');
expect(html).not.toContain('id="share-range"');
expect(html).not.toContain('id="share-rt-Observation"');
// Expiry, label, and the pre-attached document all stay.
expect(html).toContain('id="share-expiry"');
expect(html).toContain('value="Blood panel 2026"');
expect(html).toContain('data-testid="share-attached-chips"');
expect(html).toContain("1 of 50 selected");
});
});
describe("buildShareLinkCreatePayload — scope contract", () => {
const common = {
label: " Blood panel 2026 ",
rangeDays: 30,
expiryDays: 30,
};
it("document-only: empty report scope, FHIR off, and the launched doc always rides along", () => {
const payload = buildShareLinkCreatePayload({
...common,
// Even if the caller state still holds record-scope values, they must be
// dropped: a document link never carries a health scope.
allowFhirApi: true,
resourceTypes: ["Patient", "Observation"],
documentIds: ["doc-1"],
documentOnly: true,
});
expect(payload.resourceTypes).toEqual([]);
expect(payload.allowFhirApi).toBe(false);
expect(payload.documentOnly).toBe(true);
// No report sections are ever sent for a document link.
expect(payload).not.toHaveProperty("sections");
// The launched document is always in the created link (pre-attach fix).
expect(payload.documentIds).toEqual(["doc-1"]);
expect(payload.label).toBe("Blood panel 2026");
});
it("record share: keeps the full scope and omits documentIds when none picked", () => {
const payload = buildShareLinkCreatePayload({
...common,
allowFhirApi: false,
resourceTypes: ["Patient", "Observation"],
documentIds: [],
documentOnly: false,
});
expect(payload.resourceTypes).toEqual(["Patient", "Observation"]);
expect(payload).not.toHaveProperty("documentIds");
expect(payload).not.toHaveProperty("documentOnly");
});
it("record share: attaches the picked documents when the owner chose some", () => {
const payload = buildShareLinkCreatePayload({
...common,
allowFhirApi: false,
resourceTypes: ["Patient", "Observation"],
documentIds: ["a", "b"],
documentOnly: false,
});
expect(payload.documentIds).toEqual(["a", "b"]);
});
});