af3f1b949c679e85dd730846370e6209a140e331.svn-base 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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("参数传递:"+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. String jsonString = JSONObject.toJSON(list).toString();
  96. printJson(res,jsonString);
  97. return null;
  98. }
  99. /**
  100. * 模糊匹配获取所有的检查名称
  101. * @param request
  102. * @param model
  103. * @param res
  104. * @param param
  105. * @return
  106. */
  107. @RequestMapping("/getAlllabInfo")
  108. public String getAllLabInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  109. List<Parameter> par = sqlbuilderService.getAllLabInfo(param);
  110. List list = new ArrayList();
  111. for(Parameter p:par){
  112. Map map1 = new HashMap();
  113. map1.put("value", p.getItemId());
  114. map1.put("label", p.getItemName());
  115. list.add(map1);
  116. }
  117. String jsonString = JSONObject.toJSON(list).toString();
  118. printJson(res,jsonString);
  119. return null;
  120. }
  121. /**
  122. * 获取检验结果,文本结果和数字结果等suggestion列表
  123. * @param request
  124. * @param model
  125. * @param res
  126. * @param param
  127. * @return
  128. */
  129. @RequestMapping("/getSuggestionList")
  130. public String getSuggestionList(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  131. List<Parameter> par = sqlbuilderService.getSuggestionList(param);
  132. List list = new ArrayList();
  133. for(Parameter p:par){
  134. //c.item_name,text_value,numerical_value,reference_range,abnormal_flag_name
  135. Map map1 = new HashMap();
  136. map1.put("itemName", p.getItemName());
  137. map1.put("textValue", p.getTextValue());
  138. map1.put("numericalValue", p.getNumericalValue());
  139. map1.put("referenceRange", p.getReferenceRange());
  140. map1.put("abnormalFlagName", p.getAbnormalFlagName());
  141. list.add(map1);
  142. }
  143. String jsonString = JSONObject.toJSON(list).toString();
  144. printJson(res,jsonString);
  145. return null;
  146. }
  147. /**
  148. * 模糊匹配获取所有的药品名称
  149. * @param request
  150. * @param model
  151. * @param res
  152. * @param param
  153. * @return
  154. */
  155. @RequestMapping("/getAllDrugInfo")
  156. public String getAllDrugInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  157. List<Parameter> par = sqlbuilderService.getAllDrugInfo(param);
  158. List list = new ArrayList();
  159. for(Parameter p:par){
  160. Map map1 = new HashMap();
  161. map1.put("value", p.getDrugId());
  162. map1.put("label", p.getDrugName());
  163. list.add(map1);
  164. }
  165. String jsonString = JSONObject.toJSON(list).toString();
  166. printJson(res,jsonString);
  167. return null;
  168. }
  169. /**
  170. * 获取所有的药品大类名称
  171. * @param request
  172. * @param model
  173. * @param res
  174. * @param param
  175. * @return
  176. */
  177. @RequestMapping("/getAllDrugCategory")
  178. public String getAllDrugCategory(HttpServletRequest request,Model model,HttpServletResponse res){
  179. List<Parameter> par = sqlbuilderService.getAllDrugCategory();
  180. List list = new ArrayList();
  181. for(Parameter p:par){
  182. Map map1 = new HashMap();
  183. map1.put("value", p.getDrugId());
  184. map1.put("label", p.getDrugName());
  185. list.add(map1);
  186. }
  187. String jsonString = JSONObject.toJSON(list).toString();
  188. printJson(res,jsonString);
  189. return null;
  190. }
  191. /**
  192. * 根据药品名称获取模糊匹配的suggestion
  193. * @param request
  194. * @param model
  195. * @param res
  196. * @param param
  197. * @return
  198. */
  199. @RequestMapping("/getSuggestionByDrug")
  200. public String getSuggestionByDrug(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  201. List<Parameter> par = sqlbuilderService.getSuggestionByDrug(param);
  202. List list = new ArrayList();
  203. for(Parameter p:par){
  204. Map map1 = new HashMap();
  205. map1.put("value", p.getDrugId());
  206. map1.put("label", p.getDrugName());
  207. list.add(map1);
  208. }
  209. String jsonString = JSONObject.toJSON(list).toString();
  210. printJson(res,jsonString);
  211. return null;
  212. }
  213. /**
  214. * 根据药品父节点名称获取子节点药品名称
  215. * @param request
  216. * @param model
  217. * @param res
  218. * @param param
  219. * @return
  220. */
  221. @RequestMapping("/getChildDrug")
  222. public String getChildDrug(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  223. List<Parameter> par = sqlbuilderService.getChildDrug(param);
  224. List list = new ArrayList();
  225. for(Parameter p:par){
  226. Map map1 = new HashMap();
  227. map1.put("value", p.getDrugId());
  228. map1.put("label", p.getDrugName());
  229. map1.put("parent", p.getParent());
  230. list.add(map1);
  231. }
  232. String jsonString = JSONObject.toJSON(list).toString();
  233. printJson(res,jsonString);
  234. return null;
  235. }
  236. /**
  237. * 递归通过子类别将所有父类药品列出来
  238. * @param request
  239. * @param model
  240. * @param res
  241. * @param param
  242. * @return
  243. */
  244. @RequestMapping("/getParentPath")
  245. public String getParentPath(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  246. List<Parameter> par = sqlbuilderService.getParentPath(param);
  247. List list = new ArrayList();
  248. for(Parameter p:par){
  249. Map map1 = new HashMap();
  250. map1.put("value", p.getDrugId());
  251. map1.put("label", p.getDrugName());
  252. map1.put("parent", p.getParent());
  253. list.add(map1);
  254. }
  255. String jsonString = JSONObject.toJSON(list).toString();
  256. printJson(res,jsonString);
  257. return null;
  258. }
  259. /**
  260. * 递归通过子类别将所有父类药品列出来并且所有父类的同类列出来
  261. * @param request
  262. * @param model
  263. * @param res
  264. * @param param
  265. * @return
  266. */
  267. @RequestMapping("/getAllDrugPathInfo")
  268. public String getAllDrugPathInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  269. List<Parameter> par = sqlbuilderService.getParentPath(param);
  270. List<String> strList = new ArrayList();
  271. for(Parameter p:par){
  272. strList.add(p.getDrugId());
  273. }
  274. param.setStrList(strList);
  275. param.setStrSize(strList.size());
  276. List<Parameter> pathInfo = sqlbuilderService.getAllDrugPathInfo(param);
  277. List list = new ArrayList();
  278. for(Parameter p:pathInfo){
  279. Map map1 = new HashMap();
  280. map1.put("value", p.getDrugId());
  281. map1.put("label", p.getDrugName());
  282. map1.put("parent", p.getParent());
  283. list.add(map1);
  284. }
  285. String jsonString = JSONObject.toJSON(list).toString();
  286. printJson(res,jsonString);
  287. return null;
  288. }
  289. }