-
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.
feat(mongodb): implement delete patient API
- Loading branch information
1 parent
565fc7f
commit 0f8c39d
Showing
3 changed files
with
62 additions
and
0 deletions.
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,33 @@ | ||
const { Controller } = require("@root/api/controller.class"); | ||
const { ApiLogger } = require("@root/utils/logs/api-logger"); | ||
const { ApiErrorArrayHandler } = require("@error/api-errors.handler"); | ||
const { DeletePatientService } = require("./service/delete-patient.service"); | ||
|
||
class DeletePatientController extends Controller { | ||
constructor(req, res) { | ||
super(req, res); | ||
this.apiLogger = new ApiLogger(this.request, "PAM-RS"); | ||
this.apiLogger.addTokenValue(); | ||
} | ||
async mainProcess() { | ||
this.apiLogger.logger.info(`Delete Patient: ${this.request.params.patientID}`); | ||
|
||
let deletePatientService = new DeletePatientService(this.request, this.response); | ||
try { | ||
await deletePatientService.delete(); | ||
return this.response | ||
.set("content-type", "application/dicom+json") | ||
.status(200) | ||
.send(); | ||
} catch(e) { | ||
let apiErrorArrayHandler = new ApiErrorArrayHandler(this.response, this.apiLogger, e); | ||
return apiErrorArrayHandler.doErrorResponse(); | ||
} | ||
} | ||
} | ||
|
||
module.exports = async function (req, res) { | ||
let controller = new DeletePatientController(req, res); | ||
|
||
await controller.doPipeline(); | ||
}; |
27 changes: 27 additions & 0 deletions
27
api/dicom-web/controller/PAM-RS/service/delete-patient.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,27 @@ | ||
const { DicomWebServiceError, DicomWebStatusCodes } = require("@error/dicom-web-service"); | ||
const { PatientModel } = require("@models/mongodb/models/patient.model"); | ||
|
||
class DeletePatientService { | ||
constructor(req, res) { | ||
/** @type { import("express").Request } */ | ||
this.request = req; | ||
/** @type { import("express").Response } */ | ||
this.response = res; | ||
} | ||
|
||
async delete() { | ||
let { patientID } = this.request.params; | ||
let patient = await PatientModel.findOne({ patientID}); | ||
if (!patient) { | ||
throw new DicomWebServiceError( | ||
DicomWebStatusCodes.NoSuchObjectInstance, | ||
`Patient "${this.request.params.patientID}" does not exist.`, | ||
404 | ||
); | ||
} | ||
|
||
await patient.incrementDeleteStatus(); | ||
} | ||
} | ||
|
||
module.exports.DeletePatientService = DeletePatientService; |
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