diff --git a/src/api/inspect/inspectpacsdata/index.ts b/src/api/inspect/inspectpacsdata/index.ts index 0cb974a..4f7f97a 100644 --- a/src/api/inspect/inspectpacsdata/index.ts +++ b/src/api/inspect/inspectpacsdata/index.ts @@ -55,5 +55,9 @@ export const PacsDataApi = { //更新pacs抓取数据对应项的item updatePacsDataitem: async (data: PacsDataVO) => { return await request.put({ url: `/inspect/pacs-data/updatePacsDataitem`, data }) + }, + //根据体检编号获取PACS数据 + getByMedicalSnAndType: async (medicalSn: string,type: string) => { + return await request.get({ url: `/inspect/pacs-data/getByMedicalSnAndType?medicalSn=${medicalSn}&type=${type}` }) } } diff --git a/src/api/inspect/inspectpatient/index.ts b/src/api/inspect/inspectpatient/index.ts index 0f096a3..d315860 100644 --- a/src/api/inspect/inspectpatient/index.ts +++ b/src/api/inspect/inspectpatient/index.ts @@ -65,6 +65,11 @@ export const PatientApi = { return await request.put({ url: `/inspect/patient/update`, data }) }, + //根据体检编号更新患者状态 + updatePatientStatus: async (medicalSn: string, status: number) => { + return await request.put({ url: `/inspect/patient/updatePatientStatus?medicalSn=` + medicalSn + `&status=` + status }) + }, + // 删除患者信息 deletePatient: async (id: number) => { return await request.delete({ url: `/inspect/patient/delete?id=` + id }) @@ -193,4 +198,5 @@ export const PatientApi = { url: `/inspect/patient/updateChiefinspector?medicalSn=${medicalSn}&chiefinspectorid=${chiefinspectorid}&chiefinspector=${chiefinspector}` }) } + } diff --git a/src/views/Department-entry/Batch-review.vue b/src/views/Department-entry/Batch-review.vue index 8ed05ac..6eecae4 100644 --- a/src/views/Department-entry/Batch-review.vue +++ b/src/views/Department-entry/Batch-review.vue @@ -69,7 +69,7 @@ import { PatientApi, type PatientVO } from '@/api/inspect/inspectpatient' import { ElMessage } from 'element-plus' import Pagination from '@/components/Pagination/index.vue' import dayjs from 'dayjs' -import { InspectOrgApi, InspectOrgVO } from '@/api/inspect/inspectorg/index' +import { InspectOrgApi } from '@/api/inspect/inspectorg/index' import { getUserProfile } from '@/api/system/user/profile' import { ElLoading } from 'element-plus' import { PacsDataApi } from '@/api/inspect/inspectpacsdata' @@ -124,7 +124,9 @@ const handleQuery = async () => { examhosname: examinfo.orgName, status: 0 } + const data = await PatientApi.getPatientPage(params) + list.value = data.list || [] total.value = data.total || 0 } @@ -160,7 +162,6 @@ const handleBatchReview = async () => { } const currentTimestamp = Date.now() - const currentDate = formatDate(new Date()) // 逐条处理选中的体检编号 for (const row of selectedRows.value) { @@ -172,163 +173,261 @@ const handleBatchReview = async () => { // 定义需要同步的类型 const types = ['XCG', 'NCG', 'SHQX', 'ECG', 'YBJC'] - // 首先检查每种类型是否已存在数据 - const existingDataPromises = types.map((type) => + // 并行检查所有类型数据是否存在(包括超声和心电图) + const allCheckPromises = [ + // 检查常规类型数据 + ...types.map((type) => + PacsDataApi.getPacsDataPage({ + code: medicalSn, + type: type, + pageNo: 1, + pageSize: 1 + }).catch((error) => { + console.warn(`检查${type}数据是否存在时出错:`, error) + return { list: [], type } + }).then(result => ({ ...result, type })) + ), + // 检查超声数据 PacsDataApi.getPacsDataPage({ code: medicalSn, - type: type, + type: 'US', pageNo: 1, pageSize: 1 }).catch((error) => { - console.warn(`检查${type}数据是否存在时出错:`, error) - return { list: [] } - }) - ) + console.warn('检查超声数据是否存在时出错:', error) + return { list: [], type: 'US' } + }).then(result => ({ ...result, type: 'US' })), + // 检查心电图数据 + PacsDataApi.getPacsDataPage({ + code: medicalSn, + type: 'ECG', + pageNo: 1, + pageSize: 1 + }).catch((error) => { + console.warn('检查心电图数据是否存在时出错:', error) + return { list: [], type: 'ECG' } + }).then(result => ({ ...result, type: 'ECG' })) + ] - // 检查超声数据是否存在 - const usExistingData = await PacsDataApi.getPacsDataPage({ - code: medicalSn, - type: 'US', - pageNo: 1, - pageSize: 1 - }).catch((error) => { - console.warn('检查超声数据是否存在时出错:', error) - return { list: [] } - }) + // 并行执行所有检查 + const allExistingDataResults = await Promise.all(allCheckPromises) - // 检查心电图数据是否存在 - const ecgExistingData = await PacsDataApi.getPacsDataPage({ - code: medicalSn, - type: 'ECG', - pageNo: 1, - pageSize: 1 - }).catch((error) => { - console.warn('检查心电图数据是否存在时出错:', error) - return { list: [] } - }) - - // 获取所有类型的现有数据结果 - const existingDataResults = await Promise.all(existingDataPromises) - - // 确定哪些类型需要同步 + // 处理检查结果 const typesToSync: string[] = [] - existingDataResults.forEach((result, index) => { - const type = types[index] - // 如果没有数据或数据为空,则需要同步 - const needsSync = - !result.list || + let needsSyncECG = false + + allExistingDataResults.forEach((result) => { + const needsSync = !result.list || result.list.length === 0 || (result.list[0] && (!result.list[0].data || result.list[0].data === '')) - if (needsSync) { - typesToSync.push(type) - } else { - console.log(`${type}数据已存在且不为空,跳过同步`) + + if (result.type === 'US') { + // 超声数据已在additionalPromises中处理 + } else if (result.type === 'ECG') { + needsSyncECG = needsSync + } else if (types.includes(result.type) && needsSync) { + typesToSync.push(result.type) + } + + if (!needsSync) { + console.log(`${result.type}数据已存在且不为空,跳过同步`) } }) - // 检查超声数据是否需要同步 - const needsSyncUS = - !usExistingData.list || - usExistingData.list.length === 0 || - (usExistingData.list[0] && - (!usExistingData.list[0].data || usExistingData.list[0].data === '')) - - // 检查心电图数据是否需要同步 - const needsSyncECG = - !ecgExistingData.list || - ecgExistingData.list.length === 0 || - (ecgExistingData.list[0] && - (!ecgExistingData.list[0].data || ecgExistingData.list[0].data === '')) - - // 准备同步请求 + // 并行准备所有同步请求 const syncPromises: Promise[] = [] // 添加需要同步的检验报告请求 typesToSync.forEach((type) => { syncPromises.push( - PatientApi.getReportTj(medicalSn, type).catch((error) => { - console.warn(`获取${type}报告失败:`, error) - return null - }) + (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始获取${type}报告...`) + const result = await PatientApi.getReportTj(medicalSn, type) + const duration = Date.now() - startTime + console.log(`${medicalSn} 获取${type}报告完成,耗时: ${duration}ms`) + return result + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 获取${type}报告失败,耗时: ${duration}ms:`, error) + return null + } + })() ) }) - // ========== 新增:获取超声报告并写入conclusions.ultrasound ========== - let usReport = null; - try { - usReport = await PatientApi.getUSTj(medicalSn); - console.log('usReport:', usReport); // 调试输出,便于确认字段名和内容 - } catch (error) { - console.warn('获取超声报告失败:', error); - } - // ========== 新增 END ========== + // 获取超声报告 - 独立执行,不依赖其他操作 + const usReportPromise = (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始获取超声报告...`) + const result = await PatientApi.getUSTj(medicalSn) + const duration = Date.now() - startTime + console.log(`${medicalSn} 获取超声报告完成,耗时: ${duration}ms`) + return result + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 获取超声报告失败,耗时: ${duration}ms:`, error) + return null + } + })() // 如果需要,添加心电图报告请求 if (needsSyncECG) { syncPromises.push( - PatientApi.GetApiEcgInfo(medicalSn).catch((error) => { - console.warn('获取心电图报告失败:', error) - return null - }) + (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始获取心电图报告...`) + const result = await PatientApi.GetApiEcgInfo(medicalSn) + const duration = Date.now() - startTime + console.log(`${medicalSn} 获取心电图报告完成,耗时: ${duration}ms`) + return result + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 获取心电图报告失败,耗时: ${duration}ms:`, error) + return null + } + })() ) } // 如果需要,添加一般检查报告请求 if (typesToSync.includes('YBJC')) { syncPromises.push( - PatientApi.GetApiYbjcInfo(medicalSn, cardId).catch((error) => { - console.warn('获取一般检查报告失败:', error) - return null - }) + (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始获取一般检查报告...`) + const result = await PatientApi.GetApiYbjcInfo(medicalSn, cardId) + const duration = Date.now() - startTime + console.log(`${medicalSn} 获取一般检查报告完成,耗时: ${duration}ms`) + return result + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 获取一般检查报告失败,耗时: ${duration}ms:`, error) + return null + } + })() ) } - // 添加中医体质辨识报告请求 - await PatientApi.getZytzInfo(medicalSn, cardId).catch((error) => { - console.warn('获取中医体质辨识报告失败:', error) - }) + console.log(`${medicalSn} 开始并行执行 ${syncPromises.length} 个同步请求,1个超声报告请求...`) - // 调用getGwPatientInfo接口获取公卫患者信息 + // 🚀 第一步:优先获取超声报告,完全不受其他请求干扰 + const usStartTime = Date.now() + const usReport = await usReportPromise + const usDuration = Date.now() - usStartTime + console.log(`${medicalSn} 超声报告总耗时: ${usDuration}ms, 结果:`, usReport) + + // 🔄 第二步:启动其他操作(此时超声报告已完成) + console.log(`${medicalSn} 超声报告获取完成,开始启动其他任务...`) + + // 并行执行同步请求(如果有的话) + let syncResults: any[] = [] + const syncPromise = syncPromises.length > 0 ? Promise.all(syncPromises) : Promise.resolve([]) + + // 现在才启动后台任务,避免与超声报告竞争 + const backgroundPromises: Promise[] = [] if (cardId) { - try { - await PatientApi.getGwPatientInfo(cardId) - console.log(`${medicalSn} 公卫患者信息获取成功`) - } catch (error) { - console.warn(`${medicalSn} 获取公卫患者信息失败:`, error) - // 这里不中断流程,只是记录警告 - } - // 新增:调用updatePatientSupplement接口 - try { - await PatientApi.updatePatientSupplement(medicalSn, cardId) - console.log(`${medicalSn} 补充信息更新成功`) - } catch (error) { - console.warn(`${medicalSn} 更新患者补充信息失败:`, error) - } + backgroundPromises.push( + (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始获取中医体质辨识报告...`) + const result = await PatientApi.getZytzInfo(medicalSn, cardId) + const duration = Date.now() - startTime + console.log(`${medicalSn} 获取中医体质辨识报告完成,耗时: ${duration}ms`) + return result + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 获取中医体质辨识报告失败,耗时: ${duration}ms:`, error) + return null + } + })() + ) + + backgroundPromises.push( + (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始获取公卫患者信息...`) + await PatientApi.getGwPatientInfo(cardId) + const duration = Date.now() - startTime + console.log(`${medicalSn} 获取公卫患者信息完成,耗时: ${duration}ms`) + return true + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 获取公卫患者信息失败,耗时: ${duration}ms:`, error) + return false + } + })() + ) + + backgroundPromises.push( + (async () => { + const startTime = Date.now() + try { + console.log(`${medicalSn} 开始更新患者补充信息...`) + await PatientApi.updatePatientSupplement(medicalSn, cardId) + const duration = Date.now() - startTime + console.log(`${medicalSn} 更新患者补充信息完成,耗时: ${duration}ms`) + return true + } catch (error) { + const duration = Date.now() - startTime + console.warn(`${medicalSn} 更新患者补充信息失败,耗时: ${duration}ms:`, error) + return false + } + })() + ) } - // 如果没有需要同步的项目,直接进行保存 - if (syncPromises.length === 0) { - console.log(`${medicalSn} 所有报告数据已存在,直接进行保存`) - } else { - const results = await Promise.all(syncPromises) + // 等待同步请求完成(如果有的话) + if (syncPromises.length > 0) { + console.log(`${medicalSn} 等待 ${syncPromises.length} 个同步请求完成...`) + const syncStartTime = Date.now() + syncResults = await syncPromise + const syncDuration = Date.now() - syncStartTime + console.log(`${medicalSn} 同步请求完成,总耗时: ${syncDuration}ms`) + } - // 检查是否所有请求都失败了 - const allFailed = results.every((result) => result === null) + // 后台异步执行非关键操作,不阻塞主流程 + if (backgroundPromises.length > 0) { + console.log(`${medicalSn} 后台执行 ${backgroundPromises.length} 个非关键请求...`) + Promise.all(backgroundPromises).then(() => { + console.log(`${medicalSn} 所有后台任务完成`) + }).catch(error => { + console.warn(`${medicalSn} 部分后台任务失败:`, error) + }) + } + + console.log(`${medicalSn} 关键请求执行完毕,开始处理结果...`) + + // 检查同步结果 + if (syncPromises.length > 0) { + const allFailed = syncResults.every((result) => result === null) if (allFailed) { console.error(`${medicalSn} 所有报告同步失败`) failCount++ continue } + } else { + console.log(`${medicalSn} 所有报告数据已存在,直接进行保存`) } - // 等待一小段时间确保后端数据同步完成 - await new Promise((resolve) => setTimeout(resolve, 500)) + // 减少等待时间到200ms,或者根据实际情况调整 + await new Promise((resolve) => setTimeout(resolve, 200)) // 在保存之前检查各个检查项目是否有值 console.log(`${medicalSn} 开始检查检查项目数据...`) // 检查PACS数据是否完整 + const checkDataStartTime = Date.now() const pacsDataCheck = await checkPacsDataComplete(medicalSn) + const checkDataDuration = Date.now() - checkDataStartTime + console.log(`${medicalSn} 检查项目数据完整性完成,耗时: ${checkDataDuration}ms`) + if (!pacsDataCheck.isComplete) { console.warn(`${medicalSn} 检查项目数据不完整,跳过保存:`, pacsDataCheck.missingItems) failCount++ @@ -339,12 +438,16 @@ const handleBatchReview = async () => { try { console.log(`${medicalSn} 开始保存检查结果...`) - // 1. 获取患者检查项目 - const itemsRes = await PatientitemsApi.getPatientitemsPage({ - medicalSn: medicalSn, - pageNo: 1, - pageSize: 100 - }) + // 1. 获取患者检查项目 + const itemsStartTime = Date.now() + console.log(`${medicalSn} 开始获取患者检查项目...`) + const itemsRes = await PatientitemsApi.getPatientitemsPage({ + medicalSn: medicalSn, + pageNo: 1, + pageSize: 100 + }) + const itemsDuration = Date.now() - itemsStartTime + console.log(`${medicalSn} 获取患者检查项目完成,耗时: ${itemsDuration}ms`) if (itemsRes.list && itemsRes.list.length > 0) { // 2. 处理PACS数据并生成结论数据 @@ -407,7 +510,11 @@ const handleBatchReview = async () => { // 获取PACS数据 try { + const pacsStartTime = Date.now() + console.log(`${medicalSn} 开始获取PACS数据...`) const pacsRes = await PacsDataApi.getPacsDataDetail(medicalSn) + const pacsDuration = Date.now() - pacsStartTime + console.log(`${medicalSn} 获取PACS数据完成,耗时: ${pacsDuration}ms`) if (pacsRes && pacsRes.length > 0) { const typeGroups: Record = {} pacsRes.forEach((item) => { @@ -565,22 +672,36 @@ const handleBatchReview = async () => { }) // 4. 批量更新检查项目 + const updateItemsStartTime = Date.now() + console.log(`${medicalSn} 开始批量更新检查项目...`) await PatientitemsApi.updatePatientitemsBatch(allUpdatedItems) + const updateItemsDuration = Date.now() - updateItemsStartTime + console.log(`${medicalSn} 批量更新检查项目完成,耗时: ${updateItemsDuration}ms`) // 5. 更新患者状态为已检查 - await PatientApi.updatePatient({ - id: row.id, - status: 1 - }) - + const updatePatientStartTime = Date.now() + console.log(`${medicalSn} 开始更新患者状态...`) + await PatientApi.updatePatientStatus(medicalSn, 1) + const updatePatientDuration = Date.now() - updatePatientStartTime + console.log(`${medicalSn} 更新患者状态完成,耗时: ${updatePatientDuration}ms`) + // 新增:保存总检医生 + const doctorStartTime = Date.now() + console.log(`${medicalSn} 开始获取医生信息...`) const res = await DoctorApi.getDoctorPage({ pageNo: 1, pageSize: 100, // 设置较大的数值以获取所有医生 orgid: userProfile.deptId }) const doctor = res.list.find(doctor => doctor.doctorname === userProfile.nickname) + const doctorDuration = Date.now() - doctorStartTime + console.log(`${medicalSn} 获取医生信息完成,耗时: ${doctorDuration}ms`) + + const updateDoctorStartTime = Date.now() + console.log(`${medicalSn} 开始更新总检医生...`) await PatientApi.updateChiefinspector(medicalSn, doctor.doctorid, doctor.doctorname) + const updateDoctorDuration = Date.now() - updateDoctorStartTime + console.log(`${medicalSn} 更新总检医生完成,耗时: ${updateDoctorDuration}ms`) // 6. 生成汇总内容并保存 let summaryContent = '' @@ -608,25 +729,41 @@ const handleBatchReview = async () => { // 【重点】同步一般检查结论到患者主表summaryResult字段 if (conclusions.general.summary && conclusions.general.summary.trim()) { + const updateSummaryStartTime = Date.now() + console.log(`${medicalSn} 开始更新一般检查结论...`) await PatientApi.updatemedicalSn({ medicalSn: medicalSn, summaryResult: conclusions.general.summary } as any) + const updateSummaryDuration = Date.now() - updateSummaryStartTime + console.log(`${medicalSn} 更新一般检查结论完成,耗时: ${updateSummaryDuration}ms`) } // 如果有汇总内容,保存到患者信息 if (summaryContent.trim()) { + const updateContentStartTime = Date.now() + console.log(`${medicalSn} 开始保存汇总内容...`) await PatientApi.updatemedicalSn({ medicalSn: medicalSn, summaryResult: summaryContent } as any) + const updateContentDuration = Date.now() - updateContentStartTime + console.log(`${medicalSn} 保存汇总内容完成,耗时: ${updateContentDuration}ms`) } // 7. 生成体检报告 + const generateReportStartTime = Date.now() + console.log(`${medicalSn} 开始生成体检报告...`) PatientApi.generateReport(medicalSn) + const generateReportDuration = Date.now() - generateReportStartTime + console.log(`${medicalSn} 生成体检报告完成,耗时: ${generateReportDuration}ms`) // 8. 体检报告信息回传 + const pushInfoStartTime = Date.now() + console.log(`${medicalSn} 开始体检报告信息回传...`) PatientApi.PushJYPatientInfo(medicalSn) + const pushInfoDuration = Date.now() - pushInfoStartTime + console.log(`${medicalSn} 体检报告信息回传完成,耗时: ${pushInfoDuration}ms`) console.log(`${medicalSn} 保存完成`) successCount++ @@ -739,14 +876,6 @@ const checkPacsDataComplete = async (medicalSn: string) => { } } -// 添加日期格式化函数 -const formatDate = (date: Date) => { - const year = date.getFullYear() - const month = String(date.getMonth() + 1).padStart(2, '0') - const day = String(date.getDate()).padStart(2, '0') - return `${year}-${month}-${day}` -} - const handleSelectionChange = (rows: PatientVO[]) => { selectedRows.value = rows } diff --git a/src/views/Department-entry/Medical-examination-vehicle.vue b/src/views/Department-entry/Medical-examination-vehicle.vue index b5d583f..b11621d 100644 --- a/src/views/Department-entry/Medical-examination-vehicle.vue +++ b/src/views/Department-entry/Medical-examination-vehicle.vue @@ -161,6 +161,20 @@ {{ reportData.phoneNum }} +
+
+ + {{ cbc }} +
+
+ + {{ rt }} +
+
+ + {{ bt }} +
+
@@ -946,6 +960,10 @@ const loadPatientData = async (patient) => { } catch (error) { console.error('获取PACS数据失败:', error) } + + // 新增:加载患者数据时获取PACS状态 + await fetchPacsStatus(patient.medicalSn) + } catch (error) { console.error('加载患者数据失败:', error) ElMessage.error('加载患者数据失败') @@ -974,6 +992,12 @@ const handlePatientSelect = async (patient) => { biochemical: { summary: '' }, summary: { summary: '' } } + + // 重置PACS状态变量 + cbc.value = '' + rt.value = '' + bt.value = '' + // 设置选中患者 selectedPatient.value = patient @@ -1483,7 +1507,36 @@ const checkEditPermission = () => { return true } -// 修改同步结果处理函数 +// 添加血常规、尿常规、生化的状态显示变量 +const cbc = ref('') +const rt = ref('') +const bt = ref('') + +// 获取PACS状态(在加载患者数据时调用) +const fetchPacsStatus = async (medicalSn) => { + // 定义类型和变量映射 + const typeMap = [ + { type: 'cbc', ref: cbc }, + { type: 'rt', ref: rt }, + { type: 'bt', ref: bt } + ] + for (const item of typeMap) { + try { + const res = await PacsDataApi.getByMedicalSnAndType(medicalSn, item.type) + if (res && res.status) { + // 直接获取status字段 + item.ref.value = res.status || '' + } else { + item.ref.value = '' + } + } catch (e) { + console.error(`获取${item.type}状态失败:`, e) + item.ref.value = '' + } + } +} + +// 修改handleSync,在同步成功后调用fetchPacsStatus const handleSync = async () => { try { const loading = ElLoading.service({ @@ -1491,7 +1544,6 @@ const handleSync = async () => { text: '同步中...', background: 'rgba(255, 255, 255, 0.7)' }) - try { if (!selectedPatient.value?.medicalSn) { throw new Error('未选择患者或体检编号为空') @@ -1649,7 +1701,7 @@ const handleSync = async () => { // 同步后自动处理BMI和血压值 processAutoFields() - + loading.close() ElMessage.success(`同步成功`) } catch (error) { @@ -1718,6 +1770,11 @@ const handleRefresh = async (e) => { biochemical: { summary: '' } } + // 重置PACS状态变量 + cbc.value = '' + rt.value = '' + bt.value = '' + // 清空搜索栏和日期范围 searchQuery.value = '' dateRange.value = [] @@ -2207,11 +2264,7 @@ const handleSaveAllResults = async () => { // 更新患者状态为已检查 - 调用更新患者状态的API if (selectedPatient.value) { // 更新数据库中的status字段为1,同时更新体检日期为当前时间戳 - await PatientApi.updatePatient({ - id: selectedPatient.value.id, - status: 1, // 设置为已检查状态 - - }) + await PatientApi.updatePatientStatus(selectedPatient.value.medicalSn, 1) // 更新本地状态 selectedPatient.value.status = 1 @@ -2873,10 +2926,7 @@ const resetPatientStatus = async (patient) => { try { // 更新数据库中的status字段为0,同时更新体检日期为当前时间戳 - await PatientApi.updatePatient({ - id: patient.id, - status: 0, // 设置为待检查状态 - }) + await PatientApi.updatePatientStatus(patient.medicalSn, 0) // 更新本地状态 patient.status = 0