DataTask.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package com.zskk.task;
  2. import com.jfinal.plugin.activerecord.Db;
  3. import com.jfinal.plugin.activerecord.Record;
  4. import com.jfinal.plugin.cron4j.ITask;
  5. import com.zskk.model.*;
  6. import com.zskk.service.ServiceFactory;
  7. import com.zskk.service.WeixinService;
  8. import java.text.ParseException;
  9. import java.text.SimpleDateFormat;
  10. import java.util.Date;
  11. import java.util.List;
  12. import java.util.UUID;
  13. public class DataTask implements ITask {
  14. @Override
  15. public void run() {
  16. // TODO Auto-generated method stub
  17. try {
  18. List<Exams> exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=04500002 order by createdAt desc limit 30");
  19. for (Exams exams2 : exams) {
  20. try {
  21. // Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  22. Record record = Db.use("connected").findFirst("select * from (SELECT * FROM zlhis.zskk_reportinfo zs INNER JOIN zlhis.zskk_reportinfo_1 zskk ON zs.ACCESSIONNUMBER = zskk.ACCESSIONNUMBER order by REPORTDATE desc ) where ACCESSIONNUMBER=?",exams2.getAccessionNum());
  23. if (record == null) {
  24. continue;
  25. }
  26. Report report = new Report().use("zskk");
  27. report.setId(creatId());
  28. report.setReportDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  29. if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) {
  30. continue;
  31. }
  32. report.setImpression(record.getStr("IMPRESSION"));
  33. report.setDescription(record.getStr("DESCRIPTION"));
  34. report.setExamId(exams2.getId());
  35. report.setCreatedAt(new Date());
  36. report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR")));
  37. report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  38. report.setReviewDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  39. report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  40. report.setConfirmDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  41. report.save();
  42. PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
  43. patientInfos.setName(record.getStr("PATIENTNAME"));
  44. patientInfos.setPhone(record.getStr("PHONE"));
  45. patientInfos.setCardNum(record.getStr("IDCARD"));
  46. patientInfos.update();
  47. exams2.setExamStatus(9);
  48. exams2.setApplicationDepartment(record.getStr("DEPARTMENT"));
  49. exams2.setApplicationDoctor(record.getStr("CLINICALDOCTOR"));
  50. exams2.setClinDiag(record.getStr("DIAGNOSIS"));
  51. exams2.update();
  52. WeixinService wService = ServiceFactory.getService(WeixinService.class);
  53. wService.requestWeixinQrcode(report.getId());
  54. } catch (Exception e) {
  55. // TODO: handle exception
  56. continue;
  57. }
  58. }
  59. } catch (Exception e) {
  60. // TODO: handle exception
  61. }
  62. }
  63. @Override
  64. public void stop() {
  65. // TODO Auto-generated method stub
  66. }
  67. private String creatId() {
  68. UUID id=UUID.randomUUID();
  69. String[] idd = id.toString().split("-");
  70. return idd[0]+idd[1]+idd[2];
  71. }
  72. private String getDoctorIdByName(String name) {
  73. if (name == null) {
  74. return null;
  75. }
  76. Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=04500002 and realname<>''",name);
  77. if (doctors == null) {
  78. Doctors newDoctors = new Doctors().use("zskk");
  79. newDoctors.setId(creatId());
  80. newDoctors.setUsername("none");
  81. newDoctors.setRealname(name);
  82. newDoctors.setPassword("123456");
  83. newDoctors.setInstitutionId("04500002");
  84. newDoctors.setCreatedAt(new Date());
  85. newDoctors.setUpdatedAt(new Date());
  86. newDoctors.save();
  87. return newDoctors.getId();
  88. //return null;
  89. }
  90. return doctors.getId();
  91. }
  92. private Date parseStringToDate(String dateStr) {
  93. if (dateStr == null) {
  94. return new Date();
  95. }
  96. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  97. Date date = null;
  98. try {
  99. date = sdf.parse(dateStr);
  100. } catch (ParseException e) {
  101. // TODO Auto-generated catch block
  102. e.printStackTrace();
  103. }
  104. return date;
  105. }
  106. }