diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java new file mode 100644 index 0000000..fe14950 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java @@ -0,0 +1,324 @@ +package com.lyms.talkonlineweb.task; + +import com.alibaba.fastjson.JSON; +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.plugins.pagination.Page; +import com.lyms.talkonlineweb.controller.PatientController; +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.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.w3c.dom.ls.LSInput; + +import java.util.*; + +import static com.lyms.talkonlineweb.util.DateUtil.YYYY_MM_DD; + +/** + * 获取医院患者信息任务 + */ + +@Component +@Log4j2 +public class GetPatientInfoTask { + + @Autowired + private PatientInfoService patientInfoService; + @Autowired + private LymsDictService lymsDictService; + @Value("${patient.url}") + public String url;//配置yml 获取患者接口地址 + @Value("${patient.hospitalName}")//配置yml 医院名称 + public String hospitalName; + @Value("${patient.hospital}")//配置yml 医院id + public Integer hospital; + @Autowired + private LymsPatientService lymsPatientService;//患者 + @Autowired + private LymsHdepartService lymsHdepartService;//科室 + @Autowired + private LymsDoctorService lymsDoctorService;//医生 + @Autowired + private LymsPcaseService lymsPcaseService;//病例 + @Autowired + private LymsIllnessService lymsIllnessService;//疾病 + @Autowired + private LymsTcardService lymsTcardService;//问诊卡信息 + + + /** + * 获取医院患者信息。添加到问诊平台患者信息 + * 10分钟执行一次 + */ +// @Scheduled(cron = "0 */10 * * * ?") + public void getPatientInfo(){ + //每次执行时间范围是上一个小时 + String param = collateTime(); + if (StringUtil.isNotEmpty(param)) { + //返回数据 + String result = HttpUtil.getData(url + "?" + param); + if (StringUtil.isNotEmpty(result)) { + Map resultMap = JsonUtil.str2Map(result, HashMap.class); + if (CollectionUtils.isNotEmpty(resultMap)) { + List> listMap = (List>) resultMap.get("patients"); + if (CollectionUtils.isNotEmpty(listMap)) { + for (Map map : listMap) { + //处理数据 + collateData(map); + } + } + } + } + } + } + + /** + * //处理数据,执行 + * @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请求时间参数 + */ + private String collateTime(){ + String param=null; + String startDate=null; + String endDate=null; + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.set(Calendar.MINUTE, 00);//分 + calendar.set(Calendar.SECOND, 00);//秒 + calendar.set(Calendar.MILLISECOND, 000);//毫秒 + int hour = calendar.get(Calendar.HOUR_OF_DAY);//当前小时 + if(0==hour){ + calendar.add(Calendar.DATE, -1); + calendar.set(Calendar.HOUR_OF_DAY,23); + startDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); + calendar.add(Calendar.DATE, 1); + calendar.set(Calendar.HOUR_OF_DAY,00); + endDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); + }else { + endDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); + calendar.add(Calendar.HOUR_OF_DAY,-1); + startDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); + } + if(StringUtil.isNotEmpty(startDate)&&StringUtil.isNotEmpty(endDate)){ + //字符串日期和时间中间的空格需要用+连接(GET请求参数特定),date转为string格式:xxxx-xx-xx xx-xx-xxx,中间得空格需要转换连接符 + param=("start="+startDate+"&end="+endDate).replace(" ", "+"); + } + 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/StringUtil.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java index 84fbd21..6a1cd66 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java @@ -1,5 +1,8 @@ package com.lyms.talkonlineweb.util; +import java.util.Arrays; +import java.util.List; + /** * @ProjectName: talkonline * @Package: com.lyms.talkonlineweb.util @@ -54,4 +57,74 @@ public class StringUtil { } return ""; } + /** + * 字符串截取(向左截取) + * @param str 原字符串 + * @param chr 需要从哪个字符截取 + * @return String 截取后字符串 + */ + public static String leftTruncate(String str,char chr) { + String result=""; + if('\0'!=chr && isNotEmpty(str.trim())){ + char [] a = str.toCharArray(); + for (int i = 0; i < a.length; i++) { + if (a[i] == chr) { + result=str.substring(0,i+1); + break; + } + } + } + return result; + } + /** + * 字符串截取(向右截取) + * @param str 原字符串 + * @param chr 需要从哪个字符截取 + * @return String 截取后字符串 + */ + public static String rightTruncate(String str,char chr) { + String result=""; + if('\0'!=chr && isNotEmpty(str.trim())){ + char [] a = str.toCharArray(); + for (int i = 0; i < a.length; i++) { + if (a[i] == chr) { + result=str.substring(i,a.length); + break; + } + } + } + return result; + } + /** + * 字符串截取(从1个字符到另一个字符) + * @param str 原字符串 + * @param strat 开始字符截取 + * @param end 结束字符截取 + * @return String 截取后字符串 + */ + public static String strTruncate(String str,char strat,char end) { + String result=""; + if('\0'!=strat &&'\0'!=end && isNotEmpty(str) && isNotEmpty(str.trim()) ){ + char [] a = str.toCharArray(); + int s=-1; + int e=-1; + for (int i = 0; i < a.length; i++) { + if(s==-1) { + if (a[i] == strat) { + s = i; + continue; + } + }else { + if (a[i] == end) { + e=i; + break; + } + } + } + if(s!=-1&&e!=-1){ + result=str.substring(s,e+1); + } + } + return result; + } } diff --git a/talkonlineweb/src/main/resources/application.yml b/talkonlineweb/src/main/resources/application.yml index 0d8f356..da5b414 100644 --- a/talkonlineweb/src/main/resources/application.yml +++ b/talkonlineweb/src/main/resources/application.yml @@ -16,3 +16,12 @@ logging: config: classpath:logback-spring.xml excludePath: login,test1,test2 + +#获取医院患者信息配置 +patient: + #医院接口地址(String) + url: https://rp-zk-api.healthbaby.com.cn:8094/his/zkfy/getZkfyPatientList + #需要预建医院获得医院名称(String) + hospitalName: 石家庄第一医院 + #需要预建医院获得id(Integer) + hospital: 11 \ No newline at end of file