Usage

pyembeddedfhir requires Docker to run the 🔥 FHIR server. Connection to the Docker daemon can be configured via environment variables:

  • DOCKER_HOST - The URL to the Docker host.

  • DOCKER_TLS_VERIFY - Verify the host against a CA certificate.

  • DOCKER_CERT_PATH - A path to a directory containing TLS certificates to use when connecting to the Docker host.

To use pyembeddedfhir in a project:

from pyembeddedfhir.fhir_runner import FHIRFlavor, FHIRRunner

with FHIRRunner(
    flavor=FHIRFlavor.HAPI,
    host_ip="0.0.0.0",
) as running_fhir:
    print("The FHIR server is up and running 🔥")
    docker_network_id = running_fhir.network_id
    container_ip = running_fhir.ip
    port = running_fhir.port
    path = running_fhir.path
    host_port = running_fhir.host_port

API

class pyembeddedfhir.fhir_runner.FHIRRunner(flavor: pyembeddedfhir.models.FHIRFlavor, host_ip: Optional[str] = None, kill_orphans: bool = True, network_id: Optional[str] = None, startup_timeout: float = 120, docker_client: Optional[docker.client.DockerClient] = None)[source]

Bases: object

A class responsible for running a selected FHIR implementation.

Can be used in one of two ways:

  • Directly, using the running_fhir property and the stop method.

  • As a context manager: with FHIRRunner(configuration) as running_fhir:

Parameters
  • flavor (FHIRFlavor) – Selected FHIR implementation.

  • host_ip (str, optional) – Host IP used to expose the service externally , defaults to None

  • kill_orphans (bool, optional) – Whether to destroy orphaned Docker objects from previous runs, defaults to True

  • network_id (Optional[str], optional) – A Docker network id to attach to, defaults to None

  • startup_timeout (float, optional) – Number of seconds to wait for server startup, defaults to 120

  • docker_client (Optional[DockerClient], optional) – A Docker client, will be created using docker.from_env() if not set, defaults to None

Variables

running_fhir (RunningFHIR) – Descriptor of the running FHIR server.

Raises
  • NotImplementedError – Selected implementation is not supported.

  • StartupTimeoutError – An error caused by exceeding the time limit.

  • ContainerRuntimeError – An error related to container runtime.

running_fhir: pyembeddedfhir.models.RunningFHIR
stop() None[source]

Stop the FHIR server and perform cleanup.

Raises
class pyembeddedfhir.models.FHIRFlavor(value)[source]

Bases: enum.Enum

An enumeration.

HAPI = 1
MICROSOFT = 2
class pyembeddedfhir.models.RunningFHIR(network_id: str, ip: str, port: int, path: str, host_port: Optional[int])[source]

Bases: object

A descriptor of a running FHIR instance.

Variables
  • network_id (str) – The ID of the Docker network

  • ip (str) – The IP address of the Docker container

  • port (int) – The port of a running FHIR instance

  • path (str) – URL path to the FHIR instance

  • host_ip (Optional[str], optional) – The IP address of the interface on the host

host_port: Optional[int]
ip: str
network_id: str
path: str
port: int
exception pyembeddedfhir.errors.AlreadyStoppedError[source]

Bases: pyembeddedfhir.errors.PyFHIREmbeddedError

An error generated, when the user attempted to stop a server that was already stopped.

exception pyembeddedfhir.errors.ContainerRuntimeError[source]

Bases: pyembeddedfhir.errors.PyFHIREmbeddedError

An error generated, when the container runtime failed.

exception pyembeddedfhir.errors.NetworkNotFoundError[source]

Bases: pyembeddedfhir.errors.ContainerRuntimeError

An error generated, when a specified network was not found.

exception pyembeddedfhir.errors.PyFHIREmbeddedError[source]

Bases: Exception

A base class for errors in this package.

exception pyembeddedfhir.errors.StartupTimeoutError[source]

Bases: pyembeddedfhir.errors.PyFHIREmbeddedError

An error generated, when a startup timeout was reached.