|  | @ -1,5 +1,6 @@
 | 
												
													
														
															|  | package com.yihu.jw.base.service.doctor;
 |  | package com.yihu.jw.base.service.doctor;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import com.alibaba.fastjson.JSONArray;
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSONObject;
 |  | import com.alibaba.fastjson.JSONObject;
 | 
												
													
														
															|  | import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
 |  | import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
 | 
												
													
														
															|  | import com.fasterxml.jackson.databind.ObjectMapper;
 |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
												
											
												
													
														
															|  | @ -12,8 +13,7 @@ import com.yihu.jw.base.service.org.tree.TreeNode;
 | 
												
													
														
															|  | import com.yihu.jw.base.util.ConstantUtils;
 |  | import com.yihu.jw.base.util.ConstantUtils;
 | 
												
													
														
															|  | import com.yihu.jw.base.util.JavaBeanUtils;
 |  | import com.yihu.jw.base.util.JavaBeanUtils;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 |  | import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 |  | 
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
 |  | 
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
 | 
												
													
														
															|  | import com.yihu.mysql.query.BaseJpaService;
 |  | import com.yihu.mysql.query.BaseJpaService;
 | 
												
													
														
															|  | import org.springframework.beans.factory.annotation.Autowired;
 |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | import org.springframework.jdbc.core.JdbcTemplate;
 |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
												
											
												
													
														
															|  | @ -24,10 +24,8 @@ import org.springframework.util.CollectionUtils;
 | 
												
													
														
															|  | import org.springframework.util.StringUtils;
 |  | import org.springframework.util.StringUtils;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | import java.io.IOException;
 |  | import java.io.IOException;
 | 
												
													
														
															|  | import java.util.ArrayList;
 |  | 
 | 
												
													
														
															|  | import java.util.HashMap;
 |  | 
 | 
												
													
														
															|  | import java.util.List;
 |  | 
 | 
												
													
														
															|  | import java.util.Map;
 |  | 
 | 
												
													
														
															|  | 
 |  | import java.util.*;
 | 
												
													
														
															|  | 
 |  | import java.util.regex.Pattern;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | /**
 |  | /**
 | 
												
													
														
															|  |  * 
 |  |  * 
 | 
												
											
												
													
														
															|  | @ -45,16 +43,16 @@ import java.util.Map;
 | 
												
													
														
															|  | public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
 |  | public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private BaseDoctorHospitalService baseDoctorHospitalService;
 |  | 
 | 
												
													
														
															|  | 
 |  |     private BaseDoctorDao baseDoctorDao;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private BaseDoctorRoleDictService baseDoctorRoleDictService;
 |  | 
 | 
												
													
														
															|  | 
 |  |     private BaseDoctorHospitalService baseDoctorHospitalService;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private JdbcTemplate jdbcTemplate;
 |  | 
 | 
												
													
														
															|  | 
 |  |     private BaseDoctorRoleService baseDoctorRoleService;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private OrgTreeService orgTreeService;
 |  | 
 | 
												
													
														
															|  | 
 |  |     private JdbcTemplate jdbcTemplate;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private ObjectMapper objectMapper;
 |  |     private ObjectMapper objectMapper;
 | 
												
											
												
													
														
															|  | @ -66,7 +64,7 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
 | 
												
													
														
															|  |      * @param doctorId 医生id
 |  |      * @param doctorId 医生id
 | 
												
													
														
															|  |      * @return
 |  |      * @return
 | 
												
													
														
															|  |      */
 |  |      */
 | 
												
													
														
															|  |     public Map<String,Object> getDoctorInfo(String orgId, String doctorId) throws Exception{
 |  | 
 | 
												
													
														
															|  | 
 |  |     public Map<String,Object> getOneDoctorInfo(String orgId, String doctorId) throws Exception{
 | 
												
													
														
															|  |         Map<String,Object> resultMap = new HashMap<>();
 |  |         Map<String,Object> resultMap = new HashMap<>();
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         if(StringUtils.isEmpty(orgId) || StringUtils.isEmpty(doctorId)){
 |  |         if(StringUtils.isEmpty(orgId) || StringUtils.isEmpty(doctorId)){
 | 
												
											
												
													
														
															|  | @ -94,40 +92,82 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 获取医生信息(包括医生任职的医院相关信息)
 |  |      * 获取医生信息(包括医生任职的医院相关信息)
 | 
												
													
														
															|  |      * @param name
 |  | 
 | 
												
													
														
															|  |      * @param idcard
 |  | 
 | 
												
													
														
															|  | 
 |  |      * @param nameOrIdcard
 | 
												
													
														
															|  |      * @param orgCode
 |  |      * @param orgCode
 | 
												
													
														
															|  |      * @param docStatus
 |  |      * @param docStatus
 | 
												
													
														
															|  |      * @return
 |  |      * @return
 | 
												
													
														
															|  |      */
 |  |      */
 | 
												
													
														
															|  |     public List<Map<String,Object>> getDoctorFullInfo(String name,String idcard,String orgCode,String docStatus){
 |  | 
 | 
												
													
														
															|  |         List<Map<String,Object>> result = new ArrayList<>();
 |  | 
 | 
												
													
														
															|  |         StringBuilder sql = new StringBuilder();
 |  | 
 | 
												
													
														
															|  |         sql.append("select doc.id,doc.name,doc.idcard,case doc.sex when 1 then '男' when 2 then '女' else '未知' end as sex,doc.del as status,hos.hosp_name as hosptialName,dept.name as deptName,hos.role_name as roleName,hos.job_title_name jobTitleName from base_doctor doc,base_doctor_hospital hos,dict_hospital_dept dept where doc.id = hos.doctor_code and hos.dept_code = dept.code and hos.del = 1");
 |  | 
 | 
												
													
														
															|  |         if(StringUtils.isEmpty(name) && StringUtils.isEmpty(idcard) && StringUtils.isEmpty(orgCode) && StringUtils.isEmpty(docStatus)){
 |  | 
 | 
												
													
														
															|  |            result = jdbcTemplate.queryForList(sql.toString());
 |  | 
 | 
												
													
														
															|  |         }else if(StringUtils.isEmpty(name) || StringUtils.isEmpty(idcard)){
 |  | 
 | 
												
													
														
															|  |             if (!StringUtils.isEmpty(name)) {
 |  | 
 | 
												
													
														
															|  |                 sql.append(" and doc.name = '").append(idcard).append("'");
 |  | 
 | 
												
													
														
															|  |             }else{
 |  | 
 | 
												
													
														
															|  |                 sql.append(" and doc.idcard = '").append(name).append("'");
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             if(StringUtils.isEmpty(orgCode) && !StringUtils.isEmpty(docStatus)){
 |  | 
 | 
												
													
														
															|  |                 sql.append(" and doc.del = '").append(docStatus).append("'");
 |  | 
 | 
												
													
														
															|  |             }else if(!StringUtils.isEmpty(orgCode) && StringUtils.isEmpty(docStatus)){
 |  | 
 | 
												
													
														
															|  |                 sql.append(" and hos.hosp_code = '").append(orgCode).append("'");
 |  | 
 | 
												
													
														
															|  |             }else{
 |  | 
 | 
												
													
														
															|  |                 sql.append(" and hos.hosp_code = '").append(orgCode).append("'");
 |  | 
 | 
												
													
														
															|  |                 sql.append(" and doc.del = '").append(docStatus).append("'");
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             result = jdbcTemplate.queryForList(sql.toString());
 |  | 
 | 
												
													
														
															|  |         }else if(StringUtils.isEmpty(orgCode)){
 |  | 
 | 
												
													
														
															|  |             sql.append(" and doc.hosp_code = '").append(orgCode).append("'");
 |  | 
 | 
												
													
														
															|  |             result = jdbcTemplate.queryForList(sql.toString());
 |  | 
 | 
												
													
														
															|  |         }else{
 |  | 
 | 
												
													
														
															|  |             sql.append(" and doc.del = '").append(docStatus).append("'");
 |  | 
 | 
												
													
														
															|  |             result = jdbcTemplate.queryForList(sql.toString());
 |  | 
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  | 
 |  |     public JSONObject queryDoctorListFullInfo(String nameOrIdcard, String orgCode, String docStatus, int page, int size) throws Exception {
 | 
												
													
														
															|  | 
 |  |         JSONObject result = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         String orgCodeVale = null == orgCode ? "" : orgCode;
 | 
												
													
														
															|  | 
 |  |         String del = null == docStatus ? "" : docStatus;
 | 
												
													
														
															|  | 
 |  |         String nameOrIdcardValue = null == nameOrIdcard ? "" : nameOrIdcard;
 | 
												
													
														
															|  | 
 |  |         int start = 0 == page ? page++ : (page - 1) * size;
 | 
												
													
														
															|  | 
 |  |         int end = 0 == size ? 15 : page * size;
 | 
												
													
														
															|  | 
 |  |         String sql = "select" +
 | 
												
													
														
															|  | 
 |  |                 "  tb.id as id," +
 | 
												
													
														
															|  | 
 |  |                 "  tb.name as name," +
 | 
												
													
														
															|  | 
 |  |                 "  tb.idcard as idcard,  " +
 | 
												
													
														
															|  | 
 |  |                 "  tb.sex as sex,  " +
 | 
												
													
														
															|  | 
 |  |                 "  tb.mobile as mobile,  " +
 | 
												
													
														
															|  | 
 |  |                 "  GROUP_CONCAT(tb.org SEPARATOR ',') as orgInfo,  " +
 | 
												
													
														
															|  | 
 |  |                 "  tb.status as status " +
 | 
												
													
														
															|  | 
 |  |                 "from  " +
 | 
												
													
														
															|  | 
 |  |                 "  (  " +
 | 
												
													
														
															|  | 
 |  |                 "    select  " +
 | 
												
													
														
															|  | 
 |  |                 "     doc.id,  " +
 | 
												
													
														
															|  | 
 |  |                 "     doc.name,  " +
 | 
												
													
														
															|  | 
 |  |                 "     doc.idcard,  " +
 | 
												
													
														
															|  | 
 |  |                 "     case doc.sex when 1 then '男' when 2 then '女' else '未知' end as sex,  " +
 | 
												
													
														
															|  | 
 |  |                 "     doc.mobile,  " +
 | 
												
													
														
															|  | 
 |  |                 "     concat(hos.hosp_name,'/',dept.name,'/',hos.doctor_duty_name,'/',hos.job_title_name) as org,  " +
 | 
												
													
														
															|  | 
 |  |                 "     case doc.del when 0 then '无效' when 1 then '有效' end as status,  " +
 | 
												
													
														
															|  | 
 |  |                 "      doc.create_time  " +
 | 
												
													
														
															|  | 
 |  |                 "   from  " +
 | 
												
													
														
															|  | 
 |  |                 "     base_doctor doc,  " +
 | 
												
													
														
															|  | 
 |  |                 "     base_doctor_hospital hos,  " +
 | 
												
													
														
															|  | 
 |  |                 "     dict_hospital_dept dept  " +
 | 
												
													
														
															|  | 
 |  |                 "  where  " +
 | 
												
													
														
															|  | 
 |  |                 "    doc.id = hos.doctor_code  " +
 | 
												
													
														
															|  | 
 |  |                 "    and  " +
 | 
												
													
														
															|  | 
 |  |                 "    hos.dept_code = dept.code  " +
 | 
												
													
														
															|  | 
 |  |                 "    and  " +
 | 
												
													
														
															|  | 
 |  |                 "    ((doc.idcard like '{idcard}' or ''= '{idcard}'  ) and (hos.hosp_code = '{orgCode}' or ''= '{orgCode}') and (doc.del = '{docStatus}' or ''= '{docStatus}'))  " +
 | 
												
													
														
															|  | 
 |  |                 "      or  " +
 | 
												
													
														
															|  | 
 |  |                 "    ((doc.name like '{name}'  or ''= '{name}' )  and (hos.hosp_code = '{orgCode}' or ''= '{orgCode}') and (doc.del = '{docStatus}' or ''= '{docStatus}'))  " +
 | 
												
													
														
															|  | 
 |  |                 "  ) tb  " +
 | 
												
													
														
															|  | 
 |  |                 "GROUP BY tb.id order by tb.create_time desc limit {start},{end} ";
 | 
												
													
														
															|  | 
 |  |         String finalSql = sql
 | 
												
													
														
															|  | 
 |  |                 .replace("{idcard}",nameOrIdcardValue)
 | 
												
													
														
															|  | 
 |  |                 .replace("{name}",nameOrIdcardValue)
 | 
												
													
														
															|  | 
 |  |                 .replace("{orgCode}",orgCodeVale)
 | 
												
													
														
															|  | 
 |  |                 .replace("{docStatus}",del)
 | 
												
													
														
															|  | 
 |  |                 .replace("{start}",String.valueOf(start))
 | 
												
													
														
															|  | 
 |  |                 .replace("{end}",String.valueOf(end));
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         String countSql = " select " +
 | 
												
													
														
															|  | 
 |  |                 "     count(DISTINCT (doc.id)) as count " +
 | 
												
													
														
															|  | 
 |  |                 "   from " +
 | 
												
													
														
															|  | 
 |  |                 "     base_doctor doc, " +
 | 
												
													
														
															|  | 
 |  |                 "     base_doctor_hospital hos, " +
 | 
												
													
														
															|  | 
 |  |                 "     dict_hospital_dept dept " +
 | 
												
													
														
															|  | 
 |  |                 "  where " +
 | 
												
													
														
															|  | 
 |  |                 "    doc.id = hos.doctor_code " +
 | 
												
													
														
															|  | 
 |  |                 "    and " +
 | 
												
													
														
															|  | 
 |  |                 "    hos.dept_code = dept.code " +
 | 
												
													
														
															|  | 
 |  |                 "    and " +
 | 
												
													
														
															|  | 
 |  |                 "    ((doc.idcard like '{idcard}' or ''= '{idcard}' ) and (hos.hosp_code = '{orgCode}' or ''= '{orgCode}') and (doc.del = '{docStatus}' or ''= '{docStatus}')) " +
 | 
												
													
														
															|  | 
 |  |                 "      or " +
 | 
												
													
														
															|  | 
 |  |                 "    ((doc.name like '{name}' or ''= '{name}')  and (hos.hosp_code = '{orgCode}' or ''= '{orgCode}') and (doc.del = '{docStatus}' or ''= '{docStatus}')) ";
 | 
												
													
														
															|  | 
 |  |         String finalCountSql = countSql
 | 
												
													
														
															|  | 
 |  |                 .replace("{idcard}",nameOrIdcardValue)
 | 
												
													
														
															|  | 
 |  |                 .replace("{name}",nameOrIdcardValue)
 | 
												
													
														
															|  | 
 |  |                 .replace("{orgCode}",orgCodeVale)
 | 
												
													
														
															|  | 
 |  |                 .replace("{docStatus}",del);
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(finalSql);
 | 
												
													
														
															|  | 
 |  |         int count = jdbcTemplate.queryForObject(finalCountSql,Integer.class);
 | 
												
													
														
															|  | 
 |  |         result.put("count", count);
 | 
												
													
														
															|  | 
 |  |         result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
 | 
												
													
														
															|  |         return result;
 |  |         return result;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
											
												
													
														
															|  | @ -146,14 +186,15 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         JSONObject jsonObject = JSONObject.parseObject(jsonData);
 |  |         JSONObject jsonObject = JSONObject.parseObject(jsonData);
 | 
												
													
														
															|  |         JSONObject doctor = jsonObject.getJSONObject("doctor");
 |  |         JSONObject doctor = jsonObject.getJSONObject("doctor");
 | 
												
													
														
															|  |         JSONObject hospital = jsonObject.getJSONObject("hospital");
 |  | 
 | 
												
													
														
															|  |         if(null == doctor || null == hospital){
 |  | 
 | 
												
													
														
															|  | 
 |  |         JSONArray role = jsonObject.getJSONArray("role");
 | 
												
													
														
															|  | 
 |  |         JSONArray hospital = jsonObject.getJSONArray("hospital");
 | 
												
													
														
															|  | 
 |  |         if(null == doctor || CollectionUtils.isEmpty(role) || CollectionUtils.isEmpty(hospital)){
 | 
												
													
														
															|  |             result.put("msg","parameter doctor or hospital of jsonData is null");
 |  |             result.put("msg","parameter doctor or hospital of jsonData is null");
 | 
												
													
														
															|  |             result.put("response", ConstantUtils.FAIL);
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  |             return result.toJSONString();
 |  |             return result.toJSONString();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //组装医生信息
 | 
												
													
														
															|  |         BaseDoctorDO baseDoctorDO = null;
 |  |         BaseDoctorDO baseDoctorDO = null;
 | 
												
													
														
															|  |         BaseDoctorHospitalDO baseDoctorHospitalDO = null;
 |  | 
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
													
														
															|  |             baseDoctorDO = objectMapper.readValue(doctor.toJSONString(),BaseDoctorDO.class);
 |  |             baseDoctorDO = objectMapper.readValue(doctor.toJSONString(),BaseDoctorDO.class);
 | 
												
													
														
															|  |         } catch (IOException e) {
 |  |         } catch (IOException e) {
 | 
												
											
												
													
														
															|  | @ -161,34 +202,263 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
 | 
												
													
														
															|  |            result.put("response",ConstantUtils.FAIL);
 |  |            result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  |            return result.toJSONString();
 |  |            return result.toJSONString();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  |         baseDoctorDO.setPassword(baseDoctorDO.getIdcard().substring(11,17));
 | 
												
													
														
															|  |         this.save(baseDoctorDO);
 |  |         this.save(baseDoctorDO);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //组装医生角色关联关系
 | 
												
													
														
															|  | 
 |  |         BaseDoctorRoleDO baseDoctorRoleDO = null;
 | 
												
													
														
															|  | 
 |  |         List<BaseDoctorRoleDO> baseDoctorRoleDOList = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             for(Object object : role){
 | 
												
													
														
															|  | 
 |  |                 baseDoctorRoleDO = objectMapper.readValue(object.toString(),BaseDoctorRoleDO.class);
 | 
												
													
														
															|  | 
 |  |                 baseDoctorRoleDO.setDoctorCode(baseDoctorDO.getId());
 | 
												
													
														
															|  | 
 |  |                 baseDoctorRoleDOList.add(baseDoctorRoleDO);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         } catch (IOException e) {
 | 
												
													
														
															|  | 
 |  |             result.put("msg","convert hospital jsonObject to baseDoctorHospitalDO failed," + e.getCause());
 | 
												
													
														
															|  | 
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         baseDoctorRoleService.batchInsert(baseDoctorRoleDOList);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         // 组装医生任职机构及职业信息
 | 
												
													
														
															|  | 
 |  |         BaseDoctorHospitalDO baseDoctorHospitalDO = null;
 | 
												
													
														
															|  | 
 |  |         List<BaseDoctorHospitalDO> hospitalDOList = new ArrayList<>();
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
													
														
															|  |             baseDoctorHospitalDO = objectMapper.readValue(hospital.toJSONString(),BaseDoctorHospitalDO.class);
 |  | 
 | 
												
													
														
															|  |             baseDoctorHospitalDO.setDoctorCode(baseDoctorDO.getId());
 |  | 
 | 
												
													
														
															|  | 
 |  |             for(Object object : hospital){
 | 
												
													
														
															|  | 
 |  |                 baseDoctorHospitalDO = objectMapper.readValue(object.toString(),BaseDoctorHospitalDO.class);
 | 
												
													
														
															|  | 
 |  |                 baseDoctorHospitalDO.setDoctorCode(baseDoctorDO.getId());
 | 
												
													
														
															|  | 
 |  |                 hospitalDOList.add(baseDoctorHospitalDO);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  |         } catch (IOException e) {
 |  |         } catch (IOException e) {
 | 
												
													
														
															|  |             result.put("msg","convert hospital jsonObject to baseDoctorHospitalDO failed," + e.getCause());
 |  |             result.put("msg","convert hospital jsonObject to baseDoctorHospitalDO failed," + e.getCause());
 | 
												
													
														
															|  |             result.put("response",ConstantUtils.FAIL);
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         baseDoctorHospitalService.save(baseDoctorHospitalDO);
 |  | 
 | 
												
													
														
															|  | 
 |  |         baseDoctorHospitalService.batchInsert(hospitalDOList);
 | 
												
													
														
															|  |         result.put("response",ConstantUtils.SUCCESS);
 |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
												
													
														
															|  |         result.put("msg",baseDoctorDO);
 |  |         result.put("msg",baseDoctorDO);
 | 
												
													
														
															|  |         return result.toJSONString();
 |  |         return result.toJSONString();
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 修改医生
 | 
												
													
														
															|  | 
 |  |      * @param jsonData
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     @Transactional(rollbackFor = Exception.class)
 | 
												
													
														
															|  | 
 |  |     public String updateDoctor(String jsonData){
 | 
												
													
														
															|  | 
 |  |         JSONObject result = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(jsonData)){
 | 
												
													
														
															|  | 
 |  |             result.put("msg","jsonData is null");
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         JSONObject jsonObject = JSONObject.parseObject(jsonData);
 | 
												
													
														
															|  | 
 |  |         JSONObject doctor = jsonObject.getJSONObject("doctor");
 | 
												
													
														
															|  | 
 |  |         JSONArray role = jsonObject.getJSONArray("role");
 | 
												
													
														
															|  | 
 |  |         JSONArray hospital = jsonObject.getJSONArray("hospital");
 | 
												
													
														
															|  | 
 |  |         if(null == doctor || CollectionUtils.isEmpty(role) || CollectionUtils.isEmpty(hospital)){
 | 
												
													
														
															|  | 
 |  |             result.put("msg","parameter doctor or hospital of jsonData is null");
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         //判断医生id是否存在
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(doctor.getString("id"))){
 | 
												
													
														
															|  | 
 |  |             result.put("msg","parameter id for doctor is null when update doctor");
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         // 修改医生信息
 | 
												
													
														
															|  | 
 |  |         BaseDoctorDO baseDoctorDO = null;
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             baseDoctorDO = objectMapper.readValue(doctor.toJSONString(),BaseDoctorDO.class);
 | 
												
													
														
															|  | 
 |  |         } catch (IOException e) {
 | 
												
													
														
															|  | 
 |  |             result.put("msg","convert doctor jsonObject to BaseDoctorDO failed," + e.getCause());
 | 
												
													
														
															|  | 
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         this.save(baseDoctorDO);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //修改医生角色关联关系
 | 
												
													
														
															|  | 
 |  |         BaseDoctorRoleDO baseDoctorRoleDO = null;
 | 
												
													
														
															|  | 
 |  |         Set<Object> roleIdList = baseDoctorRoleService.findRoleIdList(baseDoctorDO.getId());
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             for(Object object : hospital){
 | 
												
													
														
															|  | 
 |  |                 baseDoctorRoleDO = objectMapper.readValue(object.toString(),BaseDoctorRoleDO.class);
 | 
												
													
														
															|  | 
 |  |                 if(roleIdList.contains(baseDoctorRoleDO.getId())){
 | 
												
													
														
															|  | 
 |  |                     roleIdList.remove(baseDoctorRoleDO.getId());
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 baseDoctorRoleDO.setDoctorCode(baseDoctorDO.getId());
 | 
												
													
														
															|  | 
 |  |                 baseDoctorRoleService.save(baseDoctorRoleDO);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         } catch (IOException e) {
 | 
												
													
														
															|  | 
 |  |             result.put("msg","convert hospital jsonObject to baseDoctorHospitalDO failed," + e.getCause());
 | 
												
													
														
															|  | 
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         baseDoctorHospitalService.delete(roleIdList.toArray());
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         // 修改医生任职机构及职业信息
 | 
												
													
														
															|  | 
 |  |         BaseDoctorHospitalDO baseDoctorHospitalDO = null;
 | 
												
													
														
															|  | 
 |  |         Set<Object> hospitalIdList = baseDoctorHospitalService.findDocHospIdList(baseDoctorDO.getId());
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             for(Object object : hospital){
 | 
												
													
														
															|  | 
 |  |                 baseDoctorHospitalDO = objectMapper.readValue(object.toString(),BaseDoctorHospitalDO.class);
 | 
												
													
														
															|  | 
 |  |                 if(hospitalIdList.contains(baseDoctorHospitalDO.getId())){
 | 
												
													
														
															|  | 
 |  |                     hospitalIdList.remove(baseDoctorHospitalDO.getId());
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |                 baseDoctorHospitalDO.setDoctorCode(baseDoctorDO.getId());
 | 
												
													
														
															|  | 
 |  |                 baseDoctorHospitalService.save(baseDoctorHospitalDO);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         } catch (IOException e) {
 | 
												
													
														
															|  | 
 |  |             result.put("msg","convert hospital jsonObject to baseDoctorHospitalDO failed," + e.getCause());
 | 
												
													
														
															|  | 
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         baseDoctorHospitalService.delete(hospitalIdList.toArray());
 | 
												
													
														
															|  | 
 |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
												
													
														
															|  | 
 |  |         result.put("msg",baseDoctorDO);
 | 
												
													
														
															|  | 
 |  |         return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 生效或失效单个医生
 | 
												
													
														
															|  | 
 |  |      * @param doctorCode
 | 
												
													
														
															|  | 
 |  |      * @param del
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public String enableOrDisableDoctor(String doctorCode,String del){
 | 
												
													
														
															|  | 
 |  |         JSONObject result = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(doctorCode) || StringUtils.isEmpty(del)){
 | 
												
													
														
															|  | 
 |  |             result.put("msg","parameter doctorCode or del is null");
 | 
												
													
														
															|  | 
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         BaseDoctorDO baseDoctorDO = baseDoctorDao.findOne(doctorCode);
 | 
												
													
														
															|  | 
 |  |         if( null == baseDoctorDO ){
 | 
												
													
														
															|  | 
 |  |             result.put("msg","doctor not exist for id:" + doctorCode);
 | 
												
													
														
															|  | 
 |  |             result.put("response",ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         baseDoctorDO.setDel(del);
 | 
												
													
														
															|  | 
 |  |         this.save(baseDoctorDO);
 | 
												
													
														
															|  | 
 |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
												
													
														
															|  | 
 |  |         return result.toJSONString();
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 获取医生已选中的机构/职务树形结构
 | 
												
													
														
															|  | 
 |  |      * @param doctorCode
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public String getDoctorDutyTree(String doctorCode){
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(doctorCode)){
 | 
												
													
														
															|  | 
 |  |             return "";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         List<BaseDoctorHospitalDO> list = baseDoctorHospitalService.getOrgAndDutyListByDoctorCode(doctorCode);
 | 
												
													
														
															|  | 
 |  |         List<OrgTree> orgTreeList = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         for(BaseDoctorHospitalDO one : list){
 | 
												
													
														
															|  | 
 |  |             OrgTree orgTreeParent = new OrgTree();
 | 
												
													
														
															|  | 
 |  |             orgTreeParent.setParentCode("");
 | 
												
													
														
															|  | 
 |  |             orgTreeParent.setCode(one.getHospCode());
 | 
												
													
														
															|  | 
 |  |             orgTreeParent.setName(one.getHospName());
 | 
												
													
														
															|  | 
 |  |             orgTreeList.add(orgTreeParent);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             OrgTree orgTreeChild = new OrgTree();
 | 
												
													
														
															|  | 
 |  |             orgTreeChild.setParentCode(one.getHospCode());
 | 
												
													
														
															|  | 
 |  |             orgTreeChild.setCode(one.getDoctorDutyCode());
 | 
												
													
														
															|  | 
 |  |             orgTreeChild.setName(one.getDoctorDutyName());
 | 
												
													
														
															|  | 
 |  |             orgTreeList.add(orgTreeChild);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return getOrgTree(orgTreeList);
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * 构建区域树形结构()
 |  | 
 | 
												
													
														
															|  |      * @Param level 参考OrgTree的Level枚举类型
 |  | 
 | 
												
													
														
															|  | 
 |  |      * 获取医生已选中的机构/科室树形结构
 | 
												
													
														
															|  | 
 |  |      * @param doctorCode
 | 
												
													
														
															|  |      * @return
 |  |      * @return
 | 
												
													
														
															|  |      */
 |  |      */
 | 
												
													
														
															|  |     public String getOrgTree(OrgTree.Level level){
 |  | 
 | 
												
													
														
															|  | 
 |  |     public String getDoctorDeptTree(String doctorCode){
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(doctorCode)){
 | 
												
													
														
															|  | 
 |  |             return "";
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         String sql = "select" +
 | 
												
													
														
															|  | 
 |  |                 "  hos.doctor_code ," +
 | 
												
													
														
															|  | 
 |  |                 "  hos.hosp_code as parentCode," +
 | 
												
													
														
															|  | 
 |  |                 "  org.name as parentName," +
 | 
												
													
														
															|  | 
 |  |                 "  hos.dept_code as childCode," +
 | 
												
													
														
															|  | 
 |  |                 "  dept.name as childName" +
 | 
												
													
														
															|  | 
 |  |                 " from" +
 | 
												
													
														
															|  | 
 |  |                 "  base_doctor_hospital hos," +
 | 
												
													
														
															|  | 
 |  |                 "  base_org org," +
 | 
												
													
														
															|  | 
 |  |                 "  dict_hospital_dept dept" +
 | 
												
													
														
															|  | 
 |  |                 " where" +
 | 
												
													
														
															|  | 
 |  |                 "  hos.hosp_code = org.code" +
 | 
												
													
														
															|  | 
 |  |                 "  and" +
 | 
												
													
														
															|  | 
 |  |                 "  hos.hosp_code = dept.org_code" +
 | 
												
													
														
															|  | 
 |  |                 "  and" +
 | 
												
													
														
															|  | 
 |  |                 "  hos.dept_code = dept.code" +
 | 
												
													
														
															|  | 
 |  |                 "  and doctor_code = '{doctorCode}'";
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql.replace("{doctorCode}",doctorCode));
 | 
												
													
														
															|  | 
 |  |         List<OrgTree> orgTreeList = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         for(Map<String,Object> one : list){
 | 
												
													
														
															|  | 
 |  |             OrgTree orgTreeParent = new OrgTree();
 | 
												
													
														
															|  | 
 |  |             orgTreeParent.setParentCode("");
 | 
												
													
														
															|  | 
 |  |             orgTreeParent.setCode(String.valueOf(one.get("parentCode")));
 | 
												
													
														
															|  | 
 |  |             orgTreeParent.setName(String.valueOf(one.get("parentName")));
 | 
												
													
														
															|  | 
 |  |             orgTreeList.add(orgTreeParent);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             OrgTree orgTreeChild = new OrgTree();
 | 
												
													
														
															|  | 
 |  |             orgTreeChild.setParentCode(String.valueOf(one.get("parentCode")));
 | 
												
													
														
															|  | 
 |  |             orgTreeChild.setCode(String.valueOf(one.get("childCode")));
 | 
												
													
														
															|  | 
 |  |             orgTreeChild.setName(String.valueOf(one.get("childName")));
 | 
												
													
														
															|  | 
 |  |             orgTreeList.add(orgTreeChild);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return getOrgTree(orgTreeList);
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 构建树形结构
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public String getOrgTree(List<OrgTree> orgTreeList ){
 | 
												
													
														
															|  |         List<TreeNode> treeNodes = new ArrayList<>();
 |  |         List<TreeNode> treeNodes = new ArrayList<>();
 | 
												
													
														
															|  |         treeNodes.addAll(orgTreeService.findListByLevel(level.getLevelValue()));
 |  | 
 | 
												
													
														
															|  | 
 |  |         treeNodes.addAll(orgTreeList);
 | 
												
													
														
															|  |         SimpleTree tree = new SimpleTree(treeNodes);
 |  |         SimpleTree tree = new SimpleTree(treeNodes);
 | 
												
													
														
															|  |         List<SimpleTreeNode> treeNode = tree.getRoot();
 |  |         List<SimpleTreeNode> treeNode = tree.getRoot();
 | 
												
													
														
															|  |         SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
 |  |         SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
 | 
												
													
														
															|  |         filter.getExcludes().add("parent");
 |  |         filter.getExcludes().add("parent");
 | 
												
													
														
															|  |         filter.getExcludes().add("allChildren");
 |  |         filter.getExcludes().add("allChildren");
 | 
												
													
														
															|  | 
 |  |         filter.getExcludes().add("parentNodeId");
 | 
												
													
														
															|  | 
 |  |         filter.getExcludes().add("orderNum");
 | 
												
													
														
															|  | 
 |  |         filter.getExcludes().add("level");
 | 
												
													
														
															|  |         return JSONObject.toJSONString(treeNode, filter);
 |  |         return JSONObject.toJSONString(treeNode, filter);
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 获取某一科室下的医生列表
 | 
												
													
														
															|  | 
 |  |      * @param deptCode
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public JSONObject getDoctorListByDept(String deptCode) throws Exception {
 | 
												
													
														
															|  | 
 |  |         JSONObject result = new JSONObject();
 | 
												
													
														
															|  | 
 |  |         if(StringUtils.isEmpty(deptCode)){
 | 
												
													
														
															|  | 
 |  |             result.put("msg","parameter deptCode is null");
 | 
												
													
														
															|  | 
 |  |             result.put("response", ConstantUtils.FAIL);
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         String sql = "select " +
 | 
												
													
														
															|  | 
 |  |                 "  DISTINCT hos.doctor_code as doctorCode, " +
 | 
												
													
														
															|  | 
 |  |                 "  doc.name as name, " +
 | 
												
													
														
															|  | 
 |  |                 "  hos.dept_code as deptCode " +
 | 
												
													
														
															|  | 
 |  |                 " from " +
 | 
												
													
														
															|  | 
 |  |                 "  base_doctor_hospital hos, " +
 | 
												
													
														
															|  | 
 |  |                 "  base_doctor doc " +
 | 
												
													
														
															|  | 
 |  |                 " where " +
 | 
												
													
														
															|  | 
 |  |                 "  hos.doctor_code = doc.id" +
 | 
												
													
														
															|  | 
 |  |                 " and hos.dept_code = '" + deptCode + "'";
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
												
													
														
															|  | 
 |  |         result.put("response", ConstantUtils.SUCCESS);
 | 
												
													
														
															|  | 
 |  |         result.put("msg",JavaBeanUtils.getInstance().mapListJson(list));
 | 
												
													
														
															|  | 
 |  |         return result;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | }
 |  | }
 |