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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
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) {
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) {
String value;
if (seriesInstanceUIDs != null && seriesInstanceUIDs.size() != 0
Expand Down
Loading