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

173 lines
6.5 KiB

package com.ynxbd.common.dao.his;
import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.enums.HCardTypeEnum;
import com.ynxbd.common.helper.his.HisEnum;
import com.ynxbd.common.helper.his.HisHelper;
import com.ynxbd.common.result.JsonResult;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.result.ServiceException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @Author wsq
* @Date 2020/9/27 15:13
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
*/
public class HisPatientDao {
/**
* 身份证绑定
*
* @param name 患者名
* @param sex 性别
* @param idCardNo 身份证号
* @param tel 电话
* @param address 地址
* @param birthday 生日
* @param nation 名族
* @param fName 父亲姓名
* @param fTel 父亲电话
* @param fIDCardNo 父亲身份证
* @param mName 母亲姓名
* @param mTel 母亲电话
* @param mIDCardNo 母亲身份证号
* @return 患者
*/
public Patient bind(boolean isCounty, String name, String sex, String idCardNo, HCardTypeEnum cardTypeEnum, String tel, String address, String birthday, String nation, String county, String uuid, String fName, String fTel, String fIDCardNo, String mName, String mTel, String mIDCardNo) throws ServiceException {
Map<String, Object> params = new HashMap<>();
// 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
));
params.put("TransNo", UUID.randomUUID().toString().replace("-", ""));
params.put("IdCardNo", idCardNo);
params.put("CardNo", cardNo);
params.put("Name", name);
params.put("Sex", sex.equals("男") ? "1" : "2");
params.put("BirthDay", birthday);
params.put("Address", address);
params.put("Nation", nation);
params.put("Tel", tel);
if (isCounty && !ObjectUtils.isEmpty(county)) {
params.put("Address_Code", county);
}
if (fName != null && fTel != null && fIDCardNo != null) {
params.put("GuardianFatherName", fName);
params.put("GuardianFatherTel", fIDCardNo);
params.put("GuardianFatherIdCard", fIDCardNo);
}
if (mName != null && mTel != null & mIDCardNo != null) {
params.put("GuardianMotherName", mName);
params.put("GuardianMotherTel", mTel);
params.put("GuardianMotherIdCard", mIDCardNo);
}
JsonResult JsonResult = HisHelper.getJsonResult(HisEnum.AP_Binding_Card, params);
Patient patient = JsonResult.dataMapToBean(Patient.class);
if (patient == null) {
throw new ServiceException(JsonResult.getMessage());
}
String patientId = patient.getPatientId();
if (patientId == null) {
throw new ServiceException(JsonResult.getMessage());
}
if (patientId.equals(cardNo)) { // 绑定失败返回卡号
throw new ServiceException(JsonResult.getMessage());
}
return patient;
}
/**
* HIS解绑
*
* @return 患者
*/
public JsonResult hisUnBind(String idCardNo, String cardType) throws ServiceException {
if (ObjectUtils.isEmpty(idCardNo)) {
throw new ServiceException(ResultEnum.PARAM_IS_DEFECT);
}
if (cardType == null) {
cardType = HCardTypeEnum.BABY.HIS_CODE; // 8888
}
Map<String, Object> params = new HashMap<>();
params.put("CardNo", idCardNo);
params.put("CardType", cardType);
params.put("TransNo", UUID.randomUUID().toString().replace("-", ""));
return HisHelper.getJsonResult(HisEnum.AP_UnBinding_Card, params);
}
/**
* 查询患者信息
*
* @param cardNo 卡号
* @param cardType 类型 {0:身份证; 1:健康卡;999:患者ID(PatientId) 此步骤对于已经获得PatientId 需要查询患者信息的情景。}
* @return hisResult
*/
public JsonResult selectPatientInfo(String cardNo, String cardType) throws ServiceException {
if (StringUtils.isEmpty(cardNo) || cardType == null) {
throw new ServiceException(ResultEnum.PARAM_IS_DEFECT);
}
Map<String, Object> params = new HashMap<>();
params.put("CardNo", cardNo);
params.put("CardType", cardType);
return HisHelper.getJsonResult(HisEnum.AP_Query_Patient, params);
}
/**
* 修改患者信息
*
* @param patientId
* @param name
* @param cardNo
* @param county
* @param address
* @param tel
* @param nation
* @return
*/
public JsonResult updatePatientInfo(String patientId, String name, String cardNo, String county, String address, String tel, String nation) throws ServiceException {
if (ObjectUtils.isEmpty(patientId) || ObjectUtils.isEmpty(name) || ObjectUtils.isEmpty(cardNo)) {
throw new ServiceException(ResultEnum.PARAM_IS_DEFECT);
}
Map<String, Object> params = new HashMap<>();
params.put("PatientID", patientId);
params.put("Name", name);
params.put("IDCardNo", cardNo);
// 不传入,则his中的患者信息不会被修改
params.put("Address_Code", county); // 行政区编码
params.put("Address", address); // 行政区编码
//
params.put("Tel", tel); // 行政区编码
params.put("Nation", nation); // 行政区编码
return HisHelper.getJsonResult(HisEnum.AP_Query_Patient, params);
}
//
// public static void main(String[] args) {
// String xml = "<?xml version=\"1.0\" encoding=\"GB2312\"?><Response><TransactionCode>1002</TransactionCode><ResponseCode>-1</ResponseCode><ResponseMessage>该卡已注册,不能再次注册!</ResponseMessage><PatientID>11149300</PatientID></Response>";
// WsResult wsResult = WsResult.xmlToBean(xml);
// System.out.println(wsResult.getDataMapBean(Patient.class));
// }
}