Skip to content

Commit

Permalink
camelCasing
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdulz committed Jan 16, 2024
1 parent 66e3192 commit 799e297
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 352 deletions.
80 changes: 40 additions & 40 deletions src/addressanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,85 +7,85 @@ export class AddressAnonymizer {
private randomizer: Randomizer;
private lists: lists;

address_tag: string = data.DicomMetaDictionary.nameMap["PatientAddress"].tag;
region_tag: string = data.DicomMetaDictionary.nameMap["RegionOfResidence"].tag;
country_tag: string = data.DicomMetaDictionary.nameMap["CountryOfResidence"].tag;
value_factories: { [key: string]: (original_value: string) => string };
addressTag: string = data.DicomMetaDictionary.nameMap["PatientAddress"].tag;
regionTag: string = data.DicomMetaDictionary.nameMap["RegionOfResidence"].tag;
countryTag: string = data.DicomMetaDictionary.nameMap["CountryOfResidence"].tag;
valueFactories: { [key: string]: (originalValue: string) => string };

constructor(Randomizer: Randomizer) {
this.randomizer = Randomizer;
this.lists = new lists();

this.address_tag = data.DicomMetaDictionary.unpunctuateTag(this.address_tag);
this.region_tag = data.DicomMetaDictionary.unpunctuateTag(this.region_tag);
this.country_tag = data.DicomMetaDictionary.unpunctuateTag(this.country_tag);
this.addressTag = data.DicomMetaDictionary.unpunctuateTag(this.addressTag);
this.regionTag = data.DicomMetaDictionary.unpunctuateTag(this.regionTag);
this.countryTag = data.DicomMetaDictionary.unpunctuateTag(this.countryTag);

this.value_factories = {
[this.address_tag]: this.get_legal_address,
[this.region_tag]: this.get_region,
[this.country_tag]: this.get_country,
this.valueFactories = {
[this.addressTag]: this.getLegalAddress,
[this.regionTag]: this.getRegion,
[this.countryTag]: this.getCountry,
};
}

anonymize = (dataset: dataSet, data_tag: string): boolean => {
const value_factory: (original_value: string) => string = this.value_factories[data_tag];
if (value_factory == undefined) {
anonymize = (dataset: dataSet, dataTag: string): boolean => {
const valueFactory: (originalValue: string) => string = this.valueFactories[dataTag];
if (valueFactory == undefined) {
return false;
}

if (dataset[data_tag].Value.length > 1) {
dataset[data_tag].Value = dataset[data_tag].Value.map((original_value: string) => {
return value_factory(original_value);
if (dataset[dataTag].Value.length > 1) {
dataset[dataTag].Value = dataset[dataTag].Value.map((originalValue: string) => {
return valueFactory(originalValue);
});

return true;
} else {
const original_value: string = dataset[data_tag].Value[0];
dataset[data_tag].Value[0] = value_factory(original_value);
const originalValue: string = dataset[dataTag].Value[0];
dataset[dataTag].Value[0] = valueFactory(originalValue);

return true;
}
};

get_legal_address = (original_value: string): string => {
const street: string = this.get_street_address(original_value);
const street_number: string = this.get_street_number(original_value);
const city: string = this.get_region(original_value);
getLegalAddress = (originalValue: string): string => {
const street: string = this.getStreetAddress(originalValue);
const streetNumber: string = this.getStreetNumber(originalValue);
const city: string = this.getRegion(originalValue);

return `${street_number} ${street}, ${city}`;
return `${streetNumber} ${street}, ${city}`;
};

get_street_number = (original_value: string): string => {
const [street_number_index]: number[] = this.randomizer.getIntsFromRanges(original_value, 1000);
const street_number: number = street_number_index + 1;
getStreetNumber = (originalValue: string): string => {
const [streetNumberIndex]: number[] = this.randomizer.getIntsFromRanges(originalValue, 1000);
const streetNumber: number = streetNumberIndex + 1;

return `${street_number}`;
return `${streetNumber}`;
};

get_street_address = (original_value: string): string => {
const [street_index]: number[] = this.randomizer.getIntsFromRanges(
original_value,
getStreetAddress = (originalValue: string): string => {
const [streetIndex]: number[] = this.randomizer.getIntsFromRanges(
originalValue,
this.lists.streets.length
);

return `${this.lists.streets[street_index]}`;
return `${this.lists.streets[streetIndex]}`;
};

get_region = (original_value: string): string => {
const [city_index]: number[] = this.randomizer.getIntsFromRanges(
original_value,
getRegion = (originalValue: string): string => {
const [cityIndex]: number[] = this.randomizer.getIntsFromRanges(
originalValue,
this.lists.cities.length
);

return `${this.lists.cities[city_index]}`;
return `${this.lists.cities[cityIndex]}`;
};

get_country = (original_value: string): string => {
const [country_index]: number[] = this.randomizer.getIntsFromRanges(
original_value,
getCountry = (originalValue: string): string => {
const [countryIndex]: number[] = this.randomizer.getIntsFromRanges(
originalValue,
this.lists.countries.length
);

return `${this.lists.countries[country_index]}`;
return `${this.lists.countries[countryIndex]}`;
};
}
54 changes: 27 additions & 27 deletions src/anonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ export class Anonymizer {
*/

private patientID?: string;
private date_offset_hours: number;
private dateOffsetHours: number;
randomizer: Randomizer;
address_anonymizer: AddressAnonymizer;
element_handlers: ElementHandler[];
addressAnonymizer: AddressAnonymizer;
elementHandlers: ElementHandler[];

constructor(
patientID?: string,
protected_tags?: string[],
protectedTags?: string[],
anonymizePrivateTags?: boolean,
id_prefix?: string,
id_suffix?: string,
idPrefix?: string,
idSuffix?: string,
seed?: string
) {
const minimum_offset_hours: number = 62 * 24;
const maximum_offset_hours: number = 730 * 24;
const minimumOffsetHours: number = 62 * 24;
const maximumOffsetHours: number = 730 * 24;
if (patientID) {
this.patientID = patientID;
}
this.randomizer = new Randomizer(seed);
this.date_offset_hours = Number(
this.dateOffsetHours = Number(
-(
(this.randomizer.toInt("date_offset") %
(BigInt(maximum_offset_hours) - BigInt(minimum_offset_hours))) +
BigInt(minimum_offset_hours)
(this.randomizer.toInt("dateOffset") %
(BigInt(maximumOffsetHours) - BigInt(minimumOffsetHours))) +
BigInt(minimumOffsetHours)
)
);
//this.data = data;
this.address_anonymizer = new AddressAnonymizer(this.randomizer);
this.element_handlers = [
this.addressAnonymizer = new AddressAnonymizer(this.randomizer);
this.elementHandlers = [
new UnwantedElementStripper([
"00101081", //"BranchOfService",
"00102180", //"Occupation",
Expand Down Expand Up @@ -84,36 +84,36 @@ export class Anonymizer {
"00081010", //"StationName",
"00200010", //"StudyID"
],
id_prefix,
id_suffix
idPrefix,
idSuffix
).anonymize,
this.address_anonymizer.anonymize,
new InstitutionAnonymizer(this.address_anonymizer).anonymize,
this.addressAnonymizer.anonymize,
new InstitutionAnonymizer(this.addressAnonymizer).anonymize,
new FixedValueAnonymizer("00321033", "").anonymize, // RequestingService
new FixedValueAnonymizer("00380300", "").anonymize, // CurrentPatientLocation
new DateTimeAnonymizer(this.date_offset_hours).anonymize,
new DateTimeAnonymizer(this.dateOffsetHours).anonymize,
];
if (protected_tags) {
this.element_handlers.unshift(new ValueKeeper(protected_tags).keep);
if (protectedTags) {
this.elementHandlers.unshift(new ValueKeeper(protectedTags).keep);
}
if (this.patientID) {
this.element_handlers.push(new FixedValueAnonymizer("00100020", this.patientID).anonymize);
this.elementHandlers.push(new FixedValueAnonymizer("00100020", this.patientID).anonymize);
}
if (anonymizePrivateTags) {
this.element_handlers.push(new PrivatTagAnonymizer().anonymize);
this.elementHandlers.push(new PrivatTagAnonymizer().anonymize);
}
}
anonymize(data: data.DicomDict) {
this.walk(data.meta, this.element_handlers);
this.walk(data.dict, this.element_handlers);
this.walk(data.meta, this.elementHandlers);
this.walk(data.dict, this.elementHandlers);
}

walk(dataset: dataSet, handler: ElementHandler[]) {
const tagList = Object.keys(dataset);
for (const tag of tagList) {
const element = dataset[tag];

this.anonymize_element(dataset, tag, handler);
this.anonymizeElement(dataset, tag, handler);

// If the element is a sequence, recursively walk through its items
if (tag in dataset && element.vr == "SQ") {
Expand All @@ -127,7 +127,7 @@ export class Anonymizer {
}
}

anonymize_element(dataset: dataSet, tag: string, handler: ElementHandler[]) {
anonymizeElement(dataset: dataSet, tag: string, handler: ElementHandler[]) {
// Perform operations on the element
for (const callback of handler) {
if (callback(dataset, tag)) {
Expand Down
12 changes: 6 additions & 6 deletions src/datetimeanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type returnarg = {
export class DateTimeAnonymizer {
private offset: number;

constructor(date_offset_hours: number) {
this.offset = date_offset_hours * 60 * 60 * 1000;
constructor(dateOffsetHours: number) {
this.offset = dateOffsetHours * 60 * 60 * 1000;
}

anonymize = (dataset: dataSet, dataTag: string): boolean => {
Expand All @@ -21,15 +21,15 @@ export class DateTimeAnonymizer {
}

if (dataset[dataTag].vr == "DA") {
this.anonymize_date_and_time(dataset, dataTag);
this.anonymizeDateAndTime(dataset, dataTag);
} else {
this.anonymize_datetime(dataset, dataTag);
this.anonymizeDatetime(dataset, dataTag);
}

return true;
};

anonymize_date_and_time = (dataset: dataSet, dataTag: string): void => {
anonymizeDateAndTime = (dataset: dataSet, dataTag: string): void => {
const dates = dataset[dataTag].Value;
const result: returnarg = this.checkTag(dataset, dataTag);

Expand All @@ -55,7 +55,7 @@ export class DateTimeAnonymizer {
}
};

anonymize_datetime = (dataset: dataSet, dataTag: string): void => {
anonymizeDatetime = (dataset: dataSet, dataTag: string): void => {
const dateTimes = dataset[dataTag].Value;
const newDateTimes: string[] = [];

Expand Down
6 changes: 3 additions & 3 deletions src/fixedvalueanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class FixedValueAnonymizer {
this.value = value;
}

anonymize = (dataset: dataSet, data_tag: string): boolean => {
if (data_tag == this.tag) {
dataset[data_tag].Value[0] = this.value;
anonymize = (dataset: dataSet, dataTag: string): boolean => {
if (dataTag == this.tag) {
dataset[dataTag].Value[0] = this.value;

return true;
} else {
Expand Down
47 changes: 23 additions & 24 deletions src/idanonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,54 @@ import { Randomizer } from "./randomizer";
export class IDAnonymizer {
private keywords: string[];
private randomizer: Randomizer;
private id_suffix: string;
private id_prefix: string;
private issuer_tag: string;
//private tag_ids: string[];
private idSuffix: string;
private idPrefix: string;
private issuerTag: string;
private alphabet: string;
private totalAffixesLength: number;
private indicesForRandomizer: number[];

constructor(Randomizer: Randomizer, keywords: string[], id_prefix = "", id_suffix = "") {
constructor(Randomizer: Randomizer, keywords: string[], idPrefix = "", idSuffix = "") {
this.keywords = keywords;
this.randomizer = Randomizer;
this.id_prefix = id_prefix;
this.id_suffix = id_suffix;
this.issuer_tag = data.DicomMetaDictionary.nameMap["IssuerOfPatientID"].tag;
this.idPrefix = idPrefix;
this.idSuffix = idSuffix;
this.issuerTag = data.DicomMetaDictionary.nameMap["IssuerOfPatientID"].tag;

this.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
this.totalAffixesLength = this.id_prefix.length + this.id_suffix.length;
this.totalAffixesLength = this.idPrefix.length + this.idSuffix.length;
this.indicesForRandomizer = new Array<number>(12 - this.totalAffixesLength).fill(
this.alphabet.length
);
}

anonymize = (dataset: dataSet, data_tag: string): boolean => {
if (this.keywords.includes(data_tag)) {
this.replace_id(dataset, data_tag);
anonymize = (dataset: dataSet, dataTag: string): boolean => {
if (this.keywords.includes(dataTag)) {
this.replaceID(dataset, dataTag);
return true;
} else if (data_tag == this.issuer_tag && dataset[data_tag].Value[0] != "") {
dataset[data_tag].Value[0] = "DICOM_ANONYMIZER";
} else if (dataTag == this.issuerTag && dataset[dataTag].Value[0] != "") {
dataset[dataTag].Value[0] = "DICOM_ANONYMIZER";
return true;
} else {
return false;
}
};

replace_id = (dataset: dataSet, data_tag: string): void => {
if (dataset[data_tag].Value.length > 1) {
dataset[data_tag].Value = dataset[data_tag].Value.map((original_value: string) => {
return this.new_id(original_value);
replaceID = (dataset: dataSet, dataTag: string): void => {
if (dataset[dataTag].Value.length > 1) {
dataset[dataTag].Value = dataset[dataTag].Value.map((originalValue: string) => {
return this.newID(originalValue);
});
} else {
const original_value = dataset[data_tag].Value[0];
dataset[data_tag].Value[0] = this.new_id(original_value);
const originalValue = dataset[dataTag].Value[0];
dataset[dataTag].Value[0] = this.newID(originalValue);
}
};

new_id = (original_value: string): string => {
const indexes = this.randomizer.getIntsFromRanges(original_value, ...this.indicesForRandomizer);
const id_root: string = indexes.map((i) => this.alphabet[i]).join("");
newID = (originalValue: string): string => {
const indexes = this.randomizer.getIntsFromRanges(originalValue, ...this.indicesForRandomizer);
const idRoot: string = indexes.map((i) => this.alphabet[i]).join("");

return this.id_prefix + id_root + this.id_suffix;
return this.idPrefix + idRoot + this.idSuffix;
};
}
Loading

0 comments on commit 799e297

Please sign in to comment.