Browse Source

修复模板功能无法预览

hurugang 3 years ago
parent
commit
7777b7d499

+ 35 - 0
src/main/java/cn/hnthyy/thmz/Utils/DoubleTypeAdapter.java

@@ -0,0 +1,35 @@
+package cn.hnthyy.thmz.Utils;
+
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.TypeAdapter;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+
+class DoubleTypeAdapter extends TypeAdapter<Number> {
+
+    @Override
+    public void write(JsonWriter out, Number value)
+            throws IOException {
+        out.value(value);
+    }
+
+    @Override
+    public Number read(JsonReader in) throws IOException {
+        if (in.peek() == JsonToken.NULL) {
+            in.nextNull();
+            return null;
+        }
+        try {
+            String result = in.nextString();
+            if ("".equals(result)) {
+                return null;
+            }
+            return Double.parseDouble(result);
+        } catch (NumberFormatException e) {
+            throw new JsonSyntaxException(e);
+        }
+    }
+}

+ 35 - 0
src/main/java/cn/hnthyy/thmz/Utils/IntTypeAdapter.java

@@ -0,0 +1,35 @@
+package cn.hnthyy.thmz.Utils;
+
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.TypeAdapter;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+
+class IntTypeAdapter extends TypeAdapter<Number> {
+
+    @Override
+    public void write(JsonWriter out, Number value)
+            throws IOException {
+        out.value(value);
+    }
+
+    @Override
+    public Number read(JsonReader in) throws IOException {
+        if (in.peek() == JsonToken.NULL) {
+            in.nextNull();
+            return null;
+        }
+        try {
+            String result = in.nextString();
+            if ("".equals(result)) {
+                return null;
+            }
+            return Integer.parseInt(result);
+        } catch (NumberFormatException e) {
+            throw new JsonSyntaxException(e);
+        }
+    }
+}

+ 7 - 2
src/main/java/cn/hnthyy/thmz/Utils/JsonUtil.java

@@ -1,13 +1,18 @@
 package cn.hnthyy.thmz.Utils;
 
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 
 /**
  * Json 工具类
  */
 public class JsonUtil {
-     private static Gson gson = new Gson();
-
+    // private static Gson gson = new Gson();
+    private static Gson gson = new GsonBuilder()
+            .registerTypeAdapter(int.class, new IntTypeAdapter())
+            .registerTypeAdapter(Integer.class, new IntTypeAdapter())
+            .registerTypeAdapter(double.class, new DoubleTypeAdapter())
+            .registerTypeAdapter(Double.class, new DoubleTypeAdapter()).create();
     /**
      * 将对象转成json串
      *

+ 10 - 0
src/main/java/cn/hnthyy/thmz/service/his/mz/MzChargeDetailService.java

@@ -373,4 +373,14 @@ public interface MzChargeDetailService {
      * @return
      */
     Map<String,Object> printYjReq(String patientId,Integer times) throws MzException;
+
+    /**
+     * 设置完整处方
+     *
+     * @param mzPrescriptionVo 处方信息
+     * @param needPatient      是否需要病人信息
+     * @param needVerify      是否需要校验参数  true 需要
+     * @throws MzException
+     */
+    void setFullMzPrescriptionVo(MzPrescriptionVo mzPrescriptionVo, boolean needPatient,Boolean needVerify) throws MzException;
 }

+ 14 - 12
src/main/java/cn/hnthyy/thmz/service/impl/his/mz/MzChargeDetailServiceImpl.java

@@ -867,7 +867,7 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
                 throw new MzException("本次处方有医技申请,请完善既往史内容!");
             }
         }
-        setFullMzPrescriptionVo(mzPrescriptionVo, true);
+        setFullMzPrescriptionVo(mzPrescriptionVo, true, true);
         MzPatientMi mzPatientMi = mzPatientMiMapper.selectByPatientId(mzPrescriptionVo.getPatientId());
         if (mzPatientMi == null) {
             throw new MzException("当前病人信息不存在,请先保存病人信息!");
@@ -1426,31 +1426,33 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
      *
      * @param mzPrescriptionVo 处方信息
      * @param needPatient      是否需要病人信息
+     * @param needVerify       是否需要校验参数  true 需要 保存处方或者计算价格  false 设置模板
      * @throws MzException
      */
-    public void setFullMzPrescriptionVo(MzPrescriptionVo mzPrescriptionVo, boolean needPatient) throws MzException {
+    @Override
+    public void setFullMzPrescriptionVo(MzPrescriptionVo mzPrescriptionVo, boolean needPatient, Boolean needVerify) throws MzException {
         if (mzPrescriptionVo == null) {
             throw new MzException("保存处方失败,处方参数不能为空");
         }
-        if (StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())) {
+        if (needVerify && StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())) {
             throw new MzException("保存处方失败,就诊科室不能为空");
         }
-        if (StringUtils.isBlank(mzPrescriptionVo.getDoctorCode())) {
+        if (needVerify && StringUtils.isBlank(mzPrescriptionVo.getDoctorCode())) {
             throw new MzException("保存处方失败,就诊医生不能为空");
         }
         if (needPatient && StringUtils.isBlank(mzPrescriptionVo.getPatientId())) {
             throw new MzException("保存处方失败,病人ID不能为空");
         }
-        if (mzPrescriptionVo.getJzFlag() == null) {
+        if (needVerify && mzPrescriptionVo.getJzFlag() == null) {
             throw new MzException("保存处方失败,急诊标志不能为空");
         }
-        if (!Arrays.asList(YesNoEnum.YES.code, YesNoEnum.NO.code).contains(mzPrescriptionVo.getJzFlag())) {
+        if (needVerify && !Arrays.asList(YesNoEnum.YES.code, YesNoEnum.NO.code).contains(mzPrescriptionVo.getJzFlag())) {
             throw new MzException("保存处方失败,急诊标志值错误");
         }
-        if (mzPrescriptionVo.getFirstOrNot() == null) {
+        if (needVerify && mzPrescriptionVo.getFirstOrNot() == null) {
             throw new MzException("保存处方失败,初诊复诊标识为空");
         }
-        if (!Arrays.asList(YesNoEnum.YES.code, YesNoEnum.NO.code).contains(mzPrescriptionVo.getFirstOrNot())) {
+        if (needVerify && !Arrays.asList(YesNoEnum.YES.code, YesNoEnum.NO.code).contains(mzPrescriptionVo.getFirstOrNot())) {
             throw new MzException("保存处方失败,初诊复诊标识值错误");
         }
         int times = 0;
@@ -1472,8 +1474,8 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
             mzPatientMi = new MzPatientMi();
         }
         Date now = new Date();
-        //自助开处方且是保存入库的时候
-        boolean setEmrProcess = needPatient && Constants.BRZZJF_CODE.equals(mzPrescriptionVo.getDoctorCode());
+        //(自助开处方且是保存入库的时候  或者是保存模板的时候
+        boolean setEmrProcess = (needPatient && Constants.BRZZJF_CODE.equals(mzPrescriptionVo.getDoctorCode())) || !needVerify;
         //中药治疗
         String zyzlContent = null;
         //西药治疗
@@ -1654,7 +1656,7 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
                             xyIndex++;
                             SupplyTypeEnum supplyType = SupplyTypeEnum.getSupplyTypeByCode(mzChargeDetail.getSupplyCode());
                             OrderFrequencyEnum orderFrequency = OrderFrequencyEnum.getOrderFrequencyByCode(mzChargeDetail.getFrequency());
-                            String value = xyIndex + "." + mzChargeDetail.getTcName() + " " + mzChargeDetail.getQuantity() + ypZdDict.getPackUnit() + " 用法:" + supplyType != null ? supplyType.name : "" + " 频次:" + orderFrequency != null ? orderFrequency.name : "" + " ";
+                            String value = xyIndex + "." + mzChargeDetail.getTcName() + " " + mzChargeDetail.getQuantity() + ypZdDict.getPackUnit() + " 用法:" + (supplyType != null ? supplyType.name : "") + " 频次:" + (orderFrequency != null ? orderFrequency.name : "") + " ";
                             if (xyzlContent == null) {
                                 xyzlContent = "西药治疗:" + value;
                             } else {
@@ -1900,7 +1902,7 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
 
     @Override
     public Map<String, Object> getAmountForTempPrescription(MzPrescriptionVo mzPrescriptionVo) throws MzException {
-        setFullMzPrescriptionVo(mzPrescriptionVo, false);
+        setFullMzPrescriptionVo(mzPrescriptionVo, false, true);
         if (mzPrescriptionVo == null || (mzPrescriptionVo.getMzChargeDetailList() == null || mzPrescriptionVo.getMzYjReqList() == null)) {
             throw new MzException("处方内容为空,无需进行计算!");
         }

+ 11 - 3
src/main/java/cn/hnthyy/thmz/service/impl/thmz/TemplateServiceImpl.java

@@ -2,13 +2,14 @@ package cn.hnthyy.thmz.service.impl.thmz;
 
 import cn.hnthyy.thmz.Utils.JsonUtil;
 import cn.hnthyy.thmz.Utils.PyWbUtil;
-import cn.hnthyy.thmz.entity.his.mz.MzBlRecord;
+import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.thmz.TCommonParams;
 import cn.hnthyy.thmz.entity.thmz.Template;
 import cn.hnthyy.thmz.enums.ParamsTypeEnum;
 import cn.hnthyy.thmz.enums.YesNoEnum;
 import cn.hnthyy.thmz.mapper.thmz.TCommonParamsMapper;
 import cn.hnthyy.thmz.mapper.thmz.TemplateMapper;
+import cn.hnthyy.thmz.service.his.mz.MzChargeDetailService;
 import cn.hnthyy.thmz.service.thmz.TemplateService;
 import cn.hnthyy.thmz.vo.MzPrescriptionVo;
 import org.apache.commons.lang3.StringUtils;
@@ -26,9 +27,16 @@ public class TemplateServiceImpl implements TemplateService {
     @SuppressWarnings("all")
     @Autowired
     private TCommonParamsMapper tCommonParamsMapper;
-
+    @Autowired
+    MzChargeDetailService mzChargeDetailService;
     @Override
-    public int saveTemplate(Template template) {
+    public int saveTemplate(Template template) throws MzException {
+        MzPrescriptionVo mzPrescriptionVo= (MzPrescriptionVo)JsonUtil.jsontoObject(template.getTemplateData(),MzPrescriptionVo.class);
+        if(mzPrescriptionVo==null){
+            throw new MzException("保存处方失败,处方参数不能为空");
+        }
+        mzChargeDetailService.setFullMzPrescriptionVo(mzPrescriptionVo,false,false);
+        template.setTemplateData(JsonUtil.object2Json(mzPrescriptionVo));
         if (template.getId() == null) {
             template.setCreateTime(new Date());
             int num = templateMapper.insertTemplate(template);

+ 2 - 1
src/main/java/cn/hnthyy/thmz/service/thmz/TemplateService.java

@@ -1,5 +1,6 @@
 package cn.hnthyy.thmz.service.thmz;
 
+import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.thmz.Template;
 
 import java.util.List;
@@ -15,7 +16,7 @@ public interface TemplateService {
      * @param template
      * @return
      */
-    int saveTemplate(Template template);
+    int saveTemplate(Template template) throws MzException;
 
     /**
      * 查询医生自己的,科室和全院的医疗范文  ,不查询内容

+ 1 - 1
src/main/resources/static/js/mz/clinic.js

@@ -1443,7 +1443,7 @@ function editPrescription(jsonData, type) {
             }
         }
         //入院证
-        if (mzZyReq != null && mzZyReq.reqDept != null) {
+        if (mzZyReq != null && mzZyReq.reqDept != null  && mzZyReq.reqDept != "") {
             $("#inpatientWardBeHospitalized").selectpicker('val', mzZyReq.reqDept);
             $('#inpatientWardBeHospitalized').selectpicker('refresh');
             initSmallDeptByDept();