querier
Provides a high-level abstraction for extracting patient info from NextGen.
Module
Functions
recursively_remove_links
def recursively_remove_links(dictionary: Any) ‑> Any:Remove any references to _links in the patient data from Nextgen.
Classes
FromPatientQueryError
class FromPatientQueryError(*args, **kwargs):No patient was returned when constructing from query.
Ancestors
- NextGenFHIRAPIError
- NextGenAPIError
- BitfountError
- builtins.Exception
- builtins.BaseException
NextGenGetPatientInfoError
class NextGenGetPatientInfoError(*args, **kwargs):Could not retrieve patient info.
Ancestors
- GetPatientInfoError
- NextGenEnterpriseAPIError
- NextGenAPIError
- BitfountError
- builtins.Exception
- builtins.BaseException
NextGenPatientQuerier
class NextGenPatientQuerier( patient_id: str, *, fhir_api: NextGenFHIRAPI, enterprise_api: NextGenEnterpriseAPI, fhir_patient_info: Optional[RetrievedPatientDetailsJSON] = 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_api: NextGenFHIRAPI instance.enterprise_api: NextGenEnterpriseAPI instance.fhir_patient_info: FHIR Patient Info with contact details.
Ancestors
Static methods
from_nextgen_session
def from_nextgen_session( patient_id: str, nextgen_session: NextGenAuthSession, fhir_url: str = 'https://fhir.nextgen.com/nge/prod/fhir-api-r4/fhir/R4', enterprise_url: str = 'https://nativeapi.nextgen.com/nge/prod/nge-api/api',) ‑> NextGenPatientQuerier:Build a NextGenPatientQuerier from a NextGenAuthSession.
Arguments
patient_id: The patient ID this querier will correspond to.nextgen_session: NextGenAuthSession for constructing API instances against.fhir_url: Optional, the FHIR API url to use.enterprise_url: Optional, the Enterprise API url to use.
Returns NextGenPatientQuerier for the target patient.
from_patient_query
def from_patient_query( patient_dob: str | date, given_name: Optional[str] = None, family_name: Optional[str] = None, *, fhir_api: Optional[NextGenFHIRAPI] = None, enterprise_api: Optional[NextGenEnterpriseAPI] = None, nextgen_session: Optional[NextGenAuthSession] = None, fhir_url: str = 'https://fhir.nextgen.com/nge/prod/fhir-api-r4/fhir/R4', enterprise_url: str = 'https://nativeapi.nextgen.com/nge/prod/nge-api/api',) ‑> NextGenPatientQuerier:Build a NextGenPatientQuerier from patient query details.
Arguments
patient_dob: Patient date of birth.given_name: Patient given name.family_name: Patient family name.fhir_api: Optional, NextGenFHIRAPI instance. If not provided,nextgen_sessionmust be.enterprise_api: Optional, NextGenEnterpriseAPI instance. If not provided,nextgen_sessionmust be.nextgen_session: Optional, NextGenAuthSession instance. Only needed iffhir_apiorenterprise_apiare not provided.fhir_url: Optional, FHIR API url. Only needed iffhir_apiis not provided and a non-default URL is wanted.enterprise_url: Optional, Enterprise API url. Only needed iffhir_apiis not provided and a non-default URL is wanted.
Returns NextGenPatientQuerier for the target patient.
Raises
FromPatientQueryError: if patient ID could not be found (maybe because multiple patients match the criteria, or none do)ValueError: if unable to construct the API instances because session information was not provided.
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.
get_next_appointment
def get_next_appointment(self) ‑> Optional[datetime.date]:Inherited from:
BaseEHRQuerier.get_next_appointment :
Get the next appointment date for the patient.
Returns The next appointment date for the patient from today, or None if they have no future appointment.
Raises
NextGenGetPatientInfoError: If unable to retrieve patient information.
get_patient_code_states
def get_patient_code_states( self,) ‑> PatientCodeDetails:Inherited from:
BaseEHRQuerier.get_patient_code_states :
Get information of Condition and Procedure 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 Condition and Procedure codes for the patient.
get_patient_condition_code_states
def get_patient_condition_code_states( self, statuses_filter: Optional[list[ClinicalStatus]] = None, code_types_filter: Optional[list[CodeSystems]] = None,) ‑> list[str]:Get condition codes related to this patient.
Returns A list of condition codes diagnosed for the patient.
Raises
NextGenGetPatientInfoError: If unable to retrieve patient condition information.
get_patient_latest_medical_practitioner
def get_patient_latest_medical_practitioner(self) ‑> Optional[str]:Inherited from:
BaseEHRQuerier.get_patient_latest_medical_practitioner :
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
NextGenGetPatientInfoError: If unable to retrieve patient encounter information.
get_patient_procedure_code_states
def get_patient_procedure_code_states( self, statuses_filter: Optional[list[ProcedureStatus]] = None, code_types_filter: Optional[list[CodeSystems]] = None,) ‑> list[str]:Get information of procedure codes this patient has.
Returns A list of procedure codes relevant for the patient.
Raises
NextGenGetPatientInfoError: If unable to retrieve patient procedures information.
get_previous_appointment_details
def get_previous_appointment_details( self, include_maybe_attended: bool = True,) ‑> list[EHRAppointment]:Get the details of previous appointments for the patient.
Returns The list of previous appointments for the patient, or an empty list if they have no previous appointments.
Raises
NextGenGetPatientInfoError: If unable to retrieve patient information.
produce_json_dump
def produce_json_dump( self, save_path: Path, elements_to_dump: Container[str] = frozenset({'conditions', 'patientInfo', 'chart', 'procedures', 'medications', 'encounters', 'appointments'}),) ‑> None:Inherited from:
BaseEHRQuerier.produce_json_dump :
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":
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.