doctor.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. package restcontroller.prsx.doctor;
  2. import beans.datacontrllog.DataContrlLog;
  3. import beans.datatag.DataTag;
  4. import beans.datateam.DataTeam;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.data.*;
  10. import org.apache.commons.lang.StringUtils;
  11. import org.sqlite.core.DB;
  12. import restcontroller.R;
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. /**
  17. * 医生管理
  18. */
  19. public class doctor extends Controller {
  20. /**
  21. * 构造函数
  22. *
  23. * @param content
  24. */
  25. public doctor(JSONObject content) throws YosException {
  26. super(content);
  27. }
  28. @API(title = "新建或编辑", apiversion = R.ID2025102116461002.v1.class)
  29. public String insertOrUpdate() throws YosException {
  30. ArrayList<String> sqlList = new ArrayList<>();
  31. Long sa_doctorid = content.getLongValue("sa_doctorid");
  32. Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
  33. Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep WHERE sa_hospitaldepid=4 and siteid='" + siteid + "'");
  34. Long sa_customersid = rows.isNotEmpty() ? rows.get(0).getLong("sa_customersid") : 0;
  35. if (sa_doctorid <= 0) {
  36. sa_doctorid = createTableID("sa_doctor");
  37. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_doctor");
  38. insertSQL.setSiteid(siteid);
  39. insertSQL.setUniqueid(sa_doctorid);
  40. insertSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
  41. insertSQL.setValue("sa_customersid", sa_customersid);
  42. insertSQL.setValue("doctorname", content.getStringValue("doctorname"));
  43. insertSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
  44. insertSQL.setValue("professional", content.getStringValue("professional"));
  45. insertSQL.setValue("isleader", content.getBooleanValue("isleader"));
  46. insertSQL.setValue("remarks", content.getStringValue("remarks"));
  47. sqlList.add(insertSQL.getSQL());
  48. sqlList.add(DataContrlLog.createLog(this, "sa_doctor", sa_doctorid, "新建", "新建成功").getSQL());
  49. sqlList.addAll(DataTeam.createTeamSQL(this, "sa_doctor", sa_doctorid, userid));
  50. } else {
  51. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_doctor");
  52. updateSQL.setSiteid(siteid);
  53. updateSQL.setUniqueid(sa_doctorid);
  54. updateSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
  55. updateSQL.setValue("sa_customersid", sa_customersid);
  56. updateSQL.setValue("doctorname", content.getStringValue("doctorname"));
  57. updateSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
  58. updateSQL.setValue("professional", content.getStringValue("professional"));
  59. updateSQL.setValue("isleader", content.getBooleanValue("isleader"));
  60. updateSQL.setValue("remarks", content.getStringValue("remarks"));
  61. sqlList.add(updateSQL.getSQL());
  62. sqlList.add(DataContrlLog.createLog(this, "sa_doctor", sa_doctorid, "编辑", "编辑成功").getSQL());
  63. }
  64. dbConnect.runSqlUpdate(sqlList);
  65. content.put("sa_doctorid", sa_doctorid);
  66. return detail();
  67. }
  68. @API(title = "详情", apiversion = R.ID2025102116474702.v1.class)
  69. public String detail() throws YosException {
  70. Long sa_doctorid = content.getLongValue("sa_doctorid");
  71. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
  72. querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t2", "t2.sa_hospitaldepid=t1.sa_hospitaldepid and t2.siteid=t1.siteid", "hospitaldepname");
  73. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t3", "t3.sa_customersid=t1.sa_customersid");
  74. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t3.sys_enterpriseid",
  75. "enterprisename");
  76. querySQL.setSiteid(siteid);
  77. querySQL.setUniqueid(sa_doctorid);
  78. Rows rows = querySQL.query();
  79. ArrayList<Long> ids = rows.toArrayList("sa_doctorid", new ArrayList<>());
  80. RowsMap leaderRows = DataTeam.getLeader(this, "sa_doctor", rows.toArrayList("sa_doctorid")).toRowsMap("ownerid");
  81. //标签
  82. HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_doctor", ids, false);
  83. //系统标签
  84. HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_doctor", ids, true);
  85. for (Row row : rows) {
  86. Long id = row.getLong("sa_doctorid");
  87. row.put("leader", leaderRows.get(row.getString("sa_doctorid")));
  88. if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
  89. row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
  90. }
  91. ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
  92. ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
  93. //非系统标签
  94. row.put("tag", tag);
  95. //系统标签
  96. row.put("tag_sys", sys_tag);
  97. }
  98. Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
  99. return getSucReturnObject().setData(row).toString();
  100. }
  101. @API(title = "删除", apiversion = R.ID2025102116480402.v1.class)
  102. public String delete() throws YosException {
  103. Long sa_doctorid = content.getLongValue("sa_doctorid");
  104. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_doctor");
  105. deleteSQL.setSiteid(siteid);
  106. deleteSQL.setUniqueid(sa_doctorid);
  107. deleteSQL.delete();
  108. DataContrlLog.createLog(this, "sa_doctor", sa_doctorid, "删除", "删除成功").insert();
  109. return getSucReturnObject().toString();
  110. }
  111. @API(title = "列表", apiversion = R.ID2025102208523002.v1.class)
  112. public String list() throws YosException {
  113. String tablename = "sa_doctor";
  114. int type = content.getIntValue("type");
  115. StringBuffer where = new StringBuffer(" 1=1 ");
  116. if (content.containsKey("where")) {
  117. JSONObject whereObject = content.getJSONObject("where");
  118. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  119. where.append(" and(");
  120. where.append("t1.doctorname like'%").append(whereObject.getString("condition")).append("%' ");
  121. where.append("or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
  122. where.append("or t1.professional like'%").append(whereObject.getString("condition")).append("%' ");
  123. where.append("or t2.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
  124. where.append("or t4.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  125. where.append(")");
  126. }
  127. if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
  128. where.append(" and(");
  129. where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
  130. where.append(")");
  131. }
  132. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  133. where.append(" and(");
  134. where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  135. where.append(")");
  136. }
  137. //科室类别
  138. if (whereObject.containsKey("tag") && !whereObject.getJSONArray("tag").isEmpty()) {
  139. for (Object o : whereObject.getJSONArray("tag")) {
  140. where.append(" and exists(select 1 from sys_datatag WHERE ownertable = 'sa_doctor' and siteid='").append(siteid).append("' ");
  141. where.append(" and tag='").append(o).append("' and t1.sa_doctorid=ownerid ");
  142. where.append(")");
  143. }
  144. }
  145. }
  146. String where2 = " 1=1 ";
  147. if (type == 0) {
  148. where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
  149. + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
  150. } else {
  151. where2 = DataTeam.getDataWhereStr(this, tablename, "t1", type);
  152. }
  153. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
  154. querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t2", "t2.sa_hospitaldepid=t1.sa_hospitaldepid and t2.siteid=t1.siteid", "hospitaldepname");
  155. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t3", "t3.sa_customersid=t1.sa_customersid");
  156. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t3.sys_enterpriseid",
  157. "enterprisename");
  158. querySQL.setWhere(where);
  159. querySQL.setWhere(where2);
  160. querySQL.setSiteid(siteid);
  161. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  162. Rows rows = querySQL.query();
  163. ArrayList<Long> ids = rows.toArrayList("sa_doctorid", new ArrayList<>());
  164. RowsMap leaderRows = DataTeam.getLeader(this, "sa_doctor", rows.toArrayList("sa_doctorid")).toRowsMap("ownerid");
  165. //标签
  166. HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_doctor", ids, false);
  167. //系统标签
  168. HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_doctor", ids, true);
  169. for (Row row : rows) {
  170. Long id = row.getLong("sa_doctorid");
  171. row.put("leader", leaderRows.get(row.getString("sa_doctorid")));
  172. if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
  173. row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
  174. }
  175. ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
  176. ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
  177. //非系统标签
  178. row.put("tag", tag);
  179. //系统标签
  180. row.put("tag_sys", sys_tag);
  181. }
  182. return getSucReturnObject().setData(rows).toString();
  183. }
  184. @API(title = "选择科室", apiversion = R.ID2025102208540702.v1.class)
  185. public String choosehospitaldep() throws YosException {
  186. // 1:我负责的;2:我参与的;3:我下属负责的;4:我下属参与的
  187. String tablename = "sa_hospitaldep";
  188. StringBuffer where = new StringBuffer(" 1=1 ");
  189. if (content.containsKey("where")) {
  190. JSONObject whereObject = content.getJSONObject("where");
  191. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  192. where.append(" and(");
  193. where.append("t1.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
  194. where.append("or t3.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  195. where.append("or t4.name like'%").append(whereObject.getString("condition")).append("%' ");
  196. where.append(")");
  197. }
  198. }
  199. String where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
  200. + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
  201. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_hospitaldep", "*").setTableAlias("t1");
  202. querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
  203. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid", "enterprisename");
  204. querySQL.addJoinTable(JOINTYPE.left, "sys_datateam", "t4", "t4.ownertable = 'sa_hospitaldep' and t4.siteid = t1.siteid and t4.ownerid = t1.sa_hospitaldepid and t4.isleader = 1");
  205. querySQL.setSiteid(siteid);
  206. querySQL.setWhere(where);
  207. querySQL.setWhere(where2);
  208. Rows rows = querySQL.query();
  209. ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
  210. RowsMap leaderRows = DataTeam.getLeader(this, "sa_hospitaldep", rows.toArrayList("sa_hospitaldepid")).toRowsMap("ownerid");
  211. //标签
  212. HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
  213. //系统标签
  214. HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
  215. Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
  216. RowsMap doctorRowsMap = getDoctorRowsMap(ids);
  217. for (Row row : rows) {
  218. Long id = row.getLong("sa_hospitaldepid");
  219. row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
  220. if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
  221. row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
  222. }
  223. ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
  224. ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
  225. //非系统标签
  226. row.put("tag", tag);
  227. //系统标签
  228. row.put("tag_sys", sys_tag);
  229. //科室负责人
  230. Rows doctorRows = doctorRowsMap.getOrDefault(id.toString(), new Rows());
  231. row.putIfAbsent("doctors", StringUtils.join(doctorRows.toArray("doctorname"),","));
  232. String stagename = row.getString("stagename");
  233. for (Row stageRow : stageRows) {
  234. if (stagename.equals(stageRow.getString("stagename"))) {
  235. stageRow.put("active", 1);
  236. }
  237. stageRow.putIfAbsent("active", 0);
  238. }
  239. row.put("stages", stageRows);
  240. }
  241. return getSucReturnObject().setData(rows).toString();
  242. }
  243. public RowsMap getDoctorRowsMap(List<Long> sa_hospitaldepids) throws YosException {
  244. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
  245. querySQL.setSiteid(siteid);
  246. querySQL.setWhere("t1.isleader=1");
  247. querySQL.setWhere("t1.sa_hospitaldepid ", sa_hospitaldepids);
  248. Rows rows = querySQL.query();
  249. return rows.toRowsMap("sa_hospitaldepid");
  250. }
  251. }