Skip to content

Commit

Permalink
Removes Single Contention Classification Endpoint (#3610)
Browse files Browse the repository at this point in the history
removed endpoint, updated tests

Co-authored-by: Tyler Spangler <[email protected]>
  • Loading branch information
tyler-spangler6 and Tyler Spangler authored Oct 22, 2024
1 parent 70d4c04 commit 10f1dfe
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 446 deletions.
102 changes: 1 addition & 101 deletions domain-cc/cc-app/src/python_src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import sys
import time
from functools import wraps
from typing import Optional, Tuple
from typing import Tuple

from fastapi import FastAPI, HTTPException, Request

from .pydantic_models import (
Claim,
ClaimLinkInfo,
ClassifiedContention,
ClassifierResponse,
Contention,
PredictedClassification,
VaGovClaim,
)
from .util.brd_classification_codes import get_classification_name
from .util.logging_dropdown_selections import build_logging_table
from .util.lookup_table import ContentionTextLookupTable, DiagnosticCodeLookupTable
from .util.sanitizer import sanitize_log
Expand Down Expand Up @@ -69,31 +66,6 @@ def get_health_status():
return {"status": "ok"}


def log_lookup_table_match(
classification_code: int,
contention_text: str,
):
is_in_dropdown = contention_text.strip().lower() in dropdown_values
log_as_json({"is_in_dropdown": sanitize_log(is_in_dropdown)})
log_contention_text = contention_text if is_in_dropdown else "Not in dropdown"

if classification_code:
already_mapped_text = contention_text.strip().lower() # do not leak PII
log_as_json({"lookup_table_match": sanitize_log(already_mapped_text)})
elif is_in_dropdown:
log_as_json(
{
"lookup_table_match": sanitize_log(
f"No table match for {log_contention_text}"
)
}
)
else:
log_as_json(
{"lookup_table_match": sanitize_log("No table match for free text entry")}
)


def log_as_json(log: dict):
if "date" not in log.keys():
log.update({"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())})
Expand Down Expand Up @@ -190,78 +162,6 @@ def wrapper(*args, **kwargs):
return wrapper


def log_claim_stats(claim: Claim, classification: Optional[PredictedClassification]):
if classification:
classification_code = classification.classification_code
classification_name = classification.classification_name
else:
classification_code = None
classification_name = None

contention_text = claim.contention_text or ""
is_in_dropdown = contention_text.strip().lower() in dropdown_values
is_mapped_text = dropdown_lookup_table.get(contention_text, None) is not None
log_contention_text = (
contention_text if is_mapped_text else "unmapped contention text"
)

log_as_json(
{
"claim_id": sanitize_log(claim.claim_id),
"claim_type": sanitize_log(claim.claim_type),
"classification_code": classification_code,
"classification_name": classification_name,
"contention_text": log_contention_text,
"diagnostic_code": sanitize_log(claim.diagnostic_code),
"form526_submission_id": sanitize_log(claim.form526_submission_id),
"is_in_dropdown": is_in_dropdown,
"is_lookup_table_match": classification_code is not None,
}
)


@app.post("/classifier", deprecated=True)
def get_classification(claim: Claim) -> Optional[PredictedClassification]:
"""[DEPRECATED] Use /va-gov-claim-classifier instead"""
log_as_json(
{
"claim_id": sanitize_log(claim.claim_id),
"form526_submission_id": sanitize_log(claim.form526_submission_id),
}
)
classification_code = None
if claim.claim_type == "claim_for_increase":
classification_code = dc_lookup_table.get(claim.diagnostic_code)[
"classification_code"
]

if claim.contention_text and not classification_code:
classification_code = dropdown_lookup_table.get(claim.contention_text)[
"classification_code"
]

if claim.claim_type == "new":
log_lookup_table_match(classification_code, claim.contention_text)
else:
log_as_json({"diagnostic code": sanitize_log(claim.diagnostic_code)})

if classification_code:
classification_name = get_classification_name(classification_code)
classification = {
"classification_code": classification_code,
"classification_name": classification_name,
}
else:
classification = None

log_as_json({"classification": classification})
log_claim_stats(
claim,
PredictedClassification(**classification) if classification else None,
)
return classification


@app.post("/claim-linker")
def link_vbms_claim_id(claim_link_info: ClaimLinkInfo):
log_as_json(
Expand Down
43 changes: 6 additions & 37 deletions domain-cc/cc-app/src/python_src/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,6 @@
from pydantic.types import conlist


class Claim(BaseModel):
claim_id: int
form526_submission_id: int
diagnostic_code: Optional[
int
] = None # only required for claim_type: "claim_for_increase"
claim_type: str = "claim_for_increase"
contention_text: Optional[
str
] = None # marked optional to retain compatibility with v1

@model_validator(mode="before")
@classmethod
def check_dc_for_cfi(cls, values):
claim_type = values.get("claim_type")
diagnostic_code = values.get("diagnostic_code")

if claim_type == "claim_for_increase" and diagnostic_code is None:
raise ValueError(
"diagnostic_code is required for claim_type claim_for_increase"
)
return values


class PredictedClassification(BaseModel):
"""Prediction result of our ML model"""

classification_code: int
classification_name: str


class ClaimLinkInfo(BaseModel):
"""used for connecting VA.gov and VBMS claims to each other in order to track contention changes downstream"""

Expand All @@ -46,9 +15,9 @@ class ClaimLinkInfo(BaseModel):
class Contention(BaseModel):
contention_text: str
contention_type: str # "disabilityActionType" in the VA.gov API
diagnostic_code: Optional[
int
] = None # only required for contention_type: "claim_for_increase"
diagnostic_code: Optional[int] = (
None # only required for contention_type: "claim_for_increase"
)

@model_validator(mode="before")
@classmethod
Expand All @@ -73,9 +42,9 @@ class VaGovClaim(BaseModel):
class ClassifiedContention(BaseModel):
classification_code: Optional[int]
classification_name: Optional[str]
diagnostic_code: Optional[
int
] = None # only required for contention_type: "claim_for_increase"
diagnostic_code: Optional[int] = (
None # only required for contention_type: "claim_for_increase"
)
contention_type: str # "disabilityActionType" in the VA.gov API


Expand Down
134 changes: 0 additions & 134 deletions domain-cc/cc-app/tests/test_api.py

This file was deleted.

8 changes: 7 additions & 1 deletion domain-cc/cc-app/tests/test_claim_linker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from fastapi.testclient import TestClient


Expand All @@ -6,7 +8,11 @@ def test_claim_ids_logged(client: TestClient, caplog):
"va_gov_claim_id": 100,
"vbms_claim_id": 200,
}
client.post("/claim-linker", json=json_post_dict)

with caplog.at_level(logging.INFO):
client.post("/claim-linker", json=json_post_dict)

print(caplog.records)
expected_claim_link_json = {
"level": "info",
"message": "linking claims",
Expand Down
Loading

0 comments on commit 10f1dfe

Please sign in to comment.