Parcourir la source

预问诊对接接口修改

rengb il y a 5 ans
Parent
commit
d1c3bee8f0

+ 6 - 0
icss-service/src/main/java/com/diagbot/vo/GetHospitalRankInfoVO.java

@@ -24,4 +24,10 @@ public class GetHospitalRankInfoVO {
     @NotBlank(message = "医院编码必传")
     private String hospitalCode;
 
+    /**
+     * 校验是否对接预问诊 0-不校验 1-校验
+     */
+    @ApiModelProperty(value = "医院编码")
+    private Integer isCkConnectPrec = 1;
+
 }

+ 8 - 0
prec-service/src/main/java/com/diagbot/client/TranServiceClient.java

@@ -1,10 +1,12 @@
 package com.diagbot.client;
 
 import com.diagbot.client.hystrix.TranServiceHystrix;
+import com.diagbot.dto.GetHospitalRankInfoDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.SignInDTO;
 import com.diagbot.dto.SysHospitalDTO;
 import com.diagbot.dto.SysSetInfoDTO;
+import com.diagbot.vo.GetHospitalRankInfoVO;
 import com.diagbot.vo.HospitalSetVO;
 import com.diagbot.vo.InquiryQuoteVO;
 import com.diagbot.vo.SignInVO;
@@ -50,4 +52,10 @@ public interface TranServiceClient {
      */
     @PostMapping("/sysSet/getHospitalDatas")
     RespDTO<SysHospitalDTO> getHospitalDeptInfoData(SysHospitalCodeVO sysHospitalCodeVO);
+
+    @PostMapping("/sysSet/getHospitalRankInfo")
+    RespDTO<GetHospitalRankInfoDTO> getHospitalRankInfo(@RequestBody GetHospitalRankInfoVO getHospitalRankInfoVO);
+
+    @PostMapping("/sysSet/getParentHospitalCode")
+    RespDTO<String> getParentHospitalCode(@RequestBody String hospitalCode);
 }

+ 14 - 0
prec-service/src/main/java/com/diagbot/client/hystrix/TranServiceHystrix.java

@@ -4,7 +4,9 @@ import java.util.List;
 
 import javax.validation.Valid;
 
+import com.diagbot.dto.GetHospitalRankInfoDTO;
 import com.diagbot.dto.SysHospitalDTO;
+import com.diagbot.vo.GetHospitalRankInfoVO;
 import com.diagbot.vo.InquiryQuoteVO;
 import com.diagbot.vo.SysHospitalCodeVO;
 import org.springframework.stereotype.Component;
@@ -49,4 +51,16 @@ public class TranServiceHystrix implements TranServiceClient {
         log.error("【hystrix】调用{}异常", "getHospitalDeptInfoData");
         return null;
     }
+
+    @Override
+    public RespDTO<GetHospitalRankInfoDTO> getHospitalRankInfo(GetHospitalRankInfoVO getHospitalRankInfoVO) {
+        log.error("【hystrix】调用{}异常", "getHospitalRankInfo");
+        return null;
+    }
+
+    @Override
+    public RespDTO<String> getParentHospitalCode(String hospitalCode) {
+        log.error("【hystrix】调用{}异常", "getParentHospitalCode");
+        return null;
+    }
 }

+ 54 - 0
prec-service/src/main/java/com/diagbot/dto/GetHospitalRankInfoDTO.java

@@ -0,0 +1,54 @@
+package com.diagbot.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2019/3/19 13:56
+ */
+@ApiModel(value = "获取大小医院信息接口出参")
+@Getter
+@Setter
+public class GetHospitalRankInfoDTO {
+
+    /**
+     * 医院id
+     */
+    @ApiModelProperty(value = "医院id")
+    private Long hospitalId;
+
+    /**
+     * 医院编码
+     */
+    @ApiModelProperty(value = "医院编码")
+    private String hospitalCode;
+
+    /**
+     * 医院名称
+     */
+    @ApiModelProperty(value = "医院名称")
+    private String hospitalName;
+
+    /**
+     * 子医院id
+     */
+    @ApiModelProperty(value = "子医院id")
+    private Long sonHospitalId;
+
+    /**
+     * 子医院编码
+     */
+    @ApiModelProperty(value = "子医院编码")
+    private String sonHospitalCode;
+
+    /**
+     * 子医院名称
+     */
+    @ApiModelProperty(value = "子医院名称")
+    private String sonHospitalName;
+
+}

+ 58 - 17
prec-service/src/main/java/com/diagbot/facade/InquiryInfoFacade.java

@@ -2,6 +2,7 @@ package com.diagbot.facade;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.diagbot.client.TranServiceClient;
+import com.diagbot.dto.GetHospitalRankInfoDTO;
 import com.diagbot.dto.GetInquiryDetailDTO;
 import com.diagbot.dto.GetInquiryDetailImgDTO;
 import com.diagbot.dto.HisInquiryDTO;
@@ -28,6 +29,7 @@ import com.diagbot.util.EntityUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.RespDTOUtil;
 import com.diagbot.util.StringUtil;
+import com.diagbot.vo.GetHospitalRankInfoVO;
 import com.diagbot.vo.GetInquiryDetailVO;
 import com.diagbot.vo.HisInquirysVO;
 import com.diagbot.vo.InquiryQuoteForIcssVO;
@@ -196,6 +198,16 @@ public class InquiryInfoFacade extends InquiryInfoServiceImpl {
                 "hospital_id", hisInquirysVO.getHospitalId());
         inquiryInfoQe.eq(StringUtil.isNotBlank(hisInquirysVO.getHospitalCode()),
                 "hospital_code", hisInquirysVO.getHospitalCode());
+
+        if (StringUtil.isNotBlank(hisInquirysVO.getSonHospitalCode())) {
+            inquiryInfoQe.and(qe ->
+                    qe.eq("son_hospital_code", hisInquirysVO.getSonHospitalCode())
+                            .or()
+                            .eq("son_hospital_code", "")
+                            .or()
+                            .isNull("son_hospital_code"));
+        }
+
         inquiryInfoQe.eq(hisInquirysVO.getHospitalDeptId() != null,
                 "hospital_dept_id", hisInquirysVO.getHospitalDeptId());
         inquiryInfoQe.eq(StringUtil.isNotBlank(hisInquirysVO.getHospitalDeptCode()),
@@ -271,6 +283,28 @@ public class InquiryInfoFacade extends InquiryInfoServiceImpl {
         return hisInquiryDTOList;
     }
 
+    /**
+     * 历史病历列表(ICSS调用)
+     *
+     * @param hisInquirysVO
+     * @return
+     */
+    public List<HisInquiryDTO> hisInquirysForIcss(HisInquirysVO hisInquirysVO) {
+        String hospitalCode = hisInquirysVO.getHospitalCode();
+        if (StringUtil.isBlank(hospitalCode)) {
+            throw new CommonException(CommonErrorCode.PARAM_IS_NULL, "医院信息(医院id或者医院编码)必传!");
+        }
+
+        RespDTO<String> respDTO = tranServiceClient.getParentHospitalCode(hospitalCode);
+        String parentHospitalCode = respDTO.data;
+        if (StringUtil.isNotBlank(parentHospitalCode)) {
+            hisInquirysVO.setHospitalCode(parentHospitalCode);
+            hisInquirysVO.setSonHospitalCode(hospitalCode);
+        }
+
+        return hisInquirys(hisInquirysVO);
+    }
+
     /**
      * 病历详情
      *
@@ -507,6 +541,15 @@ public class InquiryInfoFacade extends InquiryInfoServiceImpl {
         if (inquiryInfo == null) {
             throw new CommonException(CommonErrorCode.RPC_ERROR, "病历不存在");
         }
+
+        GetHospitalRankInfoVO getHospitalRankInfoVO = new GetHospitalRankInfoVO();
+        getHospitalRankInfoVO.setHospitalCode(inquiryQuoteForIcssVO.getHospitalCode());
+        getHospitalRankInfoVO.setIsCkConnectPrec(0);
+        RespDTO<GetHospitalRankInfoDTO> respDTO = tranServiceClient.getHospitalRankInfo(getHospitalRankInfoVO);
+        RespDTOUtil.respNGDealCover(respDTO, "引用预问诊失败");
+        GetHospitalRankInfoDTO getHospitalRankInfoDTO = respDTO.data;
+        BeanUtil.copyProperties(getHospitalRankInfoDTO, inquiryQuoteForIcssVO);
+
         if (!inquiryInfo.getHospitalCode().equals(inquiryQuoteForIcssVO.getHospitalCode())) {
             throw new CommonException(CommonErrorCode.RPC_ERROR, "医院不一致");
         }
@@ -516,20 +559,20 @@ public class InquiryInfoFacade extends InquiryInfoServiceImpl {
         if (inquiryInfo.getIsQuoted() == 0) {
             inquiryInfo.setGmtModified(now);
             inquiryInfo.setIsQuoted(1);
-            if (StringUtil.isBlank(inquiryInfo.getInquiryCode())) {
-                inquiryInfo.setInquiryCode(inquiryQuoteForIcssVO.getInquiryCode());
-            }
-            inquiryInfo.setPatientId(inquiryQuoteForIcssVO.getPatientId());
-            inquiryInfo.setPatientCode(inquiryQuoteForIcssVO.getPatientCode());
-            inquiryInfo.setPatientName(inquiryQuoteForIcssVO.getPatientName());
-            inquiryInfo.setPatientIdNo(
-                    StringUtil.isBlank(inquiryQuoteForIcssVO.getPatientIdentityNum())
-                            ? inquiryQuoteForIcssVO.getPatientIdNo()
-                            : inquiryQuoteForIcssVO.getPatientIdentityNum()
-            );
-            inquiryInfo.setPatientBirthday(inquiryQuoteForIcssVO.getPatientBirthday());
-            inquiryInfo.setPatientPhone(inquiryQuoteForIcssVO.getPatientPhone());
-            inquiryInfo.setPatientSex(inquiryQuoteForIcssVO.getPatientSex());
+            //            if (StringUtil.isBlank(inquiryInfo.getInquiryCode())) {
+            //                inquiryInfo.setInquiryCode(inquiryQuoteForIcssVO.getInquiryCode());
+            //            }
+            //            inquiryInfo.setPatientId(inquiryQuoteForIcssVO.getPatientId());
+            //            inquiryInfo.setPatientCode(inquiryQuoteForIcssVO.getPatientCode());
+            //            inquiryInfo.setPatientName(inquiryQuoteForIcssVO.getPatientName());
+            //            inquiryInfo.setPatientIdNo(
+            //                    StringUtil.isBlank(inquiryQuoteForIcssVO.getPatientIdentityNum())
+            //                            ? inquiryQuoteForIcssVO.getPatientIdNo()
+            //                            : inquiryQuoteForIcssVO.getPatientIdentityNum()
+            //            );
+            //            inquiryInfo.setPatientBirthday(inquiryQuoteForIcssVO.getPatientBirthday());
+            //            inquiryInfo.setPatientPhone(inquiryQuoteForIcssVO.getPatientPhone());
+            //            inquiryInfo.setPatientSex(inquiryQuoteForIcssVO.getPatientSex());
             updateById(inquiryInfo);
         } else if (sysSetFacade.isQuoteShow(inquiryQuoteForIcssVO.getHospitalCode())) {
             QueryWrapper<InquiryQuote> inquiryQuoteQe = new QueryWrapper<>();
@@ -559,7 +602,6 @@ public class InquiryInfoFacade extends InquiryInfoServiceImpl {
                             ? inquiryQuoteForIcssVO.getPatientIdNo()
                             : inquiryQuoteForIcssVO.getPatientIdentityNum()
             );
-
         }
         inquiryQuote.setGmtModified(now);
         inquiryQuoteFacade.saveOrUpdate(inquiryQuote);
@@ -568,5 +610,4 @@ public class InquiryInfoFacade extends InquiryInfoServiceImpl {
     }
 
 
-}
-
+}

+ 33 - 0
prec-service/src/main/java/com/diagbot/vo/GetHospitalRankInfoVO.java

@@ -0,0 +1,33 @@
+package com.diagbot.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2018/11/19 18:58
+ */
+@ApiModel(value = "获取大小医院信息接口传参")
+@Getter
+@Setter
+public class GetHospitalRankInfoVO {
+
+    /**
+     * 医院编码
+     */
+    @ApiModelProperty(value = "医院编码", required = true)
+    @NotBlank(message = "医院编码必传")
+    private String hospitalCode;
+
+    /**
+     * 校验是否对接预问诊 0-不校验 1-校验
+     */
+    @ApiModelProperty(value = "医院编码")
+    private Integer isCkConnectPrec = 1;
+
+}

+ 12 - 0
prec-service/src/main/java/com/diagbot/vo/HisInquirysVO.java

@@ -30,6 +30,18 @@ public class HisInquirysVO {
     @ApiModelProperty(value = "医院编码")
     private String hospitalCode;
 
+    /**
+     * 子医院id
+     */
+    @ApiModelProperty(value = "子医院id")
+    private Long sonHospitalId;
+
+    /**
+     * 子医院编码
+     */
+    @ApiModelProperty(value = "子医院编码")
+    private String sonHospitalCode;
+
     /**
      * 医院科室id
      */

+ 7 - 0
prec-service/src/main/java/com/diagbot/web/InquiryInfoController.java

@@ -60,6 +60,13 @@ public class InquiryInfoController {
         return RespDTO.onSuc(inquiryInfoFacade.hisInquirys(hisInquirysVO));
     }
 
+    @ApiOperation(value = "历史病历列表(ICSS调用)[by:rengb]")
+    @PostMapping("/hisInquirysForIcss")
+    @SysLogger("hisInquirysForIcss")
+    public RespDTO<List<HisInquiryDTO>> hisInquirysForIcss(@Valid @RequestBody HisInquirysVO hisInquirysVO) {
+        return RespDTO.onSuc(inquiryInfoFacade.hisInquirysForIcss(hisInquirysVO));
+    }
+
     @ApiOperation(value = "病历详情[by:rengb]")
     @PostMapping("/getInquiryDetail")
     @SysLogger("getInquiryDetail")

+ 135 - 111
tran-service/src/main/java/com/diagbot/facade/PatientInfoDjFacade.java

@@ -17,6 +17,7 @@ import com.diagbot.exception.ServiceErrorCode;
 import com.diagbot.idc.VisibleIdCreater;
 import com.diagbot.service.DoctorInfoService;
 import com.diagbot.service.HospitalDeptService;
+import com.diagbot.service.PatientInfoService;
 import com.diagbot.service.impl.PatientInfoServiceImpl;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.DateUtil;
@@ -59,6 +60,9 @@ public class PatientInfoDjFacade extends PatientInfoServiceImpl {
     private SysSetFacade sysSetFacade;
     @Autowired
     private VisibleIdCreater visibleIdCreater;
+    @Autowired
+    @Qualifier("patientInfoServiceImpl")
+    private PatientInfoService patientInfoService;
 
     /**
      * 对接-页面顶部病人医生科室信息——查询
@@ -68,40 +72,32 @@ public class PatientInfoDjFacade extends PatientInfoServiceImpl {
      */
     public GetTopPatientInfoDjDTO getTopPatientInfoDj(GetTopPatientInfoDjVO getTopPatientInfoDjVO) {
         String hospitalCode = getTopPatientInfoDjVO.getHospitalCode();
-        String sonHospitalCode = getTopPatientInfoDjVO.getSonHospitalCode();
-        if (StringUtil.isBlank(sonHospitalCode)) {
-            QueryWrapper<SysSet> sysSetQe = new QueryWrapper<>();
-            sysSetQe.eq("sys_type", SysTypeEnum.PREC_SERVICE.getKey())
-                    .eq("code", "junior_hospital")
-                    .like("value", hospitalCode);
-            SysSet juniorHospitalSysSet = sysSetFacade.getOne(sysSetQe, false);
-            if (juniorHospitalSysSet != null
-                    && Lists.newArrayList(juniorHospitalSysSet.getValue().split(",")).contains(hospitalCode)) {
-                hospitalCode = juniorHospitalSysSet.getHospitalCode();
-                sonHospitalCode = getTopPatientInfoDjVO.getHospitalCode();
-            }
-            getTopPatientInfoDjVO.setHospitalCode(hospitalCode);
-            getTopPatientInfoDjVO.setSonHospitalCode(sonHospitalCode);
-        }
+        String sonHospitalCode =
+                StringUtil.isNotBlank(getTopPatientInfoDjVO.getSonHospitalCode())
+                        ? getTopPatientInfoDjVO.getSonHospitalCode()
+                        : hospitalCode;
+        getTopPatientInfoDjVO.setSonHospitalCode(sonHospitalCode);
 
         GetTopPatientInfoDjDTO getTopPatientInfoDjDTO = this.baseMapper.getTopPatientInfoDj(getTopPatientInfoDjVO);
         getTopPatientInfoDjDTO.setSystemTime(DateUtil.now());
         getTopPatientInfoDjDTO.setRecordId(getTopPatientInfoDjVO.getRecordId());
         getTopPatientInfoDjDTO.setPatientAge(DateUtil.yearCompare(getTopPatientInfoDjDTO.getBirthday(), DateUtil.now()));
 
-        if (StringUtil.isNotBlank(sonHospitalCode)) {
+        if (!hospitalCode.equals(sonHospitalCode)) {
             QueryWrapper<HospitalInfo> hospitalInfoQe = new QueryWrapper<>();
-            hospitalInfoQe.eq("code", sonHospitalCode);
-            HospitalInfo sonHospitalInfo = hospitalInfoFacade.getOne(hospitalInfoQe, false);
-            if (sonHospitalInfo != null) {
-                getTopPatientInfoDjDTO.setSonHospitalId(sonHospitalInfo.getId());
-                getTopPatientInfoDjDTO.setSonHospitalCode(sonHospitalInfo.getCode());
-                getTopPatientInfoDjDTO.setSonHospitalName(sonHospitalInfo.getName());
-            }
+            hospitalInfoQe.eq("code", hospitalCode);
+            HospitalInfo hospitalInfo = hospitalInfoFacade.getOne(hospitalInfoQe, false);
+            getTopPatientInfoDjDTO.setHospitalId(hospitalInfo.getId());
+            getTopPatientInfoDjDTO.setHospitalCode(hospitalInfo.getCode());
+            getTopPatientInfoDjDTO.setHospitalName(hospitalInfo.getName());
+        } else {
+            getTopPatientInfoDjDTO.setSonHospitalId(null);
+            getTopPatientInfoDjDTO.setSonHospitalCode(null);
+            getTopPatientInfoDjDTO.setSonHospitalName(null);
         }
 
         QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
-        hospitalDeptQe.eq("hospital_code", StringUtil.isBlank(sonHospitalCode) ? hospitalCode : sonHospitalCode);
+        hospitalDeptQe.eq("hospital_code", sonHospitalCode);
         hospitalDeptQe.eq("code", getTopPatientInfoDjVO.getHospitalDeptCode());
         HospitalDept hospitalDept = hospitalDeptFacade.getOne(hospitalDeptQe, false);
         if (hospitalDept != null) {
@@ -145,16 +141,17 @@ public class PatientInfoDjFacade extends PatientInfoServiceImpl {
      * @return
      */
     private List<SignInDTO> autoGenePatinfo(SignInVO signInVO) {
+        String hospitalCode = signInVO.getHospitalCode();
+        String sonHospitalCode =
+                StringUtil.isNotBlank(signInVO.getSonHospitalCode()) ? signInVO.getSonHospitalCode() : hospitalCode;
         QueryWrapper<SysSet> sysSetQe = new QueryWrapper<>();
         sysSetQe.eq("sys_type", SysTypeEnum.PREC_SERVICE.getKey());
         sysSetQe.and(qe1 -> qe1
                 .and(qe2 -> qe2
-                        .eq("hospital_code", signInVO.getHospitalCode())
+                        .eq("hospital_code", hospitalCode)
                         .eq("code", "patientinfo"))
                 .or(qe3 -> qe3
-                        .eq("hospital_code",
-                                StringUtil.isBlank(signInVO.getSonHospitalCode()) ? signInVO.getHospitalCode()
-                                        : signInVO.getSonHospitalCode())
+                        .eq("hospital_code", sonHospitalCode)
                         .eq("code", "default_dept")));
         Map<String, String> sysSetCodeValue = sysSetFacade.list(sysSetQe).stream()
                 .collect(Collectors.toMap(SysSet::getCode, i -> i.getValue()));
@@ -178,21 +175,22 @@ public class PatientInfoDjFacade extends PatientInfoServiceImpl {
         signInDTO.setHospitalDeptCode(hospitalDeptCode);
 
         QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
-        hospitalDeptQe.eq("hospital_code",
-                StringUtil.isBlank(signInVO.getSonHospitalCode()) ? signInVO.getHospitalCode() : signInVO.getSonHospitalCode());
+        hospitalDeptQe.eq("hospital_code", sonHospitalCode);
         hospitalDeptQe.eq("code", hospitalDeptCode);
         signInDTO.setHospitalDeptName(hospitalDeptFacade.getOne(hospitalDeptQe, false).getName());
 
         QueryWrapper<PatientInfo> patientInfoQe = new QueryWrapper<>();
-        patientInfoQe.eq("hospital_code", signInVO.getHospitalCode());
+        patientInfoQe.eq("hospital_code", sonHospitalCode);
         patientInfoQe.eq("name", signInVO.getPatientName());
         patientInfoQe.and(a ->
                 a.eq("id_no", signInVO.getPatientInfo()).or().eq("identity_num", signInVO.getPatientInfo()));
-        PatientInfo patientInfo = getOne(patientInfoQe, false);
-        if (patientInfo == null) {
+        patientInfoQe.orderByAsc("remark");
+        List<PatientInfo> patientInfoList = list(patientInfoQe);
+        PatientInfo patientInfo = null;
+        if (ListUtil.isEmpty(patientInfoList)) {
             patientInfo = new PatientInfo();
             patientInfo.setGmtCreate(DateUtil.now());
-            patientInfo.setHospitalCode(signInVO.getHospitalCode());
+            patientInfo.setHospitalCode(sonHospitalCode);
             patientInfo.setIdNo(signInVO.getPatientInfo());
             patientInfo.setIdentityNum(signInVO.getPatientInfo());
             patientInfo.setName(signInVO.getPatientName());
@@ -203,7 +201,10 @@ public class PatientInfoDjFacade extends PatientInfoServiceImpl {
             patientInfo.setRemark("1");//自动生成标志
 
             save(patientInfo);
+        } else {
+            patientInfo = patientInfoList.get(0);
         }
+
         signInDTO.setPatientCode(patientInfo.getCode());
         signInDTO.setPatientName(patientInfo.getName());
 
@@ -250,96 +251,119 @@ public class PatientInfoDjFacade extends PatientInfoServiceImpl {
     private void generateByRif(List<RegisterInfoDTO> rifList) {
         String hospitalCode = rifList.get(0).getHospitalCode();
         String hospitalName = rifList.get(0).getHospitalName();
-        PatientInfo patientInfo = rifList.get(0).getPatientInfo();
-        QueryWrapper<PatientInfo> patientInfoQe = new QueryWrapper<>();
-        patientInfoQe.eq("hospital_code", hospitalCode);
-        patientInfoQe.eq("code", patientInfo.getCode());
-        PatientInfo patientInfoQuery = getOne(patientInfoQe, false);
-        PatientInfo saveOrUpat = new PatientInfo();
-        Long patId = null;
-        if (patientInfoQuery != null) {
-            patId = patientInfoQuery.getId();
-            BeanUtil.copyProperties(patientInfoQuery, saveOrUpat);
-        }
-        BeanUtil.copyProperties(patientInfo, saveOrUpat);
-        saveOrUpat.setId(patId);
-        saveOrUpat.setHospitalCode(hospitalCode);
-        saveOrUpdate(saveOrUpat);
 
-        List<String> doctorCodeList = Lists.newArrayList();
-        List<DoctorInfo> doctorInfoList = Lists.newArrayList();
+        List<PatientInfo> patientSaveOrUpdateList = Lists.newArrayList();
+        List<HospitalDept> deptSaveOrUpdateList = Lists.newArrayList();
+        List<DoctorInfo> doctorSaveOrUpdateList = Lists.newArrayList();
         rifList.forEach(rif -> {
-            String sonHospitalCode = rif.getSonHospitalCode();
-            String sonHospitalName = rif.getSonHospitalName();
+            String sonHospitalCode = StringUtil.isNotBlank(rif.getSonHospitalCode()) ? rif.getSonHospitalCode() : hospitalCode;
+            String sonHospitalName = StringUtil.isNotBlank(rif.getSonHospitalCode()) ? rif.getSonHospitalName() : hospitalName;
+
+            /********** 患者部分 **********/
+            PatientInfo patientInfo = rif.getPatientInfo();
+            if (!patientSaveOrUpdateList.stream()
+                    .filter(patientSaveOrUpdate -> patientSaveOrUpdate.getHospitalCode().equals(sonHospitalCode))
+                    .map(patientSaveOrUpdate -> patientSaveOrUpdate.getCode())
+                    .collect(Collectors.toList())
+                    .contains(patientInfo.getCode())) {
+                QueryWrapper<PatientInfo> patientInfoQe = new QueryWrapper<>();
+                patientInfoQe.eq("hospital_code", sonHospitalCode);
+                patientInfoQe.eq("code", patientInfo.getCode());
+                PatientInfo patientInfoQuery = getOne(patientInfoQe, false);
+                PatientInfo saveOrUpat = new PatientInfo();
+                Long patId = null;
+                if (patientInfoQuery != null) {
+                    patId = patientInfoQuery.getId();
+                    BeanUtil.copyProperties(patientInfoQuery, saveOrUpat);
+                }
+                BeanUtil.copyProperties(patientInfo, saveOrUpat);
+                saveOrUpat.setId(patId);
+                saveOrUpat.setHospitalCode(sonHospitalCode);
+                patientSaveOrUpdateList.add(saveOrUpat);
+            }
 
+            /********** 科室部分 **********/
             List<String> deptCodeList = rif.getDetail().stream()
-                    .filter(i -> StringUtil.isNotBlank(i.getHospitalDeptCode()) && StringUtil.isNotBlank(i.getHospitalDeptName()))
+                    .filter(i -> StringUtil.isNotBlank(i.getHospitalDeptCode())
+                            && StringUtil.isNotBlank(i.getHospitalDeptName()))
                     .map(i -> i.getHospitalDeptCode())
                     .collect(Collectors.toList());
-            QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
-            hospitalDeptQe.eq("hospital_code", StringUtil.isBlank(sonHospitalCode) ? hospitalCode : sonHospitalCode);
-            hospitalDeptQe.in("code", deptCodeList);
-            Map<String, HospitalDept> deptMap = hospitalDeptFacade.list(hospitalDeptQe)
-                    .stream()
-                    .collect(Collectors.toMap(HospitalDept::getCode, i -> i));
-            List<HospitalDept> deptSaveOrUpdateList = Lists.newArrayList();
-            rif.getDetail().stream()
-                    .filter(i -> StringUtil.isNotBlank(i.getHospitalDeptCode()) && StringUtil.isNotBlank(i.getHospitalDeptName()))
-                    .forEach(i -> {
-                        HospitalDept hospitalDeptQuery = deptMap.get(i.getHospitalDeptCode());
-                        if (hospitalDeptQuery == null) {
-                            HospitalDept hospitalDept = new HospitalDept();
-                            hospitalDept.setHospitalCode(StringUtil.isNotBlank(sonHospitalCode) ? sonHospitalCode : hospitalCode);
-                            hospitalDept.setHospitalName(StringUtil.isNotBlank(sonHospitalCode) ? sonHospitalName : hospitalName);
-                            hospitalDept.setCode(i.getHospitalDeptCode());
-                            hospitalDept.setName(i.getHospitalDeptName());
-                            hospitalDept.setconceptDeptName("全科");
-                            deptSaveOrUpdateList.add(hospitalDept);
-                        } else {
-                            hospitalDeptQuery.setName(i.getHospitalDeptName());
-                            deptSaveOrUpdateList.add(hospitalDeptQuery);
-                        }
-                    });
-            if (ListUtil.isNotEmpty(deptSaveOrUpdateList)) {
-                hospitalDeptService.saveOrUpdateBatch(deptSaveOrUpdateList);
+            if (ListUtil.isNotEmpty(deptCodeList)) {
+                QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
+                hospitalDeptQe.eq("hospital_code", sonHospitalCode);
+                hospitalDeptQe.in("code", deptCodeList);
+                Map<String, HospitalDept> deptMap = hospitalDeptFacade.list(hospitalDeptQe)
+                        .stream()
+                        .collect(Collectors.toMap(HospitalDept::getCode, i -> i));
+                rif.getDetail().stream()
+                        .filter(i -> StringUtil.isNotBlank(i.getHospitalDeptCode())
+                                && StringUtil.isNotBlank(i.getHospitalDeptName()))
+                        .forEach(i -> {
+                            if (!deptSaveOrUpdateList.stream()
+                                    .filter(deptSaveOrUpdate -> deptSaveOrUpdate.getHospitalCode().equals(sonHospitalCode))
+                                    .map(deptSaveOrUpdate -> deptSaveOrUpdate.getCode())
+                                    .collect(Collectors.toList())
+                                    .contains(i.getHospitalDeptCode())) {
+                                HospitalDept hospitalDeptQuery = deptMap.get(i.getHospitalDeptCode());
+                                if (hospitalDeptQuery == null) {
+                                    hospitalDeptQuery = new HospitalDept();
+                                    hospitalDeptQuery.setHospitalCode(sonHospitalCode);
+                                    hospitalDeptQuery.setHospitalName(sonHospitalName);
+                                    hospitalDeptQuery.setCode(i.getHospitalDeptCode());
+                                    hospitalDeptQuery.setName(i.getHospitalDeptName());
+                                    hospitalDeptQuery.setconceptDeptName("全科");
+                                } else {
+                                    hospitalDeptQuery.setName(i.getHospitalDeptName());
+                                }
+                                deptSaveOrUpdateList.add(hospitalDeptQuery);
+                            }
+                        });
             }
 
-            rif.getDetail().stream()
+            /********** 医生部分 **********/
+            List<String> doctorCodeList = rif.getDetail().stream()
                     .filter(i -> i.getDoctorInfo() != null).map(i -> i.getDoctorInfo())
                     .filter(i -> StringUtil.isNotBlank(i.getCode()) && StringUtil.isNotBlank(i.getName()))
-                    .forEach(i -> {
-                        doctorCodeList.add(i.getCode());
-                        doctorInfoList.add(i);
-                    });
+                    .map(i -> i.getCode())
+                    .collect(Collectors.toList());
+            if (ListUtil.isNotEmpty(doctorCodeList)) {
+                QueryWrapper<DoctorInfo> doctorInfoQe = new QueryWrapper<>();
+                doctorInfoQe.eq("hospital_code", sonHospitalCode);
+                doctorInfoQe.in("code", doctorCodeList);
+                Map<String, DoctorInfo> doctorMap = doctorInfoFacade.list(doctorInfoQe)
+                        .stream()
+                        .collect(Collectors.toMap(DoctorInfo::getCode, i -> i));
+                rif.getDetail().stream()
+                        .filter(i -> i.getDoctorInfo() != null).map(i -> i.getDoctorInfo())
+                        .filter(i -> StringUtil.isNotBlank(i.getCode()) && StringUtil.isNotBlank(i.getName()))
+                        .forEach(i -> {
+                            if (!doctorSaveOrUpdateList.stream()
+                                    .filter(doctorSaveOrUpdate -> doctorSaveOrUpdate.getHospitalCode().equals(sonHospitalCode))
+                                    .map(doctorSaveOrUpdate -> doctorSaveOrUpdate.getCode())
+                                    .collect(Collectors.toList())
+                                    .contains(i.getCode())) {
+                                DoctorInfo doctorInfoQuery = doctorMap.get(i.getCode());
+                                DoctorInfo doctorInfo = new DoctorInfo();
+                                Long docId = null;
+                                if (doctorInfoQuery != null) {
+                                    docId = doctorInfoQuery.getId();
+                                    BeanUtil.copyProperties(doctorInfoQuery, doctorInfo);
+                                }
+                                BeanUtil.copyProperties(i, doctorInfo);
+                                doctorInfo.setHospitalCode(sonHospitalCode);
+                                doctorInfo.setId(docId);
+                                doctorSaveOrUpdateList.add(doctorInfo);
+                            }
+                        });
+            }
         });
 
-        if (ListUtil.isEmpty(doctorCodeList)) {
-            return;
+        if (ListUtil.isNotEmpty(patientSaveOrUpdateList)) {
+            patientInfoService.saveOrUpdateBatch(patientSaveOrUpdateList);
+        }
+        if (ListUtil.isNotEmpty(deptSaveOrUpdateList)) {
+            hospitalDeptService.saveOrUpdateBatch(deptSaveOrUpdateList);
         }
-
-        QueryWrapper<DoctorInfo> doctorInfoQe = new QueryWrapper<>();
-        doctorInfoQe.eq("hospital_code", hospitalCode);
-        doctorInfoQe.in("code", doctorCodeList);
-        Map<String, DoctorInfo> doctorMap = doctorInfoFacade.list(doctorInfoQe)
-                .stream().collect(Collectors.toMap(DoctorInfo::getCode, i -> i));
-        List<DoctorInfo> doctorSaveOrUpdateList = Lists.newArrayList();
-        doctorInfoList.forEach(i -> {
-            DoctorInfo doctorInfoQuery = doctorMap.get(i.getCode());
-            DoctorInfo doctorInfo = new DoctorInfo();
-            Long docId = null;
-            if (doctorInfoQuery != null) {
-                docId = doctorInfoQuery.getId();
-                BeanUtil.copyProperties(doctorInfoQuery, doctorInfo);
-            }
-            BeanUtil.copyProperties(i, doctorInfo);
-            doctorInfo.setHospitalCode(hospitalCode);
-            doctorInfo.setId(docId);
-            if (!doctorSaveOrUpdateList.stream()
-                    .map(doc -> doc.getCode()).distinct()
-                    .collect(Collectors.toList()).contains(doctorInfo.getCode())) {
-                doctorSaveOrUpdateList.add(doctorInfo);
-            }
-        });
         if (ListUtil.isNotEmpty(doctorSaveOrUpdateList)) {
             doctorInfoService.saveOrUpdateBatch(doctorSaveOrUpdateList);
         }

+ 29 - 2
tran-service/src/main/java/com/diagbot/facade/SysSetFacade.java

@@ -114,9 +114,10 @@ public class SysSetFacade extends SysSetServiceImpl {
                 .collect(Collectors.toMap(SysSet::getCode, i -> i));
 
         SysSet connectPrecSysSet = sysSetMap.get("connect_prec");
-        if (connectPrecSysSet == null
+        if (getHospitalRankInfoVO.getIsCkConnectPrec()==1
+                &&(connectPrecSysSet == null
                 || StringUtil.isBlank(connectPrecSysSet.getValue())
-                || connectPrecSysSet.getValue().equals("0")) {
+                || connectPrecSysSet.getValue().equals("0"))) {
             throw new CommonException(CommonErrorCode.RPC_ERROR, "不支持同时对接预问诊");
         }
 
@@ -152,6 +153,32 @@ public class SysSetFacade extends SysSetServiceImpl {
         return getHospitalRankInfoDTO;
     }
 
+    /**
+     * 获取父级医院编码
+     *
+     * @param hospitalCode
+     * @return
+     */
+    public String getParentHospitalCode(String hospitalCode) {
+        if (StringUtil.isBlank(hospitalCode)) {
+            return null;
+        }
+
+        QueryWrapper<SysSet> sysSetQe = new QueryWrapper<>();
+        sysSetQe.eq("sys_type", SysTypeEnum.PREC_SERVICE.getKey())
+                .eq("code", "junior_hospital")
+                .like("value", hospitalCode);
+        SysSet juniorHospitalSysSet = getOne(sysSetQe);
+
+        if (juniorHospitalSysSet != null) {
+            if (Lists.newArrayList(juniorHospitalSysSet.getValue().split(",")).contains(hospitalCode)) {
+                return juniorHospitalSysSet.getHospitalCode();
+            }
+        }
+
+        return null;
+    }
+
     /**
      * @param hospitalCodeSetVO
      * @return

+ 5 - 0
tran-service/src/main/java/com/diagbot/vo/GetHospitalRankInfoVO.java

@@ -17,4 +17,9 @@ public class GetHospitalRankInfoVO {
      */
     private String hospitalCode;
 
+    /**
+     * 校验是否对接预问诊 0-不校验 1-校验
+     */
+    private Integer isCkConnectPrec = 1;
+
 }

+ 8 - 2
tran-service/src/main/java/com/diagbot/web/SysSetController.java

@@ -39,7 +39,6 @@ public class SysSetController {
     SysSetFacade sysSetFacade;
 
 
-
     @ApiOperation(value = "根据医院编码获取配置信息[by:wangfeng]", notes = "hospitalCode :医院code  必填<br> ")
     @PostMapping("/getSysSetInfoDatas")
     @SysLogger("getSysSetInfoDatas")
@@ -64,10 +63,17 @@ public class SysSetController {
         return RespDTO.onSuc(sysSetFacade.getHospitalRankInfo(getHospitalRankInfoVO));
     }
 
+    @ApiOperation(value = "获取父级医院编码[by:rengb]")
+    @PostMapping("/getParentHospital")
+    @SysLogger("getParentHospitalCode")
+    public RespDTO<String> getParentHospitalCode(@RequestBody String hospitalCode) {
+        return RespDTO.onSuc(sysSetFacade.getParentHospitalCode(hospitalCode));
+    }
+
     @ApiOperation(value = "获取校验管理员身份[by:wangfeng]")
     @PostMapping("/getAdminCheckout")
     @SysLogger("getAdminCheckout")
-    public RespDTO<Boolean> getAdminCheckout(@Valid @RequestBody HospitalCodeSetVO hospitalCodeSetVO){
+    public RespDTO<Boolean> getAdminCheckout(@Valid @RequestBody HospitalCodeSetVO hospitalCodeSetVO) {
         return RespDTO.onSuc(sysSetFacade.getAdminCheckout(hospitalCodeSetVO));
     }
 }

+ 4 - 1
tran-service/src/main/resources/mapper/PatientInfoMapper.xml

@@ -76,6 +76,9 @@
         a.id as hospitalId,
         a.`code` as hospitalCode,
         a.`name` as hospitalName,
+        a.id as sonHospitalId,
+        a.`code` as sonHospitalCode,
+        a.`name` as sonHospitalName,
         c.id as doctorId,
         c.`code` as doctorCode,
         c.`name` as doctorName,
@@ -94,7 +97,7 @@
         ON a.code=d.hospital_code and d.is_deleted='N' and d.`code`=#{patientCode}
         WHERE a.is_deleted='N'
         AND a.`status`=1
-        AND a.`code`=#{hospitalCode}
+        AND a.`code`=#{sonHospitalCode}
     </select>
 
 </mapper>