|
|
@@ -0,0 +1,286 @@
|
|
|
+package restcontroller.prsx.doctor;
|
|
|
+
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.datatag.DataTag;
|
|
|
+import beans.datateam.DataTeam;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.sqlite.core.DB;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 医生管理
|
|
|
+ */
|
|
|
+public class doctor extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public doctor(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "新建或编辑", apiversion = R.ID2025102116461002.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ Long sa_doctorid = content.getLongValue("sa_doctorid");
|
|
|
+ Long sa_hospitaldepid = content.getLongValue("sa_hospitaldepid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_hospitaldep WHERE sa_hospitaldepid=4 and siteid='" + siteid + "'");
|
|
|
+ Long sa_customersid = rows.isNotEmpty() ? rows.get(0).getLong("sa_customersid") : 0;
|
|
|
+
|
|
|
+ if (sa_doctorid <= 0) {
|
|
|
+ sa_doctorid = createTableID("sa_doctor");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_doctor");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_doctorid);
|
|
|
+ insertSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
|
|
|
+ insertSQL.setValue("sa_customersid", sa_customersid);
|
|
|
+ insertSQL.setValue("doctorname", content.getStringValue("doctorname"));
|
|
|
+ insertSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
|
|
|
+ insertSQL.setValue("professional", content.getStringValue("professional"));
|
|
|
+ insertSQL.setValue("isleader", content.getBooleanValue("isleader"));
|
|
|
+ insertSQL.setValue("remarks", content.getStringValue("remarks"));
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_doctor", sa_doctorid, "新建", "新建成功").getSQL());
|
|
|
+ sqlList.addAll(DataTeam.createTeamSQL(this, "sa_doctor", sa_doctorid, userid));
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_doctor");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_doctorid);
|
|
|
+ updateSQL.setValue("sa_hospitaldepid", sa_hospitaldepid);
|
|
|
+ updateSQL.setValue("sa_customersid", sa_customersid);
|
|
|
+ updateSQL.setValue("doctorname", content.getStringValue("doctorname"));
|
|
|
+ updateSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
|
|
|
+ updateSQL.setValue("professional", content.getStringValue("professional"));
|
|
|
+ updateSQL.setValue("isleader", content.getBooleanValue("isleader"));
|
|
|
+ updateSQL.setValue("remarks", content.getStringValue("remarks"));
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_doctor", sa_doctorid, "编辑", "编辑成功").getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ content.put("sa_doctorid", sa_doctorid);
|
|
|
+
|
|
|
+ return detail();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "详情", apiversion = R.ID2025102116474702.v1.class)
|
|
|
+ public String detail() throws YosException {
|
|
|
+ Long sa_doctorid = content.getLongValue("sa_doctorid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t2", "t2.sa_hospitaldepid=t1.sa_hospitaldepid and t2.siteid=t1.siteid", "hospitaldepname");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t3", "t3.sa_customersid=t1.sa_customersid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t3.sys_enterpriseid",
|
|
|
+ "enterprisename");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setUniqueid(sa_doctorid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sa_doctorid", new ArrayList<>());
|
|
|
+ RowsMap leaderRows = DataTeam.getLeader(this, "sa_doctor", rows.toArrayList("sa_doctorid")).toRowsMap("ownerid");
|
|
|
+ //标签
|
|
|
+ HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_doctor", ids, false);
|
|
|
+ //系统标签
|
|
|
+ HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_doctor", ids, true);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Long id = row.getLong("sa_doctorid");
|
|
|
+ row.put("leader", leaderRows.get(row.getString("sa_doctorid")));
|
|
|
+ if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
|
|
|
+ row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
|
|
|
+ }
|
|
|
+ ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
|
|
|
+ ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
|
|
|
+ //非系统标签
|
|
|
+ row.put("tag", tag);
|
|
|
+ //系统标签
|
|
|
+ row.put("tag_sys", sys_tag);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(row).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID2025102116480402.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+ Long sa_doctorid = content.getLongValue("sa_doctorid");
|
|
|
+
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_doctor");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setUniqueid(sa_doctorid);
|
|
|
+ deleteSQL.delete();
|
|
|
+
|
|
|
+ DataContrlLog.createLog(this, "sa_doctor", sa_doctorid, "删除", "删除成功").insert();
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "列表", apiversion = R.ID2025102208523002.v1.class)
|
|
|
+ public String list() throws YosException {
|
|
|
+
|
|
|
+ String tablename = "sa_doctor";
|
|
|
+ int type = content.getIntValue("type");
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.doctorname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.professional like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t4.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.createdate >='").append(whereObject.getString("startdate")).append(" 00:00:00' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ //科室类别
|
|
|
+ if (whereObject.containsKey("tag") && !whereObject.getJSONArray("tag").isEmpty()) {
|
|
|
+ for (Object o : whereObject.getJSONArray("tag")) {
|
|
|
+ where.append(" and exists(select 1 from sys_datatag WHERE ownertable = 'sa_doctor' and siteid='").append(siteid).append("' ");
|
|
|
+ where.append(" and tag='").append(o).append("' and t1.sa_doctorid=ownerid ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String where2 = " 1=1 ";
|
|
|
+ if (type == 0) {
|
|
|
+ where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
|
|
|
+ + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
|
|
|
+ } else {
|
|
|
+ where2 = DataTeam.getDataWhereStr(this, tablename, "t1", type);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_hospitaldep", "t2", "t2.sa_hospitaldepid=t1.sa_hospitaldepid and t2.siteid=t1.siteid", "hospitaldepname");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t3", "t3.sa_customersid=t1.sa_customersid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t3.sys_enterpriseid",
|
|
|
+ "enterprisename");
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setWhere(where2);
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sa_doctorid", new ArrayList<>());
|
|
|
+ RowsMap leaderRows = DataTeam.getLeader(this, "sa_doctor", rows.toArrayList("sa_doctorid")).toRowsMap("ownerid");
|
|
|
+ //标签
|
|
|
+ HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_doctor", ids, false);
|
|
|
+ //系统标签
|
|
|
+ HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_doctor", ids, true);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Long id = row.getLong("sa_doctorid");
|
|
|
+ row.put("leader", leaderRows.get(row.getString("sa_doctorid")));
|
|
|
+ if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
|
|
|
+ row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
|
|
|
+ }
|
|
|
+ ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
|
|
|
+ ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
|
|
|
+ //非系统标签
|
|
|
+ row.put("tag", tag);
|
|
|
+ //系统标签
|
|
|
+ row.put("tag_sys", sys_tag);
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "选择科室", apiversion = R.ID2025102208540702.v1.class)
|
|
|
+ public String choosehospitaldep() throws YosException {
|
|
|
+ // 1:我负责的;2:我参与的;3:我下属负责的;4:我下属参与的
|
|
|
+ String tablename = "sa_hospitaldep";
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.hospitaldepname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t3.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t4.name like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String where2 = "(" + DataTeam.getDataWhereStr(this, tablename, "t1", 1)
|
|
|
+ + " or " + DataTeam.getDataWhereStr(this, tablename, "t1", 2) + ")";
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_hospitaldep", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_customers", "t2", "t2.sa_customersid=t1.sa_customersid and t2.siteid=t1.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t3.sys_enterpriseid=t2.sys_enterpriseid and t3.siteid=t2.siteid", "enterprisename");
|
|
|
+ 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");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setWhere(where2);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sa_hospitaldepid", new ArrayList<>());
|
|
|
+ RowsMap leaderRows = DataTeam.getLeader(this, "sa_hospitaldep", rows.toArrayList("sa_hospitaldepid")).toRowsMap("ownerid");
|
|
|
+ //标签
|
|
|
+ HashMap<Long, ArrayList<String>> tagList = DataTag.queryTag(this, "sa_hospitaldep", ids, false);
|
|
|
+ //系统标签
|
|
|
+ HashMap<Long, ArrayList<String>> sysTagList = DataTag.queryTag(this, "sa_hospitaldep", ids, true);
|
|
|
+ Rows stageRows = dbConnect.runSqlQuery("SELECT stagename,sequence from sa_devstage WHERE siteid='" + siteid + "' order by sequence");
|
|
|
+ RowsMap doctorRowsMap = getDoctorRowsMap(ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Long id = row.getLong("sa_hospitaldepid");
|
|
|
+ row.put("leader", leaderRows.get(row.getString("sa_hospitaldepid")));
|
|
|
+ if (leaderRows.get(String.valueOf(id)).isNotEmpty()) {
|
|
|
+ row.put("depname", leaderRows.get(String.valueOf(id)).get(0).getString("depname"));
|
|
|
+ }
|
|
|
+ ArrayList<String> tag = tagList.get(id) != null ? tagList.get(id) : new ArrayList<>();
|
|
|
+ ArrayList<String> sys_tag = sysTagList.get(id) != null ? sysTagList.get(id) : new ArrayList<>();
|
|
|
+ //非系统标签
|
|
|
+ row.put("tag", tag);
|
|
|
+ //系统标签
|
|
|
+ row.put("tag_sys", sys_tag);
|
|
|
+ //科室负责人
|
|
|
+ Rows doctorRows = doctorRowsMap.getOrDefault(id.toString(), new Rows());
|
|
|
+ row.putIfAbsent("doctors", StringUtils.join(doctorRows.toArray("doctorname"),","));
|
|
|
+ String stagename = row.getString("stagename");
|
|
|
+ for (Row stageRow : stageRows) {
|
|
|
+ if (stagename.equals(stageRow.getString("stagename"))) {
|
|
|
+ stageRow.put("active", 1);
|
|
|
+ }
|
|
|
+ stageRow.putIfAbsent("active", 0);
|
|
|
+ }
|
|
|
+ row.put("stages", stageRows);
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public RowsMap getDoctorRowsMap(List<Long> sa_hospitaldepids) throws YosException {
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_doctor", "*").setTableAlias("t1");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("t1.isleader=1");
|
|
|
+ querySQL.setWhere("t1.sa_hospitaldepid ", sa_hospitaldepids);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return rows.toRowsMap("sa_hospitaldepid");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|