Skip to main content

address_utils

Shared utilities for EHR address handling.

Module

Functions

extract_postal_code_and_country

def extract_postal_code_and_country(    addresses: Iterable[Union[object, dict[str, object]]],)> tuple[typing.Optional[str], typing.Optional[str]]:

Extract postal code and country from addresses.

Iterates through the addresses and prefers the first that has both a non-empty postal code and country. If no such address exists, falls back to the first address with at least a postal code (country may be None). This ensures valid postal codes are not dropped when country is missing, allowing downstream distance filtering to work (e.g. with a default country).

Arguments

  • addresses: Iterable of address objects (dict or object with postalCode and country).

Returns Tuple of (postal_code, country). Either may be None if no address has a postal code.