changeset 2521:6db878376018

support anonymization of CurrentRequestedProcedureEvidenceSequence
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Apr 2018 17:59:16 +0200
parents b94ed97508e6
children ce2dfba9417c
files Core/DicomFormat/DicomTag.h Core/DicomNetworking/DicomFindAnswers.cpp Core/DicomParsing/DicomModification.cpp Core/DicomParsing/ParsedDicomFile.cpp Core/DicomParsing/ParsedDicomFile.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/Scheduler/ModifyInstanceCommand.cpp UnitTestsSources/FromDcmtkTests.cpp
diffstat 8 files changed, 43 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomFormat/DicomTag.h	Thu Mar 29 16:14:10 2018 +0200
+++ b/Core/DicomFormat/DicomTag.h	Mon Apr 09 17:59:16 2018 +0200
@@ -201,4 +201,6 @@
   static const DicomTag DICOM_TAG_FRAME_OF_REFERENCE_UID(0x0020, 0x0052);
   static const DicomTag DICOM_TAG_REFERENCED_FRAME_OF_REFERENCE_UID(0x3006, 0x0024);
   static const DicomTag DICOM_TAG_RELATED_FRAME_OF_REFERENCE_UID(0x3006, 0x00c2);
+  static const DicomTag DICOM_TAG_CURRENT_REQUESTED_PROCEDURE_EVIDENCE_SEQUENCE(0x0040, 0xa375);
+  static const DicomTag DICOM_TAG_REFERENCED_SERIES_SEQUENCE(0x0008, 0x1115);
 }
--- a/Core/DicomNetworking/DicomFindAnswers.cpp	Thu Mar 29 16:14:10 2018 +0200
+++ b/Core/DicomNetworking/DicomFindAnswers.cpp	Mon Apr 09 17:59:16 2018 +0200
@@ -125,7 +125,7 @@
 
   void DicomFindAnswers::Add(ParsedDicomFile& dicom)
   {
-    AddAnswerInternal(dicom.Clone());
+    AddAnswerInternal(dicom.Clone(true));
   }
 
   void DicomFindAnswers::Add(const void* dicom,
--- a/Core/DicomParsing/DicomModification.cpp	Thu Mar 29 16:14:10 2018 +0200
+++ b/Core/DicomParsing/DicomModification.cpp	Mon Apr 09 17:59:16 2018 +0200
@@ -125,15 +125,33 @@
                                ValueRepresentation vr,
                                const std::string& value)
     {
-      if ((tag == DICOM_TAG_FRAME_OF_REFERENCE_UID || 
-           tag == DICOM_TAG_REFERENCED_FRAME_OF_REFERENCE_UID || 
-           tag == DICOM_TAG_REFERENCED_SOP_INSTANCE_UID ||
-           tag == DICOM_TAG_RELATED_FRAME_OF_REFERENCE_UID) &&
-          IsEnabled(tag))
+      if (!IsEnabled(tag))
+      {
+        return Action_None;
+      }
+      else if (tag == DICOM_TAG_FRAME_OF_REFERENCE_UID || 
+               tag == DICOM_TAG_REFERENCED_FRAME_OF_REFERENCE_UID || 
+               tag == DICOM_TAG_REFERENCED_SOP_INSTANCE_UID ||
+               tag == DICOM_TAG_RELATED_FRAME_OF_REFERENCE_UID)
       {
         newValue = that_.MapDicomIdentifier(Toolbox::StripSpaces(value), ResourceType_Instance);
         return Action_Replace;
       }
+      else if (parentTags.size() == 1 &&
+               parentTags[0] == DICOM_TAG_CURRENT_REQUESTED_PROCEDURE_EVIDENCE_SEQUENCE &&
+               tag == DICOM_TAG_STUDY_INSTANCE_UID)
+      {
+        newValue = that_.MapDicomIdentifier(Toolbox::StripSpaces(value), ResourceType_Study);
+        return Action_Replace;
+      }
+      else if (parentTags.size() == 2 &&
+               parentTags[0] == DICOM_TAG_CURRENT_REQUESTED_PROCEDURE_EVIDENCE_SEQUENCE &&
+               parentTags[1] == DICOM_TAG_REFERENCED_SERIES_SEQUENCE &&
+               tag == DICOM_TAG_SERIES_INSTANCE_UID)
+      {
+        newValue = that_.MapDicomIdentifier(Toolbox::StripSpaces(value), ResourceType_Series);
+        return Action_Replace;
+      }
       else
       {
         return Action_None;
--- a/Core/DicomParsing/ParsedDicomFile.cpp	Thu Mar 29 16:14:10 2018 +0200
+++ b/Core/DicomParsing/ParsedDicomFile.cpp	Mon Apr 09 17:59:16 2018 +0200
@@ -1007,13 +1007,17 @@
   }
 
 
-  ParsedDicomFile::ParsedDicomFile(ParsedDicomFile& other) : 
+  ParsedDicomFile::ParsedDicomFile(ParsedDicomFile& other,
+                                   bool keepSopInstanceUid) : 
     pimpl_(new PImpl)
   {
     pimpl_->file_.reset(dynamic_cast<DcmFileFormat*>(other.pimpl_->file_->clone()));
 
-    // Create a new instance-level identifier
-    ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
+    if (!keepSopInstanceUid)
+    {
+      // Create a new instance-level identifier
+      ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance));
+    }
   }
 
 
@@ -1041,9 +1045,9 @@
   }
 
 
-  ParsedDicomFile* ParsedDicomFile::Clone()
+  ParsedDicomFile* ParsedDicomFile::Clone(bool keepSopInstanceUid)
   {
-    return new ParsedDicomFile(*this);
+    return new ParsedDicomFile(*this, keepSopInstanceUid);
   }
 
 
--- a/Core/DicomParsing/ParsedDicomFile.h	Thu Mar 29 16:14:10 2018 +0200
+++ b/Core/DicomParsing/ParsedDicomFile.h	Mon Apr 09 17:59:16 2018 +0200
@@ -75,7 +75,8 @@
     struct PImpl;
     PImpl* pimpl_;
 
-    ParsedDicomFile(ParsedDicomFile& other);
+    ParsedDicomFile(ParsedDicomFile& other,
+                    bool keepSopInstanceUid);
 
     void CreateFromDicomMap(const DicomMap& source,
                             Encoding defaultEncoding);
@@ -111,7 +112,7 @@
 
     DcmFileFormat& GetDcmtkObject() const;
 
-    ParsedDicomFile* Clone();
+    ParsedDicomFile* Clone(bool keepSopInstanceUid);
 
 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
     void SendPathValue(RestApiOutput& output,
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Thu Mar 29 16:14:10 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Mon Apr 09 17:59:16 2018 +0200
@@ -104,7 +104,7 @@
 
     ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
 
-    std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone());
+    std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone(true));
     modification.Apply(*modified);
     modified->Answer(call.GetOutput());
   }
@@ -162,7 +162,7 @@
        * Compute the resulting DICOM instance.
        **/
 
-      std::auto_ptr<ParsedDicomFile> modified(original.Clone());
+      std::auto_ptr<ParsedDicomFile> modified(original.Clone(true));
       modification.Apply(*modified);
 
       DicomInstanceToStore toStore;
@@ -434,7 +434,7 @@
     {
       for (Json::ArrayIndex i = 0; i < content.size(); i++)
       {
-        std::auto_ptr<ParsedDicomFile> dicom(base.Clone());
+        std::auto_ptr<ParsedDicomFile> dicom(base.Clone(false));
         const Json::Value* payload = NULL;
 
         if (content[i].type() == Json::stringValue)
--- a/OrthancServer/Scheduler/ModifyInstanceCommand.cpp	Thu Mar 29 16:14:10 2018 +0200
+++ b/OrthancServer/Scheduler/ModifyInstanceCommand.cpp	Mon Apr 09 17:59:16 2018 +0200
@@ -95,7 +95,7 @@
 
         {
           ServerContext::DicomCacheLocker lock(context_, *it);
-          modified.reset(lock.GetDicom().Clone());
+          modified.reset(lock.GetDicom().Clone(true));
         }
 
         modification_->Apply(*modified);
--- a/UnitTestsSources/FromDcmtkTests.cpp	Thu Mar 29 16:14:10 2018 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Mon Apr 09 17:59:16 2018 +0200
@@ -88,7 +88,7 @@
   {
     char b[1024];
     sprintf(b, "UnitTestsResults/anon%06d.dcm", i);
-    std::auto_ptr<ParsedDicomFile> f(o.Clone());
+    std::auto_ptr<ParsedDicomFile> f(o.Clone(false));
     if (i > 4)
       o.ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, "coucou");
     m.Apply(*f);