diff --git a/api-sql/dicom-web/controller/QIDO-RS/service/instanceQueryBuilder.js b/api-sql/dicom-web/controller/QIDO-RS/service/instanceQueryBuilder.js index ea45f279..bb4a0816 100644 --- a/api-sql/dicom-web/controller/QIDO-RS/service/instanceQueryBuilder.js +++ b/api-sql/dicom-web/controller/QIDO-RS/service/instanceQueryBuilder.js @@ -7,6 +7,7 @@ const { VerifyIngObserverSqModel } = require("@models/sql/models/verifyingObserv const { PersonNameModel } = require("@models/sql/models/personName.model"); const sequelize = require("@models/sql/instance"); const { SeriesQueryBuilder } = require("./seriesQueryBuilder"); +const { Op } = require("sequelize"); class InstanceQueryBuilder extends BaseQueryBuilder { constructor(queryOptions) { @@ -35,7 +36,7 @@ class InstanceQueryBuilder extends BaseQueryBuilder { this["0040A073.0040A075"] = VerifyingObserverQueryBuilder.prototype.getName.bind(verifyingObserverQueryBuilder); this["0040A073.0040A030"] = VerifyingObserverQueryBuilder.prototype.getDateTime.bind(verifyingObserverQueryBuilder); this["0040A073.0040A027"] = VerifyingObserverQueryBuilder.prototype.getOrganization.bind(verifyingObserverQueryBuilder); - + let seriesQueryBuilder = new SeriesQueryBuilder(queryOptions); let seriesQuery = seriesQueryBuilder.build(); @@ -122,7 +123,7 @@ class ConceptNameCodeSqQueryBuilder { } isModelIncluded() { - return this.instanceQueryBuilder.includeQueries.find(v=> v.model.getTableName() === "ConceptNameCodeSQ"); + return this.instanceQueryBuilder.includeQueries.find(v => v.model.getTableName() === "ConceptNameCodeSQ"); } getCodeValue(value) { @@ -136,7 +137,7 @@ class ConceptNameCodeSqQueryBuilder { } getCodingSchemeVersion(value) { - let q = this.instanceQueryBuilder.getStringQuery(dictionary.keyword.CodingSchemeVersion ,value); + let q = this.instanceQueryBuilder.getStringQuery(dictionary.keyword.CodingSchemeVersion, value); this.addQuery(q); } @@ -172,13 +173,13 @@ class ContentSqQueryBuilder { } isModelIncluded() { - return this.instanceQueryBuilder.includeQueries.find(v=> v.model.getTableName() === "DicomContentSQ"); + return this.instanceQueryBuilder.includeQueries.find(v => v.model.getTableName() === "DicomContentSQ"); } isConceptNameCodeInclude() { let currentModel = this.isModelIncluded(); if (currentModel && currentModel.include) { - return currentModel.include.find( v => v.model.getTableName() === "ConceptNameCode"); + return currentModel.include.find(v => v.model.getTableName() === "ConceptNameCode"); } return false; } @@ -186,7 +187,7 @@ class ContentSqQueryBuilder { isConceptCodeInclude() { let currentModel = this.isModelIncluded(); if (currentModel && currentModel.include) { - return currentModel.include.find( v=> v.model.getTableName() === "ConceptCode"); + return currentModel.include.find(v => v.model.getTableName() === "ConceptCode"); } return false; } @@ -226,7 +227,7 @@ class ContentSqQueryBuilder { this.addConceptNameCodeQuery(q); } - getConceptCodeValue (value) { + getConceptCodeValue(value) { let q = this.instanceQueryBuilder.getStringQuery(dictionary.keyword.CodeValue, value); this.addConceptCodeQuery(q); } @@ -266,7 +267,7 @@ class ContentSqQueryBuilder { addConceptNameCodeQuery(q) { if (!this.conceptNameCodeInclude) { - this.conceptNameCodeInclude = { + this.conceptNameCodeInclude = { model: DicomCodeModel, as: "ConceptNameCode", where: { @@ -296,7 +297,7 @@ class ContentSqQueryBuilder { addConceptCodeQuery(q) { if (!this.conceptCodeInclude) { - this.conceptCodeInclude = { + this.conceptCodeInclude = { model: DicomCodeModel, as: "ConceptCode", where: { @@ -332,36 +333,53 @@ class VerifyingObserverQueryBuilder { } isModelIncluded() { - return this.instanceQueryBuilder.includeQueries.find(v=> v.model.getTableName() === "VerifyingObserverSQ"); + return this.instanceQueryBuilder.includeQueries.find(v => v.model.getTableName() === "VerifyingObserverSQ"); } isPersonNameIncluded() { let currentModel = this.isModelIncluded(); if (currentModel && currentModel.include) { - return currentModel.include.find( v => v.model.getTableName() === "PersonName"); + return currentModel.include.find(v => v.model.getTableName() === "PersonName"); } return false; } getName(value) { - let q = this.instanceQueryBuilder.getPersonNameQuery(dictionary.keyword.VerifyingObserverName, value); + let { query } = this.instanceQueryBuilder.getPersonNameQuery(dictionary.keyword.VerifyingObserverName, value); this.addQuery({}); let currentModel = this.isModelIncluded(); currentModel.include = currentModel.include ? currentModel.include : []; let personNameIncluded = this.isPersonNameIncluded(); - if (personNameIncluded) { - personNameIncluded.where = { - ...personNameIncluded.where, - ...q.query - }; - } else { + if (!personNameIncluded) { currentModel.include.push({ model: PersonNameModel, where: { - ...q.query + [Op.or]: [ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ] }, attributes: [] }); + } else { + personNameIncluded.where[Op.or].push(...[ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ]); } } diff --git a/api-sql/dicom-web/controller/QIDO-RS/service/patientQueryBuilder.js b/api-sql/dicom-web/controller/QIDO-RS/service/patientQueryBuilder.js index ba7cfed7..c9b22e9b 100644 --- a/api-sql/dicom-web/controller/QIDO-RS/service/patientQueryBuilder.js +++ b/api-sql/dicom-web/controller/QIDO-RS/service/patientQueryBuilder.js @@ -3,6 +3,7 @@ const { dictionary } = require("@models/DICOM/dicom-tags-dic"); const { BaseQueryBuilder } = require("./querybuilder"); const sequelize = require("@models/sql/instance"); const { PersonNameModel } = require("@models/sql/models/personName.model"); +const { Op } = require("sequelize"); class PatientQueryBuilder extends BaseQueryBuilder { constructor(queryOptions) { @@ -10,15 +11,50 @@ class PatientQueryBuilder extends BaseQueryBuilder { this.query = {}; } + getIncludedPersonNameModel() { + if (this.includeQueries.length > 0) { + return this.includeQueries.find(v => v.model.getTableName() === "PersonName"); + } + return undefined; + } + getPatientName(value) { let { query } = this.getPersonNameQuery(dictionary.keyword.PatientName, value); - this.includeQueries.push({ - model: PersonNameModel, - required: true, - where: { - ...query - } - }); + + let includedPersonNameModel = this.getIncludedPersonNameModel(); + if (!includedPersonNameModel) { + this.includeQueries.push({ + model: PersonNameModel, + required: true, + where: { + [Op.or]: [ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ] + } + }); + } else { + includedPersonNameModel.where[Op.or] = [ + ...includedPersonNameModel.where[Op.or], + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ]; + } + } getPatientID(value) { diff --git a/api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js b/api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js index c0102ae5..dab6ebc5 100644 --- a/api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js +++ b/api-sql/dicom-web/controller/QIDO-RS/service/querybuilder.js @@ -4,7 +4,6 @@ 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"); const sequelize = require("@models/sql/instance"); class BaseQueryBuilder { @@ -41,7 +40,7 @@ class BaseQueryBuilder { */ getQueryByParam_(key) { let value = this.queryOptions.query[key]; - let values = Array.isArray(value) ? value: [value]; + let values = Array.isArray(value) ? value : [value]; for (let i = 0; i < values.length; i++) { let paramValue = values[i]; @@ -310,6 +309,28 @@ class StudyQueryBuilder extends BaseQueryBuilder { } } + getIncludedPatientModel() { + if (this.includeQueries.length > 0) { + return this.includeQueries.find(v => v.model.getTableName() === "Patient"); + } + return undefined; + } + + getIncludedPersonNameModelInPatient() { + let includedPatientModel = this.getIncludedPatientModel(); + if (includedPatientModel) { + return includedPatientModel.include.find(v => v.model.getTableName() === "PersonName"); + } + return undefined; + } + + getIncludedPersonNameModel() { + if (this.includeQueries.length > 0) { + return this.includeQueries.find(v => v.model.getTableName() === "PersonName"); + } + return undefined; + } + getStudyInstanceUID(value) { let q = this.getStringQuery(dictionary.keyword.StudyInstanceUID, value); @@ -320,16 +341,45 @@ class StudyQueryBuilder extends BaseQueryBuilder { } getPatientName(value) { - let q = this.getPersonNameQuery(dictionary.keyword.PatientName, value); - this.includeQueries.push({ - model: PatientModel, - include: [{ - model: PersonNameModel, - where: q.query, + let { query } = this.getPersonNameQuery(dictionary.keyword.PatientName, value); + let includedPatientModel = this.getIncludedPatientModel(); + if (!includedPatientModel) { + this.includeQueries.push({ + model: sequelize.model("Patient"), + include: [{ + model: sequelize.model("PersonName"), + where: { + [Op.or]: [ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ] + }, + required: true + }], required: true - }], - required: true - }); + }); + } else { + let personNameModel = this.getIncludedPersonNameModelInPatient(); + personNameModel.where[Op.or].push(...[ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ]); + } + } getPatientID(value) { @@ -376,12 +426,39 @@ class StudyQueryBuilder extends BaseQueryBuilder { } getReferringPhysicianName(value) { - let q = this.getPersonNameQuery(dictionary.keyword.ReferringPhysicianName, value); - this.includeQueries.push({ - model: PersonNameModel, - where: q.where, - required: true - }); + let { query } = this.getPersonNameQuery(dictionary.keyword.ReferringPhysicianName, value); + let includedPersonNameModel = this.getIncludedPersonNameModel(); + if (!includedPersonNameModel) { + this.includeQueries.push({ + model: PersonNameModel, + where: { + [Op.or]: [ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ] + }, + required: true + }); + } else { + includedPersonNameModel.where[Op.or].push(...[ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ]); + } } getStudyID(value) { diff --git a/api-sql/dicom-web/controller/QIDO-RS/service/seriesQueryBuilder.js b/api-sql/dicom-web/controller/QIDO-RS/service/seriesQueryBuilder.js index eff06601..e512a480 100644 --- a/api-sql/dicom-web/controller/QIDO-RS/service/seriesQueryBuilder.js +++ b/api-sql/dicom-web/controller/QIDO-RS/service/seriesQueryBuilder.js @@ -35,6 +35,20 @@ class SeriesQueryBuilder extends BaseQueryBuilder { }; } } + + getIncludedPerformingPhysicianNameModel() { + if (this.includeQueries.length > 0) { + return this.includeQueries.find(v=> _.get(v, "as", "") === "performingPhysicianName"); + } + return undefined; + } + + getIncludedOperatorsNameModel() { + if (this.includeQueries.length > 0) { + return this.includeQueries.find(v=> _.get(v, "as", "") === "operatorsName"); + } + return undefined; + } getSeriesDate(value) { let q = this.getDateQuery(dictionary.keyword.SeriesDate, value); this.query = { @@ -71,14 +85,40 @@ class SeriesQueryBuilder extends BaseQueryBuilder { getPerformingPhysicianName(value) { let { query } = this.getPersonNameQuery(dictionary.keyword.PerformingPhysicianName, value); - this.includeQueries.push({ - model: PersonNameModel, - as: "performingPhysicianName", - where: { - ...query - }, - attributes: [] - }); + let includedPerformingPhysicianNameModel = this.getIncludedPerformingPhysicianNameModel(); + if (!includedPerformingPhysicianNameModel) { + this.includeQueries.push({ + model: PersonNameModel, + as: "performingPhysicianName", + where: { + [Op.or]: [ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ] + }, + attributes: [] + }); + } else { + includedPerformingPhysicianNameModel.where[Op.or].push(...[ + { + alphabetic: query[Op.or].alphabetic + }, + { + ideographic: query[Op.or].ideographic + }, + { + phonetic: query[Op.or].phonetic + } + ]); + } + } getOperatorsName(value) {