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 Additional Logging for new endpoint #3779

Merged

Conversation

tyler-spangler6
Copy link
Contributor

What was the problem?

This adds a new field to logging and updates an existing field for only the new expanded classifier.

Previous Logging:

{
    "vagov_claim_id": 100,
    "claim_type": "new",
    "classification_code": 8989,
    "classification_name": "Mental Disorders",
    "contention_text": "PTSD (post-traumatic stress disorder)",
    "diagnostic_code": "None",
    "is_in_dropdown": true,
    "is_lookup_table_match": true,
    "is_multi_contention": true,
    "endpoint": "/va-gov-claim-classifier",
    "date": "2024-11-20 14:20:24",
    "level": "info"
}
{
    "vagov_claim_id": 100,
    "claim_type": "claim_for_increase",
    "classification_code": 8940,
    "classification_name": "Cancer - Musculoskeletal - Other",
    "contention_text": "unmapped contention text",
    "diagnostic_code": 5012,
    "is_in_dropdown": false,
    "is_lookup_table_match": true,
    "is_multi_contention": true,
    "endpoint": "/va-gov-claim-classifier",
    "date": "2024-11-20 14:20:24",
    "level": "info"
}
{
    "vagov_claim_id": 100,
    "claim_type": "new",
    "classification_code": null,
    "classification_name": null,
    "contention_text": "unmapped contention text",
    "diagnostic_code": 8550,
    "is_in_dropdown": false,
    "is_lookup_table_match": false,
    "is_multi_contention": true,
    "endpoint": "/va-gov-claim-classifier",
    "date": "2024-11-20 14:20:24",
    "level": "info"
}
{
    "claim_id": 100,
    "form526_submission_id": 500,
    "is_fully_classified": false,
    "percent_clasified": 66.66666666666666,
    "num_processed_contentions": 3,
    "num_classified_contentions": 2,
    "endpoint": "/va-gov-claim-classifier",
    "date": "2024-11-20 14:20:24",
    "level": "info"
}
{
    "process_time": 0.004019021987915039,
    "url": "/va-gov-claim-classifier",
    "date": "2024-11-20 14:20:24",
    "level": "info"
}

New Logging for expanded classifier:

{
    "vagov_claim_id": 100,
    "claim_type": "new",
    "classification_code": 8989,
    "classification_name": "Mental Disorders",
    "contention_text": "PTSD (post-traumatic stress disorder)",
    "processed_contention_text": "ptsd post traumatic stress disorder",
    "diagnostic_code": "None",
    "is_in_dropdown": true,
    "is_lookup_table_match": true,
    "is_multi_contention": true,
    "endpoint": "/expanded-contention-classification",
    "date": "2024-11-20 14:27:09",
    "level": "info"
}
{
    "vagov_claim_id": 100,
    "claim_type": "claim_for_increase",
    "classification_code": 8940,
    "classification_name": "Cancer - Musculoskeletal - Other",
    "contention_text": "unmapped contention text ['']",
    "processed_contention_text": "",
    "diagnostic_code": 5012,
    "is_in_dropdown": false,
    "is_lookup_table_match": true,
    "is_multi_contention": true,
    "endpoint": "/expanded-contention-classification",
    "date": "2024-11-20 14:27:09",
    "level": "info"
}
{
    "vagov_claim_id": 100,
    "claim_type": "new",
    "classification_code": 8997,
    "classification_name": "Musculoskeletal - Knee",
    "contention_text": "unmapped contention text ['acl tear']",
    "processed_contention_text": "acl tear",
    "diagnostic_code": 8550,
    "is_in_dropdown": false,
    "is_lookup_table_match": true,
    "is_multi_contention": true,
    "endpoint": "/expanded-contention-classification",
    "date": "2024-11-20 14:27:09",
    "level": "info"
}
{
    "claim_id": 100,
    "form526_submission_id": 500,
    "is_fully_classified": true,
    "percent_clasified": 100.0,
    "num_processed_contentions": 3,
    "num_classified_contentions": 3,
    "endpoint": "/expanded-contention-classification",
    "date": "2024-11-20 14:27:09",
    "level": "info"
}
{
    "process_time": 0.004132986068725586,
    "url": "/expanded-contention-classification",
    "date": "2024-11-20 14:27:09",
    "level": "info"
}

The additional field of processed_classified_text will us compare classifications based on the text processing lookup. This should also prevent logging any PII because we will only log the contention text if there is a match with the lookup table after processing. Additionally adding the processed text in the contention text field will help with our DataDog widgets to differentiate between unclassifiable unmapped text and classifiable unmapped text.

Associated tickets or Slack threads:

How does this fix it?1

How to test this PR

  • Step 1
  • Step 22

Footnotes

  1. Pull-Requests guidelines. If PR is significant, update Current Software State wiki page.

  2. To check if a PR will succeed in the SecRel workflow, test PRs in the SecRel pipeline.

Copy link
Contributor

github-actions bot commented Nov 20, 2024

Test Results

136 tests  ±0   136 ✅ ±0   22s ⏱️ -3s
 39 suites ±0     0 💤 ±0 
 39 files   ±0     0 ❌ ±0 

Results for commit f245737. ± Comparison against base commit 89bbf65.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Nov 20, 2024

JaCoCo Test Coverage

Overall Project 72.23%

There is no coverage information present for the Files changed

@tyler-spangler6 tyler-spangler6 marked this pull request as ready for review November 22, 2024 14:33
@tyler-spangler6 tyler-spangler6 requested a review from a team as a code owner November 22, 2024 14:33
Copy link

@williamphelps13 williamphelps13 left a comment

Choose a reason for hiding this comment

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

Nice work here! Just one comment - Could the new code in log_contention_stats be broken into its own helper function?

Comment on lines 124 to 144
if request.url.path == "/expanded-contention-classification":
processed_text = expanded_lookup_table.prep_incoming_text(
contention.contention_text
)
# only log these items if the expanded lookup returns a classification code
if expanded_lookup_table.get(contention.contention_text)["classification_code"]:
if log_contention_text == "unmapped contention text":
log_contention_text = f"unmapped contention text {[processed_text]}"

logging_dict.update(
{
"processed_contention_text": processed_text,
"contention_text": log_contention_text,
}
)
# log none as the processed text if it is not in the LUT and leave unmapped contention text as is
else:
logging_dict.update({"processed_contention_text": None})
log_as_json(logging_dict)
else:
log_as_json(logging_dict)

Choose a reason for hiding this comment

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

What if broke this code out into a helper function? Something like:

def _update_logging_for_expanded_contention(
    logging_dict: dict, contention_text: str, log_contention_text: str
):
    """
    # Updates the logging dictionary for `/expanded-contention-classification`
    """
    processed_text = expanded_lookup_table.prep_incoming_text(contention_text)
    classification = expanded_lookup_table.get(contention_text)

    if classification.get("classification_code"):
        if log_contention_text == "unmapped contention text":
            log_contention_text = f"unmapped contention text {[processed_text]}"

        logging_dict.update(
            {
                "processed_contention_text": processed_text,
                "contention_text": log_contention_text,
            }
        )
    # log none as the processed text if it is not in the LUT and leave unmapped contention text as is
    else:
        logging_dict.update({"processed_contention_text": None})

    return logging_dict

That is then used like:

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

    log_as_json(logging_dict)

@williamphelps13 williamphelps13 self-requested a review December 2, 2024 17:36
Copy link

@williamphelps13 williamphelps13 left a comment

Choose a reason for hiding this comment

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

Thanks for checking out the comment! Glad it looked like a positive change. This PR looks good to me.

@tyler-spangler6 tyler-spangler6 merged commit 9164fd1 into develop Dec 2, 2024
16 checks passed
@tyler-spangler6 tyler-spangler6 deleted the conditions-update-logging-expanded-classifier branch December 2, 2024 18:53
Copy link
Collaborator

@gabezurita gabezurita left a comment

Choose a reason for hiding this comment

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

LGTM!

)

# log_as_json(logging_dict)
# else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this commented-out code left in deliberately?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gabezurita Sorry I missed this comment before merging. That was accidentally left behind, I will clean this up in a following PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants