wangxiaoshuang 2025-05-29 17:23:26 +08:00
parent c01a01f306
commit aabcd91635
6 changed files with 342 additions and 209 deletions

26
app.js
View File

@ -3,7 +3,7 @@ const moment = require('moment');
const path = require('path') const path = require('path')
const chalk = require('chalk') const chalk = require('chalk')
const PNG16Convertor = require('./app/microprogram/PNG16Convertor.js'); const PNG16Convertor = require('./app/microprogram/PNG16Convertor.js');
const child_process = require('child_process'); // const child_process = require('child_process');
module.exports = app => { module.exports = app => {
app.beforeStart(async () => { app.beforeStart(async () => {
// 应用会等待这个函数执行完成才启动 // 应用会等待这个函数执行完成才启动
@ -15,21 +15,21 @@ module.exports = app => {
// } catch (error) { // } catch (error) {
// throw new Error('初始化数据失败', error); // throw new Error('初始化数据失败', error);
// } // }
['DICOM', 'SCP_STORE'].forEach(element => { // ['DICOM', 'SCP_STORE'].forEach(element => {
try { // try {
ctx.service.util.createDirectory(path.join(__dirname, `app/public/${element}`)) // ctx.service.util.createDirectory(path.join(__dirname, `app/public/${element}`))
} catch (error) { // } catch (error) {
console.error(error) // console.error(error)
} // }
}); // });
// child_process.exec(CMD, (error, stderr, stdout) => { // child_process.exec(CMD, (error, stderr, stdout) => {
// }) // })
// try { try {
// await ctx.service.util.storesPython() await ctx.service.util.storesPython()
// } catch (error) { } catch (error) {
// console.error(error) console.error(error)
// } }
moment.locale('zh-cn') moment.locale('zh-cn')

View File

@ -4,13 +4,13 @@ const BaseController = require("./base");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
function getObjectMkdir (url) { function getObjectMkdir(url) {
let index = url.lastIndexOf("/") let index = url.lastIndexOf("/")
let a = url.substring(0,index); let a = url.substring(0, index);
return a return a
} }
function getObjectName (url) { function getObjectName(url) {
var value = url var value = url
var str = value.split("/"); //https://进行分割, var str = value.split("/"); //https://进行分割,
var name = str[str.length - 1] var name = str[str.length - 1]
@ -18,7 +18,7 @@ function getObjectName (url) {
} }
function parseDicomFile(file, uploadQueues, path) { function parseDicomFile(file, uploadQueues, path) {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
var data = dicomParser.parseDicom(file) var data = dicomParser.parseDicom(file)
var studyUid = data.string('x0020000d') var studyUid = data.string('x0020000d')
@ -26,7 +26,7 @@ function parseDicomFile(file, uploadQueues, path) {
while ( while (
studyIndex < uploadQueues.length && studyIndex < uploadQueues.length &&
uploadQueues[studyIndex].dicomInfo.studyUid !== studyUid uploadQueues[studyIndex].dicomInfo.studyUid !== studyUid
) { ) {
++studyIndex ++studyIndex
} }
if (studyIndex >= uploadQueues.length) { if (studyIndex >= uploadQueues.length) {
@ -40,7 +40,7 @@ function parseDicomFile(file, uploadQueues, path) {
if (time) { if (time) {
time = `${time.substring(0, 2)}:${time.substring(2, 4)}:${time.substring(4, 6)}` time = `${time.substring(0, 2)}:${time.substring(2, 4)}:${time.substring(4, 6)}`
} }
if(date){ if (date) {
studyTime = time ? `${date} ${time}` : `${date} 00:00:00` studyTime = time ? `${date} ${time}` : `${date} 00:00:00`
} }
uploadQueues.push({ uploadQueues.push({
@ -85,7 +85,7 @@ function parseDicomFile(file, uploadQueues, path) {
while ( while (
instanceIndex < fileList.length && instanceIndex < fileList.length &&
fileList[instanceIndex].instanceUid !== instanceUid fileList[instanceIndex].instanceUid !== instanceUid
) { ) {
++instanceIndex ++instanceIndex
} }
if (instanceIndex >= fileList.length) { if (instanceIndex >= fileList.length) {
@ -97,7 +97,7 @@ function parseDicomFile(file, uploadQueues, path) {
var seriesUid = data.string('x0020000e') var seriesUid = data.string('x0020000e')
var seriesList = uploadQueues[studyIndex].seriesList var seriesList = uploadQueues[studyIndex].seriesList
var seriesItem = seriesList.find(function(item) { var seriesItem = seriesList.find(function (item) {
return item.seriesUid === seriesUid return item.seriesUid === seriesUid
}) })
if (!seriesItem) { if (!seriesItem) {
@ -111,7 +111,7 @@ function parseDicomFile(file, uploadQueues, path) {
seriesList.push(seriesItem) seriesList.push(seriesItem)
} }
var instanceList = seriesItem.instanceList var instanceList = seriesItem.instanceList
var instanceItem = instanceList.find(function(item) { var instanceItem = instanceList.find(function (item) {
return item.instanceUid === instanceUid return item.instanceUid === instanceUid
}) })
if (!instanceItem) { if (!instanceItem) {
@ -139,12 +139,12 @@ class PacsController extends BaseController {
super(props); super(props);
} }
//获取pacs位置 //获取pacs位置
async getPACS(){ async getPACS() {
try{ try {
console.log(this.ctx.request.query) console.log(this.ctx.request.query)
let pacs = await this.ctx.model.Pacs.find(this.ctx.request.query).select("_id aet host port mode description") let pacs = await this.ctx.model.Pacs.find(this.ctx.request.query).select("_id aet host port mode description")
return this.success(pacs) return this.success(pacs)
}catch (error) { } catch (error) {
return this.error(error) return this.error(error)
} }
} }
@ -156,11 +156,13 @@ class PacsController extends BaseController {
TaskCode: 'string', TaskCode: 'string',
}) })
let config = await this.service.config.getConfig(); let config = await this.service.config.getConfig();
console.log(config, 'config')
let a = await this.ctx.service.pacs.findFromPacs(this.ctx.request.body, config) let a = await this.ctx.service.pacs.findFromPacs(this.ctx.request.body, config)
console.log(a, 'a')
if (a) { if (a) {
let $in = a.map(v => {return v.SeriesInstanceUID}) let $in = a.map(v => { return v.SeriesInstanceUID })
console.log($in) console.log($in)
let list = await this.ctx.model.Series.find({SeriesInstanceUID: {$in: $in}}) let list = await this.ctx.model.Series.find({ SeriesInstanceUID: { $in: $in } })
// let list = await this.ctx.model.Pacs.find({}) // let list = await this.ctx.model.Pacs.find({})
console.log(list) console.log(list)
let newA = a.map(v => { let newA = a.map(v => {
@ -196,7 +198,7 @@ class PacsController extends BaseController {
TaskCode: 'string', TaskCode: 'string',
seriesList: 'array' seriesList: 'array'
}) })
let {pacs_id, seriesList,trialId,siteId,subjectId,subjectVisitId, userName, userId, task_id, trialCode, subjectCode, TaskCode} = this.ctx.request.body let { pacs_id, seriesList, trialId, siteId, subjectId, subjectVisitId, userName, userId, task_id, trialCode, subjectCode, TaskCode } = this.ctx.request.body
let config = await this.service.config.getConfig(); let config = await this.service.config.getConfig();
for (let i = 0; i < seriesList.length; i++) { for (let i = 0; i < seriesList.length; i++) {
let series = seriesList[i] let series = seriesList[i]
@ -210,7 +212,7 @@ class PacsController extends BaseController {
userName: userName, userName: userName,
userId: userId userId: userId
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
} }
let directoryPath = config.ossPacsPath + `/${trialCode}/${subjectCode}/${TaskCode}/${userId}/` let directoryPath = config.ossPacsPath + `/${trialCode}/${subjectCode}/${TaskCode}/${userId}/`
let pathList = fs.readdirSync(directoryPath) let pathList = fs.readdirSync(directoryPath)
@ -220,7 +222,7 @@ class PacsController extends BaseController {
let file = fs.readFileSync(item) let file = fs.readFileSync(item)
await parseDicomFile(file, uploadQueues, item) await parseDicomFile(file, uploadQueues, item)
} }
console.log(uploadQueues) console.log(uploadQueues, 'uploadQueues')
const Authorization = this.ctx.get('Authorization'); const Authorization = this.ctx.get('Authorization');
let arr = [] let arr = []
for (let i = 0; i < uploadQueues.length; ++i) { for (let i = 0; i < uploadQueues.length; ++i) {
@ -235,7 +237,7 @@ class PacsController extends BaseController {
visitTaskId: task_id, visitTaskId: task_id,
Authorization: Authorization, Authorization: Authorization,
} }
arr.push(this.ctx.service.pacs.archiveStudy(uploadQueues, i ,info, config)) arr.push(this.ctx.service.pacs.archiveStudy(uploadQueues, i, info, config))
} }
let a = await Promise.all(arr) let a = await Promise.all(arr)
// 获取 // 获取
@ -245,7 +247,7 @@ class PacsController extends BaseController {
} }
} }
async pushImage() { async pushImage() {
try{ try {
this.ctx.validate({ this.ctx.validate({
pacs_id: 'string', pacs_id: 'string',
imagesList: 'array', imagesList: 'array',
@ -257,10 +259,12 @@ class PacsController extends BaseController {
let { let {
pacs_id, imagesList, task_id, trialCode, subjectCode, TaskCode pacs_id, imagesList, task_id, trialCode, subjectCode, TaskCode
} = this.ctx.request.body } = this.ctx.request.body
let pacs = await this.ctx.model.Pacs.findOne({_id: pacs_id}) let pacs = await this.ctx.model.Pacs.findOne({ _id: pacs_id })
let config = await this.service.config.getConfig(); // let config = await this.service.config.getConfig();
let downloadErrorList = [], downloadsuccessList = [] let config = {}
let downloadErrorList = [], downloadsuccessList = []
let studyList = [] let studyList = []
config.ossPacsPath = path.join(__dirname, "../public/DICOM")
for (let i = 0; i < imagesList.length; i++) { for (let i = 0; i < imagesList.length; i++) {
let image = imagesList[i] let image = imagesList[i]
fs.mkdirSync(config.ossPacsPath + getObjectMkdir(`/${trialCode}/${subjectCode}/${TaskCode}/initial_data/1`), { recursive: true }); fs.mkdirSync(config.ossPacsPath + getObjectMkdir(`/${trialCode}/${subjectCode}/${TaskCode}/initial_data/1`), { recursive: true });
@ -273,7 +277,7 @@ class PacsController extends BaseController {
status: '下载中', status: '下载中',
downloadCount: imagesList.length downloadCount: imagesList.length
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
if (!~studyList.indexOf(`${config.ossPacsPath}/${trialCode}/${subjectCode}/${TaskCode}/initial_data`)) { if (!~studyList.indexOf(`${config.ossPacsPath}/${trialCode}/${subjectCode}/${TaskCode}/initial_data`)) {
studyList.push(`${config.ossPacsPath}/${trialCode}/${subjectCode}/${TaskCode}/initial_data`) studyList.push(`${config.ossPacsPath}/${trialCode}/${subjectCode}/${TaskCode}/initial_data`)
} }
@ -285,7 +289,7 @@ class PacsController extends BaseController {
$set: { $set: {
status: '下载完成', status: '下载完成',
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
// 开始推送 // 开始推送
for (let i = 0; i < studyList.length; i++) { for (let i = 0; i < studyList.length; i++) {
let study = studyList[i] let study = studyList[i]
@ -296,7 +300,7 @@ class PacsController extends BaseController {
$set: { $set: {
status: '推送中', status: '推送中',
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
} }
await this.ctx.model.Status.findOneAndUpdate({ await this.ctx.model.Status.findOneAndUpdate({
task_id: task_id task_id: task_id
@ -304,15 +308,15 @@ class PacsController extends BaseController {
$set: { $set: {
status: '推送完成', status: '推送完成',
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
return this.success({downloadErrorList, downloadsuccessList}) return this.success({ downloadErrorList, downloadsuccessList })
}catch (error) { } catch (error) {
return this.error(error) return this.error(error)
} }
} }
//新增pacs位置 //新增pacs位置
async addPACS(){ async addPACS() {
try { try {
this.ctx.validate({ this.ctx.validate({
trialId: 'string', trialId: 'string',
@ -321,15 +325,15 @@ class PacsController extends BaseController {
aet: 'string', aet: 'string',
}) })
let { let {
host,port,aet,trialId host, port, aet, trialId
} = this.ctx.request.body } = this.ctx.request.body
let para = this.ctx.request.body let para = this.ctx.request.body
let pacs = await this.ctx.model.Pacs.findOne({ let pacs = await this.ctx.model.Pacs.findOne({
host,port,aet,trialId host, port, aet, trialId
}) })
if(pacs){ if (pacs) {
return this.error("PACS位置已存在",60001) return this.error("PACS位置已存在", 60001)
}else{ } else {
pacs = this.ctx.model.Pacs(para) pacs = this.ctx.model.Pacs(para)
let result = await pacs.save() let result = await pacs.save()
return this.success(result) return this.success(result)
@ -346,7 +350,7 @@ class PacsController extends BaseController {
aet: 'string', aet: 'string',
}) })
let { let {
_id, host,port,aet,mode, trialId, description _id, host, port, aet, mode, trialId, description
} = this.ctx.request.body } = this.ctx.request.body
let para = this.ctx.request.body let para = this.ctx.request.body
let result let result
@ -361,11 +365,11 @@ class PacsController extends BaseController {
mode: mode, mode: mode,
description: description description: description
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
return this.success(result) return this.success(result)
} }
//删除pacs位置 //删除pacs位置
async delPACS(){ async delPACS() {
try { try {
this.ctx.validate({ this.ctx.validate({
pacs_id: { pacs_id: {
@ -377,11 +381,11 @@ class PacsController extends BaseController {
pacs_id pacs_id
} = this.ctx.request.body } = this.ctx.request.body
let pacs = await this.ctx.model.Pacs.findOne({ let pacs = await this.ctx.model.Pacs.findOne({
_id:pacs_id _id: pacs_id
}); });
if (!pacs) throw '未找到该PACS' if (!pacs) throw '未找到该PACS'
await this.ctx.model.Pacs.deleteOne({ await this.ctx.model.Pacs.deleteOne({
_id:pacs_id _id: pacs_id
}); });
return this.success() return this.success()
} catch (e) { } catch (e) {
@ -393,7 +397,7 @@ class PacsController extends BaseController {
async testConnection() { async testConnection() {
try { try {
this.ctx.validate({ this.ctx.validate({
pacs_ids:"array" pacs_ids: "array"
}) })
} catch (error) { } catch (error) {
return this.error(error) return this.error(error)
@ -401,7 +405,7 @@ class PacsController extends BaseController {
try { try {
let { pacs_ids } = this.ctx.request.body let { pacs_ids } = this.ctx.request.body
if(!pacs_ids.length) return this.error("参数为空") if (!pacs_ids.length) return this.error("参数为空")
let result = await this.ctx.service.pacs.testConnection(pacs_ids) let result = await this.ctx.service.pacs.testConnection(pacs_ids)
return this.success(result) return this.success(result)
} catch (error) { } catch (error) {
@ -412,54 +416,54 @@ class PacsController extends BaseController {
return this.error(msg) return this.error(msg)
} }
} }
async wxFindFromPacs () { async wxFindFromPacs() {
try { try {
let { let {
PatientID PatientID
} = this.ctx.request.body } = this.ctx.request.body
if (!PatientID) { if (!PatientID) {
throw 'PatientID必填' throw 'PatientID必填'
}
let result = await this.ctx.service.pacs.findFromPacs({PatientID: PatientID})
if (result.length > 0) {
let item = result[0]
let isHas = await this.ctx.model.Dcmtemp.findOne({StudyInstanceUID: item.StudyInstanceUID})
if (isHas) {
this.ctx.model.Dcmtemp.findOneAndUpdate({
_id: isHas._id
}, {
$set: {
host: item.host,
port: item.port,
aet: item.aet,
done: 0,
NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances,
StudyInstanceUID: item.StudyInstanceUID,
status: 0
}
}).exec()
} else {
let params = {
host: item.host,
port: item.port,
aet: item.aet,
done: 0,
NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances,
StudyInstanceUID: item.StudyInstanceUID,
status: 0
} }
let m = new this.ctx.model.Dcmtemp(params) let result = await this.ctx.service.pacs.findFromPacs({ PatientID: PatientID })
m.save() if (result.length > 0) {
} let item = result[0]
let isHas = await this.ctx.model.Dcmtemp.findOne({ StudyInstanceUID: item.StudyInstanceUID })
if (isHas) {
this.ctx.model.Dcmtemp.findOneAndUpdate({
_id: isHas._id
}, {
$set: {
host: item.host,
port: item.port,
aet: item.aet,
done: 0,
NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances,
StudyInstanceUID: item.StudyInstanceUID,
status: 0
}
}).exec()
} else {
let params = {
host: item.host,
port: item.port,
aet: item.aet,
done: 0,
NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances,
StudyInstanceUID: item.StudyInstanceUID,
status: 0
}
let m = new this.ctx.model.Dcmtemp(params)
m.save()
}
}
return this.success(result)
} catch (error) {
let msg = error
if (error.message) {
msg = error.message.split('\n')
}
return this.error(msg)
} }
return this.success(result)
} catch (error) {
let msg = error
if (error.message) {
msg = error.message.split('\n')
}
return this.error(msg)
}
} }
//查询 //查询
@ -477,16 +481,16 @@ class PacsController extends BaseController {
} }
//获取下载进度 //获取下载进度
async percent(){ async percent() {
try { try {
this.ctx.validate({ this.ctx.validate({
task_ids:"array" task_ids: "array"
}) })
} catch (error) { } catch (error) {
return this.error(error) return this.error(error)
} }
let { task_ids } = this.ctx.request.body let { task_ids } = this.ctx.request.body
let result = await this.ctx.model.Status.find({task_id: {$in: task_ids}}) let result = await this.ctx.model.Status.find({ task_id: { $in: task_ids } })
return this.success(result) return this.success(result)
} }
//下载 //下载
@ -502,35 +506,35 @@ class PacsController extends BaseController {
let { para } = this.ctx.request.body let { para } = this.ctx.request.body
try { try {
for (let i = 0; i < para.length; i++) { for (let i = 0; i < para.length; i++) {
let item = para[i] let item = para[i]
let isHas = await this.ctx.model.Dcmtemp.findOne({StudyInstanceUID: item.StudyInstanceUID}) let isHas = await this.ctx.model.Dcmtemp.findOne({ StudyInstanceUID: item.StudyInstanceUID })
if (isHas) { if (isHas) {
this.ctx.model.Dcmtemp.findOneAndUpdate({ this.ctx.model.Dcmtemp.findOneAndUpdate({
_id: isHas._id _id: isHas._id
}, { }, {
$set: { $set: {
host: item.host, host: item.host,
port: item.port, port: item.port,
aet: item.aet, aet: item.aet,
done: 0, done: 0,
NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances, NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances,
StudyInstanceUID: item.StudyInstanceUID, StudyInstanceUID: item.StudyInstanceUID,
status: 0 status: 0
} }
}).exec() }).exec()
} else { } else {
let params = { let params = {
host: item.host, host: item.host,
port: item.port, port: item.port,
aet: item.aet, aet: item.aet,
done: 0, done: 0,
NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances, NumberOfStudyRelatedInstances: item.NumberOfStudyRelatedInstances,
StudyInstanceUID: item.StudyInstanceUID, StudyInstanceUID: item.StudyInstanceUID,
status: 0 status: 0
}
let m = new this.ctx.model.Dcmtemp(params)
m.save()
} }
let m = new this.ctx.model.Dcmtemp(params)
m.save()
}
} }
return this.success() return this.success()
} catch (error) { } catch (error) {
@ -539,8 +543,8 @@ class PacsController extends BaseController {
} }
//study抽取report //study抽取report
async getLocalPort () { async getLocalPort() {
return this.success({port: this.config.site.PACS_SCP_PORT, aet: this.config.site.PACS_SCP_AET}) return this.success({ port: this.config.site.PACS_SCP_PORT, aet: this.config.site.PACS_SCP_AET })
} }
} }
module.exports = PacsController; module.exports = PacsController;

View File

@ -2,6 +2,7 @@
const Service = require("egg").Service; const Service = require("egg").Service;
const OSS = require('ali-oss'); const OSS = require('ali-oss');
const http = require('http');
function fileToBlob(file) { function fileToBlob(file) {
// 创建 FileReader 对象 // 创建 FileReader 对象
let reader = new FileReader(); let reader = new FileReader();
@ -32,26 +33,33 @@ class ImageService extends Service {
*/ */
async downloadImage(path, osPath, config) { async downloadImage(path, osPath, config) {
try { try {
const client = new OSS({ let client = await this.getClient()
region: config.region, if (client) {
accessKeyId: config.accessKeyId, const result = await client.get(path, osPath);
accessKeySecret: config.accessKeySecret, return result
bucket: config.bucket }
}); return false
const result = await client.get(path, osPath); // const client = new OSS({
return result // region: config.region,
// accessKeyId: config.accessKeyId,
// accessKeySecret: config.accessKeySecret,
// bucket: config.bucket
// });
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
} }
async dcmUpload (name, file, config){ dcmUpload(name, file, config) {
const client = new OSS({
region: config.region, // const client = new OSS({
accessKeyId: config.accessKeyId, // region: config.region,
accessKeySecret: config.accessKeySecret, // accessKeyId: config.accessKeyId,
bucket: config.bucket // accessKeySecret: config.accessKeySecret,
}); // bucket: config.bucket
// });
return new Promise(async resolve => { return new Promise(async resolve => {
let client = await this.getClient()
try { try {
let res = await client.put(name, file) let res = await client.put(name, file)
resolve({ resolve({
@ -63,5 +71,54 @@ class ImageService extends Service {
} }
}) })
} }
async getClient() {
if (this.ctx.state.ossConfig && this.isCredentialsExpired(this.ctx.state.ossConfig.expiration)) return new OSS(this.ctx.state.ossConfig)
let config = null
let res = await this.getOssConfig()
if (res && res.IsSuccess) {
config = res.Result[res.Result.ObjectStoreUse]
config.bucket = config.bucketName
config.basePath = config.viewEndpoint;
config.stsToken = config.securityToken
config.timeout = 10 * 60 * 1000
this.ctx.state.config = config
return new OSS(config)
}
return false
}
getOssConfig() {
return new Promise((res, rej) => {
const Authorization = this.ctx.get('Authorization');
let options = {
hostname: '106.14.89.110',
port: 30000,
path: "/user/GetObjectStoreToken",
method: "GET",
headers: {
Authorization: Authorization
}
}
const req = http.request(options, r => {
let data = '';
r.on('data', chunk => {
data += chunk
})
r.on('end', () => {
res(JSON.parse(data))
})
})
req.end()
})
}
isCredentialsExpired(credentials) {
if (!credentials) {
return true;
}
const expireDate = new Date(credentials);
const now = new Date();
// 如果有效期不足五分钟,视为过期。
return expireDate.getTime() - now.getTime() <= 300000;
}
} }
module.exports = ImageService; module.exports = ImageService;

View File

@ -3,13 +3,14 @@ const child_process = require('child_process');
const fs = require('fs'); const fs = require('fs');
const readline = require('readline'); const readline = require('readline');
const path = require('path'); const path = require('path');
const axios = require('axios') // const axios = require('axios')
const http = require('http');
const request = require('request'); const request = require('request');
var querystring = require('querystring'); var querystring = require('querystring');
function getObjectMkdir (url) { function getObjectMkdir(url) {
let index = url.lastIndexOf("/") let index = url.lastIndexOf("/")
let path = url.substring(0,index); let path = url.substring(0, index);
return path return path
} }
@ -61,24 +62,24 @@ class PacsService extends Service {
} }
//测试连接 //测试连接
async testConnection(pacs_ids){ async testConnection(pacs_ids) {
let result = [] let result = []
let PACS_SCP_AET = this.config.site.PACS_SCP_AET let PACS_SCP_AET = this.config.site.PACS_SCP_AET
for(let i=0;i<pacs_ids.length;i++){ for (let i = 0; i < pacs_ids.length; i++) {
try{ try {
let pacs_id = pacs_ids[i] let pacs_id = pacs_ids[i]
let pacs = await this.ctx.model.Pacs.findOne({_id:pacs_id}) let pacs = await this.ctx.model.Pacs.findOne({ _id: pacs_id })
if(!pacs){ if (!pacs) {
result.push("pacs位置不存在") result.push("pacs位置不存在")
continue continue
} }
let { let {
aet,host,port aet, host, port
} = pacs } = pacs
let para = `-v ${host} ${port} -aec ${aet} -aet ${PACS_SCP_AET}` let para = `-v ${host} ${port} -aec ${aet} -aet ${PACS_SCP_AET}`
let r = await this.echoscu(para) let r = await this.echoscu(para)
result.push(r) result.push(r)
}catch(e){ } catch (e) {
result.push(e) result.push(e)
} }
} }
@ -115,21 +116,22 @@ class PacsService extends Service {
} }
//查询 //查询
async findFromPacs(body, config){ async findFromPacs(body, config) {
try { try {
let pacs = await this.ctx.model.Pacs.findOne({_id: body.pacs_id}).select("aet host port") let pacs = await this.ctx.model.Pacs.findOne({ _id: body.pacs_id }).select("aet host port")
let result = [] let result = []
if (!pacs) throw "pacs位置不存在" if (!pacs) throw "pacs位置不存在"
let { let {
aet, host, port aet, host, port
} = pacs } = pacs
let dict = await this.parseQRDist() let dict = await this.parseQRDist()
console.log(dict, 'dict')
for (let modeIndex = 0; modeIndex < body.modeList.length; modeIndex++) { for (let modeIndex = 0; modeIndex < body.modeList.length; modeIndex++) {
let mode = body.modeList[modeIndex] let mode = body.modeList[modeIndex]
for (let StudyInstanceUIDIndex = 0; StudyInstanceUIDIndex < body.StudyInstanceUidList.length; StudyInstanceUIDIndex++) { for (let StudyInstanceUIDIndex = 0; StudyInstanceUIDIndex < body.StudyInstanceUidList.length; StudyInstanceUIDIndex++) {
let StudyInstanceUID = body.StudyInstanceUidList[StudyInstanceUIDIndex] let StudyInstanceUID = body.StudyInstanceUidList[StudyInstanceUIDIndex]
let param = { let param = {
PatientID: `${body.trialCode}-${body.subjectCode}`, PatientID: `${body.trialCode}_${body.subjectCode}`,
StudyDescription: '', StudyDescription: '',
StudyID: '', StudyID: '',
PatientName: '', PatientName: '',
@ -152,7 +154,7 @@ class PacsService extends Service {
//查询指定pacs //查询指定pacs
//循环pacs 获取数据 //循环pacs 获取数据
let para = `${host} ${port} -aec ${aet} -aet ${config.aet} -S -k QueryRetrieveLevel=SERIES` + search let para = `${host} ${port} -aec ${aet} -aet ${config.aet} -S -k QueryRetrieveLevel=SERIES` + search
let resp = await this.findscu(para, {aet, host, port}) let resp = await this.findscu(para, { aet, host, port })
result = Object.assign(result, resp) result = Object.assign(result, resp)
} }
} }
@ -167,18 +169,19 @@ class PacsService extends Service {
SeriesNumber: result[i].SeriesNumber, SeriesNumber: result[i].SeriesNumber,
PatientID: result[i].PatientID PatientID: result[i].PatientID
} }
}, {upsert: true, new: true}) }, { upsert: true, new: true })
} }
} }
return result return result
} catch (e) { } catch (e) {
return(e) return (e)
} }
} }
async storescu(pacs, config, study) { async storescu(pacs, config, study) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
let CMD = `dcmsend -v +sd -aec ${pacs.aet} -aet ${config.aet} ${pacs.host} ${pacs.port} ${study}` // let CMD = `dcmsend -v +sd -aec ${pacs.aet} -aet ${config.aet} ${pacs.host} ${pacs.port} ${study}`
let CMD = `dcmsend -v +sd -aec ${pacs.aet} -aet AET ${pacs.host} ${pacs.port} ${study}`
console.log(CMD) console.log(CMD)
child_process.exec(CMD, { child_process.exec(CMD, {
timeout: 300000, timeout: 300000,
@ -201,7 +204,7 @@ class PacsService extends Service {
}) })
} }
//^^ //^^
async findscu(para,obj) { async findscu(para, obj) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let CMD = `findscu ${para}` let CMD = `findscu ${para}`
console.log(CMD) console.log(CMD)
@ -214,13 +217,13 @@ class PacsService extends Service {
reject(error) reject(error)
} else if (stderr) { } else if (stderr) {
let str = stderr.toString().replace(/\u0000/g, "") let str = stderr.toString().replace(/\u0000/g, "")
console.log('stderr',str) console.log('stderr', str)
let resp = await this.parseFindResult(str,obj) let resp = await this.parseFindResult(str, obj)
resolve(resp) resolve(resp)
} else if (stdout) { } else if (stdout) {
let str = stdout.toString().replace(/\u0000/g, "") let str = stdout.toString().replace(/\u0000/g, "")
console.log('stdout', str) console.log('stdout', str)
let resp = await this.parseFindResult(str,obj) let resp = await this.parseFindResult(str, obj)
resolve(resp) resolve(resp)
} else { } else {
resolve() resolve()
@ -267,7 +270,7 @@ class PacsService extends Service {
} }
//^^ //^^
//整理查询结果 //整理查询结果
async parseFindResult(str,obj) { async parseFindResult(str, obj) {
let result = [] let result = []
let dict = await this.parseQRDist() let dict = await this.parseQRDist()
console.log(dict) console.log(dict)
@ -305,7 +308,7 @@ class PacsService extends Service {
console.log('result', result) console.log('result', result)
return result return result
} }
async setDcmTempState (dcmtempList, para, state, done) { async setDcmTempState(dcmtempList, para, state, done) {
try { try {
if (dcmtempList) { if (dcmtempList) {
let dcmtempId = dcmtempList._id let dcmtempId = dcmtempList._id
@ -339,9 +342,9 @@ class PacsService extends Service {
//下载 //下载
async movescu(body, series, config) { async movescu(body, series, config) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try{ try {
let {pacs_id, seriesList, userName, userId, task_id, trialCode, subjectCode, TaskCode} = body let { pacs_id, seriesList, userName, userId, task_id, trialCode, subjectCode, TaskCode } = body
let pacs = await this.ctx.model.Pacs.findOne({_id: pacs_id}).select("aet host port") let pacs = await this.ctx.model.Pacs.findOne({ _id: pacs_id }).select("aet host port")
if (!pacs) throw "pacs位置不存在" if (!pacs) throw "pacs位置不存在"
fs.mkdirSync(config.ossPacsPath + getObjectMkdir(`/${trialCode}/${subjectCode}/${TaskCode}/${userId}/1`), { recursive: true }); fs.mkdirSync(config.ossPacsPath + getObjectMkdir(`/${trialCode}/${subjectCode}/${TaskCode}/${userId}/1`), { recursive: true });
let directoryPath = config.ossPacsPath + `/${trialCode}/${subjectCode}/${TaskCode}/${userId}/` let directoryPath = config.ossPacsPath + `/${trialCode}/${subjectCode}/${TaskCode}/${userId}/`
@ -354,10 +357,10 @@ class PacsService extends Service {
movescu.stderr.on('data', (data) => { movescu.stderr.on('data', (data) => {
console.log(`move======pending: ${data}`); console.log(`move======pending: ${data}`);
}) })
movescu.on('close', async (code, data)=> { movescu.on('close', async (code, data) => {
resolve() resolve()
}); });
}catch(e){ } catch (e) {
console.log(e) console.log(e)
} }
}) })
@ -365,14 +368,14 @@ class PacsService extends Service {
//^^ //^^
//读取文件夹子文件个数 //读取文件夹子文件个数
async readNum(fileName){ async readNum(fileName) {
let filePath = `${this.config.site.PACS_SCP_STORE}/${fileName}` let filePath = `${this.config.site.PACS_SCP_STORE}/${fileName}`
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.readdir(filePath,(err,files)=>{ fs.readdir(filePath, (err, files) => {
if(err){ if (err) {
//未下载 //未下载
resolve(-1) resolve(-1)
}else{ } else {
resolve(files.length) resolve(files.length)
} }
}) })
@ -380,17 +383,17 @@ class PacsService extends Service {
} }
//保存patient //保存patient
async dicomInfoSave(filesName,user_id){ async dicomInfoSave(filesName, user_id) {
let filesPath = `${this.config.site.PACS_SCP_STORE}/${filesName}` let filesPath = `${this.config.site.PACS_SCP_STORE}/${filesName}`
fs.readdir(filesPath,(err,files)=>{ fs.readdir(filesPath, (err, files) => {
if(err){ if (err) {
}else{ } else {
for(let i=0;i<1;i++){ for (let i = 0; i < 1; i++) {
let fileName = files[i] let fileName = files[i]
let filePath = `${filesPath}/${fileName}` let filePath = `${filesPath}/${fileName}`
let fileData = fs.readFileSync(filePath) let fileData = fs.readFileSync(filePath)
this.setStudy(fileData,user_id) this.setStudy(fileData, user_id)
} }
} }
}) })
@ -452,33 +455,75 @@ class PacsService extends Service {
} }
addOrUpdateArchiveStudy(data, Authorization, config) { addOrUpdateArchiveStudy(data, Authorization, config) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios({ let options = {
method: 'post', hostname: '106.14.89.110',
data: data, port: 30000,
path: "/Study/preArchiveDicomStudy",
method: "POST",
headers: { headers: {
Authorization: Authorization Authorization: Authorization
}, }
url: config.eiscPath + '/api/Study/preArchiveDicomStudy' }
}).then(res => { const req = http.request(options, r => {
console.log(res.data) let data = '';
resolve(res.data) r.on('data', chunk => {
data += chunk
})
r.on('end', () => {
resolve(JSON.parse(data))
})
}) })
req.write(data)
req.end()
// axios({
// method: 'post',
// data: data,
// headers: {
// Authorization: Authorization
// },
// url: config.eiscPath + '/api/Study/preArchiveDicomStudy'
// }).then(res => {
// console.log(res.data)
// resolve(res.data)
// })
}) })
} }
preArchiveDicomStudy(info, config) { preArchiveDicomStudy(info, config) {
info.IsDicomReUpload = true info.IsDicomReUpload = true
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios({ let options = {
method: 'post', hostname: '106.14.89.110',
data: info, port: 30000,
path: "/Study/preArchiveDicomStudy",
method: "POST",
headers: { headers: {
Authorization: info.Authorization Authorization: info.Authorization
}, }
url: config.eiscPath + '/api/Study/preArchiveDicomStudy' }
}).then(res => { const req = http.request(options, r => {
console.log(res.data) let data = '';
resolve(res.data) r.on('data', chunk => {
data += chunk
})
r.on('end', () => {
resolve(JSON.parse(data))
})
}) })
req.write(info)
req.end()
// axios({
// method: 'post',
// data: info,
// headers: {
// Authorization: info.Authorization
// },
// url: config.eiscPath + '/api/Study/preArchiveDicomStudy'
// }).then(res => {
// console.log(res.data)
// resolve(res.data)
// })
}) })
} }
archiveStudy(uploadQueues, index, info, config) { archiveStudy(uploadQueues, index, info, config) {
@ -634,9 +679,9 @@ class PacsService extends Service {
let serie = await this.ctx.model.Series.findOne({ let serie = await this.ctx.model.Series.findOne({
SeriesInstanceUID: SeriesInstanceUID SeriesInstanceUID: SeriesInstanceUID
}) })
.populate({ .populate({
path: "images_ids", path: "images_ids",
}) })
let num = 1; let num = 1;
if (serie && serie.images_ids) { if (serie && serie.images_ids) {
for (let i = 0; i < serie.images_ids.length; i++) { for (let i = 0; i < serie.images_ids.length; i++) {

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
const { url } = require('inspector'); // const { url } = require('inspector');
const path = require('path'); const path = require('path');
module.exports = appInfo => { module.exports = appInfo => {
const config = exports = {}; const config = exports = {};
@ -76,6 +76,7 @@ module.exports = appInfo => {
config.logger = { config.logger = {
// level: 'ERROR', // level: 'ERROR',
dir: path.join(process.cwd(), 'logs'),
consoleLevel: 'DEBUG', consoleLevel: 'DEBUG',
appLogName: `${appInfo.name}-api.log`, //应用相关日志, appLogName: `${appInfo.name}-api.log`, //应用相关日志,
coreLogName: "web.log", //框架内核、插件日志。 coreLogName: "web.log", //框架内核、插件日志。
@ -126,7 +127,7 @@ module.exports = appInfo => {
config.jwt = { config.jwt = {
secret: "6YPhrbCSKLejwZ5F", secret: "6YPhrbCSKLejwZ5F",
exp:1000*24*60*60 //存在时间 单位位秒 exp: 1000 * 24 * 60 * 60 //存在时间 单位位秒
}; };
config.regexp = { config.regexp = {
@ -146,7 +147,20 @@ module.exports = appInfo => {
config.initData = {} config.initData = {}
config.png16 = {
}; config.static = {
prefix: '/',
dir: process.cwd() + '/public'
}
config.rundir = process.cwd() + '/run'
config.development = {
enable: false, // 禁用 egg-development 插件
}
config.watcher = { // 关闭文件监听
enable: false,
}
config.png16 = {
};
return config; return config;
}; };

View File

@ -42,8 +42,21 @@
"cov": "egg-bin cov", "cov": "egg-bin cov",
"lint": "eslint .", "lint": "eslint .",
"ci": "npm run lint && npm run cov", "ci": "npm run lint && npm run cov",
"build": "pkg . --targets node14-win-x64 --out-path ./dist --debug",
"autod": "autod" "autod": "autod"
}, },
"bin": "index.js",
"pkg": {
"assets": [
"./config/*.js",
"./app.js",
"./init.js",
"./app/**/*.js",
"./node_modules/nanoid/**/*",
"./node_modules/js-md5/**/*",
"./node_modules/egg-security/**/*"
]
},
"ci": { "ci": {
"version": "8" "version": "8"
}, },