You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

738 lines
34 KiB
Java

package com.xjgs.service;
import com.xjgs.dao.JDBCUtils;
import com.xjgs.dao.JDBCUtils3;
import com.xjgs.dao.JDBCUtils4;
import com.xjgs.dao.JDBCUtils5;
import com.xjgs.util.FileUtil;
import com.xjgs.util.FtpUtil;
import com.xjgs.util.Logger;
import com.xjgs.vo.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
public class RadiateService {
private static Logger logger = new Logger();
public List<Ris_Study> getFansheEntity(){
String sql = "select PATIENT_ID,REQUESTEDPROCEDUREDESCRIPTION,ACCESSIONNUMBER,STUDYUID,REPORTDATE,SOURCE_ID\n" +
",\n" +
"( CAST( DATEPART(year,REPORTDATE) as nvarchar(4)) +'/' + CAST( DATEPART(MONTH,REPORTDATE) as nvarchar(2))+'/'+ CAST(DATEPART(DAY,REPORTDATE) as nvarchar(2))\n" +
"+'/1.2.277.0.10.'+rtrim(ACCESSIONNUMBER)+'/'\n" +
"+'1.2.277.0.10.'+rtrim(ACCESSIONNUMBER)+'/')\n" +
"as 'DCMFile',\n" +
"('1.2.277.0.10.5.1.4.1.1.88.11.'+rtrim(ACCESSIONNUMBER)+'.dcm')\n" +
"as 'DCMName' \n" +
"from RIS_STUDIES where \n" +
"PROF in (2,3,4,5,6) \n" +
"and REPORTDATE is not null\n" +
"and SOURCE_ID is not null\n" +
"and AUDITINGDATE between DATEADD(SS,-1036800,getdate()) and CONVERT(varchar(100), GETDATE(), 21) and (PATIENTTYPE = '住院' or PATIENTTYPE='急诊')\n" +
"order by REPORTDATE DESC";
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
List<Ris_Study>ris_studies = new ArrayList<> ();
Ris_Study ris_study = null;
try {
connection = JDBCUtils4.getConnection ();
statement = connection.prepareStatement (sql);
resultSet = statement.executeQuery ();
while (resultSet.next ()){
ris_study = new Ris_Study ();
ris_study.setPatientId(resultSet.getString("PATIENT_ID"));
ris_study.setACCESSIONNUMBER(resultSet.getString("ACCESSIONNUMBER"));
ris_study.setRecord_name (resultSet.getString ("REQUESTEDPROCEDUREDESCRIPTION"));
ris_study.setSource_id (resultSet.getString("SOURCE_ID"));
ris_study.setReportdate (resultSet.getString ("REPORTDATE"));
ris_study.setPath (resultSet.getString ("DCMFile"));
ris_study.setFirstname (resultSet.getString ("DCMName"));
ris_studies.add (ris_study);
}
}catch (Exception ex){
logger.log(ex.toString());
}finally {
JDBCUtils.release (resultSet,statement,connection);
}
return ris_studies;
}
public void loadDcmToPdf(Ris_Study ris_study) {
String temp = System.getProperty("user.dir") + "\\temp";
File fs = new File(temp);
if (!fs.isDirectory()) {
fs.mkdirs();
}
UUID uuid = UUID.randomUUID();//UUID唯一识别
String id = uuid.toString();
id = id.replace("-", "");
FtpUtil ftpUtil = new FtpUtil();
File file = new File(temp + "\\" + id + ".pdf");
File file3 = new File(temp + "\\" + id + ".dcm");
ftpUtil.downloadFile(ris_study.getPath(), ris_study.getFirstname(), temp, id + ".dcm");
File fd = new File(temp + "\\" + id + ".dcm");
boolean b = fd.exists();
try {
if (b) {
DCM2PDF(temp + "\\" + id + ".dcm", temp + "\\" + id + ".pdf");
if (file.exists()) {
Archive_Detail archiveDetail = new Archive_Detail();
ArchiveMaster archiveMaster = pacsGetHisId(ris_study.getSource_id());
ArchiveMaster archiveMaster1 = null;
if (StringUtils.isNoneBlank(archiveMaster.getPatientId())) {
archiveMaster1 = getMasterIdByPa(archiveMaster.getPatientId());
if (StringUtils.isNoneBlank(archiveMaster1.getId())) {
archiveMaster.setId(archiveMaster1.getId());
} else {
uploadHomePageByPid(archiveMaster.getPatientId());
ArchiveMaster id1 = getMasterIdByPa(archiveMaster.getPatientId());
archiveMaster.setId(id1.getId());
}
archiveDetail.setMasterId(archiveMaster.getId());
archiveDetail.setUploadDateTime(new Date());
archiveDetail.setAssortId("EABEEB5D628449A7930F4C0A9953A754");
archiveDetail.setSource("pacs");
archiveDetail.setFlag("0");
archiveDetail.setTitle(ris_study.getRecord_name().replaceAll("\\s*", ""));
archiveDetail.setSubAssort(ris_study.getSource_id() + "_" + ris_study.getACCESSIONNUMBER());
archiveDetail.setPdfPath(getXmlPath("path") + "\\pacs\\" + archiveMaster.getPatientId() + "\\" + id + ".pdf");
File file2 = new File(getXmlPath("path") + "\\pacs\\" + archiveMaster.getPatientId());
if (!file2.isDirectory()) {
file2.mkdirs();
}
FileUtils.copyFile(file, new File(archiveDetail.getPdfPath()));
File file1 = new File(archiveDetail.getPdfPath());
if (file1.exists() && FileUtil.checkFileWritingOn(file1.getAbsolutePath())) {
writeArchiveDetail(archiveDetail);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = sdf.format(new Date());
logger.log("dcm转化成功,同步时间:"+format);
}
}
}
} else {
fanshe(ris_study.getPatientId());
}
} catch (Exception e) {
logger.log(e.toString());
} finally {
file.delete();
file3.delete();
}
}
public void fanshe(String patient_id){
String temp = System.getProperty("user.dir")+"\\temp";
File fs = new File (temp);
if(!fs.isDirectory ()){
fs.mkdirs ();
}
String loccalPath = getXmlPath("path");
ItextPdfImpl itextPdf = new ItextPdfImpl();
List<Fangshe>fangsheList= getFangshe(patient_id);
List<Archive_Detail> archive_details = getAssortIdBySource ("pacs");
Archive_Detail archiveDetail = null;
for(Fangshe fangshe:fangsheList){
boolean flag = true;
for(Archive_Detail archive_detail:archive_details){
if(archive_detail.getSubAssort ().equals(fangshe.getSource_id ()+"_"+fangshe.getACCESSIONNUMBER())){
flag = false;
}
}
if(flag){
String picPath = getPicPath(fangshe);
String picPath1 = getPicPath1 (fangshe);
UUID uuid = UUID.randomUUID();//UUID唯一识别
String id = uuid.toString();
id = id.replace("-", "");
archiveDetail = new Archive_Detail();
archiveDetail.setAssortId("EABEEB5D628449A7930F4C0A9953A754");
archiveDetail.setSubAssort(fangshe.getSource_id ()+"_"+fangshe.getACCESSIONNUMBER());
archiveDetail.setUploadDateTime(new Date());
archiveDetail.setSource("pacs");
archiveDetail.setFlag("0");
archiveDetail.setTitle(fangshe.getREQUESTEDPROCEDUREDESCRIPTION().replaceAll ("\\s*",""));
try {
ArchiveMaster archiveMaster = pacsGetHisId(fangshe.getSource_id());
if(StringUtils.isNoneBlank(archiveMaster.getPatientId ())){
ArchiveMaster archiveMaster1 = getMasterIdByPa(archiveMaster.getPatientId());
if(StringUtils.isNoneBlank(archiveMaster1.getId())){
archiveMaster.setId(archiveMaster1.getId());
}
else{
uploadHomePageByPid(archiveMaster.getPatientId());
ArchiveMaster id1 = getMasterIdByPa(archiveMaster.getPatientId());
archiveMaster.setId(id1.getId());
}
File file = new File(loccalPath+"\\pacs\\"+archiveMaster.getPatientId());
if(!file.isDirectory ()){
file.mkdirs();
}
boolean b = itextPdf.writePdf (fangshe,temp + "\\" + id + ".pdf",picPath,picPath1,fangshe.getProf ());
if(b && FileUtil.checkFileWritingOn(temp + "\\" + id + ".pdf")){
FileUtils.copyFile (new File (temp+"\\"+id+".pdf"),new File (loccalPath+"\\pacs\\"+archiveMaster.getPatientId()+"\\"+id+".pdf"));
archiveDetail.setPdfPath(loccalPath+"\\pacs\\"+archiveMaster.getPatientId()+"\\"+id+".pdf");
archiveDetail.setMasterId(archiveMaster.getId());
File file1 = new File (archiveDetail.getPdfPath ());
if(file1.exists () && FileUtil.checkFileWritingOn(file1.getAbsolutePath())){
writeArchiveDetail(archiveDetail);
logger.log("模板打出报告>>>>>单号:"+patient_id);
}
}
}
}catch (Exception e){
logger.log(e.toString());
}finally {
File file2 = new File (temp+"\\"+id+".pdf");
if(file2.exists()){
file2.delete ();
}
}
}
}
}
public String getPicPath(Fangshe source){
String path = getXmlPath("pic");
User user = getUserEntity (source.getREPORTDOCTOR ());
String str = "";
if(null != user.getCode ()){
File file = new File (path+user.getCode ()+".png");
if(file.exists ()){
str = path+user.getCode ()+".png";
}
File file1 = new File (path+"介入科\\"+user.getCode ()+".png");
if(file1.exists ()){
str = path+"介入科\\"+user.getCode ()+".png";
}
File file2 = new File (path+"内镜中心\\"+user.getCode ()+".png");
if(file2.exists ()){
str = path+"内镜中心\\"+user.getCode ()+".png";
}
if(!StringUtils.isNoneBlank (str)){
File file3 = new File (path+"B超\\"+source.getREPORTDOCTOR ()+".png");
if(file3.exists ()){
str = path+"B超\\"+source.getREPORTDOCTOR ()+".png";
}
File file4 = new File (path+"病理\\"+source.getREPORTDOCTOR ()+".png");
if(file4.exists ()){
str = path+"病理\\"+source.getREPORTDOCTOR ()+".png";
}
}
}else{
File file = new File (path+"B超\\"+source.getREPORTDOCTOR ()+".png");
if(file.exists ()){
str = path+"B超\\"+source.getREPORTDOCTOR ()+".png";
}
File file1 = new File (path+"病理\\"+source.getREPORTDOCTOR ()+".png");
if(file1.exists ()){
str = path+"病理\\"+source.getREPORTDOCTOR ()+".png";
}
}
if(!StringUtils.isNoneBlank (str)){
logger.log ("未签名医师:"+source.getProf ()+"-:"+source.getREPORTDOCTOR ());
}
return str;
}
public String getPicPath1(Fangshe source){
String path = getXmlPath("pic");
User user = getUserEntity (source.getAUDITINGDOCTOR ());
String str = "";
if(null != user.getCode ()){
File file = new File (path+user.getCode ()+".png");
if(file.exists ()){
str = path+user.getCode ()+".png";
}
File file1 = new File (path+"介入科\\"+user.getCode ()+".png");
if(file1.exists ()){
str = path+"介入科\\"+user.getCode ()+".png";
}
File file2 = new File (path+"内镜中心\\"+user.getCode ()+".png");
if(file2.exists ()){
str = path+"内镜中心\\"+user.getCode ()+".png";
}
if(!StringUtils.isNoneBlank (str)){
File file3 = new File (path+"B超\\"+source.getAUDITINGDOCTOR ()+".png");
if(file3.exists ()){
str = path+"B超\\"+source.getAUDITINGDOCTOR ()+".png";
}
File file4 = new File (path+"病理\\"+source.getAUDITINGDOCTOR ()+".png");
if(file4.exists ()){
str = path+"病理\\"+source.getAUDITINGDOCTOR ()+".png";
}
}
}else{
File file = new File (path+"B超\\"+source.getAUDITINGDOCTOR ()+".png");
if(file.exists ()){
str = path+"B超\\"+source.getAUDITINGDOCTOR ()+".png";
}
File file1 = new File (path+"病理\\"+source.getAUDITINGDOCTOR ()+".png");
if(file1.exists ()){
str = path+"病理\\"+source.getAUDITINGDOCTOR ()+".png";
}
}
if(!StringUtils.isNoneBlank (str)){
logger.log ("未签名医师:"+source.getProf ()+"-:"+source.getAUDITINGDOCTOR ());
}
return str;
}
public User getUserEntity(String name){
String sql = "select user_name from power_user where name=?";
Object[]parms = new Object[]{name};
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
User user = new User ();
try {
connection = JDBCUtils5.getConnection ();
statement = connection.prepareStatement (sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
resultSet = statement.executeQuery ();
while (resultSet.next ()){
user.setCode (resultSet.getString ("user_name"));
}
}catch (Exception ex){
}finally {
JDBCUtils.release (resultSet,statement,connection);
}
return user;
}
public List<Archive_Detail>getAssortIdBySource(String source){
String sql = "select SubAssort from archive_detail where Source = ? order by UpLoadDateTime desc";
Object[]parms = new Object[]{source};
Archive_Detail archive_detail = null;
List<Archive_Detail>details = new ArrayList<>();
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = JDBCUtils3.getConnection();
statement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
resultSet = statement.executeQuery();
while (resultSet.next()){
archive_detail = new Archive_Detail();
archive_detail.setSubAssort(resultSet.getString("SubAssort"));
details.add(archive_detail);
}
}catch (Exception e){
logger.log(e.toString());
}finally {
JDBCUtils.release(resultSet,statement,connection);
}
return details;
}
public List<Fangshe> getFangshe(String patient_id){
ResultSet resultSet = null;
Connection connection = null;
PreparedStatement statement = null;
String sql = "select ACCESSIONNUMBER,PROF,source_id,FIRSTNAME AS 姓名,PATIENTSEX AS 性别,PATIENTAGE AS 年龄,PATIENT_ID AS 检查号,\n" +
"REQUESTINGDEPARTMENT AS 申请科室,BEDID AS 床号,INPATIENT_ID AS 住院号,CLINICAL_ID AS 门诊号,\n" +
"REQUESTEDPROCEDUREDESCRIPTION AS 检查部位,EXAMINEDESCRIPTION AS 检查所见,DIAGNOSISPROMPT AS \n" +
"诊断提示,CONVERT(varchar, DATEPART(yy,EXAMINEDATE))+'年'+CONVERT(varchar, DATEPART(mm,EXAMINEDATE))+'月'+\n" +
"CONVERT(varchar, DATEPART(DD,EXAMINEDATE))+'日'AS 检查日期,CONVERT(varchar, DATEPART(yy,REPORTDATE))+'年'+\n" +
"CONVERT(varchar, DATEPART(mm,REPORTDATE))+'月'+CONVERT(varchar, DATEPART(DD,REPORTDATE))+'日' AS 报告日期,\n" +
"REPORTDOCTOR AS 报告医生,CONVERT(varchar, DATEPART(yy,AUDITINGDATE))+'年'+CONVERT(varchar, DATEPART(mm,AUDITINGDATE))+'月'+\n" +
"CONVERT(varchar, DATEPART(DD,AUDITINGDATE))+'日'AS 审核日期,AUDITINGDOCTOR AS 审核医生 from RIS_STUDIES\n" +
"where REPORTDATE is not null and PATIENT_ID=?";
Fangshe fangshe = null;
List<Fangshe>fangsheList = new ArrayList<>();
Object[]parms= new Object[]{patient_id};
try {
connection = JDBCUtils4.getConnection();
statement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
resultSet = statement.executeQuery();
while (resultSet.next()){
fangshe = new Fangshe();
fangshe.setACCESSIONNUMBER (resultSet.getString ("ACCESSIONNUMBER"));
fangshe.setProf (convertProf (resultSet.getString ("PROF")));
fangshe.setSource_id(resultSet.getString("source_id"));
fangshe.setFIRSTNAME(resultSet.getString("姓名"));
fangshe.setPATIENTSEX(resultSet.getString("性别"));
fangshe.setPATIENTAGE(resultSet.getString("年龄"));
fangshe.setPATIENT_ID(resultSet.getString("检查号"));
fangshe.setREQUESTINGDEPARTMENT(resultSet.getString("申请科室"));
fangshe.setBEDID(resultSet.getString("床号"));
fangshe.setINPATIENT_ID(resultSet.getString("门诊号"));
fangshe.setCLINICAL_ID(resultSet.getString("住院号"));
fangshe.setREQUESTEDPROCEDUREDESCRIPTION(resultSet.getString("检查部位"));
fangshe.setEXAMINEDESCRIPTION(resultSet.getString("检查所见"));
fangshe.setDIAGNOSISPROMPT(resultSet.getString("诊断提示"));
fangshe.setEXAMINEDATE(resultSet.getString("检查日期"));
fangshe.setREPORTDATE(resultSet.getString("报告日期"));
fangshe.setREPORTDOCTOR(convertName (resultSet.getString("报告医生")));
fangshe.setAUDITINGDATE(resultSet.getString("审核日期"));
fangshe.setAUDITINGDOCTOR(convertName (resultSet.getString("审核医生")));
fangsheList.add(fangshe);
}
} catch (Exception e) {
logger.log(e.toString());
}finally {
JDBCUtils.release(resultSet,statement,connection);
}
return fangsheList;
}
public void fangsheInfo(){
List<Archive_Detail> archive_details = pacsGetPatId ();
List<Ris_Study> fansheEntity = getFansheEntity ();
for(Ris_Study risStudy:fansheEntity){
boolean flag = true;
for(Archive_Detail archive_detail:archive_details){
if(archive_detail.getSubAssort().equals(risStudy.getSource_id()+"_"+risStudy.getACCESSIONNUMBER())){
flag = false;
}
}
if(flag){
loadDcmToPdf (risStudy);
}
}
}
public List<Archive_Detail> pacsGetPatId(){
String sql = "select SubAssort from archive_detail where Source = 'pacs'order by UpLoadDateTime desc";
Archive_Detail archive_detail = null;
List<Archive_Detail>details = new ArrayList<>();
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = JDBCUtils3.getConnection();
statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()){
archive_detail = new Archive_Detail();
archive_detail.setSubAssort(resultSet.getString("SubAssort"));
details.add(archive_detail);
}
}catch (Exception e){
logger.log(e.toString());
}finally {
JDBCUtils.release(resultSet,statement,connection);
}
return details;
}
//增加病例文件信息表记录
public int writeArchiveDetail(Archive_Detail archiveDetail) {
String sql = "insert into archive_detail(id,PDF_PATH,MasterID,UpLoadDateTime,AssortID,Source,SubAssort,Title,flag)values(replace(newid(), '-', '')," +
"?,?,?,?,?,?,?,?)";
Connection connection = null;
PreparedStatement statement = null;
Object[] parms = new Object[]{archiveDetail.getPdfPath(), archiveDetail.getMasterId(), archiveDetail.getUploadDateTime(), archiveDetail.getAssortId(), archiveDetail.getSource(), archiveDetail.getSubAssort(), archiveDetail.getTitle(), archiveDetail.getFlag()};
int j = 0;
try {
connection = JDBCUtils3.getConnection();
statement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
j = statement.executeUpdate();
} catch (Exception e) {
logger.log(e.toString());
}finally {
JDBCUtils.release(null,statement,connection);
}
return j;
}
public ArchiveMaster getMasterIdByPa(String jzh){
String sql = "select ID,patient_id from archive_master where patient_id = ?";
Object[]parms = new Object[]{jzh};
ArchiveMaster archiveMaster = null;
ResultSet resultSet = null;
Connection connection = null;
PreparedStatement statement = null;
try {
connection = JDBCUtils3.getConnection();
statement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
resultSet = statement.executeQuery();
while (resultSet.next()){
archiveMaster = new ArchiveMaster();
archiveMaster.setId(resultSet.getString("ID"));
archiveMaster.setPatientId(resultSet.getString("patient_id"));
}
} catch (Exception e) {
logger.log(e.toString());
}
finally {
JDBCUtils.release(resultSet,statement,connection);
}
return archiveMaster == null ? new ArchiveMaster():archiveMaster;
}
public ArchiveMaster pacsGetHisId(String sourceId){
String sql = "select fvisit_id,fappnote_no from mp.smp_pacs_appnote where fappnote_no = ?";
Object[]parms = new Object[]{sourceId};
ArchiveMaster archiveMaster = null;
ResultSet resultSet = null;
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = JDBCUtils.getConnection();
preparedStatement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
preparedStatement.setObject(i + 1, parms[i]);
}
}
resultSet = preparedStatement.executeQuery();
while (resultSet.next()){
archiveMaster = new ArchiveMaster();
archiveMaster.setPatientId(resultSet.getString("fvisit_id"));
}
} catch (SQLException e) {
logger.log(e.toString());
} catch (Exception e) {
logger.log(e.toString());
} finally {
JDBCUtils.release(resultSet,preparedStatement,connection);
}
return archiveMaster == null ? new ArchiveMaster():archiveMaster;
}
public void uploadHomePageByPid(String patientId){
String sql = "select t.zyh as 住院号,t.jzh as 记账号,t.zycs as 住院次数,t.xm as 姓名,t.xb as 性别,t.ryrq as 入院日期,t.cyrq as 出院日期,t.sfzh as 身份证号,t.rybq as 入院科室,t.dqbq as 出院科室,t.rycw as 入院床位,hp.fdrname as 主管医生 " +
"from ndns.zl t left join hthis.p_doctor hp on t.dqys = hp.fdrid where t.jzh = ? order by t.jzh desc";
ArchiveMaster master = null;
ResultSet resultSet = null;
Connection connection = null;
PreparedStatement statement = null;
Object[]parms = new Object[]{patientId};
try {
connection = JDBCUtils.getConnection();
statement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
resultSet = statement.executeQuery();
while (resultSet.next()) {
master = new ArchiveMaster();
master.setInpNo(resultSet.getString("住院号").trim());
master.setPatientId(resultSet.getString("记账号").trim());
master.setVisitId(resultSet.getString("住院次数"));
master.setName(resultSet.getString("姓名"));
master.setSex(resultSet.getString("性别"));
master.setAdmissionDateTime(resultSet.getString("入院日期"));
master.setDischargeDateTime(resultSet.getString("出院日期"));
master.setIdNo(resultSet.getString("身份证号"));
master.setDeptAdmissionTo(resultSet.getString("入院科室"));
master.setDeptName(resultSet.getString("出院科室"));
master.setDoctorInCharge(resultSet.getString("主管医生"));
master.setBedId(resultSet.getString ("入院床位"));
if(null == master.getDischargeDateTime()|| master.getDischargeDateTime().isEmpty()){
master.setStatus("在院");
}else{
master.setStatus("归档中");
}
if ("2".equals(master.getSex())) {
master.setSex("女");
} else {
master.setSex("男");
}
writeHomeEntity(master);
}
} catch (Exception e) {
logger.log(e.toString());
}
finally {
JDBCUtils.release(resultSet,statement,connection);
}
}
public String convertProf(String profName){
Map<String,String>profMap = new HashMap<> ();
profMap.put ("1","B超检查报告单");
profMap.put ("2","CR检查报告单");
profMap.put ("3","CT检查报告单");
profMap.put ("4","MR检查报告单");
profMap.put ("5","放射检查报告单");
profMap.put ("6","DR检查报告单");
profMap.put ("7","数字胃肠检查报告单");
profMap.put ("8","DSA检查小C报告单");
profMap.put ("9","DSA检查大C报告单");
profMap.put ("20","骨密度检查报告单");
profMap.put ("22","胃镜检查报告单");
profMap.put ("23","肠镜检查报告单");
profMap.put ("24","鼻咽喉镜检查报告单");
profMap.put ("25","十二指肠镜检查报告单");
profMap.put ("26","TCD检查报告单");
profMap.put ("27","支气管检查报告单");
profMap.put ("28","肺功能检查报告单");
profMap.put ("29","心电图检查报告单");
profMap.put ("30","病理检查报告单");
profMap.put ("32","超声内镜报告单");
profMap.put ("33","胶囊内镜检查报告单");
profMap.put ("34","呼气试验检查报告单");
profMap.put ("36","液基检查报告单");
profMap.put ("37","细胞学检查报告单");
profMap.put ("38","HPV检查报告单");
profMap.put ("39","皮肤科检查报告单");
if(StringUtils.isNoneBlank (profName)){
return profMap.get (profName);
}
return "";
}
public String convertName(String name){
if(StringUtils.isNoneBlank (name)){
String[] strings = name.split ("/");
if(2 == strings.length){
return strings[0];
}else {
return name;
}
}else {
return "";
}
}
//新增首页数据
int writeHomeEntity(ArchiveMaster archiveMaster) {
String sql = "insert into archive_master(id,patient_id,inp_no,visit_id,name,sex,dept_name,discharge_date_time," +
"archivestate,admission_date_time,dept_admission_to,doctor_in_charge,id_no,bed_id)values(replace(newid(), '-', ''),?,?,?,?,?,?,?,?,?,?,?,?,?)";
Object[] parms = new Object[]{archiveMaster.getPatientId(), archiveMaster.getInpNo(), archiveMaster.getVisitId(), archiveMaster.getName(), archiveMaster.getSex(), archiveMaster.getDeptName(), archiveMaster.getDischargeDateTime(), archiveMaster.getStatus(), archiveMaster.getAdmissionDateTime(), archiveMaster.getDeptAdmissionTo(), archiveMaster.getDoctorInCharge(), archiveMaster.getIdNo(),archiveMaster.getBedId ()};
Connection connection = null;
PreparedStatement statement = null;
int j = 0;
try {
connection = JDBCUtils3.getConnection();
statement = connection.prepareStatement(sql);
if (parms != null && parms.length > 0) {
for (int i = 0; i < parms.length; i++) {
statement.setObject(i + 1, parms[i]);
}
}
j = statement.executeUpdate();
} catch (Exception e) {
logger.log(e.toString());
}finally {
JDBCUtils.release(null,statement,connection);
}
return j;
}
private void DCM2PDF( String dcmFile, String toPDFFile) throws Exception
{
File oFile = null;
byte b1 = 37;
byte b2 = 80;
byte b3 = 68;
byte b4 = 70;
FileInputStream inputStream = null;
String pdfFile = toPDFFile;
File tFile = null;
FileOutputStream outputStream = null;
try {
oFile = new File(dcmFile);
if(!(oFile.isFile() && oFile.exists()))
{
throw new Exception("DCM 文件读取失败=>"+dcmFile);
}
inputStream = new FileInputStream(oFile);
byte[] bs = new byte[(int) oFile.length()];
inputStream.read(bs, 0, bs.length);
int seekPos = -1;
for (int i = 0; i < bs.length; i++) {
byte B1 = bs[i];
byte B2 = 0;
byte B3 = 0;
byte B4 = 0;
if (i + 1 < bs.length) {
B2 = (byte)bs[i + 1];
}
if (i + 2 < bs.length) {
B3 = (byte)bs[i + 2];
}
if (i + 3 < bs.length) {
B4 = (byte)bs[i + 3];
}
if (b1 == B1 && b2 == B2 && B3 == b3 && b4 == B4) {
seekPos = i;
break;
}
}
if (seekPos == -1) {
System.out.println("未发现2550 4446");
throw new Exception("DCM 未读取到标志位=>"+dcmFile);
}
tFile = new File(pdfFile);
if(tFile.isFile() && tFile.exists())
{
throw new Exception("目标文件已经存在=>"+pdfFile);
}
outputStream = new FileOutputStream(tFile, true);
for (int i = seekPos; i < bs.length; i++) {
outputStream.write(bs[i]);
}
} catch (Exception ex) {
System.out.println("读写出错" + ex.getMessage());
throw ex;
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String getXmlPath(String elementName) {
Document doc = null;
try {
doc = new SAXReader ().read(this.getClass().getResourceAsStream("/localPath.xml"));
} catch (DocumentException e) {
logger.log(e.toString());
}
Element root = doc.getRootElement();
Iterator itr = root.elementIterator();
while(itr.hasNext()){
Element element = (Element)itr.next();
if(elementName.equals(element.getName())){
return element.getTextTrim();
}
}
return "";
}
}