医共体数据同步调整

debug
王绍全 6 days ago
parent 6272b6b540
commit 5c35c12675
  1. 6
      src/main/java/com/ynxbd/common/TestA.java
  2. 4
      src/main/java/com/ynxbd/common/action/AliAction.java
  3. 32
      src/main/java/com/ynxbd/common/action/HealthCardAction.java
  4. 74
      src/main/java/com/ynxbd/common/action/HealthCodeAction.java
  5. 4
      src/main/java/com/ynxbd/common/action/PatientAction.java
  6. 5
      src/main/java/com/ynxbd/common/bean/Patient.java
  7. 4
      src/main/java/com/ynxbd/common/config/db/DataBase.java
  8. 54
      src/main/java/com/ynxbd/common/dao/PatientDao.java
  9. 17
      src/main/java/com/ynxbd/common/dao/his/HisPatientDao.java
  10. 8
      src/main/java/com/ynxbd/common/helper/common/DateHelper.java
  11. 84
      src/main/java/com/ynxbd/common/helper/common/LocalDateHelper.java
  12. 225
      src/main/java/com/ynxbd/common/helper/common/SmsNewHelper.java
  13. 4
      src/main/java/com/ynxbd/common/helper/common/Zip2String.java
  14. 153
      src/main/java/com/ynxbd/common/service/GMCService.java
  15. 16
      src/main/java/com/ynxbd/common/service/HCodeService.java
  16. 124
      src/main/java/com/ynxbd/common/service/PatientService.java

@ -3,6 +3,7 @@ package com.ynxbd.common;
import com.ynxbd.common.bean.Doctor;
import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.enums.MerchantEnum;
import com.ynxbd.common.dao.PatientDao;
import com.ynxbd.common.helper.common.HMACHelper;
import com.ynxbd.common.helper.common.JsonHelper;
import com.ynxbd.common.result.JsonResult;
@ -61,6 +62,11 @@ public class TestA {
// }
public static void main(String[] args) {
List<Patient> patients = new PatientDao().selectListByPatientId("1");
System.out.println(patients);
}
// public static void main(String[] args) {
// System.out.println(AesWxHelper.encode("524404"));
//

@ -13,6 +13,7 @@ import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.result.ServiceException;
import com.ynxbd.common.service.PatientService;
import com.ynxbd.wx.wxfactory.AesWxHelper;
import com.ynxbd.wx.wxfactory.WxCacheHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
@ -111,7 +112,7 @@ public class AliAction extends BaseAction {
/**
* 绑定新患者不通过电子健康卡
* [患者绑定]支付宝
*/
@Action("bindMyself")
public Result bindMyself(boolean isVerifyCode, String smsCode, String openid, String accessToken, String address, String county, String areaCode, String areaAddress, String nation, String birthday) {
@ -151,6 +152,7 @@ public class AliAction extends BaseAction {
bindInfo.setAreaCode(areaCode);
bindInfo.setAreaAddress(areaAddress);
bindInfo.setOpenid(openid);
bindInfo.setEnOpenId(AesWxHelper.encode(openid));
bindInfo.setSex(gender);
bindInfo.setNation(nation);
bindInfo.setBirthday(birthday);

@ -131,13 +131,32 @@ public class HealthCardAction extends BaseAction {
}
}
/**
* 身份绑定-医共体敏感数据加密传输
*/
@Action("bindCardGmc")
public Result bindCardGmc(String enOpenId, @AesDecode String healthCardId, String address, String areaCode, String areaAddress, @AesDecode String tel, String sex, String name, String nation, String birthday, @AesDecode String idCardNo, String cardType, String enUnionId, String enGmcOpenId, String hospAppId) {
if (idCardNo == null || tel == null) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
return bindCard(false, false, enOpenId, healthCardId, address, areaCode, areaAddress, tel, sex, name, nation, birthday, idCardNo, cardType, enUnionId, enGmcOpenId);
}
/**
* [电子健康卡]身份绑定成人
*/
@Action("bindCard")
public Result bindCard(@AesDecode String openid, Boolean isEnableHC, String healthCardId, boolean isAreaCode, String address, String areaCode, String areaAddress, String tel, String sex, String name, String nation, String birthday, String idCardNo, String cardType, String enUnionId, String enGmcOpenId) {
log.info("[电子健康卡]身份绑定 openid={}, isEnableHC={} healthCardId={}, name={}, sex={}, nation={}, birthday={}, tel={}, address={}, areaCode={}, areaAddress={}, cardType={}, enUnionId={}, enGmcOpenId={}",
openid, isEnableHC, healthCardId, name, sex, nation, birthday, tel, address, areaCode, areaAddress, cardType, enUnionId, enGmcOpenId);
public Result bindCard(Boolean isEnableHC, boolean isAreaCode, String enOpenId, String healthCardId, String address, String areaCode, String areaAddress, String tel, String sex, String name, String nation, String birthday, String idCardNo, String cardType, String enUnionId, String enGmcOpenId) {
log.info("[电子健康卡]身份绑定 enOpenId={}, isEnableHC={} healthCardId={}, name={}, sex={}, nation={}, birthday={}, tel={}, address={}, areaCode={}, areaAddress={}, cardType={}, enUnionId={}, enGmcOpenId={}",
enOpenId, isEnableHC, healthCardId, name, sex, nation, birthday, tel, address, areaCode, areaAddress, cardType, enUnionId, enGmcOpenId);
if (enOpenId == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String openid = AesWxHelper.decode(enOpenId);
if (openid == null) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
if (tel == null || sex == null || birthday == null || name == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
@ -147,10 +166,6 @@ public class HealthCardAction extends BaseAction {
return Result.error(ResultEnum.PARAM_ADDRESS_ERROR);
}
if (openid == null) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
HCardTypeEnum cardTypeEnum = HCardTypeEnum.findByWxCode(cardType, HCardTypeEnum._01);
if (cardTypeEnum == null) {
return Result.error(ResultEnum.CARD_TYPE_NOT_FOUNT);
@ -188,9 +203,10 @@ public class HealthCardAction extends BaseAction {
info.setAreaCode(areaCode);
info.setAreaAddress(areaAddress);
//
info.setEnOpenId(enOpenId);
info.setEnUnionId(enUnionId);
info.setEnGmcOpenId(enGmcOpenId);
return new PatientService().bindCard(request, false, isAreaCode, info);
return new PatientService().bindCard(request, false, true, isAreaCode,true, info);
}

@ -1,6 +1,5 @@
package com.ynxbd.common.action;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.Patient;
@ -16,6 +15,7 @@ import com.ynxbd.common.helper.common.IDNumberHelper;
import com.ynxbd.common.helper.common.ValidHelper;
import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.service.GMCService;
import com.ynxbd.common.service.HCodeService;
import com.ynxbd.common.service.PatientService;
import com.ynxbd.wx.wxfactory.AesWxHelper;
@ -26,9 +26,7 @@ import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.ehcache.Cache;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.ArrayList;
/**
* @Author wsq
@ -151,7 +149,7 @@ public class HealthCodeAction extends BaseAction {
bindInfo.setEnUnionId(enUnionId);
bindInfo.setEnHospAppId(enHospAppId);
bindInfo.setEnGmcOpenId(enGmcOpenId);
return new PatientService().bindCard(request, false, isAreaCode, bindInfo);
return new PatientService().bindCard(request, false, true, isAreaCode, true, bindInfo);
}
@ -181,42 +179,50 @@ public class HealthCodeAction extends BaseAction {
return Result.error(ResultEnum.PARAM_TYPE_ERROR);
}
// 先注册,后修改-->先获取健康卡ID
JSONObject rspObj = HCodeService.registerHealthCard(false, hisPatientId, wechatCode, birthday, cardTypeEnum, address, null, sex, nation, name, idCardNo, tel);
if (rspObj == null) {
log.info("[电子健康卡]升级绑定失败, 响应内容为空");
return Result.error("[电子健康卡]升级绑定失败, 响应内容为空");
}
try {
// 先注册,后修改-->先获取健康卡ID
JSONObject rspObj = HCodeService.registerHealthCard(false, hisPatientId, wechatCode, birthday, cardTypeEnum, address, null, sex, nation, name, idCardNo, tel);
if (rspObj == null) {
log.info("[电子健康卡]升级绑定失败, 响应内容为空");
return Result.error("[电子健康卡]升级绑定失败, 响应内容为空");
}
String healthCardId = rspObj.getString("healthCardId");
if (healthCardId == null) {
// 响应处理
String errMsg = rspObj.getString("errMsg");
String resultCode = rspObj.getString("resultCode");
HealthCardRespCodeEnum healthCardRespCodeEnum = HealthCardRespCodeEnum.findEnumByResultCode(resultCode);
String healthCardId = rspObj.getString("healthCardId");
if (healthCardId == null) {
// 响应处理
String errMsg = rspObj.getString("errMsg");
String resultCode = rspObj.getString("resultCode");
HealthCardRespCodeEnum healthCardRespCodeEnum = HealthCardRespCodeEnum.findEnumByResultCode(resultCode);
log.info("[电子健康卡]升级绑定失败原因 resultCode={}, errMsg={}, statusMsg={}", resultCode, errMsg, healthCardRespCodeEnum.MESSAGE);
return Result.error(healthCardRespCodeEnum.MESSAGE);
}
Patient bindInfo = new Patient();
bindInfo.setOpenid(openid);
bindInfo.setPatientId(hisPatientId);
bindInfo.setEmpiId(epId);
bindInfo.setIdCardNo(idCardNo);
bindInfo.setHealthCardId(healthCardId);
bindInfo.setName(name);
bindInfo.setNation(nation);
bindInfo.setTel(tel);
bindInfo.setAddress(address);
log.info("[电子健康卡]升级绑定失败原因 resultCode={}, errMsg={}, statusMsg={}", resultCode, errMsg, healthCardRespCodeEnum.MESSAGE);
return Result.error(healthCardRespCodeEnum.MESSAGE);
}
boolean isUpdate = new PatientDao().updateInfo(bindInfo, id);
if (isUpdate) {
Patient bindInfo = new Patient();
bindInfo.setTel(tel);
bindInfo.setOpenid(openid);
bindInfo.setPatientId(hisPatientId);
bindInfo.setHisPatientId(hisPatientId);
bindInfo.setEmpiId(epId);
bindInfo.setIdCardNo(idCardNo);
bindInfo.setHealthCardId(healthCardId);
bindInfo.setName(name);
bindInfo.setNation(nation);
bindInfo.setId(id);
bindInfo.setAddress(address);
// 注意:检查后会补充数据,顺序不能在添加集合后
new GMCService().checkGmcPatient(bindInfo);
ArrayList<Patient> patients = new ArrayList<>();
patients.add(bindInfo);
new PatientService().updateBind(patients, bindInfo, healthCardId);
Cache<String, User> cache = WxCacheHelper.getUserCacheManager();
cache.remove(openid);
return Result.success();
} catch (Exception e) {
return Result.error(e);
}
return Result.error();
}

@ -330,7 +330,7 @@ public class PatientAction extends BaseAction {
bindInfo.setMotherName(mName);
bindInfo.setMotherTel(mTel);
bindInfo.setMotherIdCardNo(mIDCardNo);
return new PatientService().bind(request, false, true, bindInfo);
return new PatientService().bind(request, false, false, true, true, bindInfo);
}
@ -420,7 +420,7 @@ public class PatientAction extends BaseAction {
// http://127.0.0.1:8080/wx/patient/getGMCEmpiId?hisPatientId=5C881337931CDBBC8D38FACAE2D302D8
@Action("getGMCEmpiId")
public Result getGMCEmpiId(@AesDecode String hisPatientId) {
String empiId = new HisPatientDao().getGMCEmpiId(hisPatientId);
String empiId = new HisPatientDao().queryGMCEmpiId(hisPatientId);
if (ObjectUtils.isEmpty(empiId)) {
return Result.error(ResultEnum.DATA_NOT_FOUND);
}

@ -10,6 +10,7 @@ import lombok.ToString;
import org.apache.commons.lang3.ObjectUtils;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @Author wsq
@ -71,7 +72,7 @@ public class Patient implements Serializable {
private String uuid;
//
private String healthCardId;
// 证件类型,电子健康卡
// 证件类型:电子健康卡枚举
private String cardType;
// 区
private String county;
@ -105,6 +106,8 @@ public class Patient implements Serializable {
private String gmcUniqueId;
// 是否为医共体绑定[1:是]
private Integer gmcBindState;
// 检查时间
private LocalDateTime gmcCheckTime;
// HIS[BindingFlag:值为1时,说明患者尚未绑定或建档]
private String bindingFlag;

@ -261,6 +261,10 @@ public class DataBase {
isBreak = true;
if (java.time.LocalDateTime.class == valClazz && java.time.LocalDateTime.class != f.getType()) {
BeanUtils.setProperty(bean, f.getName(), rs.getTimestamp(i));
} else if (java.sql.Timestamp.class == valClazz && java.time.LocalDateTime.class == f.getType()) {
BeanUtils.setProperty(bean, f.getName(), rs.getTimestamp(i) == null ? null : rs.getTimestamp(i).toLocalDateTime());
} else {
BeanUtils.setProperty(bean, f.getName(), value);
}

@ -165,8 +165,17 @@ public class PatientDao {
return !dataList.isEmpty() ? dataList.get(0) : null;
}
// 根据id解绑
public boolean removePatientById(Integer id, String remark) {
String sql = "update patientBase set deletedState=1, deletedTime=now(), remark=? where id=?";
return DataBase.update(sql, ps -> {
ps.setString(1, remark);
ps.setLong(2, id);
}) > 0;
}
/**
* 健康卡解绑
* 解绑
*
* @param openid openid
* @param epId 医共体id|本院id
@ -175,9 +184,9 @@ public class PatientDao {
public boolean removePatient(String openid, String epId) {
String sql;
if (WeChatConfig.IS_ENABLE_GMC) {
sql = "update patientBase set updateTime=now(), age=null, deletedState=1 where openid=? and empiId=?";
sql = "update patientBase set deletedState=1, deletedTime=now() where openid=? and empiId=?";
} else {
sql = "update patientBase set updateTime=now(), age=null, deletedState=1 where openid=? and patientId=?";
sql = "update patientBase set deletedState=1, deletedTime=now() where openid=? and patientId=?";
}
return DataBase.update(sql, ps -> {
ps.setString(1, openid);
@ -235,13 +244,14 @@ public class PatientDao {
return false;
}
String sql = "update patientBase set deletedState=0, healthCardId=?, name=?, nation=?, tel=?, address=?, uuid=?, areaCode=?, areaAddress=?, patientId=?, empiId=?, gmcBindState=?, " +
String sql = "update patientBase set deletedState=0, updateTime=now(), healthCardId=?, name=?, nation=?, tel=?, address=?, uuid=?, areaCode=?, areaAddress=?, patientId=?, empiId=?, gmcBindState=?, gmcCheckTime=?, " +
" uniqueId=if(uniqueId is null or uniqueId = '', ?, uniqueId), " +
" gmcUniqueId=if(gmcUniqueId is null or gmcUniqueId = '', ?, gmcUniqueId) " +
" where id=? and openid=? and idCardNo=?";
bindInfo.setGmcBindState(WeChatConfig.IS_ENABLE_GMC ? 1 : 0);
bindInfo.setEmpiId(WeChatConfig.IS_ENABLE_GMC ? bindInfo.getEmpiId() : null);
bindInfo.setGmcCheckTime(WeChatConfig.IS_ENABLE_GMC ? bindInfo.getGmcCheckTime() : null);
return DataBase.update(sql, ps -> {
ps.setString(1, bindInfo.getHealthCardId());
@ -255,12 +265,13 @@ public class PatientDao {
ps.setString(9, bindInfo.getPatientId());
ps.setString(10, bindInfo.getEmpiId());
ps.setInt(11, bindInfo.getGmcBindState());
ps.setString(12, CodeHelper.get32UUID());
ps.setString(13, bindInfo.getGmcUniqueId());
ps.setObject(12, bindInfo.getGmcCheckTime());
ps.setString(13, CodeHelper.get32UUID());
ps.setString(14, bindInfo.getGmcUniqueId());
// 条件
ps.setInt(14, id);
ps.setString(15, bindInfo.getOpenid());
ps.setString(16, bindInfo.getIdCardNo());
ps.setInt(15, id);
ps.setString(16, bindInfo.getOpenid());
ps.setString(17, bindInfo.getIdCardNo());
}) > 0;
}
@ -283,8 +294,8 @@ public class PatientDao {
*/
public boolean insert(boolean isMyself, Patient bindData) {
bindData.setIsMyself(isMyself);
String sql = "insert into patientBase(bindDate, openid, patientId, hisTransNo, name, sex, idCardNo, tel, birthday, nation, healthCardId, age, uuid, fatherName, fatherTel, fatherIDCardNo, motherName, motherTel, motherIDCardNo, address, areaCode, areaAddress, isMyself, cardType, unionId, uniqueId, empiId, gmcUniqueId, gmcBindState) " +
" values(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
String sql = "insert into patientBase(bindDate, openid, patientId, hisTransNo, name, sex, idCardNo, tel, birthday, nation, healthCardId, age, uuid, fatherName, fatherTel, fatherIDCardNo, motherName, motherTel, motherIDCardNo, address, areaCode, areaAddress, isMyself, cardType, unionId, uniqueId, empiId, gmcUniqueId, gmcBindState, gmcCheckTime) " +
" values(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
return DataBase.insert(sql, ps -> {
setInsertPs(ps, bindData);
@ -299,8 +310,8 @@ public class PatientDao {
* @return bool
*/
public int insertBatch(List<Patient> dataList) {
String sql = "insert into patientBase(bindDate, openid, patientId, hisTransNo, name, sex, idCardNo, tel, birthday, nation, healthCardId, age, uuid, fatherName, fatherTel, fatherIDCardNo, motherName, motherTel, motherIDCardNo, address, areaCode, areaAddress, isMyself, cardType, unionId, uniqueId, empiId, gmcUniqueId, gmcBindState %s) " +
" values(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? %s)";
String sql = "insert into patientBase(bindDate, openid, patientId, hisTransNo, name, sex, idCardNo, tel, birthday, nation, healthCardId, age, uuid, fatherName, fatherTel, fatherIDCardNo, motherName, motherTel, motherIDCardNo, address, areaCode, areaAddress, isMyself, cardType, unionId, uniqueId, empiId, gmcUniqueId, gmcBindState, gmcCheckTime %s) " +
" values(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? %s)";
List<Patient> hasIdList = new ArrayList<>();
List<Patient> noneIdList = new ArrayList<>();
@ -322,7 +333,7 @@ public class PatientDao {
int hasIdRows = hasIdList.isEmpty() ? 0 : DataBase.insertBatch(String.format(sql, ",id", ",?"), ps -> {
for (Patient item : hasIdList) {
setInsertPs(ps, item);
ps.setInt(29, item.getId()); // 此处需注意修改
ps.setInt(30, item.getId()); // 此处需注意修改
ps.addBatch();
}
});
@ -333,6 +344,7 @@ public class PatientDao {
private void setInsertPs(PreparedStatement ps, Patient item) throws SQLException {
item.setGmcBindState(WeChatConfig.IS_ENABLE_GMC ? 1 : item.getGmcBindState() == null ? 0 : item.getGmcBindState());
item.setEmpiId(WeChatConfig.IS_ENABLE_GMC ? item.getEmpiId() : null);
item.setGmcCheckTime(WeChatConfig.IS_ENABLE_GMC ? item.getGmcCheckTime() : null);
HCardTypeEnum cardTypeEnum = item.getCardTypeEnum();
@ -366,6 +378,7 @@ public class PatientDao {
ps.setString(26, item.getEmpiId());
ps.setString(27, item.getGmcUniqueId());
ps.setObject(28, item.getGmcBindState(), Types.INTEGER);
ps.setObject(29, item.getGmcCheckTime());
}
@ -504,24 +517,17 @@ public class PatientDao {
return DataBase.select(sql, Patient.class, null);
}
public boolean removePatient(Integer id, String remark) {
String sql = "update patientBase set deletedState=1, remark=? where id=?";
return DataBase.update(sql, ps -> {
ps.setString(1, remark);
ps.setLong(2, id);
}) > 0;
}
public boolean updateGmcInfo(boolean hasCard, Integer id, String empiId) {
if (!hasCard) { // 无证绑定->标记为已删除
return removePatient(id, "无证绑定");
return removePatientById(id, "无证绑定");
}
if (ObjectUtils.isEmpty(empiId)) {
return false;
}
int gmcBindState = WeChatConfig.IS_ENABLE_GMC && WeChatConfig.IS_GMC_SERVER ? 1 : 0; // 医共体主服务器直接标识为1,其他医院的服务器同步时为0,后续使用时同步
String sql = "update patientBase set gmcBindState=?, empiId=? where id=?";
String sql = "update patientBase set gmcCheckTime=now(), gmcBindState=?, empiId=? where id=?";
return DataBase.update(sql, ps -> {
ps.setInt(1, gmcBindState);
ps.setString(2, empiId);
@ -531,7 +537,7 @@ public class PatientDao {
}
public boolean updateGmcBindState(String gmcUniqueId, Integer id, String empiId) {
String sql = "update patientBase set gmcBindState= 1, gmcUniqueId=? where id=? and empiId=?";
String sql = "update patientBase set gmcBindState= 1, gmcCheckTime=now(), gmcUniqueId=? where id=? and empiId=?";
return DataBase.update(sql, ps -> {
ps.setString(1, gmcUniqueId);
// 条件

@ -37,12 +37,14 @@ public class HisPatientDao {
String uuid = bindData.getUuid();
String idCardNo = bindData.getIdCardNo();
HCardTypeEnum cardTypeEnum = bindData.getCardTypeEnum();
// idCardNo = null 是儿童
String cardNo = idCardNo == null ? uuid : idCardNo;
params.put("CardType", idCardNo == null ? HCardTypeEnum.NO_CARD.HIS_CODE : (
cardTypeEnum.HIS_CODE == null ? HCardTypeEnum._01.HIS_CODE : cardTypeEnum.HIS_CODE
));
// 是否为无证绑定
boolean isNoCard = ObjectUtils.isEmpty(idCardNo);
String cardNo = isNoCard ? uuid : idCardNo; // 无证绑定传递uuid
params.put("CardType", isNoCard
? HCardTypeEnum.NO_CARD.HIS_CODE
: (cardTypeEnum == null || cardTypeEnum.HIS_CODE == null) ? HCardTypeEnum._01.HIS_CODE : cardTypeEnum.HIS_CODE
);
params.put("TransNo", UUID.randomUUID().toString().replace("-", ""));
params.put("IdCardNo", idCardNo);
params.put("CardNo", cardNo);
@ -89,6 +91,7 @@ public class HisPatientDao {
if (patientId.equals(cardNo)) { // 绑定失败返回卡号
throw new ServiceException(JsonResult.getMessage());
}
patient.setHisPatientId(patientId);
return patient;
}
@ -165,7 +168,7 @@ public class HisPatientDao {
*
* @return 患者
*/
public String getGMCEmpiId(String patientId) {
public String queryGMCEmpiId(String patientId) {
if (ObjectUtils.isEmpty(patientId)) {
return null;
}

@ -42,14 +42,6 @@ public class DateHelper {
}
public static LocalDateTime strToLocalDateTime(String date) {
try {
return LocalDateTime.parse(date, DateTimeFormatter.ofPattern(DateEnum.yyyy_MM_dd_HH_mm_ss.TYPE));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String DateTimeToString(Date date) {
if (date == null || "".equals(date.toString())) {

@ -0,0 +1,84 @@
package com.ynxbd.common.helper.common;
import lombok.extern.slf4j.Slf4j;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Slf4j
public class LocalDateHelper {
/**
* 字符串转LocalDateTime
*
* @param dateStr 字符串
* @return LocalDateTime
*/
public static LocalDateTime strToLocalDateTime(String dateStr) {
try {
return LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern(DateHelper.DateEnum.yyyy_MM_dd_HH_mm_ss.TYPE));
} catch (Exception e) {
log.error(e.getMessage());
}
return null;
}
/**
* [判断]当前时间 > 目标时间[minutes]分钟
*
* @param target 待比较时间
* @return 大于当前时间6分钟 ? true: false
*/
public static boolean isNowGreaterThanMinute(LocalDateTime target, int minutes) {
if (target == null) {
return false;
}
Duration diff = Duration.between(target, LocalDateTime.now());
return diff.toMillis() > (minutes * 60 * 1000L);
}
/**
* [判断]当前时间 < 目标时间[minutes]分钟
*/
public static boolean isNowLessThanMinute(LocalDateTime target, int minutes) {
if (target == null) {
return false;
}
Duration diff = Duration.between(LocalDateTime.now(), target);
return diff.toMillis() > (minutes * 60 * 1000L);
}
/**
* 减少时间
*
* @param target 目标时间
* @param minutes 减少分钟
*/
public static LocalDateTime minusMinutes(LocalDateTime target, int minutes) {
return target.minusMinutes(minutes);
}
/**
* 增加时间
*
* @param target 目标时间
* @param minutes 减少分钟
*/
public static LocalDateTime plusMinutes(LocalDateTime target, int minutes) {
return target.plusMinutes(minutes);
}
public static void main(String[] args) {
LocalDateTime target = LocalDateTime.parse("2026-06-19T17:10:00");
System.out.println(target);
boolean overNowMinute = isNowGreaterThanMinute(target, 6);
System.out.println(overNowMinute);
boolean overNowMinute2 = isNowLessThanMinute(target, 3);
System.out.println(overNowMinute2);
}
}

@ -1,225 +0,0 @@
//package com.ynxbd.common.helper.common;
//
//import com.alibaba.fastjson.JSON;
//import com.ynxbd.common.bean.sms.SmsTemplate;
//import com.ynxbd.common.config.EhcacheConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.ehcache.Cache;
//
//import java.util.Date;
//import java.util.Properties;
//
//@Slf4j
//public class SmsNewHelper {
// private SmsNewHelper() {
// }
//
// final private static String OK = "OK";
//
// private static String ACCESS_KEY_ID;
// private static String ACCESS_KEY_SECRET;
// private static String SIGN_NAME;
// // 缓存
// private static Cache<String, SmsTemplate> CACHE;
//
// static {
// Properties properties = FileHelper.readProperties("sms.properties");
// // 读取配置文件...\wx\web\WEB-INF\classes\sms.properties
// if (properties != null) {
// ACCESS_KEY_ID = FileHelper.propertiesGetString(properties, "sms.accessKeyId");
// ACCESS_KEY_SECRET = FileHelper.propertiesGetString(properties, "sms.accessKeySecret");
// SIGN_NAME = FileHelper.propertiesGetString(properties, "sms.signName");
// }
// createCache();
// }
//
// private synchronized static void createCache() {
// if (CACHE == null) {
// // 创建一个缓存实例(5分钟最大存活时间)
// CACHE = EhcacheConfig.createCacheTTL(String.class, SmsTemplate.class, "sms_cache", (60L * 5));
// }
// }
//
// /**
// * 使用AK&SK初始化账号Client
// *
// * @param accessKeyId accessKeyId
// * @param accessKeySecret accessKeySecret
// * @return Client
// */
// public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) {
// try {
// com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// // 您的AccessKey ID
// .setAccessKeyId(accessKeyId)
// // 您的AccessKey Secret
// .setAccessKeySecret(accessKeySecret);
// // 访问的域名
// config.endpoint = "dysmsapi.aliyuncs.com";
// return new com.aliyun.dysmsapi20170525.Client(config);
// } catch (Exception e) {
// e.printStackTrace();
// }
// return null;
// }
//
//
//
// public static boolean sendAli(String template, String tel, String signName, Object smsTemplate) {
// try {
// com.aliyun.dysmsapi20170525.Client client = createClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET);
// if (client == null) {
// return false;
// }
// com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
// .setPhoneNumbers(tel)
// .setSignName(signName)
// .setTemplateCode(template)
// .setTemplateParam(JSON.toJSONString(smsTemplate));
//
// com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
// // 复制代码运行请自行打印 API 的返回值
// com.aliyun.dysmsapi20170525.models.SendSmsResponse resp = client.sendSmsWithOptions(sendSmsRequest, runtime);
// if (resp == null) {
// return false;
// }
// com.aliyun.dysmsapi20170525.models.SendSmsResponseBody body = resp.body;
// if (body == null) {
// return false;
// }
//
// if (OK.equals(body.code) && OK.equals(body.message)) {
// return true;
// }
// log.error("[短信]发送失败:{}", body.message);
// } catch (Exception e) {
// e.printStackTrace();
// log.error("[短信]发送失败:{}", e.getMessage());
// }
// return false;
// }
//
//
// /**
// * 是否重复发送
// *
// * @param tel 储电话号码的集合
// * @return 验证码 | null = 发送异常
// */
// public static String isRepeat(String tel) {
// if (CACHE == null) {
// createCache();
// }
// if (CACHE != null) {
// SmsTemplate smsTemplate = CACHE.get(tel);
// if (smsTemplate == null) {
// return null;
// }
//
// Long countDown = smsTemplate.getCountDown();
// if (countDown == null) {
// return null;
// }
//
// countDown = new Date().getTime() - countDown; // 计算倒计时
//
// if (countDown < 60000) { // 60s内请求,返回重复提示
// countDown = ((60000 - countDown) / 1000);
// String message = "重复请求" + countDown + "s";
// log.info(message);
// return message;
// }
// CACHE.remove(tel); // 超过60s,如果还存在则移除
// }
// return null;
// }
//
//
// /**
// * 验证码验证
// *
// * @param phone 手机号码
// * @param code 验证码
// */
// public static boolean codeVerify(String phone, String code) {
// if (CACHE == null) {
// createCache();
// }
// if (CACHE == null) return false;
//
// SmsTemplate smsTemplate = CACHE.get(phone);
//
// if (smsTemplate == null) return false;
//
// return code.equals(smsTemplate.getCode());
// }
//
//
//
// /**
// * 通用-发送短信
// *
// * @param template 模板
// * @param tel 电话号码
// * @param smsObj 模板内容
// */
// public static boolean send(String template, String tel, Object smsObj) {
// return send(template, tel, null, smsObj);
// }
//
// /**
// * 通用-发送短信
// *
// * @param template 模板
// * @param tel 电话号码
// * @param signName 签名
// * @param smsObj 模板内容
// */
// public static boolean send(String template, String tel, String signName, Object smsObj) {
// boolean status = sendAli(template, tel, signName, smsObj);
// log.info("发送短信 tel={} {}", tel, status ? "成功" : "失败");
// return status;
// }
//
//
//
// /**
// * 发送短信验证码
// *
// * @param template 短信模板
// * @param tel 电话号码
// * @return 是否发送成功
// * @code code 验证码
// */
// public static boolean sendCode(String template, String tel, String code) {
// return sendCode(template, tel, null, code);
// }
//
// /**
// * 发送短信验证码
// *
// * @param template 短信模板
// * @param tel 电话号码
// * @param signName 签名
// * @return 是否发送成功
// * @code code 验证码
// */
// public static boolean sendCode(String template, String tel, String signName, String code) {
// SmsTemplate smsTemplate = new SmsTemplate();
// smsTemplate.setCode(code);
// smsTemplate.setTel(tel);
// smsTemplate.setCountDown(new Date().getTime());
//
// boolean status = send(template, tel, signName, smsTemplate);
//
// if (CACHE == null) {
// createCache();
// }
// if (status && CACHE != null) {
// CACHE.put(tel, smsTemplate); //添加缓存值
// return true;
// }
// return false;
// }
//
//}

@ -1,4 +0,0 @@
package com.ynxbd.common.helper.common;

@ -8,6 +8,7 @@ import com.ynxbd.common.dao.GMCUserDao;
import com.ynxbd.common.dao.PatientDao;
import com.ynxbd.common.dao.his.HisPatientDao;
import com.ynxbd.common.helper.common.JsonHelper;
import com.ynxbd.common.helper.common.LocalDateHelper;
import com.ynxbd.common.helper.http.OkHttpHelper;
import com.ynxbd.common.result.JsonResult;
import com.ynxbd.common.result.JsonResultEnum;
@ -19,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ -71,14 +73,20 @@ public class GMCService {
)).findFirst().orElse(null);
if (findDBItem == null) { // 需新增
item.setPatientId(null); // 清空本院患者id
item.setPatientId(null); // 清空主体医院的-本院患者id
item.setHisPatientId(null);
addList.add(item);
} else { // 比对数据
item.setId(findDBItem.getId());
item.setPatientId(findDBItem.getPatientId()); // 本院患者id->用于新增数据
item.setHisPatientId(findDBItem.getPatientId()); // 本院患者id->用于检查数据
if (!findDBItem.equalsPatient(item)) { // 数据不同->需修改本地数据
item.setId(findDBItem.getId());
item.setPatientId(findDBItem.getPatientId());
removeIds.add(findDBItem.getId());
addList.add(item);
} else {
item.setGmcCheckTime(findDBItem.getGmcCheckTime()); // 本院的检查时间
checkGmcPatient(item);
}
}
}
@ -92,17 +100,16 @@ public class GMCService {
Integer gmcBindState = item.getGmcBindState();
if (gmcBindState == null || gmcBindState == 0) { // 未与主体医院交互校验过
System.out.println("[医共体]向主体医院同步数据...");
System.out.println(JsonHelper.toJsonString(item));
item.setEnGmcOpenId(enGmcOpenId);
Patient patient = new GMCService().bindGmcServer(request, item);
if (patient == null) {
log.error("[医共体]同步用户数据,返回数据为空 id:{}", item.getId());
log.error("[医共体]同步用户数据失败,返回数据为空 id:{}", item.getId());
continue;
}
String empiId = patient.getEmpiId();
String gmcUniqueId = patient.getGmcUniqueId();
if (ObjectUtils.isEmpty(gmcUniqueId) || ObjectUtils.isEmpty(empiId)) {
log.error("[医共体]同步用户数据,返回唯一键为空 id:{}", item.getId());
log.error("[医共体]同步用户数据失败,返回唯一键为空 id:{}", item.getId());
continue;
}
if (!empiId.equals(item.getEmpiId())) {
@ -127,7 +134,7 @@ public class GMCService {
delRows = new PatientDao().delByIds(wxOpenId, removeIds);
}
int addRows = addItems(addList);
int addRows = addItems(addList); // 添加后会补充数据
long endTime = System.currentTimeMillis();
String takeTime = (endTime - begTime) + "ms"; // 耗时
@ -135,35 +142,83 @@ public class GMCService {
return gmcPatients;
}
/**
* 添加
*
* @param patients
* @return
*/
public int addItems(List<Patient> patients) {
if (patients.isEmpty()) {
return 0;
}
HisPatientDao hisPatientDao = new HisPatientDao();
int addRows = 0;
List<Patient> addList = new ArrayList<>();
if (!patients.isEmpty()) {
for (Patient item : patients) {
try {
if (ObjectUtils.isEmpty(item.getEmpiId())) {
log.info("[医共体-数据同步]本院绑定失败");
continue;
}
Patient bindInfo = hisPatientDao.bind(false, item);
if (bindInfo == null) {
log.info("[医共体-数据同步]本院绑定失败");
continue;
}
String patientId = bindInfo.getPatientId(); // 本院患者id
if (ObjectUtils.isEmpty(patientId)) {
continue;
}
item.setPatientId(patientId);
addList.add(item);
} catch (Exception e) {
log.error(e.getMessage());
for (Patient item : patients) {
try {
if (ObjectUtils.isEmpty(item.getEmpiId())) {
log.info("[医共体-数据同步]本院绑定失败");
continue;
}
Patient hisBindInfo = hisPatientDao.bind(false, item);
if (hisBindInfo == null) {
log.info("[医共体-数据同步]本院绑定失败");
continue;
}
String hisPatientId = hisBindInfo.getHisPatientId(); // 本院患者id
String empiId = hisBindInfo.getEmpiId(); // 医共体id
if (ObjectUtils.isEmpty(hisPatientId) || ObjectUtils.isEmpty(empiId)) {
continue;
}
item.setGmcCheckTime(LocalDateTime.now());
item.setPatientId(hisPatientId);
item.setHisPatientId(hisPatientId);
item.setEmpiId(empiId);
addList.add(item);
} catch (Exception e) {
log.error(e.getMessage());
}
addRows = new PatientDao().insertBatch(addList);
}
return addRows;
return new PatientDao().insertBatch(addList);
}
public final int CHECK_HOUR = 2; // 检查超过n小时
/**
* 检查医共体id是否失效
*
* @param patient 用户信息
*/
public void checkGmcPatient(Patient patient) {
if (!WeChatConfig.IS_ENABLE_GMC) { // 不是医共体,无需检查
return;
}
if (patient == null || ObjectUtils.isEmpty(patient.getIdCardNo()) || HCardTypeEnum.NO_CARD.WX_CODE.equals(patient.getCardType())) { // 为空 || 无证件号 || 无证
return;
}
LocalDateTime gmcCheckTime = patient.getGmcCheckTime(); // 数据检查时间
boolean isNeedCheck = ObjectUtils.isEmpty(patient.getEmpiId()) || gmcCheckTime == null || LocalDateHelper.isNowGreaterThanMinute(gmcCheckTime, 60 * CHECK_HOUR); // 标记时间超过n小时
if (!isNeedCheck) { // 无需检查
return;
}
String hisPatientId = patient.getHisPatientId(); // 本院id
patient.setGmcCheckTime(LocalDateTime.now()); // 记录检查时间
String newEmpiId = new HisPatientDao().queryGMCEmpiId(hisPatientId);
if (ObjectUtils.isEmpty(newEmpiId)) { // HIS返回医共体id为空==>需要绑定数据
log.warn("[医共体ID检查]id已失效 hisPatientId={}", hisPatientId);
new PatientService().bindCard(null, false, false, false, false, patient); // 检查仅请求本院
} else { // 补充医共体id数据
log.warn("[医共体ID检查]补充医共体ID数据 hisPatientId={}, newEmpiId={}", hisPatientId, newEmpiId);
patient.setEmpiId(newEmpiId);
new PatientDao().updateGmcInfo(true, patient.getId(), newEmpiId);
}
}
/**
@ -173,9 +228,11 @@ public class GMCService {
* @param bindInfo 绑定信息
*/
public Patient bindGmcServer(HttpServletRequest request, Patient bindInfo) throws ServiceException {
String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 只有子服务器有主服务器的openId
String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 认证主体的openid[县医院openid]
String gmcOpenId = AesWxHelper.decode(enGmcOpenId);
String enOpenId = bindInfo.getEnOpenId(); // 本院openid
log.info("[医共体绑定-转发]enGmcOpenId={}, gmcOpenId={}", enGmcOpenId, gmcOpenId);
if (ObjectUtils.isEmpty(gmcOpenId)) {
throw new ServiceException("医共体非主体公众号ID参数异常");
@ -192,21 +249,21 @@ public class GMCService {
}
String finalAreaCode = areaCode;
JsonResult jsonResult = postFormGMC(request, "/healthCode/bind", params -> {
params.put("isAreaCode", false);
params.put("isFace", false);
params.put("isHealthCard", false);
JsonResult jsonResult = postFormGMC(request, "/health_card/bindCardGmc", params -> {
params.put("enOpenId", enGmcOpenId); // 主服务器的openId
params.put("healthCardId", AesWxHelper.encode(bindInfo.getHealthCardId()));
params.put("address", bindInfo.getAddress());
params.put("areaCode", finalAreaCode);
params.put("areaAddress", bindInfo.getAreaAddress());
params.put("tel", bindInfo.getTel());
params.put("tel", AesWxHelper.encode(bindInfo.getTel()));
params.put("sex", bindInfo.getSex());
params.put("name", bindInfo.getName());
params.put("nation", bindInfo.getNation());
params.put("birthday", bindInfo.getBirthday());
params.put("idCardNo", bindInfo.getIdCardNo());
params.put("enOpenId", enGmcOpenId); // 主服务器的openId
params.put("idCardNo", AesWxHelper.encode(bindInfo.getIdCardNo()));
params.put("enGmcOpenId", enGmcOpenId); // 主服务器的openId
params.put("enUnionId", bindInfo.getEnUnionId());
params.put("hospAppId", WeChatConfig.APP_ID);
}, null);
@ -220,15 +277,15 @@ public class GMCService {
}
String gmcUniqueId = resp.getString("gmcUniqueId");
String enPatientId = resp.getString("enPatientId");
String enEmpiId = resp.getString("enEmpiId");
String enOpenId = resp.getString("enOpenId");
if (ObjectUtils.isEmpty(gmcUniqueId) || ObjectUtils.isEmpty(enPatientId) || ObjectUtils.isEmpty(enOpenId) || ObjectUtils.isEmpty(enEmpiId)) {
String enEmpiId = resp.getString("enEmpiId"); // 医共体id
String respEnGmcOpenId = resp.getString("enGmcOpenId"); // 认证主体医院openid
if (ObjectUtils.isEmpty(gmcUniqueId) || ObjectUtils.isEmpty(respEnGmcOpenId) || ObjectUtils.isEmpty(enEmpiId)) {
log.error("[医共体]主体绑定-响应数据参数缺失");
return null;
}
String patientId = AesWxHelper.decode(enPatientId);
if (ObjectUtils.isEmpty(patientId)) {
log.error("[医共体]主体绑定-数据enPatientId解密失败");
if (!respEnGmcOpenId.equals(enGmcOpenId)) {
log.error("[医共体]主体绑定-主体医院响应数据和绑定数据不一致");
return null;
}
@ -239,9 +296,9 @@ public class GMCService {
}
Patient patient = new Patient();
patient.setPatientId(patientId);
patient.setEnPatientId(enPatientId);
patient.setEnOpenId(enOpenId);
patient.setEnGmcOpenId(enGmcOpenId); // 主体医院openid
patient.setEnOpenId(enOpenId); // 本院openid
patient.setGmcUniqueId(gmcUniqueId);
patient.setEnEmpiId(enEmpiId);
patient.setEmpiId(empiId);

@ -132,31 +132,31 @@ public class HCodeService {
* @param patientId 患者ID
* @param qrCodeText 标识IDhealthCardId = qrCodeText
*/
public JSONObject bindCardRelation(Boolean isMiniApp, String patientId, String qrCodeText) {
public boolean bindCardRelation(Boolean isMiniApp, String patientId, String qrCodeText) {
try {
if (!HealthCardConfig.IS_UPLOAD_DATA) {
return null;
if (!HealthCardConfig.IS_UPLOAD_DATA) { // 阻止上传数据时->禁止绑定关系
return false;
}
if (patientId == null || ObjectUtils.isEmpty(qrCodeText)) {
log.info("[电子健康卡]绑定健康卡和医院关系-参数缺失 patientId={}, qrCodeText={}", patientId, qrCodeText);
return null;
return false;
}
CommonIn commonIn = HealthCardConfig.createCommonIn(isMiniApp, null);
if (commonIn == null) {
return null;
return false;
}
JSONObject resultJson = HealthCardConfig.createHealthCardService().bindCardRelation(commonIn, patientId, qrCodeText);
HealthCardConfig.HCardResult result = new HealthCardConfig.HCardResult(resultJson);
if (!result.isOk) {
log.info("[电子健康卡]绑定健康卡和医院关系-失败: {}", result.getJsonCommon());
return null;
return false;
}
return result.getRsp();
return true;
} catch (Exception e) {
ErrorHelper.println(e);
}
return null;
return false;
}

@ -4,6 +4,7 @@ import com.ynxbd.common.bean.GMCUser;
import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.User;
import com.ynxbd.common.bean.enums.HCardTypeEnum;
import com.ynxbd.common.config.HealthCardConfig;
import com.ynxbd.common.dao.PatientDao;
import com.ynxbd.common.dao.his.HisPatientDao;
import com.ynxbd.common.helper.common.*;
@ -68,6 +69,37 @@ public class PatientService {
return patients;
}
/**
* 绑定信息更新
*
* @param patients 患者集
* @param bindInfo 新信息
* @param healthCardId 健康卡id
*/
public void updateBind(List<Patient> patients, Patient bindInfo, String healthCardId) throws ServiceException {
HCodeService hCodeService = new HCodeService();
PatientDao patientDao = new PatientDao();
String dbHisPatientId;
for (Patient patientItem : patients) {
dbHisPatientId = patientItem.getPatientId();
// 上传健康卡数据 && 本地健康卡id为空 && 传入的健康卡id不为空
if (HealthCardConfig.IS_UPLOAD_DATA && ObjectUtils.isEmpty(patientItem.getHealthCardId()) && !ObjectUtils.isEmpty(healthCardId)) {
if (hCodeService.bindCardRelation(false, dbHisPatientId, healthCardId)) { // 绑定患者和院内关系
log.error("[电子健康卡]绑定患者和医院关系失败 hisPatientId={}", dbHisPatientId);
} else {
patientItem.setHealthCardId(healthCardId);
}
}
if (!patientDao.updateInfo(bindInfo, patientItem.getId())) {
log.info("[患者]更新失败 hisPatientId={}", dbHisPatientId);
throw new ServiceException(ResultEnum.PATIENT_UPDATE_ERROR);
}
}
}
// public List<Patient> queryGMCPatientList(String enUnionId, String openid, String unionId, boolean isEnPid) {
// // 在查询时完成数据同步
// if (!WeChatConfig.IS_GMC_SERVER) { // 不为医共体主体=>查询医共体患者数据
@ -86,14 +118,17 @@ public class PatientService {
}
return new GMCService().syncPatientData(request, openId, gmcUser.getGmcOpenId(), gmcUser.getGmcUnionId());
}
List<Patient> dbPatients = new PatientDao().selectListByToken(openId, unionId);
GMCService gmcService = new GMCService();
List<Patient> patients = new ArrayList<>();
for (Patient item : dbPatients) {
String patientId = item.getPatientId();
item.setHisPatientId(patientId); // 本院患者id
if (WeChatConfig.IS_ENABLE_GMC) {
gmcService.checkGmcPatient(item); // 检查后返回医共体id
String empiId = item.getEmpiId();
if (ObjectUtils.isEmpty(empiId)) { // 医共体开启时,如果没有id就不返回该信息
continue;
@ -109,56 +144,50 @@ public class PatientService {
return patients;
}
/**
* [有证绑定]
*
* @param request request
* @param isMyself 是否为本人支付宝使用
* @param isGmcBind 是否请求医共体主体
* @param isAreaCode 是否传递地区编码
* @param isBindSize 是否限制绑定数量同步检查数据时不限制
* @param bindInfo 绑定信息
*/
public Result bindCard(HttpServletRequest request, boolean isMyself, boolean isAreaCode, Patient bindInfo) {
public Result bindCard(HttpServletRequest request, boolean isMyself, boolean isGmcBind, boolean isAreaCode, boolean isBindSize, Patient bindInfo) {
bindInfo.clearGuardianData();
return bind(request, isMyself, isAreaCode, bindInfo);
return bind(request, isMyself, isGmcBind, isAreaCode, isBindSize, bindInfo);
}
private void updateBind(List<Patient> patients, Patient bindInfo, String healthCardId) throws ServiceException {
for (Patient patientItem : patients) {
String dbPatientId = patientItem.getPatientId();
if (healthCardId != null && new HCodeService().bindCardRelation(false, dbPatientId, healthCardId) == null) { // 绑定患者和院内关系
log.info("[电子健康卡]绑定患者和医院关系失败");
}
String hcId = patientItem.getHealthCardId();
if (!ObjectUtils.isEmpty(hcId)) {
healthCardId = hcId;
}
if (!new PatientDao().updateInfo(bindInfo, patientItem.getId())) {
log.info("[患者]更新失败 patientId={}", dbPatientId);
throw new ServiceException(ResultEnum.PATIENT_UPDATE_ERROR);
}
}
}
/**
* [绑定]
*
* @param isMyself 是否为自己
* @param isAreaCode 是否传递行政区编码
* @param bindInfo 绑定数据
* @param request request
* @param isMyself 是否为自己绑定
* @param isGmcBind 可使用gmc绑定防止支付宝和无证绑定调用
* @param isAreaCode 是否传递区域编码
* @param bindInfo 绑定信息
*/
public Result bind(HttpServletRequest request, boolean isMyself, boolean isAreaCode, Patient bindInfo) {
public Result bind(HttpServletRequest request, boolean isMyself, boolean isGmcBind, boolean isAreaCode, boolean isBindSize, Patient bindInfo) {
if (bindInfo == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String openid = bindInfo.getOpenid();
if (WeChatConfig.IS_ENABLE_GMC && !WeChatConfig.IS_GMC_SERVER) { // 开启医共体 && 不是医共体主体
if (isGmcBind && WeChatConfig.IS_ENABLE_GMC && !WeChatConfig.IS_GMC_SERVER) { // 运行使用医共体绑定 && 开启医共体 && 不是医共体主体
try {
Patient patient = new GMCService().bindGmcServer(request, bindInfo);
if (patient == null) {
return Result.error("[医共体]绑定返回数据为空");
return Result.error("[医共体]主体绑定响应数据为空");
}
WxCacheHelper.removeUser(openid);
Map<String, Object> map = new HashMap<>();
map.put("gmcUniqueId", patient.getGmcUniqueId());
map.put("enOpenId", AesWxHelper.encode(openid));
map.put("enOpenId", patient.getEnOpenId());
map.put("enGmcOpenId", patient.getEnGmcOpenId());
map.put("enEmpiId", patient.getEnEmpiId());
return Result.success(map);
} catch (Exception e) {
ErrorHelper.println(e);
@ -180,7 +209,7 @@ public class PatientService {
}
PatientDao patientDao = new PatientDao();
List<Patient> patients = patientDao.selectListByOpenid(openid);
if (patients.size() > 5) {
if (isBindSize && patients.size() > 5) {
log.info("[患者]绑定患者数超过5人 openid={}", openid);
return Result.error(ResultEnum.PATIENT_BIND_EXCEEDS_5); // 绑定人数超过5人
}
@ -189,6 +218,7 @@ public class PatientService {
try {
hisPatient = new HisPatientDao().bind(isAreaCode, bindInfo);
} catch (ServiceException e) {
System.out.println("异常");
return Result.error(e);
}
@ -197,7 +227,7 @@ public class PatientService {
}
String empiId = hisPatient.getEmpiId(); // 医共体ID
String patientId = hisPatient.getPatientId();
String hisPatientId = hisPatient.getHisPatientId(); // 本院患者id
String hisTransNo = hisPatient.getHisTransNo();
if (WeChatConfig.IS_ENABLE_GMC && ObjectUtils.isEmpty(empiId)) {
@ -205,32 +235,32 @@ public class PatientService {
}
bindInfo.setEmpiId(empiId);
bindInfo.setPatientId(patientId);
bindInfo.setPatientId(hisPatientId);
bindInfo.setHisTransNo(hisTransNo);
try {
List<Patient> dbPatients = patientDao.selectByOpenIdAndCardNo(openid, idCardNo);
if (dbPatients.isEmpty()) { // 数据库没有-->添加
log.info("[用户身份绑定]添加 name={}, patientId={}, empiId={}", name, patientId, empiId);
log.info("[用户身份绑定]添加 name={}, patientId={}, empiId={}", name, hisPatientId, empiId);
bindInfo.setGmcBindState(1);
if (bindInfo.getEnUnionId() != null) {
bindInfo.setUnionId(AesWxHelper.decode(bindInfo.getEnUnionId()));
}
if (!patientDao.insert(isMyself, bindInfo)) {
log.info("[用户身份绑定]添加患者失败 name={}, patientId={}, empiId={}", name, patientId, empiId);
log.info("[用户身份绑定]添加患者失败 name={}, patientId={}, empiId={}", name, hisPatientId, empiId);
return Result.error(ResultEnum.PATIENT_ADD_ERROR);
}
} else {
log.info("[患者]更新 isMyself={}, patientId={}, name={}, empiId={}, healthCardId={}", isMyself, patientId, name, empiId, healthCardId);
log.info("[患者]更新 isMyself={}, patientId={}, name={}, empiId={}, healthCardId={}", isMyself, hisPatientId, name, empiId, healthCardId);
if (isMyself) {
if (!patientDao.updateMyself(bindInfo)) {
log.info("[患者]自身信息更新失败 patientId={}, empiId={}", patientId, empiId);
log.info("[患者]自身信息更新失败 patientId={}, empiId={}", hisPatientId, empiId);
return Result.error(ResultEnum.PATIENT_UPDATE_ERROR);
}
} else {
List<Patient> pIdEqualsPatients = dbPatients.stream().filter(o -> o.getPatientId().equals(hisPatient.getPatientId())).collect(Collectors.toList());
if (pIdEqualsPatients.isEmpty()) { // 患者ID相同的人数不为0
List<Patient> pIdEqualsPatients = dbPatients.stream().filter(o -> o.getPatientId().equals(hisPatientId)).collect(Collectors.toList());
if (pIdEqualsPatients.isEmpty()) { // 不存在HIS患者id相同的数据
updateBind(dbPatients, bindInfo, healthCardId);
} else {
updateBind(pIdEqualsPatients, bindInfo, healthCardId);
@ -243,9 +273,11 @@ public class PatientService {
WxCacheHelper.removeUser(openid);
Map<String, Object> map = new HashMap<>();
String enGmcOpenId = AesWxHelper.encode(openid); // 主体医院
map.put("enOpenId", enGmcOpenId); // 本院openid
map.put("enGmcOpenId", enGmcOpenId); // 认证主体医院openid
map.put("gmcUniqueId", bindInfo.getGmcUniqueId());
map.put("enOpenId", AesWxHelper.encode(openid));
map.put("enPatientId", AesWxHelper.encode(patientId));
if (!ObjectUtils.isEmpty(empiId)) {
map.put("enEmpiId", AesWxHelper.encode(empiId));
}
@ -293,9 +325,9 @@ public class PatientService {
return Result.success();
}
public Result removePatient(String openid, String patientId, String idCardNo) {
boolean isRemove = new PatientDao().removePatient(openid, patientId);
log.info("[患者解绑]{} patientId={}, idCardNo={}", (isRemove ? "成功" : "失败"), patientId, ParamHelper.hideIdCardNo(idCardNo));
public Result removePatient(String openid, String epId, String idCardNo) {
boolean isRemove = new PatientDao().removePatient(openid, epId);
log.info("[患者解绑]{} patientId={}, idCardNo={}", (isRemove ? "成功" : "失败"), epId, ParamHelper.hideIdCardNo(idCardNo));
if (!isRemove) {
return Result.error();
}
@ -305,7 +337,7 @@ public class PatientService {
}
/**
* [绑定本人]
* [绑定本人]主要用于支付宝
*/
public Result bindMyself(HttpServletRequest request, boolean isVerifyCode, String tel, String smsCode, Patient bindInfo) {
String openid = bindInfo.getOpenid();
@ -318,7 +350,7 @@ public class PatientService {
String address = bindInfo.getAddress();
log.info("[身份绑定] openid={}, name={}, address={}, areaCode={}, nation={}, sex={}, birthday={}", openid, name, address, areaCode, nation, sex, birthday);
if (bindInfo.getOpenid() == null || sex == null || birthday == null || name == null || nation == null) {
if (openid == null || sex == null || birthday == null || name == null || nation == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
@ -363,7 +395,7 @@ public class PatientService {
bindInfo.setHealthCardId(null);
bindInfo.setUuid(UUID.randomUUID().toString().replace("-", "")); // 儿童身份证代码
return bindCard(request, true, true, bindInfo);
return bindCard(request, true, false, true, true, bindInfo);
}
@ -480,9 +512,9 @@ public class PatientService {
boolean hasCard = !HCardTypeEnum.NO_CARD.WX_CODE.equals(patient.getCardType()) && !ObjectUtils.isEmpty(patient.getIdCardNo());
if (hasCard) {
empiId = hisPatientDao.getGMCEmpiId(patientId); // 医共体患者id
empiId = hisPatientDao.queryGMCEmpiId(patientId); // 医共体患者id
if (ObjectUtils.isEmpty(empiId)) {
patientDao.removePatient(id, "医共体");
patientDao.removePatientById(id, "医共体");
log.warn("[医共体id]查询失败 patientId={}", patientId);
continue;
}

Loading…
Cancel
Save