diff --git a/src/anonymizer.ts b/src/anonymizer.ts index 88bf9d8..e82fe80 100644 --- a/src/anonymizer.ts +++ b/src/anonymizer.ts @@ -18,33 +18,27 @@ export class Anonymizer { reuse an Anonymizer. */ + private patientID: string; - - private id_prefix: string | undefined; - private id_suffix: string | undefined; - private seed: string | undefined; - - + private date_offset_hours: number randomizer: Randomizer; address_anonymizer: AddressAnonymizer; element_handlers: any[]; - private date_offset_hours: number - constructor( patientID: string, id_prefix?: string | undefined, id_suffix?: string | undefined, seed?: string | undefined) { + + constructor( patientID: string, protected_tags?: string[], id_prefix?: string, id_suffix?: string, seed?: string) { const minimum_offset_hours: number = 62 * 24; const maximum_offset_hours: number = 730 * 24; this.patientID = patientID; - this.id_prefix = id_prefix; - this.id_suffix = id_suffix; - this.seed = seed; - this.randomizer = new Randomizer(this.seed) + this.randomizer = new Randomizer(seed) this.date_offset_hours = Number(-( this.randomizer.toInt("date_offset") % (BigInt(maximum_offset_hours) - BigInt(minimum_offset_hours)) + BigInt(minimum_offset_hours) )) //this.data = data; this.address_anonymizer = new AddressAnonymizer(this.randomizer); this.element_handlers = - [new UnwantedElementStripper(["00101081",//"BranchOfService", + [new Protector(protected_tags).protect, + new UnwantedElementStripper(["00101081",//"BranchOfService", "00102180",//"Occupation", "00101090",//"MedicalRecordLocator", "00101080",//"MilitaryRank", @@ -73,7 +67,7 @@ export class Anonymizer { "00081010",//"StationName", "00200010",//"StudyID" ], - undefined, undefined).anonymize, + id_prefix, id_suffix).anonymize, this.address_anonymizer.anonymize, new InstitutionAnonymizer(this.address_anonymizer).anonymize, new FixedValueAnonymizer("00100020", this.patientID).anonymize, diff --git a/src/datetimeanonymizer.ts b/src/datetimeanonymizer.ts index 5d19281..30277e6 100644 --- a/src/datetimeanonymizer.ts +++ b/src/datetimeanonymizer.ts @@ -116,7 +116,7 @@ export class DateTimeAnonymizer{ - zipLongest = (fillValue: any | undefined, ...arr: any[]): string[][] =>{ + zipLongest = (fillValue: string = "", ...arr: any[]): string[][] =>{ const maxLength = Math.max(...arr.map((arr: any) => arr.length)); return Array.from({ length: maxLength }, (_, index) => { diff --git a/src/idanonymizer.ts b/src/idanonymizer.ts index 8c7847a..68cd0c9 100644 --- a/src/idanonymizer.ts +++ b/src/idanonymizer.ts @@ -6,15 +6,15 @@ export class IDAnonymizer { private keywords: string[]; private randomizer: Randomizer; - private id_suffix: string | undefined; - private id_prefix: string | undefined; + private id_suffix: string; + private id_prefix: string; private issuer_tag: string; //private tag_ids: string[]; private alphabet: string; private totalAffixesLength: number; private indicesForRandomizer: number[]; - constructor(Randomizer: Randomizer, keywords: string[], id_prefix?: string | undefined, id_suffix?: string | undefined) { + constructor(Randomizer: Randomizer, keywords: string[], id_prefix: string = "", id_suffix: string = "") { this.keywords = keywords; this.randomizer = Randomizer; this.id_prefix = id_prefix; @@ -22,21 +22,7 @@ export class IDAnonymizer { this.issuer_tag = dcmjs.data.DicomMetaDictionary.nameMap["IssuerOfPatientID"].tag //this.tag_ids = this.keywords.map(tag_name => dcmjs.data.DicomMetaDictionary.unpunctuateTag(dcmjs.data.DicomMetaDictionary.nameMap[tag_name].tag)); this.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - - if (this.id_prefix && this.id_suffix){ - this.totalAffixesLength = this.id_prefix.length + this.id_suffix.length - } else if (this.id_prefix && !this.id_suffix){ - this.id_suffix = "" - this.totalAffixesLength = this.id_prefix.length - - } else if (!this.id_prefix && this.id_suffix){ - this.id_prefix = "" - this.totalAffixesLength = this.id_suffix.length - } - else { - this.totalAffixesLength = 0 - } - + this.totalAffixesLength = this.id_prefix.length + this.id_suffix.length this.indicesForRandomizer = new Array(12 - this.totalAffixesLength).fill(this.alphabet.length) } diff --git a/src/pnanonymizer.ts b/src/pnanonymizer.ts index 8a234d3..11db94c 100644 --- a/src/pnanonymizer.ts +++ b/src/pnanonymizer.ts @@ -32,7 +32,7 @@ export class PNAnonymizer { return true } - new_pn(original_value: string, sex?: string | undefined,){ + new_pn(original_value: string, sex: string = "",){ let first_names: string[]; if (sex == "F"){ first_names = this.lists.female_first_names;} diff --git a/src/randomizer.ts b/src/randomizer.ts index ea6204c..ce8a1a4 100644 --- a/src/randomizer.ts +++ b/src/randomizer.ts @@ -4,8 +4,8 @@ import getRandomValues from 'get-random-values'; // use only in node env export class Randomizer { private seed: string; - constructor(seed?: string | undefined ) { - if (seed != null || seed === undefined) { + constructor(seed: string = "" ) { + if (seed == "") { this.seed = this.generateRandomSeed(); } else { this.seed = seed; @@ -67,8 +67,6 @@ export class Randomizer { for (const x of suprema) { const s = BigInt(x) result.push(Number(big_Int % s)); - // console.log(s, big_Int, big_Int%s); - // console.log(BigInt(Math.floor(Number(big_Int / s)))); big_Int = big_Int / s; }