Skip to content

Commit

Permalink
adressed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdulz committed Oct 10, 2023
1 parent 8e66b34 commit 93376eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/anonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 11 additions & 4 deletions src/datetimeanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
};

Expand All @@ -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);
Expand Down Expand Up @@ -95,14 +100,16 @@ 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)
.replace("%m", month)
.replace("%d", day)
.replace("%H", hours)
.replace("%M", minutes)
.replace("%S", seconds);
.replace("%S", seconds)
.replace("%s", milliseconds);
};

zipLongest = (fillValue = "", ...arr: string[]): string[][] => {
Expand Down Expand Up @@ -133,7 +140,7 @@ export class DateTimeAnonymizer {
} else {
const returnArg: returnarg = {
value: "",
tag: timeNameTag,
tag: "",
};
return returnArg;
}
Expand Down
4 changes: 2 additions & 2 deletions src/idanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/pnanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93376eb

Please sign in to comment.