How to use the deid.logger.bot.warning function in deid

To help you get started, we’ve selected a few deid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / deid / deid / identifiers / actions.py View on Github external
def parse_value(item,value):
    '''parse_value will parse the value field of an action,
    either returning the string, or a variable looked up
    in the case of var:FieldName
    '''
    # Does the user want a custom value?
    if re.search('[:]',value):
        value_type,value_option = value.split(':') 
        if value_type.lower() == "var": 

            # If selected variable not provided, skip
            if value_option not in item:
                return None
            return item[value_option]
        bot.warning('%s is not a valid value type, skipping.' %(value_type))
        return None
    return value
github pydicom / deid / deid / utils / actions.py View on Github external
# Does the user want a custom value?
    if re.search("[:]", value):
        value_type, value_option = value.split(":", 1)
        if value_type.lower() == "var":

            # If selected variable not provided, skip
            if value_option not in item:
                return None
            return item[value_option]

        # The user is providing a specific function
        elif value_type.lower() == "func":

            if value_option not in item:
                bot.warning("%s not found in item lookup." % (value_option))
                return None

            # item is the lookup, value from the recipe, and field
            # The field is an entire dicom element object
            return item[value_option](dicom=dicom, value=value, field=field, item=item)

        bot.warning("%s is not a valid value type, skipping." % (value_type))
        return None
    return value
github pydicom / deid / deid / config / utils.py View on Github external
# The user has provided a directory
    if os.path.isdir(path):
        contenders = [
            "%s/%s" % (path, x) for x in os.listdir(path) if x.startswith("deid")
        ]

        if len(contenders) == 0:
            bot.warning(
                "No deid settings files found in %s, will use default dicom.deid."
                % path
            )
            contenders.append(default_deid)

        elif len(contenders) > 1:
            bot.warning("Multiple deid files found in %s, will use first." % (path))

        path = contenders[0]

    # We have a file path at this point
    if not os.path.exists(path):
        bot.exit("Cannot find deid file %s, exiting." % (path))

    return path
github pydicom / deid / deid / dicom / fields.py View on Github external
prefix: the parent name
    """
    items = {}
    for item in sequence:

        # If it's a Dataset, we need to further unwrap it
        if isinstance(item, Dataset):
            for subitem in item:
                items.update(extract_item(subitem, prefix=prefix))

        # Private tags are DataElements
        elif isinstance(item, DataElement):
            items[item.tag] = extract_item(item, prefix=prefix)

        else:
            bot.warning(
                "Unrecognized type %s in extract sequences, skipping." % type(item)
            )
    return items
github pydicom / deid / deid / config / utils.py View on Github external
# Add the filter label to the config
                config = parse_label(
                    config=config,
                    section=section,
                    label=line,
                    section_name=section_name,
                    members=members,
                )
            # Parse the action
            else:
                config = parse_config_action(
                    section=section, section_name=section_name, line=line, config=config
                )
        else:
            bot.warning("%s not recognized to be in valid format, skipping." % line)
    return config
github pydicom / deid / deid / dicom / actions.py View on Github external
elif dcmvr == "DT":
            # NEMA-compliant format for DICOM timestamp is
            # YYYYMMDDHHMMSS.FFFFFF&ZZXX
            try:
                new_value = get_timestamp(
                    original, jitter_days=value, format="%Y%m%d%H%M%S.%f%z"
                )
            except:
                new_value = get_timestamp(
                    original, jitter_days=value, format="%Y%m%d%H%M%S.%f"
                )

        else:
            # Do nothing and issue a warning.
            bot.warning("JITTER not supported for %s with VR=%s" % (field, dcmvr))

        if new_value is not None and new_value != original:

            # Only update if there's something to update AND there's been change
            dicom = update_tag(dicom, field=field, value=new_value)

    return dicom
github pydicom / deid / deid / dicom / pixels.py View on Github external
filters = criteria["filters"]
        label = [x for x in [criteria['modality'],
                             criteria['manufacturer'],
                             criteria['label']]
                 if x is not None]

        for func,actions in filters.items():
            for action in actions:
                flagged = apply_filter(dicom=dicom,
                                       field=action['field'],
                                       filter_name=func,
                                       value=action["value"])
                                     
                if flagged:
                    label = " ".join(label)
                    bot.warning("FLAG for %s: %s" %(dicom_name,label))
                    return flagged


    bot.debug("%s header filter indicates pixels are clean." %dicom_name)
    return flagged
github pydicom / deid / deid / dicom / parser.py View on Github external
# For a replacement, this is likely
                if uid in self.fields:
                    element = self.fields[uid]

                    # Nested fields
                    while not hasattr(element, "value"):
                        element = element.element
                    element.value = value

                else:
                    element = DataElement(tag["tag"], tag["VR"], value)
                    self.dicom.add(element)
                    self.fields[uid] = DicomField(element, name, uid)
            else:
                bot.warning("Cannot find tag for field %s, skipping." % name)
github pydicom / deid / deid / dicom / groups.py View on Github external
subset = {}

    if not fields:
        fields = get_fields(dicom)

    for action in actions:

        if action["action"] == "FIELD":
            subset.update(
                expand_field_expression(
                    field=action["field"], dicom=dicom, contenders=fields
                )
            )

        else:
            bot.warning(
                "Unrecognized action %s for fields list extraction." % action["action"]
            )
    return subset
github pydicom / deid / deid / dicom / pixels / clean.py View on Github external
def save_png(self, output_folder=None, image_type="cleaned", title=None):
        """save an original or cleaned dicom as png to disk.
           Default image_format is "cleaned" and can be set 
           to "original." If the image was already clean (not 
           flagged) the cleaned image is just a copy of original
        """
        if hasattr(self, image_type):
            png_file = self._get_clean_name(output_folder, "png")
            plt = self.get_figure(image_type=image_type, title=title)
            plt.savefig(png_file)
            plt.close()
            return png_file
        else:
            bot.warning("use detect() --> clean() before saving is possible.")