Repository: Sage-Bionetworks/Genie

Issue:
Modify vital status inconsistency check
One site reports that they are able to supply the YEAR but not INT of the vital status values.  

Therefore, should allow for a numeric year and `Unknown` INT pattern for both death and contact variable pairs.

Discussion:

Patch:
diff --git a/genie_registry/clinical.py b/genie_registry/clinical.py
index cbf1a42..cac16e4 100644
--- a/genie_registry/clinical.py
+++ b/genie_registry/clinical.py
@@ -140,8 +140,14 @@ def _check_int_year_consistency(
     for str_val in string_vals:
         # n string values per row
         n_str = (clinicaldf[cols] == str_val).sum(axis=1)
-        if n_str.between(0, len(cols), inclusive="neither").any():
-            is_text_inconsistent = True
+        # year can be known with unknown interval value
+        # otherwise must be all numeric or the same text value
+        if str_val == "Unknown":
+            if ((n_str == 1) & (clinicaldf[interval_col] != "Unknown")).any():
+                is_text_inconsistent = True
+        else:
+            if n_str.between(0, len(cols), inclusive="neither").any():
+                is_text_inconsistent = True
 
     is_redaction_inconsistent = False
     # Check that the redacted values are consistent


Test patch:
diff --git a/tests/test_clinical.py b/tests/test_clinical.py
index e0d29e0..70e8f1b 100644
--- a/tests/test_clinical.py
+++ b/tests/test_clinical.py
@@ -727,13 +727,13 @@ def test_remap_clinical_values(col):
 def test__check_int_year_consistency_valid():
     """Test valid vital status consistency"""
     testdf = pd.DataFrame(
-        {"INT_2": [1, 2, "Unknown"],
-         "YEAR_1": [1, 4, "Unknown"],
-         "FOO_3": [1, 3, "Unknown"]}
+        {"INT_2": [1, 2, "Unknown", "Unknown"],
+         "YEAR_1": [1, 4, "Unknown", 1],
+         "FOO_3": [1, 3, "Unknown", 1]}
     )
     error = genie_registry.clinical._check_int_year_consistency(
         clinicaldf=testdf,
-        cols=['INT_2', "YEAR_1"],
+        cols=["INT_2", "YEAR_1"],
         string_vals=["Unknown"]
     )
     assert error == ""
@@ -759,7 +759,7 @@ def test__check_int_year_consistency_valid():
         (
             pd.DataFrame(
                 {"INT_2": [1, "Unknown", "Unknown"],
-                 "YEAR_1": [1, 4, "Unknown"]}
+                 "YEAR_1": [1, "Not Applicable", "Unknown"]}
             ),
             "Patient: you have inconsistent text values in INT_2, YEAR_1.\n"
         ),
@@ -780,10 +780,17 @@ def test__check_int_year_consistency_valid():
         (
             pd.DataFrame(
                 {"INT_2": ["<6570", "Unknown", "Unknown"],
-                 "YEAR_1": [1, 3, "Unknown"]}
+                 "YEAR_1": [1, "Not Applicable", "Unknown"]}
             ),
             "Patient: you have inconsistent redaction and text values in "
             "INT_2, YEAR_1.\n"
+        ),
+        (
+            pd.DataFrame(
+                {"INT_2": ["12345", "Unknown", "Unknown"],
+                 "YEAR_1": ["Unknown", "Unknown", "Unknown"]}
+            ),
+            "Patient: you have inconsistent text values in INT_2, YEAR_1.\n"
         )
     ]
 )