Skip to content

Commit

Permalink
feat(mongodb): implement search for WML items API
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Dec 9, 2023
1 parent b65061e commit 926de76
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 12 deletions.
40 changes: 40 additions & 0 deletions api/dicom-web/controller/MWL-RS/get-mwlItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { ApiErrorArrayHandler } = require("@error/api-errors.handler");
const { Controller } = require("@root/api/controller.class");
const { ApiLogger } = require("@root/utils/logs/api-logger");
const { GetMwlItemService } = require("./service/get-mwlItem.service");

class GetMwlItemController extends Controller {
constructor(req, res) {
super(req, res);
this.apiLogger = new ApiLogger(this.request, "MWL-RS");
}

async mainProcess() {
try {
let mwlItems = await new GetMwlItemService(this.request, this.response).getMwlItems();


if (mwlItems.length === 0) return this.response.status(204).end();

return this.response
.set("Content-Type", "application/dicom+json")
.status(200)
.json(mwlItems);

} 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 GetMwlItemController(req, res);

await controller.doPipeline();
};
23 changes: 23 additions & 0 deletions api/dicom-web/controller/MWL-RS/service/get-mwlItem.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { MwlItemModel } = require("@models/mongodb/models/mwlitems.model");
const { BaseQueryService } = require("@root/api/dicom-web/service/base-query.service");

class GetMwlItemService extends BaseQueryService {
constructor(req, res) {
super(req, res);
}

async getMwlItems() {
let queryOptions = {
query: this.query,
skip: this.skip_,
limit: this.limit_,
includeFields: this.includeFields_
};

let docs = await MwlItemModel.getDicomJson(queryOptions);

return docs;
}
}

module.exports.GetMwlItemService = GetMwlItemService;
20 changes: 20 additions & 0 deletions api/dicom-web/mwl-rs.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,24 @@ router.post("/mwlitems",
require("./controller/MWL-RS/create-mwlItem")
);

/**
* @openapi
* /dicom-web/mwlitems:
* get:
* tags:
* - MWL-RS
* description: >
* This transaction search Modality WorkList items.
* parameters:
* - $ref: "#/components/parameters/filter"
* responses:
* "200":
* description: Query successfully
* content:
* "application/dicom+json":
* schema:
* type: array
*/
router.get("/mwlitems",require("./controller/MWL-RS/get-mwlItem"));

module.exports = router;
1 change: 1 addition & 0 deletions api/dicom-web/service/base-query.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ function convertAllQueryToDicomTag(iParam, pushSuffixValue=true) {
}
//#endregion

module.exports.BaseQueryService = BaseQueryService;
module.exports.convertAllQueryToDicomTag = convertAllQueryToDicomTag;
9 changes: 8 additions & 1 deletion docs/swagger/parameters/dicomweb-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ components:
"image/jpeg":
schema:
type: string
format: byte
format: byte
parameters:
"filter":
description: "{attributeID}={value}; {attributeID} = {dicomTag} | {dicomKeyword} | {dicomTag}.{attributeID} | {dicomKeyword}.{attributeID}"
schema:
type: array
items:
type: string
19 changes: 8 additions & 11 deletions models/mongodb/models/mwlitems.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const mongoose = require("mongoose");
const _ = require("lodash");
const { tagsNeedStore } = require("../../DICOM/dicom-tags-mapping");
const { getVRSchema } = require("../schema/dicomJsonAttribute");
const { IncludeFieldsFactory } = require("../service");

let mwlItemSchema = new mongoose.Schema(
{},
Expand All @@ -19,25 +20,17 @@ let mwlItemSchema = new mongoose.Schema(
* @returns
*/
getDicomJson: async function (queryOptions) {
// TODO: Not Yet Test
let {
mwlItem
} = queryOptions.requestParams;

let query = mwlItem ? {
mwlInstanceUID: mwlItem
} : queryOptions.query;

let projection = mongoose.model("mwlItems").getDicomJsonProjection(queryOptions.includeFields);
try {
let docs = await mongoose.model("mwlItems").find(query)
let docs = await mongoose.model("mwlItems").find(queryOptions.query, projection)
.limit(queryOptions.limit)
.skip(queryOptions.skip)
.setOptions({
strictQuery: false
})
.exec();


let mwlDicomJson = docs.map((v) => {
let obj = v.toObject();
delete obj._id;
Expand All @@ -50,6 +43,10 @@ let mwlItemSchema = new mongoose.Schema(
} catch (e) {
throw e;
}
},
getDicomJsonProjection: function (includeFields) {
let includeFieldsFactory = new IncludeFieldsFactory(includeFields);
return includeFieldsFactory.getMwlLevelFields();
}
},
methods: {
Expand Down
13 changes: 13 additions & 0 deletions models/mongodb/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ class IncludeFieldsFactory {
};
}

getMwlLevelFields() {
if (this.all) {
return {};
}

let fields = {};
for (let tag in tagsOfRequiredMatching.Mwl) {
fields[tag] = 1;
}

return fields;
}

/**
* @private
*/
Expand Down

0 comments on commit 926de76

Please sign in to comment.