@@ -146,17 +146,21 @@ def read_snomed_complex_map_tsv(
146146 file_path : str ,
147147 prefix_map : Dict [str , str ] = None ,
148148 meta : Dict [str , str ] = None ,
149+ filter_by_confident_mappings = True
149150) -> MappingSetDataFrame :
150151 """Parse special SNOMED ICD10CM mapping file and translates it into a MappingSetDataFrame.
151152
152- :param file_path: The path to the obographs file
153+ :param file_path: The path to the source file
153154 :param prefix_map: an optional prefix map
154155 :param meta: an optional dictionary of metadata elements
156+ :param filter_by_confident_mappings: Will only include mapping rows where the `mapAdvice` field includes an 'ALWAYS
157+ <code>' pattern.
155158 :return: A SSSOM MappingSetDataFrame
156159 """
157160 raise_for_bad_path (file_path )
158161 df = read_pandas (file_path )
159- df2 = from_snomed_complex_map_tsv (df , prefix_map = prefix_map , meta = meta )
162+ df2 = from_snomed_complex_map_tsv (
163+ df , prefix_map = prefix_map , meta = meta , filter_by_confident_mappings = filter_by_confident_mappings )
160164 return df2
161165
162166
@@ -524,12 +528,15 @@ def from_snomed_complex_map_tsv(
524528 df : pd .DataFrame ,
525529 prefix_map : Optional [PrefixMap ] = None ,
526530 meta : Optional [MetadataType ] = None ,
531+ filter_by_confident_mappings = True
527532) -> MappingSetDataFrame :
528533 """Convert a snomed_icd10cm_map dataframe to a MappingSetDataFrame.
529534
530535 :param df: A mappings dataframe
531536 :param prefix_map: A prefix map
532537 :param meta: A metadata dictionary
538+ :param filter_by_confident_mappings: Will only include mapping rows where the `mapAdvice` field includes an 'ALWAYS
539+ <code>' pattern.
533540 :return: MappingSetDataFrame
534541
535542 # Field descriptions
@@ -563,11 +570,23 @@ def from_snomed_complex_map_tsv(
563570 - mapCategoryId,SctId,Identifies the SNOMED CT concept in the metadata hierarchy which is the MapCategory for the
564571 associated map record. This is a subtype of 447634004 |ICD-10 Map Category value|.,
565572 """
573+ # Local variables
566574 # https://www.findacode.com/snomed/447561005--snomed-ct-source-code-to-target-map-correlation-not-specified.html
567575 match_type_snomed_unspecified_id = 447561005
576+ # - Note: joeflack4: I used this info as a reference for this pattern.
577+ # https://www.medicalbillingandcoding.org/icd-10-cm/#:~:text=ICD%2D10%2DCM%20is%20a,decimal%20point%20and%20the%20subcategory.
578+ always_confidence_pattern = 'ALWAYS [A-Z]{1}[0-9]{1,2}\.[0-9A-Z]{1,4}'
579+ always_confidence_antipattern = always_confidence_pattern + '\?'
568580 prefix_map = _ensure_prefix_map (prefix_map )
569581 ms = _init_mapping_set (meta )
570582
583+ # Filtering
584+ if filter_by_confident_mappings :
585+ df = df [
586+ (df ['mapAdvice' ].str .contains (always_confidence_pattern , regex = True , na = False )) &
587+ (~ df ['mapAdvice' ].str .contains (always_confidence_antipattern , regex = True , na = False ))]
588+
589+ # Map mappings
571590 mlist : List [Mapping ] = []
572591 for _ , row in df .iterrows ():
573592 mdict = {
0 commit comments