Skip to content

Commit

Permalink
feat(mongodb): implement delete patient API
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Dec 23, 2023
1 parent 565fc7f commit 0f8c39d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api/dicom-web/controller/PAM-RS/delete-patient.js
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 api/dicom-web/controller/PAM-RS/service/delete-patient.service.js
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;
2 changes: 2 additions & 0 deletions api/dicom-web/pam-rs.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ router.post("/patients", validateParams({
*/
router.put("/patients/:patientID", require("./controller/PAM-RS/update-patient"));

router.delete("/patients/:patientID", require("./controller/PAM-RS/delete-patient"));

module.exports = router;

0 comments on commit 0f8c39d

Please sign in to comment.