Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ jobs:
flow_unit_shards: ${{ steps.classify.outputs.flow_unit_shards }}
types: ${{ steps.classify.outputs.types }}
agent: ${{ steps.classify.outputs.agent }}
eligibility: ${{ steps.classify.outputs.eligibility }}
verify: ${{ steps.classify.outputs.verify }}
capture: ${{ steps.classify.outputs.capture }}
privacy: ${{ steps.classify.outputs.privacy }}
Expand Down Expand Up @@ -144,7 +145,7 @@ jobs:
if [ "$EVENT_NAME" = pull_request ]; then unit_shards=4; else unit_shards=2; fi
echo "flow_unit_shards=$unit_shards" >> "$GITHUB_OUTPUT"
all() {
for pkg in flow types agent verify capture privacy desktop tray program_graph weight; do echo "$pkg=true" >> "$GITHUB_OUTPUT"; done
for pkg in flow types agent eligibility verify capture privacy desktop tray program_graph weight; do echo "$pkg=true" >> "$GITHUB_OUTPUT"; done
exit 0
}
case "$EVENT_NAME" in
Expand Down Expand Up @@ -180,6 +181,8 @@ jobs:
types="$(hit "^packages/types/|$wf")"
# The agent shim is tested against the in-tree core.
agent="$(hit "^packages/(agent|flow|types)/|$wf")"
# The optional eligibility connector is tested against the in-tree core.
eligibility="$(hit "^packages/(connectors/eligibility|flow|types)/|$wf")"
verify="$(hit "^packages/(verify|flow|types)/|$wf")"
capture="$(hit "^packages/capture/|$wf")"
privacy="$(hit "^packages/privacy/|$wf")"
Expand All @@ -197,6 +200,7 @@ jobs:
echo "flow=$flow"
echo "types=$types"
echo "agent=$agent"
echo "eligibility=$eligibility"
echo "verify=$verify"
echo "capture=$capture"
echo "privacy=$privacy"
Expand Down Expand Up @@ -337,6 +341,51 @@ jobs:
- name: Test
run: pytest -q

eligibility:
name: eligibility connector (py${{ matrix.python-version }})
needs: scope
if: github.event.pull_request.draft != true && (needs.scope.outputs.eligibility == 'true')
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON((github.event_name == 'pull_request' || github.event_name == 'merge_group') && '["3.12"]' || '["3.10", "3.12"]') }}
defaults:
run:
working-directory: packages/connectors/eligibility
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
- uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
with:
enable-cache: true
cache-dependency-glob: |
packages/connectors/eligibility/uv.lock
packages/flow/uv.lock
cache-suffix: eligibility-py${{ matrix.python-version }}
- name: Install eligibility connector against the in-tree core
run: >-
python ../../../scripts/ci/locked_install.py
--lock 'packages/connectors/eligibility[dev]'
--editable packages/types --editable packages/flow
--editable packages/connectors/eligibility
- name: Confirm the in-tree packages are installed
run: |
python - <<'PY'
import pathlib, openadapt_eligibility, openadapt_flow
assert "packages/flow" in pathlib.Path(openadapt_flow.__file__).resolve().as_posix()
assert "packages/connectors/eligibility" in pathlib.Path(openadapt_eligibility.__file__).resolve().as_posix()
PY
- name: Ruff
run: ruff check openadapt_eligibility tests
- name: Test
run: pytest -q

verify:
name: verify facade (py${{ matrix.python-version }})
needs: scope
Expand Down Expand Up @@ -1839,6 +1888,7 @@ jobs:
- scope
- types
- agent
- eligibility
- verify
- verify-clean-install
- flow-lint
Expand Down Expand Up @@ -1895,6 +1945,7 @@ jobs:
selects = {
"types": "types",
"agent": "agent",
"eligibility": "eligibility",
"verify": "verify",
"verify-clean-install": "verify",
"flow-lint": "flow",
Expand Down
22 changes: 22 additions & 0 deletions packages/connectors/eligibility/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# openadapt-eligibility

Optional domain connector for API-first 270/271 healthcare payer eligibility
checks (including Stedi route bindings, qualifier-aware response parsing,
waterfall fallback routing, and atomic practice-local artifact storage).

This package is intentionally separated from `openadapt-flow` so that
domain-specific payer and vendor integrations live outside the general-purpose
verification engine.

## Usage

```python
from openadapt_eligibility import (
EligibilityRequest,
StediAccountBoundary,
StediEligibilityClient,
load_payer_routes,
run_waterfall,
write_and_verify,
)
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING: # pragma: no cover
from openadapt_flow.eligibility.artifact import (
from openadapt_eligibility.artifact import (
ArtifactEncryption,
EligibilityArtifact,
PracticeArtifactPolicy,
purge_expired_eligibility_artifacts,
write_and_verify,
write_eligibility_artifacts,
)
from openadapt_flow.eligibility.client import (
from openadapt_eligibility.client import (
ApplicationMode,
BenefitSelection,
EligibilityRequest,
Expand All @@ -33,7 +33,7 @@
StediEligibilityClient,
eligibility_request_sha256,
)
from openadapt_flow.eligibility.waterfall import (
from openadapt_eligibility.waterfall import (
EligibilityRoute,
PayerCapability,
RouteDecision,
Expand Down Expand Up @@ -102,15 +102,15 @@
def __getattr__(name: str) -> object:
"""Lazy re-exports (PEP 562) -- importing the package stays cheap."""
if name in _CLIENT:
from openadapt_flow.eligibility import client
from openadapt_eligibility import client

return getattr(client, name)
if name in _WATERFALL:
from openadapt_flow.eligibility import waterfall
from openadapt_eligibility import waterfall

return getattr(waterfall, name)
if name in _ARTIFACT:
from openadapt_flow.eligibility import artifact
from openadapt_eligibility import artifact

return getattr(artifact, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
from typing import Iterator, Literal, Mapping, Optional, Union
from uuid import uuid4

from pydantic import BaseModel, Field, field_validator, model_validator

from openadapt_flow.eligibility.client import (
ApplicationMode,
EligibilityRequest,
EligibilityResult,
eligibility_request_sha256,
parse_271,
)
from openadapt_flow.private_file import open_binary
from openadapt_flow.runtime.effects.document_hash import DocumentHashVerifier
from openadapt_flow.runtime.effects.effect import (
Expand All @@ -43,6 +34,15 @@
ValueExpr,
Verdict,
)
from pydantic import BaseModel, Field, field_validator, model_validator

from openadapt_eligibility.client import (
ApplicationMode,
EligibilityRequest,
EligibilityResult,
eligibility_request_sha256,
parse_271,
)

RESULTS_CSV = "eligibility_results.csv"
TRANSACTIONS_DIR = "transactions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The public module is mechanism, not a production payer recipe. A deployment
supplies a practice-owned account boundary and an exact, reviewed payer binding
through :mod:`openadapt_flow.eligibility.waterfall`.
through :mod:`openadapt_eligibility.waterfall`.

Primary contract references (reviewed 2026-07-21):

Expand Down Expand Up @@ -30,9 +30,8 @@
from typing import Any, Callable, Literal, Mapping, Optional
from uuid import uuid4

from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator

from openadapt_flow.runtime.effects.auth import AuthRef
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator

STEDI_ELIGIBILITY_URL = (
"https://healthcare.us.stedi.com/2024-04-01/change/medicalnetwork/eligibility/v3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from pydantic import BaseModel, Field, field_validator, model_validator

from openadapt_flow.eligibility.client import (
from openadapt_eligibility.client import (
ApplicationMode,
EligibilityRequest,
EligibilityResult,
Expand Down
36 changes: 36 additions & 0 deletions packages/connectors/eligibility/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "openadapt-eligibility"
version = "0.1.0"
description = "Optional 270/271 healthcare payer eligibility connector for OpenAdapt Flow"
readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.10,<3.13"
dependencies = [
"openadapt-flow>=3.4.0,<4",
"pydantic>=2.0",
"PyYAML>=6.0",
"requests>=2.31",
"cryptography>=50.0.0",
]

[project.optional-dependencies]
dev = [
"httpx>=0.27.0",
"hypothesis>=6.100.0",
"pytest>=8.0.0",
"ruff>=0.4.0",
]

[tool.hatch.build.targets.wheel]
packages = ["openadapt_eligibility"]

[tool.uv.sources]
openadapt-flow = { path = "../../flow", editable = true }
openadapt-types = { path = "../../types", editable = true }

[tool.pytest.ini_options]
testpaths = ["tests"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import httpx
import pytest

from openadapt_flow.eligibility.client import (
from openadapt_eligibility.client import (
STEDI_ELIGIBILITY_URL,
ApplicationMode,
BenefitSelection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from pathlib import Path

import pytest

from openadapt_flow.eligibility.artifact import (
from openadapt_eligibility.artifact import (
BOUNDARY_FILE,
RESULTS_CSV,
TRANSACTIONS_DIR,
Expand All @@ -22,7 +21,7 @@
write_and_verify,
write_eligibility_artifacts,
)
from openadapt_flow.eligibility.client import (
from openadapt_eligibility.client import (
ApplicationMode,
BenefitSelection,
EligibilityRequest,
Expand Down Expand Up @@ -318,7 +317,7 @@ def fail_stage(source, destination):
def test_every_staged_contract_is_verified_before_promotion(
tmp_path, monkeypatch, target
):
import openadapt_flow.eligibility.artifact as artifact_module
import openadapt_eligibility.artifact as artifact_module

real_write = artifact_module._write_exclusive

Expand Down Expand Up @@ -365,7 +364,7 @@ def fail_index(source, destination):


def test_independent_effect_failure_rolls_back_new_transaction(tmp_path, monkeypatch):
import openadapt_flow.eligibility.artifact as artifact_module
import openadapt_eligibility.artifact as artifact_module

monkeypatch.setattr(artifact_module, "all_confirmed", lambda _verdicts: False)
with pytest.raises(RuntimeError, match="did not confirm"):
Expand Down Expand Up @@ -615,3 +614,26 @@ def test_committed_file_symlink_substitution_is_refused(tmp_path):
write_eligibility_artifacts(
active_result(), tmp_path, request=request(), policy=volume_policy()
)


def test_write_exclusive_preserves_exact_bytes_and_refuses_overwrite(tmp_path):
from hypothesis import HealthCheck, given, settings
from hypothesis import strategies as st
from openadapt_eligibility.artifact import _write_exclusive

@settings(
max_examples=30,
deadline=None,
suppress_health_check=[HealthCheck.function_scoped_fixture],
)
@given(payload=st.binary(max_size=2048))
def _check(payload: bytes) -> None:
path = tmp_path / "evidence.bin"
path.unlink(missing_ok=True)
_write_exclusive(path, payload)
assert path.read_bytes() == payload
with pytest.raises(FileExistsError):
_write_exclusive(path, b"replacement")
assert path.read_bytes() == payload

_check()
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
from datetime import datetime, timezone

import pytest

from openadapt_flow.eligibility.artifact import (
from openadapt_eligibility.artifact import (
ArtifactEncryption,
PracticeArtifactPolicy,
all_confirmed,
write_and_verify,
)
from openadapt_flow.eligibility.client import (
from openadapt_eligibility.client import (
ApplicationMode,
BenefitSelection,
EligibilityRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

import httpx
import pytest

from openadapt_flow.eligibility.client import (
from openadapt_eligibility.client import (
ApplicationMode,
EligibilityRequest,
EligibilityStatus,
StediAccountBoundary,
StediEligibilityClient,
)
from openadapt_flow.eligibility.waterfall import (
from openadapt_eligibility.waterfall import (
DEFAULT_REGISTRY_PATH,
EligibilityRoute,
PayerCapability,
Expand Down Expand Up @@ -290,7 +289,7 @@ def test_malformed_registry_fails_loud(tmp_path):


def test_lazy_package_exports():
import openadapt_flow.eligibility as eligibility
import openadapt_eligibility as eligibility

assert eligibility.EligibilityRoute is EligibilityRoute
assert callable(eligibility.run_waterfall)
Expand Down
Loading
Loading