changeset 34:a865c7992a87

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Dec 2016 11:34:18 +0100
parents 12987d11be33
children 6465fbd23bce
files Framework/Messaging/MessagingToolbox.cpp Framework/Messaging/MessagingToolbox.h Framework/Toolbox/DicomFrameConverter.cpp Framework/Toolbox/DicomStructureSet.cpp
diffstat 4 files changed, 36 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Messaging/MessagingToolbox.cpp	Mon Dec 19 11:29:23 2016 +0100
+++ b/Framework/Messaging/MessagingToolbox.cpp	Mon Dec 19 11:34:18 2016 +0100
@@ -162,8 +162,9 @@
       }         
     }
 
-    void ParseJson(Json::Value& target,
-                   const std::string& source)
+
+    static void ParseJson(Json::Value& target,
+                          const std::string& source)
     {
       Json::Reader reader;
       if (!reader.parse(source, target))
@@ -172,6 +173,7 @@
       }
     }
 
+
     void RestApiGet(Json::Value& target,
                     OrthancPlugins::IOrthancConnection& orthanc,
                     const std::string& uri)
@@ -182,6 +184,17 @@
     }
 
 
+    void RestApiPost(Json::Value& target,
+                     OrthancPlugins::IOrthancConnection& orthanc,
+                     const std::string& uri,
+                     const std::string& body)
+    {
+      std::string tmp;
+      orthanc.RestApiPost(tmp, uri, body);
+      ParseJson(target, tmp);
+    }
+
+
     bool HasWebViewerInstalled(OrthancPlugins::IOrthancConnection& orthanc)
     {
       try
--- a/Framework/Messaging/MessagingToolbox.h	Mon Dec 19 11:29:23 2016 +0100
+++ b/Framework/Messaging/MessagingToolbox.h	Mon Dec 19 11:34:18 2016 +0100
@@ -69,13 +69,15 @@
     };
 
 
-    void ParseJson(Json::Value& target,
-                   const std::string& source);
-
     void RestApiGet(Json::Value& target,
                     OrthancPlugins::IOrthancConnection& orthanc,
                     const std::string& uri);
 
+    void RestApiPost(Json::Value& target,
+                     OrthancPlugins::IOrthancConnection& orthanc,
+                     const std::string& uri,
+                     const std::string& body);
+
     bool HasWebViewerInstalled(OrthancPlugins::IOrthancConnection& orthanc);
 
     bool CheckOrthancVersion(OrthancPlugins::IOrthancConnection& orthanc);
--- a/Framework/Toolbox/DicomFrameConverter.cpp	Mon Dec 19 11:29:23 2016 +0100
+++ b/Framework/Toolbox/DicomFrameConverter.cpp	Mon Dec 19 11:34:18 2016 +0100
@@ -79,14 +79,12 @@
 
     Vector c, w;
     if (GeometryToolbox::ParseVector(c, dicom, OrthancPlugins::DICOM_TAG_WINDOW_CENTER) &&
-        GeometryToolbox::ParseVector(w, dicom, OrthancPlugins::DICOM_TAG_WINDOW_WIDTH))
+        GeometryToolbox::ParseVector(w, dicom, OrthancPlugins::DICOM_TAG_WINDOW_WIDTH) &&
+        c.size() > 0 && 
+        w.size() > 0)
     {
-      if (c.size() > 0 && 
-          w.size() > 0)
-      {
-        defaultWindowCenter_ = static_cast<float>(c[0]);
-        defaultWindowWidth_ = static_cast<float>(w[0]);
-      }
+      defaultWindowCenter_ = static_cast<float>(c[0]);
+      defaultWindowWidth_ = static_cast<float>(w[0]);
     }
 
     OrthancPlugins::DicomDatasetReader reader(dicom);
--- a/Framework/Toolbox/DicomStructureSet.cpp	Mon Dec 19 11:29:23 2016 +0100
+++ b/Framework/Toolbox/DicomStructureSet.cpp	Mon Dec 19 11:34:18 2016 +0100
@@ -95,25 +95,22 @@
                                                                      DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0,
                                                                      DICOM_TAG_REFERENCED_SOP_INSTANCE_UID));
 
-    std::string post;
-    orthanc.RestApiPost(post, "/tools/lookup", parentUid);
-
-    Json::Value tmp;
-    MessagingToolbox::ParseJson(tmp, post);
+    Json::Value parentLookup;
+    MessagingToolbox::RestApiPost(parentLookup, orthanc, "/tools/lookup", parentUid);
 
-    if (tmp.type() != Json::arrayValue ||
-        tmp.size() != 1 ||
-        !tmp[0].isMember("Type") ||
-        !tmp[0].isMember("Path") ||
-        tmp[0]["Type"].type() != Json::stringValue ||
-        tmp[0]["ID"].type() != Json::stringValue ||
-        tmp[0]["Type"].asString() != "Instance")
+    if (parentLookup.type() != Json::arrayValue ||
+        parentLookup.size() != 1 ||
+        !parentLookup[0].isMember("Type") ||
+        !parentLookup[0].isMember("Path") ||
+        parentLookup[0]["Type"].type() != Json::stringValue ||
+        parentLookup[0]["ID"].type() != Json::stringValue ||
+        parentLookup[0]["Type"].asString() != "Instance")
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);          
     }
 
     Json::Value parentInstance;
-    MessagingToolbox::RestApiGet(parentInstance, orthanc, "/instances/" + tmp[0]["ID"].asString());
+    MessagingToolbox::RestApiGet(parentInstance, orthanc, "/instances/" + parentLookup[0]["ID"].asString());
 
     if (parentInstance.type() != Json::objectValue ||
         !parentInstance.isMember("ParentSeries") ||
@@ -135,7 +132,7 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
     }
 
-    FullOrthancDataset parentTags(orthanc, "/instances/" + tmp[0]["ID"].asString() + "/tags");
+    FullOrthancDataset parentTags(orthanc, "/instances/" + parentLookup[0]["ID"].asString() + "/tags");
     SliceGeometry slice(parentTags);
 
     Vector v;