import { useCallback } from 'react'; import { environment } from '../environments/environment.ts'; import { useHttpService } from './HttpService.tsx'; // apiUrl, NOT fhirClinicalApi. `/R4/imaging/*` is declared in api.yaml, on the gateway that // resolves to environment.apiUrl - the same base Stage 1's ImagingUploadService.tsx uses for // /R4/imaging/import. environment.fhirClinicalApi is a DIFFERENT gateway serving FHIR resource types // (/R4/ImagingStudy and friends, in templates/fhir/03-fhir-clinical.yaml); it declares no imaging // path at all. Pointing here would make API Gateway return 403 "Missing Authentication Token" for an // unmatched resource BEFORE the authorizer runs - which reads like an auth failure, not a wrong host, // and would show as "This imaging study could not be loaded" for every user with no frame ever fetched. // // Already ends in /R4 - do not append another. And never environment.healthLakeEndpoint: that key does // not exist on environment. const API_URL = environment.apiUrl; // The shape AWS HealthImaging returns from GetImageSetMetadata, narrowed to the fields this feature // reads. Deliberately permissive Record for the DICOM blocks rather than an // enumeration of every tag: the converter in healthImagingToWadoRs.ts reads a known handful by name // and narrows each at the point of use, so declaring 400 optional DICOM keywords here would buy // nothing and rot immediately. export interface HealthImagingInstance { DICOM?: Record; ImageFrames?: { ID: string }[]; // Sits on the instance, NOT inside DICOM - and is NOT the same value as // DICOM.TransferSyntaxUID. That one is the uploaded file's syntax; this is what HealthImaging // actually stores and hands back from GetImageFrame. Verified live on the imported CT: // DICOM.TransferSyntaxUID = 1.2.840.10008.1.2 (Implicit VR LE) while // StoredTransferSyntaxUID = 1.2.840.10008.1.2.4.202 (HTJ2K), for the same instance. StoredTransferSyntaxUID?: string; } export interface HealthImagingSeries { DICOM?: Record; Instances?: Record; } export interface HealthImagingMetadata { Study?: { DICOM?: Record; Series?: Record; }; } // Exported as a plain function, not a hook method, because the Cornerstone image loader builds these // urls from inside a callback that is not a React render - see dicomLoader.ts. export const frameUrl = (imageSetId: string, studyId: string, frameId: string): string => `${API_URL}/imaging/imageset/${encodeURIComponent(imageSetId)}/frame` + `?study=${encodeURIComponent(studyId)}&frameId=${encodeURIComponent(frameId)}`; export const metadataUrl = (imageSetId: string, studyId: string): string => `${API_URL}/imaging/imageset/${encodeURIComponent(imageSetId)}/metadata` + `?study=${encodeURIComponent(studyId)}`; export const useImagingFrameService = () => { const { get } = useHttpService(); const fetchImageSetMetadata = useCallback( (imageSetId: string, studyId: string): Promise => get(metadataUrl(imageSetId, studyId)), [get] ); return { fetchImageSetMetadata }; };