Skip to content
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

Add Expanded lookup table endpoint #3674

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
62 changes: 62 additions & 0 deletions domain-cc/cc-app/src/python_src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
Contention,
VaGovClaim,
)
from .util.expanded_lookup_config import FILE_READ_HELPER
from .util.expanded_lookup_table import ExpandedLookupTable
from .util.logging_dropdown_selections import build_logging_table
from .util.lookup_table import ContentionTextLookupTable, DiagnosticCodeLookupTable
from .util.sanitizer import sanitize_log

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"],
)

dc_lookup_table = DiagnosticCodeLookupTable()
dropdown_lookup_table = ContentionTextLookupTable()
dropdown_values = build_logging_table()
Expand Down Expand Up @@ -232,3 +240,57 @@ 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"]
Comment on lines +253 to +254

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this have any benefit here (and in the next conditional)?

Suggested change
classification_code = classification["classification_code"]
classification_name = classification["classification_name"]
classification_code = classification.get("classification_code")
classification_name = classification.get("classification_name")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using dict[] is preferred if we are certain the key exists which we are since we have the defaults set in the lookup_tables.get() methods. I think the advantage of using dict.get() is that handles the keyerror using the default. I am good to switch it if it helps readability and consistency though.


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(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
169 changes: 169 additions & 0 deletions domain-cc/cc-app/src/python_src/util/expanded_lookup_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
"""
This file contains constants and configurations for the expanded lookup table.
Parameters
----------
COMMON_WORDS: list[str]
List of words to remove from incoming text and lookup table values.
MUSCULOSKELETAL_LUT: dict
Lookup table for musculoskeletal conditions.
FILE_READ_HELPER: dict
Helper dictionary that has the filepath and column names for instantiating the lookup table
"""

import os

from .table_versions import CONDITION_DROPDOWN_TABLE_VERSION

FILE_READ_HELPER = {
"filepath": os.path.join(
os.path.dirname(__file__),
"data",
"condition_dropdown_lookup_table",
f"[Release notes] Contention Text to Classification mapping release notes - Contention Text Lookup "
f"{CONDITION_DROPDOWN_TABLE_VERSION}.csv",
),
"contention_text": "CONTENTION TEXT",
"classification_code": "CLASSIFICATION CODE",
"classification_name": "CLASSIFICATION TEXT",
}

MUSCULOSKELETAL_LUT = {
"knee": {
"classification_code": 8997,
"classification_name": "Musculoskeletal - Knee",
},
"ankle": {
"classification_code": 8991,
"classification_name": "Musculoskeletal - Ankle",
},
"hip": {
"classification_code": 8996,
"classification_name": "Musculoskeletal - Hip",
},
"elbow": {
"classification_code": 8993,
"classification_name": "Musculoskeletal - Elbow",
},
"shoulder": {
"classification_code": 9002,
"classification_name": "Musculoskeletal - Shoulder",
},
"wrist": {
"classification_code": 9004,
"classification_name": "Musculoskeletal - Wrist",
},
"low back": {
"classification_code": 8998,
"classification_name": "Musculoskeletal - Mid/Lower Back (Thoracolumbar Spine)",
},
"lower back": {
"classification_code": 8998,
"classification_name": "Musculoskeletal - Mid/Lower Back (Thoracolumbar Spine)",
},
"neck": {
"classification_code": 8999,
"classification_name": "Musculoskeletal - Neck/Upper Back (Cervical Spine)",
},
"mid back": {
"classification_code": 8998,
"classification_name": "Musculoskeletal - Mid/Lower Back (Thoracolumbar Spine)",
},
"upper back": {
"classification_code": 8999,
"classification_name": "Musculoskeletal - Neck/Upper Back (Cervical Spine)",
},
"foot": {
"classification_code": 8994,
"classification_name": "Musculoskeletal - Foot",
},
"toe": {
"classification_code": 8994,
"classification_name": "Musculoskeletal - Foot",
},
"toes": {
"classification_code": 8994,
"classification_name": "Musculoskeletal - Foot",
},
"feet": {
"classification_code": 8994,
"classification_name": "Musculoskeletal - Foot",
},
}

COMMON_WORDS = [
"left",
"right",
"bilateral",
"in",
"of",
"or",
"the",
"my",
"and",
"chronic",
# 'lower',
"to",
"and",
"major",
"than",
"with",
# 'upper',
# 'low',
"a",
"va",
"for",
"as",
"has",
"me",
"one",
"use",
"year",
"within",
"worse",
"at",
"have",
"side",
"by",
"frequent",
"mild",
"loud",
"weak",
"bl",
# 'not',
"exam",
"undiagnosed",
"during",
"is",
"when",
"day",
"was",
"all",
"aircraft",
"total",
"moderate",
"noises",
"complete",
"after",
"up",
"it",
"bi",
"daily",
"no",
"had",
"getting",
"also",
"rt",
"sp",
"be",
"see",
"need",
"an",
"which",
"since",
"this",
"jet",
"can't",
"cant",
"pain",
"condition",
]
Loading