How to use the deid.dicom.fields.DicomField 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 / dicom / fields.py View on Github external
def add_element(element, name, uid):
        """Add an element to fields, but only if it has not been seen.
           The uid is derived from the tag (group, element) and includes
           nesting, so the "same" tag on different levels is considered
           different.
        """
        if uid not in seen:
            fields[uid] = DicomField(element, name, uid)
            seen.append(uid)
github pydicom / deid / deid / dicom / parser.py View on Github external
if tag:
                uid = getattr(field, "uid", None) or str(tag["tag"])

                # 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 / parser.py View on Github external
def add_field(self, field, value):
        """add a field to the dicom. If it's already present, update the value.
        """
        value = parse_value(
            item=self.lookup, value=value, field=field, dicom=self.dicom
        )

        # Assume we don't want to add an empty value
        if value is not None:

            # If provided a field object, create based on keyword or tag identifer
            name = field
            if isinstance(field, DicomField):
                name = field.element.keyword or field.stripped_tag

            # Generate a tag item, add if it's a name found in the dicom dictionary
            tag = get_tag(name)

            # Second try, it might be a private (or other numerical) string identifier
            if not tag:
                tag = add_tag(name)

            if tag:
                uid = getattr(field, "uid", None) or str(tag["tag"])

                # For a replacement, this is likely
                if uid in self.fields:
                    element = self.fields[uid]