@radicalimaging/static-wado-creator 1.3.2 → 1.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +234 -0
  2. package/README.md +1 -1
  3. package/bin/mkdicomweb.mjs +8 -0
  4. package/dist/canvas-xaqc8v6y.node +0 -0
  5. package/dist/index.js +481518 -0
  6. package/lib/DeleteStudy.js +9 -2
  7. package/lib/RejectInstance.js +15 -3
  8. package/lib/StaticWado.js +245 -41
  9. package/lib/createPart10.js +8 -4
  10. package/lib/createThumbnail.js +181 -0
  11. package/lib/index.js +2 -0
  12. package/lib/instanceMain.js +1 -0
  13. package/lib/mkdicomwebConfig.js +122 -19
  14. package/lib/model/TagLists.js +24 -3
  15. package/lib/model/uids.js +5 -1
  16. package/lib/operation/InstanceDeduplicate.js +14 -4
  17. package/lib/operation/ScanStudy.js +38 -5
  18. package/lib/operation/StudyData.js +158 -38
  19. package/lib/operation/ThumbnailService.js +65 -31
  20. package/lib/operation/adapter/decodeImage.js +5 -2
  21. package/lib/operation/adapter/getImageInfo.js +19 -1
  22. package/lib/operation/adapter/transcodeImage.js +174 -52
  23. package/lib/operation/extractImageFrames.js +19 -4
  24. package/lib/operation/getDataSet.js +41 -7
  25. package/lib/operation/getEncapsulatedImageFrame.js +30 -6
  26. package/lib/operation/getUncompressedImageFrame.js +10 -2
  27. package/lib/operation/getVR.js +10 -2
  28. package/lib/operation/getValue.js +40 -12
  29. package/lib/operation/validateMetadata.js +40 -0
  30. package/lib/program/index.js +5 -3
  31. package/lib/serverMain.js +27 -0
  32. package/lib/util/IdCreator.js +32 -6
  33. package/lib/util/adaptProgramOpts.js +1 -1
  34. package/lib/util/compressionOptionParser.js +12 -3
  35. package/lib/util/resultsReport.ts +88 -0
  36. package/lib/writer/CompleteStudyWriter.js +49 -13
  37. package/lib/writer/DeduplicateWriter.js +2 -1
  38. package/lib/writer/ExpandUriPath.js +4 -1
  39. package/lib/writer/HashDataWriter.js +5 -1
  40. package/lib/writer/ImageFrameWriter.js +38 -13
  41. package/lib/writer/RawDicomWriter.js +11 -2
  42. package/lib/writer/VideoWriter.js +19 -7
  43. package/lib/writer/WriteMultipart.js +3 -1
  44. package/lib/writer/WriteStream.js +12 -4
  45. package/lib/writer/static-dicomweb.code-workspace +8 -0
  46. package/package.json +23 -19
  47. package/bin/mkdicomweb.js +0 -9
  48. package/license.md +0 -21
@@ -8,7 +8,9 @@ function decodeUtf8(s, options) {
8
8
  }
9
9
 
10
10
  /** Gets a value as a UTF-8 string - todo, make UTF-8 decode optional. */
11
- const getValueInlineString = (dataSet, attr, options) => [decodeUtf8(dataSet.string(attr.tag), options)];
11
+ const getValueInlineString = (dataSet, attr, options) => [
12
+ decodeUtf8(dataSet.string(attr.tag), options),
13
+ ];
12
14
 
13
15
  const getStrings = (dataSet, attr, options) => {
14
16
  const ret = dataSet.string(attr.tag);
@@ -20,21 +22,27 @@ const getStrings = (dataSet, attr, options) => {
20
22
 
21
23
  const getValuePatientName = (dataSet, attr) => {
22
24
  const strings = getStrings(dataSet, attr);
23
- return (strings && strings.map((item) => ({ Alphabetic: item }))) || undefined;
25
+ return (
26
+ (strings && strings.map((item) => ({ Alphabetic: item }))) || undefined
27
+ );
24
28
  };
25
29
 
26
30
  /** Gets either InlineBinary or BulkDataURI, if already defined */
27
31
  const getValueInlineBinary = (dataSet, attr) => {
28
32
  if (attr.BulkDataURI) return { BulkDataURI: attr.BulkDataURI };
29
- const binaryValue = dataSet.byteArray.slice(attr.dataOffset, attr.dataOffset + attr.length);
33
+ const binaryValue = dataSet.byteArray.slice(
34
+ attr.dataOffset,
35
+ attr.dataOffset + attr.length,
36
+ );
30
37
  return { InlineBinary: binaryValue.toString("base64") };
31
38
  };
32
39
 
33
40
  const getValueInlineSignedShort = (dataSet, attr) => {
34
- if (attr.length > 2) {
35
- return getValueInlineBinary(dataSet, attr);
41
+ const ret = [];
42
+ for (let i = 0; i < attr.length / 2; i++) {
43
+ ret.push(dataSet.int16(attr.tag, i));
36
44
  }
37
- return [dataSet.int16(attr.tag)];
45
+ return ret;
38
46
  };
39
47
 
40
48
  const getValueInlineUnsignedShort = (dataSet, attr) => {
@@ -70,9 +78,11 @@ const getValueInlineFloat = (dataSet, attr) => {
70
78
  return ret;
71
79
  };
72
80
 
73
- const getValueInlineIntString = (dataSet, attr) => getStrings(dataSet, attr).map((val) => parseInt(val));
81
+ const getValueInlineIntString = (dataSet, attr) =>
82
+ getStrings(dataSet, attr).map((val) => parseInt(val));
74
83
 
75
- const getValueInlineFloatString = (dataSet, attr) => getStrings(dataSet, attr).map((val) => parseFloat(val));
84
+ const getValueInlineFloatString = (dataSet, attr) =>
85
+ getStrings(dataSet, attr).map((val) => parseFloat(val));
76
86
 
77
87
  const getValueInlineFloatDouble = (dataSet, attr) => {
78
88
  if (attr.length > 8) {
@@ -177,15 +187,30 @@ const isValueInline = (attr, options) => {
177
187
  * @param {*} parentAttr attr's parent. If not present means attr is at root level.
178
188
  * @returns
179
189
  */
180
- const getValue = async (dataSet, attr, vr, getDataSet, callback, options, parentAttr) => {
190
+ const getValue = async (
191
+ dataSet,
192
+ attr,
193
+ vr,
194
+ getDataSet,
195
+ callback,
196
+ options,
197
+ parentAttr,
198
+ ) => {
181
199
  // It will only process pixelData tag if on metadata root. Otherwise it will be skiped.
182
200
  if (attr.tag === "x7fe00010" && !parentAttr) {
183
- const BulkDataURI = await extractImageFrames(dataSet, attr, vr, callback, options);
201
+ const BulkDataURI = await extractImageFrames(
202
+ dataSet,
203
+ attr,
204
+ vr,
205
+ callback,
206
+ options,
207
+ );
184
208
  return { BulkDataURI };
185
209
  }
186
210
  if (attr.tag === "xfffee00d") return undefined;
187
211
  // Group length
188
- if (attr.tag.length == 9 && attr.tag.substring(5, 9) === "0000") return undefined;
212
+ if (attr.tag.length == 9 && attr.tag.substring(5, 9) === "0000")
213
+ return undefined;
189
214
  if (attr.items) {
190
215
  // sequences
191
216
  const result = [];
@@ -202,7 +227,10 @@ const getValue = async (dataSet, attr, vr, getDataSet, callback, options, parent
202
227
  if (isValueInline(attr, options)) {
203
228
  return getValueInline(dataSet, attr, vr, options);
204
229
  }
205
- const binaryValue = dataSet.byteArray.slice(attr.dataOffset, attr.dataOffset + attr.length);
230
+ const binaryValue = dataSet.byteArray.slice(
231
+ attr.dataOffset,
232
+ attr.dataOffset + attr.length,
233
+ );
206
234
  const mimeType = attr.tag == "x00420011" && dataSet.string("x00420012");
207
235
 
208
236
  const BulkDataURI = await callback.bulkdata(binaryValue, { mimeType });
@@ -0,0 +1,40 @@
1
+ const { Tags } = require("@radicalimaging/static-wado-util");
2
+
3
+ function validateMetadata(options) {
4
+ const serviceUrl = "";
5
+ const { verify, multipart: stowResponse } = options;
6
+
7
+ return function (id, result) {
8
+ const getValue = Tags.getValue.bind(null, result.metadata);
9
+ if (verify) {
10
+ console.verbose("Validating metadata", id);
11
+ if (id.studyInstanceUid.length > 64) {
12
+ throw new Error(`StudyInstanceUID too long: ${id.studyInstanceUid}`);
13
+ }
14
+ if (id.seriesInstanceUid.length > 64) {
15
+ throw new Error(`SeriesInstanceUID too long: ${id.studyInstanceUid}`);
16
+ }
17
+ }
18
+ if (stowResponse) {
19
+ const RetrieveURL = `${serviceUrl}${id.studyInstanceUid}/series/${id.seriesInstanceUid}/instances/${id.sopInstanceUid}`;
20
+
21
+ // TODO - add check here from plugin to add remote query checks, eg kheops or similar
22
+ const { filename } = id;
23
+ const successMessage = {
24
+ ReferencedSOPSequence: [
25
+ {
26
+ StudyInstanceUID: id.studyInstanceUid,
27
+ SeriesInstanceUID: id.seriesInstanceUid,
28
+ ReferencedSOPClassUID: getValue(Tags.SOPClassUID),
29
+ ReferencedSOPInstanceUID: id.sopInstanceUid,
30
+ RetrieveURL,
31
+ StorageURL: filename,
32
+ },
33
+ ],
34
+ };
35
+ this.success("instanceStored", successMessage, filename);
36
+ }
37
+ };
38
+ }
39
+
40
+ module.exports = validateMetadata;
@@ -7,9 +7,11 @@ const staticWadoUtil = require("@radicalimaging/static-wado-util");
7
7
  * @returns Program object
8
8
  */
9
9
  async function configureProgram(defaults) {
10
- const configurationFile = await staticWadoUtil.loadConfiguration(defaults, process.argv);
11
- console.log("Loaded configuration from", configurationFile);
12
- staticWadoUtil.configureCommands(defaults);
10
+ const configurationFile = await staticWadoUtil.loadConfiguration(
11
+ defaults,
12
+ process.argv,
13
+ );
14
+ return staticWadoUtil.configureCommands(defaults);
13
15
  }
14
16
 
15
17
  exports.configureProgram = configureProgram;
@@ -0,0 +1,27 @@
1
+ const readline = require("node:readline");
2
+ const {
3
+ argv,
4
+ argv0,
5
+ exit,
6
+ stdin: input,
7
+ stdout: output,
8
+ } = require("node:process");
9
+
10
+ const StaticWado = require("./StaticWado");
11
+ const adaptProgramOpts = require("./util/adaptProgramOpts");
12
+
13
+ module.exports = async function createMain(options, program) {
14
+ const rl = readline.createInterface({ input, output });
15
+ for await (const line of rl) {
16
+ if (!line) continue;
17
+ if (line.startsWith("exit")) {
18
+ exit(0);
19
+ }
20
+ argv.splice(2, argv.length - 2, ...line.split(" "));
21
+ console.verbose("exec mkdicomweb", JSON.stringify(argv));
22
+
23
+ // Configure program commander
24
+ await StaticWado.configureProgram(StaticWado.mkdicomwebConfig);
25
+ output.write("mkdicomweb server -->\n");
26
+ }
27
+ };
@@ -1,14 +1,40 @@
1
1
  const path = require("path");
2
+ const {
3
+ getStudyUIDPathAndSubPath,
4
+ } = require("@radicalimaging/static-wado-util");
2
5
 
3
- function IdCreator({ directoryName, deduplicatedRoot, deduplicatedInstancesRoot }) {
6
+ function IdCreator({
7
+ directoryName,
8
+ deduplicatedRoot,
9
+ deduplicatedInstancesRoot,
10
+ hashStudyUidPath,
11
+ }) {
4
12
  return (uids, filename) => {
5
- const studyPath = path.join(directoryName, "studies", uids.studyInstanceUid);
6
- const seriesRootPath = path.join(studyPath, "series", uids.seriesInstanceUid);
7
- const sopInstanceRootPath = path.join(studyPath, "series", uids.seriesInstanceUid, "instances", uids.sopInstanceUid);
8
- const deduplicatedPath = path.join(deduplicatedRoot, uids.studyInstanceUid);
9
- const deduplicatedInstancesPath = path.join(deduplicatedInstancesRoot, uids.studyInstanceUid);
13
+ const { studyInstanceUid, seriesInstanceUid, sopInstanceUid } = uids;
14
+
15
+ const { path: hashPath = "", subpath: hashSubpath = "" } = hashStudyUidPath
16
+ ? getStudyUIDPathAndSubPath(studyInstanceUid)
17
+ : {};
18
+
19
+ const studySubDir = hashStudyUidPath
20
+ ? path.join(hashPath, hashSubpath, studyInstanceUid)
21
+ : studyInstanceUid;
22
+
23
+ const studyPath = path.join(directoryName, "studies", studySubDir);
24
+ const seriesRootPath = path.join(studyPath, "series", seriesInstanceUid);
25
+ const sopInstanceRootPath = path.join(
26
+ seriesRootPath,
27
+ "instances",
28
+ sopInstanceUid,
29
+ );
10
30
  const imageFrameRootPath = path.join(sopInstanceRootPath, "frames");
11
31
 
32
+ const deduplicatedPath = path.join(deduplicatedRoot, studySubDir);
33
+ const deduplicatedInstancesPath = path.join(
34
+ deduplicatedInstancesRoot,
35
+ studySubDir,
36
+ );
37
+
12
38
  return {
13
39
  ...uids,
14
40
  studyPath,
@@ -34,6 +34,6 @@ module.exports = function adaptProgramOpts(programOpts, defaults) {
34
34
  encapsulatedImage: encapsulatedImage ?? singlePartImage !== true,
35
35
  singlePartImage: singlePartImage ?? encapsulatedImage === false,
36
36
  delete: deleteInstances,
37
- }
37
+ },
38
38
  );
39
39
  };
@@ -1,13 +1,22 @@
1
1
  const { program } = require("@radicalimaging/static-wado-util");
2
- const { getDestinationTranscoder } = require("../operation/adapter/transcodeImage");
2
+ const {
3
+ getDestinationTranscoder,
4
+ } = require("../operation/adapter/transcodeImage");
3
5
 
4
6
  module.exports = function compressionOptionParser(value) {
5
7
  const destination = getDestinationTranscoder(value);
6
8
  if (destination) {
7
- console.log("Found destination transferSyntax ", destination.transferSyntaxUid, "for ", value);
9
+ console.log(
10
+ "Found destination transferSyntax ",
11
+ destination.transferSyntaxUid,
12
+ "for ",
13
+ value,
14
+ );
8
15
  } else {
9
16
  console.log("No transcoder destination for ", value);
10
- throw new program.InvalidArgumentError(`No transcoder destination for ${value}`);
17
+ throw new program.InvalidArgumentError(
18
+ `No transcoder destination for ${value}`,
19
+ );
11
20
  }
12
21
  return destination.transferSyntaxUid;
13
22
  };
@@ -0,0 +1,88 @@
1
+ import fs from "fs";
2
+
3
+ const results = [];
4
+ let sopResponse = null;
5
+
6
+ function ensureSOPResponse(data) {
7
+ if( !data.ReferencedSOPSequence && !data.FailedSOPSequence ) {
8
+ return;
9
+ }
10
+ if( !sopResponse ) {
11
+ sopResponse = {
12
+ ...data,
13
+ FailedSOPSequence: undefined,
14
+ ReferencedSOPSequence: undefined,
15
+ }
16
+ results.push(sopResponse);
17
+ }
18
+ if( data.ReferencedSOPSequence ) {
19
+ sopResponse.ReferencedSOPSequence ||= [];
20
+ sopResponse.ReferencedSOPSequence.push(...data.ReferencedSOPSequence);
21
+ }
22
+ if( data.FailedSOPSequence ) {
23
+ sopResponse.FailedSOPSequence ||= [];
24
+ sopResponse.FailedSOPSequence.push(...data.FailedSOPSequence);
25
+ }
26
+
27
+ }
28
+ export function Success(options) {
29
+ const { deleteInput = false } = options;
30
+
31
+ return (_action, data, file) => {
32
+ if( data.ReferencedSOPSequence ) {
33
+ ensureSOPResponse(data);
34
+ } else {
35
+ results.push(data);
36
+ }
37
+ if (file && deleteInput) {
38
+ console.noQuiet("Deleting", file);
39
+ fs.unlinkSync(file);
40
+ } else if( file ) {
41
+ console.verbose("Not deleting", file);
42
+ }
43
+ };
44
+ }
45
+
46
+ export function Failure(options) {
47
+ const { deleteFailed } = options;
48
+
49
+ return (_action, data, file) => {
50
+ if (data.FailedSOPSequence) {
51
+ ensureSOPResponse(data);
52
+ } else {
53
+ results.push(data);
54
+ }
55
+ if( file && deleteFailed ) {
56
+ console.noQuiet("Deleting failure", file);
57
+ fs.unlinkSync(file);
58
+ } else if( file ) {
59
+ console.verbose("Not deleting failure file", file);
60
+ }
61
+ };
62
+ }
63
+
64
+ export function clearResults() {
65
+ results.splice(0,results.length);
66
+ sopResponse = null;
67
+ }
68
+
69
+ export function WriteResults(options) {
70
+ const { multipart } = options;
71
+
72
+ return function () {
73
+ if (multipart) {
74
+ const str =
75
+ results.length === 1
76
+ ? JSON.stringify(results[0])
77
+ : `[\n${results.map((r) => JSON.stringify(r, null, 2)).join(",\n")}\n]`;
78
+ console.log(
79
+ "\r\n--boundary-response\r\n" +
80
+ "content-type: application/json\r\n\r\n" +
81
+ str +
82
+ "\r\n--boundary-response--\r\n"
83
+ );
84
+ }
85
+
86
+ clearResults();
87
+ };
88
+ }
@@ -1,4 +1,8 @@
1
- const { JSONReader, JSONWriter, Stats } = require("@radicalimaging/static-wado-util");
1
+ const {
2
+ JSONReader,
3
+ JSONWriter,
4
+ Stats,
5
+ } = require("@radicalimaging/static-wado-util");
2
6
  const { Tags } = require("@radicalimaging/static-wado-util");
3
7
  const StudyData = require("../operation/StudyData");
4
8
 
@@ -22,48 +26,77 @@ const CompleteStudyWriter = (options) => {
22
26
  if (options.isGroup) {
23
27
  if (studyData.dirty) {
24
28
  await studyData.writeDeduplicatedGroup();
25
- console.log("Wrote updated deduplicated data for study", studyData.studyInstanceUid);
29
+ console.noQuiet(
30
+ "Wrote updated deduplicated data for study",
31
+ studyData.studyInstanceUid,
32
+ );
26
33
  } else {
27
- console.log("Not writing new deduplicated data because it is clean:", studyData.studyInstanceUid);
34
+ console.noQuiet(
35
+ "Not writing new deduplicated data because it is clean:",
36
+ studyData.studyInstanceUid,
37
+ );
38
+ const message = {
39
+ text: "Metadata clean, not updating",
40
+ status: 0,
41
+ studyInstanceUid: studyData.studyInstanceUid,
42
+ };
43
+ this.success("metadataClean", message);
28
44
  }
29
45
  await studyData.deleteInstancesReferenced();
30
46
  }
31
47
 
32
48
  if (!options.isStudyData) {
33
- console.verbose("Not configured to write study metadata", studyData.studyInstanceUid);
34
- if (options.notifications) this.notificationService.notifyStudy(studyData.studyInstanceUid);
49
+ if (options.notifications)
50
+ this.notificationService.notifyStudy(studyData.studyInstanceUid);
35
51
  delete this.studyData;
36
52
  Stats.StudyStats.summarize();
37
53
  return;
38
54
  }
39
55
 
40
56
  const isDirtyMetadata = await studyData.dirtyMetadata();
41
- if (!isDirtyMetadata) {
57
+ if (!isDirtyMetadata && !options.force) {
42
58
  console.log("Study metadata", studyData.studyInstanceUid, "is clean.");
43
59
  delete this.studyData;
44
- Stats.StudyStats.summarize(`Study metadata ${studyData.studyInstanceUid} has clean metadata, not writing`);
60
+ Stats.StudyStats.summarize(
61
+ `Study metadata ${studyData.studyInstanceUid} has clean metadata, not writing`,
62
+ );
45
63
  return;
46
64
  }
47
- console.log("Writing study metadata", studyData.studyInstanceUid);
65
+ console.noQuiet("Writing study metadata", studyData.studyInstanceUid);
48
66
 
49
67
  const studyQuery = await studyData.writeMetadata();
50
68
 
51
- const allStudies = await JSONReader(options.directoryName, "studies/index.json.gz", []);
69
+ const allStudies = await JSONReader(
70
+ options.directoryName,
71
+ "studies/index.json.gz",
72
+ [],
73
+ );
52
74
  const studyUID = Tags.getValue(studyQuery, Tags.StudyInstanceUID);
53
75
  if (!studyUID) {
54
76
  console.error("studyQuery=", studyQuery);
55
77
  throw new Error("Study query has null studyUID");
56
78
  }
57
- const studyIndex = allStudies.findIndex((item) => Tags.getValue(item, Tags.StudyInstanceUID) == studyUID);
79
+ const studyIndex = allStudies.findIndex(
80
+ (item) => Tags.getValue(item, Tags.StudyInstanceUID) == studyUID,
81
+ );
58
82
  if (studyIndex == -1) {
59
83
  allStudies.push(studyQuery);
60
84
  } else {
61
85
  allStudies[studyIndex] = studyQuery;
62
86
  }
63
87
  await JSONWriter(options.directoryName, "studies", allStudies);
64
- if (options.notifications) this.notificationService.notifyStudy(studyData.studyInstanceUid);
88
+ if (options.notifications)
89
+ this.notificationService.notifyStudy(studyData.studyInstanceUid);
90
+ const message = {
91
+ action: "metadata",
92
+ status: 0,
93
+ studyInstanceUid: studyData.studyInstanceUid,
94
+ };
95
+ this.success("completeStudyWriter", message);
65
96
  delete this.studyData;
66
- Stats.StudyStats.summarize(`Wrote study metadata/query files for ${studyData.studyInstanceUid}`);
97
+ Stats.StudyStats.summarize(
98
+ `Wrote study metadata/query files for ${studyData.studyInstanceUid}`,
99
+ );
67
100
  }
68
101
 
69
102
  /**
@@ -81,7 +114,10 @@ const CompleteStudyWriter = (options) => {
81
114
  await callback.completeStudy(studyData);
82
115
  }
83
116
  callback.setStudyData(new StudyData(id, options));
84
- await callback.studyData.init(options);
117
+ if (!options.isSkipStudyScan) {
118
+ console.verbose("Initiate StudyData");
119
+ await callback.studyData.init(options);
120
+ }
85
121
  return callback.studyData;
86
122
  };
87
123
 
@@ -24,7 +24,8 @@ const DeduplicateWriter = (options) =>
24
24
  const studyData = await this.completeStudy.getCurrentStudyData(this, id);
25
25
 
26
26
  if (options.isDeduplicate) {
27
- if (options.verbose) console.log("Writing single instance", id.studyInstanceUid);
27
+ if (options.verbose)
28
+ console.log("Writing single instance", id.studyInstanceUid);
28
29
  await perInstanceWriter(id, data);
29
30
  } else if (options.verbose) {
30
31
  console.log("Not writing single instance deduplicated");
@@ -8,7 +8,10 @@ const ExpandUriPath = (id, path, options) => {
8
8
  }
9
9
  expandedRelative = `studies/${id.studyInstanceUid}/${expandedRelativeSeries}`;
10
10
  }
11
- if (options.verbose) console.log(`Expanded path returned: ${prependBulkDataUri}${expandedRelative}${path}`);
11
+ if (options.verbose)
12
+ console.log(
13
+ `Expanded path returned: ${prependBulkDataUri}${expandedRelative}${path}`,
14
+ );
12
15
  return `${prependBulkDataUri}${expandedRelative}${path}`;
13
16
  };
14
17
 
@@ -43,7 +43,11 @@ const HashDataWriter =
43
43
  gzip,
44
44
  });
45
45
  if (isRaw) {
46
- await WriteMultipart(writeStream, [new MultipartHeader("Content-Type", "application/octet-stream")], rawData);
46
+ await WriteMultipart(
47
+ writeStream,
48
+ [new MultipartHeader("Content-Type", "application/octet-stream")],
49
+ rawData,
50
+ );
47
51
  } else {
48
52
  await writeStream.write(rawData);
49
53
  }
@@ -18,29 +18,54 @@ const ImageFrameWriter = (options) => {
18
18
  }
19
19
 
20
20
  if (encapsulatedImage || !extension) {
21
- const writeStream = WriteStream(id.imageFrameRootPath, `${1 + index}.mht`, {
22
- gzip: type.gzip,
23
- mkdir: true,
24
- });
21
+ const writeStream = WriteStream(
22
+ id.imageFrameRootPath,
23
+ `${1 + index}.mht`,
24
+ {
25
+ gzip: type.gzip,
26
+ mkdir: true,
27
+ },
28
+ );
25
29
  await WriteMultipart(
26
30
  writeStream,
27
- [new MultipartHeader("Content-Type", type.contentType, [new MultipartAttribute("transfer-syntax", transferSyntaxUid)])],
28
- content
31
+ [
32
+ new MultipartHeader("Content-Type", type.contentType, [
33
+ new MultipartAttribute("transfer-syntax", transferSyntaxUid),
34
+ ]),
35
+ ],
36
+ content,
29
37
  );
30
38
  await writeStream.close();
31
- console.verbose("Wrote encapsulated image frame", id.sopInstanceUid, index + 1, type.contentType);
39
+ console.verbose(
40
+ "Wrote encapsulated image frame",
41
+ id.sopInstanceUid,
42
+ index + 1,
43
+ type.contentType,
44
+ );
32
45
  }
33
46
  if (extension && singlePartImage) {
34
- const writeStreamSingle = WriteStream(id.imageFrameRootPath, `${1 + index}${extension}`, {
35
- gzip: type.gzip,
36
- mkdir: true,
37
- });
47
+ const writeStreamSingle = WriteStream(
48
+ id.imageFrameRootPath,
49
+ `${1 + index}${extension}`,
50
+ {
51
+ gzip: type.gzip,
52
+ mkdir: true,
53
+ },
54
+ );
38
55
  await writeStreamSingle.write(content);
39
56
  await writeStreamSingle.close();
40
- console.verbose("Wrote single part image frame", id.sopInstanceUid, index + 1, extension);
57
+ console.verbose(
58
+ "Wrote single part image frame",
59
+ id.sopInstanceUid,
60
+ index + 1,
61
+ extension,
62
+ );
41
63
  }
42
64
  const includeSeries = true;
43
- return ExpandUriPath(id, `instances/${id.sopInstanceUid}/frames`, { includeSeries, ...options });
65
+ return ExpandUriPath(id, `instances/${id.sopInstanceUid}/frames`, {
66
+ includeSeries,
67
+ ...options,
68
+ });
44
69
  };
45
70
  };
46
71
 
@@ -4,10 +4,15 @@ const WriteMultipart = require("./WriteMultipart");
4
4
  const { MultipartHeader } = require("./MultipartHeader");
5
5
 
6
6
  const modalitiesToRawWrite = ["SEG", "SR"];
7
+ const sopClassesToRawWrite = ["1.2.840.10008.5.1.4.1.1.30"];
7
8
 
8
9
  const defaultSelector = (instance) => {
9
10
  const modality = instance.metadata[Tags.Modality]?.Value?.[0];
10
- return modalitiesToRawWrite.indexOf(modality) !== -1;
11
+ const sopClass = instance.metadata[Tags.SOPClassUID]?.Value?.[0];
12
+ return (
13
+ modalitiesToRawWrite.indexOf(modality) !== -1 ||
14
+ sopClassesToRawWrite.indexOf(sopClass) !== -1
15
+ );
11
16
  };
12
17
 
13
18
  /** Writes out raw DICOM files, encapsulated in multipart and gzipped - currently just DICOM SR and SEG */
@@ -28,7 +33,11 @@ const RawDicomWriter =
28
33
  });
29
34
  const { length } = content;
30
35
  const buffer = content.slice(0, length);
31
- await WriteMultipart(writeStream, [new MultipartHeader("Content-Type", contentType, [])], buffer);
36
+ await WriteMultipart(
37
+ writeStream,
38
+ [new MultipartHeader("Content-Type", contentType, [])],
39
+ buffer,
40
+ );
32
41
  await writeStream.close();
33
42
  };
34
43
  RawDicomWriter.defaultSelector = defaultSelector;
@@ -19,16 +19,23 @@ const VIDEO_TYPES = {
19
19
  // TODO - add the new multi-segment MPEG2 and H264 variants
20
20
  };
21
21
 
22
- const isVideo = (value) => VIDEO_TYPES[value && value.string ? value.string(Tags.RawTransferSyntaxUID) : value];
22
+ const isVideo = (value) =>
23
+ VIDEO_TYPES[
24
+ value && value.string ? value.string(Tags.RawTransferSyntaxUID) : value
25
+ ];
23
26
 
24
27
  const VideoWriter = () =>
25
28
  async function run(id, dataSet) {
26
29
  console.log(`Writing video ${id.sopInstanceUid}`);
27
30
  const extension = VIDEO_TYPES[dataSet.string(Tags.RawTransferSyntaxUID)];
28
31
  const filename = `index.${extension}`;
29
- const writeStream = WriteStream(`${id.sopInstanceRootPath}/rendered`, filename, {
30
- mkdir: true,
31
- });
32
+ const writeStream = WriteStream(
33
+ `${id.sopInstanceRootPath}/rendered`,
34
+ filename,
35
+ {
36
+ mkdir: true,
37
+ },
38
+ );
32
39
  let length = 0;
33
40
  const { fragments } = dataSet.elements.x7fe00010;
34
41
 
@@ -39,13 +46,18 @@ const VideoWriter = () =>
39
46
  // The zero position fragment isn't available, even though present in the original data
40
47
  for (let i = 0; i < fragments.length; i++) {
41
48
  const fragment = fragments[i];
42
- const blob = dataSet.byteArray.slice(fragment.position, fragment.position + fragment.length);
49
+ const blob = dataSet.byteArray.slice(
50
+ fragment.position,
51
+ fragment.position + fragment.length,
52
+ );
43
53
  length += blob.length;
44
54
  await writeStream.write(blob);
45
55
  }
46
56
  await writeStream.close();
47
- console.log(`Done video ${id.sopInstanceRootPath}\\${filename} of length ${length}`);
48
- return `series/${id.seriesInstanceUid}/instances/${id.sopInstanceUid}/pixeldata.${extension}?length=${length}&offset=0`;
57
+ console.log(
58
+ `Done video ${id.sopInstanceRootPath}\\${filename} of length ${length}`,
59
+ );
60
+ return `series/${id.seriesInstanceUid}/instances/${id.sopInstanceUid}/rendered?length=${length}&offset=0&accept=video/mp4`;
49
61
  };
50
62
 
51
63
  module.exports = VideoWriter;
@@ -9,7 +9,9 @@ const WriteMultipart = async (writeStream, headers, content) => {
9
9
  if (header.attributes) {
10
10
  for (let j = 0; j < header.attributes.length; j++) {
11
11
  const attribute = header.attributes[j];
12
- await writeStream.write(`;${attribute.attributeName}=${attribute.attributeValue}`);
12
+ await writeStream.write(
13
+ `;${attribute.attributeName}=${attribute.attributeValue}`,
14
+ );
13
15
  }
14
16
  }
15
17
  await writeStream.write("\r\n");