8df391cc1a0c5408f07810b5934e1f2083fc904d.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. package com.synyi.edc.controller;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.apache.log4j.Logger;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.ui.Model;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import com.alibaba.fastjson.JSONObject;
  16. import com.synyi.edc.pojo.Parameter;
  17. import com.synyi.edc.service.ISqlbuilderService;
  18. import com.synyi.edc.util.SqlBuilderUtils;
  19. /**
  20. * sql语句生成主要contorller
  21. * @author wy
  22. *
  23. */
  24. @Controller
  25. @RequestMapping("/sqlbuilder")
  26. public class SqlbuilderController {
  27. private Logger log = Logger.getLogger(SqlbuilderController.class);
  28. @Resource
  29. private ISqlbuilderService sqlbuilderService;
  30. @RequestMapping("/toIndex")
  31. public String toJ(HttpServletRequest request,Model model){
  32. // int userId = Integer.parseInt(request.getParameter("id"));
  33. // User user = this.userService.getUserById(userId);
  34. // model.addAttribute("user", user);
  35. return "index";
  36. }
  37. /**
  38. * sql生成方法
  39. * @param request
  40. * @param model
  41. * @param param
  42. * @param res
  43. * @return
  44. */
  45. @RequestMapping("/generate")
  46. public String generate(HttpServletRequest request,Model model,Parameter param,HttpServletResponse res){
  47. log.info("generate方法参数传递:"+param);
  48. String jsonStr = param.getEventData();
  49. String stepStr = param.getGroupData();
  50. String returnSql = SqlBuilderUtils.genGroupSql(jsonStr,stepStr);
  51. log.info("生成sql:"+returnSql);
  52. printJson(res,returnSql);
  53. return null;
  54. }
  55. /**
  56. * 打印返回参数
  57. * @param res
  58. * @param str
  59. */
  60. public void printJson(HttpServletResponse res,String str){
  61. res.setContentType("text/plain");
  62. res.setCharacterEncoding("utf-8");
  63. res.setHeader("Access-Control-Allow-Origin", "*");
  64. res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
  65. res.setHeader("Access-Control-Max-Age", "3600");
  66. res.setHeader("Access-Control-Allow-Headers", "x-requested-with");
  67. PrintWriter pw = null;
  68. try {
  69. pw = res.getWriter();
  70. pw.write(str);
  71. } catch (IOException e) {
  72. e.printStackTrace();
  73. }finally{
  74. pw.flush();
  75. pw.close();
  76. }
  77. }
  78. /**
  79. * 获取所有的医院列表
  80. * @param request
  81. * @param model
  82. * @param res
  83. * @return
  84. */
  85. @RequestMapping("/getAllOrg")
  86. public String getAllOrg(HttpServletRequest request,Model model,HttpServletResponse res){
  87. List<Parameter> par = sqlbuilderService.getAllOrgInfo();
  88. List list = new ArrayList();
  89. for(Parameter p:par){
  90. Map map1 = new HashMap();
  91. map1.put("value", p.getOrgCode());
  92. map1.put("label", p.getOrgName());
  93. list.add(map1);
  94. }
  95. log.info("getAllOrg方法返回数据:"+list);
  96. String jsonString = JSONObject.toJSON(list).toString();
  97. printJson(res,jsonString);
  98. return null;
  99. }
  100. /**
  101. * 模糊匹配获取所有的检查名称
  102. * @param request
  103. * @param model
  104. * @param res
  105. * @param param
  106. * @return
  107. */
  108. @RequestMapping("/getAlllabInfo")
  109. public String getAllLabInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  110. log.info("getAllLabInfo方法参数传递:"+param);
  111. List<Parameter> par = sqlbuilderService.getAllLabInfo(param);
  112. List list = new ArrayList();
  113. for(Parameter p:par){
  114. Map map1 = new HashMap();
  115. map1.put("value", p.getItemId());
  116. map1.put("label", p.getItemName());
  117. list.add(map1);
  118. }
  119. log.info("getAllLabInfo方法返回数据:"+list);
  120. String jsonString = JSONObject.toJSON(list).toString();
  121. printJson(res,jsonString);
  122. return null;
  123. }
  124. /**
  125. * 获取检验结果,文本结果和数字结果等suggestion列表
  126. * @param request
  127. * @param model
  128. * @param res
  129. * @param param
  130. * @return
  131. */
  132. @RequestMapping("/getSuggestionList")
  133. public String getSuggestionList(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  134. log.info("getSuggestionList方法参数传递:"+param);
  135. List<Parameter> par = sqlbuilderService.getSuggestionList(param);
  136. List list = new ArrayList();
  137. for(Parameter p:par){
  138. //c.item_name,text_value,numerical_value,reference_range,abnormal_flag_name
  139. Map map1 = new HashMap();
  140. map1.put("itemName", p.getItemName());
  141. map1.put("textValue", p.getTextValue());
  142. map1.put("numericalValue", p.getNumericalValue());
  143. map1.put("referenceRange", p.getReferenceRange());
  144. map1.put("abnormalFlagName", p.getAbnormalFlagName());
  145. list.add(map1);
  146. }
  147. log.info("getSuggestionList方法返回数据:"+list);
  148. String jsonString = JSONObject.toJSON(list).toString();
  149. printJson(res,jsonString);
  150. return null;
  151. }
  152. /**
  153. * 模糊匹配获取所有的药品名称
  154. * @param request
  155. * @param model
  156. * @param res
  157. * @param param
  158. * @return
  159. */
  160. @RequestMapping("/getAllDrugInfo")
  161. public String getAllDrugInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  162. log.info("getAllDrugInfo方法参数传递:"+param);
  163. List<Parameter> par = sqlbuilderService.getAllDrugInfo(param);
  164. List list = new ArrayList();
  165. for(Parameter p:par){
  166. Map map1 = new HashMap();
  167. map1.put("value", p.getDrugId());
  168. map1.put("label", p.getDrugName());
  169. list.add(map1);
  170. }
  171. log.info("getAllDrugInfo方法返回数据:"+list);
  172. String jsonString = JSONObject.toJSON(list).toString();
  173. printJson(res,jsonString);
  174. return null;
  175. }
  176. /**
  177. * 获取所有的药品大类名称
  178. * @param request
  179. * @param model
  180. * @param res
  181. * @param param
  182. * @return
  183. */
  184. @RequestMapping("/getAllDrugCategory")
  185. public String getAllDrugCategory(HttpServletRequest request,Model model,HttpServletResponse res){
  186. List<Parameter> par = sqlbuilderService.getAllDrugCategory();
  187. List list = new ArrayList();
  188. for(Parameter p:par){
  189. Map map1 = new HashMap();
  190. map1.put("value", p.getDrugId());
  191. map1.put("label", p.getDrugName());
  192. list.add(map1);
  193. }
  194. log.info("getAllDrugCategory方法返回数据:"+list);
  195. String jsonString = JSONObject.toJSON(list).toString();
  196. printJson(res,jsonString);
  197. return null;
  198. }
  199. /**
  200. * 根据药品名称获取模糊匹配的suggestion
  201. * @param request
  202. * @param model
  203. * @param res
  204. * @param param
  205. * @return
  206. */
  207. @RequestMapping("/getSuggestionByDrug")
  208. public String getSuggestionByDrug(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  209. log.info("getSuggestionByDrug方法参数传递:"+param);
  210. List<Parameter> par = sqlbuilderService.getSuggestionByDrug(param);
  211. List list = new ArrayList();
  212. for(Parameter p:par){
  213. Map map1 = new HashMap();
  214. map1.put("value", p.getDrugId());
  215. map1.put("label", p.getDrugName());
  216. list.add(map1);
  217. }
  218. log.info("getSuggestionByDrug方法返回数据:"+list);
  219. String jsonString = JSONObject.toJSON(list).toString();
  220. printJson(res,jsonString);
  221. return null;
  222. }
  223. /**
  224. * 根据药品父节点名称获取子节点药品名称
  225. * @param request
  226. * @param model
  227. * @param res
  228. * @param param
  229. * @return
  230. */
  231. @RequestMapping("/getChildDrug")
  232. public String getChildDrug(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  233. log.info("getChildDrug方法参数传递:"+param);
  234. List<Parameter> par = sqlbuilderService.getChildDrug(param);
  235. List list = new ArrayList();
  236. for(Parameter p:par){
  237. Map map1 = new HashMap();
  238. map1.put("value", p.getDrugId());
  239. map1.put("label", p.getDrugName());
  240. map1.put("parent", p.getParent());
  241. list.add(map1);
  242. }
  243. log.info("getChildDrug方法返回数据:"+list);
  244. String jsonString = JSONObject.toJSON(list).toString();
  245. printJson(res,jsonString);
  246. return null;
  247. }
  248. /**
  249. * 递归通过子类别将所有父类药品列出来
  250. * @param request
  251. * @param model
  252. * @param res
  253. * @param param
  254. * @return
  255. */
  256. @RequestMapping("/getParentPath")
  257. public String getParentPath(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  258. log.info("getParentPath方法参数传递:"+param);
  259. List<Parameter> par = sqlbuilderService.getParentPath(param);
  260. List list = new ArrayList();
  261. for(Parameter p:par){
  262. Map map1 = new HashMap();
  263. map1.put("value", p.getDrugId());
  264. map1.put("label", p.getDrugName());
  265. map1.put("parent", p.getParent());
  266. list.add(map1);
  267. }
  268. log.info("getParentPath方法返回数据:"+list);
  269. String jsonString = JSONObject.toJSON(list).toString();
  270. printJson(res,jsonString);
  271. return null;
  272. }
  273. /**
  274. * 递归通过子类别将所有父类药品列出来并且所有父类的同类列出来
  275. * @param request
  276. * @param model
  277. * @param res
  278. * @param param
  279. * @return
  280. */
  281. @RequestMapping("/getAllDrugPathInfo")
  282. public String getAllDrugPathInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  283. log.info("getAllDrugPathInfo方法参数传递:"+param);
  284. List<Parameter> par = sqlbuilderService.getParentPath(param);
  285. List<String> strList = new ArrayList();
  286. for(Parameter p:par){
  287. strList.add(p.getDrugId());
  288. }
  289. param.setStrList(strList);
  290. param.setStrSize(strList.size());
  291. List<Parameter> pathInfo = sqlbuilderService.getAllDrugPathInfo(param);
  292. List list = new ArrayList();
  293. for(Parameter p:pathInfo){
  294. Map map1 = new HashMap();
  295. map1.put("value", p.getDrugId());
  296. map1.put("label", p.getDrugName());
  297. map1.put("parent", p.getParent());
  298. list.add(map1);
  299. }
  300. log.info("getAllDrugPathInfo方法返回数据:"+list);
  301. String jsonString = JSONObject.toJSON(list).toString();
  302. printJson(res,jsonString);
  303. return null;
  304. }
  305. /**
  306. * 模糊匹配获取所有的手术名称
  307. * @param request
  308. * @param model
  309. * @param res
  310. * @param param
  311. * @return
  312. */
  313. @RequestMapping("/getAllOperationInfo")
  314. public String getAllOperationInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  315. log.info("getAllOperationInfo方法参数传递:"+param);
  316. List<Parameter> par = sqlbuilderService.getAllOperationInfo(param);
  317. List list = new ArrayList();
  318. for(Parameter p:par){
  319. Map map1 = new HashMap();
  320. map1.put("value", p.getOperationCode());
  321. map1.put("label", p.getOperationName());
  322. list.add(map1);
  323. }
  324. log.info("getAllOperationInfo方法返回数据:"+list);
  325. String jsonString = JSONObject.toJSON(list).toString();
  326. printJson(res,jsonString);
  327. return null;
  328. }
  329. }