-
Notifications
You must be signed in to change notification settings - Fork 0
feat: LCD-anchored confidence scoring algorithm (v2) #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c454b2
feat: add policy data models, confidence scorer, and generic fallback…
rsalus 820fe3e
feat: add policy registry with 5 LCD-backed seed policies
rsalus e04e7c5
feat: update PAFormResponse model and enhance evidence extractor
rsalus d932d23
Merge branch 'worktree-agent-a6ba31f2' into confidence-algorithm-v2
rsalus 680352f
Merge branch 'worktree-agent-ae80ae91' into confidence-algorithm-v2
rsalus 3b20396
feat: wire form generator and analyze endpoint to LCD policy engine
rsalus b687927
fix: PA ID generation collision when demo seed data exists
rsalus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """Policy data models for LCD-backed prior authorization criteria.""" | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class PolicyCriterion(BaseModel): | ||
| """A single criterion from a coverage policy.""" | ||
|
|
||
| id: str | ||
| description: str | ||
| weight: float # 0.0-1.0, clinical importance | ||
| required: bool = False # Hard gate — if NOT_MET, caps score | ||
| lcd_section: str | None = None # e.g. "L34220 §4.2" | ||
| bypasses: list[str] = [] # criterion IDs this one bypasses when MET | ||
|
|
||
|
|
||
| class PolicyDefinition(BaseModel): | ||
| """Complete policy definition with LCD metadata.""" | ||
|
|
||
| policy_id: str | ||
| policy_name: str | ||
| lcd_reference: str | None = None # e.g. "L34220" | ||
| lcd_title: str | None = None | ||
| lcd_contractor: str | None = None | ||
| payer: str | ||
| procedure_codes: list[str] | ||
| diagnosis_codes: list[str] = [] | ||
| criteria: list[PolicyCriterion] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Generic fallback policy for unsupported procedure codes.""" | ||
|
|
||
| from src.models.policy import PolicyCriterion, PolicyDefinition | ||
|
|
||
|
|
||
| def build_generic_policy(procedure_code: str) -> PolicyDefinition: | ||
| """Build a generic medical necessity policy for any procedure code.""" | ||
| return PolicyDefinition( | ||
| policy_id=f"generic-{procedure_code}", | ||
| policy_name="General Medical Necessity", | ||
| lcd_reference=None, | ||
| payer="General", | ||
| procedure_codes=[procedure_code], | ||
| diagnosis_codes=[], | ||
| criteria=[ | ||
| PolicyCriterion( | ||
| id="medical_necessity", | ||
| description="Medical necessity is documented with clinical rationale", | ||
| weight=0.40, | ||
| required=True, | ||
| ), | ||
| PolicyCriterion( | ||
| id="diagnosis_present", | ||
| description="Valid diagnosis code is present and supports the procedure", | ||
| weight=0.30, | ||
| required=True, | ||
| ), | ||
| PolicyCriterion( | ||
| id="conservative_therapy", | ||
| description="Conservative therapy attempted or documented as not applicable", | ||
| weight=0.30, | ||
| required=False, | ||
| ), | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """Policy registry for resolving procedure codes to policy definitions.""" | ||
|
|
||
| from src.models.policy import PolicyDefinition | ||
| from src.policies.generic_policy import build_generic_policy | ||
|
|
||
|
|
||
| class PolicyRegistry: | ||
| """Resolves procedure codes to LCD-backed policy definitions.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self._by_cpt: dict[str, PolicyDefinition] = {} | ||
|
|
||
| def register(self, policy: PolicyDefinition) -> None: | ||
| for cpt in policy.procedure_codes: | ||
| self._by_cpt[cpt] = policy | ||
|
|
||
| def resolve(self, procedure_code: str) -> PolicyDefinition: | ||
| """Return LCD-backed policy if available, else generic fallback.""" | ||
| if procedure_code in self._by_cpt: | ||
| return self._by_cpt[procedure_code] | ||
| return build_generic_policy(procedure_code) | ||
|
|
||
|
|
||
| # Module-level singleton | ||
| registry = PolicyRegistry() | ||
|
|
||
| # Import seed policies to register them | ||
| from src.policies.seed import register_all_seeds # noqa: E402 | ||
|
|
||
| register_all_seeds(registry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| """Seed policy loader.""" | ||
| from src.policies.seed.mri_lumbar import POLICY as MRI_LUMBAR | ||
| from src.policies.seed.mri_brain import POLICY as MRI_BRAIN | ||
| from src.policies.seed.tka import POLICY as TKA | ||
| from src.policies.seed.physical_therapy import POLICY as PHYSICAL_THERAPY | ||
| from src.policies.seed.epidural_steroid import POLICY as EPIDURAL_STEROID | ||
|
|
||
| ALL_SEED_POLICIES = [MRI_LUMBAR, MRI_BRAIN, TKA, PHYSICAL_THERAPY, EPIDURAL_STEROID] | ||
|
|
||
|
|
||
| def register_all_seeds(registry) -> None: | ||
| for policy in ALL_SEED_POLICIES: | ||
| registry.register(policy) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Epidural Steroid Injection seed policy — LCD L39240.""" | ||
|
|
||
| from src.models.policy import PolicyCriterion, PolicyDefinition | ||
|
|
||
| POLICY = PolicyDefinition( | ||
| policy_id="lcd-esi-L39240", | ||
| policy_name="Epidural Steroid Injection", | ||
| lcd_reference="L39240", | ||
| lcd_title="Epidural Steroid Injections", | ||
| lcd_contractor="Noridian Healthcare Solutions", | ||
| payer="CMS Medicare", | ||
| procedure_codes=["62322", "62323"], | ||
| diagnosis_codes=["M54.10", "M54.16", "M54.17", "M48.06"], | ||
| criteria=[ | ||
| PolicyCriterion( | ||
| id="diagnosis_confirmed", | ||
| description="Radiculopathy/stenosis confirmed by history, exam, and imaging", | ||
| weight=0.25, | ||
| required=True, | ||
| lcd_section="L39240 — Requirement 1", | ||
| ), | ||
| PolicyCriterion( | ||
| id="severity_documented", | ||
| description="Pain severe enough to impact QoL/function, documented with standardized scale", | ||
| weight=0.20, | ||
| required=True, | ||
| lcd_section="L39240 — Requirement 2", | ||
| ), | ||
| PolicyCriterion( | ||
| id="conservative_care_4wk", | ||
| description="4 weeks conservative care failed/intolerable (except acute herpes zoster)", | ||
| weight=0.25, | ||
| required=True, | ||
| lcd_section="L39240 — Requirement 3", | ||
| ), | ||
| PolicyCriterion( | ||
| id="frequency_within_limits", | ||
| description="<=4 sessions per region per rolling 12 months", | ||
| weight=0.15, | ||
| required=True, | ||
| lcd_section="L39240 — Frequency Limits", | ||
| ), | ||
| PolicyCriterion( | ||
| id="image_guidance_planned", | ||
| description="Fluoroscopy or CT guidance with contrast planned", | ||
| weight=0.15, | ||
| required=True, | ||
| lcd_section="L39240 — Procedural Requirements", | ||
| ), | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| """MRI Brain seed policy — LCD L37373.""" | ||
|
|
||
| from src.models.policy import PolicyCriterion, PolicyDefinition | ||
|
|
||
| POLICY = PolicyDefinition( | ||
| policy_id="lcd-mri-brain-L37373", | ||
| policy_name="MRI Brain", | ||
| lcd_reference="L37373", | ||
| lcd_title="Magnetic Resonance Imaging of the Brain", | ||
| lcd_contractor="Noridian Healthcare Solutions", | ||
| payer="CMS Medicare", | ||
| procedure_codes=["70551", "70552", "70553"], | ||
| diagnosis_codes=["G40.909", "R51.9", "G43.909", "G35"], | ||
| criteria=[ | ||
| PolicyCriterion( | ||
| id="diagnosis_present", | ||
| description="Valid ICD-10 for neurological condition", | ||
| weight=0.15, | ||
| required=True, | ||
| lcd_section="L37373 / A57204 — Covered Diagnoses", | ||
| ), | ||
| PolicyCriterion( | ||
| id="neurological_indication", | ||
| description="Tumor, stroke, MS, seizures, unexplained neuro deficit", | ||
| weight=0.35, | ||
| required=True, | ||
| lcd_section="L37373 — Indications for MRI", | ||
| ), | ||
| PolicyCriterion( | ||
| id="ct_insufficient", | ||
| description="CT already performed and insufficient, or MRI specifically indicated", | ||
| weight=0.25, | ||
| required=False, | ||
| lcd_section="L37373 — MRI vs CT Selection", | ||
| ), | ||
| PolicyCriterion( | ||
| id="clinical_documentation", | ||
| description="Supporting clinical findings documented", | ||
| weight=0.25, | ||
| required=True, | ||
| lcd_section="L37373 — Coverage Requirements", | ||
| ), | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add type annotation for
registryparameter.Per coding guidelines, all functions must have complete type annotations.
🔧 Add type hint
🤖 Prompt for AI Agents