Skip to content

Commit

Permalink
add icd10 regex expectation (#4691)
Browse files Browse the repository at this point in the history
Co-authored-by: Austin Ziech Robinson <44794138+austiezr@users.noreply.github.com>
  • Loading branch information
zachlindsey and austiezr committed Apr 8, 2022
1 parent 540ce27 commit 7b3217b
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from great_expectations.expectations.regex_based_column_map_expectation import (
RegexBasedColumnMapExpectation,
)


class ExpectColumnValuesToHaveValidICD10CodeFormat(RegexBasedColumnMapExpectation):
"""Checks if each value matches a regex for ICD10 codes. Does NOT ensure
the given code actually exists in any version of the ICD10.
"""

regex_camel_name = "ICD10Codes"
regex = "[A-Za-z][0-9][A-Za-z0-9](?:\\.[A-Za-z0-9]{0,4})?\\Z"
semantic_type_name_plural = None

examples = [
{
"data": {
"valid_icd10": ["Z99.0", "Z08", "J09.X2", "S22.000A"],
"invalid_icd10": ["XXX.X", "AA2.01", "2A", "S22.0000A"],
},
"tests": [
{
"title": "positive_test",
"exact_match_out": False,
"in": {"column": "valid_icd10"},
"out": {"success": True},
"include_in_gallery": True,
},
{
"title": "negative_test",
"exact_match_out": False,
"in": {"column": "invalid_icd10"},
"out": {"success": False, "unexpected_index_list": [0, 1, 2, 3]},
},
],
"test_backends": [{"backend": "pandas", "dialects": None}],
}
]

# Here your regex is used to create a custom metric for this expectation
map_metric = RegexBasedColumnMapExpectation.register_metric(
regex_camel_name=regex_camel_name,
regex_=regex,
)

# This object contains metadata for display in the public Gallery
library_metadata = {
"tags": ["typed-entities", "hackathon"],
"contributors": [
"@zachlindsey",
],
}


if __name__ == "__main__":
ExpectColumnValuesToHaveValidICD10CodeFormat().print_diagnostic_checklist()

0 comments on commit 7b3217b

Please sign in to comment.