diff Plugin/Plugin.cpp @ 19:20af33af313a

is-stable-series
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 09 Apr 2015 16:41:49 +0200
parents 379131283479
children a6492d20b2a8
line wrap: on
line diff
--- a/Plugin/Plugin.cpp	Tue Apr 07 17:09:25 2015 +0200
+++ b/Plugin/Plugin.cpp	Thu Apr 09 16:41:49 2015 +0200
@@ -215,6 +215,53 @@
 
 
 
+static int32_t IsStableSeries(OrthancPluginRestOutput* output,
+                              const char* url,
+                              const OrthancPluginHttpRequest* request)
+{
+ try
+  {
+    if (request->method != OrthancPluginHttpMethod_Get)
+    {
+      OrthancPluginSendMethodNotAllowed(context_, output, "GET");
+      return 0;
+    }
+
+    const std::string id = request->groups[0];
+    Json::Value series;
+
+    if (OrthancPlugins::GetJsonFromOrthanc(series, context_, "/series/" + id) &&
+        series.type() == Json::objectValue)
+    {
+      bool value = (series["IsStable"].asBool() ||
+                    series["Status"].asString() == "Complete");
+      std::string answer = value ? "true" : "false";
+      OrthancPluginAnswerBuffer(context_, output, answer.c_str(), answer.size(), "application/json");
+    }
+    else
+    {
+      OrthancPluginSendHttpStatusCode(context_, output, 404);
+    }
+
+    return 0;
+  }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
+  catch (std::runtime_error& e)
+  {
+    OrthancPluginLogError(context_, e.what());
+    return -1;
+  }
+  catch (boost::bad_lexical_cast&)
+  {
+    OrthancPluginLogError(context_, "Bad lexical cast");
+    return -1;
+  }
+}
+
 
 extern "C"
 {
@@ -328,6 +375,7 @@
 
     /* Install the callbacks */
     OrthancPluginRegisterRestCallback(context_, "/web-viewer/series/(.*)", ServeCache<CacheBundle_SeriesInformation>);
+    OrthancPluginRegisterRestCallback(context_, "/web-viewer/is-stable-series/(.*)", IsStableSeries);
     OrthancPluginRegisterRestCallback(context_, "/web-viewer/instances/(.*)", ServeCache<CacheBundle_DecodedImage>);
     OrthancPluginRegisterRestCallback(context, "/web-viewer/libs/(.*)", ServeEmbeddedFolder<EmbeddedResources::JAVASCRIPT_LIBS>);