Skip to content

Commit

Permalink
feat(study): complete person name query
Browse files Browse the repository at this point in the history
- Modify the compose way of person name queries
  - Have a query and field (may be used later to distinguish fields) attrs
  - The outer structure should be Field: Query Method
- Modify the content returned by querybuilder to
sequelize's query Option
- Patient Name needs to join with Patient and Person name for querying
- Add ReferringPhysicianName foreign key to Study
- ReferringPhysicianName query by joining only with Person Name
  • Loading branch information
Chinlinlee committed Aug 3, 2023
1 parent 73d8e97 commit 7ac8ace
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class QidoDicomJsonFactory {
"study": async () => {
// return await getStudyDicomJson(queryOptions);
let queryBuilder = new StudyQueryBuilder(queryOptions);
queryBuilder.build();
let q = queryBuilder.build();
let studies = await StudyModel.findAll({
where: queryBuilder.query
...q
});
console.log(studies);
},
Expand Down
109 changes: 86 additions & 23 deletions api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const moment = require("moment");
const { dictionary } = require("@models/DICOM/dicom-tags-dic");
const { Op, Sequelize, cast, col } = require("sequelize");
const { raccoonConfig } = require("@root/config-class");
const { PersonNameModel } = require("@models/sql/models/personName.model");
const { PatientModel } = require("@models/sql/models/patient.model");

class BaseQueryBuilder {
constructor(queryOptions) {
Expand Down Expand Up @@ -65,28 +67,34 @@ class BaseQueryBuilder {
* @param {string} value
* @returns
*/
getPersonNameQuery(value) {
getPersonNameQuery(tag, value) {
if (value.includes("%") || value.includes("_")) {
return {
[Op.or]: {
[Op.like]: {
alphabetic: value
},
[Op.like]: {
ideographic: value
},
[Op.like]: {
phonetic: value
query: {
[Op.or]: {
alphabetic: {
[Op.like]: value
},
ideographic: {
[Op.like]: value
},
phonetic: {
[Op.like]: value
}
}
}
},
field: tag
};
}
return {
[Op.or]: {
alphabetic: value,
ideographic: value,
phonetic: value
}
query: {
[Op.or]: {
alphabetic: value,
ideographic: value,
phonetic: value
}
},
field: tag
};
}

Expand Down Expand Up @@ -236,32 +244,70 @@ class StudyQueryBuilder extends BaseQueryBuilder {
}
}
}
console.log(this.query);

let sequelizeQuery = {
where: this.query
};

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

getSequelizeIncludePersonNameQuery() {
let includes = [];

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

getStudyInstanceUID(value) {
let q = this.getStringQuery(dictionary.keyword.StudyInstanceUID, value);
_.merge(this.query, q);
this.query = {
...this.query,
...q
};
}

getPatientName(value) {
let q = this.getPersonNameQuery(value);
this.personQuery.push(q);
let q = this.getPersonNameQuery(dictionary.keyword.PatientName, value);
this.personQuery.push({
model: PatientModel,
include: [{
model: PersonNameModel,
where: q.query,
required: true
}],
required: true
});
}

getPatientID(value) {
let q = this.getStringQuery(dictionary.keyword.PatientID, value);
_.merge(this.query, q);
this.query = {
...this.query,
...q
};
}

getStudyDate(value) {
let q = this.getDateQuery(dictionary.keyword.StudyDate, value);
this.mergeQuery(q);
this.query = {
...this.query,
...q
};
}

getStudyTime(value) {
let q = this.getTimeQuery(dictionary.keyword.StudyTime, value);
this.mergeQuery(q);
this.query = {
...this.query,
...q
};
}

getAccessionNumber(value) {
Expand All @@ -279,6 +325,23 @@ class StudyQueryBuilder extends BaseQueryBuilder {
...q
};
}

getReferringPhysicianName(value) {
let q = this.getPersonNameQuery(dictionary.keyword.ReferringPhysicianName, value);
this.personQuery.push({
model: PersonNameModel,
where: q.where,
required: true
});
}

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


Expand Down
3 changes: 3 additions & 0 deletions models/sql/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ async function init() {
foreignKey: "x00100020",
targetKey: "x00100020"
});
StudyModel.belongsTo(PersonNameModel, {
foreignKey: "x00080090"
});
SeriesModel.belongsTo(StudyModel, {
foreignKey: "x0020000D",
targetKey: "x0020000D"
Expand Down

0 comments on commit 7ac8ace

Please sign in to comment.