Skip to content

Commit

Permalink
feat(WIP): series query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Aug 3, 2023
1 parent 4da907d commit c3f604d
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
68 changes: 68 additions & 0 deletions api-sql/dicom-web/controller/QIDO-RS/seriesQueryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { dictionary } = require("@models/DICOM/dicom-tags-dic");
const { BaseQueryBuilder } = require("./service/querybuilder");
const { Op, Sequelize } = require("sequelize");
const { raccoonConfig } = require("@root/config-class");

class SeriesQueryBuilder extends BaseQueryBuilder {
getSeriesDate(value) {
let q = this.getDateQuery(dictionary.keyword.SeriesDate, value);
this.query = {
...this.query,
...q
};
}
getModality(value) {
let q = this.getStringQuery(dictionary.keyword.Modality, value);
this.query = {
...this.query,
...q
};
}
getSeriesDescription(value) {
let q = this.getStringQuery(dictionary.keyword.SeriesDescription, value);
this.query = {
...this.query,
...q
};
}

getPersonNameJsonArrayQuery(tag, value) {
if (raccoonConfig.sqlDbConfig.dialect === "postgres") {
value = this.getWildCardRegexString(value);
return {
[Op.or]: [
Sequelize.literal(`"x${tag}" @? '$[*].Alphabetic ? (@ like_regex "${value}" flag "is")'`)
]
};
}
throw new Error("Not implemented");
}

getPerformingPhysicianName(value) {
let q = this.getPersonNameJsonArrayQuery(dictionary.keyword.PerformingPhysicianName, value);
this.query = {
...this.query,
...q
};
}

getOperatorsName(value) {
let q = this.getPersonNameJsonArrayQuery(dictionary.keyword.OperatorsName, value);
this.query = {
...this.query,
...q
};
}

getSeriesNumber(value) {
let q = this.getStringQuery(dictionary.keyword.SeriesNumber, value);
this.query = {
...this.query,
...q
};
}


}

module.exports.SeriesQueryBuilder = SeriesQueryBuilder;
53 changes: 53 additions & 0 deletions api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@ class BaseQueryBuilder {
constructor(queryOptions) {
this.queryOptions = queryOptions;
this.personQuery = [];
this.bind = [];
}

build() {
for (let key in this.queryOptions.query) {
let commaValue = this.comma(key, this.queryOptions.query[key]);

for (let i = 0; i < commaValue.length; i++) {
let value = this.getWildCardQuery(commaValue[i][key]);
try {
this[`get${dictionary.tag[key]}`](value);
} catch (e) {
if (e.message.includes("not a function")) break;
}
}
}

let sequelizeQuery = {
where: this.query
};

let includesPersonNameQuery = this.getSequelizeIncludePersonNameQuery();
if (includesPersonNameQuery.length > 0) {
_.set(sequelizeQuery, "include", includesPersonNameQuery);
}

if (this.bind.length > 0 ) {
_.set(sequelizeQuery, "bind", this.bind);
}
return sequelizeQuery;
}

getSequelizeIncludePersonNameQuery() {
let includes = [];

for (let personNameQuery of this.personQuery) {
includes.push(personNameQuery);
}
return includes;
}

comma(key, value) {
Expand Down Expand Up @@ -211,6 +250,20 @@ class BaseQueryBuilder {
return value;
}

getWildCardRegexString(value) {
let wildCardIndex = value.indexOf("%");
let questionIndex = value.indexOf("_");

if (wildCardIndex >= 0 || questionIndex >= 0) {
value = value.replace(/%/gm, ".*");
value = value.replace(/_/gm, ".");
value = value.replace(/\^/gm, "\\^");
value = "^" + value;
}

return value;
}

/**
*
* @param {*} q
Expand Down
2 changes: 1 addition & 1 deletion models/sql/po/series.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SeriesPersistentObject {
this.x0008103E = _.get(dicomJson, "0008103E.Value.0", "");
this.x0008103F = _.get(dicomJson, "0008103F.Value", undefined);
this.x00081050 = _.get(dicomJson, "00081050.Value", "");
this.x00081052 = _.get(dicomJson, "00081052.Value", "");
this.x00081052 = _.get(dicomJson, "00081052.Value.0", "");
this.x00081070 = _.get(dicomJson, "00081070.Value", "");
this.x00081072 = _.get(dicomJson, "00081072.Value", "");
this.x00081250 = _.get(dicomJson, "00081250.Value", "");
Expand Down

0 comments on commit c3f604d

Please sign in to comment.