diff --git a/src/anonymizer.ts b/src/anonymizer.ts index 201b887..5666e1c 100644 --- a/src/anonymizer.ts +++ b/src/anonymizer.ts @@ -114,7 +114,7 @@ export class Anonymizer { this.anonymize_element(dataset, tag, handler); // If the element is a sequence, recursively walk through its items - if (tag in dataset && element.vr === "SQ") { + if (tag in dataset && element.vr == "SQ") { for (let i = 0; i < element.Value.length; i++) { const sequence = element.Value; for (const item of sequence) { diff --git a/src/datetimeanonymizer.ts b/src/datetimeanonymizer.ts index fc8ee0a..c7a8b7f 100644 --- a/src/datetimeanonymizer.ts +++ b/src/datetimeanonymizer.ts @@ -20,7 +20,7 @@ export class DateTimeAnonymizer { return true; } - if (dataset[dataTag].vr != "DA") { + if (dataset[dataTag].vr == "DA") { this.anonymize_date_and_time(dataset, dataTag); } else { this.anonymize_datetime(dataset, dataTag); @@ -47,7 +47,11 @@ export class DateTimeAnonymizer { dataset[dataTag].Value = newDates; if (result.tag != "") { - dataset[result.tag].Value = newTimes; + try { + dataset[result.tag].Value = newTimes; + } catch { + console.log(); + } } }; @@ -64,6 +68,7 @@ export class DateTimeAnonymizer { shiftDateTime = (dateTimeValue: string): string => { const dateTimeFormat = "%Y%m%d%H".slice(0, dateTimeValue.length - 2); + const oldDateTime = this.parseDateTime(dateTimeValue); const newDateTime = new Date(oldDateTime.getTime() + this.offset); let newDateTimeString = this.formatDate(newDateTime, dateTimeFormat); @@ -95,6 +100,7 @@ export class DateTimeAnonymizer { const hours = padZero(date.getHours(), 2); const minutes = padZero(date.getMinutes(), 2); const seconds = padZero(date.getSeconds(), 2); + const milliseconds = padZero(date.getMilliseconds(), 6); return format .replace("%Y", year) @@ -102,7 +108,8 @@ export class DateTimeAnonymizer { .replace("%d", day) .replace("%H", hours) .replace("%M", minutes) - .replace("%S", seconds); + .replace("%S", seconds) + .replace("%s", milliseconds); }; zipLongest = (fillValue = "", ...arr: string[]): string[][] => { @@ -133,7 +140,7 @@ export class DateTimeAnonymizer { } else { const returnArg: returnarg = { value: "", - tag: timeNameTag, + tag: "", }; return returnArg; } diff --git a/src/idanonymizer.ts b/src/idanonymizer.ts index cb59c93..6d7a252 100644 --- a/src/idanonymizer.ts +++ b/src/idanonymizer.ts @@ -30,8 +30,8 @@ export class IDAnonymizer { if (this.keywords.includes(data_tag)) { this.replace_id(dataset, data_tag); return true; - } else if (data_tag == this.issuer_tag) { - dataset[data_tag].Value[0] = "WieAuchImmerDiesesToolHeisenWird"; + } else if (data_tag == this.issuer_tag && dataset[data_tag].Value[0] != "") { + dataset[data_tag].Value[0] = "DICOM_ANONYMIZER"; return true; } else { return false; diff --git a/src/pnanonymizer.ts b/src/pnanonymizer.ts index ddf7cd8..2d09158 100644 --- a/src/pnanonymizer.ts +++ b/src/pnanonymizer.ts @@ -15,8 +15,11 @@ export class PNAnonymizer { if (dataset[data_tag].vr != "PN") { return false; } + let patient_sex = ""; + if ("00100040" in dataset) { + patient_sex = dataset["00100040"].Value[0]; //PatientSex + } - const patient_sex = dataset["00100040"].Value[0]; //PatientSex if (dataset[data_tag].Value.length > 1) { dataset[data_tag].Value = dataset[data_tag].Value.map((original_name: string) => { return this.new_pn(original_name, patient_sex);