Skip to content

Commit 2174d5e

Browse files
committed
Apply Alireza review
1 parent 6567df0 commit 2174d5e

File tree

9 files changed

+130
-81
lines changed

9 files changed

+130
-81
lines changed

src/imageLoader/wadors/getPixelData.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,24 @@ function assertMediaTypeIsValid(mediaType) {
5757
}
5858

5959
/**
60-
* Parses media type and extracts its type and subtype.
60+
* Builds an accept header field value for HTTP GET multipart request messages.
6161
*
62-
* @param mediaType e.g. image/jpeg
63-
* @private
64-
*/
65-
function parseMediaType(mediaType) {
66-
assertMediaTypeIsValid(mediaType);
67-
68-
return mediaType.split('/');
69-
}
70-
71-
/**
72-
* Builds an accept header field value for HTTP GET multipart request
73-
messages.
62+
* Takes in input a media types array of type [{mediaType, transferSyntaxUID}, ... ],
63+
* cross-compares with a map defining the supported media types per transferSyntaxUID
64+
* and finally composes a string for the accept header field value as in example below:
65+
*
66+
* "multipart/related; type="image/x-dicom-rle"; transfer-syntax=1.2.840.10008.1.2.5,
67+
* multipart/related; type="image/jpeg"; transfer-syntax=1.2.840.10008.1.2.4.50,
68+
* multipart/related; type="application/octet-stream"; transfer-syntax=*"
69+
*
70+
* NOTE: the xhr request will try to fetch with all the transfer-syntax syntaxes
71+
* specified in the accept header field value in descending order.
72+
* The first element ("image/x-dicom-rle" in this example) has the highest priority.
7473
*
7574
* @param {Array} mediaTypes Acceptable media types
7675
* @param {Object} supportedMediaTypes Supported media types
76+
*
77+
* @returns {string} accept header field value
7778
*/
7879

7980
function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
@@ -87,6 +88,12 @@ function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
8788
);
8889
}
8990

91+
const supportedMediaTypesArray = Object.values(supportedMediaTypes).flat(1);
92+
93+
supportedMediaTypesArray.forEach((supportedMediaType) => {
94+
assertMediaTypeIsValid(supportedMediaType);
95+
});
96+
9097
const fieldValueParts = [];
9198

9299
mediaTypes.forEach((item) => {
@@ -96,9 +103,9 @@ function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
96103

97104
let fieldValue = `multipart/related; type="${mediaType}"`;
98105

99-
// SupportedMediaTypes is a lookup table that maps Transfer Syntax UID
106+
// supportedMediaTypesArray is a lookup table that maps Transfer Syntax UID
100107
// to one or more Media Types
101-
if (!Object.values(supportedMediaTypes).flat(1).includes(mediaType)) {
108+
if (!supportedMediaTypesArray.includes(mediaType)) {
102109
if (
103110
(!mediaType.endsWith('/*') || !mediaType.endsWith('/')) &&
104111
mediaType !== 'application/octet-stream'
@@ -118,10 +125,10 @@ function buildMultipartAcceptHeaderFieldValue(mediaTypes, supportedMediaTypes) {
118125
const expectedMediaTypes = supportedMediaTypes[transferSyntaxUID];
119126

120127
if (!expectedMediaTypes.includes(mediaType)) {
121-
const actualType = parseMediaType(mediaType)[0];
128+
const actualType = mediaType.split('/')[0];
122129

123130
expectedMediaTypes.map((expectedMediaType) => {
124-
const expectedType = parseMediaType(expectedMediaType)[0];
131+
const expectedType = expectedMediaType.split('/')[0];
125132

126133
const haveSameType = actualType === expectedType;
127134

@@ -169,6 +176,8 @@ function getPixelData(uri, imageId, mediaTypes) {
169176
),
170177
};
171178

179+
console.info('bellla', headers);
180+
172181
return new Promise((resolve, reject) => {
173182
const loadPromise = xhrRequest(uri, imageId, headers);
174183

src/imageLoader/wadors/loadImage.js

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import external from '../../externalModules.js';
22
import getPixelData from './getPixelData.js';
33
import createImage from '../createImage.js';
4-
4+
import { mediaTypes } from '../../shared/mediaTypes/mediaTypes.js';
55
/**
66
* Helper method to extract the transfer-syntax from the response of the server.
77
* @param {string} contentType The value of the content-type header as returned by the WADO-RS server.
@@ -72,69 +72,6 @@ function loadImage(imageId, options = {}) {
7272
const promise = new Promise((resolve, reject) => {
7373
// TODO: load bulk data items that we might need
7474

75-
const xdicomrleMediaType = 'image/x-dicom-rle';
76-
const xdicomrleTransferSyntaxUID = '1.2.840.10008.1.2.5';
77-
const jpegMediaType = 'image/jpeg';
78-
const jpegTransferSyntaxUID1 = '1.2.840.10008.1.2.4.50';
79-
const jpegTransferSyntaxUID2 = '1.2.840.10008.1.2.4.51';
80-
const jpegTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.57';
81-
const jllMediaType = 'image/jll';
82-
const jlllTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.70';
83-
const jlsMediaType = 'image/jls';
84-
const jlsTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.80';
85-
const jlsTransferSyntaxUID = '1.2.840.10008.1.2.4.81';
86-
const jp2MediaType = 'image/jp2';
87-
const jp2TransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.90';
88-
const jp2TransferSyntaxUID = '1.2.840.10008.1.2.4.91';
89-
const octetStreamMediaType = 'application/octet-stream';
90-
const octetStreamTransferSyntaxUID = '*';
91-
const mediaTypes = [];
92-
93-
mediaTypes.push(
94-
...[
95-
{
96-
mediaType: xdicomrleMediaType,
97-
transferSyntaxUID: xdicomrleTransferSyntaxUID,
98-
},
99-
{
100-
mediaType: jpegMediaType,
101-
transferSyntaxUID: jpegTransferSyntaxUID1,
102-
},
103-
{
104-
mediaType: jpegMediaType,
105-
transferSyntaxUID: jpegTransferSyntaxUID2,
106-
},
107-
{
108-
mediaType: jpegMediaType,
109-
transferSyntaxUID: jpegTransferSyntaxUIDlossless,
110-
},
111-
{
112-
mediaType: jllMediaType,
113-
transferSyntaxUID: jlllTransferSyntaxUIDlossless,
114-
},
115-
{
116-
mediaType: jlsMediaType,
117-
transferSyntaxUID: jlsTransferSyntaxUIDlossless,
118-
},
119-
{
120-
mediaType: jlsMediaType,
121-
transferSyntaxUID: jlsTransferSyntaxUID,
122-
},
123-
{
124-
mediaType: jp2MediaType,
125-
transferSyntaxUID: jp2TransferSyntaxUIDlossless,
126-
},
127-
{
128-
mediaType: jp2MediaType,
129-
transferSyntaxUID: jp2TransferSyntaxUID,
130-
},
131-
{
132-
mediaType: octetStreamMediaType,
133-
transferSyntaxUID: octetStreamTransferSyntaxUID,
134-
},
135-
]
136-
);
137-
13875
function sendXHR(imageURI, imageId, mediaTypes) {
13976
// get the pixel data from the server
14077
return getPixelData(imageURI, imageId, mediaTypes)

src/shared/mediaTypes/jll.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const jllMediaType = 'image/jll';
2+
const jllTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.70';
3+
4+
export { jllMediaType, jllTransferSyntaxUIDlossless };

src/shared/mediaTypes/jls.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const jlsMediaType = 'image/jls';
2+
const jlsTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.80';
3+
const jlsTransferSyntaxUID = '1.2.840.10008.1.2.4.81';
4+
5+
export { jlsMediaType, jlsTransferSyntaxUIDlossless, jlsTransferSyntaxUID };

src/shared/mediaTypes/jp2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const jp2MediaType = 'image/jp2';
2+
const jp2TransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.90';
3+
const jp2TransferSyntaxUID = '1.2.840.10008.1.2.4.91';
4+
5+
export { jp2MediaType, jp2TransferSyntaxUIDlossless, jp2TransferSyntaxUID };

src/shared/mediaTypes/jpeg.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const jpegMediaType = 'image/jpeg';
2+
const jpegTransferSyntaxUIDlossy1 = '1.2.840.10008.1.2.4.50';
3+
const jpegTransferSyntaxUIDlossy2 = '1.2.840.10008.1.2.4.51';
4+
const jpegTransferSyntaxUIDlossless = '1.2.840.10008.1.2.4.57';
5+
6+
export {
7+
jpegMediaType,
8+
jpegTransferSyntaxUIDlossy1,
9+
jpegTransferSyntaxUIDlossy2,
10+
jpegTransferSyntaxUIDlossless,
11+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { xdicomrleMediaType, xdicomrleTransferSyntaxUID } from './xdicomrle.js';
2+
import {
3+
jpegMediaType,
4+
jpegTransferSyntaxUIDlossy1,
5+
jpegTransferSyntaxUIDlossy2,
6+
jpegTransferSyntaxUIDlossless,
7+
} from './jpeg.js';
8+
import { jllMediaType, jllTransferSyntaxUIDlossless } from './jll.js';
9+
import {
10+
jlsMediaType,
11+
jlsTransferSyntaxUID,
12+
jlsTransferSyntaxUIDlossless,
13+
} from './jls.js';
14+
import {
15+
jp2MediaType,
16+
jp2TransferSyntaxUID,
17+
jp2TransferSyntaxUIDlossless,
18+
} from './jp2.js';
19+
import {
20+
octetStreamMediaType,
21+
octetStreamTransferSyntaxUID,
22+
} from './octetStream.js';
23+
24+
// NOTE: the position of the elements in the array indicates the mediaType
25+
// priority when fetching an image. An element at the beginning of the array
26+
// has the highest priority.
27+
const mediaTypes = [
28+
{
29+
mediaType: xdicomrleMediaType,
30+
transferSyntaxUID: xdicomrleTransferSyntaxUID,
31+
},
32+
{
33+
mediaType: jpegMediaType,
34+
transferSyntaxUID: jpegTransferSyntaxUIDlossy1,
35+
},
36+
{
37+
mediaType: jpegMediaType,
38+
transferSyntaxUID: jpegTransferSyntaxUIDlossy2,
39+
},
40+
{
41+
mediaType: jpegMediaType,
42+
transferSyntaxUID: jpegTransferSyntaxUIDlossless,
43+
},
44+
{
45+
mediaType: jllMediaType,
46+
transferSyntaxUID: jllTransferSyntaxUIDlossless,
47+
},
48+
{
49+
mediaType: jlsMediaType,
50+
transferSyntaxUID: jlsTransferSyntaxUIDlossless,
51+
},
52+
{
53+
mediaType: jlsMediaType,
54+
transferSyntaxUID: jlsTransferSyntaxUID,
55+
},
56+
{
57+
mediaType: jp2MediaType,
58+
transferSyntaxUID: jp2TransferSyntaxUIDlossless,
59+
},
60+
{
61+
mediaType: jp2MediaType,
62+
transferSyntaxUID: jp2TransferSyntaxUID,
63+
},
64+
{
65+
mediaType: octetStreamMediaType,
66+
transferSyntaxUID: octetStreamTransferSyntaxUID,
67+
},
68+
];
69+
70+
export { mediaTypes };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const octetStreamMediaType = 'application/octet-stream';
2+
const octetStreamTransferSyntaxUID = '*';
3+
4+
export { octetStreamMediaType, octetStreamTransferSyntaxUID };

src/shared/mediaTypes/xdicomrle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const xdicomrleMediaType = 'image/x-dicom-rle';
2+
const xdicomrleTransferSyntaxUID = '1.2.840.10008.1.2.5';
3+
4+
export { xdicomrleMediaType, xdicomrleTransferSyntaxUID };

0 commit comments

Comments
 (0)