Files
temetro/frontend/components/settings/settings-view.tsx
T
Khalid Abdi 43eaccb97e feat: HL7/FHIR, e-prescribing & insurance claims integrations
Real, standards-compliant integration clients that the clinic points at
its own (sandbox or production) endpoints — no mock data.

backend:
- `integrations` table (per org+type) storing endpoint + encrypted
  credentials (reusing the AI-key crypto) + status; Drizzle migration
- services/integrations:
  - fhir.ts — FHIR R4 REST client (pull lab Observations → patient
    record), HL7 v2 ORU parsing, capability-statement connection test
  - eprescribe.ts — NCPDP SCRIPT NewRx message build + transmit
  - claims.ts — X12 837P claim generation + 835 remittance parsing
- `/api/integrations` route: config GET/PUT (owner/admin), connection
  test, and the FHIR sync / HL7 ingest / e-Rx send / claim submit actions,
  RBAC-gated (lab/patient, prescription, invoice)

frontend:
- lib/integrations.ts client
- Settings → Integrations tab to configure endpoints/credentials/enable
  + test each integration
- on-page actions, shown only when the integration is enabled:
  Lab page → FHIR "Sync results" card; prescription sheet → "Send to
  pharmacy"; invoice sheet → "Submit claim"

Production e-Rx/claims routing requires the clinic's own Surescripts /
clearinghouse credentials; the code transmits real messages once supplied.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 20:15:00 +03:00

81 lines
3.1 KiB
TypeScript

"use client";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { cn } from "@/lib/utils";
import { AIPanel } from "@/components/settings/settings-ai";
import { SigningPanel } from "@/components/settings/settings-billing";
import { CareTeamPanel } from "@/components/settings/settings-care-team";
import { DevelopersPanel } from "@/components/settings/settings-developers";
import { IntegrationsPanel } from "@/components/settings/settings-integrations";
import { ProfilePanel } from "@/components/settings/settings-preferences";
import { RecordsPanel } from "@/components/settings/settings-records";
import { useActiveRole } from "@/lib/roles";
const TABS = [
{ id: "profile", labelKey: "settings.tabs.profile" },
{ id: "ai", labelKey: "settings.tabs.ai" },
{ id: "records", labelKey: "settings.tabs.records" },
{ id: "signing", labelKey: "settings.tabs.signing" },
{ id: "careTeam", labelKey: "settings.tabs.careTeam" },
{ id: "integrations", labelKey: "settings.tabs.integrations" },
{ id: "developers", labelKey: "settings.tabs.developers" },
] as const;
// Per-user tabs every clinician sees; the rest are clinic-wide (admin only).
const PERSONAL_TABS = ["profile", "ai"];
type Tab = (typeof TABS)[number]["id"];
export function SettingsView() {
const { t } = useTranslation();
const role = useActiveRole();
const [tab, setTab] = useState<Tab>("profile");
// Only clinic owners/admins manage clinic-wide settings (care team, records,
// signing, developers). Everyone else gets their personal tabs (profile, AI).
const isAdmin = role === "owner" || role === "admin";
const visibleTabs = isAdmin
? TABS
: TABS.filter((item) => PERSONAL_TABS.includes(item.id));
const activeTab = visibleTabs.some((item) => item.id === tab) ? tab : "profile";
return (
<div className="mx-auto w-full max-w-3xl px-6 py-10">
<div className="flex flex-col gap-5 sm:flex-row sm:items-center sm:justify-between">
<h1 className="text-2xl font-semibold tracking-tight">
{t(`settings.tabs.${activeTab}`)}
</h1>
<nav className="flex flex-wrap items-center gap-1">
{visibleTabs.map((item) => (
<button
className={cn(
"rounded-lg px-3 py-1.5 text-sm transition-colors",
activeTab === item.id
? "bg-muted text-foreground"
: "text-muted-foreground hover:text-foreground"
)}
key={item.id}
onClick={() => setTab(item.id)}
type="button"
>
{t(item.labelKey)}
</button>
))}
</nav>
</div>
<div className="mt-10 space-y-12">
{activeTab === "profile" && <ProfilePanel />}
{activeTab === "ai" && <AIPanel />}
{activeTab === "records" && <RecordsPanel />}
{activeTab === "signing" && <SigningPanel />}
{activeTab === "careTeam" && <CareTeamPanel />}
{activeTab === "integrations" && <IntegrationsPanel />}
{activeTab === "developers" && <DevelopersPanel />}
</div>
</div>
);
}