@@ -38,6 +38,7 @@ import com.openhis.workflow.service.IDeviceDispenseService;
import com.openhis.workflow.service.IDeviceRequestService ;
import com.openhis.workflow.service.IServiceRequestService ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import javax.annotation.Resource ;
@@ -92,6 +93,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
@Resource
DoctorStationSendApplyUtil doctorStationSendApplyUtil ;
/**
* 查询医嘱信息
*
@@ -111,6 +113,20 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
public IPage < AdviceBaseDto > getAdviceBaseInfo ( AdviceBaseDto adviceBaseDto , String searchKey , Long locationId ,
List < Long > adviceDefinitionIdParamList , Long organizationId , Integer pageNo , Integer pageSize ,
Integer pricingFlag , List < Integer > adviceTypes , String orderPricing ) {
// 生成缓存键, 处理可能的null值
String safeSearchKey = searchKey ! = null ? searchKey : " " ;
String safeAdviceTypesStr = " " ;
if ( adviceTypes ! = null & & ! adviceTypes . isEmpty ( ) ) {
safeAdviceTypesStr = String . join ( " , " , adviceTypes . stream ( ) . map ( String : : valueOf ) . collect ( Collectors . toList ( ) ) ) ;
}
String safeOrganizationId = organizationId ! = null ? organizationId . toString ( ) : " " ;
String safePricingFlag = pricingFlag ! = null ? pricingFlag . toString ( ) : " " ;
String safePageNo = pageNo ! = null ? pageNo . toString ( ) : " " ;
String safePageSize = pageSize ! = null ? pageSize . toString ( ) : " " ;
log . info ( " 从数据库查询医嘱基础信息 " ) ;
// 设置默认科室 (不取前端传的了)
organizationId = SecurityUtils . getLoginUser ( ) . getOrgId ( ) ;
@@ -172,98 +188,190 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
. add ( cfg . getLocationId ( ) ) ;
}
}
// 费用定价子表信息
List < AdvicePriceDto > childCharge = doctorStationAdviceAppMapper
. getChildCharge ( ConditionCode . LOT_NUMBER_PRICE . getCode ( ) , chargeItemDefinitionIdList ) ;
// 费用定价主表信息
List < AdvicePriceDto > mainCharge
= doctorStationAdviceAppMapper . getMainCharge ( chargeItemDefinitionIdList , PublicationStatus . ACTIVE . getValue ( ) ) ;
// 费用定价子表信息 - 使用分批处理避免大量参数问题
List < AdvicePriceDto > childCharge = new ArrayList < > ( ) ;
if ( chargeItemDefinitionIdList ! = null & & ! chargeItemDefinitionIdList . isEmpty ( ) ) {
// 分批处理, 每批最多500个ID
int batchSize = 500 ;
for ( int i = 0 ; i < chargeItemDefinitionIdList . size ( ) ; i + = batchSize ) {
int endIndex = Math . min ( i + batchSize , chargeItemDefinitionIdList . size ( ) ) ;
List < Long > batch = chargeItemDefinitionIdList . subList ( i , endIndex ) ;
childCharge . addAll ( doctorStationAdviceAppMapper
. getChildCharge ( ConditionCode . LOT_NUMBER_PRICE . getCode ( ) , batch ) ) ;
}
}
// 费用定价主表信息 - 使用分批处理避免大量参数问题
List < AdvicePriceDto > mainCharge = new ArrayList < > ( ) ;
if ( chargeItemDefinitionIdList ! = null & & ! chargeItemDefinitionIdList . isEmpty ( ) ) {
// 分批处理, 每批最多500个ID
int batchSize = 500 ;
for ( int i = 0 ; i < chargeItemDefinitionIdList . size ( ) ; i + = batchSize ) {
int endIndex = Math . min ( i + batchSize , chargeItemDefinitionIdList . size ( ) ) ;
List < Long > batch = chargeItemDefinitionIdList . subList ( i , endIndex ) ;
mainCharge . addAll ( doctorStationAdviceAppMapper . getMainCharge ( batch , PublicationStatus . ACTIVE . getValue ( ) ) ) ;
}
}
String unitCode = " " ; // 包装单位
Long chargeItemDefinitionId ; // 费用定价主表ID
for ( AdviceBaseDto baseDto : adviceBaseDtoList ) {
switch ( baseDto . getAdviceTableName ( ) ) {
case CommonConstants . TableName . MED_MEDICATION_DEFINITION : // 药品
// 是否皮试
baseDto
. setSkinTestFlag_enumText ( EnumUtils . getInfoByValue ( Whether . class , baseDto . getSkinTestFlag ( ) ) ) ;
// 是否为注射药物
baseDto . setInjectFlag_enumText ( EnumUtils . getInfoByValue ( Whether . class , baseDto . getInjectFlag ( ) ) ) ;
case CommonConstants . TableName . ADM_DEVICE_DEFINITION : // 耗材
// 每一条医嘱的库存集合信息 , 包装单位库存前端计算
List < AdviceInventoryDto > inventoryList = adviceInventory . stream ( ) . filter ( e - > baseDto
. getAdviceDefinitionId ( ) . equals ( e . getItemId ( ) )
& & baseDto . getAdviceTableName ( ) . equals ( e . getItemTable ( ) )
& & ( pharmacyMultipleChoice
| | ( baseDto . getPositionId ( ) = = null | | baseDto . getPositionId ( ) . equals ( e . getLocationId ( ) ) ) ) )
. collect ( Collectors . toList ( ) ) ;
// 库存信息
baseDto . setInventoryList ( inventoryList ) ;
// 设置默认产品批号
if ( ! inventoryList . isEmpty ( ) ) {
// 库存大于0
List < AdviceInventoryDto > hasInventoryList = inventoryList . stream ( )
. filter ( e - > e . getQuantity ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) . collect ( Collectors . toList ( ) ) ;
if ( ! hasInventoryList . isEmpty ( ) ) {
baseDto . setDefaultLotNumber ( hasInventoryList . get ( 0 ) . getLotNumber ( ) ) ;
}
}
if ( ! inventoryList . isEmpty ( ) & & ! medLocationConfig . isEmpty ( ) ) {
// 第一步: 在medLocationConfig中匹配categoryCode
AdviceInventoryDto result1 = medLocationConfig . stream ( )
. filter ( dto - > baseDto . getCategoryCode ( ) . equals ( dto . getCategoryCode ( ) ) ) . findFirst ( )
. orElse ( null ) ;
if ( result1 ! = null ) {
// 第二步: 在inventoryList中匹配locationId
AdviceInventoryDto result2 = inventoryList . stream ( )
. filter ( dto - > result1 . getLocationId ( ) . equals ( dto . getLocationId ( ) ) ) . findFirst ( )
. orElse ( null ) ;
if ( result2 ! = null & & result2 . getLotNumber ( ) ! = null ) {
baseDto . setDefaultLotNumber ( result2 . getLotNumber ( ) ) ;
}
}
}
String tableName = baseDto . getAdviceTableName ( ) ;
if ( CommonConstants . TableName . MED_MEDICATION_DEFINITION . equals ( tableName ) ) { // 药品
// 是否皮试
baseDto
. setSkinTestFlag_enumText ( EnumUtils . getInfoByValue ( Whether . class , baseDto . getSkinTestFlag ( ) ) ) ;
// 是否为注射药物
baseDto . setInjectFlag_enumText ( EnumUtils . getInfoByValue ( Whether . class , baseDto . getInjectFlag ( ) ) ) ;
unitCode = baseDto . getUnitCode ( ) ;
chargeItemDefinitionId = baseDto . getChargeItemDefinitionId ( ) ;
List < AdvicePrice Dto > priceDto List = new ArrayList < > ( ) ;
// 库存信息里取 命中条件 去匹配价格
for ( AdviceInventoryDto adviceInventoryDto : inventoryList ) {
Long finalChargeItemDefinitionId = char geItemDefinitionId ;
String finalUnitCode = unitCode ;
// 从定价子表取价格(适用于批次售卖场景)
List < AdvicePriceDto > childPrice = childCharge . stream ( )
. filter ( e - > e . getDefinitionId ( ) . equals ( finalChargeItemDefinitionId )
& & e . getConditionValue ( ) . equals ( adviceInventoryDto . getLotNumber ( ) ) )
. peek ( e - > e . setUnitCode ( f inalUnitCode ) ) // 设置 unitCode
. collect ( Collectors . toList ( ) ) ;
// 从定价主表取价格(适用于统一零售价场景)
List < AdvicePriceDto > mainPrice = mainCharge . stream ( )
. filter ( e - > b aseDto . getChargeItemDefinitionId ( ) . equals ( e . getDefinitionId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
// 按批次售价
if ( OrderPricingSource . BATCH_SELLING_PRICE . getCode ( ) . equals ( orderPricingSource ) ) {
priceDtoList . addAll ( childPrice ) ;
} else {
priceDtoList . addAll ( mainPrice ) ;
// fallthrough to 耗材处理逻辑(保持原有逻辑)
// 每一条医嘱的库存集合信息 , 包装单位库存前端计算
List < AdviceInventory Dto > inventory List = adviceInventory . stream ( ) . filter ( e - >
baseDto . getAdviceDefinitionId ( ) ! = null & & e . getItemId ( ) ! = null
& & baseDto . getAdviceDefinitionId ( ) . equals ( e . getItemId ( ) )
& & baseDto . getAdviceTableName ( ) ! = null & & e . get ItemTable ( ) ! = null
& & baseDto . getAdviceTableName ( ) . equals ( e . getItemTable ( ) )
& & ( pharmacyMultipleChoice
| | ( baseDto . getPositionId ( ) = = null | | ( e . getLocationId ( ) ! = null & & baseDto . getPositionId ( ) . equals ( e . getLocationId ( ) ) ) ) ) )
. collect ( Collectors . toList ( ) ) ;
// 库存信息
baseDto . setInventoryList ( inventoryList ) ;
// 设置默认产品批号
if ( ! inventoryList . isEmpty ( ) ) {
// 库存大于0
List < AdviceInventoryDto > h asInventoryList = inventoryList . stream ( )
. filter ( e - > e . getQuantity ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) . collect ( Collectors . toList ( ) ) ;
if ( ! hasInventoryList . isEmpty ( ) ) {
baseDto . setDefaultLotNumber ( hasInventoryList . get ( 0 ) . getLotNumber ( ) ) ;
}
}
if ( ! inventoryList . isEmpty ( ) & & ! medLocationConfig . isEmpty ( ) ) {
// 第一步: 在medLocationConfig中匹配categoryCode
AdviceInventoryDto result1 = medLocationConfig . stream ( )
. filter ( dto - > baseDto . getCategoryCode ( ) ! = null & & dto . getCategoryCode ( ) ! = null
& & baseDto . getCategoryCode ( ) . equals ( dto . getCategoryCode ( ) ) ) . findFirst ( )
. orElse ( null ) ;
if ( result1 ! = null ) {
// 第二步: 在inventoryList中匹配locationId
AdviceInventoryDto result2 = inventoryList . stream ( )
. filter ( dto - > result1 . getLocationId ( ) ! = null & & dto . getLocationId ( ) ! = null
& & result1 . getLocationId ( ) . equals ( dto . getLocationId ( ) ) ) . findFirst ( )
. orElse ( null ) ;
if ( result2 ! = null & & result2 . getLotNumber ( ) ! = null ) {
baseDto . setDefaultLotNumber ( result2 . getLotNumber ( ) ) ;
}
}
// 价格信息
baseDto . setPriceList ( priceDtoList ) ;
break ;
case CommonConstants . TableName . WOR_ACTIVITY_DEFINITION : // 诊疗
List < AdvicePriceDto > priceList
= mainCharge . stream ( ) . filter ( e - > baseDto . getChargeItemDefinitionId ( ) . equals ( e . getDefinitionId ( ) ) )
. collect ( Collectors . to List ( )) ;
// 价格信息
baseDto . setPriceList ( priceList ) ;
// 活动类型
baseDto . setActivityType_enumText (
EnumUtils . getInfoByValue ( ActivityType . class , baseDto . getActivityType ( ) ) ) ;
break ;
default :
break ;
}
unitCode = baseDto . getUnitCode ( ) ;
chargeItemDefinitionId = baseDto . getChargeItemDefinitionId ( ) ;
List < AdvicePriceDto > priceDto List = new ArrayList < > ( ) ;
// 库存信息里取 命中条件 去匹配价格
for ( AdviceInventoryDto adviceInventoryDto : inventory List ) {
Long finalChargeItemDefinitionId = chargeItemDefinitionId ;
String finalUnitCode = unitCode ;
// 从定价子表取价格(适用于批次售卖场景)
List < AdvicePriceDto > childPrice = childCharge . stream ( )
. filter ( e - > e . getDefinitionId ( ) ! = null & & finalChargeItemDefinitionId ! = null
& & e . getDefinitionId ( ) . equals ( finalChargeItemDefinitionId )
& & e . getConditionValue ( ) ! = null & & adviceInventoryDto . getLotNumber ( ) ! = null
& & e . getConditionValue ( ) . equals ( adviceInventoryDto . getLotNumber ( ) ) )
. peek ( e - > e . setUnitCode ( finalUnitCode ) ) // 设置 unitCode
. collect ( Collectors . toList ( ) ) ;
// 从定价主表取价格(适用于统一零售价场景)
List < AdvicePriceDto > mainPrice = mainCharge . stream ( )
. filter ( e - > baseDto . getChargeItemDefinitionId ( ) ! = null & & e . getDefinitionId ( ) ! = null
& & baseDto . getChargeItemDefinitionId ( ) . equals ( e . getDefinitionId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
// 按批次售价
if ( OrderPricingSource . BATCH_SELLING_PRICE . getCode ( ) . equals ( orderPricingSource ) ) {
priceDtoList . addAll ( childPrice ) ;
} else {
priceDtoList . addAll ( mainPrice ) ;
}
}
// 价格信息
baseDto . setPriceList ( priceDtoList ) ;
} else if ( CommonConstants . TableName . ADM_DEVICE_DEFINITION . equals ( tableName ) ) { // 耗材
// 每一条医嘱的库存集合信息 , 包装单位库存前端计算
List < AdviceInventoryDto > inventoryList = adviceInventory . stream ( ) . filter ( e - >
baseDto . getAdviceDefinitionId ( ) ! = null & & e . getItemId ( ) ! = null
& & baseDto . getAdviceDefinitionId ( ) . equals ( e . getItemId ( ) )
& & baseDto . getAdviceTableName ( ) ! = null & & e . getItemTable ( ) ! = null
& & baseDto . getAdviceTableName ( ) . equals ( e . getItemTable ( ) )
& & ( pharmacyMultipleChoice
| | ( baseDto . getPositionId ( ) = = null | | ( e . getLocationId ( ) ! = null & & baseDto . getPositionId ( ) . equals ( e . getLocationId ( ) ) ) ) ) )
. collect ( Collectors . toList ( ) ) ;
// 库存信息
baseDto . setInventoryList ( inventoryList ) ;
// 设置默认产品批号
if ( ! inventoryList . isEmpty ( ) ) {
// 库存大于0
List < AdviceInventoryDto > hasInventoryList = inventoryList . stream ( )
. filter ( e - > e . getQuantity ( ) . compareTo ( BigDecimal . ZERO ) > 0 ) . collect ( Collectors . toList ( ) ) ;
if ( ! hasInventoryList . isEmpty ( ) ) {
baseDto . setDefaultLotNumber ( hasInventoryList . get ( 0 ) . getLotNumber ( ) ) ;
}
}
if ( ! inventoryList . isEmpty ( ) & & ! medLocationConfig . isEmpty ( ) ) {
// 第一步: 在medLocationConfig中匹配categoryCode
AdviceInventoryDto result1 = medLocationConfig . stream ( )
. filter ( dto - > baseDto . getCategoryCode ( ) ! = null & & dto . getCategoryCode ( ) ! = null
& & baseDto . getCategoryCode ( ) . equals ( dto . getCategoryCode ( ) ) ) . findFirst ( )
. orElse ( null ) ;
if ( result1 ! = null ) {
// 第二步: 在inventoryList中匹配locationId
AdviceInventoryDto result2 = inventoryList . stream ( )
. filter ( dto - > result1 . getLocationId ( ) ! = null & & dto . getLocationId ( ) ! = null
& & result1 . getLocationId ( ) . equals ( dto . getLocationId ( ) ) ) . findFirst ( )
. orElse ( null ) ;
if ( result2 ! = null & & result2 . getLotNumber ( ) ! = null ) {
baseDto . setDefaultLotNumber ( result2 . getLotNumber ( ) ) ;
}
}
}
unitCode = baseDto . getUnitCode ( ) ;
chargeItemDefinitionId = baseDto . getChargeItemDefinitionId ( ) ;
List < AdvicePriceDto > priceDtoList = new ArrayList < > ( ) ;
// 库存信息里取 命中条件 去匹配价格
for ( AdviceInventoryDto adviceInventoryDto : inventoryList ) {
Long finalChargeItemDefinitionId = chargeItemDefinitionId ;
String finalUnitCode = unitCode ;
// 从定价子表取价格(适用于批次售卖场景)
List < AdvicePriceDto > childPrice = childCharge . stream ( )
. filter ( e - > e . getDefinitionId ( ) ! = null & & finalChargeItemDefinitionId ! = null
& & e . getDefinitionId ( ) . equals ( finalChargeItemDefinitionId )
& & e . getConditionValue ( ) ! = null & & adviceInventoryDto . getLotNumber ( ) ! = null
& & e . getConditionValue ( ) . equals ( adviceInventoryDto . getLotNumber ( ) ) )
. peek ( e - > e . setUnitCode ( finalUnitCode ) ) // 设置 unitCode
. collect ( Collectors . toList ( ) ) ;
// 从定价主表取价格(适用于统一零售价场景)
List < AdvicePriceDto > mainPrice = mainCharge . stream ( )
. filter ( e - > baseDto . getChargeItemDefinitionId ( ) ! = null & & e . getDefinitionId ( ) ! = null
& & baseDto . getChargeItemDefinitionId ( ) . equals ( e . getDefinitionId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
// 按批次售价
if ( OrderPricingSource . BATCH_SELLING_PRICE . getCode ( ) . equals ( orderPricingSource ) ) {
priceDtoList . addAll ( childPrice ) ;
} else {
priceDtoList . addAll ( mainPrice ) ;
}
}
// 价格信息
baseDto . setPriceList ( priceDtoList ) ;
} else if ( CommonConstants . TableName . WOR_ACTIVITY_DEFINITION . equals ( tableName ) ) { // 诊疗
List < AdvicePriceDto > priceList
= mainCharge . stream ( ) . filter ( e - > baseDto . getChargeItemDefinitionId ( ) ! = null & & e . getDefinitionId ( ) ! = null
& & baseDto . getChargeItemDefinitionId ( ) . equals ( e . getDefinitionId ( ) ) )
. collect ( Collectors . toList ( ) ) ;
// 价格信息
baseDto . setPriceList ( priceList ) ;
// 活动类型
baseDto . setActivityType_enumText (
EnumUtils . getInfoByValue ( ActivityType . class , baseDto . getActivityType ( ) ) ) ;
}
}
return adviceBaseInfo ;
}
@@ -288,83 +396,99 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
*/
@Override
public R < ? > saveAdvice ( AdviceSaveParam adviceSaveParam , String adviceOpType ) {
// 患者挂号对应的科室id
Long organizationId = adviceSaveParam . getOrganizationId ( ) ;
// 医嘱分类信息
List < AdviceSaveDto > adviceSaveList = adviceSaveParam . getAdviceSaveList ( ) ;
// 药品
List < AdviceSaveDto > medicineList = adviceSaveList . stream ( )
. filter ( e - > ItemType . MEDICINE . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
// 耗材
List < AdviceSaveDto > deviceList = adviceSaveList . stream ( )
. filter ( e - > ItemType . DEVICE . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
// 诊疗活动
List < AdviceSaveDto > activityList = adviceSaveList . stream ( )
. filter ( e - > ItemType . ACTIVITY . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
try {
// 患者挂号对应的科室id
Long organizationId = adviceSaveParam . getOrganizationId ( ) ;
// 医嘱分类信息
List < AdviceSaveDto > adviceSaveList = adviceSaveParam . getAdviceSaveList ( ) ;
// 药品
List < AdviceSaveDto > medicineList = adviceSaveList . stream ( )
. filter ( e - > ItemType . MEDICINE . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
// 耗材
List < AdviceSaveDto > deviceList = adviceSaveList . stream ( )
. filter ( e - > ItemType . DEVICE . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
// 诊疗活动
List < AdviceSaveDto > activityList = adviceSaveList . stream ( )
. filter ( e - > ItemType . ACTIVITY . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
/**
* 保存时,校验库存
*/
if ( AdviceOpType . SAVE_ADVICE . getCode ( ) . equals ( adviceOpType ) ) {
List < AdviceSaveDto > medUpdateList
= medicineList . stream ( ) . filter ( e - > e . getRequestId ( ) ! = null ) . collect ( Collectors . toList ( ) ) ;
List < AdviceSaveDto > devUpdateList
= deviceList . stream ( ) . filter ( e - > e . getRequestId ( ) ! = null ) . collect ( Collectors . toList ( ) ) ;
// 编辑时,释放本身占用的库存发放
for ( AdviceSaveDto adviceSaveDto : medUpdateList ) {
iMedicationDispenseService . deleteMedicationDispense ( adviceSaveDto . getRequestId ( ) ) ;
/**
* 保存时,校验库存
*/
if ( AdviceOpType . SAVE_ADVICE . getCode ( ) . equals ( adviceOpType ) ) {
List < AdviceSaveDto > medUpdateList
= medicineList . stream ( ) . filter ( e - > e . getRequestId ( ) ! = null ) . collect ( Collectors . toList ( ) ) ;
List < AdviceSaveDto > devUpdateList
= deviceList . stream ( ) . filter ( e - > e . getRequestId ( ) ! = null ) . collect ( Collectors . toList ( ) ) ;
// 编辑时,释放本身占用的库存发放
for ( AdviceSaveDto adviceSaveDto : medUpdateList ) {
iMedicationDispenseService . deleteMedicationDispense ( adviceSaveDto . getRequestId ( ) ) ;
}
for ( AdviceSaveDto adviceSaveDto : devUpdateList ) {
iDeviceDispenseService . deleteDeviceDispense ( adviceSaveDto . getRequestId ( ) ) ;
}
List < AdviceSaveDto > needCheckList
= adviceSaveList . stream ( ) . filter ( e - > ! DbOpType . DELETE . getCode ( ) . equals ( e . getDbOpType ( ) )
& & ! ItemType . ACTIVITY . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
// 校验库存
String tipRes = adviceUtils . checkInventory ( needCheckList ) ;
if ( tipRes ! = null ) {
return R . fail ( null , tipRes ) ;
}
}
for ( AdviceSaveDto adviceSaveDto : devUpdateList ) {
iDeviceDispenseService . deleteDeviceDispense ( adviceSaveDto . getRequestId ( ) ) ;
// 当前时间
Date curDate = new Date ( ) ;
// 医嘱签发编码
String signCode = assignSeqUtil . getSeq ( AssignSeqEnum . ADVICE_SIGN . getPrefix ( ) , 10 ) ;
/**
* 处理药品请求
*/
List < String > medRequestIdList
= this . handMedication ( medicineList , curDate , adviceOpType , organizationId , signCode ) ;
/**
* 处理诊疗项目请求
*/
this . handService ( activityList , curDate , adviceOpType , organizationId , signCode ) ;
/**
* 处理耗材请求
*/
this . handDevice ( deviceList , curDate , adviceOpType ) ;
// 签发时,把草稿状态的账单更新为待收费
if ( AdviceOpType . SIGN_ADVICE . getCode ( ) . equals ( adviceOpType ) & & ! adviceSaveList . isEmpty ( ) ) {
// 签发的医嘱id集合
List < Long > requestIds = adviceSaveList . stream ( )
. filter ( e - > ! DbOpType . DELETE . getCode ( ) . equals ( e . getDbOpType ( ) ) & & e . getRequestId ( ) ! = null )
. collect ( Collectors . toList ( ) ) . stream ( ) . map ( AdviceSaveDto : : getRequestId ) . collect ( Collectors . toList ( ) ) ;
// 就诊id
Long encounterId = adviceSaveList . get ( 0 ) . getEncounterId ( ) ;
iChargeItemService . update ( new LambdaUpdateWrapper < ChargeItem > ( )
. set ( ChargeItem : : getStatusEnum , ChargeItemStatus . PLANNED . getValue ( ) )
. eq ( ChargeItem : : getEncounterId , encounterId )
. eq ( ChargeItem : : getStatusEnum , ChargeItemStatus . DRAFT . getValue ( ) )
. in ( ChargeItem : : getServiceId , requestIds ) ) ;
}
List < AdviceSaveDto > needCheckList
= adviceSaveList . stream ( ) . filter ( e - > ! DbOpType . DELETE . getCode ( ) . equals ( e . getDbOpTyp e ( ) )
& & ! ItemType . ACTIVITY . getValue ( ) . equals ( e . getAdviceType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
// 校验库存
String tipRes = adviceUtils . checkInventory ( needCheckList ) ;
if ( tipRes ! = null ) {
return R . fail ( null , tipRes ) ;
}
// 数据变更后清理相关缓存
clearRelatedCach e ( ) ;
return R . ok ( medRequestIdList ,
MessageUtils . createMessage ( PromptMsgConstant . Common . M00002 , new Object [ ] { " 门诊医嘱 " } ) ) ;
} catch ( Exception e ) {
// 异常处理
throw e ;
}
// 当前时间
Date curDate = new Date ( ) ;
// 医嘱签发编码
String signCode = assignSeqUtil . getSeq ( AssignSeqEnum . ADVICE_SIGN . getPrefix ( ) , 10 ) ;
}
/**
* 处理药品请求
*/
List < String > medRequestIdList
= this . handMedication ( medicineList , curDate , adviceOpType , organizationId , signCode ) ;
/**
* 处理诊疗项目请求
*/
this . handService ( activityList , curDate , adviceOpType , organizationId , signCode ) ;
/**
* 处理耗材请求
*/
this . handDevice ( deviceList , curDate , adviceOpType ) ;
// 签发时,把草稿状态的账单更新为待收费
if ( AdviceOpType . SIGN_ADVICE . getCode ( ) . equals ( adviceOpType ) & & ! adviceSaveList . isEmpty ( ) ) {
// 签发的医嘱id集合
List < Long > requestIds = adviceSaveList . stream ( )
. filter ( e - > ! DbOpType . DELETE . getCode ( ) . equals ( e . getDbOpType ( ) ) & & e . getRequestId ( ) ! = null )
. collect ( Collectors . toList ( ) ) . stream ( ) . map ( AdviceSaveDto : : getRequestId ) . collect ( Collectors . toList ( ) ) ;
// 就诊id
Long encounterId = adviceSaveList . get ( 0 ) . getEncounterId ( ) ;
iChargeItemService . update ( new LambdaUpdateWrapper < ChargeItem > ( )
. set ( ChargeItem : : getStatusEnum , ChargeItemStatus . PLANNED . getValue ( ) )
. eq ( ChargeItem : : getEncounterId , encounterId )
. eq ( ChargeItem : : getStatusEnum , ChargeItemStatus . DRAFT . getValue ( ) )
. in ( ChargeItem : : getServiceId , requestIds ) ) ;
}
return R . ok ( medRequestIdList ,
MessageUtils . createMessage ( PromptMsgConstant . Common . M00002 , new Object [ ] { " 门诊医嘱 " } ) ) ;
/**
* 清理相关缓存
*/
private void clearRelatedCache ( ) {
// 目前不使用缓存,此方法为空实现
// 如果将来启用缓存,可以在这里实现缓存清理逻辑
}
/**