comparison OrthancExplorer/explorer.js @ 2873:703d1e848907

Orthanc Explorer: Lookup and limit the results to 100 patients/studies
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Oct 2018 16:27:49 +0200
parents 73d7d95dd75e
children 67ebfacf4467
comparison
equal deleted inserted replaced
2872:9d08edde614b 2873:703d1e848907
10 // http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html 10 // http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html
11 //$.mobile.ajaxEnabled = false; 11 //$.mobile.ajaxEnabled = false;
12 //$.mobile.page.prototype.options.addBackBtn = true; 12 //$.mobile.page.prototype.options.addBackBtn = true;
13 //$.mobile.defaultPageTransition = 'slide'; 13 //$.mobile.defaultPageTransition = 'slide';
14 14
15
16 var LIMIT_RESOURCES = 100;
15 17
16 var currentPage = ''; 18 var currentPage = '';
17 var currentUuid = ''; 19 var currentUuid = '';
18 20
19 21
358 }); 360 });
359 }); 361 });
360 362
361 363
362 364
365 $('#lookup').live('pagebeforeshow', function() {
366 // NB: "GenerateDicomDate()" is defined in "query-retrieve.js"
367 var target = $('#lookup-study-date');
368 $('option', target).remove();
369 target.append($('<option>').attr('value', '*').text('Any date'));
370 target.append($('<option>').attr('value', GenerateDicomDate(0)).text('Today'));
371 target.append($('<option>').attr('value', GenerateDicomDate(-1)).text('Yesterday'));
372 target.append($('<option>').attr('value', GenerateDicomDate(-7) + '-').text('Last 7 days'));
373 target.append($('<option>').attr('value', GenerateDicomDate(-31) + '-').text('Last 31 days'));
374 target.append($('<option>').attr('value', GenerateDicomDate(-31 * 3) + '-').text('Last 3 months'));
375 target.append($('<option>').attr('value', GenerateDicomDate(-365) + '-').text('Last year'));
376 target.selectmenu('refresh');
377
378 $('#lookup-result').hide();
379 });
380
381
382 $('#lookup-submit').live('click', function() {
383 $('#lookup-result').hide();
384
385 var lookup = {
386 'Level' : 'Study',
387 'Expand' : true,
388 'Limit' : LIMIT_RESOURCES + 1,
389 'Query' : {
390 'StudyDate' : $('#lookup-study-date').val()
391 }
392 };
393
394 $('#lookup-form input').each(function(index, input) {
395 if (input.value.length != 0) {
396 if (input.id == 'lookup-patient-id') {
397 lookup['Query']['PatientID'] = input.value;
398 }
399 else if (input.id == 'lookup-patient-name') {
400 lookup['Query']['PatientName'] = input.value;
401 }
402 else if (input.id == 'lookup-accession-number') {
403 lookup['Query']['AccessionNumber'] = input.value;
404 }
405 else if (input.id == 'lookup-study-description') {
406 lookup['Query']['StudyDescription'] = input.value;
407 }
408 else {
409 console.error('Unknown lookup field: ' + input.id);
410 }
411 }
412 });
413
414 console.log(lookup);
415
416 $.ajax({
417 url: '../tools/find',
418 type: 'POST',
419 data: JSON.stringify(lookup),
420 dataType: 'json',
421 async: false,
422 error: function() {
423 alert('Error during lookup');
424 },
425 success: function(studies) {
426 console.log(studies);
427 FormatListOfStudies('#lookup-result ul', '#lookup-alert', '#lookup-count', studies);
428 $('#lookup-result').show();
429 }
430 });
431
432 return false;
433 });
434
435
363 $('#find-patients').live('pagebeforeshow', function() { 436 $('#find-patients').live('pagebeforeshow', function() {
364 GetResource('/patients?expand', function(patients) { 437 GetResource('/patients?expand&since=0&limit=' + (LIMIT_RESOURCES + 1), function(patients) {
365 var target = $('#all-patients'); 438 var target = $('#all-patients');
366 $('li', target).remove(); 439 $('li', target).remove();
367 440
368 SortOnDicomTag(patients, 'PatientName', false, false); 441 SortOnDicomTag(patients, 'PatientName', false, false);
369 442
370 for (var i = 0; i < patients.length; i++) { 443 var count, showAlert;
444 if (patients.length <= LIMIT_RESOURCES) {
445 count = patients.length;
446 showAlert = false;
447 }
448 else {
449 count = LIMIT_RESOURCES;
450 showAlert = true;
451 }
452
453 for (var i = 0; i < count; i++) {
371 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID); 454 var p = FormatPatient(patients[i], '#patient?uuid=' + patients[i].ID);
372 target.append(p); 455 target.append(p);
373 } 456 }
374 457
375 target.listview('refresh'); 458 target.listview('refresh');
376 }); 459
377 }); 460 if (showAlert) {
378 461 $('#count-patients').text(LIMIT_RESOURCES);
462 $('#alert-patients').show();
463 } else {
464 $('#alert-patients').hide();
465 }
466 });
467 });
468
469
470
471 function FormatListOfStudies(targetId, alertId, countId, studies)
472 {
473 var target = $(targetId);
474 $('li', target).remove();
475
476 for (var i = 0; i < studies.length; i++) {
477 var patient = studies[i].PatientMainDicomTags.PatientName;
478 var study = studies[i].MainDicomTags.StudyDescription;
479
480 var s;
481 if (typeof patient === 'string') {
482 s = patient;
483 }
484
485 if (typeof study === 'string') {
486 if (s.length > 0) {
487 s += ' - ';
488 }
489
490 s += study;
491 }
492
493 studies[i]['Label'] = s;
494 }
495
496 Sort(studies, function(a) { return a.Label }, false, false);
497
498
499 var count, showAlert;
500 if (studies.length <= LIMIT_RESOURCES) {
501 count = studies.length;
502 showAlert = false;
503 }
504 else {
505 count = LIMIT_RESOURCES;
506 showAlert = true;
507 }
508
509 for (var i = 0; i < count; i++) {
510 var p = FormatStudy(studies[i], '#study?uuid=' + studies[i].ID, false, true);
511 target.append(p);
512 }
513
514 target.listview('refresh');
515
516 if (showAlert) {
517 $(countId).text(LIMIT_RESOURCES);
518 $(alertId).show();
519 } else {
520 $(alertId).hide();
521 }
522 }
379 523
380 524
381 $('#find-studies').live('pagebeforeshow', function() { 525 $('#find-studies').live('pagebeforeshow', function() {
382 GetResource('/studies?expand', function(studies) { 526 GetResource('/studies?expand&since=0&limit=' + (LIMIT_RESOURCES + 1), function(studies) {
383 var target = $('#all-studies'); 527 FormatListOfStudies('#all-studies', '#alert-studies', '#count-studies', studies);
384 $('li', target).remove();
385
386 for (var i = 0; i < studies.length; i++) {
387 var patient = studies[i].PatientMainDicomTags.PatientName;
388 var study = studies[i].MainDicomTags.StudyDescription;
389
390 var s;
391 if (typeof patient === 'string') {
392 s = patient;
393 }
394
395 if (typeof study === 'string') {
396 if (s.length > 0) {
397 s += ' - ';
398 }
399
400 s += study;
401 }
402
403 studies[i]['Label'] = s;
404 }
405
406 Sort(studies, function(a) { return a.Label }, false, false);
407
408 for (var i = 0; i < studies.length; i++) {
409 var p = FormatStudy(studies[i], '#study?uuid=' + studies[i].ID, false, true);
410 target.append(p);
411 }
412
413 target.listview('refresh');
414 }); 528 });
415 }); 529 });
416 530
417 531
418 532