@@ -268,17 +268,21 @@ def parse_snomed_complex_map_tsv(
268268 file_path : str ,
269269 prefix_map : Dict [str , str ] = None ,
270270 meta : Dict [str , str ] = None ,
271+ filter_by_confident_mappings = True
271272) -> MappingSetDataFrame :
272273 """Parse special SNOMED ICD10CM mapping file and translates it into a MappingSetDataFrame.
273274
274- :param file_path: The path to the obographs file
275+ :param file_path: The path to the source file
275276 :param prefix_map: an optional prefix map
276277 :param meta: an optional dictionary of metadata elements
278+ :param filter_by_confident_mappings: Will only include mapping rows where the `mapAdvice` field includes an 'ALWAYS
279+ <code>' pattern.
277280 :return: A SSSOM MappingSetDataFrame
278281 """
279282 raise_for_bad_path (file_path )
280283 df = read_pandas (file_path )
281- df2 = from_snomed_complex_map_tsv (df , prefix_map = prefix_map , meta = meta )
284+ df2 = from_snomed_complex_map_tsv (
285+ df , prefix_map = prefix_map , meta = meta , filter_by_confident_mappings = filter_by_confident_mappings )
282286 return df2
283287
284288
@@ -691,12 +695,15 @@ def from_snomed_complex_map_tsv(
691695 df : pd .DataFrame ,
692696 prefix_map : Optional [PrefixMap ] = None ,
693697 meta : Optional [MetadataType ] = None ,
698+ filter_by_confident_mappings = True
694699) -> MappingSetDataFrame :
695700 """Convert a snomed_icd10cm_map dataframe to a MappingSetDataFrame.
696701
697702 :param df: A mappings dataframe
698703 :param prefix_map: A prefix map
699704 :param meta: A metadata dictionary
705+ :param filter_by_confident_mappings: Will only include mapping rows where the `mapAdvice` field includes an 'ALWAYS
706+ <code>' pattern.
700707 :return: MappingSetDataFrame
701708
702709 # Field descriptions
@@ -730,11 +737,23 @@ def from_snomed_complex_map_tsv(
730737 - mapCategoryId,SctId,Identifies the SNOMED CT concept in the metadata hierarchy which is the MapCategory for the
731738 associated map record. This is a subtype of 447634004 |ICD-10 Map Category value|.,
732739 """
740+ # Local variables
733741 # https://www.findacode.com/snomed/447561005--snomed-ct-source-code-to-target-map-correlation-not-specified.html
734742 match_type_snomed_unspecified_id = 447561005
743+ # - Note: joeflack4: I used this info as a reference for this pattern.
744+ # https://www.medicalbillingandcoding.org/icd-10-cm/#:~:text=ICD%2D10%2DCM%20is%20a,decimal%20point%20and%20the%20subcategory.
745+ always_confidence_pattern = 'ALWAYS [A-Z]{1}[0-9]{1,2}\.[0-9A-Z]{1,4}'
746+ always_confidence_antipattern = always_confidence_pattern + '\?'
735747 prefix_map = _ensure_prefix_map (prefix_map )
736748 ms = _init_mapping_set (meta )
737749
750+ # Filtering
751+ if filter_by_confident_mappings :
752+ df = df [
753+ (df ['mapAdvice' ].str .contains (always_confidence_pattern , regex = True , na = False )) &
754+ (~ df ['mapAdvice' ].str .contains (always_confidence_antipattern , regex = True , na = False ))]
755+
756+ # Map mappings
738757 mlist : List [Mapping ] = []
739758 for _ , row in df .iterrows ():
740759 mdict = {
0 commit comments