微信后端代码
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.

343 lines
14 KiB

package com.ynxbd.common.action;
import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.PatientLink;
import com.ynxbd.common.bean.enums.HCardTypeEnum;
import com.ynxbd.common.config.interceptor.AesDecode;
import com.ynxbd.common.dao.PatientDao;
import com.ynxbd.common.dao.his.HisPatientDao;
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.common.service.PatientService;
import com.ynxbd.wx.wxfactory.AesWxHelper;
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 java.util.List;
import java.util.UUID;
@Slf4j
@Namespace("/patient")
public class PatientAction extends BaseAction {
/**
* [患者]根据patientId查询信息
*/
@Action("getHisInfoByPatientId")
public Result getHisInfoByPatientId(@AesDecode String patientId) {
log.info("[患者]根据patientId查询HIS信息 patientId={}", patientId);
if (patientId == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
try {
JsonResult jsonResult = new HisPatientDao().selectPatientInfo(patientId, "999");
if (!jsonResult.success()) {
return Result.error(jsonResult.getMessage());
}
Patient patient = jsonResult.dataMapToBean(Patient.class);
if (patient == null) {
return Result.error(ResultEnum.DATA_NOT_FOUND);
}
String encode = Base64Helper.encode(patient, true);
if (encode == null) {
return Result.error();
}
return Result.success(patient);
} catch (ServiceException e) {
return Result.error(e);
}
}
/**
* [患者]根据patientId查询信息
*/
@Action("getInfoByPatientId")
public Result getInfoByPatientId(@AesDecode String patientId) {
log.info("[患者]根据patientId查询信息 patientId={}", patientId);
if (patientId == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
List<Patient> patients = new PatientDao().selectListByPatientId(patientId);
if (patients.isEmpty()) {
return Result.error(ResultEnum.DATA_NOT_FOUND);
}
Patient patient = patients.get(0);
String idCardNo = patient.getIdCardNo();
if (ObjectUtils.isEmpty(idCardNo)) { // 儿童
String fatherTel = patient.getFatherTel();
if (ObjectUtils.isEmpty(fatherTel)) {
patient.setTel(patient.getMotherTel());
patient.setIdCardNo(patient.getMotherIdCardNo());
} else {
patient.setTel(fatherTel);
patient.setIdCardNo(patient.getFatherIdCardNo());
}
patient.setFatherTel(null);
patient.setFatherName(null);
patient.setFatherIdCardNo(null);
//
patient.setMotherTel(null);
patient.setMotherName(null);
patient.setMotherIdCardNo(null);
}
patient.setUuid(null);
String encode = Base64Helper.encode(patient, true);
if (encode == null) {
return Result.error();
}
return Result.success(encode);
}
/**
* [患者]根据openid查询信息
*/
@Action("getListByOpenid")
public Result getListByOpenid(String openid) {
log.info("[患者]根据openid查询信息 openid={}", openid);
if (openid == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
List<Patient> patients = new PatientDao().selectListByOpenid(openid);
return Result.success(patients);
}
/**
* [患者] 外部对接-根据openId查询患者信息
*
* @param openid openId
* @param organizeName 组织机构代码
* @return 返回患者信息
*/
@Action("getPatientsByOpenid")
public Result getPatientsByOpenid(String openid, String organizeName) {
log.info("[外部患者信息对接]根据openid查询信息 openid={},organizeName-{}", openid, organizeName);
organizeName = AesMicroHelper.decode(organizeName);
if (organizeName == null) {
return Result.error(ResultEnum.PERMISSION_NO_ACCESS);
}
if (openid == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
List<PatientLink> patients = new PatientDao().selectPatientsByOpenid(openid);
return Result.success(patients);
}
/**
* [患者] 外部对接-根据openId加密版查询患者信息
*
* @param enParams 加密openId
* @param organizeName 组织机构代码
* @return 返回患者信息
*/
@Action("getPatientsByEncOpenid")
public Result getPatientsByEncOpenid(String enParams, String organizeName) {
String openid = AesMicroHelper.decode(enParams);
log.info("[外部患者信息对接]根据openid查询信息 openid={},organizeName-{},emParams-{}", openid, organizeName, enParams);
organizeName = AesMicroHelper.decode(organizeName);
if (organizeName == null) {
return Result.error(ResultEnum.PERMISSION_NO_ACCESS);
}
if (openid == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
List<PatientLink> patients = new PatientDao().selectPatientsByEncOpenid(openid);
return Result.success(patients);
}
/**
* [患者]获取关联的openid
*
* @param cardNo 患者id
* @param algorithm 算法
* @param isLastBind 是否只查询最后一次绑定的微信
* @param isEncryptComma 是否加密逗号
*/
@Action("getOpenIdsByCardNo")
public Result getOpenIdsByCardNo(String cardNo, String algorithm, Boolean isLastBind, Boolean isEncryptComma) {
log.info("[患者]获取关联的openid, patientId={}, algorithm={}", cardNo, algorithm);
if (cardNo == null || algorithm == null || isEncryptComma == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
List<Patient> dataList = new PatientDao().selectOpenIdsByCardNo(cardNo);
return new PatientService().toOpenIds(dataList, algorithm, isLastBind, isEncryptComma);
}
/**
* [患者]获取关联的openid
*
* @param patientId 患者id
* @param algorithm 算法
* @param isLastBind 是否只查询最后一次绑定的微信
* @param isEncryptComma 是否加密逗号
*/
@Action("getOpenIdsByPatientId")
public Result getOpenIdsByPatientId(String patientId, String algorithm, Boolean isLastBind, Boolean isEncryptComma) {
log.info("[患者]获取关联的openid, patientId={}, algorithm={}", patientId, algorithm);
if (patientId == null || algorithm == null || isEncryptComma == null) {
return Result.error(ResultEnum.PARAM_IS_BLANK);
}
List<Patient> dataList = new PatientDao().selectOpenIdsByPatientId(patientId);
return new PatientService().toOpenIds(dataList, algorithm, isLastBind, isEncryptComma);
}
/**
* [无证|有证绑定]绑定新患者不通过电子健康卡
*/
@Action("bind")
public Result bind(boolean isVerifyCode, String tel, String smsCode, String address, String areaCode, String areaAddress, String idCardNo, String openid, String sex, String name, String nation, String birthday, String cardType, String enUnionId, String enOpenId, String enGmcOpenId, String enHospAppId) {
log.info("[身份绑定] openid={}, name={}, address={}, areaCode={}, areaAddress={}, nation={}, sex={}, birthday={}, cardType={}", openid, name, address, areaCode, areaAddress, nation, sex, birthday, cardType);
if (openid == null || sex == null || birthday == null || name == null || nation == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
if (isVerifyCode) {
if (ObjectUtils.isEmpty(smsCode) || smsCode.length() > 6 || smsCode.length() < 4) {
return Result.error(ResultEnum.SMS_CODE_ERROR);
}
if (ObjectUtils.isEmpty(tel) || tel.length() != 11) {
return Result.error(ResultEnum.SMS_TEL_ERROR);
}
if (!SmsHelper.codeVerify(tel, smsCode, false)) {
return Result.error(ResultEnum.SMS_CODE_VERIFY_ERROR); // 短信验证码失效或错误
}
}
if (address == null || areaCode == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
if (!ValidHelper.isValidNation(nation)) {
return Result.error(ResultEnum.NATION_ERROR);
}
if (!DateHelper.isValidDate(birthday)) {
return Result.error(ResultEnum.PARAM_DATE_ERROR);
}
String fName = null, fTel = null, fIDCardNo = null;
String mName = null, mTel = null, mIDCardNo = null;
if (cardType == null) cardType = HCardTypeEnum._01.WX_CODE;
HCardTypeEnum cardTypeEnum = HCardTypeEnum.toTypeByWxCode(cardType);
if (cardTypeEnum == null) {
return Result.error(ResultEnum.CARD_TYPE_NOT_FOUNT);
}
if (HCardTypeEnum.NO_CARD.equals(cardTypeEnum)) { // 儿童
fTel = getString("fTel");
fName = getString("fName");
fIDCardNo = getString("fIDCardNo");
mTel = getString("mTel");
mName = getString("mName");
mIDCardNo = getString("mIDCardNo");
Result result = new PatientService().noCardParamsValid(fTel, fName, fIDCardNo, mTel, mName, mIDCardNo);
if (!result.isOK()) {
return result;
}
} else {
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);
}
}
Patient bindInfo = new Patient();
bindInfo.setUuid(UUID.randomUUID().toString().replace("-", "")); // 儿童身份证代码
bindInfo.setHealthCardId(null);
bindInfo.setOpenid(openid);
bindInfo.setEnOpenId(enOpenId);
bindInfo.setEnUnionId(enUnionId);
bindInfo.setEnHospAppId(enHospAppId);
bindInfo.setEnGmcOpenId(enGmcOpenId);
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.setFatherName(fName);
bindInfo.setFatherTel(fTel);
bindInfo.setFatherIdCardNo(fIDCardNo);
//
bindInfo.setMotherName(mName);
bindInfo.setMotherTel(mTel);
bindInfo.setMotherIdCardNo(mIDCardNo);
return new PatientService().bind(request, false, true, bindInfo);
}
/**
* 患者解绑
*/
@Action("unBind")
public Result unBind(String openid, String patientId) {
log.info("[患者解绑]解绑 openid={}, patientId={}", openid, patientId);
if (openid == null || patientId == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
try {
Patient patient = new PatientDao().selectByOpenidAndPatientId(openid, patientId);
if (patient == null) {
log.info("[患者解绑]失败,库中不存在该患者 patientId={}", patientId);
return Result.error(ResultEnum.PATIENT_NOT_FOUND);
}
String cardType = HCardTypeEnum._01.HIS_CODE;
String idCardNo = patient.getIdCardNo();
if (ObjectUtils.isEmpty(idCardNo)) { // 无身份证类型解绑
idCardNo = patient.getUuid();
if (HCardTypeEnum.BABY.WX_CODE.equals(idCardNo)) {
idCardNo = null;
}
cardType = HCardTypeEnum.BABY.HIS_CODE; // 8888
}
if (idCardNo == null) {
log.info("身份证为空不允许解绑 openid={}, patientId={}", openid, patientId);
return Result.error(ResultEnum.PATIENT_UN_BIND_ERROR);
}
JsonResult jsonResult = new HisPatientDao().hisUnBind(idCardNo, cardType);
if (jsonResult.success()) {
return new PatientService().removePatient(openid, patientId, idCardNo);
}
String message = jsonResult.getMessage();
if (message.contains("未注册或已解绑")) {
return new PatientService().removePatient(openid, patientId, idCardNo);
}
return Result.error(message);
} catch (ServiceException e) {
return Result.error(e);
}
}
}