优化了病历清单的文件树和pdf浏览加载

master
zengwh 2 years ago
parent d9cae5c139
commit 9f69cb040a

@ -0,0 +1,30 @@
package com.emr.controller;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* @author
* @description: XXX
* @createTime 2023/6/21 16:00
*/
public class SessionContant {
public static String setPdfUrl(String masterId, String imgStr, List<String> urlList, HttpServletRequest request) {
String key = masterId + "_" + imgStr;
request.getSession().setAttribute(key,urlList);
return key;
}
public static List<String> getPdfUrl(String key, HttpServletRequest request) {
Object attribute = request.getSession().getAttribute(key);
if(null != attribute){
List<String> list = (List<String>) attribute;
//删除缓存
request.getSession().removeAttribute(key);
return list;
}
return null;
}
}

@ -13,6 +13,7 @@ import com.emr.util.*;
import com.itextpdf.text.pdf.PdfReader;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
@ -22,6 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@ -338,65 +340,88 @@ public class inHospitalController {
*/
@ResponseBody
@RequestMapping(value = "/getPdfToPdf")
public String getPdfToPdf(HttpServletResponse response, HttpServletRequest request, String imgStr, String masterId, String flag) throws Exception {
//组织分类id集合
if(StringUtils.isNotBlank(imgStr)){
String[] assortIds = StringUtils.split(imgStr, ",");
List<String> srcFileList = archiveDetailService.getPdfUrlByMasterOrId(assortIds,masterId,flag,null);
if(!CollectionUtils.isEmpty(srcFileList)){
//设置进缓存
String key = SessionContant.setPdfUrl(masterId, imgStr, srcFileList, request);
return key;
}
}
return null;
}
/*
@ResponseBody
@RequestMapping(value = "/getPdfToPdf")
public String getPdfToPdf(HttpServletResponse response, HttpServletRequest request, String imgStr, String masterId, String flag) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String result = "";
// 项目在容器中实际发布运行的根路径
String realPath = request.getSession().getServletContext().getRealPath("/");
//realPath = realPath.split("target")[0]
realPath = pictureUrl + "\\static\\img\\";
//pdf名称
String pdfFileName = String.valueOf(System.currentTimeMillis());
//病案号文件夹
if (masterId == "" && masterId == null) {
result = "";
return result;
}
//判断文件夹是否存在
File fileDic = new File(realPath + masterId + "\\");
if (!fileDic.exists() && !fileDic.isDirectory()) {
fileDic.mkdirs();
}
List<Zd_Assort> zds = zd_assortService.selectByColm(new Zd_Assort()); //from db
//from args
//病案号/类别/id文件夹(图片路径下的子文件夹名称)
//生成pdf(图片路径pdf生成路径图片路径文件夹列表)
List imgList = new ArrayList();
if (imgStr != "" && imgStr != null) {
String[] imgArr = imgStr.split(",");
if (imgArr.length > 0) {
for (int i = 0; i < imgArr.length; i++) {
imgList.add(imgArr[i]);
try {
String result = "";
// 项目在容器中实际发布运行的根路径
String realPath = request.getSession().getServletContext().getRealPath("/");
//realPath = realPath.split("target")[0]
realPath = pictureUrl + "\\static\\img\\";
//pdf名称
String pdfFileName = String.valueOf(System.currentTimeMillis());
//病案号文件夹
if (masterId == "" && masterId == null) {
result = "";
return result;
}
//判断文件夹是否存在
File fileDic = new File(realPath + masterId + "\\");
if (!fileDic.exists() && !fileDic.isDirectory()) {
fileDic.mkdirs();
}
List<Zd_Assort> zds = zd_assortService.selectByColm(new Zd_Assort()); //from db
//from args
//病案号/类别/id文件夹(图片路径下的子文件夹名称)
//生成pdf(图片路径pdf生成路径图片路径文件夹列表)
List imgList = new ArrayList();
if (imgStr != "" && imgStr != null) {
String[] imgArr = imgStr.split(",");
if (imgArr.length > 0) {
for (int i = 0; i < imgArr.length; i++) {
imgList.add(imgArr[i]);
}
}
}
}
for (int i = zds.size() - 1; i >= 0; i--) {
String a = zds.get(i).getAssortId();
if (imgList.indexOf(a) == -1) {
zds.remove(i);
for (int i = zds.size() - 1; i >= 0; i--) {
String a = zds.get(i).getAssortId();
if (imgList.indexOf(a) == -1) {
zds.remove(i);
}
}
}
ArrayList<String> fileList = new ArrayList<>();
for (int i = 0; i < zds.size(); i++) {
String asordID = zds.get(i).getAssortId();
String pdfA = GeneratePDFFileByAssortID(masterId, asordID, realPath, flag);
if (pdfA == "" || pdfA.length() == 0) {
continue;
ArrayList<String> fileList = new ArrayList<>();
for (int i = 0; i < zds.size(); i++) {
String asordID = zds.get(i).getAssortId();
String pdfA = GeneratePDFFileByAssortID(masterId, asordID, realPath, flag);
if (pdfA == "" || pdfA.length() == 0) {
continue;
}
fileList.add(pdfA);
}
if (fileList.size() == 0) {
return "";
}
fileList.add(pdfA);
}
if (fileList.size() == 0) {
return "";
}
String pdfPath = autoPdfUrl.trim() + "/" + String.valueOf(System.currentTimeMillis()) + ".pdf";
PDFHelper.Append(fileList, pdfPath);
//PrintToPdfUtil.mergePdfFiles(fileList, pdfPath);
return pdfPath;
String pdfPath = autoPdfUrl.trim() + "/" + String.valueOf(System.currentTimeMillis()) + ".pdf";
//PDFHelper.Append(fileList, pdfPath);
//PrintToPdfUtil.mergePdfFiles(fileList, pdfPath);
return "1233";
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
*/
/**
* idPDFpdf
@ -1283,6 +1308,35 @@ public class inHospitalController {
// }
// }
/**
* @Description: pdfStreamHandelerpdf
* @param: [request, response]
* @return: void
* @author
* @createTime 2023/6/21 15:46
*/
@RequestMapping(value = "/pdfStreamHandeler")
public void pdfStreamHandeler(HttpServletRequest request, HttpServletResponse response)throws Exception {
String filePath = request.getParameter("url");
String[] list=filePath.split("titleName=");
String key =list[0].substring(0,list[0].length()-1);
//titleName为前端页面title显示的患者姓名这里要去掉
List<String> filePaths = SessionContant.getPdfUrl(key, request);
if (null != filePaths && !filePaths.isEmpty()) {
try {
//合成PDF
Jpg2PdfUtil.mulFile2One(response, filePaths, null);
//清除session里的filePaths值
request.removeAttribute(key);
} catch (Exception e) {
ExceptionPrintUtil.printException(e);
e.printStackTrace();
}
}
}
/*
@RequestMapping(value = "/pdfStreamHandeler")
public void pdfStreamHandeler(HttpServletRequest request, HttpServletResponse response) {
String filePath = request.getParameter("url");
@ -1306,6 +1360,7 @@ public class inHospitalController {
} catch (Exception e) {
}
}
*/
@RequestMapping("getImg2")

@ -170,4 +170,8 @@ public interface Archive_DetailMapper {
* @return
*/
List<Archive_Detail> selectPdfPathMayError(Archive_Detail_Vo record);
Integer selectChildByCloCount(@Param("mIds") String mIds);
List<String> getPdfUrlByMasterOrId(@Param("assortIds") String[] assortIds, @Param("masterId")String masterId, @Param("flag")String flag, @Param("fileIds")String fileIds);
}

@ -1,5 +1,6 @@
package com.emr.dao;
import com.emr.dto.Archive_MasterDto;
import com.emr.entity.Archive_Master;
import com.emr.entity.Archive_Master_Following;
import com.emr.entity.Archive_Master_Vo;
@ -254,4 +255,6 @@ public interface Archive_MasterMapper {
* @return
*/
Integer selectTime1(Archive_Master_Vo archiveMasterVo);
List<Archive_MasterDto> selectChildMasterId(String time);
}

@ -0,0 +1,17 @@
package com.emr.dto;
import lombok.Data;
/**
* @author
* @description: XXX
* @createTime 2023/6/21 14:11
*/
@Data
public class Archive_MasterDto {
private String id;
private String inpNo;
private String admissionDateTime;
}

@ -133,6 +133,8 @@ public interface Archive_DetailService {
List<Archive_Detail> selectPdfPathMayError(Archive_Detail_Vo record);
OffsetLimitPage selectPdfPathMayError(Archive_Detail_Vo record, Integer offset, Integer limit);
List<String> getPdfUrlByMasterOrId(String[] assortIds, String masterId, String flag, String fileIds);
}

@ -8,6 +8,7 @@ package com.emr.service.ipml;
import com.emr.dao.Archive_DetailMapper;
import com.emr.dao.Archive_MasterMapper;
import com.emr.dto.Archive_MasterDto;
import com.emr.entity.*;
import com.emr.service.Archive_DetailService;
import com.emr.util.Jpg2PdfUtil;
@ -46,7 +47,31 @@ public class Archive_DetailServiceImpl implements Archive_DetailService {
@Override
public Integer selectChildByClo(Archive_Detail_Vo record) {
return archiveDetailMapper.selectChildByClo(record);
//查询该主键的病案号和住院时间
Archive_Master archiveMaster = archiveMasterMapper.selectById(record.getPatientId());
//查询该住院时间的数据集合
List<Archive_MasterDto> list = archiveMasterMapper.selectChildMasterId(archiveMaster.getAdmissionDateTime());
//定义是该患者的婴儿的masterId集合
StringBuilder mIdStr = new StringBuilder();
if(!CollectionUtils.isEmpty(list)){
for (Archive_MasterDto dto : list){
if(!dto.getId().equals(archiveMaster.getId()) && (dto.getInpNo().contains(archiveMaster.getInpNo() + "B") || dto.getInpNo().contains(archiveMaster.getInpNo() + "_B"))){
if(StringUtils.isNotBlank(mIdStr)){
mIdStr.append(",");
}
mIdStr.append("'").append(dto.getId()).append("'");
}
}
}
if(StringUtils.isNotBlank(mIdStr)) {
try {
Integer count = archiveDetailMapper.selectChildByCloCount(mIdStr.toString());
return count;
} catch (Exception e) {
e.printStackTrace();
}
}
return 0;
}
@Override
@ -266,6 +291,11 @@ public class Archive_DetailServiceImpl implements Archive_DetailService {
return null;
}
@Override
public List<String> getPdfUrlByMasterOrId(String[] assortIds, String masterId, String flag, String fileIds) {
return archiveDetailMapper.getPdfUrlByMasterOrId(assortIds,masterId,flag,fileIds);
}
}

@ -36,7 +36,7 @@ public class Jpg2PdfUtil {
/**
* itextpdf
*/
private PdfReader check(String file) {
private static PdfReader check(String file) {
if(StringUtils.isNotBlank(file)) {
PdfReader pdfReader = null;
try {
@ -72,7 +72,7 @@ public class Jpg2PdfUtil {
}
}
public void mulFile2One(HttpServletResponse response, List<String> files, String waterMarkName) {
public static void mulFile2One(HttpServletResponse response, List<String> files, String waterMarkName) {
List<PdfReader> list = new ArrayList<>();
//遍历删除,除去损坏,文件不存在,抛异常就是空白页
Iterator<String> iterator = files.iterator();
@ -94,11 +94,6 @@ public class Jpg2PdfUtil {
document.open();
for (PdfReader reader : list) {
bos.flush();
//判断是否加水印
if (StringUtils.isNotBlank(waterMarkName)) {
setWatermark(bos, reader, waterMarkName, null);
reader = new PdfReader(bos.toByteArray());
}
int n = reader.getNumberOfPages();
for (int j = 1; j <= n; j++) {
document.newPage();

@ -139,9 +139,15 @@
</select>
<select id="selectByClo" resultMap="BaseResultMap2" parameterType="com.emr.entity.Archive_Detail_Vo">
SELECT z.assort_id,z.assort_name,z.assort_sort,z.print_flag,s.pageNum
from(select AssortID,count(*) pageNum from
archive_detail
select *,COUNT(1) pageNum from (
SELECT
z.assort_id,
z.assort_name,
z.assort_sort,
z.print_flag
FROM
zd_assort z
INNER JOIN archive_detail s ON s.AssortID= z.assort_id
where 1=1
<if test="patientId != null and patientId != ''">
and MasterID=#{patientId,jdbcType=VARCHAR}
@ -152,11 +158,9 @@
<if test="flag != null">
and flag = #{flag,jdbcType=NVARCHAR}
</if>
GROUP BY AssortID) s
RIGHT JOIN zd_assort z
on s.AssortID=z.assort_id
where s.pageNum>0
ORDER BY z.assort_sort
) s
group by assort_id,assort_name,assort_sort,print_flag
ORDER BY s.assort_sort
</select>
<select id="detailByClo" resultMap="BaseResultMap2" parameterType="com.emr.entity.Archive_Detail_Vo">
select
@ -715,5 +719,34 @@
where 1=1 and m.back_flag= 3
and f.id=#{patientId,jdbcType=VARCHAR}
</select>
<select id="selectChildByCloCount" resultType="java.lang.Integer">
select count(1) from Archive_Detail where MasterID in (${mIds}) and flag = '0'
</select>
<select id="getPdfUrlByMasterOrId" resultType="java.lang.String">
SELECT
PDF_PATH
FROM
Archive_Detail
INNER JOIN
zd_assort
on Archive_Detail.AssortID = zd_assort.assort_id
WHERE 1=1
<if test="fileIds != null and fileIds != ''">
AND ID IN (${fileIds})
</if>
<if test="masterId != null and masterId != ''">
AND MasterID = #{masterId}
</if>
<if test="assortIds != null">
AND AssortID IN (
<foreach collection="assortIds" item="item" separator=",">
#{item}
</foreach>
)
</if>
<if test="flag != null and flag != ''">
AND flag = #{flag}
</if>
order by zd_assort.assort_sort
</select>
</mapper>

@ -2666,5 +2666,7 @@
<select id="selectByInpAndVisitId" resultType="com.emr.entity.Archive_Master">
select patient_id from archive_master where inp_no=#{inpNo} and visit_id=#{visitId}
</select>
<select id="selectChildMasterId" resultType="com.emr.dto.Archive_MasterDto">
select id,inp_no from Archive_Master where admission_date_time = #{time}
</select>
</mapper>

@ -23,7 +23,6 @@
//处理服务器发送来的数据
ws.onmessage = function (e) {
debugger
var msg = e.data.split(strSplit);
var a1 = msg[0];
if (msg.length == 5 && msg[2] == 2) {
@ -67,7 +66,6 @@
}
function narnBorrow(type, title, text, noticeId) {
debugger
naranja()[type]({
title: title,
text: text,

Loading…
Cancel
Save