|
@@ -3,20 +3,23 @@ package com.fs.his.service.impl;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.enums.ImTypeEnum;
|
|
import com.fs.common.enums.ImTypeEnum;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
|
|
+import com.fs.common.exception.file.OssException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
|
|
+import com.fs.fastgptApi.param.ChatImgParam;
|
|
|
|
|
+import com.fs.fastgptApi.result.ChatDetailTStreamFResult;
|
|
|
|
|
+import com.fs.fastgptApi.service.ChatService;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.*;
|
|
import com.fs.his.domain.*;
|
|
|
import com.fs.his.mapper.FsDoctorMapper;
|
|
import com.fs.his.mapper.FsDoctorMapper;
|
|
|
import com.fs.his.mapper.FsFollowMapper;
|
|
import com.fs.his.mapper.FsFollowMapper;
|
|
|
import com.fs.his.mapper.FsFollowTempMapper;
|
|
import com.fs.his.mapper.FsFollowTempMapper;
|
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
import com.fs.his.mapper.FsStoreOrderMapper;
|
|
|
-import com.fs.his.param.FsDoctorListUParam;
|
|
|
|
|
-import com.fs.his.param.FsDoctorParam;
|
|
|
|
|
-import com.fs.his.param.FsUpdateFollowParam;
|
|
|
|
|
|
|
+import com.fs.his.param.*;
|
|
|
import com.fs.his.service.IFsDoctorService;
|
|
import com.fs.his.service.IFsDoctorService;
|
|
|
import com.fs.his.service.IFsPrescribeService;
|
|
import com.fs.his.service.IFsPrescribeService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
@@ -32,12 +35,16 @@ import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
import com.fs.system.oss.OSSFactory;
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import com.google.zxing.WriterException;
|
|
import com.google.zxing.WriterException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
@@ -78,6 +85,9 @@ public class FsDoctorServiceImpl implements IFsDoctorService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private OpenIMService openIMService;
|
|
private OpenIMService openIMService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ChatService chatService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询医生管理
|
|
* 查询医生管理
|
|
|
*
|
|
*
|
|
@@ -551,4 +561,675 @@ public class FsDoctorServiceImpl implements IFsDoctorService
|
|
|
return fsDoctorMapper.getChooseDoctorListByMap(params);
|
|
return fsDoctorMapper.getChooseDoctorListByMap(params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传处方图片
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @param doctorId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R uploadPrescriptionImg(MultipartFile file, String doctorId) {
|
|
|
|
|
+ if (file == null) {
|
|
|
|
|
+ return R.error("请选择要上传的文件");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return uploadSingleFile(file, doctorId);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*//上传处方图片
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R uploadPrescriptionImg(MultipartFile[] files, String doctorId) {
|
|
|
|
|
+ if (files == null || files.length == 0) {
|
|
|
|
|
+ return R.error("请选择要上传的文件");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
+ int total = files.length;
|
|
|
|
|
+ int successCount = 0;
|
|
|
|
|
+ int failCount = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (MultipartFile file : files) {
|
|
|
|
|
+ Map<String, Object> resultMap = uploadSingleFile(file, doctorId);
|
|
|
|
|
+ resultList.add(resultMap);
|
|
|
|
|
+
|
|
|
|
|
+ if ("success".equals(resultMap.get("status"))) {
|
|
|
|
|
+ successCount++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok()
|
|
|
|
|
+ .put("total", total)
|
|
|
|
|
+ .put("successCount", successCount)
|
|
|
|
|
+ .put("failCount", failCount)
|
|
|
|
|
+ .put("data", resultList);
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ private R uploadSingleFile(MultipartFile file, String doctorId) {
|
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
|
+ resultMap.put("name", fileName);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //validateFile(file, fileName);
|
|
|
|
|
+
|
|
|
|
|
+ CloudStorageService storage = OSSFactory.build();
|
|
|
|
|
+ String suffix = getFileSuffix(fileName);
|
|
|
|
|
+ String url = storage.uploadSuffix(file.getBytes(), suffix);
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionImgLogParam imgLogParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ boolean saveSuccess = savePrescriptionLog(imgLogParam,url, doctorId);
|
|
|
|
|
+
|
|
|
|
|
+ if (saveSuccess) {
|
|
|
|
|
+ resultMap.put("id", imgLogParam.getId());
|
|
|
|
|
+ resultMap.put("url", url);
|
|
|
|
|
+ return R.ok().put("result",resultMap).put("msg", "图片上传成功!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resultMap.put("id", imgLogParam.getId());
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ return R.error().put("result",resultMap).put("msg", "保存记录失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (OssException e) {
|
|
|
|
|
+ log.error("图片格式或内容校验失败:{}", fileName, e);
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ return R.error().put("result",resultMap).put("msg", e.getMessage());
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("读取文件失败:{}", fileName, e);
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ return R.error().put("result",resultMap).put("msg", "文件读取失败!");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("图片上传失败:{}", fileName, e);
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ resultMap.put("msg", "");
|
|
|
|
|
+ return R.error().put("result",resultMap).put("msg", "图片上传失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void validateFile(MultipartFile file, String fileName) throws OssException {
|
|
|
|
|
+ if (file.isEmpty()) {
|
|
|
|
|
+ throw new OssException("上传文件不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (fileName == null || fileName.isEmpty()) {
|
|
|
|
|
+ throw new OssException("文件名不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String suffix = getFileSuffix(fileName).toLowerCase();
|
|
|
|
|
+ if (!isValidImageType(suffix)) {
|
|
|
|
|
+ throw new OssException("只支持上传图片格式(jpg、png、gif、bmp)");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ long fileSize = file.getSize();
|
|
|
|
|
+ if (fileSize > 10 * 1024 * 1024) {
|
|
|
|
|
+ throw new OssException("文件大小不能超过10MB");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getFileSuffix(String fileName) {
|
|
|
|
|
+ int lastDotIndex = fileName.lastIndexOf(".");
|
|
|
|
|
+ if (lastDotIndex > 0 && lastDotIndex < fileName.length() - 1) {
|
|
|
|
|
+ return fileName.substring(lastDotIndex);
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isValidImageType(String suffix) {
|
|
|
|
|
+ return ".jpg".equals(suffix) || ".jpeg".equals(suffix)
|
|
|
|
|
+ || ".png".equals(suffix) || ".gif".equals(suffix)
|
|
|
|
|
+ || ".bmp".equals(suffix) || ".webp".equals(suffix);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean savePrescriptionLog(DoctorPrescriptionImgLogParam imgLogParam,String url, String doctorId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ imgLogParam.setDoctorId(Long.parseLong(doctorId));
|
|
|
|
|
+ imgLogParam.setUrl(url);
|
|
|
|
|
+ imgLogParam.setStatus(0);
|
|
|
|
|
+
|
|
|
|
|
+ int insertResult = fsDoctorMapper.insertFsDoctorPrescriptionImgLog(imgLogParam);
|
|
|
|
|
+
|
|
|
|
|
+ if (insertResult != 1) {
|
|
|
|
|
+ log.error("插入处方图片日志失败,doctorId: {}, url: {}", doctorId, url);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionParam prescriptionParam = new DoctorPrescriptionParam();
|
|
|
|
|
+ prescriptionParam.setPrescriptionImg(url);
|
|
|
|
|
+ prescriptionParam.setDoctorId(Long.parseLong(doctorId));
|
|
|
|
|
+ prescriptionParam.setIsParse(0);
|
|
|
|
|
+ prescriptionParam.setStatus(0);
|
|
|
|
|
+ prescriptionParam.setLogId(imgLogParam.getId());
|
|
|
|
|
+
|
|
|
|
|
+ int prescriptionResult = fsDoctorMapper.insertFsDoctorPrescription(prescriptionParam);
|
|
|
|
|
+
|
|
|
|
|
+ if (prescriptionResult != 1) {
|
|
|
|
|
+ log.error("插入处方记录失败,logId: {}, url: {}", imgLogParam.getId(), url);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ log.error("医生ID格式错误:{}", doctorId, e);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("保存处方记录异常,doctorId: {}, url: {}", doctorId, url, e);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析处方图片
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R cleanPrescriptionImg(String doctorId) {
|
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
+ DoctorPrescriptionImgLogParam imgLogParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ imgLogParam.setDoctorId(Long.parseLong(doctorId));
|
|
|
|
|
+ imgLogParam.setStatus(1);
|
|
|
|
|
+ List<DoctorPrescriptionImgLogParam> paramList = fsDoctorMapper.selectFsDoctorPrescribeImgByDoctorId(imgLogParam);
|
|
|
|
|
+
|
|
|
|
|
+ if (paramList == null || paramList.isEmpty()) {
|
|
|
|
|
+ return R.error("请先上传能解析的图片")
|
|
|
|
|
+ .put("data", resultList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int total = paramList.size();
|
|
|
|
|
+ int successCount = 0;
|
|
|
|
|
+ int failCount = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (DoctorPrescriptionImgLogParam logParam : paramList) {
|
|
|
|
|
+ Map<String, Object> resultMap = processSingleImage(logParam, doctorId);
|
|
|
|
|
+ resultList.add(resultMap);
|
|
|
|
|
+
|
|
|
|
|
+ if ((Boolean) resultMap.get("status")) {
|
|
|
|
|
+ successCount++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok()
|
|
|
|
|
+ .put("total", total)
|
|
|
|
|
+ .put("successCount", successCount)
|
|
|
|
|
+ .put("failCount", failCount)
|
|
|
|
|
+ .put("data", resultList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> processSingleImage(DoctorPrescriptionImgLogParam logParam, String doctorId) {
|
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
+ String url = logParam.getUrl();
|
|
|
|
|
+ resultMap.put("url", url);
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionImgLogParam updateParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ updateParam.setId(logParam.getId());
|
|
|
|
|
+ updateParam.setStatus(3);
|
|
|
|
|
+ updateParam.setRemark("图像解析中...");
|
|
|
|
|
+ fsDoctorMapper.updateFsDoctorPrescriptionImgLog(updateParam);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DoctorPrescriptionParam processResult = imageProcess(url, doctorId);
|
|
|
|
|
+ processResult.setLogId(logParam.getId());
|
|
|
|
|
+
|
|
|
|
|
+ if (processResult.getIsParse() != 1 || processResult.getPrescriptionCode() == null) {
|
|
|
|
|
+ updateParam.setStatus(2);
|
|
|
|
|
+ updateParam.setRemark("图像解析失败,请重新上传!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "图像解析失败,请重新上传!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer existCount = fsDoctorMapper.selectFsDoctorPrescriptionByCode(processResult.getPrescriptionCode());
|
|
|
|
|
+ if (existCount >= 1) {
|
|
|
|
|
+ updateParam.setStatus(2);
|
|
|
|
|
+ updateParam.setRemark("处方单号已存在,请重新上传!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "处方单号已存在,请重新上传!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ boolean saveSuccess = savePrescription(processResult, logParam.getId());
|
|
|
|
|
+ if (saveSuccess) {
|
|
|
|
|
+ updateParam.setStatus(1);
|
|
|
|
|
+ updateParam.setRemark("解析成功");
|
|
|
|
|
+ resultMap.put("status", true);
|
|
|
|
|
+ resultMap.put("result", processResult);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ updateParam.setStatus(2);
|
|
|
|
|
+ updateParam.setRemark("保存失败,请重新解析!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "保存失败,请重新解析!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ updateParam.setStatus(2);
|
|
|
|
|
+ updateParam.setRemark("处理异常:" + e.getMessage());
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "处理异常,请稍后重试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fsDoctorMapper.updateFsDoctorPrescriptionImgLog(updateParam);
|
|
|
|
|
+ return resultMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean savePrescription(DoctorPrescriptionParam processResult, Long logId) {
|
|
|
|
|
+ DoctorPrescriptionParam existingParam = fsDoctorMapper.selectPrescriptionImgInfoByLogId(logId);
|
|
|
|
|
+
|
|
|
|
|
+ if (existingParam != null) {
|
|
|
|
|
+ processResult.setId(existingParam.getId());
|
|
|
|
|
+ processResult.setStatus(0);
|
|
|
|
|
+ return fsDoctorMapper.updateFsDoctorPrescription(processResult) > 0;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ processResult.setStatus(0);
|
|
|
|
|
+ return fsDoctorMapper.insertFsDoctorPrescription(processResult) > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R selectPrescriptionImgList(String doctorId, DoctorPrescriptionImgLogParam param) {
|
|
|
|
|
+ PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
|
|
|
|
+ List<DoctorPrescriptionImgLogParam> param1 = fsDoctorMapper.selectAllPrescriptionImgList(doctorId,param);
|
|
|
|
|
+ return R.ok().put("result",new PageInfo<>(param1));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R selectPrescriptionImgInfo(Long imgLogId) {
|
|
|
|
|
+ DoctorPrescriptionParam param = fsDoctorMapper.selectPrescriptionImgInfoByLogId(imgLogId);
|
|
|
|
|
+ return R.ok().put("result",param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R cleanPrescriptionImgSecond(Long prescriptionId) {
|
|
|
|
|
+ if (prescriptionId == null) {
|
|
|
|
|
+ return R.error("处方ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionParam param = fsDoctorMapper.selectPrescriptionImgInfo(prescriptionId);
|
|
|
|
|
+ if (param == null) {
|
|
|
|
|
+ return R.error("未找到对应的处方记录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String url = param.getPrescriptionImg();
|
|
|
|
|
+ if (url == null || url.isEmpty()) {
|
|
|
|
|
+ return R.error("处方图片不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> resultMap = reprocessPrescriptionImage(param, url);
|
|
|
|
|
+ return R.ok().put("data", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> reprocessPrescriptionImage(DoctorPrescriptionParam prescriptionParam, String url) {
|
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
+ resultMap.put("url", url);
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionImgLogParam logUpdateParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ logUpdateParam.setId(prescriptionParam.getLogId());
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DoctorPrescriptionParam processResult = imageProcess(url, String.valueOf(prescriptionParam.getDoctorId()));
|
|
|
|
|
+
|
|
|
|
|
+ if (processResult.getIsParse() != 1 || processResult.getPrescriptionCode() == null) {
|
|
|
|
|
+ updateLogStatus(logUpdateParam, 2, "图像解析失败,请重新上传!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "图像解析失败,请重新上传!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ handleParsedPrescription(processResult, logUpdateParam, resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("重新解析处方图片失败,prescriptionId: {}", prescriptionParam.getId(), e);
|
|
|
|
|
+ updateLogStatus(logUpdateParam, 2, "解析异常:" + e.getMessage());
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "解析异常,请稍后重试!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return resultMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void handleParsedPrescription(DoctorPrescriptionParam processResult,
|
|
|
|
|
+ DoctorPrescriptionImgLogParam logUpdateParam,
|
|
|
|
|
+ Map<String, Object> resultMap) {
|
|
|
|
|
+ Integer existCount = fsDoctorMapper.selectFsDoctorPrescriptionByCode(processResult.getPrescriptionCode());
|
|
|
|
|
+ DoctorPrescriptionParam param = fsDoctorMapper.selectPrescriptionImgInfoByLogId(logUpdateParam.getId());
|
|
|
|
|
+ boolean status = param != null && !processResult.getPrescriptionCode().equals(param.getPrescriptionCode()) && param.getIsDel() == 0;
|
|
|
|
|
+ if (existCount >= 1 && status) {
|
|
|
|
|
+ updateLogStatus(logUpdateParam, 2, "处方单号已存在,请重新上传!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "处方单号已存在,请重新上传!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ processResult.setLogId(logUpdateParam.getId());
|
|
|
|
|
+ resultMap.put("status", true);
|
|
|
|
|
+ resultMap.put("result", processResult);
|
|
|
|
|
+
|
|
|
|
|
+ /*boolean saveSuccess = saveNewPrescription(processResult);
|
|
|
|
|
+ if (saveSuccess) {
|
|
|
|
|
+ updateLogStatus(logUpdateParam, 1, "解析成功");
|
|
|
|
|
+ resultMap.put("status", true);
|
|
|
|
|
+ resultMap.put("result", processResult);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ updateLogStatus(logUpdateParam, 2, "保存失败,请重新解析!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "保存失败,请重新解析!");
|
|
|
|
|
+ }*/
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean saveNewPrescription(DoctorPrescriptionParam processResult) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ processResult.setStatus(0);
|
|
|
|
|
+ int updated = fsDoctorMapper.updateFsDoctorPrescriptionByLogId(processResult);
|
|
|
|
|
+ return updated > 0;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("保存新处方记录失败,处方号: {}", processResult.getPrescriptionCode(), e);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R uploadPrescriptionImg(MultipartFile file, Long logId) {
|
|
|
|
|
+ if (file == null || file.isEmpty()) {
|
|
|
|
|
+ return R.error("上传文件不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (logId == null) {
|
|
|
|
|
+ return R.error("日志ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> resultMap = uploadAndUpdateSingleFile(file, logId);
|
|
|
|
|
+
|
|
|
|
|
+ if ("success".equals(resultMap.get("status"))) {
|
|
|
|
|
+ return R.ok().put("data", resultMap);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return R.error((String) resultMap.get("message")).put("data", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> uploadAndUpdateSingleFile(MultipartFile file, Long logId) {
|
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
|
+ resultMap.put("name", fileName);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ validateFile(file, fileName);
|
|
|
|
|
+
|
|
|
|
|
+ CloudStorageService storage = OSSFactory.build();
|
|
|
|
|
+ String suffix = getFileSuffix(fileName);
|
|
|
|
|
+ String url = storage.uploadSuffix(file.getBytes(), suffix);
|
|
|
|
|
+
|
|
|
|
|
+ boolean updateSuccess = updatePrescriptionWithNewImage(url, logId);
|
|
|
|
|
+
|
|
|
|
|
+ if (updateSuccess) {
|
|
|
|
|
+ resultMap.put("id", logId);
|
|
|
|
|
+ resultMap.put("status", "success");
|
|
|
|
|
+ resultMap.put("url", url);
|
|
|
|
|
+ resultMap.put("message", "图片上传成功!");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resultMap.put("id", 0);
|
|
|
|
|
+ resultMap.put("status", "error");
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ resultMap.put("message", "更新记录失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (OssException e) {
|
|
|
|
|
+ log.error("图片格式或内容校验失败:{}", fileName, e);
|
|
|
|
|
+ resultMap.put("id", 0);
|
|
|
|
|
+ resultMap.put("status", "error");
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ resultMap.put("message", e.getMessage());
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ log.error("读取文件失败:{}", fileName, e);
|
|
|
|
|
+ resultMap.put("id", 0);
|
|
|
|
|
+ resultMap.put("status", "error");
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ resultMap.put("message", "文件读取失败!");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("图片上传失败:{}", fileName, e);
|
|
|
|
|
+ resultMap.put("id", 0);
|
|
|
|
|
+ resultMap.put("status", "error");
|
|
|
|
|
+ resultMap.put("url", "");
|
|
|
|
|
+ resultMap.put("message", "图片上传失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return resultMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean updatePrescriptionWithNewImage(String url, Long logId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ DoctorPrescriptionImgLogParam imgLogParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ imgLogParam.setUrl(url);
|
|
|
|
|
+ imgLogParam.setId(logId);
|
|
|
|
|
+
|
|
|
|
|
+ int logUpdateResult = fsDoctorMapper.updateFsDoctorPrescriptionImgLog(imgLogParam);
|
|
|
|
|
+ if (logUpdateResult != 1) {
|
|
|
|
|
+ log.error("更新处方图片日志失败,logId: {}, url: {}", logId, url);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionParam prescriptionParam = new DoctorPrescriptionParam();
|
|
|
|
|
+ prescriptionParam.setPrescriptionImg(url);
|
|
|
|
|
+ prescriptionParam.setLogId(logId);
|
|
|
|
|
+ prescriptionParam.setIsParse(0);
|
|
|
|
|
+
|
|
|
|
|
+ int prescriptionUpdateResult = fsDoctorMapper.updateFsDoctorPrescriptionByLogId(prescriptionParam);
|
|
|
|
|
+ if (prescriptionUpdateResult < 1) {
|
|
|
|
|
+ log.error("更新处方记录失败,logId: {}, url: {}", logId, url);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("更新处方记录异常,logId: {}, url: {}", logId, url, e);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateLogStatus(DoctorPrescriptionImgLogParam logParam, Integer status, String remark) {
|
|
|
|
|
+ logParam.setStatus(status);
|
|
|
|
|
+ logParam.setRemark(remark);
|
|
|
|
|
+ fsDoctorMapper.updateFsDoctorPrescriptionImgLog(logParam);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 自定义图片处理方法
|
|
|
|
|
+ private DoctorPrescriptionParam imageProcess(String url,String doctorId) {
|
|
|
|
|
+ ChatImgParam param=new ChatImgParam();
|
|
|
|
|
+ param.setChatId(doctorId);
|
|
|
|
|
+ param.setStream(false);
|
|
|
|
|
+ param.setDetail(true);
|
|
|
|
|
+ List<ChatImgParam.Message> messageList=new ArrayList<ChatImgParam.Message>();
|
|
|
|
|
+ ChatImgParam.Message message = new ChatImgParam.Message();
|
|
|
|
|
+ message.setRole("user");
|
|
|
|
|
+ List<ChatImgParam.Message.content> contents = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ ChatImgParam.Message.content content = new ChatImgParam.Message.content();
|
|
|
|
|
+ content.setType("text");
|
|
|
|
|
+ content.setText("请根据提示词识别图片内容");
|
|
|
|
|
+ contents.add(content);
|
|
|
|
|
+
|
|
|
|
|
+ //设置上传的图片
|
|
|
|
|
+ ChatImgParam.Message.content contentImg = new ChatImgParam.Message.content();
|
|
|
|
|
+ contentImg.setType("image_url");
|
|
|
|
|
+ ChatImgParam.Message.ImageUrl imageUrl = new ChatImgParam.Message.ImageUrl();
|
|
|
|
|
+ imageUrl.setUrl(url);
|
|
|
|
|
+ contentImg.setImage_url(imageUrl);
|
|
|
|
|
+ contents.add(contentImg);
|
|
|
|
|
+
|
|
|
|
|
+ message.setContent(contents);
|
|
|
|
|
+ messageList.add(message);
|
|
|
|
|
+ param.setMessages(messageList);
|
|
|
|
|
+
|
|
|
|
|
+ R r = chatService.initiatingTakeChatNew(param, "http://129.28.170.206:3000/api", "fastgpt-t3Z1s8Lb6pKMILsSNUHDCOZ4PWgcRlwcWJT7DvrxtvqJfyZbEyWLqS8Up");
|
|
|
|
|
+ if(!r.get("code").equals(200)){
|
|
|
|
|
+ DoctorPrescriptionParam doctorPrescriptionParam = new DoctorPrescriptionParam();
|
|
|
|
|
+ doctorPrescriptionParam.setIsParse(0);
|
|
|
|
|
+ return doctorPrescriptionParam;
|
|
|
|
|
+ }
|
|
|
|
|
+ ChatDetailTStreamFResult result=(ChatDetailTStreamFResult)r.get("data");
|
|
|
|
|
+
|
|
|
|
|
+ String contentKh = result.getChoices().get(0).getMessage().getContent();
|
|
|
|
|
+ System.out.println("模型解析图片结果:"+contentKh);
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ DoctorPrescriptionParam fromJson = gson.fromJson(contentKh, DoctorPrescriptionParam.class);
|
|
|
|
|
+ fromJson.setPrescriptionImg(url);
|
|
|
|
|
+ fromJson.setDoctorId(Long.parseLong(doctorId));
|
|
|
|
|
+ return fromJson;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public R deletePrescription(Long imgLogId, Long doctorId) {
|
|
|
|
|
+ DoctorPrescriptionParam param = fsDoctorMapper.selectPrescriptionImgInfoByLogId(imgLogId);
|
|
|
|
|
+ if(param == null || param.getId()==null){
|
|
|
|
|
+ return R.error("未找到对应的处方记录");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long prescriptionId = param.getId();
|
|
|
|
|
+
|
|
|
|
|
+ if (doctorId == null) {
|
|
|
|
|
+ return R.error("医生ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DoctorPrescriptionParam prescription = fsDoctorMapper.selectPrescriptionImgInfo(prescriptionId);
|
|
|
|
|
+ if (prescription == null) {
|
|
|
|
|
+ return R.error("未找到对应的处方记录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!prescription.getDoctorId().equals(doctorId)) {
|
|
|
|
|
+ return R.error("无权删除该处方记录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (prescription.getIsDel() != null && prescription.getIsDel() == 1) {
|
|
|
|
|
+ return R.error("该处方已被删除");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer status = prescription.getStatus();
|
|
|
|
|
+ if (status != null && (status == 3 || status == 4 || status == 6)) {
|
|
|
|
|
+ String statusMsg = getStatusDescription(status);
|
|
|
|
|
+ return R.error("当前处方状态为" + statusMsg + ",不允许删除");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DoctorPrescriptionParam updateParam = new DoctorPrescriptionParam();
|
|
|
|
|
+ updateParam.setId(prescriptionId);
|
|
|
|
|
+ updateParam.setIsDel(1);
|
|
|
|
|
+ int prescriptionResult = fsDoctorMapper.updateFsDoctorPrescription(updateParam);
|
|
|
|
|
+
|
|
|
|
|
+ if (prescriptionResult <= 0) {
|
|
|
|
|
+ log.error("软删除处方记录失败,prescriptionId: {}", prescriptionId);
|
|
|
|
|
+ return R.error("删除处方记录失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (prescription.getLogId() != null) {
|
|
|
|
|
+ DoctorPrescriptionImgLogParam logUpdateParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ logUpdateParam.setId(prescription.getLogId());
|
|
|
|
|
+ logUpdateParam.setIsDel(1);
|
|
|
|
|
+ int logResult = fsDoctorMapper.updateFsDoctorPrescriptionImgLog(logUpdateParam);
|
|
|
|
|
+
|
|
|
|
|
+ if (logResult <= 0) {
|
|
|
|
|
+ log.warn("更新处方图片日志状态失败,logId: {}", prescription.getLogId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("成功删除处方记录,prescriptionId: {}, doctorId: {}", prescriptionId, doctorId);
|
|
|
|
|
+ return R.ok("删除成功");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("删除处方记录异常,prescriptionId: {}", prescriptionId, e);
|
|
|
|
|
+ throw new RuntimeException("删除处方记录失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R cleanPrescriptionImgOne(Long imgLogId) {
|
|
|
|
|
+ DoctorPrescriptionParam param = fsDoctorMapper.selectPrescriptionImgInfoByLogId(imgLogId);
|
|
|
|
|
+ if(param == null || param.getId()==null){
|
|
|
|
|
+ return R.error("未找到对应的处方记录");
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.cleanPrescriptionImgSecond(param.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R savePrescriptionInfo(DoctorPrescriptionParam param) {
|
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
+ Integer existCount = fsDoctorMapper.selectFsDoctorPrescriptionByCode(param.getPrescriptionCode());
|
|
|
|
|
+ DoctorPrescriptionParam paramDb = fsDoctorMapper.selectPrescriptionImgInfoByLogId(param.getId());
|
|
|
|
|
+ boolean status1 = paramDb != null && !param.getPrescriptionCode().equals(paramDb.getPrescriptionCode()) && paramDb.getIsDel() == 0;
|
|
|
|
|
+ if (existCount >= 1 && status1) {
|
|
|
|
|
+ DoctorPrescriptionImgLogParam imgLogParam = new DoctorPrescriptionImgLogParam();
|
|
|
|
|
+ imgLogParam.setId(param.getLogId());
|
|
|
|
|
+ updateLogStatus(imgLogParam, 2, "处方单号已存在,请重新上传!");
|
|
|
|
|
+ resultMap.put("status", false);
|
|
|
|
|
+ resultMap.put("result", "处方单号已存在,请重新上传!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer status = param.getStatus();
|
|
|
|
|
+ if(status == 0){
|
|
|
|
|
+ int i = fsDoctorMapper.updateFsDoctorPrescriptionByLogId(param);
|
|
|
|
|
+ if(i <= 0){
|
|
|
|
|
+ resultMap.put("msg", "暂存处方信息失败");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ resultMap.put("msg", "暂存处方信息成功");
|
|
|
|
|
+ return R.ok().put("result", resultMap);
|
|
|
|
|
+ }else if(status == 1){
|
|
|
|
|
+ if(param.getPrescriptionCode() == null){
|
|
|
|
|
+ resultMap.put("msg", "处方单号未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getAge() == null){
|
|
|
|
|
+ resultMap.put("msg", "年龄未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getSex() == null){
|
|
|
|
|
+ resultMap.put("msg", "性别未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getChiefComplaint() == null){
|
|
|
|
|
+ resultMap.put("msg", "主诉未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getHistoryOfPresentIllness() == null){
|
|
|
|
|
+ resultMap.put("msg", "现病史未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getSuggest() == null){
|
|
|
|
|
+ resultMap.put("msg", "医生建议未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getPrescriptionInfo() == null){
|
|
|
|
|
+ resultMap.put("msg", "处方信息未填,请重新上传!");
|
|
|
|
|
+ return R.error().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ fsDoctorMapper.updateFsDoctorPrescriptionByLogId(param);
|
|
|
|
|
+ resultMap.put("msg", "保存处方信息成功");
|
|
|
|
|
+ return R.ok().put("result", resultMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R commitPrescriptionInfo(DoctorPrescriptionParam param) {
|
|
|
|
|
+ int i = fsDoctorMapper.updateFsDoctorPrescriptionByLogId(param);
|
|
|
|
|
+ boolean status = i > 0;
|
|
|
|
|
+ return R.ok().put("success", status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<DoctorPrescriptionImgLogParam> selectPrescriptionLogList(DoctorPrescriptionImgLogParam param) {
|
|
|
|
|
+ return fsDoctorMapper.selectPrescriptionLogList(param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int updateFsDoctorPrescription(DoctorPrescriptionParam param) {
|
|
|
|
|
+ return fsDoctorMapper.updateFsDoctorPrescriptionByLogId(param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getStatusDescription(Integer status) {
|
|
|
|
|
+ switch (status) {
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ return "待审核";
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ return "审核通过";
|
|
|
|
|
+ case 6:
|
|
|
|
|
+ return "已完成";
|
|
|
|
|
+ default:
|
|
|
|
|
+ return "状态" + status;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|