-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move SQL out of plugins and integration
- Loading branch information
1 parent
fe6b794
commit 09bbc38
Showing
16 changed files
with
332 additions
and
67 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
api-sql/dicom-web/controller/STOW-RS/service/dicom-jpeg-generator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const fs = require("fs"); | ||
const { Dcm2JpgExecutor$Dcm2JpgOptions } = require("../../../../../models/DICOM/dcm4che/wrapper/org/github/chinlinlee/dcm2jpg/Dcm2JpgExecutor$Dcm2JpgOptions"); | ||
const colorette = require("colorette"); | ||
const { DicomJpegGenerator } = require("@root/api/dicom-web/controller/STOW-RS/service/dicom-jpeg-generator"); | ||
/** | ||
* @typedef JsDcm2JpegTask | ||
* @property {Dcm2JpgExecutor$Dcm2JpgOptions} jsDcm2Jpeg | ||
* @property {string} jpegFilename | ||
*/ | ||
|
||
class SqlDicomJpegGenerator extends DicomJpegGenerator { | ||
/** | ||
* | ||
* @param {import("../../../../../models/DICOM/dicom-json-model").DicomJsonModel} dicomJsonModel | ||
* @param {string} dicomInstanceFilename | ||
*/ | ||
constructor(dicomJsonModel, dicomInstanceFilename) { | ||
super(dicomJsonModel, dicomInstanceFilename); | ||
} | ||
|
||
|
||
|
||
/** | ||
* @private | ||
*/ | ||
async insertStartTask_() { | ||
let startTaskObj = { | ||
studyUID: this.dicomJsonModel.uidObj.studyUID, | ||
seriesUID: this.dicomJsonModel.uidObj.seriesUID, | ||
instanceUID: this.dicomJsonModel.uidObj.sopInstanceUID, | ||
status: false, | ||
message: "processing", | ||
taskTime: new Date(), | ||
finishedTime: null, | ||
fileSize: `${(fs.statSync(this.dicomInstanceFilename).size / 1024 / 1024).toFixed(3)}MB` | ||
}; | ||
|
||
|
||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
async insertEndTask_() { | ||
let endTaskObj = { | ||
studyUID: this.dicomJsonModel.uidObj.studyUID, | ||
seriesUID: this.dicomJsonModel.uidObj.seriesUID, | ||
instanceUID: this.dicomJsonModel.uidObj.sopInstanceUID, | ||
status: true, | ||
message: "generated", | ||
finishedTime: new Date() | ||
}; | ||
|
||
} | ||
|
||
/** | ||
* @private | ||
* @param {string} message | ||
*/ | ||
async insertErrorTask_(message) { | ||
let errorTaskObj = { | ||
studyUID: this.dicomJsonModel.uidObj.studyUID, | ||
seriesUID: this.dicomJsonModel.uidObj.seriesUID, | ||
instanceUID: this.dicomJsonModel.uidObj.sopInstanceUID, | ||
status: false, | ||
message: message, | ||
finishedTime: new Date() | ||
}; | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports.SqlDicomJpegGenerator = SqlDicomJpegGenerator; |
47 changes: 47 additions & 0 deletions
47
api-sql/dicom-web/controller/STOW-RS/service/request-multipart-parser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const formidable = require("formidable"); | ||
const path = require("path"); | ||
const _ = require("lodash"); | ||
|
||
class StowRsRequestMultipartParser { | ||
/** | ||
* @param {import('express').Request} req | ||
*/ | ||
constructor(req) { | ||
this.request = req; | ||
} | ||
|
||
/** | ||
* | ||
* @return {Promise<import('../../../../../utils/typeDef/STOW-RS/STOW-RS.def').MultipartParseResult>} | ||
*/ | ||
async parse() { | ||
return new Promise((resolve, reject) => { | ||
new formidable.IncomingForm({ | ||
uploadDir: path.join(process.cwd(), "/tempUploadFiles"), | ||
maxFileSize: 100 * 1024 * 1024 * 1024, | ||
multiples: true, | ||
isGetBoundaryInData: true | ||
}).parse(this.request, async (err, fields, files) => { | ||
|
||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
let fileField = Object.keys(files).pop(); | ||
let uploadFiles = files[fileField]; | ||
if (!_.isArray(uploadFiles)) uploadFiles = [uploadFiles]; | ||
|
||
return resolve({ | ||
status: true, | ||
multipart: { | ||
fields: fields, | ||
files: uploadFiles | ||
} | ||
}); | ||
|
||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports.StowRsRequestMultipartParser = StowRsRequestMultipartParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { performance } = require("node:perf_hooks"); | ||
const errorResponseMessage = require("@root/utils/errorResponse/errorResponseMessage"); | ||
const { ApiLogger } = require("@root/utils/logs/api-logger"); | ||
const { Controller } = require("@root/api/controller.class"); | ||
const { StowRsRequestMultipartParser } = require("./service/request-multipart-parser"); | ||
const { SqlStowRsService: StowRsService } = require("./service/stow-rs.service"); | ||
|
||
class StoreInstanceController extends Controller { | ||
constructor(req, res) { | ||
super(req, res); | ||
} | ||
|
||
async mainProcess() { | ||
let startSTOWTime = performance.now(); | ||
let retCode; | ||
let storeMessage; | ||
let apiLogger = new ApiLogger(this.request, "STOW-RS"); | ||
apiLogger.addTokenValue(); | ||
|
||
try { | ||
let requestMultipartParser = new StowRsRequestMultipartParser(this.request); | ||
let multipartParseResult = await requestMultipartParser.parse(); | ||
|
||
if (multipartParseResult.status) { | ||
let stowRsService = new StowRsService(this.request, multipartParseResult.multipart.files); | ||
let storeInstancesResult = await stowRsService.storeInstances(); | ||
|
||
retCode = storeInstancesResult.code; | ||
storeMessage = storeInstancesResult.responseMessage; | ||
} | ||
let endSTOWTime = performance.now(); | ||
let elapsedTime = (endSTOWTime - startSTOWTime).toFixed(3); | ||
apiLogger.logger.info(`Finished STOW-RS, elapsed time: ${elapsedTime} ms`); | ||
|
||
this.response.writeHead(retCode, { | ||
"Content-Type": "application/dicom" | ||
}); | ||
|
||
return this.response.end(JSON.stringify(storeMessage)); | ||
} catch (e) { | ||
let errorStr = JSON.stringify(e, Object.getOwnPropertyNames(e)); | ||
apiLogger.logger.error(errorStr); | ||
|
||
let errorMessage = | ||
errorResponseMessage.getInternalServerErrorMessage(errorStr); | ||
this.response.writeHead(500, { | ||
"Content-Type": "application/dicom+json" | ||
}); | ||
return this.response.end(JSON.stringify(errorMessage)); | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* To store DICOM instance | ||
* 1. we parse multipart request to get file info that user upload | ||
* 2. parse DICOM to JSON and store DICOM file from step 1 | ||
* 3. parse DICOM json model to FHIR (Patient, Endpoint, ImagingStudy) | ||
* 4. upload FHIR to FHIR server | ||
* @param {import('express').Request} req | ||
* @param {import('express').Response} res | ||
*/ | ||
module.exports = async function (req, res) { | ||
let controller = new StoreInstanceController(req, res); | ||
|
||
await controller.doPipeline(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const express = require("express"); | ||
const Joi = require("joi"); | ||
const { validateParams, intArrayJoi } = require("@root/api/validator"); | ||
const router = express(); | ||
|
||
//#region STOW-RS | ||
|
||
/** | ||
* @openapi | ||
* /dicom-web/studies: | ||
* post: | ||
* tags: | ||
* - STOW-RS | ||
* description: store DICOM instance | ||
* requestBody: | ||
* content: | ||
* multipart/related: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* file: | ||
* type: string | ||
* format: binary | ||
* encoding: | ||
* file: | ||
* contentType: application/dicom; | ||
* responses: | ||
* "200": | ||
* description: The DICOM instance store successfully | ||
*/ | ||
router.post("/studies", require("./controller/STOW-RS/storeInstance")); | ||
|
||
//#endregion | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
plugins/sql/models/personName.model.js → models/sql/models/personName.model.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.