changeset 4501:11c2ddb4e2ca

FromDcmtkBridge::LogMissingTagsForStore()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Feb 2021 15:24:36 +0100
parents 3b4940bca158
children e3e759cbd19c
files OrthancFramework/Sources/DicomFormat/DicomMap.cpp OrthancFramework/Sources/DicomFormat/DicomMap.h OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h
diffstat 4 files changed, 82 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Tue Feb 09 14:49:30 2021 +0100
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Tue Feb 09 15:24:36 2021 +0100
@@ -920,13 +920,44 @@
 
   void DicomMap::LogMissingTagsForStore() const
   {
+    std::string patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid;
+    
+    if (HasTag(DICOM_TAG_PATIENT_ID))
+    {
+      patientId = ValueAsString(*this, DICOM_TAG_PATIENT_ID);
+    }
+
+    if (HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
+    {
+      studyInstanceUid = ValueAsString(*this, DICOM_TAG_STUDY_INSTANCE_UID);
+    }
+
+    if (HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
+    {
+      seriesInstanceUid = ValueAsString(*this, DICOM_TAG_SERIES_INSTANCE_UID);
+    }
+
+    if (HasTag(DICOM_TAG_SOP_INSTANCE_UID))
+    {
+      sopInstanceUid = ValueAsString(*this, DICOM_TAG_SOP_INSTANCE_UID);
+    }
+
+    LogMissingTagsForStore(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
+  }
+
+  
+  void DicomMap::LogMissingTagsForStore(const std::string& patientId,
+                                        const std::string& studyInstanceUid,
+                                        const std::string& seriesInstanceUid,
+                                        const std::string& sopInstanceUid)
+  {
     std::string s, t;
 
-    if (HasTag(DICOM_TAG_PATIENT_ID))
+    if (!patientId.empty())
     {
       if (t.size() > 0)
         t += ", ";
-      t += "PatientID=" + ValueAsString(*this, DICOM_TAG_PATIENT_ID);
+      t += "PatientID=" + patientId;
     }
     else
     {
@@ -935,11 +966,11 @@
       s += "PatientID";
     }
 
-    if (HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
+    if (!studyInstanceUid.empty())
     {
       if (t.size() > 0)
         t += ", ";
-      t += "StudyInstanceUID=" + ValueAsString(*this, DICOM_TAG_STUDY_INSTANCE_UID);
+      t += "StudyInstanceUID=" + studyInstanceUid;
     }
     else
     {
@@ -948,11 +979,11 @@
       s += "StudyInstanceUID";
     }
 
-    if (HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
+    if (!seriesInstanceUid.empty())
     {
       if (t.size() > 0)
         t += ", ";
-      t += "SeriesInstanceUID=" + ValueAsString(*this, DICOM_TAG_SERIES_INSTANCE_UID);
+      t += "SeriesInstanceUID=" + seriesInstanceUid;
     }
     else
     {
@@ -961,11 +992,11 @@
       s += "SeriesInstanceUID";
     }
 
-    if (HasTag(DICOM_TAG_SOP_INSTANCE_UID))
+    if (!sopInstanceUid.empty())
     {
       if (t.size() > 0)
         t += ", ";
-      t += "SOPInstanceUID=" + ValueAsString(*this, DICOM_TAG_SOP_INSTANCE_UID);
+      t += "SOPInstanceUID=" + sopInstanceUid;
     }
     else
     {
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.h	Tue Feb 09 14:49:30 2021 +0100
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.h	Tue Feb 09 15:24:36 2021 +0100
@@ -138,6 +138,11 @@
 
     void LogMissingTagsForStore() const;
 
+    static void LogMissingTagsForStore(const std::string& patientId,
+                                       const std::string& studyInstanceUid,
+                                       const std::string& seriesInstanceUid,
+                                       const std::string& sopInstanceUid);
+
     bool LookupStringValue(std::string& result,
                            const DicomTag& tag,
                            bool allowBinary) const;
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Tue Feb 09 14:49:30 2021 +0100
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Tue Feb 09 15:24:36 2021 +0100
@@ -2642,6 +2642,42 @@
 
     return FromDcmtkBridge::LookupOrthancTransferSyntax(target, xfer);
   }
+
+
+  void FromDcmtkBridge::LogMissingTagsForStore(DcmDataset& dicom)
+  {
+    std::string patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid;
+
+    const char* c = NULL;
+    if (dicom.findAndGetString(DCM_PatientID, c).good() &&
+        c != NULL)
+    {
+      patientId.assign(c);
+    }
+
+    c = NULL;
+    if (dicom.findAndGetString(DCM_StudyInstanceUID, c).good() &&
+        c != NULL)
+    {
+      studyInstanceUid.assign(c);
+    }
+
+    c = NULL;
+    if (dicom.findAndGetString(DCM_SeriesInstanceUID, c).good() &&
+        c != NULL)
+    {
+      seriesInstanceUid.assign(c);
+    }
+
+    c = NULL;
+    if (dicom.findAndGetString(DCM_SOPInstanceUID, c).good() &&
+        c != NULL)
+    {
+      sopInstanceUid.assign(c);
+    }
+    
+    DicomMap::LogMissingTagsForStore(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
+  }
 }
 
 
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Tue Feb 09 14:49:30 2021 +0100
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Tue Feb 09 15:24:36 2021 +0100
@@ -222,5 +222,7 @@
 
     static bool LookupOrthancTransferSyntax(DicomTransferSyntax& target,
                                             DcmDataset& dicom);
+
+    static void LogMissingTagsForStore(DcmDataset& dicom);
   };
 }