28a576ed56427c7cb0ed62a7eadf0b1958440644.svn-base 8.9 KB

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