-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement patient query of C-Find
- Loading branch information
1 parent
6cf73a0
commit 1a99d45
Showing
120 changed files
with
5,263 additions
and
4,850 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
const _ = require("lodash"); | ||
const { default: PatientQueryTask } = require("@java-wrapper/org/github/chinlinlee/dcm777/net/PatientQueryTask"); | ||
const { PatientQueryTaskInjectInterface, createPatientQueryTaskInjectProxy } = require("@java-wrapper/org/github/chinlinlee/dcm777/net/PatientQueryTaskInject"); | ||
const { createQueryTaskInjectProxy, QueryTaskInjectInterface } = require("@java-wrapper/org/github/chinlinlee/dcm777/net/QueryTaskInject"); | ||
const { default: Attributes } = require("@dcm4che/data/Attributes"); | ||
const { default: Tag } = require("@dcm4che/data/Tag"); | ||
const { default: VR } = require("@dcm4che/data/VR"); | ||
const { DimseQueryBuilder } = require("./queryBuilder"); | ||
const patientModel = require("@models/mongodb/models/patient"); | ||
|
||
|
||
class JsPatientQueryTask { | ||
constructor(as, pc, rq, keys) { | ||
this.as = as; | ||
this.pc = pc; | ||
this.rq = rq; | ||
this.keys = keys; | ||
|
||
this.patientAttr = null; | ||
this.init = false; | ||
this.cursor = null; | ||
this.patient = null; | ||
} | ||
|
||
async get() { | ||
let patientQueryTask = await PatientQueryTask.newInstanceAsync( | ||
this.as, | ||
this.pc, | ||
this.rq, | ||
this.keys, | ||
this.getQueryTaskInjectProxy(), | ||
this.getPatientQueryTaskInjectProxy() | ||
); | ||
return patientQueryTask; | ||
} | ||
|
||
getQueryTaskInjectProxy() { | ||
/** @type { QueryTaskInjectInterface } */ | ||
this.queryTaskInjectMethods = { | ||
hasMoreMatches: () => { | ||
return !_.isNull(this.patientAttr); | ||
}, | ||
nextMatch: async () => { | ||
let tempRecord = this.patientAttr; | ||
await this.patientQueryTaskInjectMethods.wrappedFindNextPatient(); | ||
return tempRecord; | ||
}, | ||
adjust: async (match) => { | ||
let basicAd = await this.basicAdjust(match); | ||
await basicAd.remove(Tag.DirectoryRecordType); | ||
|
||
if (await this.keys.contains(Tag.SOPClassUID)) { | ||
await basicAd.setString(Tag.SOPClassUID, VR.UI, await match.getString(Tag.ReferencedSOPClassUIDInFile)); | ||
} | ||
|
||
if (await this.keys.contains(Tag.SOPInstanceUID)) { | ||
await basicAd.setString(Tag.SOPInstanceUID, VR.UI, await match.getString(Tag.ReferencedSOPInstanceUIDInFile)); | ||
} | ||
|
||
await basicAd.setString(Tag.QueryRetrieveLevel, VR.CS, await this.keys.getString(Tag.QueryRetrieveLevel)); | ||
|
||
return basicAd; | ||
} | ||
}; | ||
|
||
if (!this.queryTaskInjectProxy) { | ||
this.queryTaskInjectProxy = createQueryTaskInjectProxy(this.queryTaskInjectMethods); | ||
} | ||
|
||
return this.queryTaskInjectProxy; | ||
} | ||
|
||
getPatientQueryTaskInjectProxy() { | ||
|
||
/** @type { PatientQueryTaskInjectInterface }*/ | ||
this.patientQueryTaskInjectMethods = { | ||
wrappedFindNextPatient: async () => { | ||
await this.patientQueryTaskInjectMethods.findNextPatient(); | ||
}, | ||
getPatient: async () => { | ||
let queryBuilder = new DimseQueryBuilder(this.keys, "patient"); | ||
let normalQuery = await queryBuilder.toNormalQuery(); | ||
let mongoQuery = await queryBuilder.getMongoQuery(normalQuery); | ||
|
||
if (_.isNull(this.patientAttr) && !this.init) { | ||
let returnKeys = this.getReturnKeys(normalQuery); | ||
|
||
this.cursor = await patientModel.getDimseResultCursor({ | ||
...mongoQuery.$match | ||
}, returnKeys); | ||
|
||
this.patient = await this.cursor.next(); | ||
this.patientAttr = this.patient ? await this.patient.getAttributes() : null; | ||
} else { | ||
this.patient = await this.cursor.next(); | ||
this.patientAttr = this.patient ? await this.patient.getAttributes() : null; | ||
} | ||
|
||
}, | ||
findNextPatient: async () => { | ||
await this.patientQueryTaskInjectMethods.getPatient(); | ||
return !_.isNull(this.patientAttr); | ||
} | ||
}; | ||
|
||
if (!this.patientQueryTaskProxy) { | ||
this.patientQueryTaskProxy = createPatientQueryTaskInjectProxy(this.patientQueryTaskInjectMethods); | ||
} | ||
|
||
return this.patientQueryTaskProxy; | ||
} | ||
|
||
/** | ||
* | ||
* @param {Attributes} match | ||
* @returns | ||
*/ | ||
async basicAdjust(match) { | ||
if (match == null) { | ||
return null; | ||
} | ||
|
||
let filtered = new Attributes(await match.size()); | ||
|
||
if (!await this.keys.contains(Tag.SpecificCharacterSet)) { | ||
let ss = await match.getStrings(Tag.SpecificCharacterSet); | ||
if (!ss) | ||
await filtered.setString(Tag.SpecificCharacterSet, VR.CS, ss); | ||
} | ||
await filtered.addSelected(match, this.keys); | ||
await filtered.supplementEmpty(this.keys); | ||
return filtered; | ||
} | ||
|
||
getReturnKeys(query) { | ||
let returnKeys = {}; | ||
let queryKeys = Object.keys(query); | ||
for (let i = 0; i < queryKeys.length; i++) { | ||
returnKeys[queryKeys[i].split(".").shift()] = 1; | ||
} | ||
return returnKeys; | ||
} | ||
} | ||
|
||
module.exports.JsPatientQueryTask = JsPatientQueryTask; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const _ = require("lodash"); | ||
|
||
const { default: Attributes } = require("@dcm4che/data/Attributes"); | ||
const { queryTagsOfEachLevel } = require("./queryTagsOfEachLevel"); | ||
// const { default: ElementDictionary } = require("@dcm4che/data/ElementDictionary"); | ||
const { default: StringUtils } = require("@dcm4che/util/StringUtils"); | ||
const { intTagToString } = require("./utils"); | ||
const { convertRequestQueryToMongoQuery } = require("@root/api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service"); | ||
|
||
// const dict = ElementDictionary.getStandardElementDictionarySync(); | ||
|
||
class DimseQueryBuilder { | ||
|
||
/** | ||
* | ||
* @param {Attributes} queryKeys | ||
* @param {"patient" | "study" | "series" | "instance"} level | ||
*/ | ||
constructor(queryKeys, level="patient") { | ||
this.queryKeys = queryKeys; | ||
this.level = level; | ||
} | ||
|
||
async toNormalQuery() { | ||
const queryTags = queryTagsOfEachLevel[this.level]; | ||
let query = {}; | ||
for (let i = 0 ; i < queryTags.length ; i++) { | ||
let tag = queryTags[i]; | ||
/** @type {string[]} */ | ||
let tagStringValues = await StringUtils.maskNull(await this.queryKeys.getStrings(tag)); | ||
query[`${intTagToString(tag)}.Value`] = tagStringValues.join(","); | ||
} | ||
return query; | ||
} | ||
|
||
cleanEmptyQuery(query) { | ||
let clonedQuery = _.cloneDeep(query); | ||
for (let key in query) { | ||
if (!query[key]) | ||
delete clonedQuery[key]; | ||
} | ||
return clonedQuery; | ||
} | ||
|
||
async getMongoQuery(query) { | ||
return await convertRequestQueryToMongoQuery( | ||
this.cleanEmptyQuery(query) | ||
); | ||
} | ||
} | ||
|
||
module.exports.DimseQueryBuilder = DimseQueryBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { default: Tag } = require("@dcm4che/data/Tag"); | ||
|
||
const queryTagsOfEachLevel = { | ||
"patient": [ | ||
Tag.PatientName, | ||
Tag.PatientID, | ||
Tag.PatientBirthDate | ||
], | ||
"study": [ | ||
Tag.PatientID, | ||
Tag.StudyInstanceUID, | ||
Tag.StudyDate, | ||
Tag.StudyTime, | ||
Tag.AccessionNumber | ||
], | ||
"series": [ | ||
Tag.PatientID, | ||
Tag.StudyInstanceUID, | ||
Tag.SeriesInstanceUID, | ||
Tag.Modality, | ||
Tag.SeriesNumber | ||
], | ||
"instance": [ | ||
Tag.PatientID, | ||
Tag.StudyInstanceUID, | ||
Tag.SeriesInstanceUID, | ||
Tag.SOPInstanceUID, | ||
Tag.SOPClassUID, | ||
Tag.InstanceNumber | ||
] | ||
}; | ||
|
||
module.exports.queryTagsOfEachLevel = queryTagsOfEachLevel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* | ||
* @param {number} tag | ||
*/ | ||
function intTagToString(tag) { | ||
return tag.toString(16).padStart(8, "0"); | ||
} | ||
|
||
module.exports.intTagToString = intTagToString; |
Binary file modified
BIN
+1.22 KB
(110%)
models/DICOM/dcm4che/javaNode/dcm4chee/lib/qrscp/dcm777-5.29.2.jar
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.