Skip to content

Commit

Permalink
Update: SNOMED Complex Map: Now filters out any mappings that aren't …
Browse files Browse the repository at this point in the history
…of 'ALWAYS' level of confidence.
  • Loading branch information
joeflack4 committed Apr 20, 2022
1 parent 1954055 commit dd52b99
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions sssom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,21 @@ def read_snomed_complex_map_tsv(
file_path: str,
prefix_map: Dict[str, str] = None,
meta: Dict[str, str] = None,
filter_by_confident_mappings=True
) -> MappingSetDataFrame:
"""Parse special SNOMED ICD10CM mapping file and translates it into a MappingSetDataFrame.
:param file_path: The path to the obographs file
:param file_path: The path to the source file
:param prefix_map: an optional prefix map
:param meta: an optional dictionary of metadata elements
:param filter_by_confident_mappings: Will only include mapping rows where the `mapAdvice` field includes an 'ALWAYS
<code>' pattern.
:return: A SSSOM MappingSetDataFrame
"""
raise_for_bad_path(file_path)
df = read_pandas(file_path)
df2 = from_snomed_complex_map_tsv(df, prefix_map=prefix_map, meta=meta)
df2 = from_snomed_complex_map_tsv(
df, prefix_map=prefix_map, meta=meta, filter_by_confident_mappings=filter_by_confident_mappings)
return df2


Expand Down Expand Up @@ -524,12 +528,15 @@ def from_snomed_complex_map_tsv(
df: pd.DataFrame,
prefix_map: Optional[PrefixMap] = None,
meta: Optional[MetadataType] = None,
filter_by_confident_mappings=True
) -> MappingSetDataFrame:
"""Convert a snomed_icd10cm_map dataframe to a MappingSetDataFrame.
:param df: A mappings dataframe
:param prefix_map: A prefix map
:param meta: A metadata dictionary
:param filter_by_confident_mappings: Will only include mapping rows where the `mapAdvice` field includes an 'ALWAYS
<code>' pattern.
:return: MappingSetDataFrame
# Field descriptions
Expand Down Expand Up @@ -563,11 +570,23 @@ def from_snomed_complex_map_tsv(
- mapCategoryId,SctId,Identifies the SNOMED CT concept in the metadata hierarchy which is the MapCategory for the
associated map record. This is a subtype of 447634004 |ICD-10 Map Category value|.,
"""
# Local variables
# https://www.findacode.com/snomed/447561005--snomed-ct-source-code-to-target-map-correlation-not-specified.html
match_type_snomed_unspecified_id = 447561005
# - Note: joeflack4: I used this info as a reference for this pattern.
# https://www.medicalbillingandcoding.org/icd-10-cm/#:~:text=ICD%2D10%2DCM%20is%20a,decimal%20point%20and%20the%20subcategory.
always_confidence_pattern = 'ALWAYS [A-Z]{1}[0-9]{1,2}\.[0-9A-Z]{1,4}'
always_confidence_antipattern = always_confidence_pattern + '\?'
prefix_map = _ensure_prefix_map(prefix_map)
ms = _init_mapping_set(meta)

# Filtering
if filter_by_confident_mappings:
df = df[
(df['mapAdvice'].str.contains(always_confidence_pattern, regex=True, na=False)) &
(~df['mapAdvice'].str.contains(always_confidence_antipattern, regex=True, na=False))]

# Map mappings
mlist: List[Mapping] = []
for _, row in df.iterrows():
mdict = {
Expand Down

0 comments on commit dd52b99

Please sign in to comment.