Skip to main content

types

EHR types.

Module

Functions

dedupe_dataclass_list

def dedupe_dataclass_list(items: list[_T])> list[~_T]:

Remove duplicate dataclass instances from a list, preserving order.

Uses _type_preserving_key() to create hashable representations for comparison. The first occurrence of each unique item is kept.

Arguments

  • items: A list of dataclass instances.

Returns A new list with duplicates removed, maintaining original order.

Classes

Allergy

class Allergy(    date: datetime | None,    code_text: str | None,    clinical_status: str | None,    reactions: list[AllergyReaction],    codings: list[Coding] = [],):

Dataclass to describe a patient allergy/intolerance.

code is 0..1 on the source FHIR resource — a resource may carry no top-level diagnosis code at all and rely entirely on reactions[].substance_code instead (both are None in that case, not merely absent). date resolves onsetDateTimeonsetPeriod.startrecordedDate, the same fallback order Condition.onset_datetime uses.

code can itself carry more than one coding — the same diagnosis named in more than one system. codings holds every one of them; code_system/code_code/code_display are computed properties reading the first entry (None if codings is empty — a resource already read back from a row an older SDK build wrote, before this field existed). One Allergy per FHIR resource either way.

Variables

  • static clinical_status : str | None
  • static code_text : str | None
  • static codings : list[Coding]
  • code_code : str | None - The first coding's code, or None if codings is empty.
  • code_display : str | None - The first coding's display, or None if codings is empty.
  • code_system : str | None - The first coding's system, or None if codings is empty.

AllergyReaction

class AllergyReaction(substance_text: str | None, substance_codings: list[Coding] = []):

One AllergyIntolerance.reaction entry, flattened to its substance code.

reaction is 0..* on the owning AllergyIntolerance — a single allergy/intolerance can list more than one reaction, each potentially naming a different substance (e.g. a drug class entry alongside a specific drug within it). manifestation/severity/exposureRoute are not captured here; only substance is needed to match AllergyCriterion.code against, per https://hl7.org/fhir/R4/allergyintolerance-definitions.html#AllergyIntolerance.reaction.substance.

substance (like AllergyIntolerance.code) can itself carry more than one coding. substance_codings holds every one of them. substance_system/substance_code/substance_display are computed properties reading the first entry (None if substance_codings is empty — a reaction already read back from a row an older SDK build wrote, before this field existed).

Variables

  • static substance_codings : list[Coding]
  • static substance_text : str | None
  • substance_code : str | None - The first substance coding's code, or None if empty.
  • substance_display : str | None - The first substance coding's display, or None if empty.
  • substance_system : str | None - The first substance coding's system, or None if empty.

BodySite

class BodySite(    text: str | None = None,    bodysite_coding_system: str | None = None,    bodysite_coding_code: str | None = None,    bodysite_coding_display: str | None = None,):

Dataclass to describe BodySite related to a Condition/Procedure/Observation.

Variables

  • static bodysite_coding_code : str | None
  • static bodysite_coding_display : str | None
  • static bodysite_coding_system : str | None
  • static text : str | None

CodeableConcept

class CodeableConcept(    system: str | None, code: str | None, display: str | None, text: str | None,):

FHIR CodeableConcept datatype, flattened to its first coding.

Used as Observation.value[x] when the shape is valueCodeableConcept.

Variables

  • static code : str | None
  • static display : str | None
  • static system : str | None
  • static text : str | None

Coding

class Coding(system: str | None, code: str | None, display: str | None):

One coding entry within a FHIR CodeableConcept.

A CodeableConcept can carry more than one coding — the same concept named in more than one system (e.g. a SNOMED coding alongside an ICD-10 one for the same diagnosis).

Variables

  • static code : str | None
  • static display : str | None
  • static system : str | None

Condition

class Condition(    onset_datetime: datetime | None,    code_text: str | None,    clinical_status: str | None,    bodysite: BodySite | None = None,    codings: list[Coding] = [],):

Dataclass to describe patient Condition.

codings holds every coding on the resource's own code — see Coding's docstring.

Variables

  • static clinical_status : str | None
  • static code_text : str | None
  • static codings : list[Coding]
  • code_code : str | None - The first coding's code, or None if codings is empty.
  • code_display : str | None - The first coding's display, or None if codings is empty.
  • code_system : str | None - The first coding's system, or None if codings is empty.

Device

class Device(code_text: str | None, status: str | None, codings: list[Coding] = []):

Dataclass to describe a patient device record.

type is 0..1 on the source FHIR resource — a resource may carry no kind/type code at all (codings empty, not merely absent, in that case). type can itself carry more than one coding — the same kind of device named in more than one system. codings holds every one of them; code_system/code_code/code_display are computed properties reading the first entry (None if codings is empty). One Device per FHIR resource.

status is stored for tabulation only — not read by DeviceCriterion, which matches on codings alone.

Variables

  • static code_text : str | None
  • static codings : list[Coding]
  • static status : str | None
  • code_code : str | None - The first coding's code, or None if codings is empty.
  • code_display : str | None - The first coding's display, or None if codings is empty.
  • code_system : str | None - The first coding's system, or None if codings is empty.

DosageInstruction

class DosageInstruction(    text: str | None,    route: str | None,    dose_and_rate: list[DoseAndRate],    frequency: int | None,    period: float | None,    period_unit: str | None,    site: BodySite | None = None,):

One dosage/administration instruction for a Medication.

Normalised from FHIR's Dosage datatype (MedicationRequest .dosageInstruction, MedicationStatement.dosage, MedicationDispense.dosageInstruction — all 0..*, e.g. for a taper) or from MedicationAdministration.dosage (a distinct, simpler 0..1 backbone element with no timing, since an administration is a point-in-time event rather than a schedule).

dose_and_rate holds every dose reading FHIR gave us for this instruction — see DoseAndRate. It is [] when the instruction has no structured dose at all; text may still carry a free-text instruction in that case.

site is where this instruction was administered. FHIR has no Medication-level bodySite element, unlike Condition/Procedure/ Observation. The body site a medication is given to is a property of how it is dosed, not of the medication entry as a whole. Dosage.site/MedicationAdministrationDosage.site are both 0..1, singular, unlike bodySite's 0..*. A bilateral prescription carries this as two separate instructions, one per site, rather than one instruction with two sites.

Variables

  • static frequency : int | None
  • static period : float | None
  • static period_unit : str | None
  • static route : str | None
  • static text : str | None

DoseAndRate

class DoseAndRate(    type: "Literal['ordered', 'calculated'] | None",    dose_quantity: float | None,    dose_low: float | None,    dose_high: float | None,    dose_unit: str | None,):

One dose reading from FHIR's Dosage.doseAndRate list.

Dosage.doseAndRate (MedicationRequest/Statement/Dispense) is a list because one instruction can carry more than one dose reading for the same administration. The two readings FHIR's own dose-rate-type CodeSystem names are ordered (the prescriber's own order, sometimes in per-weight units such as "mg/kg") and calculated (a separately computed absolute amount for this specific patient, for example after a weight- or renal-function-based calculation, or after rounding to an available tablet strength). We keep every entry instead of choosing one, since a caller may need to read either value — the calculated amount is the one in patient-specific absolute units, but the ordered amount is the prescriber's actual instruction.

type is None for an entry with no type element — common, since the dose-rate-type binding is optional in FHIR. MedicationAdministration.dosage.dose has no type element at all (and is never a list — its single reading is represented the same way, as a one-entry list on the owning DosageInstruction), but is stamped "calculated" rather than left None: an administration records an exact amount actually given, not a prescriber's own instruction, the same distinction "calculated" already draws on a Dosage.doseAndRate entry.

The dose amount is itself a FHIR choice type: either a single quantity (dose_quantity) or a range (dose_low/dose_high, e.g. "give 1 to 2 tablets"). dose_unit applies to whichever of the two is set. Exactly one of dose_quantity or the dose_low/dose_high pair is set for a given entry; the other stays None.

Variables

  • static dose_high : float | None
  • static dose_low : float | None
  • static dose_quantity : float | None
  • static dose_unit : str | None
  • static type : Optional[Literal['ordered', 'calculated']]

DownloadedEHRDocumentInfo

class DownloadedEHRDocumentInfo(    *,    document_id: str,    document_date: str = '',    document_description: str = '',    extension: str | None = '',    source_url: str | None = None,    content_type: str | None = None,    inline_data: str | None = None,    local_path: Path,):

Document Info for successfully downloaded documents from EHR.

Variables

Static methods


from_instance

def from_instance(instance: EHRDocumentInfo, **kwargs: Any)> Self:

Inherited from:

EHRDocumentInfo.from_instance :

Method to instantiate children class from parent class.

EHRAppointmentEncounter

class EHRAppointmentEncounter(    appointment_date: date | None, location_name: str | None, event_name: str | None,):

Class for Patient Appointment.

Variables

  • static event_name : str | None
  • static location_name : str | None

Methods


format_for_csv

def format_for_csv(self)> dict[str, str]:

Format into a readable dictionary for csv.

EHRDocumentInfo

class EHRDocumentInfo(    *,    document_id: str,    document_date: str = '',    document_description: str = '',    extension: str | None = '',    source_url: str | None = None,    content_type: str | None = None,    inline_data: str | None = None,):

Document Information to facilitate download of EHR documents.

Variables

  • static content_type : str | None
  • static document_date : str
  • static document_description : str
  • static document_id : str
  • static extension : str | None
  • static inline_data : str | None
  • static source_url : str | None

Static methods


from_instance

def from_instance(instance: EHRDocumentInfo, **kwargs: Any)> Self:

Method to instantiate children class from parent class.

FailedEHRDocumentInfo

class FailedEHRDocumentInfo(    *,    document_id: str,    document_date: str = '',    document_description: str = '',    extension: str | None = '',    source_url: str | None = None,    content_type: str | None = None,    inline_data: str | None = None,    local_path: Path | None = None,    failed_reason: str,):

Document Info for documents that failed an attempt to upload.

Variables

  • static failed_reason : str

Static methods


from_instance

def from_instance(instance: EHRDocumentInfo, **kwargs: Any)> Self:

Inherited from:

EHRDocumentInfo.from_instance :

Method to instantiate children class from parent class.

Medication

class Medication(    source_resource: "Literal['MedicationRequest', 'MedicationStatement', 'MedicationDispense', 'MedicationAdministration', 'NextGenMedication']",    date: datetime | None,    code_system: str | None,    code_code: str | None,    code_display: str | None,    code_text: str | None,    status: str | None,    dosage: list[DosageInstruction] | None = None,):

Dataclass to describe a patient medication order, statement, dispense, or admin.

source_resource records which FHIR resource (or, for NextGen, which single non-FHIR source) this entry came from — a MedicationDispense or MedicationAdministration entry is materially stronger evidence of actual use than a MedicationRequest (an order, not proof the patient took it). date is normalised across each resource's own date field (MedicationRequest.authoredOn, MedicationStatement .effectiveDateTime/effectivePeriod, MedicationDispense .whenHandedOver/whenPrepared, MedicationAdministration .effectiveDateTime/effectivePeriod) rather than being named after any one of them, since one field here has to represent all four.

Variables

  • static code_code : str | None
  • static code_display : str | None
  • static code_system : str | None
  • static code_text : str | None
  • static source_resource : Literal['MedicationRequest', 'MedicationStatement', 'MedicationDispense', 'MedicationAdministration', 'NextGenMedication']
  • static status : str | None

Observation

class Observation(    date: datetime | None,    code_text: str | None,    value: ObservationValue | None,    bodysite: BodySite | None = None,    codings: list[Coding] = [],):

Observation object from FHIR.

value holds whichever ObservationValue variant value[x] populated, or None if value[x] was absent or an unhandled shape. bodysite comes from the parent resource's own bodySite (single-valued, unlike Condition/Procedure's list-valued one) — a component of a component-bearing Observation has no bodySite of its own, so it inherits the parent's, the same way it inherits the parent's date.

codings holds every coding on the resource's own code — see Coding's docstring.

Variables

  • static code_text : str | None
  • static codings : list[Coding]
  • code_code : str | None - The first coding's code, or None if codings is empty.
  • code_display : str | None - The first coding's display, or None if codings is empty.
  • code_system : str | None - The first coding's system, or None if codings is empty.

Period

class Period(start: datetime | None, end: datetime | None):

FHIR Period datatype: a start/end datetime range.

Used as Observation.value[x] when the shape is valuePeriod.

Variables

Procedure

class Procedure(    performed_datetime: datetime | None,    code_text: str | None,    bodysite: BodySite | None = None,    codings: list[Coding] = [],):

Dataclass to describe patient Procedure.

codings holds every coding on the resource's own code — see Coding's docstring.

Variables

  • static code_text : str | None
  • static codings : list[Coding]
  • code_code : str | None - The first coding's code, or None if codings is empty.
  • code_display : str | None - The first coding's display, or None if codings is empty.
  • code_system : str | None - The first coding's system, or None if codings is empty.

Quantity

class Quantity(value: float | None, unit: str | None):

FHIR Quantity datatype: a measured amount with its unit.

Used both as Observation.value[x] when the shape is valueQuantity, and nested inside Range/Ratio/SampledData.

Variables

  • static unit : str | None
  • static value : float | None

Range

class Range(low: Quantity | None, high: Quantity | None):

FHIR Range datatype: a low/high Quantity bound.

Used as Observation.value[x] when the shape is valueRange.

Variables

Ratio

class Ratio(numerator: Quantity | None, denominator: Quantity | None):

FHIR Ratio datatype: a numerator/denominator Quantity pair.

Used as Observation.value[x] when the shape is valueRatio.

Variables

  • static denominator : Quantity | None

S3UploadedEHRDocumentInfo

class S3UploadedEHRDocumentInfo(    *,    document_id: str,    document_date: str = '',    document_description: str = '',    extension: str | None = '',    source_url: str | None = None,    content_type: str | None = None,    inline_data: str | None = None,    local_path: Path,    s3_key: str,    upload_date: str,):

Document Info for documents successfully uploaded to S3.

Variables

  • static s3_key : str
  • static upload_date : str

Static methods


from_instance

def from_instance(instance: EHRDocumentInfo, **kwargs: Any)> Self:

Inherited from:

DownloadedEHRDocumentInfo.from_instance :

Method to instantiate children class from parent class.

SampledData

class SampledData(    origin: Quantity | None,    period: float | None,    factor: float | None,    lower_limit: float | None,    upper_limit: float | None,    dimensions: int | None,    data: str | None,):

FHIR SampledData datatype: a series of regularly-sampled values.

Used as Observation.value[x] when the shape is valueSampledData. data is the raw space-separated encoded sample string, not decoded into individual values.

Variables

  • static data : str | None
  • static dimensions : int | None
  • static factor : float | None
  • static lower_limit : float | None
  • static period : float | None
  • static upper_limit : float | None

ValueBoolean

class ValueBoolean(value: bool):

Wraps a plain valueBoolean.

Variables

  • static value : bool

ValueDateTime

class ValueDateTime(value: datetime):

Wraps a plain valueDateTime.

Variables

ValueInteger

class ValueInteger(value: int):

Wraps a plain valueInteger.

Variables

  • static value : int

ValueString

class ValueString(value: str):

Wraps a plain valueString, distinguishing it from valueTime.

FHIR represents both valueString and valueTime as a bare string; without a wrapper the two shapes would be indistinguishable at runtime.

Variables

  • static value : str

ValueTime

class ValueTime(value: str):

Wraps a plain valueTime (a time-of-day, e.g. "13:04:23").

Kept as a string rather than datetime.time, since FHIR time values carry no date/timezone context. See ValueString for why this needs a dedicated wrapper.

Variables

  • static value : str