querier
Provides a high-level abstraction for extracting patient info from FHIR R4 APIs.
Classes
FHIRR4GetPatientInfoError
class FHIRR4GetPatientInfoError(*args, **kwargs):Could not retrieve patient info.
Ancestors
- GetPatientInfoError
- FHIRR4APIError
- BitfountError
- builtins.Exception
- builtins.BaseException
FHIRR4PatientQuerier
class FHIRR4PatientQuerier( patient_id: str, *, fhir_client: FHIRClient, fhir_patient_info: Optional[RetrievedPatientDetailsJSON] = None, ehr_provider: Optional[str] = None, patient_dict: Optional[dict[str, Any]] = None,):Provides query/data extraction methods for a given patient.
This class is a higher-level abstraction than the direct API interactions, providing methods for extracting/munging data from the API responses.
Arguments
patient_id: The patient ID this querier corresponds to.fhir_client: FHIRClient instance.fhir_patient_info: FHIR Patient Info with contact details.ehr_provider: The EHR provider eg. "nextech", "epic"patient_dict: Optional patient details. If we've created this class with from_patient_query, we'll store the obtained patient_dict for later reference.
Ancestors
Static methods
from_patient_query
def from_patient_query( patient_dob: str | date, given_name: Optional[str] = None, family_name: Optional[str] = None, *, fhir_client: FHIRClient, ehr_provider: Optional[EHRProvider] = None,) ‑> FHIRR4PatientQuerier:Build a FHIRR4PatientQuerier from patient query details.
Arguments
patient_dob: Patient date of birth.given_name: Patient given name.family_name: Patient family name.fhir_client: FHIRClient instanceehr_provider: The EHR provider
Returns NextGenPatientQuerier for the target patient.
Raises
NoMatchingFHIRR4PatientError: No patients matching the name/dob criteria could be foundNonSpecificFHIRR4PatientError: Multiple patients match the criteria, could not determine the correct oneNoFHIRR4PatientIDError: Patient matching the criteria was found, but no patient ID was associated
get_patient_response_by_name
def get_patient_response_by_name( fhir_client: FHIRClient, patient_dob: str | date, given_name: Optional[str] = None, family_name: Optional[str] = None,) ‑> Optional[dict[str, typing.Any]]:Get JSON response from /Patient endpoint given name and DOB.
Methods
download_all_documents
def download_all_documents(self, save_path: Path) ‑> list[pathlib.Path]:Inherited from:
BaseEHRQuerier.download_all_documents :
Download PDF documents for the current patient.
Arguments
save_path: Documents path for the PDF documents to be saved.
download_documents_batch
def download_documents_batch( self, save_path: Path, batch_document_infos: list[DocumentInfo],) ‑> Tuple[list[pathlib.Path], list[str]]:Downloads a batch of documents.
Returns A tuple containing:
- list of documents that downloaded successfully.
- list of documents that could not be downloaded.
get_document_infos
def get_document_infos( self,) ‑> Iterable[list[DocumentInfo]]:Yields document items related to this patient.
get_next_appointment
def get_next_appointment(self) ‑> Optional[datetime.date]:Get the next appointment date for the patient.
Falls back to encounters if appointments are not available or empty.
Returns The next appointment date for the patient from today, or None if they have no future appointment. Any cancelled or errored appointments are ignored.
Raises
FHIRR4GetPatientInfoError: If unable to retrieve patient information.
get_patient_code_states
def get_patient_code_states( self,) ‑> PatientCodeDetails:Get information of Conditions and Procedures codes this patient has.
Sugar method that combines get_patient_condition_code_states() and get_patient_procedure_code_states() and returns a pre-constructed PatientCodeDetails container.
Returns A PatientCodeDetails instance detailing the presence or absence of the provided Conditions and Procedures codes for the patient.
Raises
FHIRR4GetPatientInfoError: If unable to retrieve condition information.
get_patient_conditions
def get_patient_conditions( self, statuses_filter: Optional[list[ClinicalStatus]] = None, code_types_filter: Optional[list[CodeSystems]] = None,) ‑> list[Condition]:Get conditions related to this patient.
Arguments
statuses_filter: If provided, returns only conditions of that status e.g. ['active','recurrence']code_types_filter: If provided, returns only conditions with codes of a specific code system (ICD10, Snomed) e.g. ["icd10"]
Returns A list of Condition objects relevant for the patient, detailing its status and dates, sorted by condition onset date.
Raises
FHIRR4GetPatientInfoError: If unable to retrieve patient condition information.
get_patient_latest_medical_practitioner
def get_patient_latest_medical_practitioner(self) ‑> Optional[str]:Retrieves the latest medical practitioner for the patient.
This is the rendering provider for the patient's last encounter.
Returns The name of the latest medical practitioner for the patient, or None if there is no name listed on the latest encounter.
Raises
FHIRR4GetPatientInfoError: If unable to retrieve patient encounter information.
get_patient_procedures
def get_patient_procedures( self, statuses_filter: Optional[list[ProcedureStatus]] = None, code_types_filter: Optional[list[CodeSystems]] = None,) ‑> list[Procedure]:Get information of procedure codes this patient has.
Arguments
statuses_filter: If provided, returns only procedures of that status e.g. ['completed', 'in-progress']code_types_filter: If provided, returns only conditions with codes of a specific code system (CPT4, Snomed) e.g. ["cpt4", "snomed"]
Returns A list of Procedure objects relevant for the patient, detailing its status and dates, sorted by procedure date.
Raises
FHIRR4GetPatientInfoError: If unable to retrieve patient procedures information.
get_patient_response_by_id
def get_patient_response_by_id(self) ‑> Optional[dict[str, typing.Any]]:Get JSON response from /Patient endpoint given a Patient ID.
get_previous_appointment_details
def get_previous_appointment_details( self, include_maybe_attended: bool = True,) ‑> list[EHRAppointment]:Get list of previous appointments for the patient.
Returns A list of EHRAppointment for the patient, sorted chronologically, or an empty list if they have no previous appointments.
Raises
FHIRR4GetPatientInfoError: If unable to retrieve patient information.
get_visual_acuity
def get_visual_acuity(self) ‑> Optional[Observation]:Get Visual Acuity observation for a patient.
produce_json_dump
def produce_json_dump( self, save_path: Path, elements_to_dump: Container[str] = frozenset({'patientInfo', 'medications', 'appointments', 'procedures', 'encounters', 'conditions', 'chart'}),) ‑> None:Produce a JSON dump of patient information for the target patient.
Saves the JSON dump out to file and the contents can be controlled by
elements_to_dump.
The following options are recognised: - "patientInfo": /Patient - "appointments": /Appointment (not always available) - "conditions": /Conditions - "encounters": /Encounters - "medications": /MedicationRequest - "procedures": /Procedures
Arguments
save_path: The file location to save the JSON dump to.elements_to_dump: Collection of elements to include in the dump. See above for what options can be included.