ViewController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.zskk.control;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import java.util.UUID;
  8. import com.jfinal.core.Controller;
  9. import com.jfinal.plugin.activerecord.Db;
  10. import com.jfinal.plugin.activerecord.Record;
  11. import com.zskk.model.Doctors;
  12. import com.zskk.model.Exams;
  13. import com.zskk.model.PatientInfos;
  14. import com.zskk.model.Report;
  15. import com.zskk.model.Studies;
  16. public class ViewController extends Controller {
  17. /**
  18. * 在被连接数据库执行sql语句
  19. */
  20. public void executeSql() {
  21. try {
  22. List<Record> d = Db.use("connected").find("select top 5 * from viewname");
  23. this.renderJson(d);
  24. } catch (Exception e) {
  25. // TODO: handle exception
  26. this.renderText(e.toString());
  27. }
  28. }
  29. public void executeSql2() {
  30. try {
  31. String sqlString = this.getPara("str");
  32. List<Record> d = Db.use("connected").find(sqlString);
  33. this.renderJson(d);
  34. } catch (Exception e) {
  35. // TODO: handle exception
  36. this.renderText(e.toString());
  37. }
  38. }
  39. public void testTask() {
  40. try {
  41. //List<Record> d = Db.use("connected").find(this.getPara("sqlStr"));
  42. 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");
  43. List<Record> examds = new ArrayList<>();
  44. for (Exams exams2 : exams) {
  45. Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  46. Record record = Db.use("connected").findFirst("select * from caller where STUDYUID=?",studies.getStudyuid());
  47. if (record == null) {
  48. continue;
  49. }
  50. examds.add(record);
  51. Report report = new Report().use("zskk");
  52. report.setId(creatId());
  53. report.setReportDatetime(aaa(record.getStr("REPORTDATE")));
  54. report.setImpression(record.getStr("IMPRESSION"));
  55. report.setDescription(record.getStr("DESCRIPTION"));
  56. report.setExamId(exams2.getId());
  57. report.setCreatedAt(new Date());
  58. if (record.getStr("FITEM_RESULT_CODE") != null) {
  59. //report.setReportResult(record.getStr("FITEM_RESULT_CODE").contains("阴")?"1":"2");
  60. }
  61. report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR")));
  62. report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  63. report.setReviewDatetime(aaa(record.getStr("REPORTDATE")));
  64. report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  65. report.setConfirmDatetime(aaa(record.getStr("REPORTDATE")));
  66. // report.save();
  67. PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
  68. patientInfos.setName(record.getStr("PATIENTNAME"));
  69. // patientInfos.update();
  70. }
  71. this.renderJson(examds);
  72. } catch (Exception e) {
  73. // TODO: handle exception
  74. this.renderText(e.toString());
  75. }
  76. }
  77. private String creatId() {
  78. UUID id = UUID.randomUUID();
  79. String[] idd= id.toString().split("-");
  80. return idd[0]+idd[1]+idd[2];
  81. }
  82. private String getDoctorIdByName(String name) {
  83. if (name == null) {
  84. return "1";
  85. }
  86. Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=73090001",name);
  87. if (doctors == null) {
  88. return "1";
  89. }
  90. return doctors.getId();
  91. }
  92. private Date aaa(String timestr) {
  93. if (timestr == 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(timestr);
  100. } catch (ParseException e) {
  101. // TODO Auto-generated catch block
  102. e.printStackTrace();
  103. }
  104. return date;
  105. }
  106. }