mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
fix(export): make the doctor-report selection controls tell the truth
The export panel rendered twenty data switches and eight of them changed nothing. The grouped selection folded down to twelve flat flags and dropped oxygen saturation, body fat, body composition, resting heart rate, HRV, VO2 max, steps and distance on the way, so a user who switched any of them off still exported the readings in the PDF, in the FHIR bundle, in the package, through a clinician share link and over MCP. Each one now resolves to a flag the aggregator reads, and the rows are excluded at the query rather than fetched and dropped. Three more controls were untruthful in their own way: - The medications switch documented itself as excluding all medication data and excluded the adherence figures only. The drug list and the per-dose administration ledger rode along regardless. Both follow the switch now; the rows are still read, because compliance and the GLP-1 block are computed from them, and they no longer leave the aggregator. - Allergies and family history were gated for the PDF and fetched unconditionally for the FHIR bundle, so a package could carry a compliant PDF and a violating bundle in the same zip. The reads are gated, and a deselected section is not read at all. - The PHQ-9, GAD-7, WHO-5 and SCI screening totals had no per-report control. They rode the mental-health module alone, which has been default-on since v1.29.1, so depression and anxiety screeners reached FHIR bundles, share links and the MCP doctor-visit resource on accounts that never chose to send them. They get their own section key, defaulting off, with the module gate kept as the second lock, and the stale privacy-by-default comment that argued otherwise is corrected. The share link's FHIR promise is removed rather than implemented. The create form offered a toggle and a resource-type picker, the values were persisted and badged on the finished link, and the API description called the toggle a REST reachability switch, while no route has ever answered a share token with FHIR or any other machine-readable format. Serving one is a feature with real security surface and does not belong in a correctness fix. The toggle, the picker, the badge and both claims are gone; the create schema rejects the two keys instead of accepting and ignoring them; the columns stay, unread, so no data is destroyed to undo a promise. Two files are split along seams this change already touched. The measurement-type gating maps and the filter that reads them leave the aggregator for their own module, so the query gate and the output gate cannot disagree; the export panel's control shape and the selection it builds leave the component, so the selection contract can be extended without the rendering. Three accepted-and-discarded wire keys (activity energy, GLP-1, side effects) are dropped: nothing rendered them and nothing read them.
This commit is contained in:
1 parent
b32d1be607
commit
68b9903966
22 files changed
+509
-426
No files matched your search
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* The data-selection controls of the health-record export panel: the state
|
||||
* shape, its starting values, and the wire selection they build.
|
||||
*
|
||||
* Split out of the panel component so the selection contract is testable and
|
||||
* extendable without the client component around it. The panel owns layout and
|
||||
* interaction; this module owns "which controls exist and what each one sends",
|
||||
* which is the part the export route, the aggregator and the control-gating
|
||||
* guard all have to agree with — and the part the grouped-selection work will
|
||||
* replace with a grouped registry, one file, without touching the rendering.
|
||||
*/
|
||||
/**
|
||||
* Every data-selection control this panel renders, as one flat state shape.
|
||||
*
|
||||
* The shape is load-bearing beyond the component: the control-gating
|
||||
* guard (`src/__tests__/doctor-report-control-gating-guard.test.ts`) walks these
|
||||
* keys, folds each one through {@link buildSelectionSections} and
|
||||
* `toDoctorReportPrefs`, and fails the build unless flipping it changes the
|
||||
* resolved selection the aggregator consumes. Adding a control here without a
|
||||
* gating path behind it is a build error, which is how eight controls that
|
||||
* changed nothing stopped being possible.
|
||||
*/
|
||||
export interface SectionState {
|
||||
weight: boolean;
|
||||
bp: boolean;
|
||||
pulse: boolean;
|
||||
oxygenSaturation: boolean;
|
||||
bodyFat: boolean;
|
||||
bodyComposition: boolean;
|
||||
restingHeartRate: boolean;
|
||||
hrv: boolean;
|
||||
vo2max: boolean;
|
||||
steps: boolean;
|
||||
distance: boolean;
|
||||
sleep: boolean;
|
||||
glucose: boolean;
|
||||
medList: boolean;
|
||||
compliance: boolean;
|
||||
mood: boolean;
|
||||
bmi: boolean;
|
||||
labs: boolean;
|
||||
allergies: boolean;
|
||||
familyHistory: boolean;
|
||||
mentalHealthScreeners: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SECTIONS: SectionState = {
|
||||
weight: true,
|
||||
bp: true,
|
||||
pulse: true,
|
||||
oxygenSaturation: true,
|
||||
bodyFat: true,
|
||||
bodyComposition: false,
|
||||
restingHeartRate: false,
|
||||
hrv: false,
|
||||
vo2max: false,
|
||||
steps: false,
|
||||
distance: false,
|
||||
sleep: false,
|
||||
glucose: true,
|
||||
medList: true,
|
||||
compliance: true,
|
||||
mood: false, // privacy default
|
||||
bmi: true,
|
||||
labs: true,
|
||||
allergies: true,
|
||||
familyHistory: true,
|
||||
// Depression / anxiety / wellbeing / insomnia screening totals — opt-in,
|
||||
// same stance as mood.
|
||||
mentalHealthScreeners: false,
|
||||
};
|
||||
|
||||
export function buildSelectionSections(s: SectionState) {
|
||||
return {
|
||||
vitals: {
|
||||
weight: s.weight,
|
||||
bp: s.bp,
|
||||
pulse: s.pulse,
|
||||
oxygenSaturation: s.oxygenSaturation,
|
||||
bodyFat: s.bodyFat,
|
||||
bodyComposition: s.bodyComposition,
|
||||
},
|
||||
cardioFitness: {
|
||||
restingHeartRate: s.restingHeartRate,
|
||||
hrv: s.hrv,
|
||||
vo2max: s.vo2max,
|
||||
},
|
||||
activity: {
|
||||
steps: s.steps,
|
||||
distance: s.distance,
|
||||
sleep: s.sleep,
|
||||
},
|
||||
glucose: s.glucose,
|
||||
medications: { list: s.medList, compliance: s.compliance },
|
||||
mood: s.mood,
|
||||
bmi: s.bmi,
|
||||
labs: s.labs,
|
||||
allergies: s.allergies,
|
||||
familyHistory: s.familyHistory,
|
||||
mentalHealthScreeners: s.mentalHealthScreeners,
|
||||
};
|
||||
}
|
||||
@@ -44,87 +44,16 @@ import { useAuth } from "@/hooks/use-auth";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {
|
||||
DEFAULT_SECTIONS,
|
||||
buildSelectionSections,
|
||||
type SectionState,
|
||||
} from "@/components/settings/health-record-export-controls";
|
||||
|
||||
type ExportFormat = "pdf" | "fhir" | "package";
|
||||
|
||||
const EXPORT_FORMATS: readonly ExportFormat[] = ["pdf", "fhir", "package"];
|
||||
|
||||
interface SectionState {
|
||||
weight: boolean;
|
||||
bp: boolean;
|
||||
pulse: boolean;
|
||||
oxygenSaturation: boolean;
|
||||
bodyFat: boolean;
|
||||
bodyComposition: boolean;
|
||||
restingHeartRate: boolean;
|
||||
hrv: boolean;
|
||||
vo2max: boolean;
|
||||
steps: boolean;
|
||||
distance: boolean;
|
||||
sleep: boolean;
|
||||
glucose: boolean;
|
||||
medList: boolean;
|
||||
compliance: boolean;
|
||||
mood: boolean;
|
||||
bmi: boolean;
|
||||
labs: boolean;
|
||||
allergies: boolean;
|
||||
familyHistory: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_SECTIONS: SectionState = {
|
||||
weight: true,
|
||||
bp: true,
|
||||
pulse: true,
|
||||
oxygenSaturation: true,
|
||||
bodyFat: true,
|
||||
bodyComposition: false,
|
||||
restingHeartRate: false,
|
||||
hrv: false,
|
||||
vo2max: false,
|
||||
steps: false,
|
||||
distance: false,
|
||||
sleep: false,
|
||||
glucose: true,
|
||||
medList: true,
|
||||
compliance: true,
|
||||
mood: false, // privacy default
|
||||
bmi: true,
|
||||
labs: true,
|
||||
allergies: true,
|
||||
familyHistory: true,
|
||||
};
|
||||
|
||||
function buildSelectionSections(s: SectionState) {
|
||||
return {
|
||||
vitals: {
|
||||
weight: s.weight,
|
||||
bp: s.bp,
|
||||
pulse: s.pulse,
|
||||
oxygenSaturation: s.oxygenSaturation,
|
||||
bodyFat: s.bodyFat,
|
||||
bodyComposition: s.bodyComposition,
|
||||
},
|
||||
cardioFitness: {
|
||||
restingHeartRate: s.restingHeartRate,
|
||||
hrv: s.hrv,
|
||||
vo2max: s.vo2max,
|
||||
},
|
||||
activity: {
|
||||
steps: s.steps,
|
||||
distance: s.distance,
|
||||
sleep: s.sleep,
|
||||
},
|
||||
glucose: s.glucose,
|
||||
medications: { list: s.medList, compliance: s.compliance },
|
||||
mood: s.mood,
|
||||
bmi: s.bmi,
|
||||
labs: s.labs,
|
||||
allergies: s.allergies,
|
||||
familyHistory: s.familyHistory,
|
||||
};
|
||||
}
|
||||
|
||||
export function HealthRecordExportPanel() {
|
||||
const { t, locale } = useTranslations();
|
||||
const { user } = useAuth();
|
||||
@@ -171,7 +100,10 @@ export function HealthRecordExportPanel() {
|
||||
|
||||
// The single "Medikamente" control gates the whole medication block
|
||||
// (list + compliance) so unchecking it actually excludes all medication
|
||||
// data from the export — matching the iOS five-section model.
|
||||
// data from the export — matching the iOS five-section model. Until
|
||||
// that was true of the compliance figures only until this change: the list
|
||||
// names, doses and schedules, and the per-dose ledger behind it, went out
|
||||
// regardless of the switch.
|
||||
function toggleMedications() {
|
||||
setSections((prev) => {
|
||||
const next = !(prev.medList && prev.compliance);
|
||||
@@ -451,6 +383,11 @@ export function HealthRecordExportPanel() {
|
||||
checked={sections.mood}
|
||||
onToggle={() => toggle("mood")}
|
||||
/>
|
||||
<ToggleRow
|
||||
label={t("settings.healthRecord.mentalHealthScreeners")}
|
||||
checked={sections.mentalHealthScreeners}
|
||||
onToggle={() => toggle("mentalHealthScreeners")}
|
||||
/>
|
||||
<ToggleRow
|
||||
label={t("settings.healthRecord.labs")}
|
||||
checked={sections.labs}
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
* The clinician share-link CREATE flow, extracted so both surfaces mount the
|
||||
* exact same form: Settings → Sharing (the owner section) and the document
|
||||
* detail sheet's "Share" action. A share link is a time-boxed, scope-frozen,
|
||||
* read-only view of the owner's own record at `/c/<token>`, optionally
|
||||
* exposing a scoped read-only FHIR face and a hand-picked, frozen-at-create
|
||||
* document set.
|
||||
* read-only view of the owner's own record at `/c/<token>`, plus a hand-picked,
|
||||
* frozen-at-create document set. It serves a rendered page and those documents
|
||||
* and nothing else. A FHIR toggle and a resource-type picker were removed
|
||||
* that configured an endpoint no route ever served.
|
||||
*
|
||||
* The raw `hls_` token, the passphrase, and the `#k=` QR are returned EXACTLY
|
||||
* ONCE on create (the server stores only hashes); this component is the single
|
||||
@@ -25,10 +26,8 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Copy, FileText, Loader2, ScanLine, X } from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import {
|
||||
ShareDocumentPicker,
|
||||
type PickedDocument,
|
||||
@@ -37,15 +36,6 @@ import { useTranslations } from "@/lib/i18n/context";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import { apiPost } from "@/lib/api/api-fetch";
|
||||
|
||||
/** The FHIR resource types a share link may serve — mirrors C4's enum. */
|
||||
const RESOURCE_TYPES = [
|
||||
"Patient",
|
||||
"Observation",
|
||||
"MedicationStatement",
|
||||
"MedicationAdministration",
|
||||
] as const;
|
||||
type ResourceType = (typeof RESOURCE_TYPES)[number];
|
||||
|
||||
/** Maximum lifetime, in days — mirrors `SHARE_LINK_MAX_DAYS` on the server. */
|
||||
export const MAX_DAYS = 90;
|
||||
const DEFAULT_DAYS = 30;
|
||||
@@ -64,8 +54,6 @@ export interface ShareLinkSummary {
|
||||
label: string;
|
||||
rangeStart: string;
|
||||
rangeEnd: string | null;
|
||||
resourceTypes: string[];
|
||||
allowFhirApi: boolean;
|
||||
/** v1.18.7 — whether a passphrase second factor guards this link. */
|
||||
protected: boolean;
|
||||
/** v1.28 — size of the frozen document set (never the ids, never bytes). */
|
||||
@@ -99,8 +87,6 @@ export interface ShareLinkCreatePayload {
|
||||
label: string;
|
||||
rangeStart: string;
|
||||
rangeEnd: null;
|
||||
resourceTypes: ResourceType[];
|
||||
allowFhirApi: boolean;
|
||||
documentIds?: string[];
|
||||
documentOnly?: boolean;
|
||||
expiresAt: string;
|
||||
@@ -111,8 +97,8 @@ export interface ShareLinkCreatePayload {
|
||||
* function so the two surfaces' scope contract is unit-testable without a DOM.
|
||||
*
|
||||
* The `documentOnly` branch is the privacy-load-bearing one: a document-launched
|
||||
* share posts an EMPTY report scope (`resourceTypes: []`, no `sections`, FHIR
|
||||
* off) plus `documentOnly: true`, and ALWAYS carries the picked document ids —
|
||||
* share posts an EMPTY report scope (no `sections`) plus `documentOnly: true`,
|
||||
* and ALWAYS carries the picked document ids —
|
||||
* so the created link serves the document(s) and nothing else. The record share
|
||||
* (Settings → Sharing) keeps its full scope and only attaches documents when
|
||||
* the owner picked some.
|
||||
@@ -121,8 +107,6 @@ export function buildShareLinkCreatePayload(input: {
|
||||
label: string;
|
||||
rangeDays: number;
|
||||
expiryDays: number;
|
||||
allowFhirApi: boolean;
|
||||
resourceTypes: ResourceType[];
|
||||
documentIds: string[];
|
||||
documentOnly: boolean;
|
||||
}): ShareLinkCreatePayload {
|
||||
@@ -135,8 +119,6 @@ export function buildShareLinkCreatePayload(input: {
|
||||
if (input.documentOnly) {
|
||||
return {
|
||||
...base,
|
||||
resourceTypes: [],
|
||||
allowFhirApi: false,
|
||||
documentOnly: true,
|
||||
// The launched document(s) always ride along — a documents-only share
|
||||
// with no document would be meaningless (the server 422s it).
|
||||
@@ -145,8 +127,6 @@ export function buildShareLinkCreatePayload(input: {
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
resourceTypes: input.resourceTypes,
|
||||
allowFhirApi: input.allowFhirApi,
|
||||
// Omit the key entirely when nothing is attached (a documents-less record
|
||||
// share stays the default). The server re-validates each id as the caller's
|
||||
// own live document before minting the link.
|
||||
@@ -162,10 +142,9 @@ export function ShareLinkCreateForm({
|
||||
}: {
|
||||
/**
|
||||
* Documents-only mode (the document-launched flow). Hides the record-scope
|
||||
* controls — FHIR API toggle, FHIR resource-type checkboxes, and the
|
||||
* history-range selector — and posts an empty report scope so the minted
|
||||
* link serves ONLY the attached document(s). Keeps the document picker,
|
||||
* label, expiry, and one-time passphrase reveal.
|
||||
* control — the history-range selector — and posts an empty report scope so
|
||||
* the minted link serves ONLY the attached document(s). Keeps the document
|
||||
* picker, label, expiry, and one-time passphrase reveal.
|
||||
*/
|
||||
documentOnly?: boolean;
|
||||
/** Documents to pre-attach — the document-launched flow seeds the one doc. */
|
||||
@@ -181,11 +160,6 @@ export function ShareLinkCreateForm({
|
||||
const [label, setLabel] = useState(initialLabel ?? "");
|
||||
const [rangeDays, setRangeDays] = useState(DEFAULT_DAYS);
|
||||
const [expiryDays, setExpiryDays] = useState(DEFAULT_DAYS);
|
||||
const [allowFhirApi, setAllowFhirApi] = useState(false);
|
||||
const [resourceTypes, setResourceTypes] = useState<ResourceType[]>([
|
||||
"Patient",
|
||||
"Observation",
|
||||
]);
|
||||
const [selectedDocs, setSelectedDocs] = useState<PickedDocument[]>(
|
||||
initialDocuments ?? [],
|
||||
);
|
||||
@@ -238,8 +212,6 @@ export function ShareLinkCreateForm({
|
||||
label,
|
||||
rangeDays,
|
||||
expiryDays,
|
||||
allowFhirApi,
|
||||
resourceTypes,
|
||||
documentIds: selectedDocs.map((d) => d.id),
|
||||
documentOnly,
|
||||
}),
|
||||
@@ -268,12 +240,6 @@ export function ShareLinkCreateForm({
|
||||
},
|
||||
});
|
||||
|
||||
function toggleResourceType(type: ResourceType) {
|
||||
setResourceTypes((prev) =>
|
||||
prev.includes(type) ? prev.filter((r) => r !== type) : [...prev, type],
|
||||
);
|
||||
}
|
||||
|
||||
async function copyValue(value: string, which: "link" | "passphrase") {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
@@ -344,51 +310,6 @@ export function ShareLinkCreateForm({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* The FHIR API + its resource-type scope expose the health RECORD.
|
||||
A documents-only link serves no record, so both are hidden and the
|
||||
posted scope is forced empty server-side regardless. */}
|
||||
{!documentOnly ? (
|
||||
<div className="border-border flex items-center justify-between rounded-lg border p-3">
|
||||
<div className="space-y-0.5 pr-3">
|
||||
<Label htmlFor="share-fhir" className="text-sm font-medium">
|
||||
{t("settings.sharing.fhirApi")}
|
||||
</Label>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{t("settings.sharing.fhirApiHint")}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="share-fhir"
|
||||
checked={allowFhirApi}
|
||||
onCheckedChange={setAllowFhirApi}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{!documentOnly && allowFhirApi && (
|
||||
<fieldset className="space-y-2">
|
||||
<legend className="text-sm font-medium">
|
||||
{t("settings.sharing.resourceTypes")}
|
||||
</legend>
|
||||
<div className="grid gap-2 sm:grid-cols-2">
|
||||
{RESOURCE_TYPES.map((type) => (
|
||||
<label
|
||||
key={type}
|
||||
className="flex items-center gap-2 text-sm"
|
||||
htmlFor={`share-rt-${type}`}
|
||||
>
|
||||
<Checkbox
|
||||
id={`share-rt-${type}`}
|
||||
checked={resourceTypes.includes(type)}
|
||||
onCheckedChange={() => toggleResourceType(type)}
|
||||
/>
|
||||
<span className="font-mono text-xs">{type}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
)}
|
||||
|
||||
{/* ── Attach documents ─────────────────────────────────────── */}
|
||||
<div className="border-border space-y-2 rounded-lg border p-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
|
||||
@@ -151,11 +151,6 @@ function ShareLinksCard() {
|
||||
{link.documentCount}
|
||||
</Badge>
|
||||
)}
|
||||
{link.allowFhirApi && (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
FHIR
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
|
||||
Reference in new issue
Block a user