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

24
app.js
View File

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

View File

@ -156,7 +156,9 @@ class PacsController extends BaseController {
TaskCode: 'string',
})
let config = await this.service.config.getConfig();
console.log(config, 'config')
let a = await this.ctx.service.pacs.findFromPacs(this.ctx.request.body, config)
console.log(a, 'a')
if (a) {
let $in = a.map(v => { return v.SeriesInstanceUID })
console.log($in)
@ -220,7 +222,7 @@ class PacsController extends BaseController {
let file = fs.readFileSync(item)
await parseDicomFile(file, uploadQueues, item)
}
console.log(uploadQueues)
console.log(uploadQueues, 'uploadQueues')
const Authorization = this.ctx.get('Authorization');
let arr = []
for (let i = 0; i < uploadQueues.length; ++i) {
@ -258,9 +260,11 @@ class PacsController extends BaseController {
pacs_id, imagesList, task_id, trialCode, subjectCode, TaskCode
} = this.ctx.request.body
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 config = {}
let downloadErrorList = [], downloadsuccessList = []
let studyList = []
config.ossPacsPath = path.join(__dirname, "../public/DICOM")
for (let i = 0; i < imagesList.length; i++) {
let image = imagesList[i]
fs.mkdirSync(config.ossPacsPath + getObjectMkdir(`/${trialCode}/${subjectCode}/${TaskCode}/initial_data/1`), { recursive: true });

View File

@ -2,6 +2,7 @@
const Service = require("egg").Service;
const OSS = require('ali-oss');
const http = require('http');
function fileToBlob(file) {
// 创建 FileReader 对象
let reader = new FileReader();
@ -32,26 +33,33 @@ class ImageService extends Service {
*/
async downloadImage(path, osPath, config) {
try {
const client = new OSS({
region: config.region,
accessKeyId: config.accessKeyId,
accessKeySecret: config.accessKeySecret,
bucket: config.bucket
});
let client = await this.getClient()
if (client) {
const result = await client.get(path, osPath);
return result
}
return false
// const client = new OSS({
// region: config.region,
// accessKeyId: config.accessKeyId,
// accessKeySecret: config.accessKeySecret,
// bucket: config.bucket
// });
} catch (e) {
console.log(e)
}
}
async dcmUpload (name, file, config){
const client = new OSS({
region: config.region,
accessKeyId: config.accessKeyId,
accessKeySecret: config.accessKeySecret,
bucket: config.bucket
});
dcmUpload(name, file, config) {
// const client = new OSS({
// region: config.region,
// accessKeyId: config.accessKeyId,
// accessKeySecret: config.accessKeySecret,
// bucket: config.bucket
// });
return new Promise(async resolve => {
let client = await this.getClient()
try {
let res = await client.put(name, file)
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;

View File

@ -3,7 +3,8 @@ const child_process = require('child_process');
const fs = require('fs');
const readline = require('readline');
const path = require('path');
const axios = require('axios')
// const axios = require('axios')
const http = require('http');
const request = require('request');
var querystring = require('querystring');
@ -124,12 +125,13 @@ class PacsService extends Service {
aet, host, port
} = pacs
let dict = await this.parseQRDist()
console.log(dict, 'dict')
for (let modeIndex = 0; modeIndex < body.modeList.length; modeIndex++) {
let mode = body.modeList[modeIndex]
for (let StudyInstanceUIDIndex = 0; StudyInstanceUIDIndex < body.StudyInstanceUidList.length; StudyInstanceUIDIndex++) {
let StudyInstanceUID = body.StudyInstanceUidList[StudyInstanceUIDIndex]
let param = {
PatientID: `${body.trialCode}-${body.subjectCode}`,
PatientID: `${body.trialCode}_${body.subjectCode}`,
StudyDescription: '',
StudyID: '',
PatientName: '',
@ -178,7 +180,8 @@ class PacsService extends Service {
async storescu(pacs, config, study) {
return new Promise((resolve, reject) => {
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)
child_process.exec(CMD, {
timeout: 300000,
@ -452,33 +455,75 @@ class PacsService extends Service {
}
addOrUpdateArchiveStudy(data, Authorization, config) {
return new Promise((resolve, reject) => {
axios({
method: 'post',
data: data,
let options = {
hostname: '106.14.89.110',
port: 30000,
path: "/Study/preArchiveDicomStudy",
method: "POST",
headers: {
Authorization: Authorization
},
url: config.eiscPath + '/api/Study/preArchiveDicomStudy'
}).then(res => {
console.log(res.data)
resolve(res.data)
}
}
const req = http.request(options, r => {
let 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) {
info.IsDicomReUpload = true
return new Promise((resolve, reject) => {
axios({
method: 'post',
data: info,
let options = {
hostname: '106.14.89.110',
port: 30000,
path: "/Study/preArchiveDicomStudy",
method: "POST",
headers: {
Authorization: info.Authorization
},
url: config.eiscPath + '/api/Study/preArchiveDicomStudy'
}).then(res => {
console.log(res.data)
resolve(res.data)
}
}
const req = http.request(options, r => {
let 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) {

View File

@ -1,5 +1,5 @@
'use strict';
const { url } = require('inspector');
// const { url } = require('inspector');
const path = require('path');
module.exports = appInfo => {
const config = exports = {};
@ -76,6 +76,7 @@ module.exports = appInfo => {
config.logger = {
// level: 'ERROR',
dir: path.join(process.cwd(), 'logs'),
consoleLevel: 'DEBUG',
appLogName: `${appInfo.name}-api.log`, //应用相关日志,
coreLogName: "web.log", //框架内核、插件日志。
@ -146,6 +147,19 @@ module.exports = appInfo => {
config.initData = {}
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;

View File

@ -42,8 +42,21 @@
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"build": "pkg . --targets node14-win-x64 --out-path ./dist --debug",
"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": {
"version": "8"
},