95de3de1f4cbc349b8c1f76d6719ddc041499e44.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.springframework.stereotype.Controller;
  13. import org.springframework.ui.Model;
  14. import org.springframework.util.CollectionUtils;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import com.alibaba.fastjson.JSON;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.synyi.edc.pojo.Parameter;
  19. import com.synyi.edc.service.ISqlbuilderService;
  20. import com.synyi.edc.service.IUserService;
  21. import com.synyi.edc.util.SqlBuilderUtils;
  22. /**
  23. * sql语句生成主要contorller
  24. * @author wy
  25. *
  26. */
  27. @Controller
  28. @RequestMapping("/sqlbuilder")
  29. public class SqlbuilderController {
  30. @Resource
  31. private IUserService userService;
  32. @Resource
  33. private ISqlbuilderService sqlbuilderService;
  34. @RequestMapping("/toIndex")
  35. public String toJ(HttpServletRequest request,Model model){
  36. // int userId = Integer.parseInt(request.getParameter("id"));
  37. // User user = this.userService.getUserById(userId);
  38. // model.addAttribute("user", user);
  39. return "index";
  40. }
  41. /**
  42. * sql生成方法
  43. * @param request
  44. * @param model
  45. * @param param
  46. * @param res
  47. * @return
  48. */
  49. @RequestMapping("/generate")
  50. public String generate(HttpServletRequest request,Model model,Parameter param,HttpServletResponse res){
  51. System.out.println(param);
  52. System.out.println();
  53. String jsonStr = param.getEventData();
  54. String stepStr = param.getGroupData();
  55. String returnSql = SqlBuilderUtils.genGroupSql(jsonStr,stepStr);
  56. System.out.println(returnSql);
  57. printJson(res,returnSql);
  58. return null;
  59. }
  60. /**
  61. * 打印返回参数
  62. * @param res
  63. * @param str
  64. */
  65. public void printJson(HttpServletResponse res,String str){
  66. res.setContentType("text/plain");
  67. res.setCharacterEncoding("utf-8");
  68. res.setHeader("Access-Control-Allow-Origin", "*");
  69. res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
  70. res.setHeader("Access-Control-Max-Age", "3600");
  71. res.setHeader("Access-Control-Allow-Headers", "x-requested-with");
  72. PrintWriter pw = null;
  73. try {
  74. pw = res.getWriter();
  75. pw.write(str);
  76. } catch (IOException e) {
  77. e.printStackTrace();
  78. }finally{
  79. pw.flush();
  80. pw.close();
  81. }
  82. }
  83. /**
  84. * 获取所有的医院列表
  85. * @param request
  86. * @param model
  87. * @param res
  88. * @return
  89. */
  90. @RequestMapping("/getAllOrg")
  91. public String getAllOrg(HttpServletRequest request,Model model,HttpServletResponse res){
  92. List<Parameter> par = sqlbuilderService.getAllOrgInfo();
  93. List list = new ArrayList();
  94. for(Parameter p:par){
  95. Map map1 = new HashMap();
  96. map1.put("value", p.getOrgCode());
  97. map1.put("label", p.getOrgName());
  98. list.add(map1);
  99. }
  100. String jsonString = JSONObject.toJSON(list).toString();
  101. printJson(res,jsonString);
  102. return null;
  103. }
  104. /**
  105. * 模糊匹配获取所有的检查名称
  106. * @param request
  107. * @param model
  108. * @param res
  109. * @param param
  110. * @return
  111. */
  112. @RequestMapping("/getAlllabInfo")
  113. public String getAllLabInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  114. List<Parameter> par = sqlbuilderService.getAllLabInfo(param);
  115. List list = new ArrayList();
  116. for(Parameter p:par){
  117. Map map1 = new HashMap();
  118. map1.put("value", p.getItemId());
  119. map1.put("label", p.getItemName());
  120. list.add(map1);
  121. }
  122. String jsonString = JSONObject.toJSON(list).toString();
  123. printJson(res,jsonString);
  124. return null;
  125. }
  126. /**
  127. * 获取检验结果,文本结果和数字结果等suggestion列表
  128. * @param request
  129. * @param model
  130. * @param res
  131. * @param param
  132. * @return
  133. */
  134. @RequestMapping("/getSuggestionList")
  135. public String getSuggestionList(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
  136. List<Parameter> par = sqlbuilderService.getSuggestionList(param);
  137. List list = new ArrayList();
  138. for(Parameter p:par){
  139. //c.item_name,text_value,numerical_value,reference_range,abnormal_flag_name
  140. Map map1 = new HashMap();
  141. map1.put("itemName", p.getItemName());
  142. map1.put("textValue", p.getTextValue());
  143. map1.put("numericalValue", p.getNumericalValue());
  144. map1.put("referenceRange", p.getReferenceRange());
  145. map1.put("abnormalFlagName", p.getAbnormalFlagName());
  146. list.add(map1);
  147. }
  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. List<Parameter> par = sqlbuilderService.getAllDrugInfo(param);
  163. List list = new ArrayList();
  164. for(Parameter p:par){
  165. Map map1 = new HashMap();
  166. map1.put("value", p.getDrugId());
  167. map1.put("label", p.getDrugName());
  168. list.add(map1);
  169. }
  170. String jsonString = JSONObject.toJSON(list).toString();
  171. printJson(res,jsonString);
  172. return null;
  173. }
  174. }