diff --git a/shanoir-ng-anonymization/src/main/java/org/shanoir/anonymization/anonymization/AnonymizationServiceImpl.java b/shanoir-ng-anonymization/src/main/java/org/shanoir/anonymization/anonymization/AnonymizationServiceImpl.java index 918785141e..e861cf326f 100644 --- a/shanoir-ng-anonymization/src/main/java/org/shanoir/anonymization/anonymization/AnonymizationServiceImpl.java +++ b/shanoir-ng-anonymization/src/main/java/org/shanoir/anonymization/anonymization/AnonymizationServiceImpl.java @@ -66,6 +66,7 @@ public void anonymize(ArrayList dicomFiles, String profile) throws Excepti tagsToDeleteForManufacturer = AnonymizationRulesSingleton.getInstance().getTagsToDeleteForManufacturer(); // init here for multi-threading reasons Map seriesInstanceUIDs = new HashMap<>(); + Map frameOfReferenceUIDs = new HashMap<>(); Map studyInstanceUIDs = new HashMap<>(); Map studyIds = new HashMap<>(); LOG.debug("anonymize : totalAmount={}", totalAmount); @@ -73,7 +74,7 @@ public void anonymize(ArrayList dicomFiles, String profile) throws Excepti 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); @@ -99,6 +100,7 @@ public void anonymizeForShanoir(ArrayList dicomFiles, String profile, Stri // init here for multi-threading reasons Map seriesInstanceUIDs = new HashMap<>(); + Map frameOfReferenceUIDs = new HashMap<>(); Map studyInstanceUIDs = new HashMap<>(); Map studyIds = new HashMap<>(); LOG.debug("anonymize : totalAmount={}", totalAmount); @@ -106,7 +108,7 @@ public void anonymizeForShanoir(ArrayList dicomFiles, String profile, Stri 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); @@ -156,7 +158,7 @@ private void anonymizePatientMetaData(Attributes attributes, String patientName, * @throws Exception */ public void performAnonymization(final File dicomFile, Map anonymizationMap, boolean isShanoirAnonymization, - String patientName, String patientID, Map seriesInstanceUIDs, + String patientName, String patientID, Map seriesInstanceUIDs, Map frameOfReferenceUIDs, Map studyInstanceUIDs, Map studyIds) throws Exception { DicomInputStream din = null; DicomOutputStream dos = null; @@ -217,6 +219,8 @@ public void performAnonymization(final File dicomFile, Map 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) { @@ -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 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 seriesInstanceUIDs) { String value; if (seriesInstanceUIDs != null && seriesInstanceUIDs.size() != 0