Commit 13c5ed71c73a4ad94606f81b8b124723b3240fb3
1 parent
949e7818b5
Exists in
master
and in
1 other branch
获取医院患者信息。添加到问诊平台患者信息,10分钟执行一次
Showing 3 changed files with 406 additions and 0 deletions
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/GetPatientInfoTask.java
View file @
13c5ed7
1 | +package com.lyms.talkonlineweb.task; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSON; | |
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
5 | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |
6 | +import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |
7 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |
8 | +import com.lyms.talkonlineweb.controller.PatientController; | |
9 | +import com.lyms.talkonlineweb.domain.*; | |
10 | +import com.lyms.talkonlineweb.result.BaseResponse; | |
11 | +import com.lyms.talkonlineweb.service.*; | |
12 | +import com.lyms.talkonlineweb.util.*; | |
13 | +import com.sun.deploy.util.StringUtils; | |
14 | +import lombok.extern.log4j.Log4j2; | |
15 | +import org.springframework.beans.factory.annotation.Autowired; | |
16 | +import org.springframework.beans.factory.annotation.Value; | |
17 | +import org.springframework.stereotype.Component; | |
18 | +import org.springframework.validation.BindingResult; | |
19 | +import org.springframework.validation.MapBindingResult; | |
20 | +import org.w3c.dom.ls.LSInput; | |
21 | + | |
22 | +import java.util.*; | |
23 | + | |
24 | +import static com.lyms.talkonlineweb.util.DateUtil.YYYY_MM_DD; | |
25 | + | |
26 | +/** | |
27 | + * 获取医院患者信息任务 | |
28 | + */ | |
29 | + | |
30 | +@Component | |
31 | +@Log4j2 | |
32 | +public class GetPatientInfoTask { | |
33 | + | |
34 | + @Autowired | |
35 | + private PatientInfoService patientInfoService; | |
36 | + @Autowired | |
37 | + private LymsDictService lymsDictService; | |
38 | + @Value("${patient.url}") | |
39 | + public String url;//配置yml 获取患者接口地址 | |
40 | + @Value("${patient.hospitalName}")//配置yml 医院名称 | |
41 | + public String hospitalName; | |
42 | + @Value("${patient.hospital}")//配置yml 医院id | |
43 | + public Integer hospital; | |
44 | + @Autowired | |
45 | + private LymsPatientService lymsPatientService;//患者 | |
46 | + @Autowired | |
47 | + private LymsHdepartService lymsHdepartService;//科室 | |
48 | + @Autowired | |
49 | + private LymsDoctorService lymsDoctorService;//医生 | |
50 | + @Autowired | |
51 | + private LymsPcaseService lymsPcaseService;//病例 | |
52 | + @Autowired | |
53 | + private LymsIllnessService lymsIllnessService;//疾病 | |
54 | + @Autowired | |
55 | + private LymsTcardService lymsTcardService;//问诊卡信息 | |
56 | + | |
57 | + | |
58 | + /** | |
59 | + * 获取医院患者信息。添加到问诊平台患者信息 | |
60 | + * 10分钟执行一次 | |
61 | + */ | |
62 | +// @Scheduled(cron = "0 */10 * * * ?") | |
63 | + public void getPatientInfo(){ | |
64 | + //每次执行时间范围是上一个小时 | |
65 | + String param = collateTime(); | |
66 | + if (StringUtil.isNotEmpty(param)) { | |
67 | + //返回数据 | |
68 | + String result = HttpUtil.getData(url + "?" + param); | |
69 | + if (StringUtil.isNotEmpty(result)) { | |
70 | + Map<String, Object> resultMap = JsonUtil.str2Map(result, HashMap.class); | |
71 | + if (CollectionUtils.isNotEmpty(resultMap)) { | |
72 | + List<Map<String, Object>> listMap = (List<Map<String, Object>>) resultMap.get("patients"); | |
73 | + if (CollectionUtils.isNotEmpty(listMap)) { | |
74 | + for (Map<String, Object> map : listMap) { | |
75 | + //处理数据 | |
76 | + collateData(map); | |
77 | + } | |
78 | + } | |
79 | + } | |
80 | + } | |
81 | + } | |
82 | + } | |
83 | + | |
84 | + /** | |
85 | + * //处理数据,执行 | |
86 | + * @param map | |
87 | + */ | |
88 | + private void collateData(Map<String,Object> map){ | |
89 | + String deptName="",doctorName="";//科室名称,医生名称 | |
90 | + String[] diagnoses=null;//疾病名称 | |
91 | + String name="",sex="",birthday="",phone="",idCard="";//姓名,性别,生日、电话、身份证 | |
92 | + List<String> diagnoseIds=new ArrayList<>();//疾病ids | |
93 | + Integer deptId=null;//科室id | |
94 | + Integer doctorId=null;//医生id | |
95 | + //姓名 | |
96 | + name=null!=map.get("name")?map.get("name").toString():null; | |
97 | + //性别 | |
98 | + sex=null!=map.get("sex")?map.get("sex").toString():null; | |
99 | + if("男".equals(sex)){ | |
100 | + sex="1"; | |
101 | + }else if("女".equals(sex)){ | |
102 | + sex="2"; | |
103 | + } | |
104 | + //生日 | |
105 | + birthday=null!=map.get("birthday")?map.get("birthday").toString():null; | |
106 | + birthday=StringUtil.leftTruncate(birthday, ' '); | |
107 | + //电话 | |
108 | + phone=null!=map.get("phone")?map.get("phone").toString():null; | |
109 | + //科室 | |
110 | + deptName=null!=map.get("dept")?map.get("dept").toString():null; | |
111 | + if(StringUtil.isNotEmpty(deptName)){ | |
112 | + LymsHdepart depart=new LymsHdepart(); | |
113 | + depart.setDname(deptName); | |
114 | + List<LymsHdepart> list=lymsHdepartService.list(Wrappers.query(depart)); | |
115 | + if(CollectionUtils.isNotEmpty(list)){ | |
116 | + deptId=list.get(0).getDid(); | |
117 | + } | |
118 | + } | |
119 | + //医生 | |
120 | + doctorName=null!=map.get("doctor")?map.get("doctor").toString():null; | |
121 | + LymsDoctor doctor=new LymsDoctor(); | |
122 | + if(StringUtil.isNotEmpty(doctorName)){ | |
123 | + doctor.setDname(doctorName); | |
124 | + List<LymsDoctor> list = lymsDoctorService.list(Wrappers.query(doctor)); | |
125 | + if(CollectionUtils.isNotEmpty(list)){ | |
126 | + doctorId=list.get(0).getDid(); | |
127 | + } | |
128 | + } | |
129 | + | |
130 | + //疾病 | |
131 | + diagnoses=null!=map.get("diagnose")?map.get("diagnose").toString().split(","):null; | |
132 | + if(null!=diagnoses){ | |
133 | + for (String diagnose : diagnoses) { | |
134 | + LymsDict dict=new LymsDict(); | |
135 | + dict.setVtype(3); | |
136 | + dict.setValue(diagnose); | |
137 | + List<LymsDict> dictList=lymsDictService.list(Wrappers.query(dict)); | |
138 | + if(CollectionUtils.isNotEmpty(dictList)){ | |
139 | + for (LymsDict lymsDict : dictList) { | |
140 | + diagnoseIds.add(lymsDict.getCode().toString()); | |
141 | + } | |
142 | + } | |
143 | + } | |
144 | + } | |
145 | + | |
146 | + //患者(身份证) | |
147 | + idCard=null!=map.get("idCard")?map.get("idCard").toString():null; | |
148 | + if(StringUtil.isNotEmpty(idCard)){ | |
149 | + LymsPatient patientQuery=new LymsPatient(); | |
150 | + patientQuery.setIdno(idCard.toLowerCase()); | |
151 | + LymsPatient patient = lymsPatientService.getOne(Wrappers.query(patientQuery)); | |
152 | + //整理添加修改接口@PostMapping("savePatient")需要的数据 | |
153 | + LymsPatient patient2=new LymsPatient(); | |
154 | + LymsPcase pcase=new LymsPcase(); | |
155 | + patient2.setPname(name); | |
156 | + patient2.setIdno(idCard); | |
157 | + patient2.setBirth(birthday); | |
158 | + patient2.setSex(Integer.parseInt(sex)); | |
159 | + patient2.setCcnt(0); | |
160 | + patient2.setCreatedby(1); | |
161 | + pcase.setMobile(phone); | |
162 | + pcase.setHid(hospital); | |
163 | + pcase.setHname(hospitalName); | |
164 | + pcase.setDid(deptId); | |
165 | + pcase.setDname(deptName); | |
166 | + pcase.setDtid(doctorId); | |
167 | + pcase.setDtname(doctorName); | |
168 | + pcase.setCreatedby(1); | |
169 | + if(null==patient){//没有该患者需要添加 | |
170 | + if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(sex) && | |
171 | + StringUtil.isNotEmpty(birthday) && StringUtil.isNotEmpty(phone) && | |
172 | + StringUtil.isNotEmpty(idCard) && CollectionUtils.isNotEmpty(diagnoseIds) && | |
173 | + null!=deptId && null!=doctorId){ | |
174 | + String illness= StringUtils.join(Arrays.asList(diagnoseIds.toArray()), ",");//疾病ids | |
175 | + BaseResponse baseResponse = saveOrUpdatePatient(patient2, pcase, illness); | |
176 | + if(null!=baseResponse && 0== baseResponse.getErrorcode()){ | |
177 | + log.info(">>>>>>>>>>>>>>>患者添加成功!"); | |
178 | + } | |
179 | + } | |
180 | + }else { | |
181 | + QueryWrapper<LymsPcase> queryWrapper=new QueryWrapper<>(); | |
182 | + queryWrapper.eq("pid", patient.getId()); | |
183 | + queryWrapper.in("pid", patient.getId()); | |
184 | + Calendar calendar = Calendar.getInstance(); | |
185 | + calendar.setTime(new Date()); | |
186 | + calendar.set(Calendar.HOUR_OF_DAY, 00);//时 | |
187 | + calendar.set(Calendar.MINUTE, 00);//分 | |
188 | + calendar.set(Calendar.SECOND, 00);//秒 | |
189 | + queryWrapper.gt("createdtime", calendar.getTime()); | |
190 | + int count = lymsPcaseService.count(queryWrapper); | |
191 | + //如果今天没有这个患者病例需要添加 | |
192 | + if(count==0){ | |
193 | + if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(sex) && | |
194 | + StringUtil.isNotEmpty(birthday) && StringUtil.isNotEmpty(phone) && | |
195 | + StringUtil.isNotEmpty(idCard) && CollectionUtils.isNotEmpty(diagnoseIds) && | |
196 | + null!=deptId && null!=doctorId){ | |
197 | + String illness= StringUtils.join(Arrays.asList(diagnoseIds.toArray()), ",");//疾病ids | |
198 | + BaseResponse baseResponse = saveOrUpdatePatient(patient2, pcase, illness); | |
199 | + if(null!=baseResponse && 0== baseResponse.getErrorcode()){ | |
200 | + log.info(">>>>>>>>>>>>>>>患者添加成功!"); | |
201 | + } | |
202 | + } | |
203 | + }else { | |
204 | + return; | |
205 | + } | |
206 | + } | |
207 | + } | |
208 | + } | |
209 | + /** | |
210 | + * //整理GET请求时间 | |
211 | + * //每次执行时间范围是上一个小时 | |
212 | + * @return string param:GET请求时间参数 | |
213 | + */ | |
214 | + private String collateTime(){ | |
215 | + String param=null; | |
216 | + String startDate=null; | |
217 | + String endDate=null; | |
218 | + Calendar calendar = Calendar.getInstance(); | |
219 | + calendar.setTime(new Date()); | |
220 | + calendar.set(Calendar.MINUTE, 00);//分 | |
221 | + calendar.set(Calendar.SECOND, 00);//秒 | |
222 | + calendar.set(Calendar.MILLISECOND, 000);//毫秒 | |
223 | + int hour = calendar.get(Calendar.HOUR_OF_DAY);//当前小时 | |
224 | + if(0==hour){ | |
225 | + calendar.add(Calendar.DATE, -1); | |
226 | + calendar.set(Calendar.HOUR_OF_DAY,23); | |
227 | + startDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); | |
228 | + calendar.add(Calendar.DATE, 1); | |
229 | + calendar.set(Calendar.HOUR_OF_DAY,00); | |
230 | + endDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); | |
231 | + }else { | |
232 | + endDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); | |
233 | + calendar.add(Calendar.HOUR_OF_DAY,-1); | |
234 | + startDate=DateUtil.getYyyyMmDdHhMmSs(calendar.getTime()); | |
235 | + } | |
236 | + if(StringUtil.isNotEmpty(startDate)&&StringUtil.isNotEmpty(endDate)){ | |
237 | + //字符串日期和时间中间的空格需要用+连接(GET请求参数特定),date转为string格式:xxxx-xx-xx xx-xx-xxx,中间得空格需要转换连接符 | |
238 | + param=("start="+startDate+"&end="+endDate).replace(" ", "+"); | |
239 | + } | |
240 | + param="start=2022-02-20+13:25:59&end=2022-02-20+14:25:59";//测试用 | |
241 | + return param; | |
242 | + } | |
243 | + //添加修改患者方法 | |
244 | + public BaseResponse saveOrUpdatePatient(LymsPatient patient, LymsPcase pcase, String illness) { | |
245 | + BaseResponse baseResponse = new BaseResponse(); | |
246 | + log.info(">>>>>>>>>>>>>>>登记病例"); | |
247 | + baseResponse.setErrormsg(""); | |
248 | + patient.setIdno(patient.getIdno().toLowerCase()); | |
249 | + LymsPatient tmpP=new LymsPatient(); | |
250 | + tmpP.setIdno(patient.getIdno().toLowerCase()); | |
251 | + LymsPatient patient2 = lymsPatientService.getOne(Wrappers.query(tmpP).eq("idno", patient.getIdno())); | |
252 | + if (patient2 == null) { | |
253 | + patient.setCreatedtime(new Date()); | |
254 | + patient.setPpasswd(Constant.COMMON_PASSWD); | |
255 | + } else { | |
256 | + patient.setId(patient2.getId()); | |
257 | + patient.setUpdatedtime(new Date()); | |
258 | + patient.setCcnt(patient2.getCcnt()+ (null== patient.getCcnt()?0:patient.getCcnt())); | |
259 | + } | |
260 | + | |
261 | + | |
262 | + if (!StringUtil.isEmpty(patient.getCode())) { | |
263 | + patient.setOpenid(WeiXinUtil.getWxOpenId(patient.getCode())); | |
264 | + } | |
265 | + | |
266 | + boolean f = lymsPatientService.saveOrUpdate(patient); | |
267 | + | |
268 | +// 添加病例 | |
269 | + pcase.setCreatedby(patient.getCreatedby()); | |
270 | + pcase.setPid(patient.getId()); | |
271 | + pcase.setCreatedtime(new Date()); | |
272 | + f = lymsPcaseService.saveOrUpdate(pcase); | |
273 | + String[] iArr = illness.split(","); | |
274 | + | |
275 | + log.info(patient); | |
276 | + log.info(pcase); | |
277 | + | |
278 | + Map param = new HashMap(); | |
279 | + param.put("vtype",3); | |
280 | + List<LymsDict> dLst=lymsDictService.listByMap(param); | |
281 | + for (int i = 0; i < iArr.length; i++) { | |
282 | + LymsIllness ness = new LymsIllness(); | |
283 | + ness.setCreatedby(patient.getCreatedby()); | |
284 | + ness.setPcid(pcase.getPcid()); | |
285 | + ness.setIid(Integer.parseInt(iArr[i])); | |
286 | + ness.setCreatedtime(new Date()); | |
287 | + | |
288 | + dLst.forEach(e->{ | |
289 | + if(e.getCode().intValue()==ness.getIid().intValue()){ | |
290 | + ness.setIname(e.getValue()); | |
291 | + } | |
292 | + }); | |
293 | + | |
294 | + param.clear(); | |
295 | + param.put("pcid", pcase.getPcid()); | |
296 | + param.put("iid", iArr[i]); | |
297 | + List<LymsIllness> iLst = lymsIllnessService.listByMap(param); | |
298 | + if (iLst.size() > 0) { | |
299 | + ness.setId(iLst.get(0).getId()); | |
300 | + } | |
301 | + f = lymsIllnessService.saveOrUpdate(ness); | |
302 | + log.info(ness.toString()); | |
303 | + } | |
304 | + | |
305 | + Date instDate = new Date(); | |
306 | + //需要添加医院购买卡记录 | |
307 | + for (int i = 0; i < patient.getCcnt() && Objects.nonNull(patient.getCcnt()); i++) { | |
308 | + LymsTcard tcard = new LymsTcard(); | |
309 | + tcard.setCnt(1); | |
310 | + tcard.setPcid(pcase.getPcid()); | |
311 | + tcard.setPid(patient.getId()); | |
312 | + tcard.setFid(2); | |
313 | + tcard.setCreatedby(patient.getCreatedby()); | |
314 | + tcard.setCreatedtime(instDate); | |
315 | + | |
316 | + lymsTcardService.saveOrUpdate(tcard); | |
317 | + } | |
318 | + baseResponse.setObject(patient); | |
319 | + baseResponse.setErrorcode(f == true ? 0 : 1); | |
320 | + return baseResponse; | |
321 | + } | |
322 | +} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/StringUtil.java
View file @
13c5ed7
1 | 1 | package com.lyms.talkonlineweb.util; |
2 | 2 | |
3 | +import java.util.Arrays; | |
4 | +import java.util.List; | |
5 | + | |
3 | 6 | /** |
4 | 7 | * @ProjectName: talkonline |
5 | 8 | * @Package: com.lyms.talkonlineweb.util |
... | ... | @@ -53,6 +56,76 @@ |
53 | 56 | |
54 | 57 | } |
55 | 58 | return ""; |
59 | + } | |
60 | + /** | |
61 | + * 字符串截取(向左截取) | |
62 | + * @param str 原字符串 | |
63 | + * @param chr 需要从哪个字符截取 | |
64 | + * @return String 截取后字符串 | |
65 | + */ | |
66 | + public static String leftTruncate(String str,char chr) { | |
67 | + String result=""; | |
68 | + if('\0'!=chr && isNotEmpty(str.trim())){ | |
69 | + char [] a = str.toCharArray(); | |
70 | + for (int i = 0; i < a.length; i++) { | |
71 | + if (a[i] == chr) { | |
72 | + result=str.substring(0,i+1); | |
73 | + break; | |
74 | + } | |
75 | + } | |
76 | + } | |
77 | + return result; | |
78 | + } | |
79 | + /** | |
80 | + * 字符串截取(向右截取) | |
81 | + * @param str 原字符串 | |
82 | + * @param chr 需要从哪个字符截取 | |
83 | + * @return String 截取后字符串 | |
84 | + */ | |
85 | + public static String rightTruncate(String str,char chr) { | |
86 | + String result=""; | |
87 | + if('\0'!=chr && isNotEmpty(str.trim())){ | |
88 | + char [] a = str.toCharArray(); | |
89 | + for (int i = 0; i < a.length; i++) { | |
90 | + if (a[i] == chr) { | |
91 | + result=str.substring(i,a.length); | |
92 | + break; | |
93 | + } | |
94 | + } | |
95 | + } | |
96 | + return result; | |
97 | + } | |
98 | + /** | |
99 | + * 字符串截取(从1个字符到另一个字符) | |
100 | + * @param str 原字符串 | |
101 | + * @param strat 开始字符截取 | |
102 | + * @param end 结束字符截取 | |
103 | + * @return String 截取后字符串 | |
104 | + */ | |
105 | + public static String strTruncate(String str,char strat,char end) { | |
106 | + String result=""; | |
107 | + if('\0'!=strat &&'\0'!=end && isNotEmpty(str) && isNotEmpty(str.trim()) ){ | |
108 | + char [] a = str.toCharArray(); | |
109 | + int s=-1; | |
110 | + int e=-1; | |
111 | + for (int i = 0; i < a.length; i++) { | |
112 | + if(s==-1) { | |
113 | + if (a[i] == strat) { | |
114 | + s = i; | |
115 | + continue; | |
116 | + } | |
117 | + }else { | |
118 | + if (a[i] == end) { | |
119 | + e=i; | |
120 | + break; | |
121 | + } | |
122 | + } | |
123 | + } | |
124 | + if(s!=-1&&e!=-1){ | |
125 | + result=str.substring(s,e+1); | |
126 | + } | |
127 | + } | |
128 | + return result; | |
56 | 129 | } |
57 | 130 | } |
talkonlineweb/src/main/resources/application.yml
View file @
13c5ed7
... | ... | @@ -16,4 +16,13 @@ |
16 | 16 | config: classpath:logback-spring.xml |
17 | 17 | |
18 | 18 | excludePath: login,test1,test2 |
19 | + | |
20 | +#获取医院患者信息配置 | |
21 | +patient: | |
22 | + #医院接口地址(String) | |
23 | + url: https://rp-zk-api.healthbaby.com.cn:8094/his/zkfy/getZkfyPatientList | |
24 | + #需要预建医院获得医院名称(String) | |
25 | + hospitalName: 石家庄第一医院 | |
26 | + #需要预建医院获得id(Integer) | |
27 | + hospital: 11 |