O3 Framework / useAttachments
useAttachments(
patientUuid,includeEncounterless,encounterUuid?):object
Defined in: packages/framework/esm-react-utils/src/useAttachments.ts:39
A React hook that fetches attachments for a patient using SWR for caching and automatic revalidation.
The UUID of the patient whose attachments should be fetched. Nothing is fetched while this is empty, so callers can defer the request.
undefined |
null |
string |
boolean
Whether to include attachments that are not
associated with any encounter. Ignored when encounterUuid is set.
string
When set, only attachments recorded on this encounter are returned. An unknown encounter UUID makes the server fall back to every attachment of the patient, so only pass a UUID you have loaded.
object
An object containing:
data: Array of attachment objects (empty array while loading)isLoading: Whether the initial fetch is in progressisValidating: Whether any request (initial or revalidation) is in progresserror: Any error that occurred during fetchingmutate: Function to trigger a revalidation of the datadata:
AttachmentResponse[]
error:
any
isLoading:
boolean
isValidating:
boolean
mutate:
KeyedMutator<FetchResponse<{results:AttachmentResponse[]; }>>
import { useAttachments } from '@openmrs/esm-framework';
function PatientAttachments({ patientUuid }) {
const { data, isLoading, error } = useAttachments(patientUuid, true);
if (isLoading) return <span>Loading...</span>;
if (error) return <span>Error loading attachments</span>;
return <AttachmentList attachments={data} />;
}
// Only the attachments recorded on one encounter
const { data } = useAttachments(patientUuid, false, encounterUuid);