You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
347 lines
17 KiB
347 lines
17 KiB
package com.ynxbd.common.action;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.ynxbd.common.action.base.BaseAction;
|
|
import com.ynxbd.common.bean.Patient;
|
|
import com.ynxbd.common.bean.User;
|
|
import com.ynxbd.common.bean.enums.HCardTypeEnum;
|
|
import com.ynxbd.common.bean.enums.HealthCardRespCodeEnum;
|
|
import com.ynxbd.common.config.HealthCardConfig;
|
|
import com.ynxbd.common.config.interceptor.AesDecode;
|
|
import com.ynxbd.common.helper.HealthCardHelper;
|
|
import com.ynxbd.common.helper.common.DateHelper;
|
|
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;
|
|
import com.ynxbd.wx.wxfactory.WxCacheHelper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.struts2.convention.annotation.Action;
|
|
import org.apache.struts2.convention.annotation.Namespace;
|
|
import org.ehcache.Cache;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* @Author wsq
|
|
* @Date 2020/9/24 18:00
|
|
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
|
|
*/
|
|
@Slf4j
|
|
@Namespace("/healthCode")
|
|
public class HealthCodeAction extends BaseAction {
|
|
|
|
|
|
/**
|
|
* [电子健康卡]患者绑定(成人)
|
|
*/
|
|
@Action("bind")
|
|
public Result bind(Boolean isMiniApp, boolean isAreaCode, boolean isFace, String orderId, String registerOrderId, String address, String areaCode, String areaAddress, String openid, String tel, String sex, String name, String nation, String birthday, String idCardNo, String cardType, Boolean isHealthCard, String healthCardId, String wechatCode, String enOpenId, String enUnionId, String enGmcOpenId, String enHospAppId) {
|
|
log.info("[电子健康卡]身份绑定 name={}, address={}, areaCode={}, areaAddress={}, nation={}, sex={}, birthday={}, tel={}, healthCardId={}, cardType={}, enUnionId={}, openId={}, enOpenId={}, enGmcOpenId={}, enChildAppId={}",
|
|
name, address, areaCode, areaAddress, nation, sex, birthday, tel, healthCardId, cardType, enUnionId, openid, enOpenId, enGmcOpenId, enHospAppId);
|
|
if (isHealthCard == null || openid == null || tel == null || sex == null || birthday == null || name == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
if (!openid.equals(AesWxHelper.decode(enOpenId))) {
|
|
log.info("[绑定]参数无效 openId={}, enOpenId={}", openid, AesWxHelper.decode(enOpenId));
|
|
return Result.error(ResultEnum.PARAM_IS_INVALID);
|
|
}
|
|
|
|
if (isHealthCard && isFace) { // 实名认证
|
|
if (!HealthCardHelper.checkUniformVerifyResult(isMiniApp, openid, orderId, registerOrderId)) {
|
|
return Result.error(ResultEnum.FACE_VERIFY_ERROR);
|
|
}
|
|
}
|
|
|
|
if (cardType == null) cardType = HCardTypeEnum._01.WX_CODE;
|
|
HCardTypeEnum cardTypeEnum = HCardTypeEnum.findByWxCode(cardType);
|
|
if (cardTypeEnum == null) {
|
|
return Result.error(ResultEnum.CARD_TYPE_NOT_FOUNT);
|
|
}
|
|
|
|
if (!ValidHelper.isValidTel(tel)) {
|
|
log.info("[电子健康卡]电话号码错误 name={}, tel={}, idCardNo={}", name, tel, idCardNo);
|
|
return Result.error(ResultEnum.TEL_ERROR);
|
|
}
|
|
|
|
if (!ValidHelper.isValidIdCard(idCardNo)) {
|
|
log.info("[电子健康卡]身份证错误 name={}, tel={}, idCardNo={}", name, tel, idCardNo);
|
|
return Result.error(ResultEnum.ID_CARD_ERROR);
|
|
}
|
|
|
|
if (!ValidHelper.isValidNation(nation)) {
|
|
return Result.error(ResultEnum.NATION_ERROR);
|
|
}
|
|
if (nation.equals("未知")) {
|
|
nation = "";
|
|
}
|
|
|
|
if (!DateHelper.isValidDate(birthday)) { // 生日异常
|
|
return Result.error(ResultEnum.PARAM_DATE_ERROR);
|
|
}
|
|
|
|
if (address == null || areaCode == null) {
|
|
log.info("[电子健康卡]地址错误 areaCode={}, address={}", areaCode, address);
|
|
return Result.error(ResultEnum.PARAM_ADDRESS_ERROR);
|
|
}
|
|
|
|
String uuid = null;
|
|
if (HealthCardConfig.isEnable() && isHealthCard && healthCardId == null) { // 没有禁用电子健康卡
|
|
log.info("[电子健康卡]绑定 wechatCode={}", wechatCode);
|
|
if (wechatCode == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
// 先注册,后修改-->先获取健康卡ID
|
|
JSONObject respObj = HCodeService.registerHealthCard(isMiniApp, null, wechatCode, birthday, cardTypeEnum, address, areaAddress, sex, nation, name, idCardNo, tel);
|
|
if (respObj == null) {
|
|
log.info("[电子健康卡]注册健康卡失败,响应内容为空");
|
|
|
|
} else {
|
|
healthCardId = respObj.getString("healthCardId");
|
|
if (ObjectUtils.isEmpty(healthCardId)) {
|
|
healthCardId = null; // 防止后续绑定院内关系失败
|
|
log.info("[电子健康卡]注册失败 healthCardId为空");
|
|
// 响应处理
|
|
String errMsg = respObj.getString("errMsg");
|
|
String resultCode = respObj.getString("resultCode");
|
|
HealthCardRespCodeEnum healthCardRespCodeEnum = HealthCardRespCodeEnum.findEnumByResultCode(resultCode);
|
|
log.info("[电子健康卡] 绑定失败原因 resultCode={}, errMsg={}, statusMsg={}", resultCode, errMsg, healthCardRespCodeEnum.MESSAGE);
|
|
if (!healthCardRespCodeEnum.IS_CONTINUE) { // 不继续执行
|
|
if (!healthCardRespCodeEnum.equals(HealthCardRespCodeEnum._10060)) { // 姓名和身份证不一致
|
|
return Result.error(healthCardRespCodeEnum.MESSAGE);
|
|
}
|
|
|
|
// 判断出生日期是否大于半年前-->婴儿
|
|
Boolean isOverDateByToday = DateHelper.isTodayMoveDateOverDate(birthday, -180);
|
|
if (isOverDateByToday == null || isOverDateByToday) {
|
|
return Result.error(healthCardRespCodeEnum.MESSAGE);
|
|
}
|
|
uuid = HCardTypeEnum.BABY.WX_CODE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Patient bindInfo = new Patient();
|
|
bindInfo.setOpenid(openid);
|
|
bindInfo.setUuid(uuid);
|
|
bindInfo.setHealthCardId(healthCardId);
|
|
bindInfo.setName(name);
|
|
bindInfo.setSex(sex);
|
|
bindInfo.setIdCardNo(idCardNo);
|
|
bindInfo.setCardTypeEnum(cardTypeEnum);
|
|
bindInfo.setTel(tel);
|
|
bindInfo.setBirthday(birthday);
|
|
bindInfo.setNation(nation);
|
|
bindInfo.setAddress(address);
|
|
bindInfo.setAreaCode(areaCode);
|
|
bindInfo.setAreaAddress(areaAddress);
|
|
//
|
|
bindInfo.setEnOpenId(enOpenId);
|
|
bindInfo.setEnUnionId(enUnionId);
|
|
bindInfo.setEnHospAppId(enHospAppId);
|
|
bindInfo.setEnGmcOpenId(enGmcOpenId);
|
|
return new PatientService().bindCard(request, false, true, isAreaCode, true, bindInfo);
|
|
}
|
|
|
|
|
|
/**
|
|
* [升级绑定]旧版-->已在HIS绑定-->注册健康卡
|
|
*/
|
|
@Action("upBind")
|
|
public Result upBind(String wechatCode, Integer id, @AesDecode String openid, @AesDecode String idCardNo, @AesDecode String hisPatientId, @AesDecode String epId, String cardType, String tel, String name, String nation, String address) {
|
|
log.info("[电子健康卡]升级绑定 id={}, name={}, address={}, nation={}, epId={}, hisPatientId={}, tel={}, idType={}, wechatCode={}", id, name, address, nation, epId, hisPatientId, tel, cardType, wechatCode);
|
|
if (wechatCode == null || openid == null || epId == null || hisPatientId == null || name == null || idCardNo == null || tel == null || address == null || nation == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
}
|
|
|
|
HCardTypeEnum cardTypeEnum = HCardTypeEnum.findByWxCode(cardType, HCardTypeEnum._01);
|
|
if (cardTypeEnum == null) {
|
|
return Result.error(ResultEnum.CARD_TYPE_NOT_FOUNT);
|
|
}
|
|
|
|
if (!ValidHelper.isValidNation(nation)) {
|
|
return Result.error(ResultEnum.NATION_ERROR);
|
|
}
|
|
|
|
String sex = IDNumberHelper.getSex(idCardNo);
|
|
String birthday = IDNumberHelper.getBirthday(idCardNo);
|
|
if (sex == null || birthday == null) { // 身份证解析数据错误
|
|
log.info("[电子健康卡]升级绑失败,身份证解析数据错误 sex={} birthday={}", sex, birthday);
|
|
return Result.error(ResultEnum.PARAM_TYPE_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);
|
|
|
|
log.info("[电子健康卡]升级绑定失败原因 resultCode={}, errMsg={}, statusMsg={}", resultCode, errMsg, healthCardRespCodeEnum.MESSAGE);
|
|
return Result.error(healthCardRespCodeEnum.MESSAGE);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
// 旧版:实名认证
|
|
@Action("registerUniformVerifyOrder")
|
|
public Result registerUniformVerifyOrder(String wechatCode, String name, String idCardNo) {
|
|
log.info("[电子健康卡]实人认证生成orderId wechatCode={}, name={}, idCardNo={}", wechatCode, name, idCardNo);
|
|
if (wechatCode == null || name == null || idCardNo == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT); // 参数为空
|
|
}
|
|
String orderId = HCodeService.bindUniformVerifyOrder(wechatCode, name, idCardNo);
|
|
return ObjectUtils.isEmpty(orderId) ? Result.error() : Result.success(orderId);
|
|
}
|
|
|
|
|
|
// 旧版:实名认证
|
|
@Action("checkUniformVerifyResult")
|
|
public Result checkUniformVerifyResult(Boolean isMiniApp, String orderId, String registerOrderId) {
|
|
log.info("[电子健康卡]实人认证结果查询 orderId={}, registerOrderId={}", orderId, registerOrderId);
|
|
if (orderId == null || registerOrderId == null) {
|
|
return Result.error(ResultEnum.PARAM_IS_DEFECT); // 参数为空
|
|
}
|
|
return Result.isOK(HealthCardHelper.checkUniformVerifyResult(isMiniApp, null, orderId, registerOrderId));
|
|
}
|
|
|
|
|
|
// @Action("batchUpdate")
|
|
// public void batchUpdate() {
|
|
// Timer timer = new Timer();
|
|
// timer.schedule(new TimerTask() {
|
|
// public void run() {
|
|
// log.info("开始执行批量领卡定时任务");
|
|
// List<Patient> lstPatient = new PatientDao().selectPatient4BatchUpdateHealthCard();
|
|
// JSONArray jsonArray = null;
|
|
// try {
|
|
// jsonArray = HCodeService.batchUpdate(lstPatient);
|
|
// } catch (Exception e) {
|
|
// log.error(e.getMessage());
|
|
// }
|
|
//
|
|
// if (jsonArray == null) return;
|
|
//
|
|
// for (int i = 0; i < jsonArray.size(); i++) {
|
|
// new PatientDao().updateCallFlag(jsonArray.getJSONObject(i).get("idNumber").toString());
|
|
// if (!"".equals(jsonArray.getJSONObject(i).get("healthCardId").toString()) && !"".equals(jsonArray.getJSONObject(i).get("idNumber").toString()))
|
|
// new PatientDao().updateHealthCard(jsonArray.getJSONObject(i).get("healthCardId").toString(),
|
|
// jsonArray.getJSONObject(i).get("idNumber").toString());
|
|
// }
|
|
// }
|
|
// }, 2 * 1000, 30 * 1000);
|
|
// }
|
|
|
|
|
|
// /**
|
|
// * [患者]查询信息
|
|
// */
|
|
// @Action("getPatientByIdCardNo")
|
|
// public Result getPatientByIdCardNo(@AesDecode String openid, @AesDecode String idCardNo) {
|
|
// log.info("[电子健康卡]根据身份证和openId查询患者信息 openid={}, idCardNo={}", openid, idCardNo);
|
|
// if (openid == null || idCardNo == null) {
|
|
// return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
// }
|
|
//
|
|
// Patient patient = new PatientDao().selectByIdCardNo(openid, idCardNo);
|
|
// return Result.success(patient);
|
|
// }
|
|
|
|
|
|
// /**
|
|
// * [电子健康卡]通过二维码获取健康卡数据
|
|
// *
|
|
// * @param qrCode 二维码
|
|
// */
|
|
// @Action("getHealthCardByQrCode")
|
|
// public Result getHealthCardByQrCode(Boolean isMiniApp, String qrCode) {
|
|
// log.info("[电子健康卡]通过二维码获取健康卡数据 isMiniApp={}, qrCode={}", isMiniApp, qrCode);
|
|
// if (qrCode == null) {
|
|
// return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
// }
|
|
//
|
|
// Patient patient = HCodeService.getHealthCardByQrCode(isMiniApp, qrCode);
|
|
// return patient == null ? Result.error() : Result.success(patient);
|
|
// }
|
|
|
|
// /**
|
|
// * [电子健康卡]查询患者集
|
|
// */
|
|
// @Action("getHealthCardList")
|
|
// public Result getHealthCardList(@AesDecode String openid) {
|
|
// log.info("[电子健康卡]查询患者集 openid={}", openid);
|
|
// if (openid == null) {
|
|
// return Result.error(ResultEnum.PARAM_IS_DEFECT);
|
|
// }
|
|
// List<Patient> patients = new PatientDao().selectHealthCardListByOpenid(openid);
|
|
// return Result.success(patients);
|
|
// }
|
|
|
|
|
|
// @Action("appBindHealthCard")
|
|
// public Result appBindHealthCard(String openid, String healthCode) {
|
|
// log.info("[新版电子健康卡]H5嵌入链接绑卡-通过healthCode获取健康卡数据 healthCode={}, openid={}", healthCode, openid);
|
|
// if (healthCode == null || openid == null) return Result.error(ResultEnum.PARAM_IS_DEFECT); // 参数为空
|
|
//
|
|
// Patient patient = HCodeService.appBindHealthCard(healthCode); // 通过健康卡授权码获取健康卡的用户信息
|
|
// if (patient == null) {
|
|
// log.info("[新版电子健康卡]H5嵌入链接绑卡 获取用户信息失败");
|
|
// return Result.error("[新版电子健康卡]H5嵌入链接绑卡 获取用户信息失败");
|
|
// }
|
|
// return Result.success(patient);
|
|
// }
|
|
|
|
|
|
// /**
|
|
// * [电子健康卡]绑卡验证授权
|
|
// */
|
|
// @Action("registerHealthCardPreAuth")
|
|
// public Result registerHealthCardPreAuth(Boolean isMiniApp, String wechatCode, String healthCode, String openId) {
|
|
// log.info("[电子健康卡]绑卡验证授权 isMiniApp={}, wechatCode={}, healthCode={}, openId={}", isMiniApp, wechatCode, healthCode, openId);
|
|
// JSONObject result = HCodeService.registerHealthCardPreAuth(isMiniApp, WeChatConfig.getDomain(true), wechatCode, healthCode, openId);
|
|
// return Result.success(result);
|
|
// }
|
|
|
|
}
|
|
|