service
One NextGen EHR connection, behind the backend-neutral EHRDataService.
Classes
NextGenEHRDataService
class NextGenEHRDataService( ehr_config: NextGenEHRConfig, *, bitfount_session: BitfountSession,):One NextGen EHR connection, over the NextGen querier and lister.
A minimal wrapper. Lookups and listing use NextGenPatientQuerier and
NextGenPatientLister, over one SMART on FHIR session and one NextGen
FHIR API. It keeps no knowledge of the server, no
response cache of its own and no auth budget: NextGen's session refreshes
its token on a 401 itself (NextGenAuthSession.request).
Its records fall short of the PatientRecord contract:
- the code and category filters on observations, and the status and code-type filters on conditions and procedures, are ignored: every result is returned;
- previous encounters raise
NextGenEncountersNotImplementedError, anEHRFetchUnsupportedError; - visual acuity is always
None; - documents cannot be listed batch by batch:
document_infosraisesEHRFetchUnsupportedError, and only every document can be downloaded.
Arguments
ehr_config: The NextGen EHR's config.bitfount_session: The Bitfount session SMART on FHIR authenticates with; it is authenticated here if it is not already.
Variables
supports_mrn_lookup : bool- Whetherfind_by_mrncan find patients: NextGen's can.
Methods
availability
def availability(self) ‑> EHRPreflightResult:Whether this EHR can be reached, before any patient is asked for.
Obtains a token from the SMART on FHIR session, then asks the NextGen
FHIR server for its CapabilityStatement
(capability_statement_attempt), as often as the preflight policy
allows (run_preflight). A rejected token is refetched for the next
attempt, and the session keeps the new one.
find_by_mrn
def find_by_mrn( self, mrn: str | Sequence[str], *, system_qualified: bool = False,) ‑> NextGenPatientQuerier:The record of the one patient holding this medical record number.
Several values are tried in turn, as EHRDataService.find_by_mrn
says, one search each. Each value is stripped of surrounding
whitespace (mrn_values), then searched as given.
Arguments
mrn: The identifier, or several to try in turn.system_qualified: Ignored: NextGen searches each value as given, with no identifier system.
Raises
ValueError: If no identifier is given, or one is blank (empty or whitespace only).NoMatchingNextGenPatientError: If no patient holds any of them.NonSpecificNextGenPatientError: If more than one patient holds the value being tried.NoNextGenPatientIDError: If the patient holding the value being tried has no ID.NextGenQuotaExceeded: If the NextGen call quota is exhausted.HTTPError: If the search request for the value being tried failed, a rejection included.requests.RequestException: If NextGen could not be reached or did not answer in time for the value being tried: the connection or timeout error left after the session's retries.
find_patient
def find_patient( self, *, given: str | None, family: str | None, dob: str | date, narrows_last_search: bool = False,) ‑> NextGenPatientQuerier:The record of the one patient with these names and date of birth.
NextGen searches by date of birth and matches the names locally, so a
search narrowing the one just made for the same date of birth answers
from that search's candidates, with no request against the daily
quota (NextGenFHIRAPI.get_patient_entries_by_dob).
Arguments
given: The given name searched on.family: The family name searched on.dob: The date of birth, as a date or aYYYY-MM-DDstring.narrows_last_search: Whether to reuse the last date-of-birth search's candidates when it was for this date of birth.
Raises
NoMatchingNextGenPatientError: If no patient matches.NonSpecificNextGenPatientError: If more than one patient matches.NoNextGenPatientIDError: If the patient found has no ID.NextGenQuotaExceeded: If the NextGen call quota is exhausted.HTTPError: If the search request failed.requests.RequestException: If NextGen could not be reached or did not answer in time: the connection or timeout error left after the session's retries.
lister
def lister(self) ‑> NextGenPatientLister:A lister paging through this EHR's patients' IDs.
patient_by_id
def patient_by_id( self, patient_id: str,) ‑> NextGenPatientQuerier:The record of the patient with this NextGen person ID.
The ID is quoted into the request path as one segment
(NextGenFHIRAPI.get_patient_info_by_id).
Arguments
patient_id: The patient's ID.
Raises
ValueError: If the ID is blank (empty or whitespace only).NoMatchingNextGenPatientError: If no patient has that ID.NextGenQuotaExceeded: If the NextGen call quota is exhausted.HTTPError: If the lookup request failed.requests.RequestException: If NextGen could not be reached or did not answer in time: the connection or timeout error left after the session's retries.
record_for_id
def record_for_id( self, patient_id: str,) ‑> NextGenPatientQuerier:A record for this NextGen person ID, taken on trust.
Built on the connection's session without a request, so its
raw_patient and demographics are None, and no read of the
patient resource can fail or raise. It builds its own NextGen FHIR API
over that session, not the connection's.
Arguments
patient_id: The patient's ID.
Raises
ValueError: If the ID is blank (empty or whitespace only).
reset_auth_budget
def reset_auth_budget(self) ‑> None:Do nothing: NextGen keeps no auth budget to reset.
stats
def stats(self) ‑> EHRServiceStats:What this connection has counted so far, as it stands now.
A snapshot. NextGen keeps no refusal counts, so only the request timer is reported; it is the process's, so it counts FHIR R4 requests made by other connections, and NextGen requests are not timed under it.