微信后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

552 lines
27 KiB

/*
* *
* * @Project 微信公众号
* * @Author 张剑峰
* * @Date 2020/12/2 下午2:27
* * @Description
* * @Version v1.0.0
* * @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
*
*/
package com.ynxbd.common.dao.lis;
import com.ynxbd.common.bean.lis.*;
import com.ynxbd.common.config.db.LisDB;
import java.util.ArrayList;
import java.util.List;
public class XBDLisDao {
public List<XBDLisReport> getReport(String treatId, String patientType) {
String condition = "0".equals(patientType) ? "in" : "not in";
String sql = "SELECT DISTINCT" +
" ID," +
" r.SampleName AS ReportName," +
" r.ReportClass AS ReportType," +
" ReqDeptName," +
" ReqDoctorName as ReqDoctName," +
" xc.ReqItemName," +
" CONVERT(varchar,CONVERT(datetime,ReqDate),20) as ReqDate," +
" Reporter," +
" CONVERT(varchar,CONVERT(datetime,ReportDate),20) as ReportDate," +
" CONVERT(varchar,CONVERT(datetime,p.TestDate),23) as TestDate," +
" p.SampleCode," +
" SpecimenName," +
" PatientID AS TreatId," +
" PatientName," +
" CASE Sex" +
" WHEN 1 THEN '男'" +
" WHEN 2 THEN '女'" +
" ELSE ''" +
" END AS Sex," +
" CONVERT(VARCHAR(10), Age) + AgeClass AS Age," +
" PatientClass As PatientType," +
" BedNo" +
" FROM" +
" dbo.Rpt_Patient p (NOLOCK)" +
" LEFT JOIN ( SELECT" +
" STUFF(( SELECT" +
" ',' + ReqItemName" +
" FROM" +
" Rpt_CheckCost (NOLOCK)" +
" WHERE" +
" SampleCode = c.SampleCode AND TestDate = c.TestDate" +
" FOR" +
" XML PATH('') ), 1, 1, '') AS ReqItemName," +
" c.ReqItemCode," +
" SampleCode," +
" TestDate" +
" FROM" +
" Rpt_CheckCost c (NOLOCK)" +
" GROUP BY" +
" c.SampleCode," +
" c.TestDate," +
" c.ReqItemCode ) xc ON p.SampleCode = xc.SampleCode AND p.TestDate = xc.TestDate"
+
" LEFT JOIN dbo.Dict_Report r (NOLOCK) ON SUBSTRING(p.SampleCode, 1, 2) = r.SampleCode"
+
" LEFT JOIN dbo.Dict_PatientClass pc (NOLOCK) ON p.PatientClassCode = pc.PatientClassCode"
+
" WHERE" +
" ISNULL(Checker, '') <> '' AND p.PatientClassCode " + condition
+ " (SELECT PatientClassCode FROM dbo.Dict_PatientClass WHERE (PatientClassName = '住院' OR PatientClassName = '住院急诊')) AND PatientID = ?"
+
" ORDER BY" +
" ReportDate";
return LisDB.select(sql, XBDLisReport.class, ps -> {
ps.setString(1, treatId);
});
}
public List<XBDLisResult> getResult(String testDate, String sampleCode) {
String sql = "SELECT" +
" a.rptItemCode as reportItemCode," +
" b.rptItemName as reportItemName," +
" a.resultStr as result," +
" a.unit," +
" a.range," +
" CASE a.UnusualFlag WHEN ' ' THEN '' ELSE a.UnusualFlag END AS UnusualFlag,"
+
" a.insCode," +
" b.seq" +
" FROM" +
" dbo.Rpt_CheckResult a" +
" LEFT JOIN dbo.Dict_ReportToItem b ON a.RptItemCode = b.RptItemCode" +
" WHERE" +
" a.TestDate = ? AND a.SampleCode = ? AND b.SampleCode = SUBSTRING(a.SampleCode, 1, 2)"
+
" ORDER BY" +
" b.Seq";
return LisDB.select(sql, XBDLisResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
});
}
public List<XBDLisImageResult> getImage(String testDate, String sampleCode) {
String sql = "SELECT RptItemCode AS code, Img AS image FROM dbo.Rpt_ImageResult WHERE TestDate = ? AND SampleCode = ?";
return LisDB.select(sql, XBDLisImageResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
});
}
public List<XBDLisBactResult> getBactResult(String testDate, String sampleCode) {
List<XBDLisBactResult> bactResults = new ArrayList<>();
String sql = "SELECT" +
" isnull(b.BactName,'') as BactName," +
" isnull(a.Result,'') as Result," +
" isnull(a.InsCode,'') as InsCode," +
" a.Seq" +
" FROM" +
" dbo.Rpt_BactResult (NOLOCK) a" +
" Right JOIN dbo.Dict_Bacteria (NOLOCK) b ON a.BactCode = b.BactCode" +
" WHERE" +
" a.TestDate = ? AND a.SampleCode = ?";
bactResults = LisDB.select(sql, XBDLisBactResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
});
for (XBDLisBactResult item : bactResults) {
List<XBDLisAntbResult> antbResults = getAntbResult(testDate, sampleCode, item.getSeq());
item.setAntbResults(antbResults);
List<XBDLisComment> comments = getComment(testDate, sampleCode, item.getSeq());
item.setComments(comments);
}
return bactResults;
}
private List<XBDLisAntbResult> getAntbResult(String testDate, String sampleCode, int seq) {
String sql = "SELECT" +
" isnull(a.AntbCode,'') as AntbCode," +
" isnull(b.AntbName,'') as AntbName," +
" isnull(a.Result,'') as Result," +
" isnull(a.Mic,'') as Mic," +
" isnull(a.InsCode,'') as InsCode," +
" a.Seq" +
" FROM" +
" dbo.Rpt_AntbResult (NOLOCK) a" +
" LEFT JOIN dbo.Dict_Antibiotic (NOLOCK) b ON a.AntbCode = b.AntbCode" +
" WHERE" +
" a.TestDate = ? AND a.SampleCode = ? AND a.seq = ?";
return LisDB.select(sql, XBDLisAntbResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
ps.setInt(3, seq);
});
}
private List<XBDLisComment> getComment(String testDate, String sampleCode, int seq) {
String sql = "Select * from Rpt_Comment Where TestDate = ? AND SampleCode = ? and Seq = ?";
return LisDB.select(sql, XBDLisComment.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
ps.setInt(3, seq);
});
}
// 科华
public List<XBDLisReport> getReport4KH(String treatId, String patientType) {
String condition = patientType.equals("0") ? "in" : "not in";
String sql = "SELECT" +
" ID" +
" ,r.report_name AS ReportName" +
" ,CASE r.REPORT_TYPE WHEN 1 THEN '细菌报告单' ELSE '基本报告单' END AS ReportType"
+
" ,Require_BM AS ReqDeptName" +
" ,Require_Doctor AS ReqDoctName" +
" ,xc.ReqItemName" +
" ,CONVERT(varchar,CONVERT(datetime,Require_Date),20) as ReqDate"
+
" ,u.Name AS Reporter" +
" ,CONVERT(varchar,CONVERT(DATETIME, Date_Report),20) as ReportDate"
+
" ,CONVERT(varchar,CONVERT(datetime,p.Date_Test),23) as TestDate"
+
" ,p.YBH AS SampleCode" +
" ,k.Kind_Name AS SpecimenName" +
" ,Patient_Code AS TreatId" +
" ,p.Name AS PatientName" +
" ,CASE Sex" +
" WHEN 1 THEN '男'" +
" WHEN 2 THEN '女'" +
" ELSE ''" +
" END AS Sex" +
" ,Age" +
" ,age_flag AS Age" +
" ,Patient_kind_name As PatientType," +
" Bed_no AS BedNo" +
" FROM" +
" dbo.UT_Check_Patient p (NOLOCK)" +
" LEFT JOIN ( SELECT" +
" STUFF(( SELECT" +
" ',' + Item_name" +
" FROM" +
" dbo.UT_CHECK_COST (NOLOCK)" +
" WHERE" +
" YBH = c.YBH AND Date_test = c.Date_test" +
" FOR" +
" XML PATH('') ), 1, 1, '') AS ReqItemName," +
" c.YBH," +
" c.Date_test" +
" FROM" +
" dbo.UT_CHECK_COST c (NOLOCK)" +
" GROUP BY" +
" c.YBH," +
" c.Date_test) xc ON p.YBH = xc.YBH AND p.Date_test = xc.Date_test" +
" LEFT JOIN UT_DICT_Report r (NOLOCK) ON SUBSTRING(p.YBH, 1, 2) = r.code"
+
" LEFT JOIN UT_DICT_Patient_kind pc (NOLOCK) ON p.Patient_Kind = pc.Patient_kind_code"
+
" LEFT JOIN UT_Check_Module_Kind k(nolock) on p.Kind = k.kind_code"
+
" LEFT JOIN dbo.UT_DICT_User u (nolock) on p.Reporter = u.User_ID"
+
" WHERE" +
" Flag_Send =5 AND p.Patient_Kind " + condition
+ " (SELECT Patient_kind_code FROM UT_DICT_Patient_kind WHERE (Patient_kind_name = '住院' OR Patient_kind_name = '住院急诊')) "
+
" AND Patient_Code = ?" +
" ORDER BY" +
" ReportDate";
return LisDB.select(sql, XBDLisReport.class, ps -> {
ps.setString(1, treatId);
});
}
public List<XBDLisReport> getReport4KH_Hhzfy(String treatId, String patientType) {
String condition = patientType.equals("0") ? "in" : "not in";
String condition2 =
patientType.equals("0") ? String.format(" AND Patient_Code = '%s'", treatId)
: String.format(" AND Bed_No = '%s'", treatId);
System.out.println("conditon2:" + condition2);
String sql = "SELECT" +
" ID" +
" ,r.report_name AS ReportName" +
" ,CASE r.REPORT_TYPE WHEN 1 THEN '细菌报告单' ELSE '基本报告单' END AS ReportType"
+
" ,Require_BM AS ReqDeptName" +
" ,Require_Doctor AS ReqDoctName" +
" ,xc.ReqItemName" +
" ,CONVERT(varchar,CONVERT(datetime,Require_Date),20) as ReqDate"
+
" ,u.Name AS Reporter" +
" ,CONVERT(varchar,CONVERT(DATETIME, Date_Report),20) as ReportDate"
+
" ,CONVERT(varchar,CONVERT(datetime,p.Date_Test),23) as TestDate"
+
" ,p.YBH AS SampleCode" +
" ,k.Kind_Name AS SpecimenName" +
" ,Patient_Code AS TreatId" +
" ,p.Name AS PatientName" +
" ,CASE Sex" +
" WHEN 1 THEN '男'" +
" WHEN 2 THEN '女'" +
" ELSE ''" +
" END AS Sex" +
" ,Age" +
" ,age_flag AS Age" +
" ,Patient_kind_name As PatientType," +
" Bed_no AS BedNo" +
" FROM" +
" dbo.UT_Check_Patient p (NOLOCK)" +
" LEFT JOIN ( SELECT" +
" STUFF(( SELECT" +
" ',' + Item_name" +
" FROM" +
" dbo.UT_CHECK_COST (NOLOCK)" +
" WHERE" +
" YBH = c.YBH AND Date_test = c.Date_test" +
" FOR" +
" XML PATH('') ), 1, 1, '') AS ReqItemName," +
" c.YBH," +
" c.Date_test" +
" FROM" +
" dbo.UT_CHECK_COST c (NOLOCK)" +
" GROUP BY" +
" c.YBH," +
" c.Date_test) xc ON p.YBH = xc.YBH AND p.Date_test = xc.Date_test" +
" LEFT JOIN UT_DICT_Report r (NOLOCK) ON SUBSTRING(p.YBH, 1, 2) = r.code"
+
" LEFT JOIN UT_DICT_Patient_kind pc (NOLOCK) ON p.Patient_Kind = pc.Patient_kind_code"
+
" LEFT JOIN UT_Check_Module_Kind k(nolock) on p.Kind = k.kind_code"
+
" LEFT JOIN dbo.UT_DICT_User u (nolock) on p.Reporter = u.User_ID"
+
" WHERE" +
" Flag_Send =5 AND p.Patient_Kind " + condition
+ " (SELECT Patient_kind_code FROM UT_DICT_Patient_kind WHERE (Patient_kind_name = '住院' OR Patient_kind_name = '住院急诊')) "
+ condition2 +
" ORDER BY" +
" ReportDate";
return LisDB.select(sql, XBDLisReport.class);
}
public List<XBDLisResult> getResult4KH(String testDate, String sampleCode) {
String sql = "SELECT a.Item_Code AS reportItemCode" +
" ,b.Item_Name AS reportItemName" +
" ,a.Test_Value2 AS result" +
" ,a.Text_Danwei AS unit" +
" ,a.Text_range AS range" +
" ,ISNULL(a.Text_Note, '') AS unusualFlag" +
" ,a.Flag_YQ AS insCode" +
" ,a.Out_Order AS seq" +
" FROM UT_Check_Result a LEFT JOIN" +
" UT_DICT_Items b ON a.Item_Code = b.Item_Code" +
" WHERE a.Test_Date = ? AND a.YBH = ?" +
" ORDER BY a.Out_Order";
return LisDB.select(sql, XBDLisResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
});
}
public List<XBDLisImageResult> getImage4KH(String testDate, String sampleCode) {
String sql = "SELECT item_code as code, item_string as url FROM dbo.UT_Check_Result_Image WHERE Date_test = ? AND YBH = ?";
return LisDB.select(sql, XBDLisImageResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
});
}
public List<XBDLisBactResult> getBactResult4KH(String testDate, String sampleCode) {
List<XBDLisBactResult> bactResults = new ArrayList<>();
String sql = "SELECT" +
" ISNULL(Bacteria_name, '') AS BactName" +
",ISNULL(Test_Value, '') AS Result" +
",ISNULL(Flag_YQ, '') AS InsCode" +
",Bacteria_serial AS Seq" +
" FROM ut_check_bacteria (NOLOCK)" +
" WHERE test_date = ? AND ybh = ?";
bactResults = LisDB.select(sql, XBDLisBactResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
});
for (XBDLisBactResult item : bactResults) {
List<XBDLisAntbResult> antbResults = getAntbResult4KH(testDate, sampleCode,
item.getSeq());
item.setAntbResults(antbResults);
List<XBDLisComment> comments = getComment4KH(testDate, sampleCode, item.getSeq());
item.setComments(comments);
}
return bactResults;
}
private List<XBDLisAntbResult> getAntbResult4KH(String testDate, String sampleCode, int seq) {
String sql = "SELECT" +
" isnull(a.Antibiotic_code,'') as AntbCode" +
" ,isnull(b.Antibiotic_name,'') as AntbName" +
" ,isnull(a.Test_value,'') as Result" +
" ,isnull(a.Mic,'') as Mic" +
" ,'' as InsCode" +
" ,a.Bacteria_serial AS Seq" +
" FROM " +
" ut_check_antibiotic a (NOLOCK)" +
" LEFT JOIN ut_dict_antibiotic b (NOLOCK) ON a.Antibiotic_code = b.Antibiotic_code"
+
" WHERE" +
" a.test_date = ? AND a.ybh = ? AND a.Bacteria_serial = ?";
return LisDB.select(sql, XBDLisAntbResult.class, ps -> {
ps.setString(1, testDate);
ps.setString(2, sampleCode);
ps.setInt(3, seq);
});
}
private List<XBDLisComment> getComment4KH(String testDate, String sampleCode, int seq) {
String sql = "Select '' As comment ";
return LisDB.select(sql, XBDLisComment.class);
}
// 石林
public List<XBDLisReport> getReport4Sl(String treatId, String patientType) {
String sql = "SELECT ID, ReportName, CASE ReportType WHEN 'xj' THEN '细菌报告单' ELSE '基本报告单' END AS ReportType, ReqDeptName, ReqDoctName, ReqItemName, ReqDate, Reporter, ReportDate, TestDate, SampleCode, SpecimenName, TreatId, PatientName, Sex, Age, PatientType, BedNo FROM SL_ReportList where TreatId = ? and patientType = ?";
return LisDB.select(sql, XBDLisReport.class, ps -> {
ps.setString(1, treatId);
ps.setString(2, patientType.equals("0") ? "住院" : "门诊");
});
}
public List<XBDLisResult> getResult4Sl(String reportId) {
String sql = "SELECT * FROM dbo.SL_ResultData WHERE ReportID = ?";
return LisDB.select(sql, XBDLisResult.class, ps -> {
ps.setString(1, reportId);
});
}
public List<XBDLisImageResult> getImage4Sl(String reportId) {
String sql = "SELECT * FROM dbo.SL_ImageData WHERE ReportID = ?";
return LisDB.select(sql, XBDLisImageResult.class, ps -> {
ps.setString(1, reportId);
});
}
public List<XBDLisBactResult> getBactResult4Sl(String reportId) {
String sql = "SELECT * FROM dbo.SL_Mobactresult WHERE ReportID = ?";
return LisDB.select(sql, XBDLisBactResult.class, ps -> {
ps.setString(1, reportId);
});
}
public List<XBDLisAntbResult> getAntbResult4Sl(String reportId) {
String sql = "SELECT * FROM dbo.SL_Moantiresult WHERE ReportID = ?";
return LisDB.select(sql, XBDLisAntbResult.class, ps -> {
ps.setString(1, reportId);
});
}
// 瑞美
public List<XBDLisReport> getReport4RM(String treatId) {
String sql = "SELECT" +
" a.reportid AS ID" +
" ,RTRIM(b.rptunitname) AS ReportName" +
" ,CASE e.resultclass WHEN '细菌' THEN '细菌报告单' ELSE '基本报告单' END AS ReportType" +
" ,isnull(c.deptname,'') AS ReqDeptName" +
" ,isnull(d.doctorname,'') AS ReqDoctName" +
" ,isnull(a.req_reason,'') AS ReqItemName" +
" ,isnull(a.req_dt,'') AS ReqDate" +
" ,isnull(a.report_username,'') AS Reporter" +
" ,isnull(a.report_dt,'') AS ReportDate" +
" ,CONVERT(VARCHAR, CONVERT(DATETIME, a.sampledate), 23) AS TestDate" +
" ,isnull(a.sampleno,'') AS SampleCode" +
" ,isnull(a.specimen_name,'') AS SpecimenName" +
" ,a.pat_no AS TreatId" +
" ,isnull(a.pat_name,'') AS PatientName" +
" ,CASE a.pat_sex" +
" WHEN 1 THEN '男'" +
" WHEN 2 THEN '女'" +
" ELSE ''" +
" END AS Sex" +
" ,isnull(a.pat_agestr,'') AS Age" +
" ,isnull(a.pat_typecode,'') AS PatientType" +
" ,isnull(a.req_bedno,'') AS BedNo" +
" FROM " +
" lab_report a left JOIN" +
" lab_reportunit b ON a.rptunitid = b.rptunitid left JOIN" +
" dc_dept c ON a.req_deptno = c.deptno left JOIN" +
" dc_doctor d ON a.req_docno = d.doctorno left JOIN" +
" lab_reportunit e ON a.rptunitid = e.rptunitid" +
" WHERE " +
" a.rechk_dt is not null AND a.rechk_user IS NOT NULL AND a.pat_no = ?";
return LisDB.select(sql, XBDLisReport.class, ps -> {
ps.setString(1, treatId);
});
}
public List<XBDLisResult> getResult4RM(int reportId) {
String sql = "SELECT" +
" a.rpt_itemcode AS ReportItemCode" +
" ,c.rpt_itemname AS ReportItemName" +
" ,a.result_str AS Result" +
" ,a.result_unit AS Unit" +
" ,a.result_ref AS Range" +
" ,CAST(CASE RTRIM(CASE WHEN a.result_flag IS NULL AND RTRIM(a.result_str) = '阴性' THEN 'N' WHEN a.result_flag IS NULL AND RTRIM(a.result_str) = '未检出' THEN 'M' ELSE a.result_flag END) "
+
" WHEN 'H' THEN '↑'" +
" WHEN 'L' THEN '↓'" +
" WHEN 'P' THEN '阳性'" +
" WHEN 'Q' THEN '弱阳性'" +
" WHEN 'N' THEN '阴性'" +
" WHEN 'M' THEN ''" +
" ELSE RTRIM(a.result_flag) END AS VARCHAR) AS UnusualFlag --异常标志 H偏高、L偏低、P阳性、Q弱阳性、N阴性、E错误、M正常\n"
+
" ,'' AS InsCode" +
" ,b.Seq" +
" FROM " +
" dbo.lab_result a LEFT JOIN" +
" lab_rptunit_item b ON a.rptunitid = b.rptunitid AND a.rpt_itemid = b.rpt_itemid LEFT JOIN"
+
" dbo.lab_rptitem c ON a.rpt_itemid = c.rpt_itemid" +
" WHERE " +
" reportid = ? ORDER BY b.seq";
return LisDB.select(sql, XBDLisResult.class, ps -> {
ps.setInt(1, reportId);
});
}
public List<XBDLisImageResult> getImage4RM(int reportId) {
String sql = "SELECT graphitemno AS code, graph_image AS image FROM dbo.lab_graph WHERE reportid = ? ORDER BY seq";
return LisDB.select(sql, XBDLisImageResult.class, ps -> {
ps.setInt(1, reportId);
});
}
public List<XBDLisBactResult> getBactResult4RM(int reportId) {
List<XBDLisBactResult> bactResults = new ArrayList<>();
String sql = "SELECT" +
" a.resultid" +
" ,a.rpt_itemcode AS ReportItemCode" +
" ,c.rpt_itemname AS BactName" +
" ,a.result_str AS Result" +
" ,'' AS InsCode" +
" ,b.Seq" +
" FROM " +
" dbo.lab_result a LEFT JOIN" +
" lab_rptunit_item b ON a.rptunitid = b.rptunitid AND a.rpt_itemid = b.rpt_itemid LEFT JOIN\n"
+
" dbo.lab_rptitem c ON a.rpt_itemid = c.rpt_itemid" +
" WHERE" +
" reportid = ? ORDER BY b.seq";
bactResults = LisDB.select(sql, XBDLisBactResult.class, ps -> {
ps.setInt(1, reportId);
});
for (XBDLisBactResult item : bactResults) {
List<XBDLisAntbResult> antbResults = getAntbResult4RM(item.getResultId());
item.setAntbResults(antbResults);
List<XBDLisComment> lstComment = new ArrayList<XBDLisComment>();
XBDLisComment comment = new XBDLisComment();
comment.setComment(item.getComment4RM());
lstComment.add(comment);
item.setComments(lstComment);
}
return bactResults;
}
private List<XBDLisAntbResult> getAntbResult4RM(int resultId) {
String sql = "SELECT" +
" a.medcode AS AntbCode" +
" ,b.medname AS AntbName" +
" ,a.medresult AS Result" +
" ,a.mic AS Mic" +
" , '' AS InsCode" +
" , '' AS Seq" +
" FROM " +
" lab_resultmed a LEFT JOIN" +
" lab_med b ON a.medcode = b.medcode" +
" WHERE " +
" resultid = ?";
return LisDB.select(sql, XBDLisAntbResult.class, ps -> {
ps.setInt(1, resultId);
});
}
}