Skip to content

Commit

Permalink
feat: #15 audit message for WADO-URI
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Aug 29, 2023
1 parent d479fe9 commit b728881
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions api/WADO-URI/service/WADO-URI.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const sharp = require('sharp');
const Magick = require("../../../models/magick");
const { NotFoundInstanceError, InvalidFrameNumberError, InstanceGoneError } = require("../../../error/dicom-instance");
const dicomModel = require("../../../models/mongodb/models/dicom");
const { AuditManager } = require("@models/DICOM/audit/auditManager");
const auditMessageModel = require("@models/mongodb/models/auditMessage");
const { EventType } = require("@models/DICOM/audit/eventType");
const { EventOutcomeIndicator } = require("@models/DICOM/audit/auditUtils");
const { DicomWebService } = require("@root/api/dicom-web/service/dicom-web.service");

class WadoUriService {

Expand All @@ -19,6 +24,7 @@ class WadoUriService {
constructor(req, res) {
this.request = req;
this.response = res;
this.auditBeginTransferring();
}

async getAndResponseDicomInstance() {
Expand All @@ -28,8 +34,10 @@ class WadoUriService {

this.response.setHeader("Content-Type", "application/dicom");
dicomInstanceReadStream.pipe(this.response);
this.auditInstanceTransferred();

} catch (e) {
this.auditInstanceTransferred(EventOutcomeIndicator.MajorFailure);

if (e instanceof NotFoundInstanceError) {
this.response.writeHead(404, {
Expand Down Expand Up @@ -60,8 +68,10 @@ class WadoUriService {
this.response.setHeader("Content-Type", "image/jpeg");

this.response.end(jpegBuffer, "buffer");
this.auditInstanceTransferred();

} catch (e) {
this.auditInstanceTransferred(EventOutcomeIndicator.MajorFailure);

if (e instanceof NotFoundInstanceError) {

Expand Down Expand Up @@ -105,7 +115,7 @@ class WadoUriService {
* @returns {Promise<fs.ReadStream>}
*/
async getDicomInstanceReadStream() {

let imagePathObj = await this.getDicomInstancePathObj();

return fs.createReadStream(imagePathObj.instancePath);
Expand All @@ -128,7 +138,7 @@ class WadoUriService {

try {
await fs.promises.access(imagePathObj.instancePath, fs.constants.F_OK);
} catch(e) {
} catch (e) {
console.error(e);
throw new InstanceGoneError("The image is deleted permanently, but meta data remain");
}
Expand Down Expand Up @@ -186,7 +196,7 @@ class WadoUriService {
}

let dicomFilename = instanceFramesObj.instancePath;
let jpegFile = dicomFilename.replace(/\.dcm\b/gi , `.${frameNumber-1}.jpg`);
let jpegFile = dicomFilename.replace(/\.dcm\b/gi, `.${frameNumber - 1}.jpg`);

let getFrameImageStatus = await Dcm2JpgExecutor.convertDcmToJpgFromFilename(
dicomFilename,
Expand Down Expand Up @@ -242,6 +252,29 @@ class WadoUriService {
await renderedService.handleImageICCProfile(this.request.query, magick, this.request.query.objectUID);
}

async auditBeginTransferring() {
let auditManager = new AuditManager(
auditMessageModel,
EventType.RETRIEVE_BEGIN, EventOutcomeIndicator.Success,
DicomWebService.getRemoteAddress(this.request), DicomWebService.getRemoteHostname(this.request),
DicomWebService.getServerAddress(), DicomWebService.getServerHostname()
);

let { studyUID } = this.request.query;
auditManager.onBeginTransferringDicomInstances([studyUID]);
}

async auditInstanceTransferred(eventResult = EventOutcomeIndicator.Success) {
let auditManager = new AuditManager(
auditMessageModel,
EventType.RETRIEVE_END, eventResult,
DicomWebService.getRemoteAddress(this.request), DicomWebService.getRemoteHostname(this.request),
DicomWebService.getServerAddress(), DicomWebService.getServerHostname()
);

let { studyUID } = this.request.query;
auditManager.onDicomInstancesTransferred([studyUID]);
}
}

module.exports.WadoUriService = WadoUriService;
Expand Down

0 comments on commit b728881

Please sign in to comment.