Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions extensions/default/src/DicomWebDataSource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export type DicomWebConfig = {
staticWado?: boolean;
/** User authentication service */
userAuthenticationService: Record<string, unknown>;
/** Additional request options for DICOMweb requests */
requestOptions?: {
headers?: HeadersInterface;
};
};

export type BulkDataURIConfig = {
Expand Down Expand Up @@ -126,6 +130,8 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
qidoDicomWebClient,
wadoDicomWebClient,
getAuthorizationHeader,
getCustomHeaders,
getBaseHeaders,
generateWadoHeader;
// Default to enabling bulk data retrieves, with no other customization as
// this is part of hte base standard.
Expand All @@ -150,13 +156,19 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
}
return xhrRequestHeaders;
};
getCustomHeaders = () => dicomWebConfig.requestOptions?.headers || {};
getBaseHeaders = () => ({
...getCustomHeaders(),
...getAuthorizationHeader(),
});

/**
* Generates the wado header for requesting resources from DICOMweb.
* These are classified into those that are dependent on the transfer syntax
* and those that aren't, as defined by the include transfer syntax attribute.
*/
generateWadoHeader = (options: HeaderOptions): HeadersInterface => {
const customHeaders = getCustomHeaders();
const authorizationHeader = getAuthorizationHeader();
if (options?.includeTransferSyntax!==false) {
//Generate accept header depending on config params
Expand All @@ -166,6 +178,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
dicomWebConfig.omitQuotationForMultipartRequest
);
return {
...customHeaders,
...authorizationHeader,
Accept: formattedAcceptHeader,
};
Expand All @@ -175,6 +188,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
// which the server expects Accept: application/dicom+json will still include that in the
// header.
return {
...customHeaders,
...authorizationHeader
};
}
Expand All @@ -184,7 +198,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
url: dicomWebConfig.qidoRoot,
staticWado: dicomWebConfig.staticWado,
singlepart: dicomWebConfig.singlepart,
headers: userAuthenticationService.getAuthorizationHeader(),
headers: getBaseHeaders(),
errorInterceptor: errorHandler.getHTTPErrorHandler(),
supportsFuzzyMatching: dicomWebConfig.supportsFuzzyMatching,
};
Expand All @@ -193,7 +207,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
url: dicomWebConfig.wadoRoot,
staticWado: dicomWebConfig.staticWado,
singlepart: dicomWebConfig.singlepart,
headers: userAuthenticationService.getAuthorizationHeader(),
headers: getBaseHeaders(),
errorInterceptor: errorHandler.getHTTPErrorHandler(),
supportsFuzzyMatching: dicomWebConfig.supportsFuzzyMatching,
};
Expand All @@ -212,7 +226,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
studies: {
mapParams: mapParams.bind(),
search: async function (origParams) {
qidoDicomWebClient.headers = getAuthorizationHeader();
qidoDicomWebClient.headers = getBaseHeaders();
const { studyInstanceUid, seriesInstanceUid, ...mappedParams } =
mapParams(origParams, {
supportsFuzzyMatching: dicomWebConfig.supportsFuzzyMatching,
Expand All @@ -228,7 +242,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
series: {
// mapParams: mapParams.bind(),
search: async function (studyInstanceUid) {
qidoDicomWebClient.headers = getAuthorizationHeader();
qidoDicomWebClient.headers = getBaseHeaders();
const results = await seriesInStudy(qidoDicomWebClient, studyInstanceUid);

return processSeriesResults(results);
Expand All @@ -237,7 +251,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
},
instances: {
search: (studyInstanceUid, queryParameters) => {
qidoDicomWebClient.headers = getAuthorizationHeader();
qidoDicomWebClient.headers = getBaseHeaders();
return qidoSearch.call(
undefined,
qidoDicomWebClient,
Expand Down Expand Up @@ -344,7 +358,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {
getWadoDicomWebClient: () => wadoDicomWebClient,

bulkDataURI: async ({ StudyInstanceUID, BulkDataURI }) => {
qidoDicomWebClient.headers = getAuthorizationHeader();
qidoDicomWebClient.headers = getBaseHeaders();
const options = {
multipart: false,
BulkDataURI,
Expand Down Expand Up @@ -392,7 +406,7 @@ function createDicomWebApi(dicomWebConfig: DicomWebConfig, servicesManager) {

store: {
dicom: async (dataset, request, dicomDict) => {
wadoDicomWebClient.headers = getAuthorizationHeader();
wadoDicomWebClient.headers = getBaseHeaders();
if (dataset instanceof ArrayBuffer) {
const options = {
datasets: [dataset],
Expand Down
1 change: 1 addition & 0 deletions platform/core/src/types/RequestHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Interface to clearly present the expected fields to linters when building a request header.
*/
export interface HeadersInterface {
[key: string]: string | string[] | undefined;
/**
* Request Accept options. For example,
* `['multipart/related; type=application/octet-stream; transfer-syntax=1.2.840.10008.1.2.1.99',]`.
Expand Down