import type { Organization } from 'fhir/r4'; /** * The practice's own STAFF sign-in page, stored on the Organization beside the patient one. * * NOTHING HERE IS DERIVED FROM THE PATIENT URL, and that is the point. The staff portal is a real page * the practice created deliberately - its own `akashere_staff_portal` shortcode, its own WordPress page, * its own stored page id - and the Portal Pages screen already resolves its permalink in the same moment * it resolves the patient one. There is nothing to guess at; there was simply a value that never * travelled. String-editing the patient URL into a guess at where a practice keeps its staff page would * be the wrong fix, and is why this sat unbuilt as an open question. */ export const ORGANIZATION_STAFF_PORTAL_URL_EXTENSION_URL = 'https://akashichealthrecords.com/fhir/StructureDefinition/organization-staff-portal-url'; export const getStaffPortalUrl = ( organization?: Organization | null, ): string | undefined => { const ext = organization?.extension?.find( (e) => e.url === ORGANIZATION_STAFF_PORTAL_URL_EXTENSION_URL, ); return ext?.valueUrl ?? ext?.valueString; }; // Immutably set/clear the staff-portal extension, preserving every other extension - including the // PATIENT portal URL sitting directly beside it, which a naive replace would drop. export const setStaffPortalUrl = ( organization: Organization, url: string, ): Organization => { const others = (organization.extension || []).filter( (e) => e.url !== ORGANIZATION_STAFF_PORTAL_URL_EXTENSION_URL, ); const trimmed = url.trim(); const extension = trimmed ? [...others, { url: ORGANIZATION_STAFF_PORTAL_URL_EXTENSION_URL, valueUrl: trimmed }] : others; return { ...organization, extension }; };