Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bot.warning("%s in not a valid choice. Defaulting to blanked." % action)
action = "BLANK"
# A values list returns fields with the value (can be private tags if not removed)
if re.search("^values", field):
values = self.lookup.get(re.sub("^values:", "", field), [])
fields = self.find_by_values(values=values)
# A fields list is used vertabim
elif re.search("^fields", field):
listing = {}
for uid, contender in self.lookup.get(
re.sub("^fields:", "", field), {}
).items():
listing.update(
expand_field_expression(
field=contender.element.keyword,
dicom=self.dicom,
contenders=self.fields,
)
)
fields = listing
else:
# If there is an expander applied to field, we iterate over
fields = expand_field_expression(
field=field, dicom=self.dicom, contenders=self.fields
)
# If it's an addition, we might not have fields
if action == "ADD":
self.add_field(field, value)
listing = {}
for uid, contender in self.lookup.get(
re.sub("^fields:", "", field), {}
).items():
listing.update(
expand_field_expression(
field=contender.element.keyword,
dicom=self.dicom,
contenders=self.fields,
)
)
fields = listing
else:
# If there is an expander applied to field, we iterate over
fields = expand_field_expression(
field=field, dicom=self.dicom, contenders=self.fields
)
# If it's an addition, we might not have fields
if action == "ADD":
self.add_field(field, value)
# Otherwise, these are operations on existing fields
else:
for uid, field in fields.items():
self._run_action(field=field, action=action, value=value)
def extract_fields_list(dicom, actions, fields=None):
"""Given a list of actions for a named group (a list) extract values from
the dicom based on the list of actions provided. This function
always returns a list intended to update some lookup to be used
to further process the dicom.
"""
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
def extract_values_list(dicom, actions, fields=None):
"""Given a list of actions for a named group (a list) extract values from
the dicom based on the list of actions provided. This function
always returns a list intended to update some lookup to be used
to further process the dicom.
"""
values = set()
# The function can be provided fields to save re-parsing
if not fields:
fields = get_fields(dicom)
for action in actions:
# Extract some subset of fields based on action
subset = expand_field_expression(
field=action["field"], dicom=dicom, contenders=fields
)
# Just grab the entire value string for a field, no parsing
if action["action"] == "FIELD":
[values.add(field.element.value) for uid, field in subset.items()]
# Split action, can optionally have a "by" and/or minlength parameter
elif action["action"] == "SPLIT":
# Default values for split are length 1 and character empty space
bot.debug("Parsing action %s" % action)
split_by = " "
minlength = 1
if "value" in action: