@@ -28,12 +28,13 @@ import com.openhis.medication.service.IMedicationRequestService;
import com.openhis.web.common.dto.PerformInfoDto ;
import com.openhis.web.common.dto.PerformRecordDto ;
import com.openhis.web.outpatientmanage.appservice.IOutpatientTreatmentAppService ;
import com.openhis.web.outpatientmanage.dto.BloodTransfusionPatchDto ;
import com.openhis.web.outpatientmanage.dto.OutpatientStationInitDto ;
import com.openhis.web.outpatientmanage.dto.OutpatientTreatmentEncounterDto ;
import com.openhis.web.outpatientmanage.dto.OutpatientTreatmentInfoDto ;
import com.openhis.web.outpatientmanage.mapper.OutpatientTreatmentAppMapper ;
import com.openhis.web.pharmacymanage.appservice.impl.I ReturnMedicineAppServiceImpl ;
import com.openhis.web.pharmacymanage.appservice.impl.I WesternMedicineDispenseAppServiceImpl ;
import com.openhis.web.pharmacymanage.appservice.impl.ReturnMedicineAppServiceImpl ;
import com.openhis.web.pharmacymanage.appservice.impl.WesternMedicineDispenseAppServiceImpl ;
import com.openhis.web.pharmacymanage.dto.InventoryDto ;
import com.openhis.web.pharmacymanage.mapper.ReturnMedicineMapper ;
import com.openhis.workflow.domain.DeviceDispense ;
@@ -81,10 +82,10 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
private ReturnMedicineMapper returnMedicineMapper ;
@Resource
private I WesternMedicineDispenseAppServiceImpl westernMedicineDispenseAppServiceImpl ;
private WesternMedicineDispenseAppServiceImpl westernMedicineDispenseAppServiceImpl ;
@Resource
private I ReturnMedicineAppServiceImpl returnedMedicineAppServiceImpl ;
private ReturnMedicineAppServiceImpl returnedMedicineAppServiceImpl ;
@Resource
private AssignSeqUtil assignSeqUtil ;
@@ -126,7 +127,6 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
// 设置模糊查询的字段名
HashSet < String > searchFields = new HashSet < > ( ) ;
searchFields . add ( CommonConstants . FieldName . PatientName ) ;
searchFields . add ( CommonConstants . FieldName . idCard ) ;
searchFields . add ( CommonConstants . FieldName . PatientPyStr ) ;
searchFields . add ( CommonConstants . FieldName . PatientWbStr ) ;
// 构建查询条件
@@ -253,11 +253,13 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
List < PerformInfoDto > devicePerformList = new ArrayList < > ( ) ;
for ( PerformInfoDto item : performInfoList ) {
if ( CommonConstants . TableName . WOR_SERVICE_REQUEST . equals ( item . getRequestTable ( ) )
| | CommonConstants . TableName . MED_MEDICATION_REQUEST . equals ( item . getRequestTable ( ) ) ) {
| | CommonConstants . TableName . MED_MEDICATION_REQUEST . equals ( item . getRequestTable ( ) )
| | CommonConstants . TableName . WOR_DEVICE_REQUEST . equals ( item . getRequestTable ( ) ) ) {
serviceMedPerformList . add ( item ) ;
} else if ( CommonConstants . TableName . WOR_DEVICE_REQUEST . equals ( item . getRequestTable ( ) ) ) {
devicePerformList . add ( item ) ;
}
// else if (CommonConstants.TableName.WOR_DEVICE_REQUEST.equals(item.getRequestTable())) {
// devicePerformList.add(item);
// }
}
// 分别处理诊疗/药品执行和耗材发放
if ( ! serviceMedPerformList . isEmpty ( ) ) {
@@ -274,7 +276,7 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
encounterId = serviceRequest . getEncounterId ( ) ;
requestId = serviceRequest . getId ( ) ;
patientId = serviceRequest . getPatientId ( ) ;
exeCount = serviceRequest . getQuantity ( ) ;
exeCount = serviceRequest . getQuantity ( ) . intValue ( ) ;
}
} else if ( CommonConstants . TableName . MED_MEDICATION_REQUEST . equals ( performInfoDto . getRequestTable ( ) ) ) {
MedicationRequest medicationRequest =
@@ -324,105 +326,105 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
} else {
return R . fail ( MessageUtils . createMessage ( PromptMsgConstant . Common . M00007 , null ) ) ;
}
// todo: 因长大农大在执行的时候都不发耗材, 暂时注释掉
// // 返回信息
// String returnMsg = null;
// if (!devicePerformList.isEmpty()) {
// // 耗材请求id列表
// List<Long> devRequestIdList = devicePerformList.stream().map(PerformInfoDto::getRequestId).toList();
// // 获取耗材发放id列表
// List<Long> devDispenseIdList = performInfoList.stream().map(PerformInfoDto::getDispenseId).toList();
// // 获取库存信息
// List<InventoryDto> inventoryList = returnMedicineMapper.selectInventoryInfoList(devDispenseIdList, null,
// CommonConstants.TableName.MED_MEDICATION_DEFINITION, CommonConstants.TableName.ADM_DEVICE_DEFINITION);
// // 按每个耗材分组
// Map<Long, List<InventoryDto>> groupedByItemId =
// inventoryList.stream().collect(Collectors.groupingBy(InventoryDto::getItemId));
// // 遍历每个分组校验库存状态
// for (Map.Entry<Long, List<InventoryDto>> entry : groupedByItemId.entrySet()) {
// List<InventoryDto> groupItems = entry.getValue();
// if (groupItems.stream().map(InventoryDto::getInventoryStatusEnum)
// .allMatch(x -> x.equals(PublicationStatus.RETIRED.getValue()))) {
// // 库存停供校验
// return R.fail(groupItems.get(0).getItemName() + "库存已停供");
// }
// }
// List<InventoryItem> inventoryItemList = new ArrayList<>();
// if (!inventoryList.isEmpty()) {
// for (InventoryDto inventoryDto : inventoryList) {
// if (PublicationStatus.ACTIVE.getValue().equals(inventoryDto.getInventoryStatusEnum())) {
// InventoryItem inventoryItem = new InventoryItem();
// // 库存数量判定
// if (inventoryDto.getDispenseUnit().equals(inventoryDto.getInventoryUnitCode())) {
// // 当前库存数量(拆零单位)=当前库存数量(拆零单位)-请求数量
// BigDecimal quantity =
// inventoryDto.getInventoryQuantity().subtract(inventoryDto.getQuantity());
// // 库存数量判定
// if (quantity.compareTo(BigDecimal.ZERO) < 0) {
// // 库存数量不足
// return R.fail(inventoryDto.getItemName() + "当前库存数量不足");
// } else {
// inventoryItem.setId(inventoryDto.getInventoryId()).setQuantity(quantity);
// }
// } else {
// // 当前库存数量(拆零单位)=当前库存数量(拆零单位)-拆零数量(拆零比×请求数量)
// BigDecimal quantity = inventoryDto.getInventoryQuantity()
// .subtract(inventoryDto.getPartPercent().multiply(inventoryDto.getQuantity()));
// // 库存数量判定
// if (quantity.compareTo(BigDecimal.ZERO) < 0) {
// // 库存数量不足
// return R.fail(inventoryDto.getItemName() + "当前库存数量不足");
// } else {
// inventoryItem.setId(inventoryDto.getInventoryId()).setQuantity(quantity);
// }
// }
// inventoryItemList.add(inventoryItem);
// }
// }
// }
// // 发耗材信息查询
// List<DeviceDispense> dispenseList = deviceDispenseService
// .list(new LambdaQueryWrapper<DeviceDispense>().in(DeviceDispense::getId, devDispenseIdList));
// if (dispenseList != null) {
// for (DeviceDispense deviceDispense : dispenseList) {
// if (deviceDispense.getStatusEnum().equals(DispenseStatus.PREPARATION.getValue())) {
// // 耗材发放状态
// deviceDispense.setStatusEnum(DispenseStatus.COMPLETED.getValue());
// // 发药数量
// deviceDispense.setDispenseQuantity(deviceDispense.getQuantity());
// // 发药时间
// deviceDispense.setDispenseTime(DateUtils.getNowDate());
// // 发药人
// deviceDispense.setPerformerId(SecurityUtils.getLoginUser().getPractitionerId());
// // 根据数量设置追溯码
// deviceDispense.setTraceNo(String.join(CommonConstants.Common.COMMA,
// Collections.nCopies(deviceDispense.getQuantity().intValue(), CommonConstants.Common.DEV_TRACE_NO)));
// }
// }
// // 药品发放更新
// deviceDispenseService.updateBatchById(dispenseList);
// } else {
// return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
// }
// // 库存更新
// inventoryItemService.updateBatchById(inventoryItemList);
// // 更新请求状态为已完成
// deviceRequestService.updateCompletedStatusBatch(devRequestIdList);
// 返回信息
String returnMsg = null ;
if ( ! devicePerformList . isEmpty ( ) ) {
// 耗材请求id列表
List < Long > devRequestIdList = devicePerformList . stream ( ) . map ( PerformInfoDto : : getRequestId ) . toList ( ) ;
// 获取耗材发放id列表
List < Long > devDispenseIdList = performInfoList . stream ( ) . map ( PerformInfoDto : : getDispenseId ) . toList ( ) ;
// 获取库存信息
List < InventoryDto > inventoryList = returnMedicineMapper . selectInventoryInfoList ( devDispenseIdList , null ,
CommonConstants . TableName . MED_MEDICATION_DEFINITION , CommonConstants . TableName . ADM_DEVICE_DEFINITION ) ;
// 按每个耗材分组
Map < Long , List < InventoryDto > > groupedByItemId =
inventoryList . stream ( ) . collect ( Collectors . groupingBy ( InventoryDto : : getItemId ) ) ;
// 遍历每个分组校验库存状态
for ( Map . Entry < Long , List < InventoryDto > > entry : groupedByItemId . entrySet ( ) ) {
List < InventoryDto > groupItems = entry . getValue ( ) ;
if ( groupItems . stream ( ) . map ( InventoryDto : : getInventoryStatusEnum )
. allMatch ( x - > x . equals ( PublicationStatus . RETIRED . getValue ( ) ) ) ) {
// 库存停供校验
return R . fail ( groupItems . get ( 0 ) . getItemName ( ) + " 库存已停供 " ) ;
}
}
List < InventoryItem > inventoryItemList = new ArrayList < > ( ) ;
if ( ! inventoryList . isEmpty ( ) ) {
for ( InventoryDto inventoryDto : inventoryList ) {
if ( PublicationStatus . ACTIVE . getValue ( ) . equals ( inventoryDto . getInventoryStatusEnum ( ) ) ) {
InventoryItem inventoryItem = new InventoryItem ( ) ;
// 库存数量判定
if ( inventoryDto . getDispenseUnit ( ) . equals ( inventoryDto . getInventoryUnitCode ( ) ) ) {
// 当前库存数量(拆零单位)=当前库存数量(拆零单位)-请求数量
BigDecimal quantity =
inventoryDto . getInventoryQuantity ( ) . subtract ( inventoryDto . getQuantity ( ) ) ;
// 库存数量判定
if ( quantity . compareTo ( BigDecimal . ZERO ) < 0 ) {
// 库存数量不足
return R . fail ( inventoryDto . getItemName ( ) + " 当前库存数量不足 " ) ;
} else {
inventoryItem . setId ( inventoryDto . getInventoryId ( ) ) . setQuantity ( quantity ) ;
}
} else {
// 当前库存数量(拆零单位)=当前库存数量(拆零单位)-拆零数量(拆零比×请求数量)
BigDecimal quantity = inventoryDto . getInventoryQuantity ( )
. subtract ( inventoryDto . getPartPercent ( ) . multiply ( inventoryDto . getQuantity ( ) ) ) ;
// 库存数量判定
if ( quantity . compareTo ( BigDecimal . ZERO ) < 0 ) {
// 库存数量不足
return R . fail ( inventoryDto . getItemName ( ) + " 当前库存数量不足 " ) ;
} else {
inventoryItem . setId ( inventoryDto . getInventoryId ( ) ) . setQuantity ( quantity ) ;
}
}
inventoryItemList . add ( inventoryItem ) ;
}
}
}
// 发耗材信息查询
List < DeviceDispense > dispenseList = deviceDispenseService
. list ( new LambdaQueryWrapper < DeviceDispense > ( ) . in ( DeviceDispense : : getId , devDispenseIdList ) ) ;
if ( dispenseList ! = null ) {
for ( DeviceDispense deviceDispense : dispenseList ) {
if ( deviceDispense . getStatusEnum ( ) . equals ( DispenseStatus . PREPARATION . getValue ( ) ) ) {
// 耗材发放状态
deviceDispense . setStatusEnum ( DispenseStatus . COMPLETED . getValue ( ) ) ;
// 发药数量
deviceDispense . setDispenseQuantity ( deviceDispense . getQuantity ( ) ) ;
// 发药时间
deviceDispense . setDispenseTime ( DateUtils . getNowDate ( ) ) ;
// 发药人
deviceDispense . setPerformerId ( SecurityUtils . getLoginUser ( ) . getPractitionerId ( ) ) ;
// 根据数量设置追溯码
deviceDispense . setTraceNo ( String . join ( CommonConstants . Common . COMMA ,
Collections . nCopies ( deviceDispense . getQuantity ( ) , CommonConstants . Common . DEV_TRACE_NO ) ) ) ;
}
}
// 药品发放更新
deviceDispenseService . updateBatchById ( dispenseList ) ;
} else {
return R . fail ( MessageUtils . createMessage ( PromptMsgConstant . Common . M00007 , null ) ) ;
}
// 库存更新
inventoryItemService . updateBatchById ( inventoryItemList ) ;
// 更新请求状态为已完成
deviceRequestService . updateCompletedStatusBatch ( devRequestIdList ) ;
// 调用医保商品销售接口
String ybSwitch = SecurityUtils . getLoginUser ( ) . getOptionJson ( ) . getString ( CommonConstants . Option . YB_SWITCH ) ;
// 医保开关
if ( Whether . YES . getCode ( ) . equals ( ybSwitch ) ) {
List < String > uploadFailedNoList =
westernMedicineDispenseAppServiceImpl . ybMedicineIntegrated ( null , devDispenseIdList ) ;
if ( uploadFailedNoList ! = null ) {
returnMsg = " 3505商品销售上传错误, 错误项目编码 " + uploadFailedNoList ;
} else {
returnMsg = " 3505商品销售上传成功 " ;
}
}
}
return R . ok ( returnMsg , " 执行成功 " ) ;
// // 调用医保商品销售接口
// String ybSwitch = SecurityUtils.getLoginUser().getOptionJson().getString(CommonConstants.Option.YB_SWITCH) ;
// // 医保开关
// if (Whether.YES.getCode().equals(ybSwitch)) {
// List<String> uploadFailedNoList =
// westernMedicineDispenseAppServiceImpl.ybMedicineIntegrated(null, devDispenseIdList);
// if (uploadFailedNoList != null) {
// returnMsg = "3505商品销售上传错误, 错误项目编码" + uploadFailedNoList;
// } else {
// returnMsg = "3505商品销售上传成功" ;
// }
// }
// }
return R . ok ( " 执行成功 " ) ;
}
/**
@@ -508,7 +510,7 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
// 生成退耗材请求
deviceRequest . setId ( null ) ; // 耗材请求id
deviceRequest . setBusNo ( assignSeqUtil . getSeqByDay ( AssignSeqEnum . DEVICE_RES_NO . getPrefix ( ) , 4 ) ) ; // 耗材请求编码
deviceRequest . setQuantity ( deviceRequest . getQuantity ( ) * ( - 1 ) ) ; // 请求数量
deviceRequest . setQuantity ( deviceRequest . getQuantity ( ) . multiply ( new BigDecimal ( " -1 " ) ) ) ; // 请求数量
deviceRequest . setStatusEnum ( RequestStatus . CANCELLED . getValue ( ) ) ; // 请求状态
deviceRequest . setRefundDeviceId ( deviceRequest . getId ( ) ) ; // 退药id
deviceRequestService . save ( deviceRequest ) ;
@@ -588,4 +590,24 @@ public class OutpatientTreatmentAppServiceImpl implements IOutpatientTreatmentAp
}
return R . ok ( returnMsg , " 取消执行成功 " ) ;
}
/**
* 输血贴查询
*
* @param requestId 请求id
* @return 输血贴
*/
@Override
public R < ? > getBloodTransfusionPatch ( Long requestId ) {
BloodTransfusionPatchDto bloodTransfusionPatch =
outpatientTreatmentAppMapper . getBloodTransfusionPatch ( requestId ) ;
// 性别枚举
bloodTransfusionPatch . setGenderEnum_enumText (
EnumUtils . getInfoByValue ( AdministrativeGender . class , bloodTransfusionPatch . getGenderEnum ( ) ) ) ;
// 计算年龄
if ( bloodTransfusionPatch . getBirthDate ( ) ! = null ) {
bloodTransfusionPatch . setAge ( AgeCalculatorUtil . getAge ( bloodTransfusionPatch . getBirthDate ( ) ) ) ;
}
return R . ok ( bloodTransfusionPatch ) ;
}
}