def pseudonymize( self, key_file: KeyFile, identifiers: List["Identifier"] ) -> List["Key"]: """Get a pseudonym for each identifier. If identifier is known in PIMS, return this. Otherwise, have PIMS generate a new pseudonym and return that. Parameters ---------- identifiers: List[Identifier] The identifiers to get pseudonyms for key_file: KeyFile The key_file to use Notes ----- Each call this function calls PIMS API twice for each unique source in identifiers. This is result of the way the API can be called Returns ------- List[Key] The PIMS pseudonym for each identifier """ keys = [] # Each call to process a list of identifiers only allows a single source. # Split identifiers by source per_source = defaultdict(list) for x in identifiers: per_source[x.source].append(x) for source, items in per_source.items(): keys = keys + self.deidentify(key_file, [x.value for x in items], source) return keys