Skip to main content

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

FHIRR4PatientQuerier

class FHIRR4PatientQuerier(    patient_id: str,    *,    fhir_client: SyncFHIRClient,    fhir_patient_info: Optional[RetrievedPatientDetailsJSON] = None,    ehr_provider: Optional[str] = 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.

Create a FHIRR4PatientQuerier instance.

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"

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: SyncFHIRClient,    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 instance
  • ehr_provider: The EHR provider

Returns NextGenPatientQuerier for the target patient.

Raises

  • NoMatchingFHIRR4PatientError: No patients matching the name/dob criteria could be found
  • NonSpecificFHIRR4PatientError: Multiple patients match the criteria, could not determine the correct one
  • NoFHIRR4PatientIDError: Patient matching the criteria was found, but no patient ID was associated

Methods


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_condition_code_states

def get_patient_condition_code_states(    self,    statuses_filter: Optional[list[ClinicalStatus]] = None,    code_types_filter: Optional[list[CodeSystems]] = None,)> list:

Get condition codes 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 codes diagnosed for the patient.

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_procedure_code_states

def get_patient_procedure_code_states(    self,    statuses_filter: Optional[list[ProcedureStatus]] = None,    code_types_filter: Optional[list[CodeSystems]] = None,)> list:

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 codes relevant for the patient.

Raises

  • FHIRR4GetPatientInfoError: If unable to retrieve patient procedures information.

get_previous_appointment_details

def get_previous_appointment_details(self, include_maybe_attended: bool = True)> list:

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.