DataTask.java 3.2 KB

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