|
|
|
|
@ -1,25 +1,28 @@ |
|
|
|
|
package com.ynxbd.common.service; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
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.dao.PatientDao; |
|
|
|
|
import com.ynxbd.common.dao.his.HisPatientDao; |
|
|
|
|
import com.ynxbd.common.helper.common.DateHelper; |
|
|
|
|
import com.ynxbd.common.helper.common.ParamHelper; |
|
|
|
|
import com.ynxbd.common.helper.common.SmsHelper; |
|
|
|
|
import com.ynxbd.common.helper.common.ValidHelper; |
|
|
|
|
import com.ynxbd.common.helper.common.*; |
|
|
|
|
import com.ynxbd.common.result.JsonResult; |
|
|
|
|
import com.ynxbd.common.result.Result; |
|
|
|
|
import com.ynxbd.common.result.ResultEnum; |
|
|
|
|
import com.ynxbd.common.result.ServiceException; |
|
|
|
|
import com.ynxbd.wx.config.WeChatConfig; |
|
|
|
|
import com.ynxbd.wx.utils.DesEncryptHelper; |
|
|
|
|
import com.ynxbd.wx.wxfactory.AesWxHelper; |
|
|
|
|
import com.ynxbd.wx.wxfactory.WxAuthHelper; |
|
|
|
|
import com.ynxbd.wx.wxfactory.WxCacheHelper; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -117,8 +120,82 @@ public class PatientService { |
|
|
|
|
/** |
|
|
|
|
* [有证绑定] |
|
|
|
|
*/ |
|
|
|
|
public Result bindCard(boolean isMyself, boolean isAreaCode, String healthCardId, String openid, String name, String sex, String idCardNo, HCardTypeEnum cardTypeEnum, String tel, String birthday, String nation, String uuid, String address, String areaCode, String areaAddress) { |
|
|
|
|
return bind(isMyself, isAreaCode, healthCardId, openid, name, sex, idCardNo, cardTypeEnum, tel, birthday, nation, uuid, address, areaCode, areaAddress, null, null, null, null, null, null); |
|
|
|
|
public Result bindCard(HttpServletRequest request, boolean isMyself, boolean isAreaCode, Patient bindInfo) { |
|
|
|
|
bindInfo.clearGuardianData(); |
|
|
|
|
return bind(request, isMyself, isAreaCode, bindInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Patient gmcServerBind(HttpServletRequest request, Patient bindInfo) throws ServiceException { |
|
|
|
|
if (!WeChatConfig.IS_ENABLE_GMC) { // 未医共体开关
|
|
|
|
|
return bindInfo; |
|
|
|
|
} |
|
|
|
|
String openid = bindInfo.getOpenid(); |
|
|
|
|
String hospAppId = AesWxHelper.decode(bindInfo.getEnHospAppId()); |
|
|
|
|
if (ObjectUtils.isEmpty(hospAppId)) { |
|
|
|
|
throw new ServiceException("医共体子公众号id参数错误"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String gmcUniqueId; |
|
|
|
|
if (WeChatConfig.IS_GMC_SERVER) { // 是医共体主服务器
|
|
|
|
|
if (!WeChatConfig.APP_ID.equals(hospAppId)) { // 不为自身AppId
|
|
|
|
|
bindInfo.setHospAppId(hospAppId); // 需存的数据
|
|
|
|
|
} |
|
|
|
|
bindInfo.setGmcUniqueId(CodeHelper.get32UUID()); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
String enGmcOpenId = bindInfo.getEnGmcOpenId(); // 只有子公众号有
|
|
|
|
|
String gmcOpenId = AesWxHelper.decode(enGmcOpenId); |
|
|
|
|
|
|
|
|
|
log.info("[转发]enGmcOpenId={}, gmcOpenId={}", enGmcOpenId, gmcOpenId); |
|
|
|
|
if (ObjectUtils.isEmpty(gmcOpenId)) { |
|
|
|
|
throw new ServiceException("医共体非主体公众号ID参数异常"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JsonResult jsonResult = WxAuthHelper.postFormGMC(request, "/healthCode/bind", params -> { |
|
|
|
|
params.put("isAreaCode", false); |
|
|
|
|
params.put("isFace", false); |
|
|
|
|
params.put("isHealthCard", false); |
|
|
|
|
|
|
|
|
|
params.put("openid", gmcOpenId); // 主体的openid
|
|
|
|
|
params.put("address", bindInfo.getAddress()); |
|
|
|
|
params.put("areaCode", bindInfo.getAreaCode()); |
|
|
|
|
params.put("areaAddress", bindInfo.getAreaAddress()); |
|
|
|
|
params.put("tel", 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); |
|
|
|
|
params.put("enUnionId", bindInfo.getEnUnionId()); |
|
|
|
|
params.put("enGmcOpenId", enGmcOpenId); |
|
|
|
|
params.put("enHospAppId", bindInfo.getEnHospAppId()); |
|
|
|
|
}, null); |
|
|
|
|
if (!jsonResult.success()) { |
|
|
|
|
throw new ServiceException(jsonResult.getMessage()); |
|
|
|
|
} |
|
|
|
|
log.info("[绑定转发] resp={}", JsonHelper.toJsonString(jsonResult)); |
|
|
|
|
|
|
|
|
|
JSONObject dataJson = jsonResult.dataMapGetNodeToJsonObj(); |
|
|
|
|
gmcUniqueId = dataJson.getString("gmcUniqueId"); |
|
|
|
|
if (ObjectUtils.isEmpty(gmcUniqueId)) { |
|
|
|
|
throw new ServiceException("医共体返回唯一id为空"); |
|
|
|
|
} |
|
|
|
|
bindInfo.setGmcUniqueId(gmcUniqueId); |
|
|
|
|
if (!enGmcOpenId.equals(dataJson.getString("enOpenId"))) { |
|
|
|
|
throw new ServiceException("医共体主体openId不匹配"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GMCUser findGMCUser = new GMCUserService().queryInfoByOpenId(openid); |
|
|
|
|
if (findGMCUser == null) { |
|
|
|
|
boolean isOK = new GMCUserService().addInfo(openid, gmcOpenId, bindInfo.getUnionId(), gmcUniqueId); |
|
|
|
|
if (!isOK) { |
|
|
|
|
log.error("[医共体关系]添加失败 openid={}, gmcOpenId={}, uuid={}", openid, gmcOpenId, gmcUniqueId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return bindInfo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -126,27 +203,26 @@ public class PatientService { |
|
|
|
|
* |
|
|
|
|
* @param isMyself 是否为自己 |
|
|
|
|
* @param isAreaCode 是否传递行政区编码 |
|
|
|
|
* @param healthCardId 健康卡id |
|
|
|
|
* @param openid openid |
|
|
|
|
* @param name 姓名 |
|
|
|
|
* @param sex 性别 |
|
|
|
|
* @param idCardNo 证件号码 |
|
|
|
|
* @param tel 电话号码 |
|
|
|
|
* @param address 地址 |
|
|
|
|
* @param birthday 出生日期 |
|
|
|
|
* @param nation 名字 |
|
|
|
|
* @param areaCode 行政区编码 |
|
|
|
|
* @param uuid uuid 随机编码 |
|
|
|
|
* @param fName 父姓名 |
|
|
|
|
* @param fTel 父电话 |
|
|
|
|
* @param fIDCardNo 父证件号码 |
|
|
|
|
* @param mName 母姓名 |
|
|
|
|
* @param mTel 母电话 |
|
|
|
|
* @param mIDCardNo 母身份证号码 |
|
|
|
|
* @param bindInfo 绑定数据 |
|
|
|
|
*/ |
|
|
|
|
public Result bind(boolean isMyself, boolean isAreaCode, String healthCardId, String openid, String name, String sex, String idCardNo, HCardTypeEnum cardTypeEnum, String tel, String birthday, String nation, String uuid, String address, String areaCode, String areaAddress, String fName, String fTel, String fIDCardNo, String mName, String mTel, String mIDCardNo) { |
|
|
|
|
log.info("[患者]身份绑定 name={}, address={}, areaCode={}, areaAddress={}, nation={}, sex={}, birthday={}, tel={}", name, address, areaCode, areaAddress, nation, sex, birthday, tel); |
|
|
|
|
if (openid == null || sex == null || birthday == null || name == null) { |
|
|
|
|
public Result bind(HttpServletRequest request, boolean isMyself, boolean isAreaCode, Patient bindInfo) { |
|
|
|
|
if (bindInfo == null) { |
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
bindInfo = gmcServerBind(request, bindInfo); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
ErrorHelper.println(e); |
|
|
|
|
return Result.error(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.info("[患者]身份绑定 bindInfo={}", JsonHelper.toJsonString(bindInfo)); |
|
|
|
|
String openid = bindInfo.getOpenid(); |
|
|
|
|
String name = bindInfo.getName(); |
|
|
|
|
String idCardNo = bindInfo.getIdCardNo(); |
|
|
|
|
String healthCardId = bindInfo.getHealthCardId(); |
|
|
|
|
|
|
|
|
|
if (openid == null || bindInfo.getSex() == null || bindInfo.getBirthday() == null || bindInfo.getName() == null) { |
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT); |
|
|
|
|
} |
|
|
|
|
PatientDao patientDao = new PatientDao(); |
|
|
|
|
@ -159,7 +235,7 @@ public class PatientService { |
|
|
|
|
|
|
|
|
|
Patient hisPatient; |
|
|
|
|
try { |
|
|
|
|
hisPatient = new HisPatientDao().bind(isAreaCode, name, sex, idCardNo, cardTypeEnum, tel, address, birthday, nation, areaCode, uuid, fName, fTel, fIDCardNo, mName, mTel, mIDCardNo); |
|
|
|
|
hisPatient = new HisPatientDao().bind(isAreaCode, bindInfo); |
|
|
|
|
} catch (ServiceException e) { |
|
|
|
|
return Result.error(e); |
|
|
|
|
} |
|
|
|
|
@ -169,16 +245,28 @@ public class PatientService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String patientId = hisPatient.getPatientId(); |
|
|
|
|
String hisTransNo = hisPatient.getHisTransNo(); |
|
|
|
|
String gmcHisPatientId = null; // HIS医共体患者ID
|
|
|
|
|
|
|
|
|
|
bindInfo.setPatientId(patientId); |
|
|
|
|
bindInfo.setHisTransNo(hisTransNo); |
|
|
|
|
bindInfo.setGmcHisPatientId(gmcHisPatientId); |
|
|
|
|
|
|
|
|
|
// 判断是否已有数据
|
|
|
|
|
Patient patient = patientDao.selectByIdCardNo(openid, idCardNo); |
|
|
|
|
if (patient == null) { // 数据库没有-->添加
|
|
|
|
|
log.info("[患者]添加 name={}, address={}, areaCode={}, healthCardId={}, nation={}, sex={}, birthday={}, tel={}", name, address, areaCode, healthCardId, nation, sex, birthday, tel); |
|
|
|
|
if (!patientDao.insert(isMyself, healthCardId, openid, patientId, hisPatient.getHisTransNo(), name, sex, idCardNo, cardTypeEnum, birthday, null, nation, tel, uuid, address, areaCode, areaAddress, fName, fTel, fIDCardNo, mName, mTel, mIDCardNo)) { |
|
|
|
|
log.info("[身份绑定]添加患者失败"); |
|
|
|
|
log.info("[用户身份绑定]添加 name={}, patientId={}", name, patientId); |
|
|
|
|
bindInfo.setGmcBindState(1); |
|
|
|
|
if (bindInfo.getEnUnionId() != null) { |
|
|
|
|
bindInfo.setUnionId(AesWxHelper.decode(bindInfo.getEnUnionId())); |
|
|
|
|
} |
|
|
|
|
if (!patientDao.insert(isMyself, bindInfo)) { |
|
|
|
|
log.info("[用户身份绑定]添加患者失败 name={}, patientId={}", name, patientId); |
|
|
|
|
return Result.error(ResultEnum.PATIENT_ADD_ERROR); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
patientId = patient.getPatientId(); |
|
|
|
|
if (healthCardId != null && new HCodeService().bindCardRelation(patientId, healthCardId) == null) { // 绑定患者和院内关系
|
|
|
|
|
log.info("[电子健康卡]绑定患者和医院关系失败"); |
|
|
|
|
} |
|
|
|
|
@ -188,28 +276,31 @@ public class PatientService { |
|
|
|
|
healthCardId = hcId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.info("[患者]更新 isMyself={}, patientId={}, name={}, healthCardId={}", isMyself, patient.getPatientId(), name, healthCardId); |
|
|
|
|
log.info("[患者]更新 isMyself={}, patientId={}, name={}, healthCardId={}", isMyself, patientId, name, healthCardId); |
|
|
|
|
if (isMyself) { |
|
|
|
|
if (!patientDao.updateMyself(openid, idCardNo, patientId, name, address, areaCode, nation, tel)) { |
|
|
|
|
log.info("[患者]自身信息更新失败 patientId={}", patient.getPatientId()); |
|
|
|
|
if (!patientDao.updateMyself(bindInfo)) { |
|
|
|
|
log.info("[患者]自身信息更新失败 patientId={}", patientId); |
|
|
|
|
return Result.error(ResultEnum.DATA_UPDATE_ERROR); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!patientDao.updateInfo(openid, idCardNo, patientId, healthCardId, name, nation, tel, uuid, address, areaCode, areaAddress)) { |
|
|
|
|
log.info("[患者]更新失败 patientId={}", patient.getPatientId()); |
|
|
|
|
if (!patientDao.updateInfo(bindInfo)) { |
|
|
|
|
log.info("[患者]更新失败 patientId={}", patientId); |
|
|
|
|
return Result.error(ResultEnum.PATIENT_UPDATE_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
WxCacheHelper.removeUser(openid); |
|
|
|
|
return Result.success(); |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
map.put("gmcUniqueId", bindInfo.getGmcUniqueId()); |
|
|
|
|
map.put("enOpenId", AesWxHelper.encode(openid)); |
|
|
|
|
return Result.success(map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* [无证绑定]参数校验 |
|
|
|
|
*/ |
|
|
|
|
public Result noCardBind(String fTel, String fName, String fIDCardNo, String mTel, String mName, String mIDCardNo) { |
|
|
|
|
public Result noCardParamsValid(String fTel, String fName, String fIDCardNo, String mTel, String mName, String mIDCardNo) { |
|
|
|
|
log.info("[无证绑定]fTel={}, fName={}, fIDCardNo={}, mTel={}, mName={}, mIDCardNo={}", fTel, fName, fIDCardNo, mTel, mName, mIDCardNo); |
|
|
|
|
|
|
|
|
|
if ((fName == null || fTel == null || fIDCardNo == null) && (mName == null || mTel == null || mIDCardNo == null)) { |
|
|
|
|
@ -257,9 +348,18 @@ public class PatientService { |
|
|
|
|
/** |
|
|
|
|
* [绑定本人] |
|
|
|
|
*/ |
|
|
|
|
public Result bindMyself(String name, String idCardNo, HCardTypeEnum cardTypeEnum, String address, String areaCode, String areaAddress, String openid, String sex, String nation, String birthday, boolean isVerifyCode, String tel, String smsCode) { |
|
|
|
|
log.info("[身份绑定] openid={}, name={}, address={}, areaCode={}, areaAddress={},nation={}, sex={}, birthday={}, cardType={}", openid, name, address, areaCode, areaAddress, nation, sex, birthday, cardTypeEnum.ALI_CODE); |
|
|
|
|
if (openid == null || sex == null || birthday == null || name == null || nation == null) { |
|
|
|
|
public Result bindMyself(HttpServletRequest request, boolean isVerifyCode, String tel, String smsCode, Patient bindInfo) { |
|
|
|
|
String openid = bindInfo.getOpenid(); |
|
|
|
|
String idCardNo = bindInfo.getIdCardNo(); |
|
|
|
|
String sex = bindInfo.getSex(); |
|
|
|
|
String birthday = bindInfo.getBirthday(); |
|
|
|
|
String name = bindInfo.getName(); |
|
|
|
|
String nation = bindInfo.getNation(); |
|
|
|
|
String areaCode = bindInfo.getAreaCode(); |
|
|
|
|
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) { |
|
|
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -301,9 +401,10 @@ public class PatientService { |
|
|
|
|
return Result.error(ResultEnum.ID_CARD_ERROR); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString().replace("-", ""); // 儿童身份证代码
|
|
|
|
|
bindInfo.setHealthCardId(null); |
|
|
|
|
bindInfo.setUuid(UUID.randomUUID().toString().replace("-", "")); // 儿童身份证代码
|
|
|
|
|
|
|
|
|
|
return bindCard(true, true, null, openid, name, sex, idCardNo, cardTypeEnum, tel, birthday, nation, uuid, address, areaCode, areaAddress); |
|
|
|
|
return bindCard(request, true, true, bindInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|