ViewController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package com.zskk.control;
  2. import com.jfinal.core.Controller;
  3. import com.jfinal.kit.PropKit;
  4. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  5. import com.jfinal.plugin.activerecord.Db;
  6. import com.jfinal.plugin.activerecord.Record;
  7. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  8. import com.jfinal.plugin.druid.DruidPlugin;
  9. import com.zskk.model.Doctors;
  10. import com.zskk.model.Exams;
  11. import com.zskk.model.PatientInfos;
  12. import com.zskk.model.Report;
  13. import java.text.ParseException;
  14. import java.text.SimpleDateFormat;
  15. import java.util.ArrayList;
  16. import java.util.Date;
  17. import java.util.List;
  18. import java.util.UUID;
  19. public class ViewController extends Controller {
  20. /**
  21. * 在被连接数据库执行sql语句
  22. */
  23. public void executeSql() {
  24. try {
  25. List<Record> d = Db.use("connected").find("select * from (select * from reportinfo order by REPORTDATE desc) where rownum <= 20");
  26. this.renderJson(d);
  27. } catch (Exception e) {
  28. // TODO: handle exception
  29. this.renderText(e.toString());
  30. }
  31. }
  32. public void executeSql2() {
  33. try {
  34. String sqlString = this.getPara("str");
  35. List<Record> d = Db.use("connected").find(sqlString);
  36. this.renderJson(d);
  37. } catch (Exception e) {
  38. // TODO: handle exception
  39. this.renderText(e.toString());
  40. }
  41. }
  42. public void executeSql3() {
  43. try {
  44. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  45. druidPluginConnected.start();
  46. // 配置ActiveRecord插件
  47. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  48. arpConnected.setDialect(new SqlServerDialect());
  49. arpConnected.start();
  50. } catch (Exception e) {
  51. // TODO: handle exception
  52. this.renderText(e.toString());
  53. }
  54. }
  55. public static DruidPlugin createConnectedDruidPlugin() {
  56. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  57. }
  58. public void testTask() {
  59. try {
  60. //List<Record> d = Db.use("connected").find(this.getPara("sqlStr"));
  61. List<Exams> exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=46400001 order by createdAt desc limit 50");
  62. List<Record> examds = new ArrayList<>();
  63. for (Exams exams2 : exams) {
  64. // Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  65. Record record = Db.use("connected").findFirst("select * from hhris.view_reportinfo where ACCESSIONNUMBER=?",exams2.getAccessionNum());
  66. if (record == null) {
  67. continue;
  68. }
  69. Report report = new Report().use("zskk");
  70. report.setId(creatId());
  71. report.setReportDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  72. if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) {
  73. continue;
  74. }
  75. report.setImpression(new String(record.getStr("DESCRIPTION").getBytes("windows-1252"),"GBK"));
  76. report.setDescription(new String(record.getStr("IMPRESSION").getBytes("windows-1252"),"GBK"));
  77. report.setExamId(exams2.getId());
  78. report.setCreatedAt(new Date());
  79. report.setReportDoctorId(getDoctorIdByName(new String(record.getStr("REPORTDOCTOR").getBytes("windows-1252"),"GBK")));
  80. report.setReviewDoctorId(getDoctorIdByName(new String(record.getStr("REVIEWDOCTOR").getBytes("windows-1252"),"GBK")));
  81. report.setReviewDatetime(parseStringToDate(new String(record.getStr("REPORTDATE").getBytes("windows-1252"),"GBK")));
  82. report.setConfirmDoctorId(getDoctorIdByName(new String(record.getStr("REVIEWDOCTOR").getBytes("windows-1252"),"GBK")));
  83. report.setConfirmDatetime(parseStringToDate(new String(record.getStr("REPORTDATE").getBytes("windows-1252"),"GBK")));
  84. report.save();
  85. PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
  86. patientInfos.setName(new String(record.getStr("PATIENTNAME").getBytes("windows-1252"),"GBK"));
  87. patientInfos.update();
  88. exams2.setClinDoctors(new String(record.getStr("CLINICALDOCTOR").getBytes("windows-1252"),"GBK"));
  89. exams2.setExamStatus(9);
  90. exams2.update();
  91. examds.add(record);
  92. }
  93. this.renderJson(examds);
  94. } catch (Exception e) {
  95. // TODO: handle exception
  96. this.renderText(e.toString());
  97. }
  98. }
  99. private String creatId() {
  100. UUID id = UUID.randomUUID();
  101. String[] idd =id.toString().split("-");
  102. return idd[0]+idd[1]+idd[2];
  103. }
  104. private String getDoctorIdByName(String name) {
  105. if (name == null) {
  106. return "1";
  107. }
  108. Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=46400001",name);
  109. if (doctors == null) {
  110. return "1";
  111. }
  112. return doctors.getId();
  113. }
  114. private Date aaa(String timestr) {
  115. if (timestr == null) {
  116. return new Date();
  117. }
  118. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  119. Date date = null;
  120. try {
  121. date = sdf.parse(timestr);
  122. } catch (ParseException e) {
  123. // TODO Auto-generated catch block
  124. e.printStackTrace();
  125. }
  126. return date;
  127. }
  128. private Date parseStringToDate(String dateStr) {
  129. if (dateStr == null) {
  130. return new Date();
  131. }
  132. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  133. Date date = null;
  134. try {
  135. date = sdf.parse(dateStr);
  136. } catch (ParseException e) {
  137. // TODO Auto-generated catch block
  138. e.printStackTrace();
  139. }
  140. return date;
  141. }
  142. }