DiseaseService.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package com.yihu.figure.service;
  2. import com.yihu.figure.dao.disease.InspectionDao;
  3. import com.yihu.figure.dao.disease.VisitDao;
  4. import com.yihu.figure.model.disease.Inspection;
  5. import com.yihu.figure.model.disease.Visit;
  6. import com.yihu.figure.util.DateUtil;
  7. import com.yihu.figure.util.HttpClientUtil;
  8. import org.json.JSONArray;
  9. import org.json.JSONObject;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  12. import org.springframework.jdbc.core.JdbcTemplate;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import org.springframework.util.StringUtils;
  16. import java.net.URLEncoder;
  17. import java.time.LocalDate;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. /**
  21. * Created by chenweida on 2017/3/6.
  22. */
  23. @Service
  24. public class DiseaseService {
  25. private String baseurl = "http://120.41.252.108:8181/figure/";
  26. @Autowired
  27. private VisitDao visitDao;
  28. @Autowired
  29. private InspectionDao inspectionDao;
  30. @Autowired
  31. private JdbcTemplate jdbcTemplate;
  32. /**
  33. * 造就诊事件的数据
  34. *
  35. * @param strSSID
  36. */
  37. @Transactional
  38. public void getResidentEventListJson(String strSSID,String patientCode) {
  39. String url = baseurl + "data/getResidentEventListJson?strSSID=" + strSSID;
  40. String response = HttpClientUtil.get(url, "UTF-8");
  41. JSONObject obj = new JSONObject(response);
  42. if (obj.has("门诊")) {
  43. List<Visit> visits = new ArrayList<>();
  44. JSONArray ja = obj.getJSONArray("门诊");
  45. for (int i = 0; i < ja.length(); i++) {
  46. JSONObject jo = ja.getJSONObject(i);
  47. Visit visit = new Visit(patientCode);
  48. visit.setDiagnosis(jo.getString("DIAGNOSIS"));
  49. visit.setEndTime(DateUtil.strToDate(jo.getString("END_TIME"), "yyyy-MM-dd HH:mm:ss"));
  50. visit.setEvent(jo.getString("EVENT"));
  51. visit.setOrgId(jo.getInt("ORG_ID"));
  52. visit.setOrgName(jo.getString("ORG_NAME"));
  53. visit.setR(jo.getInt("R") + "");
  54. visit.setType(jo.getInt("TYPE") + "");
  55. visit.setIcdCode(jo.getString("ICD_CODE"));
  56. visits.add(visit);
  57. }
  58. visitDao.save(visits);
  59. }
  60. if (obj.has("住院")) {
  61. List<Visit> visits = new ArrayList<>();
  62. JSONArray ja = obj.getJSONArray("住院");
  63. for (int i = 0; i < ja.length(); i++) {
  64. JSONObject jo = ja.getJSONObject(i);
  65. Visit visit = new Visit();
  66. visit.setDiagnosis(jo.getString("DIAGNOSIS"));
  67. visit.setEndTime(DateUtil.strToDate(jo.getString("END_TIME"), "yyyy-MM-dd HH:mm:ss"));
  68. visit.setEvent(jo.getString("EVENT"));
  69. visit.setOrgId(jo.getInt("ORG_ID"));
  70. visit.setOrgName(jo.getString("ORG_NAME"));
  71. visit.setR(jo.getInt("R") + "");
  72. visit.setType(jo.getInt("TYPE") + "");
  73. visit.setIcdCode(jo.getString("ICD_CODE"));
  74. visits.add(visit);
  75. }
  76. visitDao.save(visits);
  77. }
  78. }
  79. /**
  80. * 造检查检验的数据
  81. *
  82. * @param strSSID
  83. */
  84. @Transactional
  85. public void GetRecordListByCatalogcodesJson(String strSSID,String patientCode) {
  86. String url = baseurl + "data/GetRecordListByCatalogcodesJson?strSSID=" + strSSID;
  87. String response = HttpClientUtil.get(url, "UTF-8");
  88. JSONObject obj = new JSONObject(response);
  89. if (obj.has("检查")) {
  90. List<Inspection> inspections = new ArrayList<>();
  91. JSONArray ja = obj.getJSONArray("检查");
  92. for (int i = 0; i < ja.length(); i++) {
  93. JSONObject jo = ja.getJSONObject(i);
  94. Inspection inspection = new Inspection(patientCode);
  95. inspection.setCatalogCode(jo.getString("CATALOG_CODE"));
  96. inspection.setEhrCommitTime(DateUtil.strToDate(jo.getString("EHR_COMMIT_TIME"), "yyyy-MM-dd HH:mm:ss"));
  97. inspection.setEndTime(DateUtil.strToDate(jo.getString("END_TIME"), "yyyy-MM-dd HH:mm:ss"));
  98. inspection.setEvent(jo.getString("EVENT"));
  99. inspection.setItem(jo.getString("ITEM"));
  100. inspection.setOrgId(jo.getInt("ORG_ID"));
  101. inspection.setOrgName(jo.getString("ORG_NAME"));
  102. inspection.setR(jo.getInt("R"));
  103. inspection.setSerial(jo.getInt("SERIAL")+"");
  104. inspection.setType(jo.getInt("TYPE")+"");
  105. inspection.setUnionssid(jo.getString("UNIONSSID"));
  106. inspection.setXmanId(jo.getString("XMAN_ID"));
  107. inspections.add(inspection);
  108. }
  109. inspectionDao.save(inspections);
  110. }
  111. }
  112. /**
  113. *
  114. * @param patientCode
  115. * @param time 2015
  116. * @return
  117. */
  118. public List<Visit> getVisits(String patientCode,String time,String icdName) {
  119. StringBuffer sql=new StringBuffer("select * from figure_visit f where 1=1 and f.patient_code =? ");
  120. List<Object> params=new ArrayList<>();
  121. params.add(patientCode);
  122. if(!StringUtils.isEmpty(time)){
  123. sql.append(" and f.end_time >= ? ");
  124. params.add( LocalDate.of(Integer.valueOf(time),1,1).toString());
  125. sql.append(" and f.end_time < ? ");
  126. params.add( LocalDate.of(Integer.valueOf(time),1,1).plusYears(1).toString());
  127. }
  128. if(!StringUtils.isEmpty(icdName)){
  129. sql.append(" and f.diagnosis like ? ");
  130. params.add("%"+icdName+"%");
  131. }
  132. List<Visit> visisList= jdbcTemplate.query(sql.toString(),params.toArray(),new BeanPropertyRowMapper(Visit.class));
  133. return visisList;
  134. }
  135. public List<Inspection> getInspections(String patientCode,String time) {
  136. StringBuffer sql=new StringBuffer("select * from figure_inspection f where 1=1 and f.patient_code =? ");
  137. List<Object> params=new ArrayList<>();
  138. params.add(patientCode);
  139. if(!StringUtils.isEmpty(time)){
  140. sql.append(" and f.end_time >= ? ");
  141. params.add( LocalDate.of(Integer.valueOf(time),1,1).toString());
  142. sql.append(" and f.end_time < ? ");
  143. params.add( LocalDate.of(Integer.valueOf(time),1,1).plusYears(1).toString());
  144. }
  145. List<Inspection> inspectionList= jdbcTemplate.query(sql.toString(),params.toArray(),new BeanPropertyRowMapper(Inspection.class));
  146. return inspectionList;
  147. }
  148. }