Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frame of reference UID fix #2490

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ public void anonymize(ArrayList<File> dicomFiles, String profile) throws Excepti
tagsToDeleteForManufacturer = AnonymizationRulesSingleton.getInstance().getTagsToDeleteForManufacturer();
// init here for multi-threading reasons
Map<String, String> seriesInstanceUIDs = new HashMap<>();
Map<String, String> frameOfReferenceUIDs = new HashMap<>();
Map<String, String> studyInstanceUIDs = new HashMap<>();
Map<String, String> studyIds = new HashMap<>();
LOG.debug("anonymize : totalAmount={}", totalAmount);
int current = 0;
for (int i = 0; i < dicomFiles.size(); ++i) {
final File file = dicomFiles.get(i);
// Perform the anonymization
performAnonymization(file, anonymizationMap, false, "", "", seriesInstanceUIDs, studyInstanceUIDs, studyIds);
performAnonymization(file, anonymizationMap, false, "", "", seriesInstanceUIDs, frameOfReferenceUIDs, studyInstanceUIDs, studyIds);
current++;
final int currentPercent = current * 100 / totalAmount;
LOG.debug("anonymize : anonymization current percent= {} %", currentPercent);
Expand All @@ -99,14 +100,15 @@ public void anonymizeForShanoir(ArrayList<File> dicomFiles, String profile, Stri

// init here for multi-threading reasons
Map<String, String> seriesInstanceUIDs = new HashMap<>();
Map<String, String> frameOfReferenceUIDs = new HashMap<>();
Map<String, String> studyInstanceUIDs = new HashMap<>();
Map<String, String> studyIds = new HashMap<>();
LOG.debug("anonymize : totalAmount={}", totalAmount);
int current = 0;
for (int i = 0; i < dicomFiles.size(); ++i) {
final File file = dicomFiles.get(i);
// Perform the anonymization
performAnonymization(file, anonymizationMap, true, patientName, patientID, seriesInstanceUIDs, studyInstanceUIDs, studyIds);
performAnonymization(file, anonymizationMap, true, patientName, patientID, seriesInstanceUIDs, frameOfReferenceUIDs, studyInstanceUIDs, studyIds);
current++;
final int currentPercent = current * 100 / totalAmount;
LOG.debug("anonymize : anonymization current percent= {} %", currentPercent);
Expand Down Expand Up @@ -156,7 +158,7 @@ private void anonymizePatientMetaData(Attributes attributes, String patientName,
* @throws Exception
*/
public void performAnonymization(final File dicomFile, Map<String, String> anonymizationMap, boolean isShanoirAnonymization,
String patientName, String patientID, Map<String, String> seriesInstanceUIDs,
String patientName, String patientID, Map<String, String> seriesInstanceUIDs, Map<String, String> frameOfReferenceUIDs,
Map<String, String> studyInstanceUIDs, Map<String, String> studyIds) throws Exception {
DicomInputStream din = null;
DicomOutputStream dos = null;
Expand Down Expand Up @@ -217,6 +219,8 @@ public void performAnonymization(final File dicomFile, Map<String, String> anony
anonymizeSOPInstanceUID(tagInt, datasetAttributes, mediaStorageSOPInstanceUIDGenerated);
} else if (tagInt == Tag.SeriesInstanceUID) {
anonymizeSeriesInstanceUID(tagInt, datasetAttributes, seriesInstanceUIDs);
} else if (tagInt == Tag.FrameOfReferenceUID) {
LaurentPV marked this conversation as resolved.
Show resolved Hide resolved
anonymizeFrameOfReferenceUID(tagInt, datasetAttributes, frameOfReferenceUIDs);
} else if (tagInt == Tag.StudyInstanceUID) {
anonymizeStudyInstanceUID(tagInt, datasetAttributes, studyInstanceUIDs);
} else if (tagInt == Tag.StudyID) {
Expand Down Expand Up @@ -350,6 +354,25 @@ private void anonymizeSOPInstanceUID(int tagInt, Attributes attributes, String m
anonymizeTagAccordingToVR(attributes, tagInt, mediaStorageSOPInstanceUID);
}

private void anonymizeFrameOfReferenceUID(int tagInt, Attributes attributes, Map<String, String> frameOfReferenceUIDs) {
String value;
if (frameOfReferenceUIDs != null && frameOfReferenceUIDs.size() != 0
&& frameOfReferenceUIDs.get(attributes.getString(tagInt)) != null) {
value = frameOfReferenceUIDs.get(attributes.getString(tagInt));
} else {
UIDGeneration generator = new UIDGeneration();
String newUID = null;
try {
newUID = generator.getNewUID();
} catch (Exception e) {
LOG.error(e.getMessage());
}
value = newUID;
frameOfReferenceUIDs.put(attributes.getString(tagInt), value);
}
anonymizeTagAccordingToVR(attributes, tagInt, value);
}

private void anonymizeSeriesInstanceUID(int tagInt, Attributes attributes, Map<String, String> seriesInstanceUIDs) {
LaurentPV marked this conversation as resolved.
Show resolved Hide resolved
String value;
if (seriesInstanceUIDs != null && seriesInstanceUIDs.size() != 0
Expand Down
Loading