diff OrthancExplorer/explorer.js @ 1343:72d1c2fc0edb

Huge speed-up in Orthanc Explorer for large amount of images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 03 Apr 2015 15:44:06 +0200
parents f1c01451a8ee
children c90a4a42a3f2
line wrap: on
line diff
--- a/OrthancExplorer/explorer.js	Fri Apr 03 15:25:04 2015 +0200
+++ b/OrthancExplorer/explorer.js	Fri Apr 03 15:44:06 2015 +0200
@@ -157,42 +157,6 @@
 }
 
 
-function GetMultipleResources(type, uuids, callback)
-{
-  if (uuids == null)
-  {
-    $.ajax({
-      url: '../' + type,
-      dataType: 'json',
-      async: false,
-      cache: false,
-      success: function(s) {
-        uuids = s;
-      }
-    });
-  }
-
-  var resources = [];
-  var ajaxRequests = uuids.map(function(uuid) {
-    return $.ajax({
-      url: '../' + type + '/' + uuid,
-      dataType: 'json',
-      async: true,
-      cache: false,
-      success: function(s) {
-        resources.push(s);
-      }
-    });
-  });
-
-  // Wait for all the AJAX requests to end
-  $.when.apply($, ajaxRequests).then(function() {
-    callback(resources);
-  });
-}
-
-
-
 function CompleteFormatting(s, link, isReverse)
 {
   if (link != null)
@@ -344,19 +308,25 @@
 
 
 $('#find-patients').live('pagebeforeshow', function() {
-  GetMultipleResources('patients', null, function(patients) {
-    var target = $('#all-patients');
-    $('li', target).remove();
+  $.ajax({
+    url: '/patients?expand',
+    dataType: 'json',
+    async: false,
+    cache: false,
+    success: function(patients) {
+      var target = $('#all-patients');
+      $('li', target).remove();
     
-    SortOnDicomTag(patients, 'PatientName', false, false);
+      SortOnDicomTag(patients, 'PatientName', false, false);
 
-    for (var i = 0; i < patients.length; i++) {
-      var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID);
-      target.append(p);
+      for (var i = 0; i < patients.length; i++) {
+        var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID);
+        target.append(p);
+      }
+
+      target.listview('refresh');
     }
-
-    target.listview('refresh');
-  });
+  });        
 });
 
 
@@ -382,48 +352,54 @@
 {
   if ($.mobile.pageData) {
     GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) {
-      GetMultipleResources('studies', patient.Studies, function(studies) {
-        SortOnDicomTag(studies, 'StudyDate', false, true);
-
-        $('#patient-info li').remove();
-        $('#patient-info')
-          .append('<li data-role="list-divider">Patient</li>')
-          .append(FormatPatient(patient))
-          .listview('refresh');
+      $.ajax({
+        url: '/patients/' + $.mobile.pageData.uuid + '/studies',
+        dataType: 'json',
+        async: false,
+        cache: false,
+        success: function(studies) {
+          SortOnDicomTag(studies, 'StudyDate', false, true);
 
-        var target = $('#list-studies');
-        $('li', target).remove();
-        
-        for (var i = 0; i < studies.length; i++) {
-          if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate)
-          {
-            target.append('<li data-role="list-divider">{0}</li>'.format
-                          (FormatDicomDate(studies[i].MainDicomTags.StudyDate)));
+          $('#patient-info li').remove();
+          $('#patient-info')
+            .append('<li data-role="list-divider">Patient</li>')
+            .append(FormatPatient(patient))
+            .listview('refresh');
+
+          var target = $('#list-studies');
+          $('li', target).remove();
+          
+          for (var i = 0; i < studies.length; i++) {
+            if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate)
+            {
+              target.append('<li data-role="list-divider">{0}</li>'.format
+                            (FormatDicomDate(studies[i].MainDicomTags.StudyDate)));
+            }
+
+            target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID));
           }
 
-          target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID));
-        }
+          SetupAnonymizedOrModifiedFrom('#patient-anonymized-from', patient, 'patient', 'AnonymizedFrom');
+          SetupAnonymizedOrModifiedFrom('#patient-modified-from', patient, 'patient', 'ModifiedFrom');
 
-        SetupAnonymizedOrModifiedFrom('#patient-anonymized-from', patient, 'patient', 'AnonymizedFrom');
-        SetupAnonymizedOrModifiedFrom('#patient-modified-from', patient, 'patient', 'ModifiedFrom');
-
-        target.listview('refresh');
+          target.listview('refresh');
 
-        // Check whether this patient is protected
-        $.ajax({
-          url: '../patients/' + $.mobile.pageData.uuid + '/protected',
-          type: 'GET',
-          dataType: 'text',
-          async: false,
-          cache: false,
-          success: function (s) {
-            var v = (s == '1') ? 'on' : 'off';
-            $('#protection').val(v).slider('refresh');
-          }
-        });
+          // Check whether this patient is protected
+          $.ajax({
+            url: '../patients/' + $.mobile.pageData.uuid + '/protected',
+            type: 'GET',
+            dataType: 'text',
+            async: false,
+            cache: false,
+            success: function (s) {
+              var v = (s == '1') ? 'on' : 'off';
+              $('#protection').val(v).slider('refresh');
+            }
+          });
 
-        currentPage = 'patient';
-        currentUuid = $.mobile.pageData.uuid;
+          currentPage = 'patient';
+          currentUuid = $.mobile.pageData.uuid;
+        }
       });
     });
   }
@@ -435,37 +411,43 @@
   if ($.mobile.pageData) {
     GetSingleResource('studies', $.mobile.pageData.uuid, function(study) {
       GetSingleResource('patients', study.ParentPatient, function(patient) {
-        GetMultipleResources('series', study.Series, function(series) {
-          SortOnDicomTag(series, 'SeriesDate', false, true);
+        $.ajax({
+          url: '/studies/' + $.mobile.pageData.uuid + '/series',
+          dataType: 'json',
+          async: false,
+          cache: false,
+          success: function(series) {
+            SortOnDicomTag(series, 'SeriesDate', false, true);
 
-          $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID);
-          $('#study-info li').remove();
-          $('#study-info')
-            .append('<li data-role="list-divider">Patient</li>')
-            .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true))
-            .append('<li data-role="list-divider">Study</li>')
-            .append(FormatStudy(study))
-            .listview('refresh');
-
-          SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', 'AnonymizedFrom');
-          SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', 'ModifiedFrom');
+            $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID);
+            $('#study-info li').remove();
+            $('#study-info')
+              .append('<li data-role="list-divider">Patient</li>')
+              .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true))
+              .append('<li data-role="list-divider">Study</li>')
+              .append(FormatStudy(study))
+              .listview('refresh');
 
-          var target = $('#list-series');
-          $('li', target).remove();
-          for (var i = 0; i < series.length; i++) {
-            if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate)
-            {
-              target.append('<li data-role="list-divider">{0}</li>'.format
-                            (FormatDicomDate(series[i].MainDicomTags.SeriesDate)));
+            SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', 'AnonymizedFrom');
+            SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', 'ModifiedFrom');
+
+            var target = $('#list-series');
+            $('li', target).remove();
+            for (var i = 0; i < series.length; i++) {
+              if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate)
+              {
+                target.append('<li data-role="list-divider">{0}</li>'.format
+                              (FormatDicomDate(series[i].MainDicomTags.SeriesDate)));
+              }
+              target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID));
             }
-            target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID));
-          }
-          target.listview('refresh');
+            target.listview('refresh');
 
-          currentPage = 'study';
-          currentUuid = $.mobile.pageData.uuid;
+            currentPage = 'study';
+            currentUuid = $.mobile.pageData.uuid;
+          }
         });
-      });  
+      });
     });
   }
 }
@@ -477,34 +459,40 @@
     GetSingleResource('series', $.mobile.pageData.uuid, function(series) {
       GetSingleResource('studies', series.ParentStudy, function(study) {
         GetSingleResource('patients', study.ParentPatient, function(patient) {
-          GetMultipleResources('instances', series.Instances, function(instances) {
-            Sort(instances, function(x) { return x.IndexInSeries; }, true, false);
+          $.ajax({
+            url: '/series/' + $.mobile.pageData.uuid + '/instances',
+            dataType: 'json',
+            async: false,
+            cache: false,
+            success: function(instances) {
+              Sort(instances, function(x) { return x.IndexInSeries; }, true, false);
 
-            $('#series .patient-link').attr('href', '#patient?uuid=' + patient.ID);
-            $('#series .study-link').attr('href', '#study?uuid=' + study.ID);
+              $('#series .patient-link').attr('href', '#patient?uuid=' + patient.ID);
+              $('#series .study-link').attr('href', '#study?uuid=' + study.ID);
 
-            $('#series-info li').remove();
-            $('#series-info')
-              .append('<li data-role="list-divider">Patient</li>')
-              .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true))
-              .append('<li data-role="list-divider">Study</li>')
-              .append(FormatStudy(study, '#study?uuid=' + study.ID, true))
-              .append('<li data-role="list-divider">Series</li>')
-              .append(FormatSeries(series))
-              .listview('refresh');
+              $('#series-info li').remove();
+              $('#series-info')
+                .append('<li data-role="list-divider">Patient</li>')
+                .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true))
+                .append('<li data-role="list-divider">Study</li>')
+                .append(FormatStudy(study, '#study?uuid=' + study.ID, true))
+                .append('<li data-role="list-divider">Series</li>')
+                .append(FormatSeries(series))
+                .listview('refresh');
 
-            SetupAnonymizedOrModifiedFrom('#series-anonymized-from', series, 'series', 'AnonymizedFrom');
-            SetupAnonymizedOrModifiedFrom('#series-modified-from', series, 'series', 'ModifiedFrom');
+              SetupAnonymizedOrModifiedFrom('#series-anonymized-from', series, 'series', 'AnonymizedFrom');
+              SetupAnonymizedOrModifiedFrom('#series-modified-from', series, 'series', 'ModifiedFrom');
 
-            var target = $('#list-instances');
-            $('li', target).remove();
-            for (var i = 0; i < instances.length; i++) {
-              target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID));
+              var target = $('#list-instances');
+              $('li', target).remove();
+              for (var i = 0; i < instances.length; i++) {
+                target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID));
+              }
+              target.listview('refresh');
+
+              currentPage = 'series';
+              currentUuid = $.mobile.pageData.uuid;
             }
-            target.listview('refresh');
-
-            currentPage = 'series';
-            currentUuid = $.mobile.pageData.uuid;
           });
         });
       });
@@ -759,25 +747,32 @@
   }
 });
 
+
 $('#series-preview').live('click', function(e) {
   if ($.mobile.pageData) {
     GetSingleResource('series', $.mobile.pageData.uuid, function(series) {
-      GetMultipleResources('instances', series.Instances, function(instances) {
-        Sort(instances, function(x) { return x.IndexInSeries; }, true, false);
+      $.ajax({
+        url: '/series/' + $.mobile.pageData.uuid + '/instances',
+        dataType: 'json',
+        async: false,
+        cache: false,
+        success: function(instances) {
+          Sort(instances, function(x) { return x.IndexInSeries; }, true, false);
 
-        var images = [];
-        for (var i = 0; i < instances.length; i++) {
-          images.push([ '../instances/' + instances[i].ID + '/preview',
-                        '{0}/{1}'.format(i + 1, instances.length) ])
+          var images = [];
+          for (var i = 0; i < instances.length; i++) {
+            images.push([ '../instances/' + instances[i].ID + '/preview',
+                          '{0}/{1}'.format(i + 1, instances.length) ])
+          }
+
+          jQuery.slimbox(images, 0, {
+            overlayFadeDuration : 1,
+            resizeDuration : 1,
+            imageFadeDuration : 1,
+            loop : true
+          });
         }
-
-        jQuery.slimbox(images, 0, {
-          overlayFadeDuration : 1,
-          resizeDuration : 1,
-          imageFadeDuration : 1,
-          loop : true
-        });
-      })
+      });
     });
   }
 });