package com.zskk.task; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.cron4j.ITask; import com.zskk.model.Doctors; import com.zskk.model.Exams; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import static com.zskk.task.SendPostUtil.sendPost; public class DataTask implements ITask { //请求路径 public final static String url = "https://risserver3.pacsonline.cn/butt/getExam/butt/getExam"; public final static String url_ = "https://risserver3.pacsonline.cn/butt/getExam/butt/saveReport"; @Override public void run() { // TODO Auto-generated method stub try { //List exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=46400001 order by createdAt desc limit 50"); String s=sendPost(url, "institution_id", "13000003"); JSONObject jsonObject = JSONObject.parseObject(s); String data = jsonObject.getString("data"); List exams = JSONArray.parseArray(data,Exams.class); for (Exams exams2 : exams) { try { // Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId()); Record record = Db.use("connected").findFirst("select * from hhris.view_reportinfo where ACCESSIONNUMBER=?",exams2.getAccessionNum()); if (record == null) { continue; } Map params = new HashMap<>(); //exams表 params.put("exam_id",exams2.getId()); //报告医生姓名 params.put("report_doctor_name",record.getStr("REPORTDOCTOR")); //报告时间 params.put("report_datetime",record.getStr("REPORTDATE")); //审核医生姓名 params.put("review_doctor_name",record.getStr("REVIEWDOCTOR")); //审核时间 params.put("review_datetime",record.getStr("REPORTDATE")); //确认医生姓名 params.put("confirm_doctor_name",""); //确认时间 params.put("confirm_datetime",""); if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) { continue; } //意见建议 params.put("impression",record.getStr("IMPRESSION")); //影像所见 params.put("description",record.getStr("DESCRIPTION")); //exams表 //申请科室 params.put("application_department",""); //申请医生 params.put("application_doctor",""); //临床诊断 params.put("clin_diag",""); //patient_infos表 //患者姓名 params.put("name",record.getStr("PATIENTNAME")); //患者手机号 params.put("phone",record.getStr("PHONE")); //患者身份证号 params.put("card_num",record.getStr("IDCARD")); sendPost(url_, params); /* Report report = new Report().use("zskk"); report.setId(creatId()); report.setReportDatetime(parseStringToDate(record.getStr("REPORTDATE")));*/ /*report.setImpression(new String(record.getStr("IMPRESSION").getBytes("windows-1252"),"GBK")); report.setDescription(new String(record.getStr("DESCRIPTION").getBytes("windows-1252"),"GBK")); report.setExamId(exams2.getId()); report.setCreatedAt(new Date()); report.setReportDoctorId(getDoctorIdByName(new String(record.getStr("REPORTDOCTOR").getBytes("windows-1252"),"GBK"))); report.setReviewDoctorId(getDoctorIdByName(new String(record.getStr("REVIEWDOCTOR").getBytes("windows-1252"),"GBK"))); report.setReviewDatetime(parseStringToDate(new String(record.getStr("REPORTDATE").getBytes("windows-1252"),"GBK"))); report.setConfirmDoctorId(getDoctorIdByName(new String(record.getStr("REVIEWDOCTOR").getBytes("windows-1252"),"GBK"))); report.setConfirmDatetime(parseStringToDate(new String(record.getStr("REPORTDATE").getBytes("windows-1252"),"GBK")));*/ //report.save(); //PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId()); //patientInfos.setName(new String(record.getStr("PATIENTNAME").getBytes("windows-1252"),"GBK")); // patientInfos.setPhone(record.getStr("PHONE")); // patientInfos.setCardNum(record.getStr("IDCARD")); // patientInfos.update(); /* try { exams2.setClinDoctors(new String(record.getStr("CLINICALDOCTOR").getBytes("windows-1252"),"GBK")); } catch (Exception e) { // TODO: handle exception } exams2.setExamStatus(9); exams2.update(); WeixinService wService = new WeixinService(); wService.requestWeixinQrcode(report.getId());*/ } catch (Exception e) { // TODO: handle exception continue; } } } catch (Exception e) { // TODO: handle exception } } @Override public void stop() { // TODO Auto-generated method stub } private String creatId() { UUID id=UUID.randomUUID(); String[] idd = id.toString().split("-"); return idd[0]+idd[1]+idd[2]; } private String getDoctorIdByName(String name) { if (name == null) { return null; } Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=46400001 and realname<>''",name); if (doctors == null) { return null; } return doctors.getId(); } private Date parseStringToDate(String dateStr) { if (dateStr == null) { return new Date(); } SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { date = sdf.parse(dateStr); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; } }