-
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.
- Loading branch information
1 parent
432ce6b
commit 8d9adb3
Showing
5 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
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,38 @@ | ||
const { ApiErrorArrayHandler } = require("@error/api-errors.handler"); | ||
const { Controller } = require("@root/api/controller.class"); | ||
const { FhirConvertService } = require("./service/fhir-convert.service"); | ||
const { ApiLogger } = require("@root/utils/logs/api-logger"); | ||
|
||
|
||
class FhirConvertController extends Controller { | ||
constructor(req, res) { | ||
super(req, res); | ||
this.apiLogger = new ApiLogger(req, "fhir-convert"); | ||
this.apiLogger.addTokenValue(); | ||
} | ||
|
||
async mainProcess() { | ||
let fhirConvertService = new FhirConvertService(this.request, this.response); | ||
try { | ||
let fhirJson = await fhirConvertService.convert(); | ||
return this.response | ||
.set("content-type", "application/json") | ||
.status(200) | ||
.json(fhirJson); | ||
} catch (e) { | ||
let apiErrorArrayHandler = new ApiErrorArrayHandler(this.response, this.apiLogger, e); | ||
return apiErrorArrayHandler.doErrorResponse(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {import('express').Request} req | ||
* @param {import('express').Response} res | ||
*/ | ||
module.exports = async function (req, res) { | ||
let controller = new FhirConvertController(req, res); | ||
|
||
await controller.doPipeline(); | ||
}; |
38 changes: 38 additions & 0 deletions
38
api/fhir-convert/controller/service/fhir-convert.service.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,38 @@ | ||
const { DicomJsonToFhir } = require("dicomjson-to-fhir"); | ||
const dicomToJson = require("../dicom-to-fhir"); | ||
const { dcm2jsonV8 } = require("@models/DICOM/dcmtk"); | ||
const { raccoonConfig } = require("@root/config-class"); | ||
const Joi = require("joi"); | ||
const { DicomWebServiceError, DicomWebStatusCodes } = require("@error/dicom-web-service"); | ||
|
||
const fileSchema = Joi.object({ | ||
files: Joi.object({ | ||
file: Joi.object({ | ||
filepath: Joi.string().required() | ||
}).required() | ||
}).required() | ||
}); | ||
|
||
class FhirConvertService { | ||
constructor(req, res) { | ||
this.request = req; | ||
this.response = res; | ||
} | ||
|
||
async convert() { | ||
let { value, error } = fileSchema.validate(this.request, { allowUnknown : true}); | ||
if (error) { | ||
throw new DicomWebServiceError(DicomWebStatusCodes.InvalidArgumentValue, error.details[0].message, 400); | ||
} | ||
let dicomJson = await dcm2jsonV8.exec(this.request.files.file.filepath); | ||
let protocol = this.request.secure ? "https" : "http"; | ||
let dicomJsonToFhir = new DicomJsonToFhir( | ||
dicomJson, | ||
"raccoon-dicom-web-server", | ||
`${protocol}://${this.request.headers.host}/${raccoonConfig.dicomWebConfig.apiPath}/studies` | ||
); | ||
return dicomJsonToFhir.getFhirJson(); | ||
} | ||
} | ||
|
||
module.exports.FhirConvertService = FhirConvertService; |
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,54 @@ | ||
/** | ||
* Route /fhir-convert | ||
* Implement `DICOM convert to FHIR ImagingStudy, Patient, Endpoint` | ||
* | ||
* @author Chin-Lin Lee <[email protected]> | ||
*/ | ||
|
||
const Joi = require("joi"); | ||
const { validateByJoi } = require("../validator"); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const formidable = require("formidable"); | ||
|
||
const formMiddleWare = async (req, res, next) => { | ||
const form = formidable({}); | ||
|
||
form.parse(req, (err, fields, files) => { | ||
if (err) { | ||
next(err); | ||
return; | ||
} | ||
req.fields = fields; | ||
req.files = files; | ||
next(); | ||
}); | ||
}; | ||
|
||
/** | ||
* @openapi | ||
* /fhir-convert: | ||
* post: | ||
* tags: | ||
* - fhir-convert | ||
* description: Convert DICOM to FHIR ImagingStudy, Patient, Endpoint | ||
* requestBody: | ||
* content: | ||
* multipart/form-data: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* file: | ||
* type: string | ||
* format: binary | ||
* encoding: | ||
* file: | ||
* contentType: application/dicom; | ||
* responses: | ||
* "200": | ||
* description: The DICOM instance store successfully | ||
*/ | ||
router.post("/", formMiddleWare, require("./controller/dicom-to-fhir")); | ||
|
||
|
||
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