changeset 5241:efaeec259623 db-protobuf

added labels at the study level in orthanc explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Apr 2023 20:14:59 +0200
parents 178b0434256a
children c60a7fc95f04
files OrthancServer/OrthancExplorer/explorer.css OrthancServer/OrthancExplorer/explorer.js
diffstat 2 files changed, 144 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancExplorer/explorer.css	Wed Apr 05 11:31:05 2023 +0200
+++ b/OrthancServer/OrthancExplorer/explorer.css	Wed Apr 05 20:14:59 2023 +0200
@@ -63,3 +63,22 @@
 .switch-container .ui-slider-switch {
     width: 100%;
 }
+
+.label {
+    display: inline-block;
+    background-color: gray;
+    margin: 5px;
+    padding: 5px;
+    border-radius: 10px;
+}
+
+.label button {
+    background-color: transparent;
+    border: 0px;
+    cursor: pointer;
+    border-radius: 10px;
+}
+
+.label button:hover {
+    background-color: lightgray;
+}
--- a/OrthancServer/OrthancExplorer/explorer.js	Wed Apr 05 11:31:05 2023 +0200
+++ b/OrthancServer/OrthancExplorer/explorer.js	Wed Apr 05 20:14:59 2023 +0200
@@ -65,6 +65,12 @@
 var MODIFIED_FROM = 'ModifiedFrom';
 
 
+function IsAlphanumeric(s)
+{
+  return s.match(/^[0-9a-zA-Z]+$/);
+}
+
+
 function DeepCopy(obj)
 {
   return jQuery.extend(true, {}, obj);
@@ -701,9 +707,82 @@
     }
     target.listview('refresh');
   });
+}
 
+
+
+function RefreshLabels(nodeLabels, resourceLevel, resourceId)
+{
+  GetResource('/' + resourceLevel + '/' + resourceId + '/labels', function(labels) {
+    nodeLabels.empty();
+    
+    if (labels.length > 0) {
+      for (var i = 0; i < labels.length; i++) {
+        var removeButton = $('<button>').text('X').attr('title', 'Remove label "' + labels[i] + '"');
+
+        removeButton.click({
+          label : labels[i],
+          nodeLabels : nodeLabels
+        }, function(s) {
+          $.ajax({
+            url: '../' + resourceLevel + '/' + resourceId + '/labels/' + s.data.label,
+            dataType: 'json',
+            type: 'DELETE',
+            success: function(ss) {
+              RefreshLabels(nodeLabels, resourceLevel, resourceId);
+            }
+          });
+        });
+        
+        nodeLabels.append($('<span>').text(labels[i] + ' ').addClass('label').append(removeButton));
+      }
+    } else {
+      nodeLabels.css('display', 'none');
+    }
+  });
 }
 
+
+function ConfigureLabels(nodeLabels, addLabelButton, resourceLevel, resourceId)
+{
+  RefreshLabels(nodeLabels, resourceLevel, resourceId);
+
+  addLabelButton.click(function(s) {
+    $('#dialog').simpledialog2({
+      mode: 'button',
+      animate: false,
+      headerText: 'Add label',
+      headerClose: true,
+      buttonPrommpt: 'Enter the new label',
+      buttonInput: true,
+      width: '100%',
+      buttons : {
+        'OK': {
+          click: function () {
+            var label = $.mobile.sdLastInput;
+            if (label.length > 0) {
+              if (IsAlphanumeric(label)) {
+                $.ajax({
+                  url: '../' + resourceLevel + '/' + resourceId + '/labels/' + label,
+                  dataType: 'json',
+                  type: 'PUT',
+                  data: '',
+                  success: function(ss) {
+                    RefreshLabels(nodeLabels, resourceLevel, resourceId);
+                  }
+                });
+              } else {
+                alert('Error: Labels can only contain alphanumeric characters');
+              }
+            }
+          }
+        },
+      }
+    });
+  });
+}
+
+
 function RefreshPatient()
 {
   var pageData, target, v;
@@ -771,43 +850,58 @@
   if ($.mobile.pageData) {
     pageData = DeepCopy($.mobile.pageData);
 
-    GetResource('/studies/' + pageData.uuid + '?full', function(study) {
-      GetResource('/patients/' + study.ParentPatient + '?full', function(patient) {
-        GetResource('/studies/' + pageData.uuid + '/series?full', function(series) {
-          SortOnDicomTag(series, SERIES_DATE, false, true);
+    GetResource('/system', function(system) {
+      GetResource('/studies/' + pageData.uuid + '?full', function(study) {
+        GetResource('/patients/' + study.ParentPatient + '?full', function(patient) {
+          GetResource('/studies/' + pageData.uuid + '/series?full', function(series) {
+            SortOnDicomTag(series, SERIES_DATE, false, true);
+            
+            $('#study .patient-link').attr('href', '#patient?uuid=' + patient.ID);
+            $('#study-info li').remove();
 
-          $('#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 info = $('#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));
 
-          SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', ANONYMIZED_FROM);
-          SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', MODIFIED_FROM);
-          SetupAttachments('#study-access', 'study-attachment', pageData.uuid, 'studies');
+            if (system.HasLabels === true) {
+              var nodeLabels = $('<li>').append($('<div>'));
+              var addLabelButton = $('<a>').text('Add label');
+              ConfigureLabels(nodeLabels, addLabelButton, 'studies', study.ID)
+            
+              info
+                .append('<li data-role="list-divider">Labels</li>')
+                .append(nodeLabels)
+                .append($('<li>').attr('data-icon', 'plus').append(addLabelButton));
+            }
+
+            info.listview('refresh');
 
-          target = $('#list-series');
-          $('li', target).remove();
-          for (var i = 0; i < series.length; i++) {
-            if (i == 0 ||
-                GetMainDicomTag(series[i].MainDicomTags, SERIES_DATE) !=
-                GetMainDicomTag(series[i - 1].MainDicomTags, SERIES_DATE))
-            {
-              target.append($('<li>')
-                            .attr('data-role', 'list-divider')
-                            .text(FormatDicomDate(GetMainDicomTag(series[i].MainDicomTags, SERIES_DATE))));
+            SetupAnonymizedOrModifiedFrom('#study-anonymized-from', study, 'study', ANONYMIZED_FROM);
+            SetupAnonymizedOrModifiedFrom('#study-modified-from', study, 'study', MODIFIED_FROM);
+            SetupAttachments('#study-access', 'study-attachment', pageData.uuid, 'studies');
+
+            target = $('#list-series');
+            $('li', target).remove();
+            for (var i = 0; i < series.length; i++) {
+              if (i == 0 ||
+                  GetMainDicomTag(series[i].MainDicomTags, SERIES_DATE) !=
+                  GetMainDicomTag(series[i - 1].MainDicomTags, SERIES_DATE))
+              {
+                target.append($('<li>')
+                              .attr('data-role', 'list-divider')
+                              .text(FormatDicomDate(GetMainDicomTag(series[i].MainDicomTags, SERIES_DATE))));
+              }
+              
+              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 = pageData.uuid;
+            currentPage = 'study';
+            currentUuid = pageData.uuid;
+          });
         });
       });
     });