def testNameFinding(self): """dicom_dictionary: get long and short names for a data_element name""" names = all_names_for_tag(Tag(0x300a00b2)) # Treatment Machine Name expected = ['TreatmentMachineName'] self.assertEqual(names, expected, "Expected %s, got %s" % (expected, names)) names = all_names_for_tag(Tag(0x300A0120)) expected = ['BeamLimitingDeviceAngle', 'BLDAngle'] self.assertEqual(names, expected, "Expected %s, got %s" % (expected, names))
def dir(self, *filters): """Return an alphabetical list of data_element keywords in the dataset. Intended mainly for use in interactive Python sessions. :param filters: zero or more string arguments to the function. Used for case-insensitive match to any part of the DICOM name. :returns: All data_element names in this dataset matching the filters. If no filters, return all DICOM keywords in the dataset """ allnames = [] for tag, data_element in self.items(): allnames.extend(all_names_for_tag(tag)) # remove blanks - tags without valid names (e.g. private tags) allnames = [x for x in allnames if x] # Store found names in a dict, so duplicate names appear only once matches = {} for filter_ in filters: filter_ = filter_.lower() match = [x for x in allnames if x.lower().find(filter_) != -1] matches.update(dict([(x, 1) for x in match])) if filters: names = sorted(matches.keys()) return names else: return sorted(allnames)
def dir(self, *filters): """Return a list of some or all data_element names, in alphabetical order. Intended mainly for use in interactive Python sessions. filters -- 0 or more string arguments to the function if none provided, dir() returns all data_element names in this Dataset. Else dir() will return only those items with one of the strings somewhere in the name (case insensitive). """ allnames = [] for tag, data_element in self.items(): allnames.extend(all_names_for_tag(tag)) allnames = [ x for x in allnames if x ] # remove blanks - tags without valid names (e.g. private tags) # Store found names in a dict, so duplicate names appear only once matches = {} for filter_ in filters: filter_ = filter_.lower() match = [x for x in allnames if x.lower().find(filter_) != -1] matches.update(dict([(x, 1) for x in match])) if filters: names = sorted(matches.keys()) return names else: return sorted(allnames)
def dir(self, *filters): """Return a list of some or all data_element names, in alphabetical order. Intended mainly for use in interactive Python sessions. filters -- 0 or more string arguments to the function if none provided, dir() returns all data_element names in this Dataset. Else dir() will return only those items with one of the strings somewhere in the name (case insensitive). """ allnames = [] for tag, data_element in self.items(): allnames.extend(all_names_for_tag(tag)) allnames = [x for x in allnames if x] # remove blanks - tags without valid names (e.g. private tags) # Store found names in a dict, so duplicate names appear only once matches = {} for filter_ in filters: filter_ = filter_.lower() match = [x for x in allnames if x.lower().find(filter_) != -1] matches.update(dict([(x,1) for x in match])) if filters: names = sorted(matches.keys()) return names else: return sorted(allnames)