Files
temetro/frontend/lib/staff.ts
T
Khalid Abdi 2f36875d37 backend: add per-clinic staff specialty (Care Team -> patient sheet)
New staff_profile table (org + user, unique) holding a clinician's clinical
specialty. GET /api/staff and /api/staff/providers now include specialty; new
PATCH /api/staff/:userId (member:update) upserts it. Migration 0023.

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

61 lines
1.8 KiB
TypeScript

import { apiFetch } from "@/lib/api-client";
// A clinician who can be assigned as a patient's primary provider. Returned by
// the backend's GET /api/staff/providers (clinical roles only — excludes
// reception/pharmacy/lab). Readable by any clinic member.
export type Provider = {
userId: string;
name: string;
role: string;
// Admin-set clinical specialty (e.g. "Orthopedist"); null when unset.
specialty?: string | null;
};
export function listProviders(): Promise<Provider[]> {
return apiFetch<Provider[]>("/api/staff/providers");
}
// Update a member's clinical specialty (owner/admin only). Pass null to clear.
export function updateStaffSpecialty(
userId: string,
specialty: string | null,
): Promise<{ userId: string; specialty: string | null }> {
return apiFetch(`/api/staff/${encodeURIComponent(userId)}`, {
method: "PATCH",
body: JSON.stringify({ specialty }),
});
}
// Curated list of clinical specialties an admin can assign to a doctor. Stored
// as the plain string; values double as the i18n key suffix
// (settings.careTeam.specialties.*).
// Human label for a stored specialty key (settings.careTeam.specialties.*),
// falling back to the raw value for any legacy/free-text entries.
export function specialtyLabel(
t: (key: string) => string,
specialty?: string | null,
): string | null {
if (!specialty) return null;
const key = `settings.careTeam.specialties.${specialty}`;
const label = t(key);
return label === key ? specialty : label;
}
export const SPECIALTIES = [
"general",
"orthopedics",
"dentistry",
"cardiology",
"pediatrics",
"dermatology",
"neurology",
"obgyn",
"ophthalmology",
"ent",
"psychiatry",
"radiology",
"anesthesiology",
"surgery",
] as const;
export type Specialty = (typeof SPECIALTIES)[number];