|
@ -0,0 +1,2113 @@
|
|
|
package com.yihu.wlyy.service.app.sign;
|
|
|
|
|
|
import com.yihu.wlyy.entity.consult.Consult;
|
|
|
import com.yihu.wlyy.entity.consult.ConsultTeam;
|
|
|
import com.yihu.wlyy.entity.doctor.OperatorLog;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.doctor.profile.DoctorService;
|
|
|
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
|
|
|
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
|
|
|
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
|
|
|
import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
|
|
|
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel;
|
|
|
import com.yihu.wlyy.entity.message.Message;
|
|
|
import com.yihu.wlyy.entity.organization.Hospital;
|
|
|
import com.yihu.wlyy.entity.patient.*;
|
|
|
import com.yihu.wlyy.logs.BusinessLogs;
|
|
|
import com.yihu.wlyy.repository.consult.ConsultDao;
|
|
|
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
|
|
|
import com.yihu.wlyy.repository.dict.SystemDictDao;
|
|
|
import com.yihu.wlyy.repository.doctor.*;
|
|
|
import com.yihu.wlyy.repository.message.MessageDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalDao;
|
|
|
import com.yihu.wlyy.repository.patient.*;
|
|
|
import com.yihu.wlyy.repository.statistics.WlyySignFamilyCodeDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.app.message.MessageService;
|
|
|
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
|
|
|
import com.yihu.wlyy.service.third.fzzb.HealthEducationArticleService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.task.SignUploadTask;
|
|
|
import com.yihu.wlyy.util.*;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springside.modules.persistence.DynamicSpecifications;
|
|
|
import org.springside.modules.persistence.SearchFilter;
|
|
|
import org.springside.modules.persistence.SearchFilter.Operator;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 家庭签约业务处理类
|
|
|
*
|
|
|
* @author George
|
|
|
*/
|
|
|
@Component
|
|
|
@Transactional
|
|
|
public class FamilyContractService extends BaseService {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(FamilyContractService.class);
|
|
|
@Autowired
|
|
|
private DoctorPatientDao doctorPatientDao;
|
|
|
@Autowired
|
|
|
private SignFamilyDao signFamilyDao;
|
|
|
@Autowired
|
|
|
private DoctorServiceDao doctorServiceDao;
|
|
|
@Autowired
|
|
|
private HospitalDao hospitalDao;
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private MessageDao messageDao;
|
|
|
@Autowired
|
|
|
private DoctorTeamDao doctorTeamDao;
|
|
|
@Autowired
|
|
|
private DoctorTeamMemberDao doctorTeamDoctor;
|
|
|
@Autowired
|
|
|
private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
|
|
|
@Autowired
|
|
|
private ConsultTeamDao consultTeamDao;
|
|
|
@Autowired
|
|
|
private WlyySignFamilyCodeDao wlyySignFamilyCodeDao;
|
|
|
@Autowired
|
|
|
private SystemDictDao systemDictDao;
|
|
|
@Autowired
|
|
|
private PatientDiseaseDao patientDiseaseDao;
|
|
|
@Autowired
|
|
|
private SocialSecurityInfoDao socialSecurityInfoDao;
|
|
|
@Autowired
|
|
|
private DoctorAdminTeamDao doctorAdminTeamDao;
|
|
|
@Autowired
|
|
|
MessageService messageService;
|
|
|
|
|
|
@Autowired
|
|
|
SignPatientLabelDao labelDao;
|
|
|
@Autowired
|
|
|
SignPatientLabelLogDao labelLogDao;
|
|
|
@Autowired
|
|
|
SignPatientLabelInfoDao labelInfoDao;
|
|
|
@Autowired
|
|
|
JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
WeiXinAccessTokenUtils accessTokenUtils;
|
|
|
@Autowired
|
|
|
private DoctorWorkTimeService doctorWorkTimeService;
|
|
|
@Autowired
|
|
|
private OperatorLogDao operatorLogDao;
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils weiXinOpenIdUtils;
|
|
|
@Autowired
|
|
|
private ConsultDao consultDao;
|
|
|
@Autowired
|
|
|
private SignFamilyRenewDao signFamilyRenewDao;
|
|
|
@Autowired
|
|
|
private SignFamilyMappingDao signFamilyMappingDao;
|
|
|
@Autowired
|
|
|
private FamilyContractService familyContractService;
|
|
|
@Autowired
|
|
|
private HealthEducationArticleService healthEducationArticleService;
|
|
|
|
|
|
@Autowired
|
|
|
private ImUtill ImUtill;
|
|
|
@Autowired
|
|
|
private HttpUtil httpUtil;
|
|
|
@Value("${sign.check_upload}")
|
|
|
private String jwUrl;
|
|
|
|
|
|
@Value("${im.data_base_name}")
|
|
|
private String im_dataBase_name;
|
|
|
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
|
|
|
|
|
|
public SignFamily findSignFamilyByCode(String code) {
|
|
|
return signFamilyDao.findByCodeAndType(code, 2);
|
|
|
}
|
|
|
|
|
|
public SignFamily findByPatientByType(String patient, int type) {
|
|
|
return signFamilyDao.findByPatientAndType(patient, type);
|
|
|
}
|
|
|
|
|
|
public SignFamily findByPatient(String patient) {
|
|
|
return signFamilyDao.findByjiatingPatient(patient);
|
|
|
}
|
|
|
|
|
|
public SignFamily findSignByPatient(String patient) {
|
|
|
return signFamilyDao.findSignByPatient(patient);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取患者待签约数据
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public SignFamily findSigningByPatient(String patient) {
|
|
|
return signFamilyDao.findSigningByPatient(patient);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取患者待签约数据
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public SignFamily findSigningRenewByPatient(String patient) {
|
|
|
return signFamilyDao.findSigningByPatient(patient);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询医院列表
|
|
|
*
|
|
|
* @param type 医院类型:0全部,1大医院,2社区医院
|
|
|
* @param province 省代码
|
|
|
* @param city 城市代码
|
|
|
* @param key 搜索关键字
|
|
|
* @param id
|
|
|
* @param pagesize 分页大小
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<Hospital> findHospitals(int type, String province, String city, String town, String key, long id, int pagesize) {
|
|
|
if (pagesize <= 0) {
|
|
|
pagesize = 10;
|
|
|
}
|
|
|
// 排序
|
|
|
Sort sort = new Sort(Direction.ASC, "id");
|
|
|
// 分页信息
|
|
|
PageRequest pageRequest = new PageRequest(0, pagesize, sort);
|
|
|
// 设置查询条件
|
|
|
Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
|
|
|
if (type == 1) {
|
|
|
// 查询大医院
|
|
|
filters.put("level", new SearchFilter("level", Operator.EQ, 1));
|
|
|
} else if (type == 2) {
|
|
|
// 查询社区医院
|
|
|
filters.put("level", new SearchFilter("level", Operator.EQ, 2));
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(province)) {
|
|
|
filters.put("province", new SearchFilter("province", Operator.EQ, province));
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(city)) {
|
|
|
filters.put("city", new SearchFilter("city", Operator.EQ, city));
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(town)) {
|
|
|
filters.put("town", new SearchFilter("town", Operator.EQ, town));
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(key)) {
|
|
|
filters.put("name", new SearchFilter("name", Operator.LIKE, key));
|
|
|
}
|
|
|
if (id > 0) {
|
|
|
filters.put("id", new SearchFilter("id", Operator.GT, id));
|
|
|
}
|
|
|
// 未作废
|
|
|
filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
|
|
|
Specification<Hospital> spec = DynamicSpecifications.bySearchFilter(filters.values(), Hospital.class);
|
|
|
return hospitalDao.findAll(spec, pageRequest);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询医院下的医生
|
|
|
*
|
|
|
* @param hospital
|
|
|
* @param level 医生类型:1专科医生,2全科医生,3健康管理师
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<Doctor> findDoctors(String hospital, String city, String town, String name, Integer level, Long id, Integer pagesize) {
|
|
|
if (pagesize == null || pagesize <= 0) {
|
|
|
pagesize = 10;
|
|
|
}
|
|
|
// 排序
|
|
|
Sort sort = new Sort(Direction.ASC, "id");
|
|
|
// 分页信息
|
|
|
PageRequest pageRequest = new PageRequest(0, pagesize, sort);
|
|
|
// 设置查询条件
|
|
|
Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
|
|
|
if (StringUtils.isNoneEmpty(hospital)) {
|
|
|
filters.put("hospital", new SearchFilter("hospital", Operator.EQ, hospital));
|
|
|
}
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(city)) {
|
|
|
filters.put("city", new SearchFilter("city", Operator.EQ, city));
|
|
|
}
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(town)) {
|
|
|
filters.put("town", new SearchFilter("town", Operator.EQ, town));
|
|
|
}
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(name)) {
|
|
|
filters.put("name", new SearchFilter("name", Operator.LIKE, "%" + name + "%"));
|
|
|
}
|
|
|
if (id != null && id > 0) {
|
|
|
filters.put("id", new SearchFilter("id", Operator.GT, id));
|
|
|
}
|
|
|
// 医生类型过滤
|
|
|
if (level != null && level > 0) {
|
|
|
filters.put("level", new SearchFilter("level", Operator.EQ, level));
|
|
|
}
|
|
|
// 未作废
|
|
|
filters.put("status", new SearchFilter("status", Operator.EQ, 1));
|
|
|
Specification<Doctor> spec = DynamicSpecifications.bySearchFilter(filters.values(), Doctor.class);
|
|
|
return doctorDao.findAll(spec, pageRequest);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据医生和患者获取患者的签约状态
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public List<SignFamily> getSign(String patient, String doctor) {
|
|
|
List<SignFamily> sfList = signFamilyDao.findSSandFamilyByDoctorPatient(patient, doctor);
|
|
|
return sfList;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询集美医生主页信息
|
|
|
*
|
|
|
* @param doctor 医生标识
|
|
|
* @param patient 患者标识
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject findJiMeiDoctorMainPage(String patient, String doctor,Integer page,Integer pagesize) {
|
|
|
JSONObject json = new JSONObject();
|
|
|
// 查询医生基本信息
|
|
|
Doctor d = doctorDao.findByCode(doctor);
|
|
|
json.put("doctor", d.getCode());
|
|
|
json.put("evaluateScore", d.getEvaluateScore());
|
|
|
json.put("name", d.getName());
|
|
|
json.put("photo", d.getPhoto());
|
|
|
json.put("sex", d.getSex());
|
|
|
json.put("job", d.getJob());
|
|
|
json.put("jobName", d.getJobName());
|
|
|
json.put("hospital", d.getHospitalName());
|
|
|
json.put("dept", d.getDeptName());
|
|
|
json.put("intro", d.getIntroduce());
|
|
|
json.put("expertise", d.getExpertise());
|
|
|
json.put("level", d.getLevel());
|
|
|
|
|
|
SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
|
|
|
if (sf == null) {
|
|
|
// 没有签约信息
|
|
|
json.put("sign", -1);
|
|
|
json.put("isjimei", 0);
|
|
|
} else {
|
|
|
// 有签约信息
|
|
|
json.put("sign", sf.getStatus());
|
|
|
if(sf.getHospital().startsWith("350211")){
|
|
|
json.put("isjimei", 1);
|
|
|
}else {
|
|
|
json.put("isjimei", 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取健康文章
|
|
|
com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
|
|
|
try {
|
|
|
jsonArray = healthEducationArticleService.getDoctorArticalByUserId(null,1,null,page,pagesize,doctor);
|
|
|
}catch (Exception e){
|
|
|
logger.error("获取福州健康文章失败,"+e.getMessage());
|
|
|
}
|
|
|
json.put("healthEduArticles",jsonArray);
|
|
|
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询患者与医生的签约信息
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public int findSignStatus(String patient, String doctor) {
|
|
|
// 查询与当前医生的签约状态
|
|
|
SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
|
|
|
if (sf == null) {
|
|
|
// 没有签约信息
|
|
|
return -1;
|
|
|
} else {
|
|
|
// 有签约信息
|
|
|
return sf.getStatus();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验签约状态
|
|
|
*
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONObject checkSign(Patient patient) throws Exception {
|
|
|
JSONObject json = new JSONObject();
|
|
|
// 查询是否已存在家庭签约
|
|
|
SignFamily sf = signFamilyDao.findByIdcard(patient.getIdcard());
|
|
|
if (sf != null) {
|
|
|
// 已签约
|
|
|
json.put("sign", 1);
|
|
|
} else {
|
|
|
// 未签约
|
|
|
json.put("sign", 0);
|
|
|
}
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验当前openid是否签约家庭医生
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String checkPatient(String patient) {
|
|
|
SignFamily sf = signFamilyDao.findByjiatingPatientStatus0(patient);
|
|
|
if (sf != null) {
|
|
|
return sf.getDoctor();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询是否存在签约状态
|
|
|
*
|
|
|
* @param idcard
|
|
|
* @return
|
|
|
*/
|
|
|
public int hasSingStatus(String idcard) {
|
|
|
return signFamilyDao.hasSingStatus(idcard);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 取消签约申请
|
|
|
*
|
|
|
* @param patient 患者标识
|
|
|
* @param doctor 医生标识
|
|
|
* @return
|
|
|
*/
|
|
|
public int unsign(String patient, String doctor) throws Exception {
|
|
|
Doctor doc = doctorDao.findByCode(doctor);
|
|
|
|
|
|
if (doc == null) {
|
|
|
throw new Exception("doctor info can not find");
|
|
|
}
|
|
|
//修改签约标识为无效
|
|
|
SignFamily sf = null;
|
|
|
|
|
|
if (doc.getLevel() == 2) {
|
|
|
sf = signFamilyDao.findByDoctorPatient(doctor, patient);
|
|
|
} else if (doc.getLevel() == 3) {
|
|
|
sf = signFamilyDao.findByDoctorHealthPatient(doctor, patient);
|
|
|
}
|
|
|
if (sf.getStatus() != 0 && sf.getStatus() != 2) {
|
|
|
return -2;
|
|
|
}
|
|
|
if (sf != null) {
|
|
|
sf.setStatus(-1);
|
|
|
} else {
|
|
|
return -2;
|
|
|
}
|
|
|
//结束与医生所有消息
|
|
|
List<Message> messages = messageDao.findByPatient(patient, doctor);
|
|
|
if (messages != null && messages.size() > 0) {
|
|
|
for (Message message : messages) {
|
|
|
//修改信息为无效
|
|
|
if (message != null) {
|
|
|
message.setRead(0);
|
|
|
message.setOver("0");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return 200;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消续签
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public int unsignRenew(String patient, String doctor) throws Exception {
|
|
|
|
|
|
if (DateUtil.getNowMonth() < 7) {
|
|
|
SignFamilyRenew sf = signFamilyRenewDao.findByDoctorPatient(doctor, patient);
|
|
|
if (sf != null && sf.getStatus() != 0 && sf.getStatus() != 2) {
|
|
|
return -2;
|
|
|
}
|
|
|
sf.setStatus(-1);
|
|
|
} else {
|
|
|
SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
|
|
|
if (sf != null && sf.getStatus() != 0 && sf.getStatus() != 2) {
|
|
|
return -2;
|
|
|
}
|
|
|
sf.setStatus(-1);
|
|
|
}
|
|
|
|
|
|
//结束与医生所有消息
|
|
|
List<Message> messages = messageDao.findByPatientRenew(patient, doctor);
|
|
|
|
|
|
if (messages != null & messages.size() > 0) {
|
|
|
for (Message message : messages) {
|
|
|
//修改信息为无效
|
|
|
if (message != null) {
|
|
|
message.setRead(0);
|
|
|
message.setOver("0");
|
|
|
messageDao.save(message);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return 200;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 申请解约
|
|
|
*
|
|
|
* @param patient 患者标识
|
|
|
* @param doctor 医生标识
|
|
|
* @param openid 微信openid
|
|
|
* @param reason 解约理由
|
|
|
* @return
|
|
|
*/
|
|
|
public int surrender(String patient, String patientName, String userPhoto, String doctor, String doctorName, String openid, String reason, int sex) throws Exception {
|
|
|
// 更新为待解约
|
|
|
int res = signFamilyDao.surrender(patient, doctor);
|
|
|
SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
|
|
|
signFamily.setPatientApplyUnsignDate(new Date());
|
|
|
if (res == 0) {
|
|
|
return 0;
|
|
|
}
|
|
|
// 添加签约消息
|
|
|
Message message = new Message();
|
|
|
// 消息时间
|
|
|
message.setCzrq(new Date());
|
|
|
message.setCreateTime(new Date());
|
|
|
// 消息内容
|
|
|
message.setContent("申请解除与您的签约关系");
|
|
|
// 未读
|
|
|
message.setRead(1);
|
|
|
message.setReceiverName(doctorName);
|
|
|
// 接收人
|
|
|
message.setReceiver(doctor);
|
|
|
message.setCode(getCode());
|
|
|
// 发送人
|
|
|
message.setSender(patient);
|
|
|
message.setSenderName(patientName);
|
|
|
message.setSenderPhoto(userPhoto);
|
|
|
// 标题
|
|
|
message.setTitle("解除家庭签约申请");
|
|
|
message.setType(1);
|
|
|
message.setSignStatus("4");
|
|
|
message.setReadonly(1);
|
|
|
message.setSex(sex);
|
|
|
message.setOver("1");
|
|
|
// 设置解约理由
|
|
|
message.setReason(reason);
|
|
|
message.setData(signFamily.getCode());
|
|
|
messageDao.save(message);
|
|
|
// 发送消息给医生
|
|
|
JSONObject jsonObject = doctorWorkTimeService.isDoctorWorking(doctor);
|
|
|
if (jsonObject.getString("status").equals("1")) {
|
|
|
//如果在工作时间内就推送
|
|
|
pushMsgTask.put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_SIGN_WEB_RELIEVE.D_SW_02.name(), MessageType.MESSAGE_TYPE_DOCTOR_SIGN_WEB_RELIEVE.家庭签约.name(), patientName + " 申请解除与您的家庭签约!", patient);
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询患者的签约消息
|
|
|
*
|
|
|
* @param id
|
|
|
* @param pagesize
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<Message> findMessageByPatient(String patient, long id, int pagesize) {
|
|
|
if (pagesize <= 0) {
|
|
|
pagesize = 10;
|
|
|
}
|
|
|
// 排序
|
|
|
Sort sort = new Sort(Direction.DESC, "id");
|
|
|
// 分页信息
|
|
|
PageRequest pageRequest = new PageRequest(0, pagesize, sort);
|
|
|
// 设置查询条件
|
|
|
Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
|
|
|
filters.put("receiver", new SearchFilter("receiver", Operator.EQ, patient));
|
|
|
if (id > 0) {
|
|
|
filters.put("id", new SearchFilter("id", Operator.LT, id));
|
|
|
}
|
|
|
Specification<Message> spec = DynamicSpecifications.bySearchFilter(filters.values(), Message.class);
|
|
|
return messageDao.findAll(spec, pageRequest);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询跟医生相关的家庭签约信息
|
|
|
*
|
|
|
* @param type 0全部,1待签约,2已签约,3待解约,4已解约
|
|
|
* @param id
|
|
|
* @param pagesize 分页大小
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<SignFamily> findSignByDoctor(int type, long id, int pagesize) {
|
|
|
if (pagesize <= 0) {
|
|
|
pagesize = 10;
|
|
|
}
|
|
|
// 排序
|
|
|
Sort sort = new Sort(Direction.DESC, "id");
|
|
|
// 分页信息
|
|
|
PageRequest pageRequest = new PageRequest(0, pagesize, sort);
|
|
|
// 设置查询条件
|
|
|
Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
|
|
|
// 只查家庭签约(网络签约)
|
|
|
filters.put("type", new SearchFilter("type", Operator.EQ, 2));
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
// 待签约
|
|
|
filters.put("status", new SearchFilter("status", Operator.EQ, 0));
|
|
|
break;
|
|
|
case 2:
|
|
|
// 已签约
|
|
|
filters.put("status", new SearchFilter("status", Operator.EQ, 1));
|
|
|
break;
|
|
|
case 3:
|
|
|
// 待解约
|
|
|
filters.put("status", new SearchFilter("status", Operator.EQ, 2));
|
|
|
break;
|
|
|
case 4:
|
|
|
// 已解约
|
|
|
filters.put("status", new SearchFilter("status", Operator.EQ, -3));
|
|
|
break;
|
|
|
}
|
|
|
if (id > 0) {
|
|
|
filters.put("id", new SearchFilter("id", Operator.LT, id));
|
|
|
}
|
|
|
Specification<SignFamily> spec = DynamicSpecifications.bySearchFilter(filters.values(), SignFamily.class);
|
|
|
return signFamilyDao.findAll(spec, pageRequest);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询医生的签约消息
|
|
|
*
|
|
|
* @param doctor 医生标识
|
|
|
* @param id
|
|
|
* @param pagesize 分页大小
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<Message> findMessageByDoctor(String doctor, long id, int pagesize) {
|
|
|
if (pagesize <= 0) {
|
|
|
pagesize = 10;
|
|
|
}
|
|
|
// 排序
|
|
|
Sort sort = new Sort(Direction.DESC, "id");
|
|
|
// sort.and(new Sort(Direction.DESC,"read"));
|
|
|
// sort.and(new Sort(Direction.DESC,"czrq"));
|
|
|
|
|
|
// 分页信息
|
|
|
PageRequest pageRequest = new PageRequest(0, pagesize, sort);
|
|
|
// 设置查询条件
|
|
|
Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
|
|
|
filters.put("receiver", new SearchFilter("receiver", Operator.EQ, doctor));
|
|
|
if (id > 0) {
|
|
|
filters.put("id", new SearchFilter("id", Operator.LT, id));
|
|
|
}
|
|
|
// 只查询未处理的消息
|
|
|
filters.put("type", new SearchFilter("type", Operator.EQ, 1));
|
|
|
filters.put("over", new SearchFilter("over", Operator.EQ, 1));
|
|
|
filters.put("read", new SearchFilter("read", Operator.EQ, 1));
|
|
|
Specification<Message> spec = DynamicSpecifications.bySearchFilter(filters.values(), Message.class);
|
|
|
return messageDao.findAll(spec, pageRequest);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询已签约总数
|
|
|
*
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public int countAmountSigned(String doctor) {
|
|
|
AdminTeam adminTeam = doctorAdminTeamDao.findByLeaderCode(doctor);
|
|
|
if (adminTeam != null) {
|
|
|
//团队长只显示实际有签约关系的数量
|
|
|
return signFamilyDao.countAmountSignedByAdminTeam(adminTeam.getId());
|
|
|
} else {
|
|
|
//不是团队长显示所有有服务关系的数量
|
|
|
return signFamilyDao.countAmountSignedByDoctor(doctor);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询待签约总数
|
|
|
*
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public int countAmountUnsign(String doctor) {
|
|
|
return signFamilyDao.countAmountUnsignByDoctor(doctor);
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<?> amountPatients(String uid) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public SignFamily getFamilyContractByIdcard(String idCard) {
|
|
|
return signFamilyDao.findByIdcard(idCard);
|
|
|
|
|
|
}
|
|
|
|
|
|
public SignFamily getFamilyContractByMobile(String mobile) {
|
|
|
return signFamilyDao.findByMobile(mobile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成签约标识
|
|
|
*
|
|
|
* @param doctor 医生标识
|
|
|
* @return
|
|
|
*/
|
|
|
private String createSignCode(String doctor, String hospital) {
|
|
|
// 获取当前年份
|
|
|
String year = DateUtil.getStringDate(DateUtil.YY);
|
|
|
Hospital hospital1 = hospitalDao.findByCode(hospital);
|
|
|
Integer amount = 0;
|
|
|
SignFamilyCode wlyySignFamilyCode = wlyySignFamilyCodeDao.findByOrgCodeAndYear(hospital, year);
|
|
|
if (wlyySignFamilyCode != null) {
|
|
|
amount = wlyySignFamilyCode.getSequence() + 1;
|
|
|
wlyySignFamilyCode.setSequence(amount);
|
|
|
wlyySignFamilyCode.setModifyTime(new Date());
|
|
|
} else {
|
|
|
//创建序列
|
|
|
amount = 1;
|
|
|
SignFamilyCode wlyySignFamilyCodeTemp = new SignFamilyCode();
|
|
|
wlyySignFamilyCodeTemp.setModifyTime(new Date());
|
|
|
wlyySignFamilyCodeTemp.setOrgCode(hospital1.getCode());
|
|
|
wlyySignFamilyCodeTemp.setOrgName(hospital1.getName());
|
|
|
wlyySignFamilyCodeTemp.setYear(year);
|
|
|
wlyySignFamilyCodeTemp.setSequence(1);
|
|
|
wlyySignFamilyCodeDao.save(wlyySignFamilyCodeTemp);
|
|
|
}
|
|
|
|
|
|
return year + hospital1.getRoadCode() + hospital1.getCenterSite() + "Y" + StringUtils.leftPad(String.valueOf(amount + 1), 5, "0");
|
|
|
}
|
|
|
|
|
|
public SignFamily findBySanshiPatient(String code) {
|
|
|
|
|
|
return signFamilyDao.findSanshiSignByPatient(code);
|
|
|
}
|
|
|
|
|
|
public SignFamily findByFamilySignPatient(String code) {
|
|
|
|
|
|
return signFamilyDao.findFamilySignByPatient(code);
|
|
|
}
|
|
|
|
|
|
public SignFamily findByJiatingPatient(String code) {
|
|
|
|
|
|
return signFamilyDao.findByjiatingPatientYes(code);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询患者已签约信息
|
|
|
*
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public SignFamily findBySsPatient(String code) {
|
|
|
return signFamilyDao.findBySsPatient(code);
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getDoctorsByhospitalNoPage(String hospital, String name, Integer type) {
|
|
|
String sql = "select * from wlyy_doctor where 1=1 and del=1 and iscertified=1 and status=1 ";
|
|
|
List<Object> params = new ArrayList<Object>();
|
|
|
if (StringUtils.isNoneEmpty(hospital)) {
|
|
|
sql += " and hospital =? ";
|
|
|
params.add(hospital);
|
|
|
}
|
|
|
if (StringUtils.isNoneEmpty(name)) {
|
|
|
sql += " and name like ? ";
|
|
|
params.add("%" + name + "%");
|
|
|
}
|
|
|
if (type != null && type > 0) {
|
|
|
sql += " and level =? ";
|
|
|
params.add(type);
|
|
|
}
|
|
|
return jdbcTemplate.queryForList(sql, params.toArray());
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> getSanshiSignByPatientCode(String patientCode) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
SignFamily signFamily = signFamilyDao.findBySanshiPatient(patientCode);
|
|
|
//判斷之前有没有三师签约
|
|
|
if (signFamily != null) {
|
|
|
map.put("hasSanshi", "true");
|
|
|
//得到团队的专科医生
|
|
|
DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 1);
|
|
|
map.put("zkCode", doctorTeamMember.getMemberCode());
|
|
|
map.put("zkName", doctorTeamMember.getName());
|
|
|
//得到团队的全科医生
|
|
|
doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 2);
|
|
|
map.put("qkCode", doctorTeamMember.getMemberCode());
|
|
|
map.put("qkName", doctorTeamMember.getName());
|
|
|
//得到团队的健康管理医生
|
|
|
doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 3);
|
|
|
map.put("glsCode", doctorTeamMember.getMemberCode());
|
|
|
map.put("glsName", doctorTeamMember.getName());
|
|
|
//得到之前病人得的病
|
|
|
Patient pa = patientDao.findByCode(patientCode);
|
|
|
map.put("disease", pa.getDisease());
|
|
|
} else {
|
|
|
map.put("hasSanshi", "false");
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
public SignFamily findByPatientYes(String id) {
|
|
|
return signFamilyDao.findByjiatingPatient(id);
|
|
|
}
|
|
|
|
|
|
public SignFamily findBySanshiPatientYes(String id) {
|
|
|
return signFamilyDao.findBySanshiPatientYes(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据身份证号查找病人的三师签约信息
|
|
|
*
|
|
|
* @param idCard
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getSanshiSingInfoByPatientIdCard(String idCard) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
SignFamily sign = signFamilyDao.findByPatientSanshiSignInfo(idCard);
|
|
|
SignFamily signFamily = signFamilyDao.findByPatientFamilySignInfo(idCard);
|
|
|
|
|
|
Patient p = patientDao.findByIdcard(idCard);
|
|
|
|
|
|
//if (p == null) {
|
|
|
// result.put("signStatus", "0");
|
|
|
// result.put("msg", "病人未注册");
|
|
|
// return result;
|
|
|
//}
|
|
|
if (signFamily != null) {
|
|
|
result.put("signStatus", "2");
|
|
|
result.put("msg", "病人已申请过家庭签约!");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if (sign != null) {
|
|
|
List<DoctorTeamMember> members = doctorTeamDoctor.findByTeamAndDel(sign.getTeamCode(), "1");
|
|
|
|
|
|
if (members == null) {
|
|
|
throw new Exception("签约团队信息有误!");
|
|
|
}
|
|
|
|
|
|
//三师签约医生信息
|
|
|
for (DoctorTeamMember member : members) {
|
|
|
if (member.getType() == 1) {
|
|
|
result.put("majorDoctor", member.getMemberCode());
|
|
|
result.put("majorDoctorName", member.getName());
|
|
|
} else if (member.getType() == 2) {
|
|
|
Doctor doctor = doctorDao.findByCode(member.getMemberCode());
|
|
|
result.put("hospital", doctor.getHospital());
|
|
|
result.put("doctor", member.getMemberCode());
|
|
|
result.put("doctorName", member.getName());
|
|
|
} else if (member.getType() == 3) {
|
|
|
result.put("healthDoctor", member.getMemberCode());
|
|
|
result.put("healthDoctorName", member.getName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 查询患者疾病
|
|
|
List<PatientDisease> diseases = patientDiseaseDao.findByPatientSsDisease(p.getCode());
|
|
|
|
|
|
if (diseases != null && diseases.size() > 0) {
|
|
|
JSONArray disArray = new JSONArray();
|
|
|
|
|
|
for (PatientDisease dis : diseases) {
|
|
|
disArray.put(new JSONObject(dis));
|
|
|
}
|
|
|
|
|
|
result.put("diseases", disArray);
|
|
|
} else {
|
|
|
result.put("diseases", "");
|
|
|
}
|
|
|
|
|
|
result.put("signStatus", "1");
|
|
|
|
|
|
} else {
|
|
|
result.put("signStatus", "3");
|
|
|
}
|
|
|
|
|
|
if (p != null) {
|
|
|
JSONObject pJson = new JSONObject(p);
|
|
|
if (pJson.has("password")) {
|
|
|
pJson.remove("password");
|
|
|
}
|
|
|
if (pJson.has("salt")) {
|
|
|
pJson.remove("salt");
|
|
|
}
|
|
|
result.put("patient", pJson);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取签约医生
|
|
|
* @param patientCode
|
|
|
* @return
|
|
|
*/
|
|
|
public com.alibaba.fastjson.JSONArray getSignDoctors(String patientCode){
|
|
|
com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
|
|
|
SignFamily jtSignFamily = signFamilyDao.findFamilySignByPatient(patientCode);
|
|
|
if (jtSignFamily != null) {
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
Doctor doctor = doctorDao.findByCode(jtSignFamily.getDoctor());
|
|
|
if (doctor != null) {
|
|
|
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
|
|
|
jo.put("code", doctor.getCode());
|
|
|
jo.put("sex", doctor.getSex());
|
|
|
jo.put("name", doctor.getName());
|
|
|
jo.put("photo", doctor.getPhoto());
|
|
|
jo.put("hosptialName", doctor.getHospitalName());
|
|
|
jo.put("level", doctor.getLevel());
|
|
|
jo.put("signType", "2");//2是家庭
|
|
|
jo.put("signStatus", jtSignFamily.getStatus());
|
|
|
jo.put("jobName", doctor.getJobName());
|
|
|
jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
if (jtSignFamily.getStatus() == 0) {
|
|
|
jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
|
|
|
} else {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getBegin()));//签约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
|
|
|
}
|
|
|
jsonArray.add(jo);
|
|
|
}
|
|
|
}
|
|
|
return jsonArray;
|
|
|
}
|
|
|
public JSONArray getSignDoctorMessage(String patientCode) {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
//找出患者的三师签约信息
|
|
|
SignFamily signFamily = signFamilyDao.findSanshiSignByPatient(patientCode);
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
if (signFamily != null) {
|
|
|
//得到三师签约的服务团队
|
|
|
List<Doctor> doctors = doctorDao.findSanshiDoctorByTeam(signFamily.getTeamCode());
|
|
|
for (Doctor doctor : doctors) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("code", doctor.getCode());//医生code
|
|
|
jo.put("sex", doctor.getSex());//医生性别 1男,2女)
|
|
|
jo.put("name", doctor.getName());//医生名称
|
|
|
jo.put("photo", doctor.getPhoto());//医生头像
|
|
|
jo.put("hosptialName", doctor.getHospitalName());//所属机构名称
|
|
|
jo.put("level", doctor.getLevel());//医生等级1专科医生,2全科医生,3健康管理师
|
|
|
jo.put("signType", "1");//签约类别 1是三师 2是家庭
|
|
|
jo.put("signStatus", signFamily.getStatus());//签约状态 0待签约,1已签约 2待解约
|
|
|
jo.put("jobName", doctor.getJobName());//职称
|
|
|
jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
if (signFamily.getStatus() == 0) {
|
|
|
jo.put("sqDate", DateUtil.dateToStrShort(signFamily.getPatientApplyDate()));//申请时间
|
|
|
} else if (signFamily.getStatus() == 1) {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(signFamily.getBegin()));//签约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(signFamily.getEnd()));//结束时间
|
|
|
} else if (signFamily.getStatus() == 2) {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(signFamily.getPatientApplyUnsignDate()));//申请解约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(signFamily.getEnd()));//结束时间
|
|
|
}
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
}
|
|
|
//得到家庭签约
|
|
|
SignFamily jtSignFamily = signFamilyDao.findFamilySignByPatient(patientCode);
|
|
|
|
|
|
if (jtSignFamily != null) {
|
|
|
//家庭签约只找全科医生
|
|
|
Doctor doctor = doctorDao.findByCode(jtSignFamily.getDoctor());
|
|
|
Doctor doctorHealth = doctorDao.findByCode(jtSignFamily.getDoctorHealth());
|
|
|
if (doctor != null) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("code", doctor.getCode());
|
|
|
jo.put("sex", doctor.getSex());
|
|
|
jo.put("name", doctor.getName());
|
|
|
jo.put("photo", doctor.getPhoto());
|
|
|
jo.put("hosptialName", doctor.getHospitalName());
|
|
|
jo.put("level", doctor.getLevel());
|
|
|
jo.put("signType", "2");//2是家庭
|
|
|
jo.put("signStatus", jtSignFamily.getStatus());
|
|
|
jo.put("jobName", doctor.getJobName());
|
|
|
jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
if (jtSignFamily.getStatus() == 0) {
|
|
|
jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
|
|
|
} else {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getBegin()));//签约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
|
|
|
}
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
if (doctorHealth != null) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("code", doctorHealth.getCode());
|
|
|
jo.put("sex", doctorHealth.getSex());
|
|
|
jo.put("name", doctorHealth.getName());
|
|
|
jo.put("photo", doctorHealth.getPhoto());
|
|
|
jo.put("hosptialName", doctorHealth.getHospitalName());
|
|
|
jo.put("level", doctorHealth.getLevel());
|
|
|
jo.put("signType", "2");//2是家庭
|
|
|
jo.put("signStatus", jtSignFamily.getStatus());
|
|
|
jo.put("jobName", doctorHealth.getJobName());
|
|
|
jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
if (jtSignFamily.getStatus() == 0) {
|
|
|
jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
|
|
|
} else {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getBegin()));//签约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
|
|
|
}
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
}
|
|
|
return jsonArray;
|
|
|
}
|
|
|
|
|
|
public SignFamily getPatientSign(String patient) {
|
|
|
return signFamilyDao.findByPatient(patient);
|
|
|
}
|
|
|
|
|
|
public SignFamily getssPatientSign(String invitePatientCode) {
|
|
|
return signFamilyDao.findBySsPatient(invitePatientCode);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 患者家庭签约收费类型更新
|
|
|
*
|
|
|
* @param expensesType
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean updateExpensesType(String expensesType, String patient) {
|
|
|
return signFamilyDao.updateExpensesType(expensesType, patient) > 0;
|
|
|
}
|
|
|
|
|
|
public boolean updateSignStatus(String patientCard) {
|
|
|
// 判断患者有没有家庭签约
|
|
|
SignFamily sf = signFamilyDao.findByPatientStatus(patientCard, 0);
|
|
|
if (sf != null) {
|
|
|
sf.setStatus(-1);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public String produceSignAdminTeamCode() {
|
|
|
StringBuffer sf = new StringBuffer();
|
|
|
StringBuffer sf1 = new StringBuffer();
|
|
|
Long size = 0L;
|
|
|
//找出家庭签约中团队code是空的
|
|
|
List<SignFamily> signFamilys = signFamilyDao.findBySignTypeAndTeamCode();
|
|
|
sf.append("家庭签约中团队code是空的数据数:" + signFamilys.size());
|
|
|
for (SignFamily signFamily : signFamilys) {
|
|
|
//得到签约中的全科医生的团队
|
|
|
String doctorCode = signFamily.getDoctor();
|
|
|
Long id = doctorAdminTeamDao.findIdByLeaderCode(doctorCode);
|
|
|
if (id != null && id > 0) {
|
|
|
size++;
|
|
|
signFamily.setAdminTeamId(id);
|
|
|
} else {
|
|
|
sf1.append(",找不到医生所属的团队,医生code:" + doctorCode);
|
|
|
}
|
|
|
}
|
|
|
sf.append(",填充团队的签约数据数:" + size);
|
|
|
sf.append(sf1);
|
|
|
return sf.toString();
|
|
|
}
|
|
|
|
|
|
public JSONObject findByParamsWithDoctor(String doctorCode, String teamCode, String params, int level) throws Exception {
|
|
|
JSONObject returnMap = new JSONObject();
|
|
|
String addressSql = "select a.signcode,a.name,a.address,a.code,a.hasopenid,a.idcard,a.photo from( SELECT " +
|
|
|
" sf.CODE signcode, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.name name, " +
|
|
|
" p.address address, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
// " and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND ( " + (level == 2 ? "sf.doctor =?" : "sf.doctor_health =? ") + ") ) a where 1=1";
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(params)) {
|
|
|
addressSql += " AND a.address like '%" + params + "%'";
|
|
|
}
|
|
|
List<Map<String, Object>> datas = jdbcTemplate.queryForList(addressSql, teamCode, doctorCode);
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("signcode", map.get("signcode"));
|
|
|
jo.put("name", map.get("name"));
|
|
|
jo.put("photo", map.get("photo"));
|
|
|
jo.put("address", map.get("address"));
|
|
|
jo.put("code", map.get("code"));
|
|
|
jo.put("hasopenid", map.get("hasopenid"));
|
|
|
jo.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
|
|
|
jo.put("sex", IdCardUtil.getSexForIdcard_new(map.get("idcard").toString()));
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
returnMap.put("address", jsonArray);
|
|
|
}
|
|
|
String patientNameSql = "select a.signcode,a.name,a.address,a.code,a.hasopenid,a.idcard,a.photo from( SELECT " +
|
|
|
" sf.CODE signcode, " +
|
|
|
" p.name name, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.address address, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
//" and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND ( " + (level == 2 ? "sf.doctor =?" : "sf.doctor_health =? ") + ") ) a where 1=1";
|
|
|
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(params)) {
|
|
|
patientNameSql += " AND a.name like '%" + params + "%'";
|
|
|
}
|
|
|
datas = jdbcTemplate.queryForList(patientNameSql, teamCode, doctorCode);
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("signcode", map.get("signcode"));
|
|
|
jo.put("name", map.get("name"));
|
|
|
jo.put("photo", map.get("photo"));
|
|
|
jo.put("code", map.get("code"));
|
|
|
jo.put("hasopenid", map.get("hasopenid"));
|
|
|
jo.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
|
|
|
jo.put("sex", IdCardUtil.getSexForIdcard_new(map.get("idcard").toString()));
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
returnMap.put("name", jsonArray);
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
public JSONObject findNoHealthSignFamilyHealthByParams(String doctorCode, String teamCode, String params) throws Exception {
|
|
|
JSONObject returnMap = new JSONObject();
|
|
|
String addressSql = "select a.signcode,a.name,a.address,a.code,a.hasopenid,a.idcard,a.photo from( SELECT " +
|
|
|
" sf.CODE signcode, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.name name, " +
|
|
|
" p.address address, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
// " and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND ( sf.doctor_health is null or sf.doctor_health ='' ) ) a where 1=1";
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(params)) {
|
|
|
addressSql += " AND a.address like '%" + params + "%'";
|
|
|
}
|
|
|
List<Map<String, Object>> datas = jdbcTemplate.queryForList(addressSql, teamCode);
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("signcode", map.get("signcode"));
|
|
|
jo.put("name", map.get("name"));
|
|
|
jo.put("photo", map.get("photo"));
|
|
|
jo.put("address", map.get("address"));
|
|
|
jo.put("code", map.get("code"));
|
|
|
jo.put("hasopenid", map.get("hasopenid"));
|
|
|
jo.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
|
|
|
jo.put("sex", IdCardUtil.getSexForIdcard_new(map.get("idcard").toString()));
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
returnMap.put("address", jsonArray);
|
|
|
}
|
|
|
String patientNameSql = "select a.signcode,a.name,a.address,a.code,a.hasopenid,a.idcard,a.photo from( SELECT " +
|
|
|
" sf.CODE signcode, " +
|
|
|
" p.name name, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.address address, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
//" and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND ( sf.doctor_health is null or sf.doctor_health ='' ) ) a where 1=1";
|
|
|
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(params)) {
|
|
|
patientNameSql += " AND a.name like '%" + params + "%'";
|
|
|
}
|
|
|
datas = jdbcTemplate.queryForList(patientNameSql, teamCode);
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("signcode", map.get("signcode"));
|
|
|
jo.put("name", map.get("name"));
|
|
|
jo.put("photo", map.get("photo"));
|
|
|
jo.put("code", map.get("code"));
|
|
|
jo.put("hasopenid", map.get("hasopenid"));
|
|
|
jo.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
|
|
|
jo.put("sex", IdCardUtil.getSexForIdcard_new(map.get("idcard").toString()));
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
returnMap.put("name", jsonArray);
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
public JSONObject findNoHealthSignFamilyHealth(String doctorCode, String labelType, String patientName, Long teamCode) throws Exception {
|
|
|
JSONObject returnMap = new JSONObject();
|
|
|
//健康管理师
|
|
|
String sql = "SELECT " +
|
|
|
" sf. CODE signcode, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.name name, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" sp.id labelid, " +
|
|
|
" CASE WHEN sp.label_name is null THEN '未标注' WHEN sp.label_name='' THEN '未标注' else sp.label_name END labelname, " +
|
|
|
" sp.label_type labeltype, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.label_type = ? AND sp.`status` = 1 " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
// " and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND ( sf.doctor_health is null or sf.doctor_health ='' ) ";
|
|
|
List<Map<String, Object>> datas = null;
|
|
|
//查找居民
|
|
|
datas = jdbcTemplate.queryForList(sql, labelType, teamCode);
|
|
|
|
|
|
//根据类别查找标签
|
|
|
List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, teamCode);
|
|
|
if (s != null && s.size() > 0) {
|
|
|
for (SignPatientLabel one : s) {
|
|
|
returnMap.put(one.getLabelName(), new JSONArray());
|
|
|
}
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("signcode", map.get("signcode"));
|
|
|
jo.put("name", map.get("name"));
|
|
|
jo.put("photo", map.get("photo"));
|
|
|
jo.put("code", map.get("code"));
|
|
|
jo.put("hasopenid", map.get("hasopenid"));
|
|
|
jo.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
|
|
|
jo.put("sex", IdCardUtil.getSexForIdcard_new(map.get("idcard").toString()));
|
|
|
JSONArray jr = new JSONArray();
|
|
|
if (returnMap.has(map.get("labelname").toString())) {
|
|
|
jr = returnMap.getJSONArray(map.get("labelname").toString());
|
|
|
}
|
|
|
jr.put(jo);
|
|
|
returnMap.put(map.get("labelname").toString(), jr);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询居民的所有签约
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public List<SignFamily> findAllSignByPatient(String patient) {
|
|
|
return signFamilyDao.findAllSignByPatient(patient);
|
|
|
}
|
|
|
|
|
|
public List<SignFamily> findNoHealthSignFamilyNum(long teamCode) {
|
|
|
return signFamilyDao.findNoHealthSignFamilyNum(teamCode);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取未分配健管师关注公众号人数
|
|
|
*
|
|
|
* @param teamCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public int findNoHealthSignFamilyFocusNum(Long teamCode) throws Exception {
|
|
|
String sql = "select count(distinct patient) count from wlyy_sign_family where admin_team_code = ? and doctor_health is null and status > 0 and length(trim(ifnull(openid,''))) > 1";
|
|
|
List<Map<String, Object>> count = jdbcTemplate.queryForList(sql, teamCode);
|
|
|
if (count != null && count.size() > 0 && count.get(0).containsKey("count")) {
|
|
|
return Integer.valueOf(String.valueOf(count.get(0).get("count")));
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断居民与医生是否存在签约关系
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject isPatientAndDoctorExistSign(String patient, String doctor) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
SignFamily familySign = signFamilyDao.findFamilySignByPatient(patient);
|
|
|
SignFamily sanshiSign = signFamilyDao.findSanshiSignByPatient(patient);
|
|
|
|
|
|
if (familySign != null) {
|
|
|
if (doctor.equals(StringUtils.isEmpty(familySign.getDoctor()) ? "" : familySign.getDoctor()) ||
|
|
|
doctor.equals(StringUtils.isEmpty(familySign.getDoctorHealth()) ? "" : familySign.getDoctorHealth())) {
|
|
|
if (familySign.getStatus() == 0) {
|
|
|
result.put("status", "0");
|
|
|
result.put("msg", "已申请家庭签约");
|
|
|
} else {
|
|
|
result.put("status", "1");
|
|
|
result.put("msg", "已有家庭签约");
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
if (sanshiSign != null) {
|
|
|
if (doctor.equals(StringUtils.isEmpty(sanshiSign.getDoctor()) ? "" : sanshiSign.getDoctor()) ||
|
|
|
doctor.equals(StringUtils.isEmpty(sanshiSign.getDoctorHealth()) ? "" : sanshiSign.getDoctorHealth())) {
|
|
|
result.put("status", "2");
|
|
|
result.put("msg", "已有三师签约");
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.put("status", "-1");
|
|
|
result.put("msg", "无签约关系");
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONObject getPatientSignDoctorsByTeam(String sessionId) {
|
|
|
String infos[] = sessionId.split("_");
|
|
|
JSONObject result = new JSONObject();
|
|
|
Map<String, JSONObject> docMap = new HashMap<>();
|
|
|
SignFamily ssSign = signFamilyDao.findSignByPatient(infos[0], 1);
|
|
|
// SignFamily jtSign = signFamilyDao.findByTeamCode(infos[1]);
|
|
|
SignFamily jtSign = getSignFamilyBySessionId(sessionId, infos[0]);
|
|
|
JSONObject ssArray = new JSONObject();
|
|
|
JSONObject jtArray = new JSONObject();
|
|
|
if (ssSign != null) {
|
|
|
JSONObject qkDoc = new JSONObject();
|
|
|
qkDoc.put("doctor", ssSign.getDoctor());
|
|
|
qkDoc.put("doctorName", ssSign.getDoctorName());
|
|
|
ssArray.put("doctor", qkDoc);
|
|
|
JSONObject jgDoc = new JSONObject();
|
|
|
jgDoc.put("doctor", ssSign.getDoctorHealth());
|
|
|
jgDoc.put("doctorName", ssSign.getDoctorHealthName());
|
|
|
ssArray.put("doctorHealth", jgDoc);
|
|
|
}
|
|
|
if (jtSign != null) {
|
|
|
JSONObject qkDoc = new JSONObject();
|
|
|
qkDoc.put("doctor", jtSign.getDoctor());
|
|
|
qkDoc.put("doctorName", jtSign.getDoctorName());
|
|
|
jtArray.put("doctor", qkDoc);
|
|
|
JSONObject jgDoc = new JSONObject();
|
|
|
jgDoc.put("doctor", jtSign.getDoctorHealth());
|
|
|
jgDoc.put("doctorName", jtSign.getDoctorHealthName());
|
|
|
jtArray.put("doctorHealth", jgDoc);
|
|
|
}
|
|
|
result.put("ssSign", ssArray);
|
|
|
result.put("jtSign", jtArray);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据会话id查询 家庭签约信息
|
|
|
*
|
|
|
* @param sessionId
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public SignFamily getSignFamilyBySessionId(String sessionId, String patient) {
|
|
|
SignFamily signFamily = null;
|
|
|
String sql = "select id from " + im_dataBase_name + ".topics where session_id = '" + sessionId + "' order by create_time desc limit 0, 1";
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
String consultCode = list.get(0).get("id").toString();
|
|
|
signFamily = signFamilyDao.findByPatient(patient);
|
|
|
Consult consult = consultDao.findByCode(consultCode);
|
|
|
if (signFamily == null || signFamily.getApplyDate().getTime() - consult.getCzrq().getTime() > 0) {
|
|
|
signFamily = signFamilyDao.findOutTimeSigningByPatient(patient);
|
|
|
}
|
|
|
}
|
|
|
return signFamily;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询患者对应医生
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getPatientSignDoctors(String patient) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
Map<String, JSONObject> docMap = new HashMap<>();
|
|
|
SignFamily ssSign = signFamilyDao.findSignByPatient(patient, 1);
|
|
|
SignFamily jtSign = signFamilyDao.findSignByPatient(patient, 2);
|
|
|
JSONObject ssArray = new JSONObject();
|
|
|
JSONObject jtArray = new JSONObject();
|
|
|
|
|
|
if (ssSign != null) {
|
|
|
JSONObject qkDoc = new JSONObject();
|
|
|
qkDoc.put("doctor", ssSign.getDoctor());
|
|
|
qkDoc.put("doctorName", ssSign.getDoctorName());
|
|
|
|
|
|
ssArray.put("doctor", qkDoc);
|
|
|
|
|
|
JSONObject jgDoc = new JSONObject();
|
|
|
jgDoc.put("doctor", ssSign.getDoctorHealth());
|
|
|
jgDoc.put("doctorName", ssSign.getDoctorHealthName());
|
|
|
|
|
|
ssArray.put("doctorHealth", jgDoc);
|
|
|
}
|
|
|
if (jtSign != null) {
|
|
|
JSONObject qkDoc = new JSONObject();
|
|
|
qkDoc.put("doctor", jtSign.getDoctor());
|
|
|
qkDoc.put("doctorName", jtSign.getDoctorName());
|
|
|
|
|
|
jtArray.put("doctor", qkDoc);
|
|
|
|
|
|
JSONObject jgDoc = new JSONObject();
|
|
|
jgDoc.put("doctor", jtSign.getDoctorHealth());
|
|
|
jgDoc.put("doctorName", jtSign.getDoctorHealthName());
|
|
|
|
|
|
jtArray.put("doctorHealth", jgDoc);
|
|
|
}
|
|
|
|
|
|
result.put("ssSign", ssArray);
|
|
|
result.put("jtSign", jtArray);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public Map<String, List<Patient>> getPatientByLevel(String doctorCode, Long team) {
|
|
|
Map<String, List<Patient>> returnMap = new HashMap<>();
|
|
|
Doctor doctor = doctorDao.findByCode(doctorCode);
|
|
|
//判断当前用户是健康管理师还是全科
|
|
|
if (doctor.getLevel() == 3) {
|
|
|
//健康管理师
|
|
|
List<Patient> jkgl = signFamilyDao.findByDoctorHealthPatient(doctorCode, team);
|
|
|
returnMap.put("jk", jkgl);
|
|
|
} else if (doctor.getLevel() == 2) {
|
|
|
//全科医生
|
|
|
List<Patient> qkys = signFamilyDao.findByDoctorPatient(doctorCode, team);
|
|
|
returnMap.put("qk", qkys);
|
|
|
//健康管理师
|
|
|
List<Patient> jkgl = signFamilyDao.findByDoctorHealthPatient(doctorCode, team);
|
|
|
returnMap.put("jk", jkgl);
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
//根据姓名、地址、身份证搜索已分配健管师的居民
|
|
|
public List getPatientByLable(String doctorCode, String filter, String level, Long team, int page, int pagesize) throws Exception {
|
|
|
List list = new ArrayList();
|
|
|
//判断当前用户是健康管理师还是全科
|
|
|
List<Map<String, Object>> datas = null;
|
|
|
if (level.equals("3")) {
|
|
|
//健康管理师
|
|
|
String sql = "SELECT DISTINCT " +
|
|
|
" p.photo photo, " +
|
|
|
" p.name name, " +
|
|
|
" p.code code, " +
|
|
|
" p.sex sex," +
|
|
|
" p.address address," +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
" and sf.doctor_health = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
|
|
|
" ORDER BY p.name DESC,p.address DESC, p.idcard DESC " +
|
|
|
" limit " + (page - 1) * pagesize + "," + pagesize;
|
|
|
|
|
|
//查找居民
|
|
|
datas = jdbcTemplate.queryForList(sql, doctorCode, team, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%");
|
|
|
} else if (level.equals("2")) {
|
|
|
//全科
|
|
|
String sql = "SELECT DISTINCT " +
|
|
|
" p.photo photo, " +
|
|
|
" p.name name, " +
|
|
|
" p.code code, " +
|
|
|
" p.sex sex," +
|
|
|
" p.address address," +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.`status` = 1 " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
" and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? " +
|
|
|
" AND (p.name like ? or p.address like ? or p.idcard like ? ) " +
|
|
|
" ORDER BY p.name DESC,p.address DESC, p.idcard DESC " +
|
|
|
" limit " + (page - 1) * pagesize + "," + pagesize;
|
|
|
|
|
|
//查找居民
|
|
|
datas = jdbcTemplate.queryForList(sql, doctorCode, team, "%" + filter + "%", "%" + filter + "%", "%" + filter + "%");
|
|
|
|
|
|
} else {
|
|
|
throw new Exception("参数错误!");
|
|
|
}
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
Map ma = new HashMap();
|
|
|
ma.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard") == null ? "" : map.get("idcard").toString()));
|
|
|
ma.put("photo", map.get("photo") == null ? "" : map.get("photo").toString());
|
|
|
ma.put("name", map.get("name") == null ? "" : map.get("name").toString());
|
|
|
ma.put("code", map.get("code") == null ? "" : map.get("code").toString());
|
|
|
ma.put("sex", map.get("sex") == null ? "" : map.get("sex").toString());
|
|
|
ma.put("address", map.get("address") == null ? "" : map.get("address").toString());
|
|
|
ma.put("idcard", map.get("idcard") == null ? "" : map.get("idcard").toString());
|
|
|
list.add(ma);
|
|
|
}
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public JSONObject getPatientByLable(String doctorCode, String labelType, String level, Long team) throws Exception {
|
|
|
JSONObject returnMap = new JSONObject();
|
|
|
//判断当前用户是健康管理师还是全科
|
|
|
List<Map<String, Object>> datas = null;
|
|
|
if (level.equals("3")) {
|
|
|
//健康管理师
|
|
|
String sql = "SELECT " +
|
|
|
" sf. CODE signcode, " +
|
|
|
" p.name name, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" sp.id labelid, " +
|
|
|
" CASE WHEN sp.label_name is null THEN '未标注' WHEN sp.label_name='' THEN '未标注' else sp.label_name END labelname, " +
|
|
|
" sp.label_type labeltype, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.label_type = ? AND sp.`status` = 1 " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
" and sf.doctor_health = ? " +
|
|
|
" and sf.admin_team_code = ? ";
|
|
|
|
|
|
//查找居民
|
|
|
datas = jdbcTemplate.queryForList(sql, labelType, doctorCode, team);
|
|
|
} else if (level.equals("2")) {
|
|
|
//全科
|
|
|
String sql = "SELECT " +
|
|
|
" sf. CODE signcode, " +
|
|
|
" p.name name, " +
|
|
|
" p.photo photo, " +
|
|
|
" p.code code, " +
|
|
|
" CASE WHEN p.openid is null THEN '0' WHEN p.openid='' THEN '0' else 1 END hasopenid, " +
|
|
|
" sp.id labelid, " +
|
|
|
" CASE WHEN sp.label_name is null THEN '未标注' WHEN sp.label_name='' THEN '未标注' else sp.label_name END labelname, " +
|
|
|
" sp.label_type labeltype, " +
|
|
|
" p.idcard idcard " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" JOIN wlyy_patient p ON sf.patient = p.CODE " +
|
|
|
" left JOIN wlyy_sign_patient_label_info sp ON sf.patient = sp.patient AND sp.label_type = ? AND sp.`status` = 1 " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf. STATUS > 0 " +
|
|
|
" and sf.doctor = ? " +
|
|
|
" and sf.admin_team_code = ? ";
|
|
|
|
|
|
//查找居民
|
|
|
datas = jdbcTemplate.queryForList(sql, labelType, doctorCode, team);
|
|
|
|
|
|
} else {
|
|
|
throw new Exception("参数错误!");
|
|
|
}
|
|
|
//根据类别查找标签
|
|
|
List<SignPatientLabel> s = labelDao.findByLabelTypeAndStatusAndTeamCode(labelType, 1, team);
|
|
|
if (s != null && s.size() > 0) {
|
|
|
for (SignPatientLabel one : s) {
|
|
|
returnMap.put(one.getLabelName(), new JSONArray());
|
|
|
}
|
|
|
if (datas != null && datas.size() > 0) {
|
|
|
for (Map<String, Object> map : datas) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("signcode", map.get("signcode"));
|
|
|
jo.put("name", map.get("name"));
|
|
|
jo.put("photo", map.get("photo"));
|
|
|
jo.put("code", map.get("code"));
|
|
|
jo.put("hasopenid", map.get("hasopenid"));
|
|
|
jo.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard").toString()));
|
|
|
jo.put("sex", IdCardUtil.getSexForIdcard_new(map.get("idcard").toString()));
|
|
|
//判断name是否为空 为空就是未标注
|
|
|
//把患者添加到对应的组
|
|
|
JSONArray jr = new JSONArray();
|
|
|
if (returnMap.has(map.get("labelname").toString())) {
|
|
|
jr = returnMap.getJSONArray(map.get("labelname").toString());
|
|
|
}
|
|
|
jr.put(jo);
|
|
|
returnMap.put(map.get("labelname").toString(), jr);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
public Integer findPatientCountByAdminTeam(String doctorCode, String teamCode) {
|
|
|
String sql = "select count(sf.id) " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family sf " +
|
|
|
" WHERE " +
|
|
|
" sf.type = 2 " +
|
|
|
" AND sf.STATUS > 0 " +
|
|
|
" AND ( sf.doctor = ? or sf.doctor_health=? )" +
|
|
|
" AND sf.admin_team_code =?";
|
|
|
Object[] parms = new Object[]{doctorCode, doctorCode, teamCode};
|
|
|
Integer count = jdbcTemplate.queryForObject(sql, parms, Integer.class);
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public String getTeamName(String code) {
|
|
|
try {
|
|
|
String sql = "SELECT t.name FROM wlyy_doctor_team t WHERE t.code ='" + code + "'";
|
|
|
|
|
|
List<Map<String, Object>> map = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
if (map != null && map.size() > 0) {
|
|
|
return (String) map.get(0).get("name");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONArray getSignDoctorMessageOverDue(String patientCode) {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
//找出患者的三师签约信息
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
int year = cal.get(Calendar.YEAR);
|
|
|
|
|
|
//得到家庭签约
|
|
|
SignFamily jtSignFamily = signFamilyDao.findFamilySignByPatientOverDue(patientCode, (year - 1) + "");
|
|
|
|
|
|
if (jtSignFamily != null) {
|
|
|
//家庭签约只找全科医生
|
|
|
Doctor doctor = doctorDao.findByCode(jtSignFamily.getDoctor());
|
|
|
Doctor doctorHealth = doctorDao.findByCode(jtSignFamily.getDoctorHealth());
|
|
|
if (doctor != null) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("code", doctor.getCode());
|
|
|
jo.put("sex", doctor.getSex());
|
|
|
jo.put("name", doctor.getName());
|
|
|
jo.put("photo", doctor.getPhoto());
|
|
|
jo.put("hosptialName", doctor.getHospitalName());
|
|
|
jo.put("level", doctor.getLevel());
|
|
|
jo.put("signType", "2");//三师签约
|
|
|
jo.put("signStatus", jtSignFamily.getStatus());
|
|
|
jo.put("jobName", doctor.getJobName());
|
|
|
jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
if (jtSignFamily.getStatus() == 0) {
|
|
|
jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
|
|
|
} else {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getBegin()));//签约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
|
|
|
}
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
if (doctorHealth != null) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
jo.put("code", doctorHealth.getCode());
|
|
|
jo.put("sex", doctorHealth.getSex());
|
|
|
jo.put("name", doctorHealth.getName());
|
|
|
jo.put("photo", doctorHealth.getPhoto());
|
|
|
jo.put("hosptialName", doctorHealth.getHospitalName());
|
|
|
jo.put("level", doctorHealth.getLevel());
|
|
|
jo.put("signType", "2");//三师签约
|
|
|
jo.put("signStatus", jtSignFamily.getStatus());
|
|
|
jo.put("jobName", doctorHealth.getJobName());
|
|
|
jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
|
|
|
if (jtSignFamily.getStatus() == 0) {
|
|
|
jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
|
|
|
} else {
|
|
|
jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getBegin()));//签约时间
|
|
|
jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
|
|
|
}
|
|
|
jsonArray.put(jo);
|
|
|
}
|
|
|
}
|
|
|
return jsonArray;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 存储同步纪委标识
|
|
|
*
|
|
|
* @param idCard
|
|
|
* @param signYear
|
|
|
*/
|
|
|
public void setSignFamilyMapping(String signCode, String idCard, String signYear) {
|
|
|
SignFamilyMapping maping = new SignFamilyMapping();
|
|
|
maping.setCode(signCode);
|
|
|
maping.setCreateTime(new Date());
|
|
|
maping.setIdcard(idCard);
|
|
|
maping.setNeedUpdate("0");
|
|
|
maping.setSignYear(signYear);
|
|
|
//判断是否是预签约
|
|
|
//判断规则:如果在4月份到7月份为预签约
|
|
|
int month = DateUtil.getNowMonth();
|
|
|
if (month >= 4 && month < 7) {
|
|
|
//预签约逻辑
|
|
|
maping.setNeedUpload("0");
|
|
|
maping.setNeedRenewUpload("1");
|
|
|
} else {
|
|
|
maping.setNeedUpload("1");
|
|
|
maping.setNeedRenewUpload("0");
|
|
|
}
|
|
|
signFamilyMappingDao.save(maping);
|
|
|
}
|
|
|
|
|
|
public SignFamily findOutTimeSigningByPatient(String patient) {
|
|
|
return signFamilyDao.findOutTimeSigningByPatient(patient);
|
|
|
}
|
|
|
|
|
|
public JSONObject getServerPatientList(Long teamCode) {
|
|
|
String serverSql = "SELECT " +
|
|
|
" d.`code` As labelCode, " +
|
|
|
" d.`name` AS label " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_dict d " +
|
|
|
" WHERE " +
|
|
|
" d.type IN ('1', '2') " +
|
|
|
" AND d. YEAR = '" + DateUtil.getSignYear() + "' ";
|
|
|
String patientSql = "SELECT " +
|
|
|
" f.patient, " +
|
|
|
" f.sign_year, " +
|
|
|
" t.server_type AS serverType, " +
|
|
|
" t.server_type_name AS specialPopulation " +
|
|
|
"FROM " +
|
|
|
" wlyy_sign_family_server t, " +
|
|
|
" ( " +
|
|
|
" SELECT " +
|
|
|
" s.`code`, " +
|
|
|
" s.patient, " +
|
|
|
" s.sign_year " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family s " +
|
|
|
" WHERE " +
|
|
|
" s.`status` >= 0 " +
|
|
|
" AND s.admin_team_code = " + teamCode +
|
|
|
" AND s.doctor_health IS NULL " +
|
|
|
" ) f " +
|
|
|
"WHERE " +
|
|
|
" t.sign_code = f. CODE ";
|
|
|
List<Map<String, Object>> patientList = jdbcTemplate.queryForList(patientSql);
|
|
|
String totalSql = " SELECT " +
|
|
|
" s.patient" +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family s " +
|
|
|
" WHERE " +
|
|
|
" s.`status` >= 0 " +
|
|
|
" AND s.admin_team_code =" + teamCode +
|
|
|
" AND s.doctor_health IS NULL";
|
|
|
List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
|
|
|
|
|
|
JSONObject rs = new JSONObject();
|
|
|
rs.put("count", (totalList != null && totalList.size() > 0) ? totalList.size() : 0);
|
|
|
|
|
|
List<Map<String, Object>> serlist = jdbcTemplate.queryForList(serverSql);
|
|
|
if (serlist != null && serlist.size() > 0) {
|
|
|
if (patientList != null) {
|
|
|
for (Map<String, Object> map : serlist) {
|
|
|
String labelCode = (String) map.get("labelCode");
|
|
|
List<Map<String, String>> codes = new ArrayList<>();
|
|
|
Iterator iterator = patientList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Map<String, Object> p = (Map<String, Object>) iterator.next();
|
|
|
String serverType = p.get("serverType") == null ? "" : ((String) p.get("serverType"));
|
|
|
if (labelCode.equals(serverType)) {
|
|
|
Map<String, String> code = new HashMap<>();
|
|
|
code.put("code", (String) p.get("patient"));
|
|
|
codes.add(code);
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
map.put("codes", codes);
|
|
|
map.put("number", (codes != null && codes.size() > 0) ? codes.size() : 0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
rs.put("patients", serlist);
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
public JSONObject getCountryPatientList(Long teamCode) {
|
|
|
String totalSql = " SELECT " +
|
|
|
" s.patient,ifnull(s.sick_village,0) as labelCode" +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family s " +
|
|
|
" WHERE " +
|
|
|
" s.`status` >= 0 " +
|
|
|
" AND s.admin_team_code = ? " +
|
|
|
" AND s.doctor_health IS NULL";
|
|
|
JSONObject rs = new JSONObject();
|
|
|
List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql, new Object[]{teamCode});
|
|
|
rs.put("count", (totalList != null && totalList.size() > 0) ? totalList.size() : 0);
|
|
|
String patientSql = "SELECT " +
|
|
|
" f.sick_village AS labelCode, " +
|
|
|
" f.sick_village_name AS label, " +
|
|
|
" COUNT(1) AS number " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family f " +
|
|
|
" WHERE " +
|
|
|
" f.`status` >= 0 " +
|
|
|
" AND f.admin_team_code = ? " +
|
|
|
" AND f.doctor_health IS NULL " +
|
|
|
" AND f.sick_village IS NOT NULL " +
|
|
|
" GROUP BY " +
|
|
|
" f.sick_village " +
|
|
|
" ORDER BY " +
|
|
|
" number DESC ";
|
|
|
List<Map<String, Object>> patientList = jdbcTemplate.queryForList(patientSql, new Object[]{teamCode});
|
|
|
if (patientList != null && patientList.size() > 0) {
|
|
|
for (Map<String, Object> map : patientList) {
|
|
|
String labelCode = (String) map.get("labelCode");
|
|
|
if (StringUtils.isNotBlank(labelCode)) {
|
|
|
List<Map<String, String>> codes = new ArrayList<>();
|
|
|
Iterator iterator = totalList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Map<String, Object> p = (Map<String, Object>) iterator.next();
|
|
|
String lbCode = p.get("labelCode") == null ? "" : ((String) p.get("labelCode"));
|
|
|
if (labelCode.equals(lbCode)) {
|
|
|
Map<String, String> code = new HashMap<>();
|
|
|
code.put("code", (String) p.get("patient"));
|
|
|
codes.add(code);
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
map.put("codes", codes);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rs.put("patients", patientList);
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
public JSONObject getTeamCountryPatientChangeDoctorList(Long teamCode, String level, String oldDoctorCode) {
|
|
|
String totalSql = " SELECT " +
|
|
|
" s.patient,ifnull(s.sick_village,0) as labelCode" +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family s " +
|
|
|
" WHERE " +
|
|
|
" s.`status` >= 0 " +
|
|
|
" AND s.admin_team_code = ? ";
|
|
|
if ("2".equals(level)) {
|
|
|
totalSql = totalSql + " AND s.doctor ='" + oldDoctorCode + "'";
|
|
|
} else {
|
|
|
totalSql = totalSql + " AND s.doctor_health ='" + oldDoctorCode + "'";
|
|
|
}
|
|
|
JSONObject rs = new JSONObject();
|
|
|
List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql, new Object[]{teamCode});
|
|
|
rs.put("count", (totalList != null && totalList.size() > 0) ? totalList.size() : 0);
|
|
|
String patientSql = "SELECT " +
|
|
|
" f.sick_village AS labelCode, " +
|
|
|
" f.sick_village_name AS label, " +
|
|
|
" COUNT(1) AS number " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family f " +
|
|
|
" WHERE " +
|
|
|
" f.`status` >= 0 " +
|
|
|
" AND f.sick_village IS NOT NULL " +
|
|
|
" AND f.admin_team_code = ? ";
|
|
|
if ("2".equals(level)) {
|
|
|
patientSql = patientSql + " AND f.doctor ='" + oldDoctorCode + "'";
|
|
|
} else {
|
|
|
patientSql = patientSql + " AND f.doctor_health ='" + oldDoctorCode + "'";
|
|
|
}
|
|
|
patientSql = patientSql + " GROUP BY " +
|
|
|
" f.sick_village " +
|
|
|
" ORDER BY " +
|
|
|
" number DESC ";
|
|
|
List<Map<String, Object>> patientList = jdbcTemplate.queryForList(patientSql, new Object[]{teamCode});
|
|
|
if (patientList != null && patientList.size() > 0) {
|
|
|
for (Map<String, Object> map : patientList) {
|
|
|
String labelCode = (String) map.get("labelCode");
|
|
|
if (StringUtils.isNotBlank(labelCode)) {
|
|
|
List<Map<String, String>> codes = new ArrayList<>();
|
|
|
Iterator iterator = totalList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Map<String, Object> p = (Map<String, Object>) iterator.next();
|
|
|
String lbCode = p.get("labelCode") == null ? "" : ((String) p.get("labelCode"));
|
|
|
if (labelCode.equals(lbCode)) {
|
|
|
Map<String, String> code = new HashMap<>();
|
|
|
code.put("code", (String) p.get("patient"));
|
|
|
codes.add(code);
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
map.put("codes", codes);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rs.put("patients", patientList);
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONObject getServerPatientListNum(Long teamCode, String level, String oldDoctorCode) {
|
|
|
String serverSql = "SELECT " +
|
|
|
" d.`code` As labelCode, " +
|
|
|
" d.`name` AS label " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_dict d " +
|
|
|
" WHERE " +
|
|
|
" d.type IN ('1', '2') " +
|
|
|
" AND d. YEAR = '" + DateUtil.getSignYear() + "' ";
|
|
|
|
|
|
String patientSql = "SELECT " +
|
|
|
" f.patient, " +
|
|
|
" s.server_type AS serverType, " +
|
|
|
" s.server_type_name AS serverTypeName " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family_server s, " +
|
|
|
"( " +
|
|
|
" SELECT " +
|
|
|
" s.patient, " +
|
|
|
" s.`code` " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family s " +
|
|
|
" WHERE " +
|
|
|
" s.`status` >= 0 " +
|
|
|
" AND s.admin_team_code = " + teamCode;
|
|
|
//1查询全科,其他查询健管师
|
|
|
if ("2".equals(level)) {
|
|
|
patientSql = patientSql + " AND s.doctor ='" + oldDoctorCode + "'";
|
|
|
} else {
|
|
|
patientSql = patientSql + " AND s.doctor_health ='" + oldDoctorCode + "'";
|
|
|
}
|
|
|
patientSql = patientSql + " ) f WHERE f.`code` =s.sign_code";
|
|
|
|
|
|
List<Map<String, Object>> patientList = jdbcTemplate.queryForList(patientSql);
|
|
|
String totalSql = " SELECT " +
|
|
|
" s.patient " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family s " +
|
|
|
" WHERE " +
|
|
|
" s.`status` >= 0 " +
|
|
|
" AND s.admin_team_code =" + teamCode;
|
|
|
//1查询全科,其他查询健管师
|
|
|
if ("2".equals(level)) {
|
|
|
totalSql = totalSql + " AND s.doctor ='" + oldDoctorCode + "'";
|
|
|
} else {
|
|
|
totalSql = totalSql + " AND s.doctor_health ='" + oldDoctorCode + "'";
|
|
|
}
|
|
|
List<Map<String, Object>> totalList = jdbcTemplate.queryForList(totalSql);
|
|
|
|
|
|
JSONObject rs = new JSONObject();
|
|
|
rs.put("count", (totalList != null && totalList.size() > 0) ? totalList.size() : 0);
|
|
|
|
|
|
List<Map<String, Object>> serlist = jdbcTemplate.queryForList(serverSql);
|
|
|
if (serlist != null && serlist.size() > 0) {
|
|
|
if (patientList != null) {
|
|
|
for (Map<String, Object> map : serlist) {
|
|
|
String labelCode = (String) map.get("labelCode");
|
|
|
List<Map<String, String>> codes = new ArrayList<>();
|
|
|
Iterator iterator = patientList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Map<String, Object> p = (Map<String, Object>) iterator.next();
|
|
|
String serverType = p.get("serverType") == null ? "" : ((String) p.get("serverType"));
|
|
|
if (labelCode.equals(serverType)) {
|
|
|
Map<String, String> code = new HashMap<>();
|
|
|
code.put("code", (String) p.get("patient"));
|
|
|
codes.add(code);
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
map.put("codes", codes);
|
|
|
map.put("number", (codes != null && codes.size() > 0) ? codes.size() : 0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
rs.put("patients", serlist);
|
|
|
return rs;
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> patientGroupByServerType(String doctor) {
|
|
|
|
|
|
// 先根据server_type分组查找wlyy_sign_family表中该医生的签约的患者,然后wlyy_sign_dict left join 得到全部的类型
|
|
|
|
|
|
String sql = "SELECT " +
|
|
|
" sd.CODE labelCode, " +
|
|
|
" sd.NAME labelName, " +
|
|
|
" IFNULL(t.count,0) amount " +
|
|
|
"FROM " +
|
|
|
" wlyy_sign_dict sd " +
|
|
|
"LEFT JOIN ( " +
|
|
|
" SELECT " +
|
|
|
" s.server_type, " +
|
|
|
" s.server_type_name, " +
|
|
|
" COUNT(1) count " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family_server s, " +
|
|
|
" ( " +
|
|
|
" SELECT " +
|
|
|
" f. CODE " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family f " +
|
|
|
" WHERE " +
|
|
|
" ( " +
|
|
|
" f.doctor = ? " +
|
|
|
" OR f.doctor_health = ?" +
|
|
|
" ) " +
|
|
|
" AND f.`status` > 0 " +
|
|
|
" ) f " +
|
|
|
" WHERE " +
|
|
|
" s.sign_code = f.`code` " +
|
|
|
" GROUP BY " +
|
|
|
" s.server_type " +
|
|
|
") t ON sd.CODE = t.server_type " +
|
|
|
"WHERE " +
|
|
|
" sd.`year` = '" + DateUtil.getSignYear() + "'";
|
|
|
|
|
|
List<Map<String, Object>> queryData = jdbcTemplate.queryForList(sql, doctor, doctor);
|
|
|
|
|
|
return queryData;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断患者和医生是否有去年的签约记录
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Object> checkLastYearIsSign(String patient, String doctor) {
|
|
|
String sql = "SELECT f.id,f.admin_team_code FROM wlyy_sign_family f WHERE f.doctor ='" + doctor + "' AND f.patient='" + patient + "' AND f.sign_year='" + (DateUtil.getSignYear() - 1) + "' AND f.`status`=-4 AND f.expenses_status ='1'";
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
return list.get(0);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查找医生所属团队下的某个居民
|
|
|
*
|
|
|
* @param teamCode
|
|
|
* @param patientName
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Patient> signPatientsByName(Long teamCode, String patientName, Integer page, Integer pageSize) {
|
|
|
StringBuffer sb = new StringBuffer("SELECT " +
|
|
|
" p.* " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family a ," +
|
|
|
" wlyy_patient p ," +
|
|
|
"WHERE " +
|
|
|
" a.admin_team_code =? " +
|
|
|
" AND a.patient=p.`code` " +
|
|
|
" AND a.`status` IN (1, 2) ");
|
|
|
List params = new ArrayList<>();
|
|
|
params.add(teamCode);
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(patientName)) {
|
|
|
sb.append(" AND a.`name` LIKE ? ");
|
|
|
params.add("%" + patientName + "%");
|
|
|
}
|
|
|
|
|
|
pageSize = page * pageSize;
|
|
|
page = (page - 1) * pageSize;
|
|
|
|
|
|
sb.append(" limit " + page + "," + pageSize);
|
|
|
List<Patient> patients = jdbcTemplate.query(sb.toString(), params.toArray(), new BeanPropertyRowMapper(Patient.class));
|
|
|
return patients;
|
|
|
}
|
|
|
|
|
|
public Integer signPatientsByNameCount(Long teamCode, String patientName) {
|
|
|
StringBuffer sb = new StringBuffer("SELECT " +
|
|
|
" p.* " +
|
|
|
" FROM " +
|
|
|
" wlyy_sign_family a ," +
|
|
|
" wlyy_patient p ," +
|
|
|
"WHERE " +
|
|
|
" a.patient=p.`code` " +
|
|
|
" AND a.`status` IN (1, 2) ");
|
|
|
List params = new ArrayList<>();
|
|
|
if (teamCode != null && teamCode > 0) {
|
|
|
sb.append(" AND a.admin_team_code =? ");
|
|
|
params.add(teamCode);
|
|
|
}
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(patientName)) {
|
|
|
sb.append(" AND a.`name` LIKE ? ");
|
|
|
params.add("%" + patientName + "%");
|
|
|
}
|
|
|
|
|
|
Integer patients = jdbcTemplate.queryForObject(sb.toString(), params.toArray(), Integer.class);
|
|
|
return patients;
|
|
|
}
|
|
|
}
|