changeset 2185:115628b0651d default tip

new ScreenshotTemplate configuration
author Alain Mazy <am@orthanc.team>
date Thu, 23 Jan 2025 11:59:11 +0100 (5 weeks ago)
parents fc320529cdc0
children
files Applications/StoneWebViewer/NEWS Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebApplication/configuration.json
diffstat 3 files changed, 79 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/NEWS	Wed Jan 22 15:07:22 2025 +0100
+++ b/Applications/StoneWebViewer/NEWS	Thu Jan 23 11:59:11 2025 +0100
@@ -6,7 +6,10 @@
 * Remember the previous layout when re-opening the viewer.
 * Added a Print button in the PDF viewer toolbar.
 * Added a Download button in the PDF viewer toolbar.
- 
+* New configuration "ScreenshotTemplate" to define the filename of the
+  "download as JPEG" function.  New default value is:
+  "{PatientID}-{PatientName}-{StudyDate}-{SeriesDescription}-{InstanceNumber}-{CurrentFrame}.jpg"
+
 
 Version 2.6 (2024-08-31)
 ========================
--- a/Applications/StoneWebViewer/WebApplication/app.js	Wed Jan 22 15:07:22 2025 +0100
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Thu Jan 23 11:59:11 2025 +0100
@@ -674,7 +674,14 @@
         return null;
       }
     },
-    
+
+    GetActiveViewportVueComponent: function() {
+      if (this.activeViewport >= 1 && this.activeViewport <= 4) {
+        return $('#canvas' + this.activeViewport + '-container')[0].__vue__;
+      }
+      return null;
+    },
+
     GetActiveSeriesInstanceUid: function() {
       var s = [];
 
@@ -1221,7 +1228,58 @@
     DownloadJpeg: function()
     {
       var canvas = document.getElementById(this.GetActiveCanvas());
-      SaveDataUriScheme('StoneWebViewerScreenshot.jpg', canvas.toDataURL('image/jpeg'));
+      var path = 'StoneWebViewerScreenshot.jpg';
+      var viewport = this.GetActiveViewportVueComponent();
+
+      var template = this.globalConfiguration.ScreenshotTemplate;
+      if (template !== undefined && viewport !== undefined) {
+        // var seriesInstanceUid = this.GetActiveSeriesInstanceUid()
+        var activeTags = this.GetActiveSeries().tags;
+        // add instance related values to the dico
+        activeTags['0020,0013'] = viewport.instanceNumber;
+        activeTags['0008,0023'] = viewport.contentDate;
+        activeTags['0008,0033'] = viewport.contentTime;
+
+        activeTags['0028,0008'] = viewport.numberOfFrames;
+        activeTags['ffff,9999'] = viewport.currentFrame + 1;  // current frame is not a DICOM Tag but, let's give it an internal number to standardize the way we substitue values in the template
+
+        // allow using common Tag names in the template instead of group,element:
+        const commonTagsTranslation = {
+          'PatientName': '0010,0010',
+          'PatientID': '0010,0020',
+          'PatientBirthDate': '0010,0030',
+          'PatientSex': '0010,0040',
+          
+          'StudyDate': '0008,0020',
+          'StudyTime': '0008,0030',
+          'AccessionNumber': '0008,0050',
+          'StudyDescription': '0008,1030',
+          'StudyInstanceUID': '0020,000d',
+          
+          'SeriesDate': '0008,0021',
+          'SeriesTime': '0008,0031',
+          'Modality': '0008,0060',
+          'SeriesDescription': '0008,103e',
+          'SeriesInstanceUID': '0020,000e',
+          
+          'InstanceNumber': '0020,0013',
+          'ContentDate': '0008,0023',
+          'ContentTime': '0008,0033',
+          'NumberOfFrames': '0028,0008',
+          'CurrentFrame': 'ffff,9999'
+        }
+
+        // replace common tag names by group,element in the template
+        for (const [symbolicName, numericName] of Object.entries(commonTagsTranslation)) {
+          template = template.replace('{' + symbolicName + '}', '{' + numericName + '}');
+        } 
+        
+        path = template.replace(/{([0-9a-f,]+)}/g, function(match, group1) { return activeTags[group1] || 'undefined'; });
+        console.log('downloading a screenshot with template ', template, ' and tags: ', activeTags, ', final path: ', path);
+      }
+
+      var canvas = document.getElementById(this.GetActiveCanvas());
+      SaveDataUriScheme(path, canvas.toDataURL('image/jpeg'));
     },
 
     SetCombinedToolActions: function()
--- a/Applications/StoneWebViewer/WebApplication/configuration.json	Wed Jan 22 15:07:22 2025 +0100
+++ b/Applications/StoneWebViewer/WebApplication/configuration.json	Thu Jan 23 11:59:11 2025 +0100
@@ -149,6 +149,20 @@
      **/
     "DicomWebHttpHeaders" : {
       /* "Authorization" : "Bearer ${USER}" */
-    }
+    },
+
+
+    /**
+     * Define the the filename of the 'Download as Jpeg' screenshots.
+     * The template can either contain Patient, Study or Series tags 
+     * in the group,element form (e.g. {0008,103e}) or the DICOM tag
+     * common name (e.g. {SeriesDescription}).  A few Instance tags are
+     * also available: {InstanceNumber}, {ContentDate}, {ContentTime}.
+     * {CurrentFrame} is also available although not a DICOM Tag.
+     * (New in Stone Web viewer 2.7).  In prior versions, the filename
+     * was always "StoneWebViewerScreenshot.jpg".
+     **/
+    "ScreenshotTemplate" : "{PatientID}-{PatientName}-{StudyDate}-{SeriesDescription}-{InstanceNumber}-{CurrentFrame}.jpg"
+
   }
 }