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.
		
		
		
		
			
				
					
					
						
							315 lines
						
					
					
						
							13 KiB
						
					
					
				
			
		
		
	
	
							315 lines
						
					
					
						
							13 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.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.utils.DesEncryptHelper;
 | |
| 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.io.UnsupportedEncodingException;
 | |
| import java.nio.charset.StandardCharsets;
 | |
| import java.util.List;
 | |
| import java.util.UUID;
 | |
| 
 | |
| @Slf4j
 | |
| @Namespace("/patient")
 | |
| public class PatientAction extends BaseAction {
 | |
| 
 | |
|     /**
 | |
|      * [患者]根据patientId查询信息
 | |
|      */
 | |
|     @Action("getHisInfoByPatientId")
 | |
|     public Result getHisInfoByPatientId(String patientId) {
 | |
|         log.info("[患者]根据patientId查询信息 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(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.size() == 0) {
 | |
|             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 = AesHelper.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 = AesHelper.deCode(enParams);
 | |
|         log.info("[外部患者信息对接]根据openid查询信息 openid={},organizeName-{},emParams-{}", openid,organizeName,enParams);
 | |
|         organizeName = AesHelper.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 address, String county, String idCardNo, String openid, String sex, String name, String nation, String birthday, String cardType, String tel, String smsCode) {
 | |
|         log.info("[身份绑定] openid={}, name={}, county={}, address={}, nation={}, sex={}, birthday={}, cardType={}", openid, name, county, address, 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 || county == 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().noCardBind(fTel, fName, fIDCardNo, mTel, mName, mIDCardNo);
 | |
|             if (!result.isSuccess()) {
 | |
|                 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);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         String uuid = UUID.randomUUID().toString().replace("-", ""); // 儿童身份证代码
 | |
| 
 | |
|         return new PatientService().bind(false, true, null, openid, name, sex, idCardNo, cardTypeEnum, tel, address, birthday, nation, county, uuid, fName, fTel, fIDCardNo, mName, mTel, mIDCardNo);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 解绑健康卡
 | |
|      */
 | |
|     @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);
 | |
|         }
 | |
|     }
 | |
| 
 | |
| }
 | |
| 
 |