From 6e41d703120efc08427451834c744fb07d47b93f Mon Sep 17 00:00:00 2001 From: shiyang <316555390@qq.com> Date: Thu, 24 Feb 2022 15:44:32 +0800 Subject: [PATCH] =?UTF-8?q?his=E5=AF=B9=E6=8E=A5=E6=82=A3=E8=80=85?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8F=8A=E6=96=B0=E5=8A=A0HIS?= =?UTF-8?q?=E6=82=A3=E8=80=85=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aop/ValidatedExceptionHandler.java | 47 ++++ .../controller/LymsHisInfoController.java | 87 +++++++ .../com/lyms/talkonlineweb/domain/LymsHisInfo.java | 196 ++++++++++++++++ .../talkonlineweb/service/LymsHisInfoService.java | 12 + .../service/impl/LymsHisInfoServiceImpl.java | 252 +++++++++++++++++++++ .../talkonlineweb/task/GetPatientInfoTask.java | 236 +++---------------- .../com/lyms/talkonlineweb/util/BeanUtils.java | 186 +++++++++++++++ .../com/lyms/talkonlineweb/util/StringUtil.java | 4 +- .../main/resources/mapper/LymsHisInfoMapper.xml | 30 +++ 9 files changed, 839 insertions(+), 211 deletions(-) create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/ValidatedExceptionHandler.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsHisInfo.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/BeanUtils.java create mode 100644 talkonlineweb/src/main/resources/mapper/LymsHisInfoMapper.xml diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/ValidatedExceptionHandler.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/ValidatedExceptionHandler.java new file mode 100644 index 0000000..20250f6 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/ValidatedExceptionHandler.java @@ -0,0 +1,47 @@ +package com.lyms.talkonlineweb.aop; + +import com.lyms.talkonlineweb.result.BaseResponse; +import lombok.extern.log4j.Log4j2; +import org.springframework.web.bind.annotation.ControllerAdvice; + +import org.springframework.http.HttpStatus; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import java.util.List; + +@Log4j2 +@ControllerAdvice +public class ValidatedExceptionHandler { + /** + * 处理@Validated参数校验失败异常 + * @param exception 异常类 + * @return 响应 + */ + @ResponseBody + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MethodArgumentNotValidException.class) + public BaseResponse exceptionHandler(MethodArgumentNotValidException exception){ + BindingResult result = exception.getBindingResult(); + StringBuilder stringBuilder = new StringBuilder(); + if (result.hasErrors()) { + List errors = result.getAllErrors(); + if (errors != null) { + errors.forEach(p -> { + FieldError fieldError = (FieldError) p; + log.warn("Bad Request Parameters: dto entity [{}],field [{}],message [{}]",fieldError.getObjectName(), fieldError.getField(), fieldError.getDefaultMessage()); + stringBuilder.append(fieldError.getDefaultMessage()+";"); + }); + } + } + BaseResponse baseResponse=new BaseResponse(); + baseResponse.setErrorcode(1); + baseResponse.setErrormsg(stringBuilder.toString()); + return baseResponse; + } + +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java new file mode 100644 index 0000000..3b6c504 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java @@ -0,0 +1,87 @@ +package com.lyms.talkonlineweb.controller; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.lyms.talkonlineweb.domain.LymsDict; +import com.lyms.talkonlineweb.domain.LymsHisInfo; +import com.lyms.talkonlineweb.result.BaseResponse; +import com.lyms.talkonlineweb.service.LymsHisInfoService; +import com.lyms.talkonlineweb.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 医院his对接 + */ +@RestController +@RequestMapping("his") +public class LymsHisInfoController { + + @Autowired + private LymsHisInfoService lymsHisInfoService; + + + /** + * 获取医院患者列表 + * @param hisInfo + * @return + */ + @GetMapping("getHisInfo") + public BaseResponse getHisInfo(LymsHisInfo hisInfo, int current, int size){ + BaseResponse baseResponse=new BaseResponse(); + Page page=new Page<>(current,size); + QueryWrapper query=new QueryWrapper(); + query.orderByDesc("createdtime"); + if(null!=hisInfo.getUpType()){ + query.eq("up_type", hisInfo.getUpType()); + } + if(StringUtil.isNotEmpty(hisInfo.getSynthesisQuery())){ + query.and(wrapper -> wrapper .like("name", hisInfo.getName()) + .or().eq("phone", hisInfo.getPhone()) + .or().eq("idCard", hisInfo.getIdcard())); + } + if(null!=hisInfo.getStartCreatedtime()){ + query.ge("createdtime", hisInfo.getStartCreatedtime()); + } + if(null!=hisInfo.getEndCreatedtime()){ + query.le("createdtime", hisInfo.getEndCreatedtime()); + } + Page hisInfoPage=lymsHisInfoService.page(page,query); + baseResponse.setObject(hisInfoPage); + return baseResponse; + } + + /** + * 上传his患者信息 + * @param lymsHisInfo + * @return + */ + @PostMapping("upHisInfo") + public BaseResponse upHisInfo( @RequestBody @Validated LymsHisInfo lymsHisInfo){ + BaseResponse baseResponse=new BaseResponse(); + String result = lymsHisInfoService.upHisInfo(lymsHisInfo); + if(StringUtil.isNotEmpty(result)){ + baseResponse.setErrorcode(1); + baseResponse.setErrormsg(result); + }else { + lymsHisInfo.setUpType(1); + final boolean b = lymsHisInfoService.updateById(lymsHisInfo); + if(b){ + baseResponse.setErrorcode(0); + baseResponse.setErrormsg("患者上传成功"); + } + } + return baseResponse; + } + + + + + +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsHisInfo.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsHisInfo.java new file mode 100644 index 0000000..46ddf8e --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsHisInfo.java @@ -0,0 +1,196 @@ +package com.lyms.talkonlineweb.domain; + +import com.baomidou.mybatisplus.annotation.*; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; + +/** + * 对接医院his获取患者信息 + * @TableName lyms_his_info + */ +@TableName(value ="lyms_his_info") +@Data +public class LymsHisInfo implements Serializable { + /** + * + */ + @TableId(value = "id", type = IdType.AUTO) + @NotNull(message = "id不能为空") + private Integer id; + + /** + * 编号 + */ + @TableField(value = "vcCardNo") + @NotNull(message = "vccardno不能为空") + private String vccardno; + + /** + * 患者姓名 + */ + @TableField(value = "name") + @NotNull(message = "name不能为空") + private String name; + + /** + * 性别 + */ + @TableField(value = "sex") + @NotNull(message = "sex不能为空") + private String sex; + + /** + * 生日 + */ + @TableField(value = "birthday") + @NotNull(message = "birthday不能为空") + private String birthday; + + /** + * 电话 + */ + @TableField(value = "phone") + @NotNull(message = "phone不能为空") + private String phone; + + /** + * 身份证号码 + */ + @TableField(value = "idCard") + @NotNull(message = "idcard不能为空") + private String idcard; + + /** + * 科室名称 + */ + @TableField(value = "dept") + @NotNull(message = "dept不能为空") + private String dept; + + /** + * 疾病名称 + */ + @TableField(value = "diagnose") + @NotNull(message = "diagnose不能为空") + private String diagnose; + + /** + * 医生姓名 + */ + @TableField(value = "doctor") + @NotNull(message = "doctor不能为空") + private String doctor; + + /** + * 上传问诊平台状态。0:未上传 1:已上传 + */ + @TableField(value = "up_type") + @NotNull(message = "upType不能为空") + private Integer upType; + + /** + * 上传时间 + */ + @TableField(value = "up_time",fill = FieldFill.UPDATE) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date upTime; + + /** + * 创建时间 + */ + @TableField(value = "createdtime",fill = FieldFill.INSERT) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @NotNull(message = "createdtime不能为空") + private Date createdtime; + /** + * 筛选开始时间 + */ + private Date startCreatedtime; + /** + * 筛选结束时间 + */ + private Date endCreatedtime; + /** + * 综合查询(姓名/电话/身份证) + */ + private String synthesisQuery; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + LymsHisInfo other = (LymsHisInfo) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getVccardno() == null ? other.getVccardno() == null : this.getVccardno().equals(other.getVccardno())) + && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) + && (this.getSex() == null ? other.getSex() == null : this.getSex().equals(other.getSex())) + && (this.getBirthday() == null ? other.getBirthday() == null : this.getBirthday().equals(other.getBirthday())) + && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())) + && (this.getIdcard() == null ? other.getIdcard() == null : this.getIdcard().equals(other.getIdcard())) + && (this.getDept() == null ? other.getDept() == null : this.getDept().equals(other.getDept())) + && (this.getDiagnose() == null ? other.getDiagnose() == null : this.getDiagnose().equals(other.getDiagnose())) + && (this.getDoctor() == null ? other.getDoctor() == null : this.getDoctor().equals(other.getDoctor())) + && (this.getUpType() == null ? other.getUpType() == null : this.getUpType().equals(other.getUpType())) + && (this.getUpTime() == null ? other.getUpTime() == null : this.getUpTime().equals(other.getUpTime())) + && (this.getCreatedtime() == null ? other.getCreatedtime() == null : this.getCreatedtime().equals(other.getCreatedtime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getVccardno() == null) ? 0 : getVccardno().hashCode()); + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + ((getSex() == null) ? 0 : getSex().hashCode()); + result = prime * result + ((getBirthday() == null) ? 0 : getBirthday().hashCode()); + result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode()); + result = prime * result + ((getIdcard() == null) ? 0 : getIdcard().hashCode()); + result = prime * result + ((getDept() == null) ? 0 : getDept().hashCode()); + result = prime * result + ((getDiagnose() == null) ? 0 : getDiagnose().hashCode()); + result = prime * result + ((getDoctor() == null) ? 0 : getDoctor().hashCode()); + result = prime * result + ((getUpType() == null) ? 0 : getUpType().hashCode()); + result = prime * result + ((getUpTime() == null) ? 0 : getUpTime().hashCode()); + result = prime * result + ((getCreatedtime() == null) ? 0 : getCreatedtime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", vccardno=").append(vccardno); + sb.append(", name=").append(name); + sb.append(", sex=").append(sex); + sb.append(", birthday=").append(birthday); + sb.append(", phone=").append(phone); + sb.append(", idcard=").append(idcard); + sb.append(", dept=").append(dept); + sb.append(", diagnose=").append(diagnose); + sb.append(", doctor=").append(doctor); + sb.append(", upType=").append(upType); + sb.append(", upTime=").append(upTime); + sb.append(", createdtime=").append(createdtime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java new file mode 100644 index 0000000..85ac5af --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java @@ -0,0 +1,12 @@ +package com.lyms.talkonlineweb.service; + +import com.lyms.talkonlineweb.domain.LymsHisInfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface LymsHisInfoService extends IService { + + String upHisInfo(LymsHisInfo lymsHisInfo); +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java new file mode 100644 index 0000000..62bbb69 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java @@ -0,0 +1,252 @@ +package com.lyms.talkonlineweb.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lyms.talkonlineweb.domain.*; +import com.lyms.talkonlineweb.result.BaseResponse; +import com.lyms.talkonlineweb.service.*; +import com.lyms.talkonlineweb.mapper.LymsHisInfoMapper; +import com.lyms.talkonlineweb.util.Constant; +import com.lyms.talkonlineweb.util.StringUtil; +import com.lyms.talkonlineweb.util.WeiXinUtil; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * + */ +@Service +@Log4j2 +public class LymsHisInfoServiceImpl extends ServiceImpl + implements LymsHisInfoService{ + + @Value("${patient.hospitalName}")//配置yml 医院名称 + public String hospitalName; + @Value("${patient.hospital}")//配置yml 医院id + public Integer hospital; + @Autowired + private LymsDictService lymsDictService; + @Autowired + private LymsPatientService lymsPatientService;//患者 + @Autowired + private LymsHdepartService lymsHdepartService;//科室 + @Autowired + private LymsDoctorService lymsDoctorService;//医生 + @Autowired + private LymsPcaseService lymsPcaseService;//病例 + @Autowired + private LymsIllnessService lymsIllnessService;//疾病 + @Autowired + private LymsTcardService lymsTcardService;//问诊卡信息 + + + @Override + public String upHisInfo(LymsHisInfo lymsHisInfo) { + return collateData(lymsHisInfo); + } + + /** + * 处理数据,执行 +// * @param lymsHisInfo + */ + private String collateData(LymsHisInfo lymsHisInfo){ + if(null!=lymsHisInfo) { + //姓名 + String name = lymsHisInfo.getName(); + //性别 + Integer sex = null; + if("男".equals(lymsHisInfo.getSex())){ + sex=1; + }else if("女".equals(lymsHisInfo.getSex())){ + sex=2; + } + //生日 + String birthday = lymsHisInfo.getBirthday(); + //电话 + String phone = lymsHisInfo.getPhone(); + //科室 + Integer deptId = null;//科室id + String deptName = lymsHisInfo.getDept(); + LymsHdepart depart = new LymsHdepart(); + depart.setDname(deptName); + depart.setHid(hospital); + LymsHdepart lymsHdeparts = lymsHdepartService.getOne(Wrappers.query(depart)); + if (null!=lymsHdeparts) { + deptId = lymsHdeparts.getDid(); + }else { + return "医院科室不存在,请增加"+deptName; + } + //医生 + Integer doctorId = null;//医生id + String doctorName = lymsHisInfo.getDoctor(); + LymsDoctor doctor = new LymsDoctor(); + doctor.setHid(hospital); + doctor.setDpid(deptId); + doctor.setDname(doctorName); + List lymsDoctors = lymsDoctorService.list(Wrappers.query(doctor)); + if (CollectionUtils.isNotEmpty(lymsDoctors)) { + doctorId = lymsDoctors.get(0).getDid(); + }else { + return "医生不存在,请在"+deptName+"下面增加"+doctorName+"医生!"; + } + + //疾病 + String[] diagnoses =lymsHisInfo.getDiagnose().split(","); + List diagnoseIds = new ArrayList<>();//疾病ids + if (null != diagnoses) { + for (String diagnose : diagnoses) { + LymsDict dict = new LymsDict(); + dict.setVtype(3); + dict.setValue(diagnose); + List dictList = lymsDictService.list(Wrappers.query(dict)); + if (CollectionUtils.isNotEmpty(dictList)) { + for (LymsDict lymsDict : dictList) { + diagnoseIds.add(lymsDict.getCode().toString()); + } + } + } + } + //如果有疾病在数据库中不存在,则都不予上传 + if(diagnoses.length-1!=diagnoseIds.size()){ + return "疾病不存在,请在设置-字典管理中添加疾病:"+lymsHisInfo.getDiagnose(); + } + //患者(身份证) + String idCard = lymsHisInfo.getIdcard(); + //判断患者是否存在 + LymsPatient patientQuery = new LymsPatient(); + patientQuery.setIdno(idCard.toLowerCase()); + LymsPatient patient = lymsPatientService.getOne(Wrappers.query(patientQuery)); + if (null != patient) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("pid", patient.getId()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 00);//时 + calendar.set(Calendar.MINUTE, 00);//分 + calendar.set(Calendar.SECOND, 00);//秒 + queryWrapper.ge("createdtime", calendar.getTime()); + int count = lymsPcaseService.count(queryWrapper); + //如果今天有这个患者病例不用添加(这里防止同一天平台添加后。his有该患者病例。重复添加) + if (count != 0) { + return null; + } + } + //添加患者信息及病例 + LymsPatient patient2 = new LymsPatient(); + LymsPcase pcase = new LymsPcase(); + patient2.setPname(name); + patient2.setIdno(idCard); + patient2.setBirth(birthday); + patient2.setSex(sex); + patient2.setCcnt(0); + patient2.setCreatedby(1); + pcase.setMobile(phone); + pcase.setHid(hospital); + pcase.setHname(hospitalName); + pcase.setDid(deptId); + pcase.setDname(deptName); + pcase.setDtid(doctorId); + pcase.setDtname(doctorName); + pcase.setCreatedby(1); + String illness = StringUtils.join(Arrays.asList(diagnoseIds.toArray()), ",");//疾病ids + BaseResponse baseResponse = saveOrUpdatePatient(patient2, pcase, illness); + if (null != baseResponse && 0 == baseResponse.getErrorcode()) { + log.info(">>>>>>>>>>>>>>>患者添加成功!"); + } + } + return null; + } + + //添加修改患者方法 + public BaseResponse saveOrUpdatePatient(LymsPatient patient, LymsPcase pcase, String illness) { + BaseResponse baseResponse = new BaseResponse(); + log.info(">>>>>>>>>>>>>>>登记病例"); + baseResponse.setErrormsg(""); + patient.setIdno(patient.getIdno().toLowerCase()); + LymsPatient tmpP=new LymsPatient(); + tmpP.setIdno(patient.getIdno().toLowerCase()); + LymsPatient patient2 = lymsPatientService.getOne(Wrappers.query(tmpP).eq("idno", patient.getIdno())); + if (patient2 == null) { + patient.setCreatedtime(new Date()); + patient.setPpasswd(Constant.COMMON_PASSWD); + } else { + patient.setId(patient2.getId()); + patient.setUpdatedtime(new Date()); + patient.setCcnt(patient2.getCcnt()+ (null== patient.getCcnt()?0:patient.getCcnt())); + } + + + if (!StringUtil.isEmpty(patient.getCode())) { + patient.setOpenid(WeiXinUtil.getWxOpenId(patient.getCode())); + } + + boolean f = lymsPatientService.saveOrUpdate(patient); + +// 添加病例 + pcase.setCreatedby(patient.getCreatedby()); + pcase.setPid(patient.getId()); + pcase.setCreatedtime(new Date()); + f = lymsPcaseService.saveOrUpdate(pcase); + String[] iArr = illness.split(","); + + log.info(patient); + log.info(pcase); + + Map param = new HashMap(); + param.put("vtype",3); + List dLst=lymsDictService.listByMap(param); + for (int i = 0; i < iArr.length; i++) { + LymsIllness ness = new LymsIllness(); + ness.setCreatedby(patient.getCreatedby()); + ness.setPcid(pcase.getPcid()); + ness.setIid(Integer.parseInt(iArr[i])); + ness.setCreatedtime(new Date()); + + dLst.forEach(e->{ + if(e.getCode().intValue()==ness.getIid().intValue()){ + ness.setIname(e.getValue()); + } + }); + + param.clear(); + param.put("pcid", pcase.getPcid()); + param.put("iid", iArr[i]); + List iLst = lymsIllnessService.listByMap(param); + if (iLst.size() > 0) { + ness.setId(iLst.get(0).getId()); + } + f = lymsIllnessService.saveOrUpdate(ness); + log.info(ness.toString()); + } + + Date instDate = new Date(); + //需要添加医院购买卡记录 + for (int i = 0; i < patient.getCcnt() && Objects.nonNull(patient.getCcnt()); i++) { + LymsTcard tcard = new LymsTcard(); + tcard.setCnt(1); + tcard.setPcid(pcase.getPcid()); + tcard.setPid(patient.getId()); + tcard.setFid(2); + tcard.setCreatedby(patient.getCreatedby()); + tcard.setCreatedtime(instDate); + + lymsTcardService.saveOrUpdate(tcard); + } + baseResponse.setObject(patient); + baseResponse.setErrorcode(f == true ? 0 : 1); + return baseResponse; + } + + +} + + + + diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java index cd00ce8..1348854 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java @@ -10,15 +10,17 @@ import com.lyms.talkonlineweb.domain.*; import com.lyms.talkonlineweb.result.BaseResponse; import com.lyms.talkonlineweb.service.*; import com.lyms.talkonlineweb.util.*; -//import com.sun.deploy.util.StringUtils; import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.validation.BindingResult; import org.springframework.validation.MapBindingResult; +import org.springframework.scheduling.annotation.Scheduled; import org.w3c.dom.ls.LSInput; +import javax.swing.event.ListDataEvent; import java.util.*; import static com.lyms.talkonlineweb.util.DateUtil.YYYY_MM_DD; @@ -53,14 +55,16 @@ public class GetPatientInfoTask { private LymsIllnessService lymsIllnessService;//疾病 @Autowired private LymsTcardService lymsTcardService;//问诊卡信息 + @Autowired + private LymsHisInfoService lymsHisInfoService;//问诊卡信息 /** * 获取医院患者信息。添加到问诊平台患者信息 * 10分钟执行一次 */ -// @Scheduled(cron = "0 */10 * * * ?") - public void getPatientInfo(){ + @Scheduled(cron = "0 */10 * * * ?") + public void getPatientInfo() throws Exception { //每次执行时间范围是上一个小时 String param = collateTime(); if (StringUtil.isNotEmpty(param)) { @@ -72,9 +76,26 @@ public class GetPatientInfoTask { List> listMap = (List>) resultMap.get("patients"); if (CollectionUtils.isNotEmpty(listMap)) { for (Map map : listMap) { - - //处理数据 - collateData(map); + //添加到数据后续页面处理 + LymsHisInfo hisInfoMap = (LymsHisInfo) BeanUtils.mapToObject(map, LymsHisInfo.class);//map转对象 + if (null != hisInfoMap) { + //今天添加过不需要重复添加 + QueryWrapper qurey = new QueryWrapper(); + qurey.eq("idCard", hisInfoMap.getIdcard()); + qurey.eq("diagnose", hisInfoMap.getDiagnose()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 00);//时 + calendar.set(Calendar.MINUTE, 00);//分 + calendar.set(Calendar.SECOND, 00);//秒 + qurey.gt("createdtime", calendar.getTime()); + List list = lymsHisInfoService.list(qurey); + if (CollectionUtils.isEmpty(list)) { + hisInfoMap.setBirthday(StringUtil.isNotEmpty(hisInfoMap.getBirthday()) ? StringUtil.leftTruncate(hisInfoMap.getBirthday(), ' ') : null); + hisInfoMap.setUpType(0);//默认未上传 + lymsHisInfoService.save(hisInfoMap); + } + } } } } @@ -83,131 +104,6 @@ public class GetPatientInfoTask { } /** - * //处理数据,执行 - * @param map - */ - private void collateData(Map map){ - String deptName="",doctorName="";//科室名称,医生名称 - String[] diagnoses=null;//疾病名称 - String name="",sex="",birthday="",phone="",idCard="";//姓名,性别,生日、电话、身份证 - List diagnoseIds=new ArrayList<>();//疾病ids - Integer deptId=null;//科室id - Integer doctorId=null;//医生id - //姓名 - name=null!=map.get("name")?map.get("name").toString():null; - //性别 - sex=null!=map.get("sex")?map.get("sex").toString():null; - if("男".equals(sex)){ - sex="1"; - }else if("女".equals(sex)){ - sex="2"; - } - //生日 - birthday=null!=map.get("birthday")?map.get("birthday").toString():null; - birthday=StringUtil.leftTruncate(birthday, ' '); - //电话 - phone=null!=map.get("phone")?map.get("phone").toString():null; - //科室 - deptName=null!=map.get("dept")?map.get("dept").toString():null; - if(StringUtil.isNotEmpty(deptName)){ - LymsHdepart depart=new LymsHdepart(); - depart.setDname(deptName); - List list=lymsHdepartService.list(Wrappers.query(depart)); - if(CollectionUtils.isNotEmpty(list)){ - deptId=list.get(0).getDid(); - } - } - //医生 - doctorName=null!=map.get("doctor")?map.get("doctor").toString():null; - LymsDoctor doctor=new LymsDoctor(); - if(StringUtil.isNotEmpty(doctorName)){ - doctor.setDname(doctorName); - List list = lymsDoctorService.list(Wrappers.query(doctor)); - if(CollectionUtils.isNotEmpty(list)){ - doctorId=list.get(0).getDid(); - } - } - - //疾病 - diagnoses=null!=map.get("diagnose")?map.get("diagnose").toString().split(","):null; - if(null!=diagnoses){ - for (String diagnose : diagnoses) { - LymsDict dict=new LymsDict(); - dict.setVtype(3); - dict.setValue(diagnose); - List dictList=lymsDictService.list(Wrappers.query(dict)); - if(CollectionUtils.isNotEmpty(dictList)){ - for (LymsDict lymsDict : dictList) { - diagnoseIds.add(lymsDict.getCode().toString()); - } - } - } - } - - //患者(身份证) - idCard=null!=map.get("idCard")?map.get("idCard").toString():null; - if(StringUtil.isNotEmpty(idCard)){ - LymsPatient patientQuery=new LymsPatient(); - patientQuery.setIdno(idCard.toLowerCase()); - LymsPatient patient = lymsPatientService.getOne(Wrappers.query(patientQuery)); - //整理添加修改接口@PostMapping("savePatient")需要的数据 - LymsPatient patient2=new LymsPatient(); - LymsPcase pcase=new LymsPcase(); - patient2.setPname(name); - patient2.setIdno(idCard); - patient2.setBirth(birthday); - patient2.setSex(Integer.parseInt(sex)); - patient2.setCcnt(0); - patient2.setCreatedby(1); - pcase.setMobile(phone); - pcase.setHid(hospital); - pcase.setHname(hospitalName); - pcase.setDid(deptId); - pcase.setDname(deptName); - pcase.setDtid(doctorId); - pcase.setDtname(doctorName); - pcase.setCreatedby(1); - if(null==patient){//没有该患者需要添加 - if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(sex) && - StringUtil.isNotEmpty(birthday) && StringUtil.isNotEmpty(phone) && - StringUtil.isNotEmpty(idCard) && CollectionUtils.isNotEmpty(diagnoseIds) && - null!=deptId && null!=doctorId){ -// String illness= StringUtils.join(Arrays.asList(diagnoseIds.toArray()), ",");//疾病ids -// BaseResponse baseResponse = saveOrUpdatePatient(patient2, pcase, illness); -// if(null!=baseResponse && 0== baseResponse.getErrorcode()){ -// log.info(">>>>>>>>>>>>>>>患者添加成功!"); -// } - } - }else { - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.eq("pid", patient.getId()); - queryWrapper.in("pid", patient.getId()); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 00);//时 - calendar.set(Calendar.MINUTE, 00);//分 - calendar.set(Calendar.SECOND, 00);//秒 - queryWrapper.gt("createdtime", calendar.getTime()); - int count = lymsPcaseService.count(queryWrapper); - //如果今天没有这个患者病例需要添加 - if(count==0){ - if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(sex) && - StringUtil.isNotEmpty(birthday) && StringUtil.isNotEmpty(phone) && - StringUtil.isNotEmpty(idCard) && CollectionUtils.isNotEmpty(diagnoseIds) && - null!=deptId && null!=doctorId){ -// String illness= StringUtils.join(Arrays.asList(diagnoseIds.toArray()), ",");//疾病ids -// BaseResponse baseResponse = saveOrUpdatePatient(patient2, pcase, illness); -// if(null!=baseResponse && 0== baseResponse.getErrorcode()){ -// log.info(">>>>>>>>>>>>>>>患者添加成功!"); -// } - } - }else { - return; - } - } - } - } - /** * //整理GET请求时间 * //每次执行时间范围是上一个小时 * @return string param:GET请求时间参数 @@ -241,85 +137,7 @@ public class GetPatientInfoTask { param="start=2022-02-20+13:25:59&end=2022-02-20+14:25:59";//测试用 return param; } - //添加修改患者方法 - public BaseResponse saveOrUpdatePatient(LymsPatient patient, LymsPcase pcase, String illness) { - BaseResponse baseResponse = new BaseResponse(); - log.info(">>>>>>>>>>>>>>>登记病例"); - baseResponse.setErrormsg(""); - patient.setIdno(patient.getIdno().toLowerCase()); - LymsPatient tmpP=new LymsPatient(); - tmpP.setIdno(patient.getIdno().toLowerCase()); - LymsPatient patient2 = lymsPatientService.getOne(Wrappers.query(tmpP).eq("idno", patient.getIdno())); - if (patient2 == null) { - patient.setCreatedtime(new Date()); - patient.setPpasswd(Constant.COMMON_PASSWD); - } else { - patient.setId(patient2.getId()); - patient.setUpdatedtime(new Date()); - patient.setCcnt(patient2.getCcnt()+ (null== patient.getCcnt()?0:patient.getCcnt())); - } - - - if (!StringUtil.isEmpty(patient.getCode())) { - patient.setOpenid(WeiXinUtil.getWxOpenId(patient.getCode())); - } - - boolean f = lymsPatientService.saveOrUpdate(patient); - -// 添加病例 - pcase.setCreatedby(patient.getCreatedby()); - pcase.setPid(patient.getId()); - pcase.setCreatedtime(new Date()); - f = lymsPcaseService.saveOrUpdate(pcase); - String[] iArr = illness.split(","); - - log.info(patient); - log.info(pcase); - Map param = new HashMap(); - param.put("vtype",3); - List dLst=lymsDictService.listByMap(param); - for (int i = 0; i < iArr.length; i++) { - LymsIllness ness = new LymsIllness(); - ness.setCreatedby(patient.getCreatedby()); - ness.setPcid(pcase.getPcid()); - ness.setIid(Integer.parseInt(iArr[i])); - ness.setCreatedtime(new Date()); - - dLst.forEach(e->{ - if(e.getCode().intValue()==ness.getIid().intValue()){ - ness.setIname(e.getValue()); - } - }); - - param.clear(); - param.put("pcid", pcase.getPcid()); - param.put("iid", iArr[i]); - List iLst = lymsIllnessService.listByMap(param); - if (iLst.size() > 0) { - ness.setId(iLst.get(0).getId()); - } - f = lymsIllnessService.saveOrUpdate(ness); - log.info(ness.toString()); - } - - Date instDate = new Date(); - //需要添加医院购买卡记录 - for (int i = 0; i < patient.getCcnt() && Objects.nonNull(patient.getCcnt()); i++) { - LymsTcard tcard = new LymsTcard(); - tcard.setCnt(1); - tcard.setPcid(pcase.getPcid()); - tcard.setPid(patient.getId()); - tcard.setFid(2); - tcard.setCreatedby(patient.getCreatedby()); - tcard.setCreatedtime(instDate); - - lymsTcardService.saveOrUpdate(tcard); - } - baseResponse.setObject(patient); - baseResponse.setErrorcode(f == true ? 0 : 1); - return baseResponse; - } } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/BeanUtils.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/BeanUtils.java new file mode 100644 index 0000000..6e98353 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/BeanUtils.java @@ -0,0 +1,186 @@ +package com.lyms.talkonlineweb.util; + +import com.alibaba.fastjson.JSONObject; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.lang.annotation.*; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class BeanUtils { + + /** + * @auther HuJiaqi + * @createTime 2016年04月07日 14时12分 + * @discription byte数组转object,建议处理异常 + */ + public static Object bytesToObject(byte[] b) { + try { + ByteArrayInputStream bis = new ByteArrayInputStream(b); + ObjectInputStream ois = new ObjectInputStream(bis); + Object obj = ois.readObject(); + ois.close(); + bis.close(); + return obj; + } catch (Exception e) { + throw new RuntimeException("byte数组转object异常", e); + } + } + + /** + * @auther HuJiaqi + * @createTime 2016年04月07日 14时14分 + * @discription object转byte数组,建议处理异常 + */ + public static byte[] objectToBytes(Object obj) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(obj); + oos.flush(); + byte[] b = bos.toByteArray(); + oos.close(); + bos.close(); + return b; + } catch (Exception e) { + throw new RuntimeException("object转byte数组异常", e); + } + } + + /** + * @auther sy + * @discription map转object,建议处理异常 + */ + //map转java对象 + public static Object mapToObject(Map map, Class beanClass) throws Exception { + String jsonStr = JSONObject.toJSONString(map); + return JSONObject.parseObject(jsonStr, beanClass); + } + + /** + * @auther sy + * @discription object转map,建议处理异常 + */ + public static Map objectToMap(Object obj) { + String jsonStr = JSONObject.toJSONString(obj); + return JSONObject.parseObject(jsonStr); + } + + + public static Map objectToObjectMap(Object obj) { + try { + Class c = obj.getClass(); + Map map = new HashMap(); + BeanInfo bi = Introspector.getBeanInfo(c); + PropertyDescriptor[] pds = bi.getPropertyDescriptors(); + for (PropertyDescriptor pd : pds) { + String key = pd.getName(); + if (!key.equals("class")) { + Object result = pd.getReadMethod().invoke(obj); + if (result != null) { + map.put(key, result); + } else { + map.put(key, ""); + } + } + } + return map; + } catch (Exception e) { + throw new RuntimeException("object转map异常" + e); + } + } + + /** + * @auther HuJiaqi + * @createTime 2016年04月07日 14时24分 + * @discription 修饰filed的自定义注解,用于复制bean + */ + @Target(ElementType.FIELD) + @Retention(RetentionPolicy.RUNTIME) + @Documented + public @interface CopyName { + String value() default ""; + } + + /** + * @auther HuJiaqi + * @createTime 2016年04月07日 16时33分 + * @discription 这个方法默认子类不会有与父类相同的field,没有处理这种情况 + */ + public static void copy(Object from, Object to) { + if (from == null || to == null) { + return; + } + Class c = from.getClass(); + Field[] fields = c.getDeclaredFields(); + c = c.getSuperclass(); + while (c != null) { + Field[] temp = c.getDeclaredFields(); + fields = merge(fields, temp); + c = c.getSuperclass(); + } + if (fields != null && fields.length > 0) { + for (Field fromField : fields) { + fromField.setAccessible(true); + String fieldName; + if (fromField.isAnnotationPresent(CopyName.class)) { + CopyName adjuster = fromField.getAnnotation(CopyName.class); + fieldName = !"".equals(adjuster.value()) ? adjuster.value() : fromField.getName(); + } else { + fieldName = fromField.getName(); + } + try { + Object obj = fromField.get(from); + Field toField = null; + c = to.getClass(); + while (c != null) { + try { + toField = c.getDeclaredField(fieldName); + break; + } catch (Exception e) { + c = c.getSuperclass(); + // 如果异常了,接着找父类 + } + } + if (toField != null) { + toField.setAccessible(true); + toField.set(to, obj); + } + } catch (Exception e) { + // 什么都不干,异常就当跳过了 + } + } + } + } + + /** + * @auther HuJiaqi + * @createTime 2016年04月08日 13时10分 + * @discription 数组合并,仅支持相同类型的数组合并 + */ + public static T[] merge(T[] array1, T[] array2) { + if ((array1 == null) && (array2 == null)) + return null; + if ((array2 == null) || (array2.length == 0)) + return array1; + if ((array1 == null) || (array1.length == 0)) + return array2; + Class c = array1.getClass().getComponentType(); + Object[] array = (Object[]) Array.newInstance(c, array1.length + array2.length); + System.arraycopy(array1, 0, array, 0, array1.length); + System.arraycopy(array2, 0, array, array1.length, array2.length); + T[] result = (T[]) array; + return result; + } +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java index 6a1cd66..0c0caf3 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java @@ -60,7 +60,7 @@ public class StringUtil { /** * 字符串截取(向左截取) * @param str 原字符串 - * @param chr 需要从哪个字符截取 + * @param chr 截取到哪个字符(不包含参数字符) * @return String 截取后字符串 */ public static String leftTruncate(String str,char chr) { @@ -69,7 +69,7 @@ public class StringUtil { char [] a = str.toCharArray(); for (int i = 0; i < a.length; i++) { if (a[i] == chr) { - result=str.substring(0,i+1); + result=str.substring(0,i); break; } } diff --git a/talkonlineweb/src/main/resources/mapper/LymsHisInfoMapper.xml b/talkonlineweb/src/main/resources/mapper/LymsHisInfoMapper.xml new file mode 100644 index 0000000..b4dcdf0 --- /dev/null +++ b/talkonlineweb/src/main/resources/mapper/LymsHisInfoMapper.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + id,vcCardNo,name, + sex,birthday,phone, + idCard,dept,diagnose, + doctor,up_type,up_time, + createdtime + + -- 1.8.3.1