Skip to main content

documents

The patient's documents, from FHIR R4 DocumentReference and Binary.

Classes​

DocumentsReader​

class DocumentsReader():

Lists and downloads the patient's documents.

Pages DocumentReference searches and fetches Binary resources through the FHIR client directly rather than a SearchExecutor: these requests are not cached, and their paging is the client's own. Attachments at absolute or off-server URLs are fetched over plain HTTP with retries (_retrying_http_request).

Methods​


download_all_documents​

def download_all_documents(    self,    save_path: Path,) ‑> tuple[list[DownloadedEHRDocumentInfo], list[FailedEHRDocumentInfo]]:

Download PDF documents for the current patient.

A document that cannot be downloaded is returned as failed; a listing that fails raises, as get_document_infos does.

Arguments

  • save_path: Documents path for the PDF documents to be saved.

Raises

  • FHIRR4APIError: If a page of the listing fails (see get_document_infos).
  • OperationOutcome: As FHIRR4APIError, for a server that reports the failure that way.
  • requests.RequestException: If the server could not be reached or did not answer in time while listing.

download_documents_batch​

def download_documents_batch(    self,    save_path: Path,    batch_document_infos: list[EHRDocumentInfo],) ‑> tuple[list[DownloadedEHRDocumentInfo], list[FailedEHRDocumentInfo]]:

Downloads a batch of documents.

Returns A tuple containing:

  • list of info of documents that were successfully downloaded.
  • list of info of documents that could not be downloaded.

get_document_infos​

def get_document_infos(    self,) ‑> Iterable[list[EHRDocumentInfo]]:

Yields document items related to this patient, a page at a time.

A listing that fails raises as it is iterated, so a failure is never read as a patient with no (more) documents.

Raises

  • FHIRR4APIError: If a page of the listing fails, including an answer that is not a Bundle (such as an OperationOutcome sent with a 200), which is raised with fhirpy's InvalidResponse as its __cause__.
  • OperationOutcome: As FHIRR4APIError, for a server that reports the failure that way.
  • requests.RequestException: If the server could not be reached or did not answer in time: the connection or timeout error left after the client's retries.