@@ -227,7 +227,7 @@
< / template >
< script setup name = "MedicalExaminations" >
import { getCurrentInstance , onMounted , reactive , ref , watch , computed } from 'vue' ;
import { getCurrentInstance , onMounted , reactive , ref , watch , computed , nextTick } from 'vue' ;
import { patientInfo } from '../../../store/patient.js' ;
import { getDepartmentList } from '@/api/public.js' ;
import { getEncounterDiagnosis } from '../../api.js' ;
@@ -251,7 +251,26 @@ const findTreeItem = (list, id) => {
} ;
const emits = defineEmits ( [ 'submitOk' ] ) ;
const props = defineProps ( { } ) ;
const props = defineProps ( {
isEditMode : {
type : Boolean ,
default : false ,
} ,
editData : {
type : Object ,
default : ( ) => ( { } ) ,
} ,
// 支持通过props传入patientInfo
externalPatientInfo : {
type : Object ,
default : null ,
} ,
} ) ;
// 优先使用外部传入的patientInfo, 否则使用store中的
const effectivePatientInfo = computed ( ( ) => {
return props . externalPatientInfo || patientInfo . value ;
} ) ;
const orgOptions = ref ( [ ] ) ;
const state = reactive ( { } ) ;
const applicationListAll = ref ( ) ;
@@ -272,7 +291,9 @@ const isSevereAllergy = computed(() => {
} ) ;
const getList = ( ) => {
if ( ! patientInfo . value ? . inHospitalOrgId ) {
console . log ( 'getList called, effectivePatientInfo:' , effectivePatientInfo . value ) ;
if ( ! effectivePatientInfo . value ? . inHospitalOrgId ) {
console . log ( 'inHospitalOrgId is missing, setting empty list' ) ;
applicationList . value = [ ] ;
return ;
}
@@ -281,7 +302,7 @@ const getList = () => {
pageSize : 500 ,
pageNum : 1 ,
categoryCode : '23' ,
organizationId : p atientInfo. value . inHospitalOrgId ,
organizationId : effectiveP atientInfo. value . inHospitalOrgId ,
adviceTypes : [ 3 ] ,
} )
. then ( ( res ) => {
@@ -298,6 +319,24 @@ const getList = () => {
key : item . adviceDefinitionId ,
} ;
} ) ;
// 编辑模式下,加载完数据后设置已选项目
if ( props . isEditMode && props . editData ? . requestFormDetailList ? . length ) {
nextTick ( ( ) => {
// 使用 adviceName 匹配
const selectedNames = props . editData . requestFormDetailList . map ( item => item . adviceName ) ;
console . log ( 'getList completed, selectedNames:' , selectedNames ) ;
const selectedIds = [ ] ;
applicationList . value ? . forEach ( app => {
// 匹配时去掉价格部分,只比较名称
const appName = app . label ? . split ( ' (' ) [ 0 ] ;
if ( selectedNames . includes ( appName ) ) {
selectedIds . push ( app . key ) ;
}
} ) ;
console . log ( 'getList completed, matched selectedIds:' , selectedIds ) ;
transferValue . value = selectedIds ;
} ) ;
}
} else {
proxy . $message . error ( res . message ) ;
applicationList . value = [ ] ;
@@ -387,12 +426,65 @@ const handleSyncHistory = async () => {
// 自动带入患者过敏史
const loadPatientAllergyHistory = ( ) => {
if ( ! p atientInfo. value ? . patientId ) return ;
if ( ! effectiveP atientInfo. value ? . patientId ) return ;
} ;
// 加载编辑数据
const loadEditData = ( ) => {
if ( ! props . isEditMode || ! props . editData ? . requestFormId ) return ;
console . log ( 'loadEditData called, editData:' , props . editData ) ;
// 解析已有的descJson填充表单
if ( props . editData . descJson ) {
try {
const obj = JSON . parse ( props . editData . descJson ) ;
form . targetDepartment = obj . targetDepartment || '' ;
form . urgencyLevel = obj . urgencyLevel || 'routine' ;
form . allergyHistory = obj . allergyHistory || '' ;
form . examinationPurpose = obj . examinationPurpose || '' ;
form . medicalHistorySummary = obj . medicalHistorySummary || '' ;
form . expectedExaminationTime = obj . expectedExaminationTime || '' ;
form . symptom = obj . symptom || '' ;
form . sign = obj . sign || '' ;
form . clinicalDiagnosis = obj . clinicalDiagnosis || '' ;
form . otherDiagnosis = obj . otherDiagnosis || '' ;
form . relatedResult = obj . relatedResult || '' ;
form . attention = obj . attention || '' ;
form . allergyConfirmed = obj . allergyConfirmed || false ;
} catch ( e ) {
console . error ( '解析descJson失败:' , e ) ;
}
}
// 设置已选项目( 从requestFormDetailList获取)
// 注意:后端返回的字段是 adviceName, 不是 adviceDefinitionId
console . log ( 'requestFormDetailList:' , props . editData . requestFormDetailList ) ;
if ( props . editData . requestFormDetailList && props . editData . requestFormDetailList . length ) {
// 使用 adviceName 匹配
const selectedNames = props . editData . requestFormDetailList . map ( item => item . adviceName ) ;
console . log ( 'setting transferValue by adviceName to:' , selectedNames ) ;
// 通过名称匹配找到对应的 key
const selectedIds = [ ] ;
applicationList . value ? . forEach ( app => {
if ( selectedNames . includes ( app . label ? . split ( ' (' ) [ 0 ] ) ) {
selectedIds . push ( app . key ) ;
}
} ) ;
console . log ( 'matched selectedIds:' , selectedIds ) ;
transferValue . value = selectedIds ;
} else {
console . log ( 'requestFormDetailList is empty or undefined' ) ;
}
} ;
const projectWithDepartment = ( selectProjectIds , type ) => {
let isRelease = true ;
const arr = [ ] ;
// 确保 applicationList 存在
if ( ! applicationList . value || ! Array . isArray ( applicationList . value ) ) {
return true ;
}
selectProjectIds . forEach ( ( element ) => {
const searchData = applicationList . value . find ( ( item ) => {
return element == item . adviceDefinitionId ;
@@ -429,9 +521,28 @@ const projectWithDepartment = (selectProjectIds, type) => {
} ;
watch ( ( ) => transferValue . value , ( newValue ) => {
console . log ( 'transferValue changed:' , newValue ) ;
console . log ( 'applicationList length:' , applicationList . value ? . length ) ;
projectWithDepartment ( newValue , 1 ) ;
} ) ;
// 监听 applicationList 加载完成,重新设置已选项目
watch ( ( ) => applicationList . value , ( newList ) => {
if ( newList && newList . length > 0 && props . isEditMode && props . editData ? . requestFormDetailList ? . length ) {
console . log ( 'applicationList loaded, re-setting transferValue' ) ;
// 使用 adviceName 匹配
const selectedNames = props . editData . requestFormDetailList . map ( item => item . adviceName ) ;
const selectedIds = [ ] ;
newList . forEach ( app => {
const appName = app . label ? . split ( ' (' ) [ 0 ] ;
if ( selectedNames . includes ( appName ) ) {
selectedIds . push ( app . key ) ;
}
} ) ;
transferValue . value = selectedIds ;
}
} ) ;
const getPriorityCode = ( ) => {
return form . urgencyLevel === 'emergency' ? 1 : 0 ;
} ;
@@ -470,28 +581,32 @@ const submit = () => {
adviceType : item . adviceType ,
definitionId : item . priceList [ 0 ] . definitionId ,
definitionDetailId : item . priceList [ 0 ] . definitionDetailId ,
accountId : p atientInfo. value . accountId ,
accountId : effectiveP atientInfo. value . accountId ,
} ;
} ) ;
const submitForm = { ... form , priorityCode : getPriorityCode ( ) } ;
console . log ( '提交 descJson:' , JSON . stringify ( submitForm ) ) ;
// 如果是编辑模式, 带上requestFormId
const requestFormId = props . isEditMode ? props . editData ? . requestFormId : '' ;
saveCheckd ( {
activityList : applicationListAllFilter ,
patientId : p atientInfo. value . patientId ,
encounterId : p atientInfo. value . encounterId ,
organizationId : p atientInfo. value . inHospitalOrgId ,
requestFormId : '' ,
name : transferValue . value . map ( id => {
const item = applicationListAll . value ? . find ( i => i . adviceDefinitionId === id ) ;
return item ? . adviceName || '' ;
} ) . filter ( Boolean ) . join ( '、' ) ,
patientId : effectiveP atientInfo. value . patientId ,
encounterId : effectiveP atientInfo. value . encounterId ,
organizationId : effectiveP atientInfo. value . inHospitalOrgId ,
requestFormId : requestFormId ,
name : applicationListAllFilter . map ( item => item . adviceName ) . join ( '、' ) ,
descJson : JSON . stringify ( submitForm ) ,
categoryEnum : '2' ,
categoryEnum : '22 ' ,
} ) . then ( ( res ) => {
if ( res . code === 200 ) {
proxy . $message . success ( res . msg ) ;
if ( props . isEditMode ) {
proxy . $message . success ( res . msg || '修改成功' ) ;
} else {
proxy . $message . success ( res . msg ) ;
}
applicationList . value = [ ] ;
resetForm ( ) ;
emits ( 'submitOk' ) ;
@@ -527,7 +642,7 @@ const getLocationInfo = () => {
} ;
function getDiagnosisList ( ) {
getEncounterDiagnosis ( p atientInfo. value . encounterId ) . then ( ( res ) => {
getEncounterDiagnosis ( effectiveP atientInfo. value . encounterId ) . then ( ( res ) => {
if ( res . code == 200 ) {
const datas = ( res . data || [ ] ) . map ( ( item ) => {
let obj = { ... item } ;
@@ -548,9 +663,24 @@ onMounted(() => {
getList ( ) ;
getLocationInfo ( ) ;
loadPatientAllergyHistory ( ) ;
loadEditData ( ) ;
} ) ;
defineExpose ( { state , submit , getLocationInfo , getDiagnosisList , resetForm } ) ;
// 监听编辑模式变化,重新加载数据
watch (
( ) => props . isEditMode ,
( newVal ) => {
if ( newVal ) {
nextTick ( ( ) => {
getList ( ) ;
getLocationInfo ( ) ;
loadEditData ( ) ;
} ) ;
}
}
) ;
defineExpose ( { state , submit , getLocationInfo , getDiagnosisList , resetForm , getList } ) ;
< / script >
< style lang = "scss" scoped >