liusheng
16 小时以前 971bd30b611531464d7a878352e453ab4511f93f
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
@@ -11,13 +11,17 @@
import cn.lihu.jh.module.ecg.dal.dataobject.patient.PatDetails;
import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper;
import cn.lihu.jh.module.ecg.enums.AppointmentTypeEnum;
import cn.lihu.jh.module.ecg.enums.HisCheckCodeEnum;
import cn.lihu.jh.module.ecg.feign.RemoteDataService;
import cn.lihu.jh.module.ecg.service.config.EcgConfigService;
import cn.lihu.jh.module.ecg.service.devrent.ApplicationTemplate;
import cn.lihu.jh.module.ecg.service.queue.QueueService;
import cn.lihu.jh.module.ecg.service.queuesequence.QueueSequenceService;
import cn.lihu.jh.module.ecg.webservice.WebServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,6 +65,9 @@
    @Resource
    private AppointmentMapper appointmentMapper;
    @Autowired
    private WebServiceClient webServiceClient;
    @Override
    public Long createAppointment(AppointmentSaveReqVO createReqVO) {
        // 插入
@@ -83,6 +90,42 @@
        // 更新
        AppointmentDO updateObj = BeanUtils.toBean(updateReqVO, AppointmentDO.class);
        appointmentMapper.updateById(updateObj);
    }
    @Override
    public void updateAppointmentStatus(AppointmentSaveReqVO updateReqVO) {
        // 校验存在
        validateAppointmentExists(updateReqVO.getId());
        // 获取完整的预约信息
        AppointmentDO appointment = appointmentMapper.selectById(updateReqVO.getId());
        if (appointment == null) {
            throw exception(APPOINTMENT_NOT_EXISTS);
        }
        // 更新状态
        appointment.setStatus(updateReqVO.getStatus());
        // 调用HIS系统更新状态
        String action = "S0405";
        ApplicationTemplate app = new ApplicationTemplate();
        String statusName = AppointmentTypeEnum.getByType(appointment.getStatus());
        String message = app.getXML(appointment.getApplyNo(), appointment.getStatus(), statusName, null, appointment.getPatDeptCode(), appointment.getPatDeptDesc(), appointment.getPatWardCode(), appointment.getPatWardDesc(), appointment.getPatBedNo(), appointment.getEpisodeId(), String.valueOf(appointment.getBookSrc()), appointment.getPatId(), appointment.getPatName());
        try {
            String response = webServiceClient.callJHFWTYRK(action, "", message);
            if (response.contains("更新成功")) {
                // 更新本地数据库
                appointmentMapper.updateById(appointment);
            } else {
                throw exception(APPOINTMENT_UPDATE_FAIL);
            }
        } catch (Exception e) {
            log.error("[updateAppointmentStatus][更新预约状态失败 appointment({})]", appointment, e);
            throw exception(APPOINTMENT_UPDATE_FAIL);
        }
    }
    @Override
@@ -117,7 +160,7 @@
    @Override
    public List<AppointmentDO> queryAndCreateAppointmentByPatId(String patCode) {
        // 从医院平台查询
        List<AppointmentDO> appointmentExtermalList = getAppointmentExtermal(patCode);
        List<AppointmentDO> appointmentExtermalList = appointmentMapper.getCurrentCode(patCode);
        for (int appointmentIndex = 0; appointmentIndex < appointmentExtermalList.size(); appointmentIndex++) {
            AppointmentDO appointmentExtermal = appointmentExtermalList.get(appointmentIndex);
@@ -301,6 +344,13 @@
            Optional.ofNullable(encounter.get("location")).map(location -> (Map<String, Object>) location).map(location -> (Map<String, Object>) location.get("serviceDeliveryLocation")).map(serviceDeliveryLocation -> (Map<String, Object>) serviceDeliveryLocation.get("location")).map(location -> (Map<String, Object>) location.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatBedNo);
            Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("zdy")).map(zdy -> {
                Object ISDN = zdy.get("ISDN");
                if (ISDN != null) {
                    return ISDN.toString();
                }
                return null;
            }).ifPresent(appointment::setTolerance);
            // 设置患者来源类型
            Optional.ofNullable(encounter.get("code")).map(code -> (Map<String, Object>) code).map(code -> (String) code.get("code")).map(Integer::parseInt).ifPresent(appointment::setPatSrc);
@@ -309,6 +359,12 @@
            Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("patientPerson")).ifPresent(patientPerson -> {
                // 设置患者ID
                Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(1)).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatId);
                // 设置患者门诊号
                Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(2)).map(item -> (String) item.get("extension")).ifPresent(appointment::setOutpatientNo);
                // 设置患者住院号
                Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(2)).map(item -> (String) item.get("extension")).ifPresent(appointment::setHospitalNo);
                // 设置患者姓名
                Optional.ofNullable(patientPerson.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(appointment::setPatName);
@@ -330,6 +386,9 @@
                // 设置患者身份证号
                Optional.ofNullable(patientPerson.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> !items.isEmpty()).map(items -> (Map<String, Object>) items.get(0)).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatIdentityId);
                //患者医保卡
                Optional.ofNullable(patientPerson.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> !items.isEmpty()).map(items -> (Map<String, Object>) items.get(1)).map(item -> (String) item.get("extension")).ifPresent(appointment::setMedicalCard);
            });
            // 设置科室和病区信息
@@ -371,7 +430,6 @@
            // 将AppointmentDO转换为AppointmentSaveReqVO并保存
            AppointmentSaveReqVO saveReqVO = BeanUtils.toBean(appointment, AppointmentSaveReqVO.class);
            saveReqVO.setStatus("1");
            return createAppointment(saveReqVO);
        } catch (Exception e) {
            log.error("[handleAppointmentCreate][处理预约创建失败 dataMap({})]", dataMap, e);
@@ -559,22 +617,27 @@
        // 解析预约时间
        LocalDateTime bookTime = LocalDateTime.parse(bookTimeStr, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        LocalDate bookDate = bookTime.toLocalDate();
        Integer bookTimeslot = null;
        // 获取时间段
        String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");
        String[] time1 = timeRange.split(" ");
        String[] times = time1[1].split("-");
        String startTime = times[0].trim();
        String endTime = times[1].trim();
        // 转换时间段格式为hhmmhhmm
        int bookTimeslot = Integer.parseInt(startTime.replace(":", "")) * 10000 + Integer.parseInt(endTime.replace(":", ""));
        try {
//            String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");这行如果是更新操作的时候,有可能报空指针(但不影响,可以不用管)
            String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");
            String[] time1 = timeRange.split(" ");
            String[] times = time1[1].split("-");
            String startTime = times[0].trim();
            String endTime = times[1].trim();
            // 转换时间段格式为hhmmhhmm
            bookTimeslot = Integer.parseInt(startTime.replace(":", "")) * 10000 + Integer.parseInt(endTime.replace(":", ""));
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 更新预约信息
        appointment.setBookDate(bookDate);
        appointment.setBookTimeslot(bookTimeslot);
        appointment.setBookTime(bookTime);
        appointment.setBookSrc(Integer.parseInt(bookSrc));
        appointment.setStatus((String) ((Map<String, Object>) actAppointment.get("ZDY")).get("statusCode"));
        // 保存更新
        appointmentMapper.updateById(appointment);