Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

Pre-release

This release is a pre-release and may not be stable for production use.

Cavell Prism Client

CI PyPI Python License: MIT

Python client for Cavell Prism — turn clinical data into FHIR and persist it to your own FHIR server. Two paths:

  • Clinical notes → FHIR resources, extracted by Prism's models
  • Structured lab results → FHIR Observations, mapped deterministically with no LLM, no token cost, and idempotent re-runs

Cavell never connects to your FHIR server. Your system sends clinical text to the Prism API, receives extracted resources back, and persists them locally with your own credentials. Cavell has no access to your database and stores no credentials: every request carries your own LLM Gateway key.

Installation

pip install cavell-prism-client

Or with uv:

uv add cavell-prism-client

The import name is cavell_client.

You need a Prism API URL (https://prd.prism.cavell.app/api) and an LLM Gateway key — contact your Cavell representative for a key. For a local FHIR server, docker compose up -d in this repo starts HAPI on http://localhost:8090.

Ingest a CSV of clinical notes

Most work starts from an export, so this is the shortest complete path from a CSV to FHIR resources on your server. columns maps SDK field names to your headers — nothing in your file has to be renamed.

import csv
from cavell_client import (
    CavellClient,
    IngestionPipeline,
    Organization,
    Patient,
    Practitioner,
    Document,
)

with open("notes.csv", newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))

with CavellClient(
    api_url="https://prd.prism.cavell.app/api",
    api_key="<your LLM Gateway key>",
    fhir_base_url="http://localhost:8090",
) as client:
    pipeline = IngestionPipeline(client, default_organization="CGH-001")

    pipeline.seed(
        organizations=[Organization(identifier="CGH-001", name="City General")],
        patients=Patient.from_rows(
            rows,
            columns={"identifier": "patient_id", "name": "patient_name"},
            managing_organization="CGH-001",
        ),
        practitioners=Practitioner.from_rows(
            rows,
            columns={"identifier": "practitioner_id", "name": "practitioner_name"},
            organization_identifier="CGH-001",
        ),
    )

    documents = Document.from_rows(
        rows,
        columns={
            "text": "note_text",
            "patient_identifier": "patient_id",
            "date": "note_date",
            "document_id": "note_id",
            "encounter_id": "encounter_id",
            "practitioner_identifier": "practitioner_id",
        },
    )

    for outcome in pipeline.extract_all(documents, batch_size=500):
        print(outcome)

extract_all() sorts every document by date before batching, so each patient's notes are extracted oldest-first even when they span batches. Extraction is resume-safe (skip_processed=True by default), retries transient failures, and aborts cleanly on auth/gateway outages. A note older than the patient's newest already-extracted one is extracted against split context: it is shown the record as it stood on its own date, with everything newer sent separately so the model cannot read its own future as history. Such a note comes back with out_of_order=True — a record of how it was processed, not a failure.

Ingest a CSV of lab results

Structured results do not need a model. The same row always produces the same Observation, spends no gateway tokens, and can be re-sent safely.

import csv
from cavell_client import CavellClient, LabResult, LabIngestionPipeline

with open("lab_results.csv", newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))

with CavellClient(
    api_url="https://prd.prism.cavell.app/api",
    api_key="<your LLM Gateway key>",
    fhir_base_url="http://localhost:8090",
) as client:
    results = LabResult.from_rows(
        rows,
        columns={
            "lab_result_id": "lab_result_id",
            "patient_identifier": "patient_id",
            "test_name": "test_name",
            "value": "value",
            "collected_datetime": "collected_datetime",
            "loinc_code": "loinc_code",
            "unit": "unit",
            "reference_low": "reference_low",
            "reference_high": "reference_high",
            "encounter_id": "encounter_id",
            "practitioner_id": "practitioner_id",
        },
    )

    outcome = LabIngestionPipeline(client).ingest(results)
    print(outcome)
    # 244/251 rows accepted (244 created, 0 already present), 7 rejected

    for r in outcome.rejected:
        print(f"row {r.index}  {r.lab_result_id}  [{r.stage}]  {r.reason}")

Only the first five columns entries are required. The patients, encounters and practitioners the rows reference must already exist — lab ingestion never creates them, and a row pointing at something unknown is skipped and reported rather than silently dropped. Re-running the same file creates nothing twice: every row is a conditional create keyed on your own lab_result_id.

What every column means, and exactly when a row is rejected: CSV field reference.

Extract straight from a database

If the notes or lab results live in a database table with the same columns, skip the CSV export. Any database works — through a SQLAlchemy URL (pip install 'cavell-prism-client[database]' plus your driver) or any DB-API connection you already have — and each run only reads and extracts what is not done yet, so the same call keeps a growing table up to date:

The code is the CSV example above with the table in place of rows:

from cavell_client import DatabaseSource

notes = DatabaseSource(
    "postgresql+psycopg://reader@db.example.org/clinical", table="notes"
)

pipeline.seed(
    organizations=[Organization(identifier="CGH-001", name="City General")],
    practitioners=Practitioner.from_rows(  # same call; reads only these columns
        notes,
        columns={"identifier": "practitioner_id", "name": "practitioner_name"},
        organization_identifier="CGH-001",
    ),
)  # no patients: they are created from the table as their notes come up

report = pipeline.extract_from_database(
    notes,
    columns={...},  # the mapping you gave Document.from_rows()
    patient_columns={  # ...and the one you gave Patient.from_rows()
        "identifier": "patient_id",
        "name": "patient_name",
    },
    patient_defaults={"managing_organization": "CGH-001"},
    failures_path="prism_failures.jsonl",
)
print(report)

Bad rows are skipped and reported, and every failure is logged with who has to act — your data, Prism, or your FHIR server — and why. See Extracting from a database.

One record at a time

The same objects built by hand — for a queue consumer, a webhook, or a quick try without a file.

from cavell_client import CavellClient, IngestionPipeline
from cavell_client import (
    Organization,
    Patient,
    Document,
    LabResult,
    LabIngestionPipeline,
)

with CavellClient(
    api_url="https://prd.prism.cavell.app/api",
    api_key="<your LLM Gateway key>",
    fhir_base_url="http://localhost:8090",
) as client:
    pipeline = IngestionPipeline(client, default_organization="CGH-001")

    pipeline.seed(
        organizations=[Organization(identifier="CGH-001", name="City General")],
        patients=[Patient(identifier="MRN-1", managing_organization="CGH-001")],
    )

    for outcome in pipeline.extract(
        [
            Document(
                text="Patient diagnosed with type 2 diabetes...",
                patient_identifier="MRN-1",
                date="2024-01-15",
                document_id="note-001",
            ),
        ]
    ):
        print(outcome)

    print(
        LabIngestionPipeline(client).ingest(
            [
                LabResult(
                    lab_result_id="LAB-0001",  # your LIS accession — the idempotency key
                    patient_identifier="MRN-1",
                    test_name="C-reactive protein",
                    value="212",
                    unit="mg/L",
                    loinc_code="1988-5",
                    reference_high=5.0,
                    collected_datetime="2024-01-15T21:40:00+01:00",
                ),
            ]
        )
    )

Clinical validation

Every resource extracted from a note carries an unvalidated meta tag. When a clinician has reviewed a resource, remove the tag; any later update re-adds it:

client.list_unvalidated_resources(patient_fhir_id, "Condition")  # review queue
client.mark_validated("Condition", condition_id)  # $meta-delete

Lab Observations carry no such tag — a structured feed is already a source of truth.

Documentation

polaris-health.github.io/cavell-prism-client

Page What is in it
CSV field reference Every column of both file types, what it does, and the rejection rules
Clinical notes pipeline Seeding, chronological ordering, out-of-order notes, updates, error handling
Lab results pipeline Fail-closed reference checks, the rejection report, idempotent re-runs
Extracting from a database Connecting to any database, incremental runs on large tables, the failure report
Client API The lower-level client: direct extraction, resource queries, validation tags

Runnable demo notebooks on synthetic data live in docs/notebooks/.

Contributing & security

See CONTRIBUTING.md for development setup and the release process, and SECURITY.md for how to report vulnerabilities.

License

MIT

Metadata

Release files for cavell-prism-client 0.11.0.dev202611140519

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for cavell-prism-client 0.11.0.dev202611140519
File Size Uploaded Provenance Actions
cavell_prism_client-0.11.0.dev202611140519.tar.gz 181.9 kB With provenance Details for cavell_prism_client-0.11.0.dev202611140519.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cavell-prism-client 0.11.0.dev202611140519
File Interpreter ABI Platform Actions
cavell_prism_client-0.11.0.dev202611140519-py3-none-any.whl Python 3 none any Details for cavell_prism_client-0.11.0.dev202611140519-py3-none-any.whl

Total release size: 276.3 kB

Release files / cavell_prism_client-0.11.0.dev202611140519.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL cavell_prism_client-0.11.0.dev202611140519.tar.gz
Size 181.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f217063e5f49508cd2c9031690d517983701cf34cb249ff53754fdd2501b4b1c
BLAKE2b-256 checksum
How to use checksums
be38f71cd009ce59b41823c160fce366c73629df68f2934bb97e5fe77a4fe733
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / cavell_prism_client-0.11.0.dev202611140519-py3-none-any.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL cavell_prism_client-0.11.0.dev202611140519-py3-none-any.whl
Size 94.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f7d33cf54665dd465092203c9316d7db59a3da82125238221b969020b72f71e
BLAKE2b-256 checksum
How to use checksums
4d9d8d07d5827ec04d8fb9a91de6ae8099e3eb1b26e76d724d79741876b3c369
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for cavell-prism-client 0.11.0.dev202611140519

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Change of provenance

The configuration that created this release differs from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for cavell_prism_client-0.11.0.dev202611140519.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page