4a19929eab6d5988cf32028a77688b802de18927.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.springframework.util.CollectionUtils;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONObject;
  9. public class Test {
  10. public static void main(String args[]) {
  11. // String jsonStr = "[{\"事件\":{\"lab_standard\":[\"220\",\"230\"],\"diag_primitive\":[\"I220\",\"I230\"],\"event_type\":\"lab\"},\"医院\":{\"org_code\":[\"111111\",\"222222\"]},\"就诊类型\":{\"visit_type\":\"emergency\"},\"时间\":{\"time_from\":\"2018-7-2\",\"time_to\":\"2018-8-12\"},\"关系\":\"or\"},{\"事件\":{\"lab_standard\":[\"21\",\"33\"],\"diag_primitive\":[\"I220\",\"I230\"],\"event_type\":\"lab\"},\"医院\":{\"org_code\":[\"111111\",\"222222\",\"333333\"]},\"就诊类型\":{\"visit_type\":\"emergency\"},\"时间\":{\"time_from\":\"2018-7-10\",\"time_to\":\"2018-8-7\"},\"关系\":\"or\"}]";
  12. // //String jsonStr = "[{\"事件\":{\"lab_standard\":[\"220\",\"230\"],\"diag_primitive\":[\"I220\",\"I230\"],\"event_type\":\"lab\"},\"医院\":{\"org_code\":[\"111111\",\"222222\"]},\"就诊类型\":{\"visit_type\":\"outpat\"},\"时间\":{\"time_from\":\"2018-7-2\",\"time_to\":\"2018-8-12\"},\"关系\":\"or\"}]";
  13. // String setpStr = "{\"groupType\":\"年龄段\",\"interval\":\"20\",\"maxValue\":\"100\",\"minValue\":\"0\"}";
  14. // String returnSql = genGroupSql(jsonStr,setpStr);
  15. //
  16. //[{"label":"福州一院","value":"488099744"},{"label":"福州儿院","value":"48809974x"},{"label":"福州中医院","value":"488099743"},{"label":"福州传染病医院","value":"488099757"}]
  17. //[{"label":"福州一院","value":"488099744"},{"label":"福州儿院","value":"48809974x"},{"label":"福州中医院","value":"488099743"},{"label":"福州传染病医院","value":"488099757"}]
  18. Map map1 = new HashMap();
  19. map1.put("value", "488099744");
  20. map1.put("label", "福州一院");
  21. Map map2 = new HashMap();
  22. map2.put("value", "48809974x");
  23. map2.put("label", "福州儿院");
  24. Map map3 = new HashMap();
  25. map3.put("value", "488099743");
  26. map3.put("label", "福州中医院");
  27. Map map4 = new HashMap();
  28. map4.put("value", "488099757");
  29. map4.put("label", "福州传染病医院");
  30. List list = new ArrayList();
  31. list.add(map1);
  32. list.add(map2);
  33. list.add(map3);
  34. list.add(map4);
  35. String jsonString = JSONObject.toJSON(list).toString();
  36. System.out.println(jsonString);
  37. }
  38. public static String generateAgePart(int min,int max,int interval){
  39. String str = " case";
  40. int temp = min;
  41. for(int i=min;i<max;i+=interval){
  42. if(i>min){
  43. //System.out.println(temp+":"+i);
  44. if(temp==min){
  45. str += " when extract(year from age(event_time,c.birth_date)) >="+temp +" and extract(year from age(event_time,c.birth_date)) <"+i+" then '"+temp+"到"+i+"'\r\n";
  46. //
  47. }else if(i==max){
  48. // str += " when extract(year from age(temp1.diag_time,c.birth_date)) <="+max+" then '"+temp+"到"+max+"' end ";
  49. }else{
  50. str += " when extract(year from age(event_time,c.birth_date)) <"+i+" then '"+temp+"到"+i+"'\r\n";
  51. }
  52. temp = i;
  53. }
  54. }
  55. str += " when extract(year from age(event_time,c.birth_date)) <="+max+" then '"+temp+"到"+max+"' end \r\n ";
  56. // System.out.println(str);
  57. return str;
  58. }
  59. public static String genGroupSql(String jsonStr,String stepStr){
  60. Map<String,Map> temp1 = null; //入排条件1
  61. Map temp2 = null; //入排条件2
  62. List<Map> lis = (List)JSON.parse(jsonStr);
  63. if(!CollectionUtils.isEmpty(lis)){
  64. temp1 = lis.get(0);
  65. if(lis.size()>1){
  66. temp2 = lis.get(1);
  67. }
  68. }
  69. // System.out.println(stepStr);
  70. Map stepMap = (Map)JSON.parse(stepStr);;
  71. int maxValue = 0;
  72. int minValue = 0;
  73. int interval = 0;
  74. try{
  75. if(StringUtils.isNotBlank((String)stepMap.get("maxValue"))){
  76. maxValue = Integer.parseInt((String)stepMap.get("maxValue"));
  77. }
  78. if(StringUtils.isNotBlank((String)stepMap.get("minValue"))){
  79. minValue = Integer.parseInt((String)stepMap.get("minValue"));
  80. }
  81. if(StringUtils.isNotBlank((String)stepMap.get("interval"))){
  82. interval = Integer.parseInt((String)stepMap.get("interval"));
  83. }
  84. }catch(Exception e){}
  85. String groupType = stepMap.get("groupType")==null?"":(String)stepMap.get("groupType");
  86. String event1 = (String)temp1.get("事件").get("event_type");
  87. String event2 = temp2!=null?(String)((Map)temp2.get("事件")).get("event_type"):"";
  88. String returnSql = "";
  89. switch(event1){
  90. case "diagnosis":returnSql = "with temp1 as ("+event_diagnose(temp1,stepMap)+")";break;
  91. case "lab":returnSql = "with temp1 as ("+event_lab(temp1,stepMap)+")";break;
  92. }
  93. if(!CollectionUtils.isEmpty(temp2)){
  94. switch(event2){
  95. case "diagnosis":returnSql += ", \r\n temp2 as ("+event_diagnose(temp2,stepMap)+")";break;
  96. case "lab":returnSql += ", \r\n temp2 as ("+event_lab(temp2,stepMap)+")";break;
  97. }
  98. String rel = (String)temp2.get("关系");
  99. if("or".equals(rel)){
  100. returnSql += " \r\n select ";
  101. if(StringUtils.isNotBlank(groupType)){
  102. switch((String)stepMap.get("groupType")){
  103. case "年龄段":returnSql += generateAgePart(minValue,maxValue,interval)+" 年龄段,";break;
  104. case "年份":returnSql += "to_char(event_time,'yyyy') 年份,";break;
  105. case "医院":returnSql += "t.org_code,org.org_name,";break;
  106. case "就诊类型":returnSql += "visit_type,";break;
  107. case "性别":returnSql += "case when c.sex_code in ('2','9') then '女' when c.sex_code ='1' then '男' else '未知' end 性别,";break;
  108. }
  109. }
  110. if("patientsNumber".equals((String)stepMap.get("queryType"))){
  111. returnSql += "count(distinct t.patient_id) 人数";
  112. }else{
  113. returnSql += "count(t.patient_id) 人次";
  114. }
  115. returnSql += " \r\n from (select * from temp1 union all select * from temp2 )t ";
  116. if("性别".equals((String)stepMap.get("groupType"))||"年龄段".equals((String)stepMap.get("groupType"))){
  117. returnSql += " join patient.patient_master_info c on t.patient_id=c.patient_id \r\n";
  118. }
  119. if("医院".equals((String)stepMap.get("groupType"))){
  120. returnSql += " join mdm.organization org on t.org_code=org.org_code \r\n";
  121. }
  122. if(StringUtils.isNotBlank(groupType)){
  123. returnSql += " group by ";
  124. switch((String)stepMap.get("groupType")){
  125. case "年龄段":returnSql += generateAgePart(minValue,maxValue,interval);break;
  126. case "年份":returnSql += "to_char(event_time,'yyyy') ";break;
  127. case "医院":returnSql += "t.org_code,org.org_name";break;
  128. case "就诊类型":returnSql += "visit_type";break;
  129. case "性别":returnSql += "case when c.sex_code in ('2','9') then '女' when c.sex_code ='1' then '男' else '未知' end";break;
  130. }
  131. }
  132. }else if("and".equals(rel)){
  133. returnSql += "select count(1) 人数 from (select distinct temp1.patient_id from temp1)a join (select distinct temp2.patient_id from temp2 ) b on a.patient_id=b.patient_id";
  134. }
  135. }else{//只有temp1的情况
  136. returnSql += "\r\n select ";
  137. if(StringUtils.isNotBlank(groupType)){
  138. switch((String)stepMap.get("groupType")){
  139. case "年龄段":returnSql += generateAgePart(minValue,maxValue,interval)+" 年龄段,";break;
  140. case "年份":returnSql += "to_char(event_time,'yyyy') 年份,";break;
  141. case "医院":returnSql += "temp1.org_code,org.org_name,";break;
  142. case "就诊类型":returnSql += "visit_type,";break;
  143. case "性别":returnSql += "case when c.sex_code in ('2','9') then '女' when c.sex_code ='1' then '男' else '未知' end 性别,\r\n";break;
  144. }
  145. }
  146. if("patientsNumber".equals((String)stepMap.get("queryType"))){
  147. returnSql += "count(distinct temp1.patient_id) 人数";
  148. }else{ //visitsNumber 人次
  149. returnSql += "count(temp1.patient_id) 人次";
  150. }
  151. returnSql += " from temp1 ";
  152. if("性别".equals((String)stepMap.get("groupType"))||"年龄段".equals((String)stepMap.get("groupType"))){
  153. returnSql += " join patient.patient_master_info c on temp1.patient_id=c.patient_id \r\n ";
  154. }
  155. if("医院".equals((String)stepMap.get("groupType"))){
  156. returnSql += " join mdm.organization org on temp1.org_code=org.org_code \r\n";
  157. }
  158. if(StringUtils.isNotBlank(groupType)){
  159. returnSql += "group by ";
  160. switch((String)stepMap.get("groupType")){
  161. case "年龄段":returnSql += generateAgePart(minValue,maxValue,interval);break;
  162. case "年份":returnSql += "to_char(event_time,'yyyy') ";break;
  163. case "医院":returnSql += "temp1.org_code,org.org_name";break;
  164. case "就诊类型":returnSql += "visit_type";break;
  165. case "性别":returnSql += "case when c.sex_code in ('2','9') then '女' when c.sex_code ='1' then '男' else '未知' end";break;
  166. }
  167. }
  168. }
  169. return returnSql;
  170. }
  171. public static String event_diagnose(Map<String,Map> temp1,Map groupMap){
  172. /*{"事件":{"diag_standard":"I21,I22,I23","event_type":"诊断"},"医院":{"org_code":"9983838x,111999441,2224589985,112445580"},
  173. * "就诊类型":{"visit_type":"门诊"},"时间":{"time_from":"绝对时间:2017-01-01","time_to":"绝对时间:2017-01-10"}}
  174. *
  175. * {\"事件\":{\"diag_standard\":[\"I220\",\"I230\"],\"diag_primitive\":[\"I220\",\"I230\"],\"event_type\":\"diagnosis\"},
  176. * \"医院\":{\"org_code\":[\"111111\",\"222222\"]},\"就诊类型\":{\"visit_type\":\"hospitalization\"},\"时间\":{\"time_from\":\"2018-7-2\",\"time_to\":\"2018-8-12\"},
  177. * \"关系\":\"or\"}
  178. *
  179. * */
  180. String resultSql = "";
  181. String condition = "";
  182. //String eventType = "";
  183. for(String str:temp1.keySet()){
  184. if("事件".equals(str)){ //"事件":{"diag_standard":"I21,I22,I23","event_type":"诊断"}
  185. Map temp = temp1.get(str);
  186. //if(temp.get("event_type").equals("diagnosis")){
  187. //eventType = (String)temp.get("event_type");
  188. //,diag_time,org_code,case when visit_type='O' then '门诊' when visit_type='I' then '住院' when is_emergency=true then '急诊' else '未知' end visit_type
  189. resultSql += " select * from(select a.patient_id";
  190. String groupType = groupMap.get("groupType")==null?"":(String)groupMap.get("groupType");
  191. if(StringUtils.isNotBlank(groupType)){//"{\"groupType\":\"医院\",\"interval\":\"\",\"maxValue\":\"\",\"minValue\":\"\"}";
  192. switch(groupType){
  193. case "年龄段":resultSql += ",coalesce(a.diag_time,b.visit_time) event_time";break;
  194. case "年份":resultSql += ",coalesce(a.diag_time,b.visit_time) event_time";break;
  195. case "医院":resultSql += ",a.org_code";break;
  196. case "就诊类型":resultSql += ",case when b.visit_type='O' then '门诊' when b.visit_type='I' then '住院' when is_emergency=true then '急诊' else '未知' end visit_type";break;
  197. case "性别":resultSql += "";break;
  198. }
  199. }
  200. resultSql += ",jsonb_array_elements(diag_sycode_set) "+
  201. "as sycode \r\n from diag.patient_diagnose a ";
  202. String time_from = temp1.get("时间")==null?"":(String)temp1.get("时间").get("time_from");
  203. String visit_type = temp1.get("就诊类型")==null?"":(String)temp1.get("就诊类型").get("visit_type");
  204. if(StringUtils.isNotBlank(time_from)||StringUtils.isNotBlank(visit_type)){
  205. resultSql += " left join visit.visit_record b on a.visit_id = b.visit_id ";
  206. }else{
  207. if(StringUtils.isNotBlank(groupType)){
  208. switch((String)groupMap.get("groupType")){
  209. case "年龄段":resultSql += " left join visit.visit_record b on a.visit_id = b.visit_id ";break;
  210. case "年份":resultSql += " left join visit.visit_record b on a.visit_id = b.visit_id ";break;
  211. case "就诊类型":resultSql += " left join visit.visit_record b on a.visit_id = b.visit_id ";break;
  212. //case "性别":resultSql += "";break;
  213. }
  214. }
  215. }
  216. resultSql += "where 1=1 $condition$ ) t1 \r\n ";
  217. List<String> diag_list = (List)temp.get("diag_standard");
  218. List<String> diag_primitive = (List)temp.get("diag_primitive");
  219. if(diag_list!=null&&diag_list.size()>0){
  220. resultSql += " join (select diag_code,diag_code2,diag_name from mdm.diagnose a where a.code_sys_id=30 \r\n ";
  221. if(diag_list.size()>1){
  222. for(int i = 0;i<diag_list.size();i++){
  223. String diag_c = diag_list.get(i);
  224. if(i==0){
  225. resultSql += " and ( diag_code2 like '"+diag_c+"%'";
  226. }else if(i==diag_list.size()-1){
  227. resultSql += " or diag_code2 like '"+diag_c+"%')";
  228. }else{
  229. resultSql += " or diag_code2 like '"+diag_c+"%'";
  230. }
  231. }
  232. }else{
  233. resultSql += " and diag_code2 like '"+diag_list.get(0)+"%'";
  234. }
  235. resultSql += " \r\n )t2 on replace(t1.sycode::varchar(50),'\"','') =t2.diag_code";
  236. }else if(diag_primitive!=null&&diag_primitive.size()>0){
  237. resultSql += " join (select diag_code,diag_code2,diag_name from mdm.diagnose a where a.code_sys_id=30 \r\n ";
  238. if(diag_primitive.size()>1){
  239. for(int i = 0;i<diag_primitive.size();i++){
  240. String diag_c = diag_primitive.get(i);
  241. if(i==0){
  242. resultSql += " and ( diag_name like '%"+diag_c+"%'";
  243. }else if(i==diag_primitive.size()-1){
  244. resultSql += " or diag_name like '%"+diag_c+"%')";
  245. }else{
  246. resultSql += " or diag_name like '%"+diag_c+"%'";
  247. }
  248. }
  249. }else{
  250. resultSql += " and diag_name like '%"+diag_primitive.get(0)+"%'";
  251. }
  252. resultSql += " \r\n )t2 on replace(t1.sycode::varchar(50),'\"','') =t2.diag_code";
  253. }
  254. //}
  255. }else if("医院".equals(str)){ //"医院":{"org_code":"9983838x,111999441,2224589985,112445580"}
  256. Map temp = temp1.get(str);
  257. try{
  258. List<String> org_list = (List)temp.get("org_code");
  259. if(!CollectionUtils.isEmpty(org_list)){
  260. if(org_list.size()>1){
  261. for(int i = 0;i<org_list.size();i++){
  262. String org_code = org_list.get(i);
  263. if(i==0){
  264. condition += " and a.org_code in ('"+org_code+"',";
  265. }else if(i==org_list.size()-1){
  266. condition += "'"+org_code+"')";
  267. }else{
  268. condition += "'"+org_code+"',";
  269. }
  270. }
  271. }else{
  272. condition += " and a.org_code = '"+org_list.get(0)+"'";
  273. }
  274. }
  275. }catch(java.lang.ClassCastException e){}
  276. }else if("时间".equals(str)){//"时间":{"time_from":"绝对时间:2017-01-01","time_to":"绝对时间:2017-01-10","time_type":"诊断时间"}
  277. Map temp = temp1.get(str);
  278. String time_from = (String)temp.get("time_from");
  279. String time_to = (String)temp.get("time_to");
  280. condition += " \r\n ";
  281. if(StringUtils.isNoneBlank(time_from)&&StringUtils.isNoneBlank(time_to)){
  282. condition += " and coalesce(a.diag_time,b.visit_time) between '"+time_from +"' and '"+time_to+"'";
  283. }
  284. // switch(eventType){
  285. // case "诊断":condition+= "and coalesce(a.diag_time,b.visit_time) ";break;
  286. // case "检验时间":condition+= "and report_time ";break;
  287. // case "用药时间":condition+= "and drug_time ";break;
  288. // case "手术时间":condition+= "and oper_time ";break;
  289. // }
  290. }else if("就诊类型".equals(str)){//"就诊类型":{"visit_type":"门诊"}
  291. Map temp = temp1.get(str);
  292. String visit_type = (String)temp.get("visit_type");
  293. condition += " \r\n ";
  294. switch(visit_type){
  295. case "outpat":condition+= " and b.visit_type='O' ";break;
  296. case "inpat":condition+= " and b.visit_type='I' ";break;
  297. case "emergency":condition+= " and b.is_emergency=true ";break;
  298. }
  299. }
  300. }
  301. resultSql = resultSql.replace("$condition$", condition);
  302. return resultSql;
  303. }
  304. public static String event_lab(Map<String,Map> temp1,Map groupMap){
  305. /*{"事件":{"diag_standard":"I21,I22,I23","event_type":"诊断"},"医院":{"org_code":"9983838x,111999441,2224589985,112445580"},
  306. * "就诊类型":{"visit_type":"门诊"},"时间":{"time_from":"绝对时间:2017-01-01","time_to":"绝对时间:2017-01-10"}}
  307. *
  308. * {\"事件\":{\"diag_standard\":[\"I220\",\"I230\"],\"diag_primitive\":[\"I220\",\"I230\"],\"event_type\":\"diagnosis\"},
  309. * \"医院\":{\"org_code\":[\"111111\",\"222222\"]},\"就诊类型\":{\"visit_type\":\"hospitalization\"},\"时间\":{\"time_from\":\"2018-7-2\",\"time_to\":\"2018-8-12\"},
  310. * \"关系\":\"or\"}
  311. *
  312. * */
  313. String resultSql = "";
  314. String condition = "";
  315. //String eventType = "";
  316. for(String str:temp1.keySet()){
  317. if("事件".equals(str)){ //"事件":{"diag_standard":"I21,I22,I23","event_type":"诊断"}
  318. Map temp = temp1.get(str);
  319. //if(temp.get("event_type").equals("diagnosis")){
  320. //eventType = (String)temp.get("event_type");
  321. //,diag_time,org_code,case when visit_type='O' then '门诊' when visit_type='I' then '住院' when is_emergency=true then '急诊' else '未知' end visit_type
  322. resultSql += " select d.patient_id";
  323. String groupType = groupMap.get("groupType")==null?"":(String)groupMap.get("groupType");
  324. if(StringUtils.isNotBlank(groupType)){//"{\"groupType\":\"医院\",\"interval\":\"\",\"maxValue\":\"\",\"minValue\":\"\"}";
  325. switch(groupType){
  326. case "年龄段":resultSql += ",d.report_time event_time";break;
  327. case "年份":resultSql += ",d.report_time event_time";break;
  328. case "医院":resultSql += ",d.org_code";break;
  329. case "就诊类型":resultSql += ",case when e.visit_type='O' then '门诊' when e.visit_type='I' then '住院' when is_emergency=true then '急诊' else '未知' end visit_type";break;
  330. case "性别":resultSql += "";break;
  331. }
  332. }
  333. resultSql += " from lab.lab_report_result a join mdm.mdm_map b on a.test_item_id=b.source_id"+
  334. " \r\n join mdm.lis_item c on b.map_id=c.item_id"+
  335. " join lab.lab_report d on a.report_id=d.report_id";
  336. String visit_type = temp1.get("就诊类型")==null?"":(String)temp1.get("就诊类型").get("visit_type");
  337. if(StringUtils.isNotBlank(visit_type)){
  338. resultSql += " left join visit.visit_record e \r\n on d.visit_id = e.visit_id ";
  339. }
  340. resultSql += "where b.md_type = 'lis_item' and c.code_sys_id =197 $condition$ \r\n ";
  341. List<String> lab_list = (List)temp.get("lab_standard");
  342. List<String> diag_primitive = (List)temp.get("diag_primitive");
  343. if(lab_list!=null&&lab_list.size()>0){
  344. if(lab_list.size()>1){
  345. for(int i = 0;i<lab_list.size();i++){
  346. String diag_c = lab_list.get(i);
  347. if(i==0){
  348. resultSql += " and ( c.item_id = '"+diag_c+"'";
  349. }else if(i==lab_list.size()-1){
  350. resultSql += " or c.item_id = '"+diag_c+"')";
  351. }else{
  352. resultSql += " or c.item_id = '"+diag_c+"'";
  353. }
  354. }
  355. }else{
  356. resultSql += " and c.item_id = '"+lab_list.get(0)+"'";
  357. }
  358. }else if(diag_primitive!=null&&diag_primitive.size()>0){
  359. resultSql += " join (select diag_code,diag_code2,diag_name from mdm.diagnose a where a.code_sys_id=30 \r\n ";
  360. if(diag_primitive.size()>1){
  361. for(int i = 0;i<diag_primitive.size();i++){
  362. String diag_c = diag_primitive.get(i);
  363. if(i==0){
  364. resultSql += " and ( diag_name like '%"+diag_c+"%'";
  365. }else if(i==diag_primitive.size()-1){
  366. resultSql += " or diag_name like '%"+diag_c+"%')";
  367. }else{
  368. resultSql += " or diag_name like '%"+diag_c+"%'";
  369. }
  370. }
  371. }else{
  372. resultSql += " and diag_name like '%"+diag_primitive.get(0)+"%'";
  373. }
  374. resultSql += " \r\n )t2 on replace(t1.sycode::varchar(50),'\"','') =t2.diag_code";
  375. }
  376. //}
  377. }else if("医院".equals(str)){ //"医院":{"org_code":"9983838x,111999441,2224589985,112445580"}
  378. Map temp = temp1.get(str);
  379. try{
  380. List<String> org_list = (List)temp.get("org_code");
  381. if(!CollectionUtils.isEmpty(org_list)){
  382. if(org_list.size()>1){
  383. for(int i = 0;i<org_list.size();i++){
  384. String org_code = org_list.get(i);
  385. if(i==0){
  386. condition += " and d.org_code in ('"+org_code+"',";
  387. }else if(i==org_list.size()-1){
  388. condition += "'"+org_code+"')";
  389. }else{
  390. condition += "'"+org_code+"',";
  391. }
  392. }
  393. }else{
  394. condition += " and d.org_code = '"+org_list.get(0)+"'";
  395. }
  396. }
  397. }catch(java.lang.ClassCastException e){}
  398. }else if("时间".equals(str)){//"时间":{"time_from":"绝对时间:2017-01-01","time_to":"绝对时间:2017-01-10","time_type":"诊断时间"}
  399. Map temp = temp1.get(str);
  400. String time_from = (String)temp.get("time_from");
  401. String time_to = (String)temp.get("time_to");
  402. condition += " \r\n ";
  403. if(StringUtils.isNoneBlank(time_from)&&StringUtils.isNoneBlank(time_to)){
  404. condition += " and d.report_time between '"+time_from +"' and '"+time_to+"'";
  405. }
  406. // switch(eventType){
  407. // case "诊断":condition+= "and coalesce(a.diag_time,b.visit_time) ";break;
  408. // case "检验时间":condition+= "and report_time ";break;
  409. // case "用药时间":condition+= "and drug_time ";break;
  410. // case "手术时间":condition+= "and oper_time ";break;
  411. // }
  412. }else if("就诊类型".equals(str)){//"就诊类型":{"visit_type":"门诊"}
  413. Map temp = temp1.get(str);
  414. String visit_type = (String)temp.get("visit_type");
  415. condition += " \r\n ";
  416. switch(visit_type){
  417. case "outpat":condition+= " and e.visit_type='O' ";break;
  418. case "inpat":condition+= " and e.visit_type='I' ";break;
  419. case "emergency":condition+= " and e.is_emergency=true ";break;
  420. }
  421. }
  422. }
  423. resultSql = resultSql.replace("$condition$", condition);
  424. return resultSql;
  425. }
  426. }