changeset 6:e8e7ba4371e3

fix access to OHIF study list
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 17 Jun 2023 17:45:05 +0200
parents 8c1fe0ca24f5
children eab054ee7537
files Sources/OrthancExplorer.js Sources/Plugin.cpp
diffstat 2 files changed, 47 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Sources/OrthancExplorer.js	Fri Jun 16 15:51:40 2023 +0200
+++ b/Sources/OrthancExplorer.js	Sat Jun 17 17:45:05 2023 +0200
@@ -53,3 +53,31 @@
     }
   });
 });
+
+
+if (${USE_DICOM_WEB}) {
+  $('#lookup').live('pagebeforeshow', function() {
+    $('#open-ohif-study-list').remove();
+    
+    var b = $('<fieldset>')
+        .attr('id', 'open-ohif-study-list')
+        .addClass('ui-grid-b')
+        .append($('<div>')
+                .addClass('ui-block-a'))
+        .append($('<div>')
+                .addClass('ui-block-b')
+                .append($('<a>')
+                        .attr('id', 'coucou')
+                        .attr('data-role', 'button')
+                        .attr('href', '#')
+                        .attr('data-icon', 'forward')
+                        .attr('data-theme', 'a')
+                        .text('Open OHIF study list')
+                        .button()
+                        .click(function(e) {
+                          window.open('../ohif/');
+                        })));
+    
+    b.insertAfter($('#lookup-result'));
+  });
+}
--- a/Sources/Plugin.cpp	Fri Jun 16 15:51:40 2023 +0200
+++ b/Sources/Plugin.cpp	Sat Jun 17 17:45:05 2023 +0200
@@ -345,7 +345,11 @@
   OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Opener-Policy", "same-origin");
   OrthancPluginSetHttpHeader(context, output, "Cross-Origin-Resource-Policy", "same-origin");
 
-  const std::string uri = request->groups[0];
+  std::string uri;
+  if (request->groupsCount > 0)
+  {
+    uri = request->groups[0];
+  }
 
   if (uri == "app-config.js")
   {
@@ -362,8 +366,12 @@
     std::string s = (user + "\n" + system);
     OrthancPluginAnswerBuffer(context, output, s.c_str(), s.size(), "application/json");
   }
-  else if (uri == "viewer")
-  {  
+  else if (uri == "" ||      // Study list
+           uri == "tmtv" ||  // Total metabolic tumor volume
+           uri == "viewer")  // Default viewer (including MPR)
+  {
+    // Those correspond to the different modes of the OHIF platform:
+    // https://v3-docs.ohif.org/platform/modes/
     cache_.Answer(context, output, "index.html");
   }
   else 
@@ -545,27 +553,6 @@
 }
 
 
-static OrthancPluginErrorCode RedirectRoot(OrthancPluginRestOutput* output,
-                                           const char* url,
-                                           const OrthancPluginHttpRequest* request)
-{
-  OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
-
-  if (request->method != OrthancPluginHttpMethod_Get)
-  {
-    OrthancPluginSendMethodNotAllowed(context, output, "GET");
-  }
-  else
-  {
-    // TODO - Is there a better way to go to the list of studies in DICOMweb?
-    // TODO - What if not using DICOMweb?
-    OrthancPluginRedirect(context, output, "ohif/viewer?StudyInstanceUIDs=");
-  }
-
-  return OrthancPluginErrorCode_Success;
-}
-
-
 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
                                         OrthancPluginResourceType resourceType,
                                         const char* resourceId)
@@ -644,9 +631,16 @@
     routerBasename_ = configuration.GetStringValue("RouterBasename", "/ohif");
     useDicomWeb_ = configuration.GetBooleanValue("DicomWeb", false);
 
+    // Make sure that the router basename ends with a trailing slash
+    if (routerBasename_.empty() ||
+        routerBasename_[routerBasename_.size() - 1] != '/')
+    {
+      routerBasename_ += "/";
+    }
+
     OrthancPluginSetDescription(context, "OHIF plugin for Orthanc.");
 
-    OrthancPluginRegisterRestCallback(context, "/ohif", RedirectRoot);
+    OrthancPlugins::RegisterRestCallback<ServeFile>("/ohif", true);
     OrthancPlugins::RegisterRestCallback<ServeFile>("/ohif/(.*)", true);
     OrthancPlugins::RegisterRestCallback<GetOhifStudy>("/ohif-source/(.*)", true);