|
|
@@ -0,0 +1,267 @@
|
|
|
+package com.fs.app.facade.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fs.app.exception.FSException;
|
|
|
+import com.fs.app.facade.Hospital580FacadeService;
|
|
|
+import com.fs.common.core.domain.PageResponse;
|
|
|
+import com.fs.common.core.domain.Result;
|
|
|
+import com.fs.common.core.page.PageRequest;
|
|
|
+import com.fs.framework.aspectj.lock.DistributeLock;
|
|
|
+import com.fs.his.domain.FsPatient;
|
|
|
+import com.fs.his.service.IFsPatientService;
|
|
|
+import com.fs.his.utils.PhoneUtil;
|
|
|
+import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.service.IFsStoreOrderScrmService;
|
|
|
+import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
+import com.fs.hospital580.dto.*;
|
|
|
+import com.fs.hospital580.entity.*;
|
|
|
+import com.fs.hospital580.service.Hospital580PrescriptionAnswerScrmService;
|
|
|
+import com.fs.hospital580.service.Hospital580PrescriptionMedicineScrmService;
|
|
|
+import com.fs.hospital580.service.Hospital580PrescriptionScrmService;
|
|
|
+import com.fs.hospital580.service.Hospital580Service;
|
|
|
+import com.fs.hospital580.vo.MedicineSyncVo;
|
|
|
+import com.fs.hospital580.vo.PrescriptionMedicineScrmVo;
|
|
|
+import com.fs.hospital580.vo.RefusePrescriptionVo;
|
|
|
+import com.fs.hospital580.vo.ReviewPrescriptionVo;
|
|
|
+import com.fs.hospital580.vo.req.DiseaseReq;
|
|
|
+import com.fs.hospital580.vo.req.Prescription580Req;
|
|
|
+import com.fs.hospital580.vo.req.SaveOrderScrmReq;
|
|
|
+import com.fs.hospital580.vo.res.DiseaseQueryRes;
|
|
|
+import com.fs.hospital580.vo.res.PrescriptionDetailRes;
|
|
|
+import com.fs.hospital580.vo.res.PrescriptionListRes;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.Period;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class Hospital580FacadeServiceImpl implements Hospital580FacadeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Hospital580Service hospital580Service;
|
|
|
+ @Autowired
|
|
|
+ private Hospital580PrescriptionAnswerScrmService answerScrmService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Hospital580PrescriptionScrmService orderScrmService;
|
|
|
+ @Autowired
|
|
|
+ private IFsPatientService fsPatientService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Hospital580PrescriptionMedicineScrmService medicineScrmService;
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductScrmService productScrmService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @DistributeLock(key = "#vo.userId", scene = "savePreDemand", waitTime = 5000, errorMsg = "新增问诊信息失败")
|
|
|
+ public Result<String> savePreDemand(SaveOrderScrmReq vo) {
|
|
|
+ // 校验是否存在问诊单
|
|
|
+ if (orderScrmService.isByStoreOrder(vo.getStoreOrderId())){
|
|
|
+ throw new FSException("您已存在未处理的问诊单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存问诊信息
|
|
|
+ Hospital580PrescriptionScrmEntity order = new Hospital580PrescriptionScrmEntity();
|
|
|
+ BeanUtil.copyProperties(vo, order);
|
|
|
+ FsPatient fsPatient = fsPatientService.selectFsPatientByPatientId(vo.getPatientId());
|
|
|
+ order.setUserFamilyIdCard(fsPatient.getIdCard());
|
|
|
+ order.setUserFamilyPhone(PhoneUtil.decryptPhone(fsPatient.getMobile()));
|
|
|
+ order.setUserFamilyName(fsPatient.getPatientName());
|
|
|
+ order.setUserFamilyGender(fsPatient.getSex().byteValue());
|
|
|
+ order.setUserFamilyAge(Period.between(fsPatient.getBirthday().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now()).getYears());
|
|
|
+ order.insert();
|
|
|
+
|
|
|
+ // 保存问诊答案
|
|
|
+ answerScrmService.saveBatch(vo.getBeforeAiDataList().stream()
|
|
|
+ .map(item -> {
|
|
|
+ Hospital580PrescriptionAnswerScrmEntity entity = new Hospital580PrescriptionAnswerScrmEntity();
|
|
|
+ BeanUtil.copyProperties(item, entity);
|
|
|
+ entity.setPreId(order.getPreId());
|
|
|
+ return entity;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+
|
|
|
+ // 获取问诊链接并更新
|
|
|
+ PreDemandDto dto = new PreDemandDto();
|
|
|
+ BeanUtil.copyProperties(order, dto);
|
|
|
+ dto.setBizOrderId(order.getPreId().toString());
|
|
|
+ dto.setMemberId(order.getUserFamilyPhone());
|
|
|
+ dto.setThirdReturnUrl(vo.getStoreOrderId());
|
|
|
+ dto.setBeforeAiDataList(vo.getBeforeAiDataList().stream().map(item -> {
|
|
|
+ BeforeAiData textRecordDto = new BeforeAiData();
|
|
|
+ textRecordDto.setSubjectId(item.getSubjectId());
|
|
|
+ textRecordDto.setAnswer(item.getAnswer());
|
|
|
+ textRecordDto.setAnswerMedicine(item.getAnswerMedicine());
|
|
|
+ return textRecordDto;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+ Result580 result580 = hospital580Service.initPreDemand(dto);
|
|
|
+ order.setJumpUrl(result580.getData());
|
|
|
+ order.updateById();
|
|
|
+
|
|
|
+ return processResult(result580);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResponse<DiseaseQueryRes> diseaseQuery(DiseaseReq req) {
|
|
|
+ Result<String> stringResult = processResult(hospital580Service.disease(BeanUtil.copyProperties(req, DiseaseDto.class)));
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(stringResult.getData());
|
|
|
+ return PageResponse.of(JSONUtil.toList(jsonObject.getJSONArray("list"), DiseaseQueryRes.class),
|
|
|
+ jsonObject.getInt("rowCount"),
|
|
|
+ req.getPageNum(),
|
|
|
+ req.getPageSize());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void prescription(Prescription580Req vo) {
|
|
|
+ // 处方信息
|
|
|
+ Hospital580PrescriptionScrmEntity prescription = orderScrmService.getById(vo.getBizOrderId());
|
|
|
+ BeanUtil.copyProperties(vo, prescription);
|
|
|
+ prescription.setPrescriptionStatus(vo.getStatus());
|
|
|
+ // 更新处方记录
|
|
|
+ prescription.updateById();
|
|
|
+ List<PrescriptionMedicineScrmVo> drugRspList = vo.getDrugRspList();
|
|
|
+ drugRspList.forEach(item -> {
|
|
|
+ Hospital580PrescriptionMedicineScrmEntity entity = new Hospital580PrescriptionMedicineScrmEntity();
|
|
|
+ BeanUtil.copyProperties(item, entity);
|
|
|
+ entity.setPreId(prescription.getPreId());
|
|
|
+ // 插入药品信息
|
|
|
+ entity.insert();
|
|
|
+ });
|
|
|
+
|
|
|
+ ThreadUtil.execute(() -> {
|
|
|
+ // 同步聊天记录
|
|
|
+ TextRecordDto build = TextRecordDto.builder().diagnosisId(prescription.getDiagnosisId()).pageSize(1).pageNum(100).build();
|
|
|
+ Result580 result580 = hospital580Service.textRecord(build);
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(result580.getData());
|
|
|
+ if (jsonObject.getInt("rowCount") > build.getPageSize()) {
|
|
|
+ build.setPageSize(jsonObject.getInt("rowCount"));
|
|
|
+ result580 = hospital580Service.textRecord(build);
|
|
|
+ jsonObject = JSONUtil.parseObj(result580.getData());
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
+ Hospital580PrescriptionChatScrmEntity chatScrmEntity = new Hospital580PrescriptionChatScrmEntity();
|
|
|
+ chatScrmEntity.setContent(data.toString());
|
|
|
+ chatScrmEntity.setPreId(prescription.getPreId());
|
|
|
+ chatScrmEntity.insert();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void refusePrescription(RefusePrescriptionVo vo) {
|
|
|
+ // 修改处方信息
|
|
|
+ Hospital580PrescriptionScrmEntity prescription = orderScrmService.getById(vo.getBizOrderId());
|
|
|
+ prescription.setReason(vo.getReason());
|
|
|
+ prescription.setPrescriptionStatus((byte) 2);
|
|
|
+ prescription.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void reviewPrescription(ReviewPrescriptionVo vo) {
|
|
|
+ if (ObjectUtil.isEmpty(vo) || ObjectUtil.isEmpty(vo.getPid())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 修改处方信息
|
|
|
+ Hospital580PrescriptionScrmEntity prescription = new Hospital580PrescriptionScrmEntity();
|
|
|
+ prescription.update(new LambdaUpdateWrapper<Hospital580PrescriptionScrmEntity>()
|
|
|
+ .eq(Hospital580PrescriptionScrmEntity::getPid, vo.getPid())
|
|
|
+ .set(Hospital580PrescriptionScrmEntity::getAuditStatus, vo.getAuditStatus())
|
|
|
+ .set(Hospital580PrescriptionScrmEntity::getAuditTime, vo.getAuditTime())
|
|
|
+ .set(Hospital580PrescriptionScrmEntity::getAuditApothecaryName, vo.getAuditApothecaryName())
|
|
|
+ .set(Hospital580PrescriptionScrmEntity::getReason, vo.getReason())
|
|
|
+ .set(Hospital580PrescriptionScrmEntity::getDstFilePath, vo.getDstFilePath()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void medicineSync(MedicineSyncVo vo) {
|
|
|
+ Hospital580ProductPushScrmEntity productPushScrm = new Hospital580ProductPushScrmEntity();
|
|
|
+ List<String> medicineIdList = JSONUtil.toList(JSONUtil.parseArray(vo.getMedicineIds()), String.class);
|
|
|
+ List<Long> medicineIds = medicineIdList.stream()
|
|
|
+ .map(Long::valueOf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ productPushScrm.update(new LambdaUpdateWrapper<Hospital580ProductPushScrmEntity>()
|
|
|
+ .in(Hospital580ProductPushScrmEntity::getProductId, medicineIds)
|
|
|
+ .eq(Hospital580ProductPushScrmEntity::getPushStatus, 0)
|
|
|
+ .set(Hospital580ProductPushScrmEntity::getPushStatus, vo.getErrCode().equals("0") ? 1 : 2)
|
|
|
+ .set(Hospital580ProductPushScrmEntity::getErrMsg, vo.getErrMsg())
|
|
|
+ .set(Hospital580ProductPushScrmEntity::getUpdateTime, LocalDateTime.now()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResponse<PrescriptionListRes> prescriptionList(String userId, PageRequest pageRequest) {
|
|
|
+ // 问诊列表
|
|
|
+ IPage<Hospital580PrescriptionScrmEntity> page = orderScrmService.page(
|
|
|
+ new Page<Hospital580PrescriptionScrmEntity>(pageRequest.getPageNum(), pageRequest.getPageSize())
|
|
|
+ , new LambdaQueryWrapper<Hospital580PrescriptionScrmEntity>()
|
|
|
+ //.eq(Hospital580PrescriptionScrmEntity::getUserId, userId)
|
|
|
+ .orderByDesc(Hospital580PrescriptionScrmEntity::getCreatedTime)
|
|
|
+ );
|
|
|
+ List<Hospital580PrescriptionScrmEntity> orderRecords = page.getRecords();
|
|
|
+ // 构建返回结果
|
|
|
+ List<PrescriptionListRes> result = orderRecords.stream()
|
|
|
+ .map(order -> {
|
|
|
+ return PrescriptionListRes.builder()
|
|
|
+ .pid(order.getPid())
|
|
|
+ .preId(order.getPreId())
|
|
|
+ .createdTime(order.getCreatedTime())
|
|
|
+ .createTime(order.getCreatedTime())
|
|
|
+ .tags(order.getTags())
|
|
|
+ .userFamilyName(order.getUserFamilyName())
|
|
|
+ .userFamilyGender(order.getUserFamilyGender())
|
|
|
+ .userFamilyAge(order.getUserFamilyAge())
|
|
|
+ .prescriptionStatus(order.getPrescriptionStatus())
|
|
|
+ .doctorName(order.getDoctorName())
|
|
|
+ .serialNo(order.getSerialNo())
|
|
|
+ .build();
|
|
|
+ })
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return PageResponse.of(result, Math.toIntExact(page.getTotal()), pageRequest.getPageSize(), pageRequest.getPageNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<PrescriptionDetailRes> prescriptionDetail(String userId, Long preId) {
|
|
|
+ Hospital580PrescriptionScrmEntity byId = orderScrmService.getById(preId);
|
|
|
+ PrescriptionDetailRes prescriptionScrmVo = BeanUtil.toBean(byId, PrescriptionDetailRes.class);
|
|
|
+ prescriptionScrmVo.setDrugRspList(medicineScrmService.list(new LambdaQueryWrapper<Hospital580PrescriptionMedicineScrmEntity>()
|
|
|
+ .eq(Hospital580PrescriptionMedicineScrmEntity::getPreId, prescriptionScrmVo.getPreId()))
|
|
|
+ .stream()
|
|
|
+ .filter(Objects::nonNull) // 过滤掉空对象
|
|
|
+ .map(item -> {
|
|
|
+ PrescriptionMedicineScrmVo vo = new PrescriptionMedicineScrmVo();
|
|
|
+ BeanUtil.copyProperties(item, vo);
|
|
|
+ FsStoreProductScrm fsStoreProductScrm = productScrmService.selectFsStoreProductById(Long.valueOf(item.getCommodityCode()));
|
|
|
+ vo.setImage(fsStoreProductScrm.getImage());
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ return Result.success(prescriptionScrmVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result<String> processResult(Result580 result580) {
|
|
|
+ if (0 == result580.getErr()) {
|
|
|
+ return Result.success(result580.getData());
|
|
|
+ }
|
|
|
+ throw new FSException(result580.getErrmsg());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|