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 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 {
ctx.service.util.createDirectory(path.join(__dirname, `app/public/${element}`))
} catch (error) {
console.error(error)
}
});
// child_process.exec(CMD, (error, stderr, stdout) => {
// })
// try { // try {
// await ctx.service.util.storesPython() // 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) => {
// })
try {
await ctx.service.util.storesPython()
} catch (error) {
console.error(error)
}
moment.locale('zh-cn') moment.locale('zh-cn')

View File

@ -156,7 +156,9 @@ 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)
@ -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) {
@ -258,9 +260,11 @@ class PacsController extends BaseController {
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 config = {}
let downloadErrorList = [], downloadsuccessList = [] 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 });

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,
accessKeySecret: config.accessKeySecret,
bucket: config.bucket
});
const result = await client.get(path, osPath); const result = await client.get(path, osPath);
return result return result
}
return false
// const client = new OSS({
// 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,7 +3,8 @@ 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');
@ -124,12 +125,13 @@ class PacsService extends Service {
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: '',
@ -178,7 +180,8 @@ class PacsService extends Service {
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,
@ -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) {

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", //框架内核、插件日志。
@ -146,6 +147,19 @@ module.exports = appInfo => {
config.initData = {} 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 = { 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"
}, },