From a1b78afdb97c660a985ddedd2181fb635b0f061c Mon Sep 17 00:00:00 2001 From: Erik Ziegler Date: Mon, 27 Jan 2020 10:12:07 +0100 Subject: [PATCH] Add palette color cache object back to core (fix #1350) (#1395) --- .../services/wado/studyInstanceHelpers.js | 38 +++++++++++++++++++ .../lib/localFileLoaders/dicomFileLoader.js | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/platform/core/src/studies/services/wado/studyInstanceHelpers.js b/platform/core/src/studies/services/wado/studyInstanceHelpers.js index dbf318966..69a4bc196 100644 --- a/platform/core/src/studies/services/wado/studyInstanceHelpers.js +++ b/platform/core/src/studies/services/wado/studyInstanceHelpers.js @@ -1,3 +1,4 @@ +import { api } from 'dicomweb-client'; import DICOMWeb from '../../../DICOMWeb'; const WADOProxy = { @@ -21,6 +22,43 @@ function parseFloatArray(obj) { return result; } +/** + * Simple cache schema for retrieved color palettes. + */ +const paletteColorCache = { + count: 0, + maxAge: 24 * 60 * 60 * 1000, // 24h cache? + entries: {}, + isValidUID: function(paletteUID) { + return typeof paletteUID === 'string' && paletteUID.length > 0; + }, + get: function(paletteUID) { + let entry = null; + if (this.entries.hasOwnProperty(paletteUID)) { + entry = this.entries[paletteUID]; + // check how the entry is... + if (Date.now() - entry.time > this.maxAge) { + // entry is too old... remove entry. + delete this.entries[paletteUID]; + this.count--; + entry = null; + } + } + return entry; + }, + add: function(entry) { + if (this.isValidUID(entry.uid)) { + let paletteUID = entry.uid; + if (this.entries.hasOwnProperty(paletteUID) !== true) { + this.count++; // increment cache entry count... + } + entry.time = Date.now(); + this.entries[paletteUID] = entry; + // @TODO: Add logic to get rid of old entries and reduce memory usage... + } + }, +}; + /** * Create a plain JS object that describes a study (a study descriptor object) * @param {Object} server Object with server configuration parameters diff --git a/platform/viewer/src/lib/localFileLoaders/dicomFileLoader.js b/platform/viewer/src/lib/localFileLoaders/dicomFileLoader.js index ba1b20ef2..fa3ef260a 100644 --- a/platform/viewer/src/lib/localFileLoaders/dicomFileLoader.js +++ b/platform/viewer/src/lib/localFileLoaders/dicomFileLoader.js @@ -19,7 +19,7 @@ const DICOMFileLoader = new (class extends FileLoader { dicomData.meta ); } catch (e) { - console.log('Error on getting dicom file dataset. It defaults to empty'); + console.error('Error reading dicom file', e); } // Set imageId on dataset to be consumed later on dataset.imageId = imageId;