|
@ -1,28 +1,21 @@
|
|
|
package com.yihu.hos.device.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.hos.device.common.configuration.HealthStandardConfig;
|
|
|
import com.yihu.hos.device.common.configuration.SystemConfig;
|
|
|
import com.yihu.hos.device.common.dao.*;
|
|
|
import com.yihu.hos.device.common.http.HttpClientUtil;
|
|
|
import com.yihu.hos.device.common.http.HttpHelper;
|
|
|
import com.yihu.hos.device.common.http.HttpResponse;
|
|
|
import com.yihu.hos.device.common.util.*;
|
|
|
import com.yihu.hos.device.common.util.DateUtil;
|
|
|
import com.yihu.hos.device.common.util.ETLConstantData;
|
|
|
import com.yihu.hos.device.common.util.StringUtil;
|
|
|
import com.yihu.hos.device.model.*;
|
|
|
import com.yihu.hos.device.task.PushMsgTask;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
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.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
@ -40,54 +33,26 @@ public class DeviceService extends BaseService{
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
@Autowired
|
|
|
private DeviceDetailDao deviceDetailDao;
|
|
|
// @Autowired
|
|
|
// private PatientHealthIndexDao patientHealthIndexDao;
|
|
|
/*@Autowired
|
|
|
private BloodSuggerConfiguration bloodSuggerConfiguration;*/
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private PatientHealthStandardDao patientHealthStandardDao;
|
|
|
@Autowired
|
|
|
private SignFamilyDao signFamilyDao;
|
|
|
@Autowired
|
|
|
private MessageDao messageDao;
|
|
|
@Autowired
|
|
|
private HealthStandardConfig healthStandardConfig;
|
|
|
@Autowired
|
|
|
private HttpHelper httpHelper;
|
|
|
@Autowired
|
|
|
private HttpClientUtil HttpClientUtil;
|
|
|
@Autowired
|
|
|
private SystemConfig systemConfig;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private PatientBloodSuggerDao patientBloodSuggerDao;
|
|
|
@Autowired
|
|
|
private PatientHealthTimeDao patientHealthTimeDao;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private ConsultTeamDao consultTeamDao;
|
|
|
@Autowired
|
|
|
private ImUtill ImUtill;
|
|
|
@Autowired
|
|
|
private MessageService messageService;
|
|
|
@Autowired
|
|
|
private DoctorSwitchDao doctorSwitchDao;
|
|
|
@Autowired
|
|
|
private TrackPatientDao trackPatientDao;
|
|
|
@Value("${systemConfig.server_url}")
|
|
|
private String wlyyService;
|
|
|
@Autowired
|
|
|
private PatientAimBloodSuggerDao patientAimBloodSuggerDao;
|
|
|
@Autowired
|
|
|
private PatientAimBloodPressureDao patientAimBloodPressureDao;
|
|
|
@Autowired
|
|
|
private IotDeviceService iotDeviceService;
|
|
|
@Autowired
|
|
|
private SystemDictDao systemDictDao;
|
|
|
private AsyncService asyncService;
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(DeviceService.class);
|
|
|
private ObjectMapper objectMapper = new ObjectMapper();
|
|
@ -188,17 +153,7 @@ public class DeviceService extends BaseService{
|
|
|
return "1";//"空腹血糖"
|
|
|
}
|
|
|
|
|
|
/* private Boolean isInArea(String time, String[] timeArea) {
|
|
|
String date = DateUtil.getDateFromDateTime(time);
|
|
|
Long beginTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[0] + ":00"));
|
|
|
Long endTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[1] + ":00"));
|
|
|
if (beginTime > 0 && endTime < 0) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}*/
|
|
|
// 判断时间是否在对应时间段
|
|
|
// 判断时间是否在对应时间段
|
|
|
private Boolean isInArea(String time,String begin,String end) {
|
|
|
String date = DateUtil.getDateFromDateTime(time);
|
|
|
Long beginTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + begin ));
|
|
@ -210,26 +165,17 @@ public class DeviceService extends BaseService{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断当前指标是否正常
|
|
|
*/
|
|
|
private boolean checkHealthIndex(Double current, Double max, Double min) {
|
|
|
if (current > max || current < min || current < 0) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
/**
|
|
|
* 判断当前指标偏高或偏低
|
|
|
*/
|
|
|
private int checkHealthIndexDetail(Double current, Double max, Double min) {
|
|
|
if (current > max ) {
|
|
|
return 1;
|
|
|
}else if(current < min || current < 0){
|
|
|
return 2;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
/* private Boolean isInArea(String time, String[] timeArea) {
|
|
|
String date = DateUtil.getDateFromDateTime(time);
|
|
|
Long beginTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[0] + ":00"));
|
|
|
Long endTime = DateUtil.compareDateTime(DateUtil.toTimestamp(time), DateUtil.toTimestamp(date + " " + timeArea[1] + ":00"));
|
|
|
if (beginTime > 0 && endTime < 0) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
/**************************************************************************************************************/
|
|
|
/**
|
|
|
* 设备数据查询接口
|
|
@ -336,11 +282,11 @@ public class DeviceService extends BaseService{
|
|
|
|
|
|
//血糖、血压数据需校验,如果超标,需要发送消息给医生
|
|
|
if (paramMap.get("type").equals("1") || paramMap.get("type").equals("2")) {
|
|
|
verifyHealthIndex(result);
|
|
|
asyncService.verifyHealthIndex(result);
|
|
|
}
|
|
|
|
|
|
//指标数据上传基卫
|
|
|
uploadHealthIndex(result);
|
|
|
asyncService.uploadHealthIndex(result);
|
|
|
|
|
|
System.out.println(result);
|
|
|
} catch (Exception e) {
|
|
@ -410,18 +356,16 @@ public class DeviceService extends BaseService{
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
|
|
|
//血糖、血压数据需校验,如果超标,需要发送消息给医生
|
|
|
verifyHealthIndex(result);
|
|
|
asyncService.verifyHealthIndex(result);
|
|
|
//发送华三demo推送
|
|
|
|
|
|
//判断是否有未结束的续方咨询,发送消息给对应的医生----huangwenjie--2017.11.06
|
|
|
sendPrescriptionHealthIndexMsgresult(result,patient);
|
|
|
asyncService.sendPrescriptionHealthIndexMsgresult(result,patient);
|
|
|
|
|
|
//指标数据上传基卫
|
|
|
uploadHealthIndex(result);
|
|
|
asyncService.uploadHealthIndex(result);
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
|
yujing(patientCode,patient);
|
|
|
asyncService.yujing(patientCode,patient);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@ -475,101 +419,31 @@ public class DeviceService extends BaseService{
|
|
|
userType = "-1";
|
|
|
}
|
|
|
|
|
|
int dataUoloadCount = 0;
|
|
|
try {
|
|
|
PatientDevice patientDevice = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(deviceSn,type,userType);
|
|
|
if (patientDevice!=null){
|
|
|
String today = DateUtil.getStringDateShort();
|
|
|
String startTime = today+" 00:00:00";
|
|
|
String endTime = today+" 23:59:59";
|
|
|
int dateType =1;
|
|
|
if (deviceType==1){
|
|
|
dateType=2;
|
|
|
}else if (deviceType==2){
|
|
|
dateType=1;
|
|
|
}
|
|
|
String countSql = "SELECT count(*) num FROM device.wlyy_patient_health_index where `user`='"+patientDevice.getUser()+"' and type = "+dateType+" AND record_date >'"+startTime+"' and record_date <= '"+endTime+"'";
|
|
|
Map<String,Object> countMap = jdbcTemplate.queryForMap(countSql);
|
|
|
dataUoloadCount = Integer.valueOf(String.valueOf(countMap.get("num")));
|
|
|
}else {
|
|
|
throw new Exception("This device is not relate patient!");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
|
PatientHealthIndex result = savePatientDeviceData(deviceSn, type, data, uploadTime, userType, json);
|
|
|
if (result == null) {
|
|
|
throw new Exception("This device is not relate patient!");
|
|
|
} else {
|
|
|
//患者信息
|
|
|
String patientCode = result.getUser();
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
String hospital = "";
|
|
|
if (signFamily!=null){
|
|
|
hospital = signFamily.getHospital();
|
|
|
}
|
|
|
String flagStr = "";
|
|
|
if (deviceType==1){
|
|
|
flagStr="BP_MEASURE";
|
|
|
}else if (deviceType==2){
|
|
|
flagStr="GLU_MEASURE";
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
//增加积分
|
|
|
if (dataUoloadCount == 0 && "350205".equals(hospital.substring(0,6))){
|
|
|
String sql = "select count(*) num from device.wlyy_devices where device_code = '"+deviceSn+"'";
|
|
|
Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
|
|
|
if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
|
|
|
|
|
|
String url = wlyyService + "healthBank/insertCredits";
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"ACTIVITY_TASK\",\"flag\":\""+flagStr+"\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\"350205\"}"));
|
|
|
String response = HttpClientUtil.post(url, params, "UTF-8");
|
|
|
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
|
|
|
String status = jsonObject.getString("status");
|
|
|
if (!"200".equals(status)){
|
|
|
logger.error(jsonObject.getString("msg"));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//增加活跃度
|
|
|
if (dataUoloadCount == 0){
|
|
|
String url = wlyyService + "healthBank/createActiveRecord";
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("activeRecord", "{\"taskCode\":\""+flagStr+"\",\"patientId\":\""+result.getUser()+"\"}"));
|
|
|
String response = HttpClientUtil.post(url, params, "UTF-8");
|
|
|
if (StringUtils.isNotEmpty(response)){
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(response);
|
|
|
if (!"200".equals(jsonObject.getString("status"))){
|
|
|
logger.info("添加活跃度失败!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
|
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
asyncService.addIntegral(deviceSn,type,userType,patientCode,deviceType);
|
|
|
//血糖、血压数据需校验,如果超标,需要发送消息给医生
|
|
|
if (1 == deviceType || 2 == deviceType) {
|
|
|
verifyHealthIndex(result);
|
|
|
asyncService.verifyHealthIndex(result);
|
|
|
//发送华三demo推送
|
|
|
// messagePush(result);
|
|
|
|
|
|
//判断是否有未结束的续方咨询,发送消息给对应的医生----huangwenjie--2017.11.06
|
|
|
sendPrescriptionHealthIndexMsgresult(result,patient);
|
|
|
asyncService.sendPrescriptionHealthIndexMsgresult(result,patient);
|
|
|
}
|
|
|
|
|
|
//指标数据上传基卫
|
|
|
uploadHealthIndex(result);
|
|
|
asyncService.uploadHealthIndex(result);
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
|
yujing(patientCode,patient);
|
|
|
asyncService.yujing(patientCode,patient);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@ -579,269 +453,6 @@ public class DeviceService extends BaseService{
|
|
|
return Result.success("Device data incoming success");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 预警
|
|
|
* @param patientCode
|
|
|
* @param patient
|
|
|
*/
|
|
|
public void yujing(String patientCode,Patient patient){
|
|
|
try{
|
|
|
String patientsql = "select group_concat(label) disease from wlyy.wlyy_sign_patient_label_info where label_type = 3 and status=1 and (label = 1 or label = 2) and patient = '"+patient.getCode()+"' GROUP BY patient";
|
|
|
|
|
|
String patientdisease = jdbcTemplate.queryForObject(patientsql,String.class);
|
|
|
|
|
|
//连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
|
|
|
|
|
|
int bloodPressureBbnormalCount = 0;//血压异常次数
|
|
|
int bloodSuggurBbnormalCount = 0;//血糖异常次数
|
|
|
int stdbloodPressureBbnormalCount = 0;//血压次数
|
|
|
int stdbloodSuggurBbnormalCount = 0;//血糖次数
|
|
|
|
|
|
List<PatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
|
|
|
List<PatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
|
|
|
|
|
|
// bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,2);
|
|
|
// bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,1);
|
|
|
bloodPressurepatientHealthIndices = iotDeviceService.findByPatientAndTypeByPage(patientCode,2);
|
|
|
bloodSuggurpatientHealthIndices = iotDeviceService.findByPatientAndTypeByPage(patientCode,1);
|
|
|
|
|
|
if(!bloodPressurepatientHealthIndices.isEmpty()){
|
|
|
stdbloodPressureBbnormalCount = bloodPressurepatientHealthIndices.size();
|
|
|
}
|
|
|
|
|
|
if(!bloodSuggurpatientHealthIndices.isEmpty()){
|
|
|
stdbloodSuggurBbnormalCount = bloodSuggurpatientHealthIndices.size();
|
|
|
}
|
|
|
|
|
|
for (PatientHealthIndex index1 : bloodPressurepatientHealthIndices) {
|
|
|
if(index1.getStatus() != null && 1 == index1.getStatus()){
|
|
|
bloodPressureBbnormalCount++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (PatientHealthIndex index2 : bloodSuggurpatientHealthIndices) {
|
|
|
if(index2.getStatus() != null && 1 == index2.getStatus()){
|
|
|
bloodSuggurBbnormalCount++;
|
|
|
}
|
|
|
}
|
|
|
//连续3次异常,修改用户为预警状态
|
|
|
if( (bloodPressureBbnormalCount >=3 || bloodSuggurBbnormalCount >=3)){
|
|
|
patient.setStandardStatus(1);
|
|
|
//1.4.2加入重点关注逻辑
|
|
|
setTrackPatientByDoctor(patientCode);
|
|
|
}else{
|
|
|
Date end = new Date();
|
|
|
Date start = DateUtil.setDateTime(end,-7);
|
|
|
//计算血糖或者血压一周内的异常记录数量
|
|
|
// int errorCount = patientHealthIndexDao.getCountByTimeAndStatus(start,end,1,patientCode);
|
|
|
int errorCount = iotDeviceService.getCountByTimeAndStatus(start,end,1,patientCode);
|
|
|
if(errorCount >= 5){//超过5次,记为预警状态
|
|
|
patient.setStandardStatus(1);
|
|
|
//1.4.2加入重点关注逻辑
|
|
|
setTrackPatientByDoctor(patientCode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//连续5次正常,修改用户为非预警状态
|
|
|
if(StringUtils.isNotBlank(patientdisease)){
|
|
|
if("1".equals(patientdisease)){
|
|
|
if(stdbloodPressureBbnormalCount==5&&0 == bloodPressureBbnormalCount){
|
|
|
patient.setStandardStatus(0);
|
|
|
//1.4.2加入重点关注逻辑
|
|
|
cancalTrackPatientByDoctor(patientCode);
|
|
|
}
|
|
|
}else if("2".equals(patientdisease)){
|
|
|
if(stdbloodSuggurBbnormalCount==5&&0 == bloodSuggurBbnormalCount){
|
|
|
patient.setStandardStatus(0);
|
|
|
//1.4.2加入重点关注逻辑
|
|
|
cancalTrackPatientByDoctor(patientCode);
|
|
|
}
|
|
|
}else if( "1,2".equals(patientdisease) || "2,1".equals(patientdisease)){
|
|
|
if(stdbloodSuggurBbnormalCount==5&&stdbloodPressureBbnormalCount==5&&0 == bloodSuggurBbnormalCount && 0 == bloodPressureBbnormalCount){
|
|
|
patient.setStandardStatus(0);
|
|
|
//1.4.2加入重点关注逻辑
|
|
|
cancalTrackPatientByDoctor(patientCode);
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
patient.setStandardStatus(0);
|
|
|
//1.4.2加入重点关注逻辑
|
|
|
cancalTrackPatientByDoctor(patientCode);
|
|
|
}
|
|
|
|
|
|
patientDao.save(patient);
|
|
|
//连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置默认监控方案
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public String setDefaultAim(String patient){
|
|
|
PatientAimBloodSugger patientAimBloodSugger = patientAimBloodSuggerDao.findByPatientcode(patient);
|
|
|
PatientAimBloodPressure patientAimBloodPressure = patientAimBloodPressureDao.findByPatientcode(patient);
|
|
|
if(patientAimBloodSugger==null){
|
|
|
PatientAimBloodSugger pa = new PatientAimBloodSugger();
|
|
|
pa.setPatientcode(patient);
|
|
|
pa.setCode(getCode());
|
|
|
pa.setCreateTime(new Date());
|
|
|
pa.setUnit("mmol/L");
|
|
|
pa.setFbg("7.0");
|
|
|
pa.setHpg("11.1");
|
|
|
pa.setFbgMin("4.0");
|
|
|
pa.setHpgMin("4.0");
|
|
|
patientAimBloodSuggerDao.save(pa);
|
|
|
}
|
|
|
if(patientAimBloodPressure==null){
|
|
|
PatientAimBloodPressure pa = new PatientAimBloodPressure();
|
|
|
pa.setPatientcode(patient);
|
|
|
pa.setCode(getCode());
|
|
|
pa.setCreateTime(new Date());
|
|
|
pa.setSbp("140");
|
|
|
pa.setSbpMin("90");
|
|
|
pa.setDbp("90");
|
|
|
pa.setDbpMin("60");
|
|
|
pa.setUnit("mmHg");
|
|
|
patientAimBloodPressureDao.save(pa);
|
|
|
}
|
|
|
return "1";
|
|
|
}
|
|
|
/**
|
|
|
* 设置
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public int setTrackPatientByDoctor(String patient){
|
|
|
SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
|
|
|
if(signFamily==null){
|
|
|
return -1;
|
|
|
}
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
if(p==null){
|
|
|
return -1;
|
|
|
}
|
|
|
//医生是否自动追踪居民
|
|
|
DoctorSwitch sw = doctorSwitchDao.findByDoctor(signFamily.getDoctor());
|
|
|
DoctorSwitch swh = doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
|
|
|
|
|
|
if(sw!=null){
|
|
|
if("1".equals(sw.getAlertPatientSwitch())){
|
|
|
//查询是否与医生建立重点跟踪关系,诺无关系则建立
|
|
|
TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),patient);
|
|
|
|
|
|
if(trackPatient == null){
|
|
|
TrackPatient t = new TrackPatient();
|
|
|
t.setCreateTime(new Date());
|
|
|
t.setDoctorCode(signFamily.getDoctor());
|
|
|
t.setDoctorName(signFamily.getDoctorName());
|
|
|
t.setIdcard(signFamily.getIdcard());
|
|
|
t.setSsc(signFamily.getSsc());
|
|
|
t.setTeamCode(signFamily.getAdminTeamId().intValue());
|
|
|
t.setPatientCode(patient);
|
|
|
t.setPatientName(p.getName());
|
|
|
t.setDel("1");
|
|
|
trackPatientDao.save(t);
|
|
|
}else{
|
|
|
trackPatient.setDel("1");
|
|
|
trackPatientDao.save(trackPatient);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(swh!=null){
|
|
|
if("1".equals(swh.getAlertPatientSwitch())){
|
|
|
//查询是否与医生建立重点跟踪关系,诺无关系则建立
|
|
|
TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),patient);
|
|
|
if(trackPatient == null){
|
|
|
TrackPatient t = new TrackPatient();
|
|
|
t.setCreateTime(new Date());
|
|
|
t.setDoctorCode(signFamily.getDoctorHealth());
|
|
|
t.setDoctorName(signFamily.getDoctorHealthName());
|
|
|
t.setIdcard(signFamily.getIdcard());
|
|
|
t.setSsc(signFamily.getSsc());
|
|
|
t.setTeamCode(signFamily.getAdminTeamId().intValue());
|
|
|
t.setPatientCode(patient);
|
|
|
t.setPatientName(p.getName());
|
|
|
t.setDel("1");
|
|
|
trackPatientDao.save(t);
|
|
|
}else{
|
|
|
trackPatient.setDel("1");
|
|
|
trackPatientDao.save(trackPatient);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
public int cancalTrackPatientByDoctor(String patient){
|
|
|
SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
|
|
|
if(signFamily==null){
|
|
|
return -1;
|
|
|
}
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
if(p==null){
|
|
|
return -1;
|
|
|
}
|
|
|
//医生是否自动追踪居民
|
|
|
DoctorSwitch sw = doctorSwitchDao.findByDoctor(signFamily.getDoctor());
|
|
|
DoctorSwitch swh = doctorSwitchDao.findByDoctor(signFamily.getDoctorHealth());
|
|
|
|
|
|
if(sw!=null){
|
|
|
if("1".equals(sw.getAlertPatientSwitch())){
|
|
|
//查询是否与医生建立重点跟踪关系,诺无关系则建立
|
|
|
TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctor(),patient);
|
|
|
|
|
|
if(trackPatient == null){
|
|
|
TrackPatient t = new TrackPatient();
|
|
|
t.setCreateTime(new Date());
|
|
|
t.setDoctorCode(signFamily.getDoctor());
|
|
|
t.setDoctorName(signFamily.getDoctorName());
|
|
|
t.setIdcard(signFamily.getIdcard());
|
|
|
t.setSsc(signFamily.getSsc());
|
|
|
t.setTeamCode(signFamily.getAdminTeamId().intValue());
|
|
|
t.setPatientCode(patient);
|
|
|
t.setPatientName(p.getName());
|
|
|
t.setDel("0");
|
|
|
trackPatientDao.save(t);
|
|
|
//设置默认控制目标
|
|
|
setDefaultAim(patient);
|
|
|
}else{
|
|
|
trackPatient.setDel("0");
|
|
|
trackPatientDao.save(trackPatient);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(swh!=null){
|
|
|
if("1".equals(swh.getAlertPatientSwitch())){
|
|
|
//查询是否与医生建立重点跟踪关系,诺无关系则建立
|
|
|
TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(signFamily.getDoctorHealth(),patient);
|
|
|
if(trackPatient == null){
|
|
|
TrackPatient t = new TrackPatient();
|
|
|
t.setCreateTime(new Date());
|
|
|
t.setDoctorCode(signFamily.getDoctorHealth());
|
|
|
t.setDoctorName(signFamily.getDoctorHealthName());
|
|
|
t.setIdcard(signFamily.getIdcard());
|
|
|
t.setSsc(signFamily.getSsc());
|
|
|
t.setTeamCode(signFamily.getAdminTeamId().intValue());
|
|
|
t.setPatientCode(patient);
|
|
|
t.setPatientName(p.getName());
|
|
|
t.setDel("0");
|
|
|
trackPatientDao.save(t);
|
|
|
//设置默认控制目标
|
|
|
setDefaultAim(patient);
|
|
|
}else{
|
|
|
trackPatient.setDel("0");
|
|
|
trackPatientDao.save(trackPatient);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
/**
|
|
|
* 保存设备数据
|
|
|
*/
|
|
@ -1014,195 +625,7 @@ public class DeviceService extends BaseService{
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验指标是否超标,发送消息
|
|
|
*/
|
|
|
private void verifyHealthIndex(PatientHealthIndex data) {
|
|
|
//指标信息
|
|
|
String patientCode = data.getUser();
|
|
|
//患者信息
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
|
|
|
int type = data.getType();
|
|
|
String msgContent = "";
|
|
|
//血糖校验
|
|
|
if (type == 1) {
|
|
|
// 血糖记录,查询患者血糖预警值
|
|
|
PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 1);
|
|
|
Double maxValueBefore = healthStandardConfig.getXt_max_before();
|
|
|
Double minValueBefore = healthStandardConfig.getXt_min_before();
|
|
|
Double maxValueAfter = healthStandardConfig.getXt_max_after();
|
|
|
Double minValueAfter = healthStandardConfig.getXt_min_after();
|
|
|
if (standard != null) {
|
|
|
if (standard.getMaxValue1() > 0) {
|
|
|
maxValueBefore = standard.getMaxValue1();
|
|
|
}
|
|
|
if (standard.getMinValue1() > 0) {
|
|
|
minValueBefore = standard.getMinValue1();
|
|
|
}
|
|
|
if (standard.getMaxValue2() > 0) {
|
|
|
maxValueAfter = standard.getMaxValue2();
|
|
|
}
|
|
|
if (standard.getMinValue2() > 0) {
|
|
|
minValueAfter = standard.getMinValue2();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int index = Integer.valueOf(data.getValue2());
|
|
|
String value1 = data.getValue1();
|
|
|
// 餐后
|
|
|
if (index % 2 == 0) {
|
|
|
if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter )) {
|
|
|
// msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
|
|
|
if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
|
|
|
msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
|
|
|
}else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
|
|
|
msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
|
|
|
}
|
|
|
//体征异常,更新体征数据状态
|
|
|
// data.setStatus(1);
|
|
|
// patientHealthIndexDao.save(data);
|
|
|
iotDeviceService.updateStatus(data);
|
|
|
}
|
|
|
} else { //餐前
|
|
|
if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
|
|
|
// msgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L),请处理";
|
|
|
if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==1){
|
|
|
msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
|
|
|
}else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueAfter ,minValueAfter)==2){
|
|
|
msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
|
|
|
}
|
|
|
//体征异常,更新体征数据状态
|
|
|
// data.setStatus(1);
|
|
|
// patientHealthIndexDao.save(data);
|
|
|
iotDeviceService.updateStatus(data);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//血压校验
|
|
|
else if (type == 2) {
|
|
|
String value1 = data.getValue1();
|
|
|
String value2 = data.getValue2();
|
|
|
// 血压记录,查询患者血压预警值
|
|
|
PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 2);
|
|
|
Double maxValueSSY = healthStandardConfig.getSsy_max();
|
|
|
Double minValueSSY = healthStandardConfig.getSsy_min();
|
|
|
Double maxValueSZY = healthStandardConfig.getSzy_max();
|
|
|
Double minValueSZY = healthStandardConfig.getSzy_min();
|
|
|
if (standard != null) {
|
|
|
if (standard.getMaxValue1() > 0) {
|
|
|
maxValueSSY = standard.getMaxValue1();
|
|
|
}
|
|
|
if (standard.getMinValue1() > 0) {
|
|
|
minValueSSY = standard.getMinValue1();
|
|
|
}
|
|
|
if (standard.getMaxValue2() > 0) {
|
|
|
maxValueSZY = standard.getMaxValue2();
|
|
|
}
|
|
|
if (standard.getMinValue2() > 0) {
|
|
|
minValueSZY = standard.getMinValue2();
|
|
|
}
|
|
|
}
|
|
|
// 收缩压/舒张压校验
|
|
|
if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY) || !checkHealthIndex(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)) {
|
|
|
// msgContent = patient.getName() + "血压异常(舒张压 " + value2 + "mmHg、收缩压 " + value1 + "mmHg),请处理";
|
|
|
if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==1||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==1){
|
|
|
msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏高</span>";
|
|
|
}else if(checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueSSY, minValueSSY)==2||checkHealthIndexDetail(NumberUtils.toDouble(value2), maxValueSZY, minValueSZY)==2){
|
|
|
msgContent = "<a>"+patient.getName()+"</a><span style=\"color: #FF4C4C;\">血压偏低</span>";
|
|
|
}
|
|
|
//体征异常,更新体征数据状态
|
|
|
// data.setStatus(1);
|
|
|
// patientHealthIndexDao.save(data);
|
|
|
iotDeviceService.updateStatus(data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//超标则发送消息
|
|
|
if (msgContent != null && msgContent.length() > 0) {
|
|
|
sendMessage(msgContent, patient, data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 推送信息
|
|
|
*/
|
|
|
private void sendMessage(String content, Patient patient, PatientHealthIndex model) {
|
|
|
String patientCode = patient.getCode();
|
|
|
// 消息接收者
|
|
|
List<String> receivers = new ArrayList<String>();
|
|
|
// 查询病人家庭签约的健康管理师
|
|
|
SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patientCode);
|
|
|
String healthDoctorFamily = "";
|
|
|
String doctorFamily = "";
|
|
|
if (signFamily != null) {
|
|
|
healthDoctorFamily = signFamily.getDoctorHealth();
|
|
|
doctorFamily = signFamily.getDoctor();
|
|
|
if (StringUtils.isNotEmpty(healthDoctorFamily)) {
|
|
|
// 添加到消息接收人列表
|
|
|
receivers.add(healthDoctorFamily);
|
|
|
} else if (StringUtils.isNotEmpty(doctorFamily)){
|
|
|
// 添加到消息接收人列表
|
|
|
receivers.add(doctorFamily);
|
|
|
}
|
|
|
}
|
|
|
// 查询病人三师签约中的健康管理师
|
|
|
SignFamily signFamilySS = signFamilyDao.findBySanshiPatientYes(patientCode);
|
|
|
if (signFamilySS != null) {
|
|
|
String healthDoctorTeam = signFamilySS.getDoctorHealth();
|
|
|
// 判断是否是否是同一个健康管理师
|
|
|
if (StringUtils.isNotEmpty(healthDoctorTeam) && !StringUtils.equals(healthDoctorFamily, healthDoctorTeam)) {
|
|
|
// 添加到消息接收人列表
|
|
|
receivers.add(healthDoctorTeam);
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(signFamilySS.getDoctor())){
|
|
|
receivers.add(signFamilySS.getDoctor());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<Message> messages = new ArrayList<Message>();
|
|
|
JSONArray array = new JSONArray();
|
|
|
for (String receiver : receivers) {
|
|
|
if (StringUtils.isEmpty(receiver)) {
|
|
|
continue;
|
|
|
}
|
|
|
// 保存异常消息
|
|
|
Message message = new Message();
|
|
|
message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
message.setCzrq(new Date());
|
|
|
message.setCreateTime(new Date());
|
|
|
message.setRead(1);
|
|
|
message.setOver("1");
|
|
|
message.setReceiver(receiver);
|
|
|
message.setSender(patientCode);
|
|
|
message.setSex(patient.getSex());
|
|
|
message.setSenderName(patient.getName());
|
|
|
message.setSenderPhoto(patient.getPhoto());
|
|
|
message.setTitle("预警值信息");
|
|
|
message.setContent(content);
|
|
|
message.setType(2);
|
|
|
message.setValue1(Double.valueOf(model.getValue1()));
|
|
|
message.setValue2(Double.valueOf(model.getValue2()));
|
|
|
message.setTzCode(String.valueOf(model.getId()));//消息关联的体征id
|
|
|
message.setTzType(String.valueOf(model.getType()));//体征类别 (1血糖,2血压,3体重,4腰围)
|
|
|
messages.add(message);
|
|
|
|
|
|
if(messageService.getMessageNoticeSettingByMessageType(receiver,"1",MessageNoticeSetting.MessageTypeEnum.healthSignSwitch.getValue())){
|
|
|
// 异常通知
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("receiver", receiver);
|
|
|
json.put("type", MessageType.MESSAGE_TYPE_DOCTOR_HEALTH_INDEX.D_HI_01.name());
|
|
|
json.put("title", MessageType.MESSAGE_TYPE_DOCTOR_HEALTH_INDEX.体征指标.name());
|
|
|
json.put("msg", content);
|
|
|
json.put("data", "");
|
|
|
array.add(json);
|
|
|
}
|
|
|
}
|
|
|
// 批量保存消息
|
|
|
messageDao.save(messages);
|
|
|
// 推送消息给医生
|
|
|
pushMsgTask.put(array);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 华三demo数据推送
|
|
@ -1268,61 +691,6 @@ public class DeviceService extends BaseService{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 指标数据上传基卫
|
|
|
*/
|
|
|
private void uploadHealthIndex(PatientHealthIndex data) {
|
|
|
try {
|
|
|
String url = systemConfig.getJwServer() + "/third/archives/uploadHealthIndex";
|
|
|
|
|
|
Map<String, Object> params = new HashedMap();
|
|
|
params.put("id", data.getId());
|
|
|
|
|
|
HttpResponse response = httpHelper.post(url, params);
|
|
|
|
|
|
if (response != null && response.getStatusCode() == 200) {
|
|
|
JSONObject json = JSONObject.fromObject(response.getBody());
|
|
|
if (!"200".equals(json.optString("status"))) {
|
|
|
throw new Exception(json.optString("msg"));
|
|
|
}
|
|
|
} else {
|
|
|
throw new Exception("接口调用错误!" + response.getBody());
|
|
|
}
|
|
|
} catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断是否有未结束的续方咨询,发送消息给对应的医生
|
|
|
* @param result
|
|
|
* @param patient
|
|
|
*/
|
|
|
private void sendPrescriptionHealthIndexMsgresult(PatientHealthIndex result, Patient patient) {
|
|
|
List<ConsultTeam> consultTeams = consultTeamDao.findUnfinishedConsult(patient.getCode());
|
|
|
|
|
|
for (ConsultTeam consultTeam:consultTeams) {
|
|
|
if(consultTeam.getHealthindexType() != null){
|
|
|
org.json.JSONObject contentPatient = new org.json.JSONObject();
|
|
|
//患者发送的消息
|
|
|
contentPatient.put("title", "【本消息为系统提醒】:");
|
|
|
if(1 == result.getType()){
|
|
|
contentPatient.put("tzMsg", "体征记录:血糖 "+result.getValue1()+" mmol/L");
|
|
|
contentPatient.put("type",2);
|
|
|
}else if(2 == result.getType()){
|
|
|
contentPatient.put("tzMsg", "体征记录:血压 "+result.getValue1()+"/"+result.getValue2()+" mmHg");
|
|
|
contentPatient.put("type",1);
|
|
|
}else{}
|
|
|
|
|
|
contentPatient.put("tzTime", "检测时间:"+DateUtil.dateToStrLong(result.getRecordDate()));
|
|
|
contentPatient.put("tzAlert","温馨提示:本条体征为居民上传的健康体征数据,您可以");
|
|
|
contentPatient.put("needUpload","false");
|
|
|
contentPatient.put("healthindexid",result.getId());//体征记录 ID
|
|
|
|
|
|
//患者发送Im消息
|
|
|
ImUtill.sendTopicIM(patient.getCode(), patient.getName(), consultTeam.getConsult(), "16", contentPatient.toString(), null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|