Skip to main content

document_acuity

Visual acuity read from the patient's CCDs, from FHIR R4 DocumentReference.

Some servers (Nextech) hold a patient's visual acuity only inside the C-CDA documents they list, not as Observation resources. This reader lists the patient's documents, picks the ones that look like CCDs, and reads acuity observations out of the newest few. Each DocumentReference is one document, whatever number of renditions it lists, and only its XML or untyped renditions are downloaded.

Classes​

DocumentAcuityReader​

class DocumentAcuityReader():

Reads visual acuity from the patient's CCDs.

Methods​


acuity_in_documents_only​

def acuity_in_documents_only(self) ‑> bool:

Whether the server is marked as serving acuity only in documents.

Asks the server knowledge. False for a provider that does not read acuity from documents.

download_all_documents​

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

Inherited from:

DocumentsReader.download_all_documents :

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]]:

Inherited from:

DocumentsReader.download_documents_batch :

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_acuity​

def get_document_acuity(    self,    codes: Sequence[tuple[str | None, str]],    *,    observed: Mapping[Eye, date] | None = None,) ‑> DocumentAcuityResult:

The visual acuity observations recorded in the patient's newest CCDs.

Lists the patient's DocumentReferences (asking for CCDs by type where the server allows it), reads the newest CCDs, at most three, and keeps each eye's readings from the newest CCD that has any. A CCD is a document that parsed as a CDA or failed; a weak candidate that was not a CDA takes none of the three. At most ten candidate documents are tried in all. The search stops once both eyes are covered. Readings that name no eye, or both eyes, are kept only from the first CCD that has any readings, and cover neither eye.

Given the date of both eyes' newest best-corrected readings in the patient's Observations (observed), the documents are listed and their candidates chosen as usual, but nothing is downloaded unless a candidate may be newer than the older of the two readings: the newest of its date, period end, period start and last-updated time is on or after that reading's date, compared by calendar date, or it states none readably. A partial time stands for its last possible day (2025-03 for 2025-03-31). Otherwise the result is complete with no readings, counted as ccd_not_newer. When a candidate may be newer, counted as ccd_may_be_newer, only the candidates that may be newer are read, newest first as usual. A capped listing is read as usual, since the check cannot be made.

Within a document, only XML-typed and untyped renditions are tried, and the first that parses as a CDA is read. A document fails when none of its renditions parses, unless it was a weak (XML-only) candidate whose renditions all turned out not to be a CDA: that is a document of another kind, not a CCD that could not be read.

Documents are held in memory only. Nothing about a document, its patient or an error's message is logged or counted: only counts and text_shape masks.

Arguments

  • codes: The (system, code) pairs of the acuity observations to read. system is a short name from CODE_SYSTEM_TO_IDENTIFIER (e.g. "loinc"), or None for the code in LOINC or SNOMED.
  • observed: The date of each eye's newest best-corrected reading in the patient's Observations. With both eyes given, the CCDs are downloaded only if one may be newer (see above). None, or one eye, reads them as usual.

Returns The readings found. complete is False if the listing was capped, the server does not serve DocumentReference (no readings, counted as listing_unsupported), a CCD that could have supplied an eye failed, or the ten documents were tried with an eye still uncovered and candidates left (documents_tried_capped).

Raises

  • EHRFetchUnsupportedError: Only if the provider does not read acuity from documents. A server that will not list documents for a provider that does gives an incomplete result instead.
  • 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.

get_document_infos​

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

Inherited from:

DocumentsReader.get_document_infos :

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.

reads_acuity_from_documents​

def reads_acuity_from_documents(self) ‑> bool:

Whether the provider reads acuity from documents (get_document_acuity).

record_acuity_sources​

def record_acuity_sources(self, *, in_observations: bool, in_documents: bool) ‑> None:

Record where this patient's acuity was found, in the server knowledge.

Does nothing for a provider that does not read acuity from documents.

Arguments

  • in_observations: Whether the patient's Observations held a reading for either eye.
  • in_documents: Whether the patient's documents held a reading for either eye.