Skip to content

Commit

Permalink
feat(wado-uri): #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Apr 30, 2023
1 parent a76eebf commit a877cd4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
32 changes: 30 additions & 2 deletions api/WADO-URI/service/WADO-URI.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { Dcm2JpgExecutor } = require("../../../models/DICOM/dcm4che/wrapper/org/g
const { Dcm2JpgExecutor$Dcm2JpgOptions } = require("../../../models/DICOM/dcm4che/wrapper/org/github/chinlinlee/dcm2jpg/Dcm2JpgExecutor$Dcm2JpgOptions");
const sharp = require('sharp');
const Magick = require("../../../models/magick");
const { NotFoundInstanceError, InvalidFrameNumberError } = require("../../../error/dicom-instance");
const { NotFoundInstanceError, InvalidFrameNumberError, InstanceGoneError } = require("../../../error/dicom-instance");
const dicomModel = require("../../../models/mongodb/models/dicom");

class WadoUriService {
Expand Down Expand Up @@ -36,6 +36,16 @@ class WadoUriService {
"Content-Type": "application/dicom+json"
});
return this.response.end();
} else if (e instanceof InstanceGoneError) {
this.response.writeHead(410, {
"Content-Type": "application/dicom+json"
});
return this.response.end(JSON.stringify({
Details: e.message,
HttpStatus: 410,
Message: "Image Gone",
Method: "GET"
}));
}

throw e;
Expand Down Expand Up @@ -73,6 +83,16 @@ class WadoUriService {
Method: "GET"
}));

} else if (e instanceof InstanceGoneError) {
this.response.writeHead(410, {
"Content-Type": "application/dicom+json"
});
return this.response.end(JSON.stringify({
Details: e.message,
HttpStatus: 410,
Message: "Image Gone",
Method: "GET"
}));
}

throw e;
Expand All @@ -85,7 +105,7 @@ class WadoUriService {
* @returns {Promise<fs.ReadStream>}
*/
async getDicomInstanceReadStream() {

let imagePathObj = await this.getDicomInstancePathObj();

return fs.createReadStream(imagePathObj.instancePath);
Expand All @@ -105,6 +125,14 @@ class WadoUriService {
});

if (imagePathObj) {

try {
await fs.promises.access(imagePathObj.instancePath, fs.constants.F_OK);
} catch(e) {
console.error(e);
throw new InstanceGoneError("The image is deleted permanently, but meta data remain");
}

return imagePathObj;
}

Expand Down
11 changes: 11 additions & 0 deletions error/dicom-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class NotFoundInstanceError extends Error {
}
}

class InstanceGoneError extends Error {
constructor(message) {
super(message);
Error.captureStackTrace(this, this.constructor);

this.name = this.constructor.name;
}
}

class InvalidFrameNumberError extends Error {
constructor(message) {
super(message);
Expand All @@ -17,4 +26,6 @@ class InvalidFrameNumberError extends Error {
}

module.exports.NotFoundInstanceError = NotFoundInstanceError;
module.exports.InstanceGoneError = InstanceGoneError;
module.exports.InvalidFrameNumberError = InvalidFrameNumberError;

0 comments on commit a877cd4

Please sign in to comment.