|
@ -1,5 +1,6 @@
|
|
|
package com.yihu.jw.base.service.doctor;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
|
|
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.JavaBeanUtils;
|
|
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
@ -24,10 +24,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@ -44,11 +42,14 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDao> {
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDoctorDao baseDoctorDao;
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDoctorHospitalService baseDoctorHospitalService;
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDoctorRoleDictService baseDoctorRoleDictService;
|
|
|
private BaseDoctorRoleService baseDoctorRoleService;
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
@ -94,41 +95,47 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
|
|
|
|
|
|
/**
|
|
|
* 获取医生信息(包括医生任职的医院相关信息)
|
|
|
* @param name
|
|
|
* @param idcard
|
|
|
* @param nameOrIdcard
|
|
|
* @param orgCode
|
|
|
* @param docStatus
|
|
|
* @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("'");
|
|
|
public String getDoctorFullInfo(String nameOrIdcard,String orgCode,String docStatus,int page,int size,String sort) throws Exception {
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
String pattern = "^\\d+";
|
|
|
if(StringUtils.isEmpty(nameOrIdcard) && StringUtils.isEmpty(orgCode) && StringUtils.isEmpty(docStatus)){
|
|
|
result = baseDoctorDao.queryDoctorFullInfo();
|
|
|
}else if(!StringUtils.isEmpty(nameOrIdcard)){
|
|
|
boolean isIdcard = Pattern.matches(pattern, nameOrIdcard);
|
|
|
if(isIdcard){
|
|
|
if(StringUtils.isEmpty(orgCode) && StringUtils.isEmpty(docStatus) ){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByIdcard("%" + nameOrIdcard + "%");
|
|
|
}else if(!StringUtils.isEmpty(orgCode)){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByIdcardAndOrg("%" + nameOrIdcard + "%",orgCode);
|
|
|
}else if(!StringUtils.isEmpty(docStatus)){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByIdcardAndDocDel("%" + nameOrIdcard + "%",docStatus);
|
|
|
}else{
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByIdcardAndOrgAndDocDel("%" + nameOrIdcard + "%",orgCode,docStatus);
|
|
|
}
|
|
|
}else{
|
|
|
sql.append(" and hos.hosp_code = '").append(orgCode).append("'");
|
|
|
sql.append(" and doc.del = '").append(docStatus).append("'");
|
|
|
if(StringUtils.isEmpty(orgCode) && StringUtils.isEmpty(docStatus) ){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByName("%" + nameOrIdcard + "%");
|
|
|
}else if(!StringUtils.isEmpty(orgCode)){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByNameAndOrg("%" + nameOrIdcard + "%",orgCode);
|
|
|
}else if(!StringUtils.isEmpty(docStatus)){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByNameAndDocDel("%" + nameOrIdcard + "%",docStatus);
|
|
|
}else{
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByNameAndOrgAndDocDel("%" + nameOrIdcard + "%",orgCode,docStatus);
|
|
|
}
|
|
|
}
|
|
|
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());
|
|
|
}
|
|
|
return result;
|
|
|
}else if(StringUtils.isEmpty(orgCode) && !StringUtils.isEmpty(docStatus) ){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByDocDel(docStatus);
|
|
|
}else if(!StringUtils.isEmpty(orgCode) && StringUtils.isEmpty(docStatus)){
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByOrg(orgCode);
|
|
|
}else {
|
|
|
result = baseDoctorDao.queryDoctorFullInfoByOrgAndDocDel(orgCode,docStatus);
|
|
|
}
|
|
|
return JavaBeanUtils.getInstance().mapListJson(result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -146,14 +153,15 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
|
|
|
}
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonData);
|
|
|
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("response", ConstantUtils.FAIL);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
//组装医生信息
|
|
|
BaseDoctorDO baseDoctorDO = null;
|
|
|
BaseDoctorHospitalDO baseDoctorHospitalDO = null;
|
|
|
try {
|
|
|
baseDoctorDO = objectMapper.readValue(doctor.toJSONString(),BaseDoctorDO.class);
|
|
|
} catch (IOException e) {
|
|
@ -161,34 +169,195 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
baseDoctorDO.setPassword(baseDoctorDO.getIdcard().substring(11,17));
|
|
|
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);
|
|
|
// 如果异常,将保存的医生信息删除
|
|
|
this.delete(baseDoctorDO);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
baseDoctorRoleService.batchInsert(baseDoctorRoleDOList);
|
|
|
|
|
|
// 组装医生任职机构及职业信息
|
|
|
BaseDoctorHospitalDO baseDoctorHospitalDO = null;
|
|
|
List<BaseDoctorHospitalDO> hospitalDOList = new ArrayList<>();
|
|
|
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) {
|
|
|
result.put("msg","convert hospital jsonObject to baseDoctorHospitalDO failed," + e.getCause());
|
|
|
result.put("response",ConstantUtils.FAIL);
|
|
|
// 如果异常,将保存的医生信息,角色关联关系删除
|
|
|
this.delete(baseDoctorDO);
|
|
|
baseDoctorRoleService.delete(baseDoctorRoleDOList);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
baseDoctorHospitalService.save(baseDoctorHospitalDO);
|
|
|
baseDoctorHospitalService.batchInsert(hospitalDOList);
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("msg",baseDoctorDO);
|
|
|
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 level 参考OrgTree的Level枚举类型
|
|
|
* 生效或失效单个医生
|
|
|
* @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);
|
|
|
}
|
|
|
/**
|
|
|
* 构建树形结构
|
|
|
* @return
|
|
|
*/
|
|
|
public String getOrgTree(OrgTree.Level level){
|
|
|
public String getOrgTree(List<OrgTree> orgTreeList ){
|
|
|
List<TreeNode> treeNodes = new ArrayList<>();
|
|
|
treeNodes.addAll(orgTreeService.findListByLevel(level.getLevelValue()));
|
|
|
treeNodes.addAll(orgTreeList);
|
|
|
SimpleTree tree = new SimpleTree(treeNodes);
|
|
|
List<SimpleTreeNode> treeNode = tree.getRoot();
|
|
|
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
|
|
|
filter.getExcludes().add("parent");
|
|
|
filter.getExcludes().add("allChildren");
|
|
|
filter.getExcludes().add("parentNodeId");
|
|
|
filter.getExcludes().add("orderNum");
|
|
|
filter.getExcludes().add("level");
|
|
|
return JSONObject.toJSONString(treeNode, filter);
|
|
|
}
|
|
|
}
|