Skip to content

Commit

Permalink
Add API Field to Track Testing Classifications (#3813)
Browse files Browse the repository at this point in the history
* add parameter to track if testing claim

* added logging and updated tests

* renamed api parameter to be more descriptive

* removed unneccesary comment
  • Loading branch information
tyler-spangler6 authored Dec 3, 2024
1 parent 318c304 commit 7151d26
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
4 changes: 2 additions & 2 deletions domain-cc/cc-app/src/python_src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,14 @@ def log_contention_stats(
"is_lookup_table_match": classification_code is not None,
"is_multi_contention": is_multi_contention,
"endpoint": request.url.path,
"is_ab_test_claim": claim.is_ab_test_claim,
}

if request.url.path == "/expanded-contention-classification":
logging_dict = log_expanded_contention_text(
logging_dict, contention.contention_text, log_contention_text
)

# log_as_json(logging_dict)
# else:
log_as_json(logging_dict)


Expand All @@ -174,6 +173,7 @@ def log_claim_stats_v2(
"num_processed_contentions": response.num_processed_contentions,
"num_classified_contentions": response.num_classified_contentions,
"endpoint": request.url.path,
"is_ab_test_claim": claim.is_ab_test_claim,
}
)

Expand Down
1 change: 1 addition & 0 deletions domain-cc/cc-app/src/python_src/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class VaGovClaim(BaseModel):
claim_id: int
form526_submission_id: int
contentions: conlist(Contention, min_length=1)
is_ab_test_claim: Optional[bool] = False


class ClassifiedContention(BaseModel):
Expand Down
83 changes: 83 additions & 0 deletions domain-cc/cc-app/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_log_contention_stats_expanded(mocked_func):
"is_lookup_table_match": True,
"is_multi_contention": False,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": "acl tear",
}

Expand Down Expand Up @@ -107,6 +108,7 @@ def test_non_classified_contentions(mocked_func):
"is_lookup_table_match": False,
"is_multi_contention": False,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": None,
}
mocked_func.assert_called_once_with(expected_log)
Expand Down Expand Up @@ -157,6 +159,7 @@ def test_multiple_contentions(mocked_func):
"is_lookup_table_match": True,
"is_multi_contention": True,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": "tinnitus ringing hissing ears",
},
{
Expand All @@ -170,6 +173,7 @@ def test_multiple_contentions(mocked_func):
"is_lookup_table_match": True,
"is_multi_contention": True,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": "anxiety",
},
]
Expand Down Expand Up @@ -230,6 +234,7 @@ def test_contentions_with_pii(mocked_func):
"is_lookup_table_match": False,
"is_multi_contention": True,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": None,
},
{
Expand All @@ -243,6 +248,7 @@ def test_contentions_with_pii(mocked_func):
"is_lookup_table_match": False,
"is_multi_contention": True,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": None,
},
]
Expand Down Expand Up @@ -305,6 +311,7 @@ def test_log_claim_stats(mocked_func):
"num_processed_contentions": 2,
"num_classified_contentions": 1,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
}
log_claim_stats_v2(test_claim, classifier_response, test_expanded_request)
mocked_func.assert_called_once_with(expected_log)
Expand Down Expand Up @@ -346,6 +353,7 @@ def test_current_classifier_contention(mocked_func):
"is_lookup_table_match": False,
"is_multi_contention": False,
"endpoint": "/va-gov-claim-classifier",
"is_ab_test_claim": False,
}

mocked_func.assert_called_once_with(expected_logging_dict)
Expand Down Expand Up @@ -396,6 +404,7 @@ def test_full_logging_expanded_endpoint(mocked_func):
"is_lookup_table_match": False,
"is_multi_contention": True,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": None,
},
{
Expand All @@ -409,6 +418,7 @@ def test_full_logging_expanded_endpoint(mocked_func):
"is_lookup_table_match": True,
"is_multi_contention": True,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
"processed_contention_text": "anxiety",
},
]
Expand All @@ -429,6 +439,7 @@ def test_full_logging_expanded_endpoint(mocked_func):
"num_processed_contentions": 2,
"num_classified_contentions": 1,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": False,
}

for i in range(len(test_contentions)):
Expand All @@ -443,3 +454,75 @@ def test_full_logging_expanded_endpoint(mocked_func):
log_claim_stats_v2(test_claim, classifier_response, test_expanded_request)
mocked_func.assert_called_with(expected_claim_log)
assert mocked_func.call_count == 3


@patch("src.python_src.api.log_as_json")
def test_claim_testing_log(mocked_func):
"""
Tests that the testing claim flag is logged correctly
"""
test_contention = Contention(
contention_text="acl tear right",
contention_type="NEW",
)
test_claim = VaGovClaim(
claim_id=100,
form526_submission_id=500,
contentions=[test_contention],
is_ab_test_claim=True,
)
classified_contention = ClassifiedContention(
classification_code=8997,
classification_name="Musculoskeletal - Knee",
diagnostic_code=None,
contention_type="NEW",
)
log_contention_stats(
test_contention, classified_contention, test_claim, test_expanded_request
)

test_response = ClassifierResponse(
contentions=[classified_contention],
claim_id=test_claim.claim_id,
form526_submission_id=test_claim.form526_submission_id,
is_fully_classified=False,
num_processed_contentions=1,
num_classified_contentions=1,
)

expected_logging_dict = {
"vagov_claim_id": test_claim.claim_id,
"claim_type": "new",
"classification_code": classified_contention.classification_code,
"classification_name": classified_contention.classification_name,
"contention_text": "unmapped contention text ['acl tear']",
"diagnostic_code": "None",
"is_in_dropdown": False,
"is_lookup_table_match": True,
"is_multi_contention": False,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": True,
"processed_contention_text": "acl tear",
}

mocked_func.assert_called_with(expected_logging_dict)

log_claim_stats_v2(test_claim, test_response, test_expanded_request)

expected_claim_logging_dict = {
"claim_id": test_claim.claim_id,
"form526_submission_id": test_claim.form526_submission_id,
"is_fully_classified": test_response.is_fully_classified,
"percent_clasified": (
test_response.num_classified_contentions
/ test_response.num_processed_contentions
)
* 100,
"num_processed_contentions": test_response.num_processed_contentions,
"num_classified_contentions": test_response.num_classified_contentions,
"endpoint": "/expanded-contention-classification",
"is_ab_test_claim": True,
}

mocked_func.assert_called_with(expected_claim_logging_dict)
assert mocked_func.call_count == 2

0 comments on commit 7151d26

Please sign in to comment.