Skip to content

Commit

Permalink
refactor: duplicate method getUidsString
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Oct 29, 2023
1 parent 3d7db77 commit 1eedd4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
32 changes: 19 additions & 13 deletions api/dicom-web/controller/WADO-RS/service/WADO-RS.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ImageMultipartWriter {
if (!writeResult.status) {
retrieveAuditService.eventResult = EventOutcomeIndicator.MajorFailure;
await retrieveAuditService.completedRetrieve();

this.response.setHeader("Content-Type", "application/dicom+json");
return this.response.status(writeResult.code).json(writeResult);
}
Expand Down Expand Up @@ -98,7 +98,7 @@ class ImagePathFactory {
return {
status: false,
code: 404,
message: `not found, ${this.getUidsString()}`
message: `not found, ${getUidsString(this.uids)}`
};
}

Expand Down Expand Up @@ -139,16 +139,6 @@ class ImagePathFactory {
return existArr;
}

getUidsString() {
let uidsKeys = Object.keys(this.uids);
let strArr = [];
for (let i = 0; i < uidsKeys.length; i++) {
let key = uidsKeys[i];
strArr.push(`${key}: ${this.uids[key]}`);
}
return strArr.join(", ");
}

getPartialImagesPathString() {
return JSON.stringify(this.imagePaths.slice(0, 10).map(v => v.instancePath));
}
Expand Down Expand Up @@ -182,7 +172,7 @@ class InstanceImagePathFactory extends ImagePathFactory {
async getImagePaths() {
let imagePath = await dicomModel.getPathOfInstance(this.uids);

if(imagePath)
if (imagePath)
this.imagePaths = [imagePath];
else
this.imagePaths = [];
Expand Down Expand Up @@ -255,6 +245,21 @@ function addHostnameOfBulkDataUrl(metadata, req) {
}
}

/**
*
* @param {import("../../../../../utils/typeDef/dicom").Uids} uids
* @returns
*/
function getUidsString(uids) {
let uidsKeys = Object.keys(uids);
let strArr = [];
for (let i = 0; i < uidsKeys.length; i++) {
let key = uidsKeys[i];
strArr.push(`${key}: ${uids[key]}`);
}
return strArr.join(", ");
}

module.exports.getAcceptType = getAcceptType;
module.exports.supportInstanceMultipartType = supportInstanceMultipartType;
module.exports.sendNotSupportedMediaType = sendNotSupportedMediaType;
Expand All @@ -265,3 +270,4 @@ module.exports.SeriesImagePathFactory = SeriesImagePathFactory;
module.exports.InstanceImagePathFactory = InstanceImagePathFactory;
module.exports.multipartContentTypeWriter = multipartContentTypeWriter;
module.exports.ImageMultipartWriter = ImageMultipartWriter;
module.exports.getUidsString = getUidsString;
13 changes: 2 additions & 11 deletions api/dicom-web/controller/WADO-RS/service/thumbnail.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const dicomSeriesModel = require("../../../../../models/mongodb/models/dicomSeri
const errorResponse = require("../../../../../utils/errorResponse/errorResponseMessage");
const renderedService = require("../service/rendered.service");
const _ = require("lodash");
const { getUidsString } = require("./WADO-RS.service");
class ThumbnailService {

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ class ThumbnailService {
this.response.writeHead(404, {
"Content-Type": "application/dicom+json"
});
let notFoundMessage = errorResponse.getNotFoundErrorMessage(`Not Found, ${this.thumbnailFactory.getUidsString()}`);
let notFoundMessage = errorResponse.getNotFoundErrorMessage(`Not Found, ${getUidsString(this.thumbnailFactory.uids)}`);

let notFoundMessageStr = JSON.stringify(notFoundMessage);

Expand All @@ -82,16 +83,6 @@ class ThumbnailFactory {
}

async getThumbnailInstance() { }

getUidsString() {
let uidsKeys = Object.keys(this.uids);
let strArr = [];
for (let i = 0; i < uidsKeys.length; i++) {
let key = uidsKeys[i];
strArr.push(`${key}: ${this.uids[key]}`);
}
return strArr.join(", ");
}
}

class StudyThumbnailFactory extends ThumbnailFactory {
Expand Down

0 comments on commit 1eedd4f

Please sign in to comment.