import type { Organization } from 'fhir/r4'; /** * The practice's own NPI, read off the Organization. * * THE SYSTEM URL IS THE STANDARD FHIR ONE and it must stay in step with the server's `NPI_SYSTEM` * (`aws/sam/services/api/src/utils/npi.ts`). Both halves match on it, and a client reading a different * spelling would show an empty field for a practice that has recorded one - which reads as "not set" * and invites somebody to type it again into a server that will refuse it as already claimed. * * `identifier` CARRIES MORE THAN THIS. The array also holds the account-home-patient link and is where * an SSN would live, so this finds its entry by system rather than taking the first one. */ export const NPI_SYSTEM = 'http://hl7.org/fhir/sid/us-npi'; export const readOrganizationNpi = (organization?: Organization | null): string | undefined => { const value = organization?.identifier ?.find((identifier) => identifier.system === NPI_SYSTEM) ?.value ?.trim(); return value || undefined; };