Skip to content

Commit

Permalink
adds expanded lookup to api and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-spangler6 committed Oct 30, 2024
1 parent c626125 commit 4514c17
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 12 deletions.
55 changes: 52 additions & 3 deletions domain-cc/cc-app/src/python_src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .util.lookup_table import ContentionTextLookupTable, DiagnosticCodeLookupTable
from .util.sanitizer import sanitize_log

exanded_lookup_table = ExpandedLookupTable(
expanded_lookup_table = ExpandedLookupTable(
key_text=FILE_READ_HELPER["contention_text"],
classification_code=FILE_READ_HELPER["classification_code"],
classification_name=FILE_READ_HELPER["classification_name"],
Expand Down Expand Up @@ -242,6 +242,55 @@ def va_gov_claim_classifier(claim: VaGovClaim) -> ClassifierResponse:
return response


def get_expanded_classification(contention: Contention) -> Tuple[int, str]:
"""
Performs the dictionary lookup for the expanded lookup table
"""
classification_code = None
classification_name = None
if contention.contention_type == "INCREASE":
classification = dc_lookup_table.get(contention.diagnostic_code)
classification_code = classification["classification_code"]
classification_name = classification["classification_name"]

if contention.contention_text and not classification_code:
classification = expanded_lookup_table.get(contention.contention_text)
classification_code = classification["classification_code"]
classification_name = classification["classification_name"]

return classification_code, classification_name


def classify_contention_expanded_table(
contention: Contention, claim: VaGovClaim
) -> ClassifiedContention:
classification_code, classification_name = get_expanded_classification(contention)

response = ClassifiedContention(
classification_code=classification_code,
classification_name=classification_name,
diagnostic_code=contention.diagnostic_code,
contention_type=contention.contention_type,
)

return response


@app.post("/expanded-contention-classification")
def expanded_classifications():
return {"length_of_lookup_table": len(exanded_lookup_table)}
def expanded_classifications(claim: VaGovClaim) -> ClassifierResponse:
classified_contentions = []
for contention in claim.contentions:
classification = classify_contention_expanded_table(contention, claim)
classified_contentions.append(classification)

num_classified = len([c for c in classified_contentions if c.classification_code])

response = ClassifierResponse(
contentions=classified_contentions,
claim_id=claim.claim_id,
form526_submission_id=claim.form526_submission_id,
is_fully_classified=num_classified == len(classified_contentions),
num_processed_contentions=len(classified_contentions),
num_classified_contentions=num_classified,
)
return response
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"than",
"with",
# 'upper',
#'low',
# 'low',
"a",
"va",
"for",
Expand Down
11 changes: 5 additions & 6 deletions domain-cc/cc-app/src/python_src/util/expanded_lookup_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(

def _musculoskeletal_lookup(self):
"""
Creates a lookup table for musculoskeletal conditions with the key a frozenset
Creates a lookup table for musculoskeletal conditions with the key a frozenset.
The musculoskeletal classifications are stored in the config file and can be added/updated there.
"""
MUSCULOSKELETAL_LUT_LUT_SET = {}
for k, v in MUSCULOSKELETAL_LUT.items():
Expand Down Expand Up @@ -67,7 +68,7 @@ def _remove_common_words(self, text, common_words: List[str] = COMMON_WORDS):

def _remove_numbers_single_characters(self, text):
"""
Removes any non-letter character not already removed from the word and any single character (ex: r)
Removes numbers or single character letters
"""
regex = r"\b[a-zA-Z]{1}\b|\d"
text = re.sub(regex, " ", text)
Expand All @@ -78,8 +79,6 @@ def _removal_pipeline(self, text):
"""
Pipeline to remove all unwanted characters from the lookup table contention text values
"""
# Needs remove punctuation twice to make sure that 's are not removed and then again to ensure that double spaces
# are removed. This can definitely be cleaned up later.
text = self._remove_punctuation(text)
text = self._remove_numbers_single_characters(text)
text = self._remove_common_words(text)
Expand Down Expand Up @@ -134,8 +133,8 @@ def get(self, input_str: str, default_value=LUT_DEFAULT_VALUE):
This also process the parenthetical terms in the mappings
"""
# There is only one case of using due to in the mappings (need to figure out a better way than hard coding it)

if input_str.strip().lower() == "loss of teeth due to bone loss":
input_str = input_str.strip().lower()
if input_str == "loss of teeth due to bone loss":
return {
"classification_code": 8967,
"classification_name": "Dental and Oral",
Expand Down
11 changes: 11 additions & 0 deletions domain-cc/cc-app/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from src.python_src.util.expanded_lookup_config import FILE_READ_HELPER
from src.python_src.util.expanded_lookup_table import ExpandedLookupTable
from src.python_src.util.lookup_table import (
ContentionTextLookupTable,
DiagnosticCodeLookupTable,
Expand All @@ -15,3 +17,12 @@ def test_build_dropdown_lookup_table():
def test_build_dc_lut():
dc_lookup_table = DiagnosticCodeLookupTable()
assert len(dc_lookup_table) == DIAGNOSTIC_CODE_LUT_SIZE


def test_build_expanded_table():
expanded = ExpandedLookupTable(
FILE_READ_HELPER["contention_text"],
FILE_READ_HELPER["classification_code"],
FILE_READ_HELPER["classification_name"],
)
assert len(expanded.contention_text_lookup_table) == 1017
88 changes: 86 additions & 2 deletions domain-cc/cc-app/tests/test_expanded_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,90 @@ def test_lookup_cause_included():


def test_api_endpoint(client: TestClient):
response = client.post("/expanded-contention-classification")
json_post_data = {
"claim_id": 100,
"form526_submission_id": 500,
"contentions": [
{
"contention_text": "PTSD (post-traumatic stress disorder)",
"contention_type": "NEW",
},
{
"contention_text": "",
"contention_type": "INCREASE",
"diagnostic_code": 5012,
},
{"contention_text": "anxiety condition", "contention_type": "new"},
{"contention_text": "acl tear", "contention_type": "new"},
{"contention_text": "totally free text", "contention_type": "new"},
{"contention_text": "neuropathy in my hand", "contention_type": "new"},
{
"contention_text": "knee pain due to something else entirely",
"contention_type": "new",
},
{
"contention_text": "left ankle condition",
"contention_type": "increase",
"diagnostic_code": 1000,
},
],
}
response = client.post("/expanded-contention-classification", json=json_post_data)
assert response.status_code == 200
assert response.json() == {"length_of_lookup_table": 1017}
assert response.json() == {
"contentions": [
{
"classification_code": 8989,
"classification_name": "Mental Disorders",
"diagnostic_code": None,
"contention_type": "NEW",
},
{
"classification_code": 8940,
"classification_name": "Cancer - Musculoskeletal - Other",
"diagnostic_code": 5012,
"contention_type": "INCREASE",
},
{
"classification_code": 8989,
"classification_name": "Mental Disorders",
"diagnostic_code": None,
"contention_type": "new",
},
{
"classification_code": 8997,
"classification_name": "Musculoskeletal - Knee",
"diagnostic_code": None,
"contention_type": "new",
},
{
"classification_code": None,
"classification_name": None,
"diagnostic_code": None,
"contention_type": "new",
},
{
"classification_code": None,
"classification_name": None,
"diagnostic_code": None,
"contention_type": "new",
},
{
"classification_code": 8997,
"classification_name": "Musculoskeletal - Knee",
"diagnostic_code": None,
"contention_type": "new",
},
{
"classification_code": 8991,
"classification_name": "Musculoskeletal - Ankle",
"diagnostic_code": 1000,
"contention_type": "increase",
},
],
"claim_id": 100,
"form526_submission_id": 500,
"is_fully_classified": False,
"num_processed_contentions": 8,
"num_classified_contentions": 6,
}

0 comments on commit 4514c17

Please sign in to comment.