Pārlūkot izejas kodu

客户端弹窗-事前查询接口完成

Scott 2 gadi atpakaļ
vecāks
revīzija
633014e057

+ 39 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/common/bo/before/HospPatientDiagnosisInfoDTO.java

@@ -0,0 +1,39 @@
+package org.jeecg.modules.medical.common.bo.before;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author soft01
+ * @time 2023/6/4 14:56
+ * @description '这里描写类的用途'
+ * @parentProject medical-java
+ */
+@Data
+@ApiModel("住院诊断信息")
+public class HospPatientDiagnosisInfoDTO implements Serializable {
+    @ApiModelProperty(value = "入院-诊断名称-疾病名称")
+    private String diseaseName;
+
+    @ApiModelProperty(value = "入院-诊断编码-疾病编码")
+    private String diseaseCode;
+
+    @ApiModelProperty(value = "入院日期-入院-就诊日期")
+    private Date admissionDate;
+
+    @ApiModelProperty(value = "出院-诊断编码-疾病编码")
+    private String dischargeDiseaseCode;
+
+    @ApiModelProperty(value = "出院-诊断名称-疾病名称")
+    private String dischargeDiseaseName;
+
+    @ApiModelProperty(value = "出院日期-出院-就诊日期")
+    private Date dischargeDate;
+
+    @ApiModelProperty(value = "科室")
+    private String department;
+}

+ 53 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/common/bo/before/MedicalHistoryRecord.java

@@ -0,0 +1,53 @@
+package org.jeecg.modules.medical.common.bo.before;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author soft01
+ * @time 2023/6/4 11:09
+ * @description '就诊历史记录'
+ * @parentProject medical-java
+ */
+@Data
+@ApiModel(description = "就诊历史记录")
+public class MedicalHistoryRecord implements Serializable {
+
+    @ApiModelProperty("主键")
+    private Integer id;
+
+    @ApiModelProperty("结算单据号")
+    private String hisid;
+
+    @ApiModelProperty(value = "就诊时间")
+    private Date visitTime;
+
+    @ApiModelProperty(value = "入院科室名称")
+    private String admissionDeptName;
+
+    @ApiModelProperty(value = "入院科室ID")
+    private String admissionDeptId;
+
+    @ApiModelProperty(value = "医生姓名")
+    private String doctorName;
+
+    @ApiModelProperty(value = "医生ID")
+    private String doctorId;
+
+    @ApiModelProperty(value = "治疗类型,1 住院,2门诊")
+    private String treatmentType;
+
+    @ApiModelProperty(value = "总费用")
+    private BigDecimal totalAmount;
+
+    @ApiModelProperty(value = "基金支付金额")
+    private BigDecimal fundPayAmount;
+
+    @ApiModelProperty(value = "个人支付金额")
+    private BigDecimal personalPayAmt;
+}

+ 36 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/common/bo/before/PatientDiagnosisInfo.java

@@ -0,0 +1,36 @@
+package org.jeecg.modules.medical.common.bo.before;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author soft01
+ * @time 2023/6/4 14:48
+ * @description '患者诊断信息'
+ * @parentProject medical-java
+ */
+@Data
+@ApiModel(description = "患者诊断信息")
+public class PatientDiagnosisInfo implements Serializable {
+
+    @ApiModelProperty
+    private Integer id;
+
+    @ApiModelProperty(value = "诊断名称-疾病名称")
+    private String diseaseName;
+
+    @ApiModelProperty(value = "诊断编码-疾病编码")
+    private String diseaseCode;
+
+    @ApiModelProperty(value = "就诊日期")
+    private Date visitTime;
+
+
+    @ApiModelProperty(value = "科室")
+    private String department;
+
+}

+ 48 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/common/bo/before/PatientInformationResponse.java

@@ -0,0 +1,48 @@
+package org.jeecg.modules.medical.common.bo.before;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author soft01
+ * @time 2023/6/4 10:03
+ * @description '这里描写类的用途'
+ * @parentProject medical-java
+ */
+@Data
+@ApiModel(value = "AdvanceWarningPopup", description = "事前弹窗")
+public class PatientInformationResponse implements Serializable {
+    @ApiModelProperty(value = "患者编码")
+    private String patientId;
+
+    @ApiModelProperty(value = "患者姓名")
+    private String patientName;
+
+    @ApiModelProperty(value = "性别")
+    private String gender;
+
+    @ApiModelProperty(value = "生日")
+    private Date birthday;
+
+    @ApiModelProperty(value = "年龄")
+    private String age;
+
+    @ApiModelProperty(value = "是否医保")
+    private String medicalInsurance;
+
+    @ApiModelProperty(value = "就诊日期")
+    private Date visitDate;
+
+    @ApiModelProperty(value = "就诊流水号")
+    private String visitSerialNumber;
+
+    @ApiModelProperty(value = "科室名称")
+    private String medicalDeptName;
+
+    @ApiModelProperty(value = "科室编码")
+    private String medicalDeptCode;
+}

+ 36 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/common/bo/before/PrescriptionDetail.java

@@ -0,0 +1,36 @@
+package org.jeecg.modules.medical.common.bo.before;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author soft01
+ * @time 2023/6/4 15:29
+ * @description '描述病例的开药信息'
+ * @parentProject medical-java
+ */
+@Data
+@ApiModel(description = "病例开药明细信息")
+public class PrescriptionDetail implements Serializable {
+    @ApiModelProperty(value = "药品名称")
+    private String itemNameHosp;
+
+    @ApiModelProperty(value = "科室")
+    private String department;
+
+    @ApiModelProperty(value = "开药时间")
+    private Date usageDate;
+
+    @ApiModelProperty(value = "医生名称")
+    private String doctorName;
+
+    @ApiModelProperty("药量使用天数")
+    private Long useDay;
+
+    @ApiModelProperty(value = "剩余天数")
+    private Long remainingDays;
+}

+ 64 - 23
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/controller/AdvanceWarningAuditController.java

@@ -2,16 +2,14 @@ package org.jeecg.modules.medical.controller;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.medical.common.bo.before.MedicalHistoryRecord;
+import org.jeecg.modules.medical.common.bo.before.PatientDiagnosisInfo;
+import org.jeecg.modules.medical.common.bo.before.PatientInformationResponse;
+import org.jeecg.modules.medical.common.bo.before.PrescriptionDetail;
 import org.jeecg.modules.medical.entity.AdvanceWarningAudit;
 import org.jeecg.modules.medical.service.IAdvanceWarningAuditService;
 
@@ -20,37 +18,80 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.jeecg.common.aspect.annotation.AutoLog;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
 
- /**
+/**
  * @Description: advance_warning_audit
  * @Author: jeecg-boot
  * @Date:   2023-05-09 14:37:15
  * @Version: V1.0
  */
-@Api(tags="advance_warning_audit")
+@Api(tags="事前模块api")
 @RestController
 @RequestMapping("/medical/advanceWarningAudit")
 @Slf4j
 public class AdvanceWarningAuditController extends JeecgController<AdvanceWarningAudit, IAdvanceWarningAuditService> {
 	@Autowired
 	private IAdvanceWarningAuditService advanceWarningAuditService;
-	
+
+
+	 @ApiOperation(value = "事前工单-根据事前工单查询患者信息", notes = "根据事前工单查询患者信息")
+	 @GetMapping(value = "/patient/info")
+	 public Result<PatientInformationResponse> loadPatientInfoById(@RequestParam(name = "id", required = true) String id) {
+		 PatientInformationResponse patientInfoResponse = advanceWarningAuditService
+				 .loadPatientInfoById(id);
+		 return Result.OK(patientInfoResponse);
+	 }
+
+	 @ApiOperation(value = "事前工单-查询就诊历史记录", notes = "根据事前工单查询患者的就诊历史记录")
+	 @GetMapping(value = "/patient/medicalHistory")
+	 public Result<IPage<MedicalHistoryRecord>> queryMedicalHistoryRecords(
+			 @RequestParam(name = "id", required = true) String id,
+			 @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
+			 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+		 if (pageSize > 100) {
+			 pageSize = 100;
+		 }
+		 Page<MedicalHistoryRecord> page = new Page<>(pageNum, pageSize);
+		 IPage<MedicalHistoryRecord> medicalHistoryRecords = advanceWarningAuditService
+				 .queryMedicalHistoryRecords(page, id);
+		 return Result.OK("查询成功", medicalHistoryRecords);
+	 }
+
+
+	 @ApiOperation(value = "事前工单-查询诊断信息", notes = "根据就诊历史记录,查询诊断信息")
+	 @GetMapping(value = "/patient/diagnosis/info")
+	 public Result<List<PatientDiagnosisInfo>> loadPatientDiagnosisInfo(@RequestParam(name = "id", required = true) String id,
+																		@RequestParam(name = "treatmentType", required = true) String treatmentType) {
+		 List<PatientDiagnosisInfo> result = advanceWarningAuditService.loadPatientDiagnosisInfo(id, treatmentType);
+		 return Result.OK(result);
+	 }
+
+	 @ApiOperation(value = "事前工单-根据病例查询开药信息", notes = "根据病例查询开药信息")
+	 @GetMapping(value = "/case/prescriptions")
+	 public Result<IPage<PrescriptionDetail>> getPrescriptionsByCase(
+			 @RequestParam(name = "id", required = true) Integer id,
+			 @RequestParam(name = "treatmentType", required = true) String treatmentType,
+			 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+			 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
+
+		 if (pageSize >= 100) {
+			 pageSize = 100;
+		 }
+		 Page<MedicalHistoryRecord> page = new Page<>(pageNo, pageSize);
+		 IPage<PrescriptionDetail> prescriptions = advanceWarningAuditService.loadPrescriptionsByCase(page, id, treatmentType);
+		 return Result.OK(prescriptions);
+	 }
+
+
+
+
 	/**
 	 * 分页列表查询
 	 *
@@ -72,7 +113,7 @@ public class AdvanceWarningAuditController extends JeecgController<AdvanceWarnin
 		IPage<AdvanceWarningAudit> pageList = advanceWarningAuditService.page(page, queryWrapper);
 		return Result.OK(pageList);
 	}
-	
+
 	/**
 	 *   添加
 	 *
@@ -87,7 +128,7 @@ public class AdvanceWarningAuditController extends JeecgController<AdvanceWarnin
 		advanceWarningAuditService.save(advanceWarningAudit);
 		return Result.OK("添加成功!");
 	}
-	
+
 	/**
 	 *  编辑
 	 *
@@ -102,7 +143,7 @@ public class AdvanceWarningAuditController extends JeecgController<AdvanceWarnin
 		advanceWarningAuditService.updateById(advanceWarningAudit);
 		return Result.OK("编辑成功!");
 	}
-	
+
 	/**
 	 *   通过id删除
 	 *
@@ -117,7 +158,7 @@ public class AdvanceWarningAuditController extends JeecgController<AdvanceWarnin
 		advanceWarningAuditService.removeById(id);
 		return Result.OK("删除成功!");
 	}
-	
+
 	/**
 	 *  批量删除
 	 *
@@ -132,7 +173,7 @@ public class AdvanceWarningAuditController extends JeecgController<AdvanceWarnin
 		this.advanceWarningAuditService.removeByIds(Arrays.asList(ids.split(",")));
 		return Result.OK("批量删除成功!");
 	}
-	
+
 	/**
 	 * 通过id查询
 	 *

+ 30 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/mapper/AdvanceWarningAuditMapper.java

@@ -1,10 +1,11 @@
 package org.jeecg.modules.medical.mapper;
 
-import java.util.List;
-
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.medical.common.bo.before.*;
 import org.jeecg.modules.medical.entity.AdvanceWarningAudit;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 /**
  * @Description: advance_warning_audit
@@ -14,4 +15,30 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface AdvanceWarningAuditMapper extends BaseMapper<AdvanceWarningAudit> {
 
+    PatientInformationResponse loadPatientInfoById(@Param("id") String id);
+    IPage<MedicalHistoryRecord> queryMedicalHistoryRecords(Page<MedicalHistoryRecord> page,
+                                                           @Param("patientId") String patientId,
+                                                           @Param("startTime") String startTime);
+
+    MedicalHistoryRecord statisticsAmount(@Param("hisId") String hisId, @Param("patientId") String patientId,
+                                          @Param("tableName") String tableName);
+
+    /**
+     * 根据住院结算主单id,查询患者诊断信息
+     * @param id 住院结算主单数据
+     * @return
+     */
+    HospPatientDiagnosisInfoDTO loadHospPatientDiagnosisInfo(@Param("id") String id);
+
+    /**
+     * 根据住院结算主单id,查询患者诊断信息
+     * @param id 门诊结算主单数据
+     * @return
+     */
+    PatientDiagnosisInfo loadOutpatientPatientDiagnosisInfo(@Param("id") String id);
+
+    IPage<PrescriptionDetail> loadPrescriptionsByCase(Page<MedicalHistoryRecord> page, @Param("id") Integer id,
+                                                      @Param("tableName") String tableName);
+
+    PrescriptionDetail loadTreatmentMasterInfo(@Param("id") Integer id, @Param("tableName") String tableName);
 }

+ 141 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/mapper/xml/AdvanceWarningAuditMapper.xml

@@ -2,4 +2,144 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.medical.mapper.AdvanceWarningAuditMapper">
 
-</mapper>
+    <select id="loadPatientInfoById"
+            resultType="org.jeecg.modules.medical.common.bo.before.PatientInformationResponse">
+        SELECT
+            ad.patient_id AS patientId, -- 患者编码
+            p.patient_name AS patientName, -- 患者姓名
+            p.gender AS gender, -- 性别
+            p.birthday AS birthday, -- 生日
+            "" AS age, -- 年龄
+            "" AS medicalInsurance, -- 是否医保
+            ad.visit_time AS visitDate, -- 就诊日期
+            "" AS visitSerialNumber, -- 就诊流水号
+            ad.medical_dept_name AS medicalDeptName, -- 科室名称
+            ad.medical_dept_code AS medicalDeptCode -- 科室编码
+        FROM advance_warning_audit as ad
+        LEFT JOIN his_patient as p on ad.patient_id = p.patient_no
+        WHERE ad.id = #{id,jdbcType=INTEGER};
+    </select>
+
+    <select id="queryMedicalHistoryRecords"
+            resultType="org.jeecg.modules.medical.common.bo.before.MedicalHistoryRecord">
+        SELECT
+            t.id,
+            t.hisid,
+            t.visitTime,
+            t.admissionDeptName,
+            t.admissionDeptId,
+            t.doctorName,
+            t.doctorId,
+            t.treatmentType,
+            t.totalAmount,
+            t.fundPayAmt,
+            t.personalPayAmt
+        FROM
+            (
+                SELECT
+                    m.id,
+                    m.hisid,
+                    m.visit_time as visitTime,
+                    m.admission_dept_name as admissionDeptName,
+                    m.admission_dept_id as admissionDeptId,
+                    m.doctor_name as doctorName,
+                    m.doctor_id as doctorId, -- 以下字段从代码获取
+                    "1" as treatmentType,
+                    m.fund_pay_sumamt as totalAmount, -- 总额
+                    "" AS fundPayAmt, -- 基金支付金额
+                    "" AS personalPayAmt -- 个人支付金额
+                FROM
+                    master_admission_bill AS m
+                        left JOIN hospitalizatio_settle_detail as hsd on m.hisid = hsd.hisid
+                WHERE
+                    m.patient_id = #{patientId}
+                  AND m.visit_time >= #{startTime} UNION
+                SELECT
+                    o.id,
+                    o.hisid,
+                    o.visit_time as visitTime,
+                    o.admission_dept_name as admissionDeptName,
+                    o.admission_dept_id as admissionDeptId,
+                    o.doctor_name as doctorName,
+                    o.doctor_id doctorId,
+                    "2" as treatmentType, -- 以下字段从代码获取
+                    o.fund_pay_sumamt as totalAmount, -- 总额
+                    "" AS fundPayAmt, -- 基金支付金额
+                    "" AS personalPayAmt -- 个人支付金额
+                FROM
+                    outpatient_settle_bill AS o
+                WHERE
+                    o.patient_id = #{patientId}
+                  AND o.visit_time >= #{startTime}
+            ) AS t
+        ORDER BY
+            t.visitTime DESC
+    </select>
+
+    <select id="statisticsAmount" resultType="org.jeecg.modules.medical.common.bo.before.MedicalHistoryRecord">
+        SELECT
+            sum( cost ) AS totalAmount,
+            sum( bmi_pay_amount ) AS fundPayAmount,
+            sum( individual_payment_amount ) AS personalPayAmt
+        FROM
+            ${tableName}
+        WHERE
+            hisid = #{hisId}
+          AND patient_id = #{patientId}
+    </select>
+
+    <select id="loadHospPatientDiagnosisInfo"
+            resultType="org.jeecg.modules.medical.common.bo.before.HospPatientDiagnosisInfoDTO">
+        SELECT
+            admission_disease_name as diseaseName, -- "入院-诊断名称-疾病名称"
+            admission_disease_id as diseaseCode, -- "入院-诊断编码-疾病编码"
+            admission_date as admissionDate, -- "入院日期-入院-就诊日期"
+            discharge_disease_id_main as dischargeDiseaseCode, -- "出院-诊断编码-疾病编码"
+            discharge_disease_name_main as dischargeDiseaseName, -- "出院-诊断名称-疾病名称"
+            discharge_date as dischargeDate, -- "出院日期-出院-就诊日期"
+            admission_dept_name as department -- 科室
+        FROM
+            master_admission_bill
+        WHERE
+            id = #{id,jdbcType=INTEGER}
+    </select>
+    <select id="loadOutpatientPatientDiagnosisInfo"
+            resultType="org.jeecg.modules.medical.common.bo.before.PatientDiagnosisInfo">
+        SELECT
+            admission_disease_id as diseaseCode, -- 疾病编码
+            admission_disease_name as diseaseName, -- 疾病名称"
+            visit_time as visitTime, -- 就诊日期
+            admission_dept_name as department  -- "科室"
+        FROM outpatient_settle_bill
+        WHERE
+            id = #{id,jdbcType=INTEGER}
+    </select>
+
+    <select id="loadPrescriptionsByCase"
+            resultType="org.jeecg.modules.medical.common.bo.before.PrescriptionDetail">
+        SELECT
+            hd.item_name_hosp as itemNameHosp, -- "药品名称"
+            "" as department, -- "科室
+            hd.usage_date as usageDate, --  "开药时间
+            "" as doctorName, -- "医生名称", -- 从主表带出来
+            hd.use_day as useDay -- 药量使用天数
+--             hd.use_day - (NOW() - hd.usage_date) as "剩余天数"
+        FROM
+            ${tableName} AS hd
+        WHERE
+            hd.hisid = #{id,jdbcType=INTEGER}
+    </select>
+
+    <select id="loadTreatmentMasterInfo"
+            resultType="org.jeecg.modules.medical.common.bo.before.PrescriptionDetail">
+        SELECT
+            admission_dept_name as department, -- "科室名称",
+            admission_dept_id AS "科室编码",
+            doctor_id AS "医生编码",
+            doctor_name as doctorName -- "医生名称"
+        FROM
+            ${tableName}
+        WHERE
+            id = #{id,jdbcType=INTEGER}
+    </select>
+</mapper>

+ 34 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/IAdvanceWarningAuditService.java

@@ -1,8 +1,16 @@
 package org.jeecg.modules.medical.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.jeecg.modules.medical.common.bo.before.MedicalHistoryRecord;
+import org.jeecg.modules.medical.common.bo.before.PatientDiagnosisInfo;
+import org.jeecg.modules.medical.common.bo.before.PatientInformationResponse;
+import org.jeecg.modules.medical.common.bo.before.PrescriptionDetail;
 import org.jeecg.modules.medical.entity.AdvanceWarningAudit;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: advance_warning_audit
  * @Author: jeecg-boot
@@ -11,4 +19,30 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IAdvanceWarningAuditService extends IService<AdvanceWarningAudit> {
 
+    PatientInformationResponse loadPatientInfoById(String id);
+
+    /**
+     * 根据事前工单id,查询患者历史记录
+     * @param page  页码
+     * @param id    工单id
+     * @return
+     */
+    IPage<MedicalHistoryRecord> queryMedicalHistoryRecords(Page<MedicalHistoryRecord> page, String id);
+
+    /**
+     * 根据住院、结算id查询患者诊断信息
+     * @param id
+     * @param treatmentType 就诊类型: 1=住院,2门诊
+     * @return
+     */
+    List<PatientDiagnosisInfo> loadPatientDiagnosisInfo(String id, String treatmentType);
+
+    /**
+     * 根据病例,查询开药信息
+     * @param page 分页组
+     * @param id    住院/门诊id
+     * @param treatmentType 就诊类型; 1=住院;2=门诊
+     * @return
+     */
+    IPage<PrescriptionDetail> loadPrescriptionsByCase(Page<MedicalHistoryRecord> page, Integer id, String treatmentType);
 }

+ 158 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/impl/AdvanceWarningAuditServiceImpl.java

@@ -1,11 +1,27 @@
 package org.jeecg.modules.medical.service.impl;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.modules.medical.common.bo.before.*;
 import org.jeecg.modules.medical.entity.AdvanceWarningAudit;
 import org.jeecg.modules.medical.mapper.AdvanceWarningAuditMapper;
 import org.jeecg.modules.medical.service.IAdvanceWarningAuditService;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.util.CollectionUtils;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @Description: advance_warning_audit
@@ -14,6 +30,148 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  * @Version: V1.0
  */
 @Service
+@Slf4j
 public class AdvanceWarningAuditServiceImpl extends ServiceImpl<AdvanceWarningAuditMapper, AdvanceWarningAudit> implements IAdvanceWarningAuditService {
 
+
+    @Override
+    public PatientInformationResponse loadPatientInfoById(String id) {
+        AdvanceWarningAudit advanceWarningAudit = this.getById(id);
+        if (advanceWarningAudit == null) {
+            log.error("找不到事前工单id={}", id);
+            throw new JeecgBootException("找不到工单id");
+        }
+        PatientInformationResponse result = baseMapper.loadPatientInfoById(id);
+        return result;
+    }
+
+    @Override
+    public IPage<MedicalHistoryRecord> queryMedicalHistoryRecords(Page<MedicalHistoryRecord> page, String id) {
+        // 先查询主单,获取到患者信息
+        AdvanceWarningAudit advanceWarningAudit = this.getById(id);
+        if (advanceWarningAudit == null) {
+            log.error("找不到事前工单id={}", id);
+            throw new JeecgBootException("找不到工单id");
+        }
+        String patientId = advanceWarningAudit.getPatientId();
+        //获取距今往前推一年的时间
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime localDateTime = now.plusYears(-1L);
+
+        /*Date date;
+        ZoneId zoneId = ZoneId.systemDefault();
+        ZonedDateTime zonedTime = localDateTime.atZone(zoneId);
+        date = Date.from(zonedTime.toInstant());*/
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String startTime = localDateTime.format(dateTimeFormatter);
+
+
+        IPage<MedicalHistoryRecord> result = baseMapper.queryMedicalHistoryRecords(page, patientId, startTime);
+        // 查询子表,获取总费用,医保费用,以及个人费用
+        List<MedicalHistoryRecord> records = result.getRecords();
+        if (!CollectionUtils.isEmpty(records)) {
+            for (MedicalHistoryRecord record : records) {
+                //1 住院,2门诊
+                String treatmentType = record.getTreatmentType();
+                String tableName = "";
+                if ("1".equalsIgnoreCase(treatmentType)) {
+                    tableName = "hospitalizatio_settle_detail";
+                } else {
+                    tableName = "outpatient_settlement_details";
+                }
+
+                String hisId = record.getHisid();
+                MedicalHistoryRecord mr = baseMapper.statisticsAmount(hisId, patientId, tableName);
+                if (mr != null) {
+                    record.setTotalAmount(mr.getTotalAmount());
+                    record.setFundPayAmount(mr.getFundPayAmount());
+                    record.setPersonalPayAmt(mr.getPersonalPayAmt());
+                }
+            }
+        }
+        result.setRecords(records);
+        return result;
+    }
+
+
+    /**
+     * 根据住院、结算id查询患者诊断信息
+     * @param id
+     * @param treatmentType 就诊类型: 1=住院,2门诊
+     * @return
+     */
+    @Override
+    public List<PatientDiagnosisInfo> loadPatientDiagnosisInfo(String id, String treatmentType) {
+
+        List<PatientDiagnosisInfo> resultList = new ArrayList<>();
+
+
+        if ("1".equalsIgnoreCase(treatmentType)) { // 住院
+            HospPatientDiagnosisInfoDTO hospInfo = baseMapper.loadHospPatientDiagnosisInfo(id);
+            if (hospInfo != null) {
+                PatientDiagnosisInfo r1 = new PatientDiagnosisInfo();
+                r1.setId(1);
+                r1.setDiseaseName(hospInfo.getDiseaseName());
+                r1.setDiseaseCode(hospInfo.getDiseaseCode());
+                r1.setVisitTime(hospInfo.getAdmissionDate());
+                r1.setDepartment(hospInfo.getDepartment());
+                resultList.add(r1);
+
+                PatientDiagnosisInfo r2 = new PatientDiagnosisInfo();
+                r2.setId(2);
+                r2.setDiseaseName(hospInfo.getDischargeDiseaseName());
+                r2.setDiseaseCode(hospInfo.getDischargeDiseaseName());
+                r2.setVisitTime(hospInfo.getDischargeDate());
+                r2.setDepartment(hospInfo.getDepartment());
+                resultList.add(r2);
+            }
+        } else if ("2".equalsIgnoreCase(treatmentType)) {
+            PatientDiagnosisInfo r1 = baseMapper.loadOutpatientPatientDiagnosisInfo(id);
+            if (r1 != null) {
+                r1.setId(1);
+                resultList.add(r1);
+            }
+        }
+        return resultList;
+    }
+
+    @Override
+    public IPage<PrescriptionDetail> loadPrescriptionsByCase(Page<MedicalHistoryRecord> page, Integer id, String treatmentType) {
+
+        String detailTableName = "";
+        String masterTableName = "";
+        if ("1".equalsIgnoreCase(treatmentType)) { // 住院
+            detailTableName = "hospitalizatio_settle_detail";
+            masterTableName = "master_admission_bill";
+        } else if ("2".equalsIgnoreCase(treatmentType)) { // 门诊
+            detailTableName = "outpatient_settlement_details";
+            masterTableName = "outpatient_settle_bill";
+        }
+        //获取结算主单的科室,和医生信息
+        PrescriptionDetail masterInfo = baseMapper.loadTreatmentMasterInfo(id, masterTableName);
+        IPage<PrescriptionDetail> result = baseMapper.loadPrescriptionsByCase(page, id, detailTableName);
+        if (!CollectionUtils.isEmpty(result.getRecords())) {
+            List<PrescriptionDetail> records = result.getRecords();
+            for (PrescriptionDetail record : records) {
+                if(null != masterInfo) {
+                    record.setDepartment(masterInfo.getDepartment());
+                    record.setDoctorName(masterInfo.getDoctorName());
+                }
+                // 计算药品剩余天数
+                LocalDate now = LocalDate.now();
+                if (null != record.getUsageDate()) {
+                    Date date = record.getUsageDate();
+                    Instant instant = date.toInstant();
+                    LocalDate usageLocalDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
+                    // 获取两个日期天数相差
+                    long until = usageLocalDate.until(now, ChronoUnit.DAYS) + 1;
+                    if (record.getUseDay() != null) {
+                        record.setRemainingDays(record.getUseDay() - until);
+                    }
+                }
+            }
+            result.setRecords(records);
+        }
+        return result;
+    }
 }