package com.openhis.web.regdoctorstation.appservice.impl;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.core.common.core.domain.R;
import com.core.common.utils.AssignSeqUtil;
import com.core.common.utils.MessageUtils;
import com.core.common.utils.SecurityUtils;
import com.openhis.common.constant.CommonConstants;
import com.openhis.common.constant.PromptMsgConstant;
import com.openhis.common.enums.*;
import com.openhis.document.domain.OrderProcess;
import com.openhis.document.service.IOrderProcessService;
import com.openhis.web.doctorstation.appservice.IDoctorStationAdviceAppService;
import com.openhis.web.doctorstation.dto.AdviceBaseDto;
import com.openhis.web.regdoctorstation.appservice.ISpecialAdviceAppService;
import com.openhis.web.regdoctorstation.dto.*;
import com.openhis.web.regdoctorstation.mapper.SpecialAdviceAppMapper;
import com.openhis.workflow.domain.ServiceRequest;
import com.openhis.workflow.service.IActivityDefinitionService;
import com.openhis.workflow.service.IServiceRequestService;

import lombok.extern.slf4j.Slf4j;

/**
 * 特殊医嘱 应用实现类
 */
@Slf4j
@Service
public class SpecialAdviceAppServiceImpl implements ISpecialAdviceAppService {

    @Resource
    SpecialAdviceAppMapper specialAdviceAppMapper;

    @Resource
    AssignSeqUtil assignSeqUtil;

    @Resource
    IServiceRequestService iServiceRequestService;

    @Resource
    IDoctorStationAdviceAppService iDoctorStationAdviceAppService;

    @Resource
    IActivityDefinitionService iActivityDefinitionService;

    @Resource
    IOrderProcessService iOrderProcessService;

    /**
     * 查询护理医嘱信息
     *
     * @return 护理医嘱信息
     */
    @Override
    public NursingOrdersDto getNursingOrdersInfos() {
        NursingOrdersDto nursingOrdersDto = new NursingOrdersDto();
        // 类型为护理医嘱的编码集合
        List<String> categoryCodeList =
            Arrays.stream(NursingOrdersClass.values()).map(NursingOrdersClass::getCode).collect(Collectors.toList());
        List<NursingOrdersDetailDto> nursingOrdersInfos =
            specialAdviceAppMapper.getNursingOrdersInfos(categoryCodeList);
        // 按categoryCode进行分组
        Map<String, List<NursingOrdersDetailDto>> groupedByCategory =
            nursingOrdersInfos.stream().collect(Collectors.groupingBy(NursingOrdersDetailDto::getCategoryCode));
        // 根据不同的categoryCode赋值给对应的List
        for (Map.Entry<String, List<NursingOrdersDetailDto>> entry : groupedByCategory.entrySet()) {
            String categoryCode = entry.getKey();
            List<NursingOrdersDetailDto> detailList = entry.getValue();
            switch (categoryCode) {
                case "26": // 护理
                    nursingOrdersDto.setNursingList(detailList);
                    break;
                case "38": // 病情
                    nursingOrdersDto.setConditionList(detailList);
                    break;
                case "39": // 护理常规
                    nursingOrdersDto.setNursingRoutineList(detailList);
                    break;
                case "27": // 膳食
                    nursingOrdersDto.setDietList(detailList);
                    break;
                case "40": // 体位
                    nursingOrdersDto.setPositionList(detailList);
                    break;
                case "41": // 陪护
                    nursingOrdersDto.setCompanionCareList(detailList);
                    break;
                case "42": // 隔离等级
                    nursingOrdersDto.setIsolationLevelList(detailList);
                    break;
                default:
                    break;
            }
        }
        return nursingOrdersDto;
    }

    /**
     * 保存护理医嘱
     *
     * @param nursingOrdersSaveDto 护理医嘱保存dto
     * @return 结果
     */
    @Override
    public R<?> saveNursingOrders(NursingOrdersSaveDto nursingOrdersSaveDto) {
        // 当前登录账号参与者id
        Long practitionerId = SecurityUtils.getLoginUser().getPractitionerId();
        // 当前时间
        Date curDate = new Date();
        // 医嘱开始时间
        Date startTime = nursingOrdersSaveDto.getStartTime();
        if (startTime == null) {
            startTime = curDate;
        }
        // 就诊id
        Long encounterId = nursingOrdersSaveDto.getEncounterId();
        // 患者
        Long patientId = nursingOrdersSaveDto.getPatientId();
        // 诊断ID
        Long conditionId = nursingOrdersSaveDto.getConditionId();
        // 就诊诊断id
        Long encounterDiagnosisId = nursingOrdersSaveDto.getEncounterDiagnosisId();
        // 护理医嘱详情保存集合
        List<NursingOrdersSaveDetailDto> nursingOrdersSaveDetailDtoList =
            nursingOrdersSaveDto.getNursingOrdersSaveDetailDtoList();
        // 声明长期医嘱诊疗请求
        ServiceRequest longServiceRequest;
        // 已经存在的有效医嘱
        ServiceRequest alreadyExistsLongServiceRequest;
        // 医嘱定义id
        Long definitionId;
        AdviceBaseDto adviceBaseDto;
        AdviceBaseDto activityAdviceBaseDto;
        for (NursingOrdersSaveDetailDto nursingOrdersSaveDetailDto : nursingOrdersSaveDetailDtoList) {
            definitionId = nursingOrdersSaveDetailDto.getDefinitionId();
            Integer categoryEnum = nursingOrdersSaveDetailDto.getCategoryEnum();
            // 查询已经存在的有效医嘱
            LambdaQueryWrapper<ServiceRequest> lambdaQuery = new LambdaQueryWrapper<>();
            lambdaQuery.eq(ServiceRequest::getEncounterId, encounterId)
                .eq(ServiceRequest::getCategoryEnum, categoryEnum)
                .and(wrapper -> wrapper.eq(ServiceRequest::getStatusEnum, RequestStatus.DRAFT.getValue()).or()
                    .eq(ServiceRequest::getStatusEnum, RequestStatus.ACTIVE.getValue()).or()
                    .eq(ServiceRequest::getStatusEnum, RequestStatus.COMPLETED.getValue()))
                .orderByDesc(ServiceRequest::getCreateTime).last("LIMIT 1");
            alreadyExistsLongServiceRequest = iServiceRequestService.getOne(lambdaQuery);

            longServiceRequest = new ServiceRequest();

            if (alreadyExistsLongServiceRequest == null) {
                if (definitionId != null) {
                    adviceBaseDto = new AdviceBaseDto();
                    adviceBaseDto.setAdviceDefinitionId(definitionId); // 医嘱定义id
                    // 对应的诊疗医嘱信息
                    activityAdviceBaseDto = iDoctorStationAdviceAppService.getAdviceBaseInfo(adviceBaseDto, null, null,
                        null, null, 1, 1, Whether.NO.getValue(), List.of(3)).getRecords().get(0);
                    // 逻辑1---------------------直接新增
                    longServiceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());// 请求状态
                    longServiceRequest.setOccurrenceStartTime(startTime); // 医嘱开始时间
                    longServiceRequest.setBusNo(assignSeqUtil.getSeqByDay(AssignSeqEnum.SERVICE_RES_NO.getPrefix(), 4));
                    longServiceRequest.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue()); // 生成来源
                    longServiceRequest.setQuantity(new BigDecimal("1")); // 请求数量
                    longServiceRequest.setUnitCode(activityAdviceBaseDto.getUnitCode()); // 请求单位编码
                    longServiceRequest.setCategoryEnum(categoryEnum); // 请求类型
                    longServiceRequest.setTherapyEnum(TherapyTimeType.LONG_TERM.getValue()); // 治疗类型
                    longServiceRequest.setActivityId(definitionId);// 诊疗定义id
                    longServiceRequest.setPatientId(patientId); // 患者
                    longServiceRequest.setRequesterId(practitionerId); // 开方医生
                    longServiceRequest.setEncounterId(encounterId); // 就诊id
                    longServiceRequest.setOrgId(activityAdviceBaseDto.getPositionId()); // 执行科室
                    // longServiceRequest.setYbClassEnum();// 类别医保编码
                    longServiceRequest.setConditionId(conditionId); // 诊断id
                    longServiceRequest.setEncounterDiagnosisId(encounterDiagnosisId); // 就诊诊断id
                    iServiceRequestService.save(longServiceRequest);
                }
                // definitionId == null 时什么也不做，跳出本次循环
                continue;
            }
            // alreadyExistsLongServiceRequest != null 的情况
            if (definitionId == null) {
                // 逻辑2---------------------停掉原有的
                iServiceRequestService.update(new LambdaUpdateWrapper<ServiceRequest>()
                    .eq(ServiceRequest::getId, alreadyExistsLongServiceRequest.getId())
                    .set(ServiceRequest::getOccurrenceEndTime, curDate)
                    .set(ServiceRequest::getStatusEnum, RequestStatus.STOPPED.getValue()));
                continue;
            }

            if (alreadyExistsLongServiceRequest.getActivityId().equals(definitionId)) {
                // 逻辑3---------------------没有变化,跳出本次循环
                continue;
            }
            // 逻辑4---------------------先停掉原有的,再新增
            iServiceRequestService.update(new LambdaUpdateWrapper<ServiceRequest>()
                .eq(ServiceRequest::getId, alreadyExistsLongServiceRequest.getId())
                .set(ServiceRequest::getOccurrenceEndTime, curDate)
                .set(ServiceRequest::getStatusEnum, RequestStatus.STOPPED.getValue()));

            adviceBaseDto = new AdviceBaseDto();
            adviceBaseDto.setAdviceDefinitionId(definitionId); // 医嘱定义id
            // 对应的诊疗医嘱信息
            activityAdviceBaseDto = iDoctorStationAdviceAppService
                .getAdviceBaseInfo(adviceBaseDto, null, null, null, null, 1, 1, Whether.NO.getValue(), List.of(3))
                .getRecords().get(0);

            longServiceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());// 请求状态
            longServiceRequest.setOccurrenceStartTime(startTime); // 医嘱开始时间
            longServiceRequest.setBusNo(assignSeqUtil.getSeqByDay(AssignSeqEnum.SERVICE_RES_NO.getPrefix(), 4));
            longServiceRequest.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue()); // 生成来源
            longServiceRequest.setQuantity(new BigDecimal("1")); // 请求数量
            longServiceRequest.setUnitCode(activityAdviceBaseDto.getUnitCode()); // 请求单位编码
            longServiceRequest.setCategoryEnum(categoryEnum); // 请求类型
            longServiceRequest.setTherapyEnum(TherapyTimeType.LONG_TERM.getValue()); // 治疗类型
            longServiceRequest.setActivityId(definitionId);// 诊疗定义id
            longServiceRequest.setPatientId(patientId); // 患者
            longServiceRequest.setRequesterId(practitionerId); // 开方医生
            longServiceRequest.setEncounterId(encounterId); // 就诊id
            longServiceRequest.setOrgId(activityAdviceBaseDto.getPositionId()); // 执行科室
            // longServiceRequest.setYbClassEnum();// 类别医保编码
            longServiceRequest.setConditionId(conditionId); // 诊断id
            longServiceRequest.setEncounterDiagnosisId(encounterDiagnosisId); // 就诊诊断id
            iServiceRequestService.save(longServiceRequest);

        }

        return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"护理医嘱"}));
    }

    /**
     * 查询就诊护理医嘱
     *
     * @param encounterId 就诊id
     * @return 就诊护理医嘱
     */
    @Override
    public NursingOrdersEncounterDto getEncounterNursingOrdersInfos(Long encounterId) {
        NursingOrdersEncounterDto nursingOrdersEncounterDto = new NursingOrdersEncounterDto();
        // 类型为护理医嘱的枚举集合
        List<Integer> categoryEnumList =
            Arrays.stream(NursingOrdersClass.values()).map(NursingOrdersClass::getValue).collect(Collectors.toList());
        // 查询查询就诊护理医嘱 ; 为了排除可能存在的数据问题,每个categoryEnum按创建时间取最新的一条
        List<NursingOrdersEncounterDetailDto> encounterNursingOrdersInfos =
            specialAdviceAppMapper.getEncounterNursingOrdersInfos(encounterId, RequestStatus.DRAFT.getValue(),
                RequestStatus.ACTIVE.getValue(), RequestStatus.COMPLETED.getValue(), categoryEnumList);
        if (!encounterNursingOrdersInfos.isEmpty()) {
            // 按categoryEnum进行分组
            Map<Integer, List<NursingOrdersEncounterDetailDto>> groupedByCategory = encounterNursingOrdersInfos.stream()
                .collect(Collectors.groupingBy(NursingOrdersEncounterDetailDto::getCategoryEnum));
            // 根据不同的categoryCode赋值给对应的List
            for (Map.Entry<Integer, List<NursingOrdersEncounterDetailDto>> entry : groupedByCategory.entrySet()) {
                Integer categoryEnum = entry.getKey();
                NursingOrdersEncounterDetailDto detail = entry.getValue().get(0);
                switch (categoryEnum) {
                    case 26: // 护理
                        nursingOrdersEncounterDto.setNursing(detail);
                        break;
                    case 38: // 病情
                        nursingOrdersEncounterDto.setCondition(detail);
                        break;
                    case 39: // 护理常规
                        nursingOrdersEncounterDto.setNursingRoutine(detail);
                        break;
                    case 27: // 膳食
                        nursingOrdersEncounterDto.setDiet(detail);
                        break;
                    case 40: // 体位
                        nursingOrdersEncounterDto.setPosition(detail);
                        break;
                    case 41: // 陪护
                        nursingOrdersEncounterDto.setCompanionCare(detail);
                        break;
                    case 42: // 隔离等级
                        nursingOrdersEncounterDto.setIsolationLevel(detail);
                        break;
                    default:
                        break;
                }
            }
        }

        return nursingOrdersEncounterDto;
    }

    /**
     * 保存转科医嘱
     *
     * @param transferOrganizationParam 转科医嘱参数
     * @return 结果
     */
    @Override
    public R<?> saveTransferOrganizationOrders(TransferOrganizationParam transferOrganizationParam) {
        // 当前登录账号参与者id
        Long practitionerId = SecurityUtils.getLoginUser().getPractitionerId();
        // 当前时间
        Date curDate = new Date();
        // 医嘱开始时间
        Date startTime = transferOrganizationParam.getStartTime();
        if (startTime == null) {
            startTime = curDate;
        }
        // 就诊id
        Long encounterId = transferOrganizationParam.getEncounterId();
        // 患者
        Long patientId = transferOrganizationParam.getPatientId();
        // 诊断ID
        Long conditionId = transferOrganizationParam.getConditionId();
        // 就诊诊断id
        Long encounterDiagnosisId = transferOrganizationParam.getEncounterDiagnosisId();

        // 转科的医嘱定义id
        Long transferOrganizationDefinitionId = iActivityDefinitionService
            .getAppointActivityDefinitionId(CommonConstants.BusinessName.TRANSFER_ORGANIZATION);
        if (transferOrganizationDefinitionId == null) {
            return R.fail("请先在诊疗目录维护转科医嘱");
        }
        // 出院的医嘱定义id
        Long leaveHospitalDefinitionId =
            iActivityDefinitionService.getAppointActivityDefinitionId(CommonConstants.BusinessName.LEAVE_HOSPITAL);
        if (leaveHospitalDefinitionId != null) {
            LambdaQueryWrapper<ServiceRequest> leaveLambdaQuery = new LambdaQueryWrapper<>();
            leaveLambdaQuery.eq(ServiceRequest::getEncounterId, encounterId)
                .eq(ServiceRequest::getActivityId, leaveHospitalDefinitionId)
                .and(wrapper -> wrapper.eq(ServiceRequest::getStatusEnum, RequestStatus.DRAFT.getValue()).or()
                    .eq(ServiceRequest::getStatusEnum, RequestStatus.ACTIVE.getValue()).or());
            if (!iServiceRequestService.list(leaveLambdaQuery).isEmpty()) {
                return R.fail("已经开立出院医嘱,请勿开立转科医嘱");
            }
        }

        // 校验重复开立
        LambdaQueryWrapper<ServiceRequest> lambdaQuery = new LambdaQueryWrapper<>();
        lambdaQuery.eq(ServiceRequest::getEncounterId, encounterId)
            .eq(ServiceRequest::getActivityId, transferOrganizationDefinitionId)
            .and(wrapper -> wrapper.eq(ServiceRequest::getStatusEnum, RequestStatus.DRAFT.getValue()).or()
                .eq(ServiceRequest::getStatusEnum, RequestStatus.ACTIVE.getValue()).or());
        if (!iServiceRequestService.list(lambdaQuery).isEmpty()) {
            return R.fail("请勿重复开立转科医嘱");
        }
        AdviceBaseDto adviceBaseDto = new AdviceBaseDto();
        adviceBaseDto.setAdviceDefinitionId(transferOrganizationDefinitionId); // 医嘱定义id
        // 转科的医嘱信息
        AdviceBaseDto activityAdviceBaseDto = iDoctorStationAdviceAppService
            .getAdviceBaseInfo(adviceBaseDto, null, null, null, null, 1, 1, Whether.NO.getValue(), List.of(3))
            .getRecords().get(0);
        // 保存转科医嘱请求
        ServiceRequest serviceRequest = new ServiceRequest();
        serviceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());// 请求状态
        serviceRequest.setOccurrenceStartTime(startTime); // 医嘱开始时间
        serviceRequest.setBusNo(assignSeqUtil.getSeqByDay(AssignSeqEnum.SERVICE_RES_NO.getPrefix(), 4));
        serviceRequest.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue()); // 生成来源
        serviceRequest.setQuantity(new BigDecimal("1")); // 请求数量
        serviceRequest.setUnitCode(activityAdviceBaseDto.getUnitCode()); // 请求单位编码
        serviceRequest.setCategoryEnum(Integer.valueOf(activityAdviceBaseDto.getCategoryCode())); // 请求类型
        serviceRequest.setTherapyEnum(TherapyTimeType.TEMPORARY.getValue()); // 治疗类型
        serviceRequest.setReasonText(transferOrganizationParam.getReasonText()); // 理由
        serviceRequest.setActivityId(transferOrganizationDefinitionId);// 诊疗定义id
        serviceRequest.setPatientId(patientId); // 患者
        serviceRequest.setRequesterId(practitionerId); // 开方医生
        serviceRequest.setEncounterId(encounterId); // 就诊id
        serviceRequest.setOrgId(activityAdviceBaseDto.getPositionId()); // 执行科室
        serviceRequest.setConditionId(conditionId); // 诊断id
        serviceRequest.setEncounterDiagnosisId(encounterDiagnosisId); // 就诊诊断id
        iServiceRequestService.save(serviceRequest);

        // 保存转科医嘱请求的过程数据
        OrderProcess orderProcess = new OrderProcess();
        orderProcess.setName(CommonConstants.BusinessName.TRANSFER_ORGANIZATION); // 名称
        orderProcess.setEncounterId(encounterId); // 就诊id
        orderProcess.setRequestId(serviceRequest.getId()); // 请求id
        orderProcess.setRequestTableName(CommonConstants.TableName.WOR_SERVICE_REQUEST); // 请求表名
        orderProcess.setOriginalOrganizationId(transferOrganizationParam.getOriginalOrganizationId()); // 原科室
        orderProcess.setTargetOrganizationId(transferOrganizationParam.getTargetOrganizationId()); // 目标科室
        orderProcess.setOriginalLocationId(transferOrganizationParam.getOriginalLocationId()); // 原病区
        orderProcess.setTargetLocationId(transferOrganizationParam.getTargetLocationId()); // 目标病区
        iOrderProcessService.save(orderProcess);

        return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"转科医嘱"}));
    }

    /**
     * 保存离院医嘱
     *
     * @param leaveHospitalParam 转科离院参数
     * @return 结果
     */
    @Override
    public R<?> saveLeaveHospitalOrders(LeaveHospitalParam leaveHospitalParam) {
        // 当前登录账号参与者id
        Long practitionerId = SecurityUtils.getLoginUser().getPractitionerId();
        // 当前时间
        Date curDate = new Date();
        // 计划出院时间
        Date endTime = leaveHospitalParam.getEndTime();
        if (endTime == null) {
            endTime = endTime;
        }
        // 就诊id
        Long encounterId = leaveHospitalParam.getEncounterId();
        // 患者
        Long patientId = leaveHospitalParam.getPatientId();
        // 诊断ID
        Long conditionId = leaveHospitalParam.getConditionId();
        // 就诊诊断id
        Long encounterDiagnosisId = leaveHospitalParam.getEncounterDiagnosisId();

        // 出院的医嘱定义id
        Long transferOrganizationDefinitionId =
            iActivityDefinitionService.getAppointActivityDefinitionId(CommonConstants.BusinessName.LEAVE_HOSPITAL);
        if (transferOrganizationDefinitionId == null) {
            return R.fail("请先在诊疗目录维护出院医嘱");
        }

        // 校验重复开立
        LambdaQueryWrapper<ServiceRequest> lambdaQuery = new LambdaQueryWrapper<>();
        lambdaQuery.eq(ServiceRequest::getEncounterId, encounterId)
            .eq(ServiceRequest::getActivityId, transferOrganizationDefinitionId)
            .and(wrapper -> wrapper.eq(ServiceRequest::getStatusEnum, RequestStatus.DRAFT.getValue()).or()
                .eq(ServiceRequest::getStatusEnum, RequestStatus.ACTIVE.getValue()).or());
        if (!iServiceRequestService.list(lambdaQuery).isEmpty()) {
            return R.fail("请勿重复开立出院医嘱");
        }

        // 出院的医嘱信息
        AdviceBaseDto activityAdviceBaseDto = iDoctorStationAdviceAppService.getAdviceBaseInfo(null, null, null,
            List.of(transferOrganizationDefinitionId), null, 1, 1, Whether.NO.getValue(), List.of(3)).getRecords()
            .get(0);
        // 保存出院医嘱请求
        ServiceRequest serviceRequest = new ServiceRequest();
        serviceRequest.setStatusEnum(RequestStatus.DRAFT.getValue());// 请求状态
        serviceRequest.setOccurrenceStartTime(endTime); // 预计执行时间
        serviceRequest.setBusNo(assignSeqUtil.getSeqByDay(AssignSeqEnum.SERVICE_RES_NO.getPrefix(), 4));
        serviceRequest.setGenerateSourceEnum(GenerateSource.DOCTOR_PRESCRIPTION.getValue()); // 生成来源
        serviceRequest.setQuantity(new BigDecimal("1")); // 请求数量
        serviceRequest.setUnitCode(activityAdviceBaseDto.getUnitCode()); // 请求单位编码
        serviceRequest.setCategoryEnum(Integer.valueOf(activityAdviceBaseDto.getCategoryCode())); // 请求类型
        serviceRequest.setTherapyEnum(TherapyTimeType.TEMPORARY.getValue()); // 治疗类型
        serviceRequest.setReasonText(leaveHospitalParam.getReasonText()); // 理由
        serviceRequest.setActivityId(transferOrganizationDefinitionId);// 诊疗定义id
        serviceRequest.setPatientId(patientId); // 患者
        serviceRequest.setRequesterId(practitionerId); // 开方医生
        serviceRequest.setEncounterId(encounterId); // 就诊id
        serviceRequest.setOrgId(activityAdviceBaseDto.getPositionId()); // 执行科室
        serviceRequest.setConditionId(conditionId); // 诊断id
        serviceRequest.setEncounterDiagnosisId(encounterDiagnosisId); // 就诊诊断id
        iServiceRequestService.save(serviceRequest);

        // 保存出院医嘱请求的过程数据
        OrderProcess orderProcess = new OrderProcess();
        orderProcess.setName(CommonConstants.BusinessName.TRANSFER_ORGANIZATION); // 名称
        orderProcess.setEncounterId(encounterId); // 就诊id
        orderProcess.setRequestId(serviceRequest.getId()); // 请求id
        orderProcess.setRequestTableName(CommonConstants.TableName.WOR_SERVICE_REQUEST); // 请求表名
        orderProcess.setOutWayCode(leaveHospitalParam.getOutWayCode()); // 出院方式
        iOrderProcessService.save(orderProcess);

        return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"出院医嘱"}));
    }

}
