浏览代码

药品管理

lighter 2 年之前
父节点
当前提交
4cb2dd2e50

+ 45 - 0
src/main/java/thyyxxk/webserver/controller/zhuyuanyiji/MedicineManagementController.java

@@ -0,0 +1,45 @@
+package thyyxxk.webserver.controller.zhuyuanyiji;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.medicaltechnology.FetchMedicines;
+import thyyxxk.webserver.entity.medicaltechnology.MedicinePage;
+import thyyxxk.webserver.entity.medicaltechnology.PoisonousAnesthetics;
+import thyyxxk.webserver.service.zhuyuanyiji.MedicineManagementService;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/medicineManagement")
+public class MedicineManagementController {
+    private final MedicineManagementService service;
+
+    @Autowired
+    public MedicineManagementController(MedicineManagementService service) {
+        this.service = service;
+    }
+
+    @PostMapping("/fetchMedicinePages")
+    public ResultVo<List<MedicinePage>> fetchMedicinePages(@RequestBody @Validated FetchMedicines params) {
+        return service.fetchMedicinePages(params);
+    }
+
+    @PostMapping("/submitMedicinePages")
+    public ResultVo<List<MedicinePage>> submitMedicinePages(@RequestBody @Validated FetchMedicines params) {
+        return service.submitMedicinePages(params);
+    }
+
+    @PostMapping("/fetchUsedMedicines")
+    public ResultVo<List<MedicinePage>> fetchUsedMedicines(@RequestBody @Validated FetchMedicines params) {
+        return service.fetchUsedMedicines(params);
+    }
+
+    @PostMapping("/fetchPoisonousAnesthetics")
+    public ResultVo<Map<String, Object>> fetchPoisonousAnesthetics(@RequestBody @Validated FetchMedicines params) {
+        return service.fetchPoisonousAnesthetics(params);
+    }
+
+}

+ 65 - 0
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyiji/MedicineManagementDao.java

@@ -0,0 +1,65 @@
+package thyyxxk.webserver.dao.his.zhuyuanyiji;
+
+import org.apache.ibatis.annotations.*;
+import thyyxxk.webserver.entity.medicaltechnology.FetchMedicines;
+import thyyxxk.webserver.entity.medicaltechnology.MedicinePage;
+import thyyxxk.webserver.entity.medicaltechnology.PoisonousAnesthetics;
+
+import java.util.List;
+
+@Mapper
+public interface MedicineManagementDao {
+    @Select("select b.code as chargeCode,sum(a.amount) as amount,sum(a.charge_fee) as chargeFee, " +
+            "max(b.pack_retprice) as price,max(a.exec_unit) as execUnit,b.serial as serialNo, " +
+            "max(a.group_no) as groupNo,max(a.page_no) as pageNo,max(b.name) as drugName, " +
+            "max(b.specification) as spec,max(a.confirm_flag) as confirmFlag,max(b.drug_flag) as drugFlag " +
+            "from zy_drug a with(nolock),yp_zd_dict b with(nolock) " +
+            "where isnull(a.page_no,0)=0 and charge_date>=#{start} and charge_date<=#{end} " +
+            "and isnull(confirm_flag,'0')='0' and a.group_no='73' and a.exec_unit=#{dept} and a.charge_code=b.code " +
+            "and isnull(a.serial,'01')=b.serial group by b.code,b.serial having sum(a.amount)!=0")
+    List<MedicinePage> selectMedicinePages(FetchMedicines params);
+
+    @Select("select b.code as chargeCode,rtrim(c.name) as patName,rtrim(c.inpatient_no) as patNo,sum(a.amount) as amount, " +
+            "sum(a.charge_fee) as chargeFee,max(b.pack_retprice) as price,max(a.exec_unit) as execUnit,a.charge_date, " +
+            "b.serial as serialNo,max(a.group_no) as groupNo,max(a.page_no) as pageNo,max(b.name) as drugName, " +
+            "max(b.specification) as spec,max(a.confirm_flag) as confirmFlag,max(b.drug_flag) as drugFlag " +
+            "from zy_drug a with(nolock),yp_zd_dict b with(nolock),zy_actpatient c with(nolock) " +
+            "where charge_date>=#{start} and charge_date<=#{end} and a.group_no='73' and a.exec_unit=#{dept} " +
+            "and a.charge_code=b.code and a.inpatient_no=c.inpatient_no and isnull(a.serial,'01')=b.serial " +
+            "group by b.code,b.serial,c.inpatient_no,c.name,a.charge_date having sum(a.amount)!=0")
+    List<MedicinePage> selectUsedMedicines(FetchMedicines params);
+
+    @Delete("delete yz_yp_page_no where page_no=#{pageNo}")
+    void deleteExistTargetPageNo(int pageNo);
+
+    @Insert("insert into yz_yp_page_no (page_no,dept_code,ward_code,submit_time,submit_name,page_class,page_name," +
+            "start_date,end_date,group_no,submit_flag) values (#{pageNo},#{dept},#{dept},getdate(),'00000','A'," +
+            "'医技科室药品单',#{start},#{end},'73','1' )")
+    void insertNewPageNo(FetchMedicines params);
+
+    @Update("update zy_drug set page_no=#{pageNo},sub_date=getdate() where charge_date>=#{start} " +
+            "and charge_date<=#{end} and isnull(page_no,0)=0 and exec_unit=#{dept} " +
+            "and zy_drug.charge_code in (${chargeCodes}) and isnull(zy_drug.serial,'01')='01'")
+    void submitMedicinePages(FetchMedicines params);
+
+    @Select("select convert(varchar(5),a.charge_date,10) as chargeDate,b.name as chargeName,c.name as deptName,rtrim(d.name) as patName, " +
+            "patGender=case when isnull(d.sex,'')='' then '' when d.sex='1'then '男'else '女'end, " +
+            "d.social_no,rtrim(a.inpatient_no) as patNo,rtrim(e.admiss_diag_str) as admdiag, " +
+            "b.specification2 as spec,a.charge_amount as chargeAmount,a.charge_fee as chargeFee,rtrim(a.charge_code_mx) as chargeCode " +
+            "from zy_detail_charge a left join a_patient_mi d on a.inpatient_no=d.inpatient_no " +
+            "left join zy_actpatient e on a.inpatient_no=e.inpatient_no,zd_unit_code c, " +
+            "(select name,specification2,code,drug_flag from yp_zd_dict where drug_flag>0 group by code,name,specification2,drug_flag) b " +
+            "where a.charge_date>=#{start} and a.charge_date<=#{end} and a.exec_unit=#{dept} and " +
+            "a.charge_code_mx=b.code and a.exec_unit=c.code " +
+            "union all " +
+            "select convert(varchar(5),a.charge_date,10) as chargeDate,b.name as chargeName,'麻醉科' as deptName,rtrim(d.name) as patName, " +
+            "patGender=case when isnull(d.sex,'')='' then '' when d.sex='1'then '男'else '女'end, " +
+            "d.social_no,rtrim(a.patient_id) as patNo,admdiag='', " +
+            "b.specification2 as spec,a.quantity as chargeAmount,a.unit_price*quantity as chargeFee, " +
+            "rtrim(a.charge_item_code) as chargeCode " +
+            "from mz_charge_detail_b a left join mz_patient_mi d on a.patient_id=d.patient_id, " +
+            "(select name,specification2,code,drug_flag from yp_zd_dict where drug_flag>0 group by code,name,specification2,drug_flag) b " +
+            "where a.charge_date>=#{start} and a.charge_date<=#{end} and a.warn_dept!='1070000' and a.charge_item_code=b.code")
+    List<PoisonousAnesthetics> selectPoisonousAnesthetics(FetchMedicines params);
+}
+

+ 17 - 0
src/main/java/thyyxxk/webserver/entity/medicaltechnology/FetchMedicines.java

@@ -0,0 +1,17 @@
+package thyyxxk.webserver.entity.medicaltechnology;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+public class FetchMedicines {
+    @NotBlank(message = "开始日期不能为空")
+    private String start;
+    @NotBlank(message = "结束日期不能为空")
+    private String end;
+    @NotBlank(message = "令牌已过期,请重新登录。")
+    private String dept;
+    private Integer pageNo;
+    private String chargeCodes;
+}

+ 27 - 0
src/main/java/thyyxxk/webserver/entity/medicaltechnology/MedicinePage.java

@@ -0,0 +1,27 @@
+package thyyxxk.webserver.entity.medicaltechnology;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class MedicinePage {
+    private String chargeCode;
+    private String drugName;
+    private String execUnit;
+    private String serialNo;
+    private String groupNo;
+    private String spec;
+    private BigDecimal amount;
+    private BigDecimal chargeFee;
+    private BigDecimal price;
+    private String pageNo;
+    private String confirmFlag;
+    private String drugFlag;
+    private Date ChargeDate;
+    private String patNo;
+    private String patName;
+    private String tjFlag = "1";
+    private boolean checked = true;
+}

+ 24 - 0
src/main/java/thyyxxk/webserver/entity/medicaltechnology/PoisonousAnesthetics.java

@@ -0,0 +1,24 @@
+package thyyxxk.webserver.entity.medicaltechnology;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class PoisonousAnesthetics {
+    private String chargeCode;
+    private String chargeName;
+    private String chargeDate;
+    private String deptName;
+    private String patName;
+    private String patGender;
+    private String socialNo;
+    private String patNo;
+    private String admdiag;
+    private String spec;
+    private BigDecimal chargeAmount;
+    private BigDecimal chargeFee;
+}

+ 6 - 3
src/main/java/thyyxxk/webserver/service/medicalinsurance/SiMzService.java

@@ -308,9 +308,12 @@ public class SiMzService {
     }
 
     public void insertSiPatInfo(MzPatientInfo mz) {
-        PsnBaseInfo patinfo = dao.selectPsnBaseinfo(mz.getPatNo(), mz.getTimes());
-        patinfo.setTimes(-1);
-        dao.insertSiMzInfoPsnNo(patinfo);
+        int count = dao.selectSiMzInfoCount(mz.getPatNo(), -1);
+        if (count == 0) {
+            PsnBaseInfo patinfo = dao.selectPsnBaseinfo(mz.getPatNo(), mz.getTimes());
+            patinfo.setTimes(-1);
+            dao.insertSiMzInfoPsnNo(patinfo);
+        }
     }
 
     public ResultVo<String> saveSiMzDiags(List<SiMzDiag> diags) {

+ 98 - 0
src/main/java/thyyxxk/webserver/service/zhuyuanyiji/MedicineManagementService.java

@@ -0,0 +1,98 @@
+package thyyxxk.webserver.service.zhuyuanyiji;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.dao.his.zhuyuanyiji.MedicineManagementDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.medicaltechnology.FetchMedicines;
+import thyyxxk.webserver.entity.medicaltechnology.MedicinePage;
+import thyyxxk.webserver.entity.medicaltechnology.PoisonousAnesthetics;
+import thyyxxk.webserver.service.PublicServer;
+import thyyxxk.webserver.utils.DateUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+@Slf4j
+@Service
+public class MedicineManagementService {
+    private final MedicineManagementDao dao;
+    private final PublicServer publicService;
+
+    @Autowired
+    public MedicineManagementService(MedicineManagementDao dao, PublicServer publicService) {
+        this.dao = dao;
+        this.publicService = publicService;
+    }
+
+    public ResultVo<List<MedicinePage>> fetchMedicinePages(FetchMedicines params) {
+        transformDateToDatetime(params);
+        List<MedicinePage> list = dao.selectMedicinePages(params);
+        if (list.isEmpty()) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+        return ResultVoUtil.success(list);
+    }
+
+    public ResultVo<List<MedicinePage>> fetchUsedMedicines(FetchMedicines params) {
+        transformDateToDatetime(params);
+        List<MedicinePage> list = dao.selectUsedMedicines(params);
+        if (list.isEmpty()) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+        return ResultVoUtil.success(list);
+    }
+
+    public ResultVo<List<MedicinePage>> submitMedicinePages(FetchMedicines newMedicinePage) {
+        if (StringUtil.isBlank(newMedicinePage.getChargeCodes())) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "请勾选需要提交的药品。");
+        }
+        int pageNo = publicService.getTheDrugListNo();
+        dao.deleteExistTargetPageNo(pageNo);
+        transformDateToDatetime(newMedicinePage);
+        newMedicinePage.setPageNo(pageNo);
+        dao.insertNewPageNo(newMedicinePage);
+        dao.submitMedicinePages(newMedicinePage);
+        return ResultVoUtil.success(dao.selectMedicinePages(newMedicinePage));
+    }
+
+    public ResultVo<Map<String, Object>> fetchPoisonousAnesthetics(FetchMedicines params) {
+        transformDateToDatetime(params);
+        List<PoisonousAnesthetics> list = dao.selectPoisonousAnesthetics(params);
+        if (list.isEmpty()) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+        Map<String, List<PoisonousAnesthetics>> medicines = new TreeMap<>();
+        for (PoisonousAnesthetics item : list) {
+            String key = item.getChargeDate() + "^" + item.getChargeCode();
+            if (medicines.containsKey(key)) {
+                medicines.get(key).add(item);
+            } else {
+                List<PoisonousAnesthetics> temp = new ArrayList<>();
+                temp.add(item);
+                medicines.put(key, temp);
+            }
+        }
+        Map<String, BigDecimal> amounts = new HashMap<>();
+        for (Map.Entry<String, List<PoisonousAnesthetics>> entry : medicines.entrySet()) {
+            BigDecimal sum = BigDecimal.ZERO;
+            for (PoisonousAnesthetics item : entry.getValue()) {
+                sum = sum.add(item.getChargeAmount());
+            }
+            amounts.put(entry.getKey(), sum);
+        }
+        Map<String, Object> map = new HashMap<>();
+        map.put("medicines", medicines);
+        map.put("amounts", amounts);
+        return ResultVoUtil.success(map);
+    }
+
+    private void transformDateToDatetime(FetchMedicines params) {
+        params.setStart(params.getStart() + " 00:00:00.000");
+        params.setEnd(params.getEnd() + " 23:59:59.999");
+    }
+}