import { Attachment } from 'fhir/r4'; import { assetUrl } from './assetUrl'; /** The mark the server sets on bytes it read back from a clean malware scan. No write can add or keep it falsely. */ export const SCANNED_THUMBNAIL_URL = 'https://akashichealthrecords.com/fhir/StructureDefinition/scanned-thumbnail'; export const isScannedPhoto = (photo?: Attachment | null): boolean => Boolean(photo?.data && photo.extension?.some((extension) => extension.url === SCANNED_THUMBNAIL_URL)); /** * A photo or logo's inline bytes as an image source, only when the server put them there from a clean scan. Bytes a * browser wrote before scanning, or a link to an image elsewhere, are never drawn. */ export const scannedPhotoSrc = (photo?: Attachment | null): string | undefined => isScannedPhoto(photo) ? `data:${photo?.contentType ?? 'image/png'};base64,${photo?.data}` : undefined; export const getFhirPhotoUrl = (photo?: Attachment | null, type?: string): string => { const scanned = scannedPhotoSrc(photo); if (scanned) { return scanned; } const defaultImages: Record = { practitioner: assetUrl('default_avatar.png'), healthcareService: assetUrl('default_avatar.png'), patient: assetUrl('default_avatar.png'), organization: assetUrl('hospital.jpg') }; if (!type) { return defaultImages['practitioner']; } return defaultImages[type] ?? defaultImages['practitioner']; };