comparison 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
comparison
equal deleted inserted replaced
1342:9ec7ac03152d 1343:72d1c2fc0edb
153 success: function(s) { 153 success: function(s) {
154 callback(s); 154 callback(s);
155 } 155 }
156 }); 156 });
157 } 157 }
158
159
160 function GetMultipleResources(type, uuids, callback)
161 {
162 if (uuids == null)
163 {
164 $.ajax({
165 url: '../' + type,
166 dataType: 'json',
167 async: false,
168 cache: false,
169 success: function(s) {
170 uuids = s;
171 }
172 });
173 }
174
175 var resources = [];
176 var ajaxRequests = uuids.map(function(uuid) {
177 return $.ajax({
178 url: '../' + type + '/' + uuid,
179 dataType: 'json',
180 async: true,
181 cache: false,
182 success: function(s) {
183 resources.push(s);
184 }
185 });
186 });
187
188 // Wait for all the AJAX requests to end
189 $.when.apply($, ajaxRequests).then(function() {
190 callback(resources);
191 });
192 }
193
194 158
195 159
196 function CompleteFormatting(s, link, isReverse) 160 function CompleteFormatting(s, link, isReverse)
197 { 161 {
198 if (link != null) 162 if (link != null)
342 }); 306 });
343 307
344 308
345 309
346 $('#find-patients').live('pagebeforeshow', function() { 310 $('#find-patients').live('pagebeforeshow', function() {
347 GetMultipleResources('patients', null, function(patients) { 311 $.ajax({
348 var target = $('#all-patients'); 312 url: '/patients?expand',
349 $('li', target).remove(); 313 dataType: 'json',
314 async: false,
315 cache: false,
316 success: function(patients) {
317 var target = $('#all-patients');
318 $('li', target).remove();
350 319
351 SortOnDicomTag(patients, 'PatientName', false, false); 320 SortOnDicomTag(patients, 'PatientName', false, false);
352 321
353 for (var i = 0; i < patients.length; i++) { 322 for (var i = 0; i < patients.length; i++) {
354 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID); 323 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID);
355 target.append(p); 324 target.append(p);
356 } 325 }
357 326
358 target.listview('refresh'); 327 target.listview('refresh');
359 }); 328 }
329 });
360 }); 330 });
361 331
362 332
363 333
364 function SetupAnonymizedOrModifiedFrom(buttonSelector, resource, resourceType, field) 334 function SetupAnonymizedOrModifiedFrom(buttonSelector, resource, resourceType, field)
380 350
381 function RefreshPatient() 351 function RefreshPatient()
382 { 352 {
383 if ($.mobile.pageData) { 353 if ($.mobile.pageData) {
384 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) { 354 GetSingleResource('patients', $.mobile.pageData.uuid, function(patient) {
385 GetMultipleResources('studies', patient.Studies, function(studies) { 355 $.ajax({
386 SortOnDicomTag(studies, 'StudyDate', false, true); 356 url: '/patients/' + $.mobile.pageData.uuid + '/studies',
387 357 dataType: 'json',
388 $('#patient-info li').remove(); 358 async: false,
389 $('#patient-info') 359 cache: false,
390 .append('<li data-role="list-divider">Patient</li>') 360 success: function(studies) {
391 .append(FormatPatient(patient)) 361 SortOnDicomTag(studies, 'StudyDate', false, true);
392 .listview('refresh'); 362
393 363 $('#patient-info li').remove();
394 var target = $('#list-studies'); 364 $('#patient-info')
395 $('li', target).remove(); 365 .append('<li data-role="list-divider">Patient</li>')
396 366 .append(FormatPatient(patient))
397 for (var i = 0; i < studies.length; i++) { 367 .listview('refresh');
398 if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate) 368
399 { 369 var target = $('#list-studies');
400 target.append('<li data-role="list-divider">{0}</li>'.format 370 $('li', target).remove();
401 (FormatDicomDate(studies[i].MainDicomTags.StudyDate))); 371
372 for (var i = 0; i < studies.length; i++) {
373 if (i == 0 || studies[i].MainDicomTags.StudyDate != studies[i - 1].MainDicomTags.StudyDate)
374 {
375 target.append('<li data-role="list-divider">{0}</li>'.format
376 (FormatDicomDate(studies[i].MainDicomTags.StudyDate)));
377 }
378
379 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID));
402 } 380 }
403 381
404 target.append(FormatStudy(studies[i], '#study?uuid=' + studies[i].ID)); 382 SetupAnonymizedOrModifiedFrom('#patient-anonymized-from', patient, 'patient', 'AnonymizedFrom');
383 SetupAnonymizedOrModifiedFrom('#patient-modified-from', patient, 'patient', 'ModifiedFrom');
384
385 target.listview('refresh');
386
387 // Check whether this patient is protected
388 $.ajax({
389 url: '../patients/' + $.mobile.pageData.uuid + '/protected',
390 type: 'GET',
391 dataType: 'text',
392 async: false,
393 cache: false,
394 success: function (s) {
395 var v = (s == '1') ? 'on' : 'off';
396 $('#protection').val(v).slider('refresh');
397 }
398 });
399
400 currentPage = 'patient';
401 currentUuid = $.mobile.pageData.uuid;
405 } 402 }
406
407 SetupAnonymizedOrModifiedFrom('#patient-anonymized-from', patient, 'patient', 'AnonymizedFrom');
408 SetupAnonymizedOrModifiedFrom('#patient-modified-from', patient, 'patient', 'ModifiedFrom');
409
410 target.listview('refresh');
411
412 // Check whether this patient is protected
413 $.ajax({
414 url: '../patients/' + $.mobile.pageData.uuid + '/protected',
415 type: 'GET',
416 dataType: 'text',
417 async: false,
418 cache: false,
419 success: function (s) {
420 var v = (s == '1') ? 'on' : 'off';
421 $('#protection').val(v).slider('refresh');
422 }
423 });
424
425 currentPage = 'patient';
426 currentUuid = $.mobile.pageData.uuid;
427 }); 403 });
428 }); 404 });
429 } 405 }
430 } 406 }
431 407
433 function RefreshStudy() 409 function RefreshStudy()
434 { 410 {
435 if ($.mobile.pageData) { 411 if ($.mobile.pageData) {
436 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) { 412 GetSingleResource('studies', $.mobile.pageData.uuid, function(study) {
437 GetSingleResource('patients', study.ParentPatient, function(patient) { 413 GetSingleResource('patients', study.ParentPatient, function(patient) {
438 GetMultipleResources('series', study.Series, function(series) { 414 $.ajax({
439 SortOnDicomTag(series, 'SeriesDate', false, true); 415 url: '/studies/' + $.mobile.pageData.uuid + '/series',
440 416 dataType: 'json',
441 $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID); 417 async: false,
442 $('#study-info li').remove(); 418 cache: false,
443 $('#study-info') 419 success: function(series) {
444 .append('<li data-role="list-divider">Patient</li>') 420 SortOnDicomTag(series, 'SeriesDate', false, true);
445 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) 421
446 .append('<li data-role="list-divider">Study</li>') 422 $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID);
447 .append(FormatStudy(study)) 423 $('#study-info li').remove();
448 .listview('refresh'); 424 $('#study-info')
449 425 .append('<li data-role="list-divider">Patient</li>')
450 SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', 'AnonymizedFrom'); 426 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true))
451 SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', 'ModifiedFrom'); 427 .append('<li data-role="list-divider">Study</li>')
452 428 .append(FormatStudy(study))
453 var target = $('#list-series'); 429 .listview('refresh');
454 $('li', target).remove(); 430
455 for (var i = 0; i < series.length; i++) { 431 SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', 'AnonymizedFrom');
456 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate) 432 SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', 'ModifiedFrom');
457 { 433
458 target.append('<li data-role="list-divider">{0}</li>'.format 434 var target = $('#list-series');
459 (FormatDicomDate(series[i].MainDicomTags.SeriesDate))); 435 $('li', target).remove();
436 for (var i = 0; i < series.length; i++) {
437 if (i == 0 || series[i].MainDicomTags.SeriesDate != series[i - 1].MainDicomTags.SeriesDate)
438 {
439 target.append('<li data-role="list-divider">{0}</li>'.format
440 (FormatDicomDate(series[i].MainDicomTags.SeriesDate)));
441 }
442 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID));
460 } 443 }
461 target.append(FormatSeries(series[i], '#series?uuid=' + series[i].ID)); 444 target.listview('refresh');
445
446 currentPage = 'study';
447 currentUuid = $.mobile.pageData.uuid;
462 } 448 }
463 target.listview('refresh');
464
465 currentPage = 'study';
466 currentUuid = $.mobile.pageData.uuid;
467 }); 449 });
468 }); 450 });
469 }); 451 });
470 } 452 }
471 } 453 }
472 454
473 455
475 { 457 {
476 if ($.mobile.pageData) { 458 if ($.mobile.pageData) {
477 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { 459 GetSingleResource('series', $.mobile.pageData.uuid, function(series) {
478 GetSingleResource('studies', series.ParentStudy, function(study) { 460 GetSingleResource('studies', series.ParentStudy, function(study) {
479 GetSingleResource('patients', study.ParentPatient, function(patient) { 461 GetSingleResource('patients', study.ParentPatient, function(patient) {
480 GetMultipleResources('instances', series.Instances, function(instances) { 462 $.ajax({
481 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); 463 url: '/series/' + $.mobile.pageData.uuid + '/instances',
482 464 dataType: 'json',
483 $('#series .patient-link').attr('href', '#patient?uuid=' + patient.ID); 465 async: false,
484 $('#series .study-link').attr('href', '#study?uuid=' + study.ID); 466 cache: false,
485 467 success: function(instances) {
486 $('#series-info li').remove(); 468 Sort(instances, function(x) { return x.IndexInSeries; }, true, false);
487 $('#series-info') 469
488 .append('<li data-role="list-divider">Patient</li>') 470 $('#series .patient-link').attr('href', '#patient?uuid=' + patient.ID);
489 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true)) 471 $('#series .study-link').attr('href', '#study?uuid=' + study.ID);
490 .append('<li data-role="list-divider">Study</li>') 472
491 .append(FormatStudy(study, '#study?uuid=' + study.ID, true)) 473 $('#series-info li').remove();
492 .append('<li data-role="list-divider">Series</li>') 474 $('#series-info')
493 .append(FormatSeries(series)) 475 .append('<li data-role="list-divider">Patient</li>')
494 .listview('refresh'); 476 .append(FormatPatient(patient, '#patient?uuid=' + patient.ID, true))
495 477 .append('<li data-role="list-divider">Study</li>')
496 SetupAnonymizedOrModifiedFrom('#series-anonymized-from', series, 'series', 'AnonymizedFrom'); 478 .append(FormatStudy(study, '#study?uuid=' + study.ID, true))
497 SetupAnonymizedOrModifiedFrom('#series-modified-from', series, 'series', 'ModifiedFrom'); 479 .append('<li data-role="list-divider">Series</li>')
498 480 .append(FormatSeries(series))
499 var target = $('#list-instances'); 481 .listview('refresh');
500 $('li', target).remove(); 482
501 for (var i = 0; i < instances.length; i++) { 483 SetupAnonymizedOrModifiedFrom('#series-anonymized-from', series, 'series', 'AnonymizedFrom');
502 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID)); 484 SetupAnonymizedOrModifiedFrom('#series-modified-from', series, 'series', 'ModifiedFrom');
485
486 var target = $('#list-instances');
487 $('li', target).remove();
488 for (var i = 0; i < instances.length; i++) {
489 target.append(FormatInstance(instances[i], '#instance?uuid=' + instances[i].ID));
490 }
491 target.listview('refresh');
492
493 currentPage = 'series';
494 currentUuid = $.mobile.pageData.uuid;
503 } 495 }
504 target.listview('refresh');
505
506 currentPage = 'series';
507 currentUuid = $.mobile.pageData.uuid;
508 }); 496 });
509 }); 497 });
510 }); 498 });
511 }); 499 });
512 } 500 }
757 }); 745 });
758 746
759 } 747 }
760 }); 748 });
761 749
750
762 $('#series-preview').live('click', function(e) { 751 $('#series-preview').live('click', function(e) {
763 if ($.mobile.pageData) { 752 if ($.mobile.pageData) {
764 GetSingleResource('series', $.mobile.pageData.uuid, function(series) { 753 GetSingleResource('series', $.mobile.pageData.uuid, function(series) {
765 GetMultipleResources('instances', series.Instances, function(instances) { 754 $.ajax({
766 Sort(instances, function(x) { return x.IndexInSeries; }, true, false); 755 url: '/series/' + $.mobile.pageData.uuid + '/instances',
767 756 dataType: 'json',
768 var images = []; 757 async: false,
769 for (var i = 0; i < instances.length; i++) { 758 cache: false,
770 images.push([ '../instances/' + instances[i].ID + '/preview', 759 success: function(instances) {
771 '{0}/{1}'.format(i + 1, instances.length) ]) 760 Sort(instances, function(x) { return x.IndexInSeries; }, true, false);
761
762 var images = [];
763 for (var i = 0; i < instances.length; i++) {
764 images.push([ '../instances/' + instances[i].ID + '/preview',
765 '{0}/{1}'.format(i + 1, instances.length) ])
766 }
767
768 jQuery.slimbox(images, 0, {
769 overlayFadeDuration : 1,
770 resizeDuration : 1,
771 imageFadeDuration : 1,
772 loop : true
773 });
772 } 774 }
773 775 });
774 jQuery.slimbox(images, 0, {
775 overlayFadeDuration : 1,
776 resizeDuration : 1,
777 imageFadeDuration : 1,
778 loop : true
779 });
780 })
781 }); 776 });
782 } 777 }
783 }); 778 });
784 779
785 780