Skip to content

Commit

Permalink
feat: add string json array query
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Aug 2, 2023
1 parent 72566ca commit 6a2fbf7
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const _ = require("lodash");
const moment = require("moment");
const { dictionary } = require("@models/DICOM/dicom-tags-dic");
const { Op } = require("sequelize");
const { Op, Sequelize, cast, col } = require("sequelize");
const { raccoonConfig } = require("@root/config-class");

class BaseQueryBuilder {
Expand All @@ -27,8 +27,23 @@ class BaseQueryBuilder {
};
}

getStringArrayQuery(tag, value) {
//TODO
getStringArrayJsonQuery(tag, value) {
if (raccoonConfig.sqlDbConfig.dialect === "postgres") {
return {
[Op.or]: [
Sequelize.where(
cast(Sequelize.col(`x${tag}`), "jsonb"),
{
[Op.contains]: cast(JSON.stringify([value]), "jsonb")
}
)
]
};
} else {
return {
[Op.or]: [Sequelize.where(Sequelize.fn("JSON_CONTAINS", Sequelize.col(`x${tag}`), `[${value}]`))]
};
}
}

getNumberQuery(tag, value) {
Expand Down Expand Up @@ -170,9 +185,9 @@ class BaseQueryBuilder {
* @see {@link https://stackoverflow.com/questions/60598225/how-to-merge-javascript-object-containing-symbols "How to merge javascript object containing symbols?"}
*/
mergeQuery(q) {
_.mergeWith(this.query, q, (a ,b) => {
_.mergeWith(this.query, q, (a, b) => {
if (!_.isObject(b)) return b;

return Array.isArray(a) ? [...a, ...b] : { ...a, ...b };
});
}
Expand Down Expand Up @@ -224,6 +239,14 @@ class StudyQueryBuilder extends BaseQueryBuilder {
let q = this.getTimeQuery(dictionary.keyword.StudyTime, value);
this.mergeQuery(q);
}

getModalitiesInStudy(value) {
let q = this.getStringArrayJsonQuery(dictionary.keyword.ModalitiesInStudy, value);
this.query = {
...this.query,
q
};
}
}


Expand Down

0 comments on commit 6a2fbf7

Please sign in to comment.