|
@ -1,2452 +0,0 @@
|
|
|
package com.yihu.jw.health.service;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.device.dao.*;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.device.DoctorHealthStandard;
|
|
|
import com.yihu.jw.entity.base.device.PatientAimBloodPressure;
|
|
|
import com.yihu.jw.entity.base.device.PatientAimBloodSugger;
|
|
|
import com.yihu.jw.entity.base.device.PatientHealthStandard;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientHealthIndex;
|
|
|
import com.yihu.jw.entity.door.SignFamily;
|
|
|
import com.yihu.jw.entity.scheme.DoctorSwitch;
|
|
|
import com.yihu.jw.entity.scheme.TrackPatient;
|
|
|
import com.yihu.jw.entity.util.TransforSqlUtl;
|
|
|
import com.yihu.jw.iot.IotDeviceService;
|
|
|
import com.yihu.jw.message.dao.MessageDao;
|
|
|
import com.yihu.jw.message.service.MessageService;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.conf.SystemConf;
|
|
|
import com.yihu.jw.scheme.DoctorSwitchDao;
|
|
|
import com.yihu.jw.scheme.TrackPatientDao;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.utils.HttpClientUtil;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
|
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.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
//import org.springside.modules.utils.Clock;
|
|
|
|
|
|
@Component
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public class PatientHealthIndexService {
|
|
|
private Logger logger = LoggerFactory.getLogger(PatientHealthIndexService.class);
|
|
|
// private Clock clock = Clock.DEFAULT;
|
|
|
//
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
@Autowired
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private DevicePatientHealthIndexDao patientHealthIndexDao;
|
|
|
@Autowired
|
|
|
private PatientHealthStandardDao patientHealthStandardDao;
|
|
|
@Autowired
|
|
|
private MessageDao messageDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
|
|
|
@Autowired
|
|
|
private com.yihu.jw.util.common.CommonUtil CommonUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private PatientAimSportsDao patientAimSportsDao;
|
|
|
@Autowired
|
|
|
private DoctorHealthStandardDao doctorHealthStandardDao;
|
|
|
|
|
|
// @Value("${doctorAssistant.api}")
|
|
|
private String doctorAssistant;
|
|
|
// @Value("${doctorAssistant.target_url}")
|
|
|
private String targetUrl;
|
|
|
|
|
|
|
|
|
// @Autowired
|
|
|
// private HttpClientUtil httpClientUtil;
|
|
|
// @Autowired
|
|
|
// private ImUtill ImUtill;
|
|
|
|
|
|
@Autowired
|
|
|
private MessageService messageService;
|
|
|
@Autowired
|
|
|
private DoctorSwitchDao doctorSwitchDao;
|
|
|
@Autowired
|
|
|
private TrackPatientDao trackPatientDao;
|
|
|
|
|
|
@Autowired
|
|
|
private PatientAimBloodSuggerDao patientAimBloodSuggerDao;
|
|
|
@Autowired
|
|
|
private PatientAimBloodPressureDao patientAimBloodPressureDao;
|
|
|
@Autowired
|
|
|
private DeviceDetailDao deviceDetailDao;
|
|
|
|
|
|
@Autowired
|
|
|
private IotDeviceService iotDeviceService;
|
|
|
|
|
|
// @Autowired
|
|
|
// private WlyyIotTzDictDao wlyyIotTzDictDao;
|
|
|
// @Autowired
|
|
|
// private SqlReplaceService sqlReplaceService;
|
|
|
|
|
|
// @Autowired
|
|
|
// private PushMsgTask pushMsgTask;
|
|
|
// @Autowired
|
|
|
// private SignFamilyDao signFamilyDao;
|
|
|
// @Autowired
|
|
|
// private DoctorWorkTimeService doctorWorkTimeService;
|
|
|
// @Autowired
|
|
|
// private ConsultTeamDao consultTeamDao;
|
|
|
|
|
|
/**
|
|
|
* 获取居民标准预警值
|
|
|
*
|
|
|
* @param type
|
|
|
* @param patientCode
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getealthStandard(Integer type, String patientCode) {
|
|
|
//血糖校验
|
|
|
JSONObject json = new JSONObject();
|
|
|
if (type == 1) {
|
|
|
// 血糖记录,查询患者血糖预警值
|
|
|
PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 1);
|
|
|
Double maxValueBefore = SystemConf.HEALTH_STANDARD_ST_MAX_BEFORE;
|
|
|
Double minValueBefore = SystemConf.HEALTH_STANDARD_ST_MIN_BEFORE;
|
|
|
Double maxValueAfter = SystemConf.HEALTH_STANDARD_ST_MAX_AFTER;
|
|
|
Double minValueAfter = SystemConf.HEALTH_STANDARD_ST_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();
|
|
|
}
|
|
|
}
|
|
|
json.put("maxValueAfter", maxValueAfter);
|
|
|
json.put("maxValueBefore", maxValueBefore);
|
|
|
json.put("minValueBefore", minValueBefore);
|
|
|
json.put("minValueAfter", minValueAfter);
|
|
|
}
|
|
|
//血压校验
|
|
|
else if (type == 2) {
|
|
|
// 血压记录,查询患者血压预警值
|
|
|
PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 2);
|
|
|
Double maxValueSSY = SystemConf.HEALTH_STANDARD_SSY_MAX;
|
|
|
Double minValueSSY = SystemConf.HEALTH_STANDARD_SSY_MIN;
|
|
|
Double maxValueSZY = SystemConf.HEALTH_STANDARD_SZY_MAX;
|
|
|
Double minValueSZY = SystemConf.HEALTH_STANDARD_SZY_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();
|
|
|
}
|
|
|
}
|
|
|
json.put("minValueSZY", minValueSZY);
|
|
|
json.put("maxValueSZY", maxValueSZY);
|
|
|
json.put("minValueSSY", minValueSSY);
|
|
|
json.put("maxValueSSY", maxValueSSY);
|
|
|
|
|
|
}
|
|
|
return json;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//更改接口(包括手动记录的修改和所有的删除)
|
|
|
// public void modify(long id, String recordDate, String value1, String value2, String value3, String value4) throws Exception {
|
|
|
//
|
|
|
// DevicePatientHealthIndex result = findOne(id);
|
|
|
// if (result != null) {
|
|
|
// //字段值均为空为删除
|
|
|
// if (StringUtils.isEmpty(value1) && StringUtils.isEmpty(value2) && StringUtils.isEmpty(value3) && StringUtils.isEmpty(value4)) {
|
|
|
// result.setDel("0");
|
|
|
// } else {
|
|
|
// if (StringUtils.isNotEmpty(recordDate)) {
|
|
|
// result.setRecordDate(DateUtil.strToDate(recordDate));
|
|
|
// } else {
|
|
|
// throw new RuntimeException("Record date can not be null!");
|
|
|
// }
|
|
|
//
|
|
|
// result.setDel("1");
|
|
|
// if (StringUtils.isNotEmpty(value1)) {
|
|
|
// result.setValue1(value1);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value2)) {
|
|
|
// result.setValue2(value2);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value3)) {
|
|
|
// result.setValue3(value3);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value4)) {
|
|
|
// result.setValue4(value4);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// update(result);
|
|
|
// if ("1".equals(result.getType()) || "2".equals(result.getType())) {
|
|
|
// verifyHealthIndex(result.getId());
|
|
|
// }
|
|
|
// } else {
|
|
|
// throw new RuntimeException("Result not exit!");
|
|
|
// }
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 获取居民最新各类健康记录
|
|
|
*/
|
|
|
// public Map findDataByPatient(String patient, int type) throws Exception {
|
|
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
// String sql = "SELECT " +
|
|
|
// " * " +
|
|
|
// " FROM " +
|
|
|
// " device.wlyy_patient_health_index a " +
|
|
|
// " WHERE " +
|
|
|
// " a. USER = ? " +
|
|
|
// " AND a.type = ? " +
|
|
|
// " AND a.del = 1 " +
|
|
|
// " ORDER BY " +
|
|
|
// " a.record_date DESC " +
|
|
|
// "LIMIT 0,1 ";
|
|
|
//// List<Map<String, Object>> devicePatient = jdbcTemplate.queryForList(sql, patient, type);
|
|
|
//
|
|
|
//// sql = TransforSqlUtl.wlyy_patient_health_index(sql);
|
|
|
//
|
|
|
// List<Map<String, Object>> devicePatient = findDataByPatient(sql, patient, type);
|
|
|
// Map<String, Object> map = new HashMap<>();
|
|
|
// for (Map<String, Object> device : devicePatient) {
|
|
|
// String time = device.get("record_date") == null ? null : device.get("record_date").toString();
|
|
|
// String deviceSN = device.get("device_sn") == null ? "0" : "1";
|
|
|
// String value1 = device.get("value1") == null ? null : device.get("value1").toString();
|
|
|
// String value2 = device.get("value2") == null ? null : device.get("value2").toString();
|
|
|
// String value3 = device.get("value3") == null ? null : device.get("value3").toString();
|
|
|
// String value4 = device.get("value4") == null ? null : device.get("value4").toString();
|
|
|
// String value5 = device.get("value5") == null ? null : device.get("value5").toString();
|
|
|
// String value6 = device.get("value6") == null ? null : device.get("value6").toString();
|
|
|
// String value7 = device.get("value7") == null ? null : device.get("value7").toString();
|
|
|
// map.put("isDevice", deviceSN);
|
|
|
// if (StringUtils.isNotEmpty(time)) {
|
|
|
// Date date = sdf.parse(time);
|
|
|
// time = sdf.format(date);
|
|
|
// map.put("time", time);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value1)) {
|
|
|
// map.put("value1", value1);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value2)) {
|
|
|
// map.put("value2", value2);
|
|
|
//
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value3)) {
|
|
|
// map.put("value3", value3);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value4)) {
|
|
|
// map.put("value4", value4);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value5)) {
|
|
|
// map.put("value5", value5);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value6)) {
|
|
|
// map.put("value6", value6);
|
|
|
// }
|
|
|
// if (StringUtils.isNotEmpty(value7)) {
|
|
|
// map.put("value7", value7);
|
|
|
// }
|
|
|
// }
|
|
|
// return map;
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 判断当前值是否在区间内
|
|
|
*/
|
|
|
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 void sendMessage(String content, Patient patient, DevicePatientHealthIndex model,String oldMsgContent) {
|
|
|
// String patientCode = patient.getCode();
|
|
|
// String patientName = patient.getName();
|
|
|
// // 消息接收者
|
|
|
// List<String> receivers = new ArrayList<String>();
|
|
|
// // 查询病人家庭签约的健康管理师
|
|
|
// SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patientCode);
|
|
|
// String healthDoctorFamily = "";
|
|
|
// String doctorFamily = "";
|
|
|
// /*String doctorName = "";
|
|
|
// String doctorOpenID = "";*/
|
|
|
// if (signFamily != null) {
|
|
|
// healthDoctorFamily = signFamily.getDoctorHealth();
|
|
|
// doctorFamily = signFamily.getDoctor();
|
|
|
// if (StringUtils.isNotEmpty(healthDoctorFamily) && StringUtils.isNotEmpty(doctorFamily)){
|
|
|
// // 添加到消息接收人列表
|
|
|
// if (doctorFamily.equals(healthDoctorFamily)){
|
|
|
// //-------------健管师和家医同一个人-------------
|
|
|
// receivers.add(healthDoctorFamily);
|
|
|
// }else {
|
|
|
// //-------------健管师和家医不是同一个人-------------
|
|
|
// receivers.add(healthDoctorFamily);
|
|
|
// receivers.add(doctorFamily);
|
|
|
// }
|
|
|
// }else if (StringUtils.isNotEmpty(healthDoctorFamily) && StringUtils.isEmpty(doctorFamily)){
|
|
|
// //-------------家医为空-------------
|
|
|
// receivers.add(healthDoctorFamily);
|
|
|
// }else if (StringUtils.isNotEmpty(doctorFamily) && StringUtils.isEmpty(healthDoctorFamily)){
|
|
|
// //-------------健管师为空-------------
|
|
|
// receivers.add(doctorFamily);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// List<Message> messages = new ArrayList<Message>();
|
|
|
// JSONArray array = new JSONArray();
|
|
|
// //判断是否是今日测量数据,如果不是则不进行体征干预
|
|
|
// if(model.getRecordDate().compareTo(DateUtil.getNowDateShort()) > -1) {
|
|
|
// for (String receiver : receivers) {
|
|
|
// if (StringUtils.isEmpty(receiver)) {
|
|
|
// continue;
|
|
|
// }
|
|
|
// // 保存异常消息
|
|
|
// Message message = new Message();
|
|
|
// message.setCode(getCode());
|
|
|
// 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.setDel("1");
|
|
|
// 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", oldMsgContent);
|
|
|
// json.put("data", "");
|
|
|
// array.put(json);
|
|
|
// }
|
|
|
// }
|
|
|
// // 批量保存消息
|
|
|
// messageDao.save(messages);
|
|
|
// for (String receiver : receivers) {
|
|
|
// if (StringUtils.isEmpty(receiver)) {
|
|
|
// continue;
|
|
|
// }
|
|
|
// if (messageService.getMessageNoticeSettingByMessageType(receiver, "1", MessageNoticeSetting.MessageTypeEnum.healthSignSwitch.getValue())) {
|
|
|
// // 新增发送医生助手模板消息 v1.4.0 by wujunjie
|
|
|
// Doctor doctor = doctorDao.findByCode(receiver);
|
|
|
// if (doctor != null && StringUtils.isNotEmpty(doctor.getOpenid())) {
|
|
|
// List<Message> messagesList = messageDao.findUnreadHealthIndex(patientCode, receiver);
|
|
|
// if (messagesList != null && messagesList.size() > 0) {
|
|
|
// String url = doctorAssistant + "/wlyy/feldsher/sendDoctorTemplates";
|
|
|
// List<NameValuePair> params = new ArrayList<>();
|
|
|
// params.add(new BasicNameValuePair("type", "3"));
|
|
|
// params.add(new BasicNameValuePair("openId", doctor.getOpenid()));
|
|
|
// params.add(new BasicNameValuePair("url", targetUrl));
|
|
|
// params.add(new BasicNameValuePair("first", doctor.getName() + "医生,您的签约居民" + patientName +
|
|
|
// "有" + messagesList.size() + "条未读的体征异常消息"));
|
|
|
// params.add(new BasicNameValuePair("remark", "请进入手机APP查看"));
|
|
|
// SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
// String date = format.format(new Date());
|
|
|
// String keywords = date + "," + patientName;
|
|
|
// params.add(new BasicNameValuePair("keywords", keywords));
|
|
|
//
|
|
|
// httpClientUtil.post(url, params, "UTF-8");
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// // 推送消息给医生
|
|
|
// pushMsgTask.put(array);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 获取患者某天血糖值
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
// private com.alibaba.fastjson.JSONObject getPatientXT_Json(String patient, String dateString) {
|
|
|
// com.alibaba.fastjson.JSONObject obj = new com.alibaba.fastjson.JSONObject();
|
|
|
// obj.put("user", patient);
|
|
|
// boolean hadData = false;
|
|
|
// Date date = DateUtil.strToDateShort(dateString);
|
|
|
// /***************** 按时间排序 ***************************/
|
|
|
//
|
|
|
// String sql = "SELECT " +
|
|
|
// "MIN(id) id" +
|
|
|
// ", user" +
|
|
|
// ",value1" +
|
|
|
// ",value2" +
|
|
|
// ",value3" +
|
|
|
// ",value4" +
|
|
|
// ",value5" +
|
|
|
// ",value6" +
|
|
|
// ",value7" +
|
|
|
// ",device_sn" +
|
|
|
// ",type" +
|
|
|
// ",record_date" +
|
|
|
// ",sort_date" +
|
|
|
// ",czrq as createDate" +
|
|
|
// ",min(czrq) czrq " +
|
|
|
// " from device.wlyy_patient_health_index " +
|
|
|
// " WHERE `user` = '" + patient + "' " +
|
|
|
// " and type = 1" +
|
|
|
// " and DATE_FORMAT(record_date,'%Y-%m-%d') = '" + dateString + "'" +
|
|
|
// " and del = '1' " +
|
|
|
// " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
// " order by record_date,id desc ";
|
|
|
//// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
// List<Map<String, Object>> list = getPatientXT_JsonIot(sql, patient, dateString);
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// obj.put("type", 1);
|
|
|
// obj.put("czrq", date);
|
|
|
// obj.put("recordDate", date);
|
|
|
// obj.put("sortDate", date);
|
|
|
// for (Map<String, Object> item : list) {
|
|
|
// String data = item.get("value1").toString();
|
|
|
// String dataType = item.get("value2").toString();
|
|
|
// String deviceSn = item.get("device_sn") == null ? "" : item.get("device_sn").toString();
|
|
|
// Date recordDate = (Date) item.get("record_date");
|
|
|
// Long id = Long.parseLong(item.get("id") + "");
|
|
|
// Date createDate = (Date) item.get("createDate");
|
|
|
//
|
|
|
// String recordTime = DateUtil.dateToStr(recordDate, DateUtil.YYYY_MM_DD);
|
|
|
// String createTime = DateUtil.dateToStr(createDate, DateUtil.YYYY_MM_DD);
|
|
|
//
|
|
|
// if (data != null && dataType != null) {
|
|
|
// if (dataType.equals("1")) {
|
|
|
// obj.put("value1", data);
|
|
|
// obj.put("time1", recordDate);
|
|
|
// obj.put("id1", id);
|
|
|
// obj.put("deviceSn1", deviceSn);
|
|
|
// hadData = true;
|
|
|
// } else if (dataType.equals("2")) {
|
|
|
// obj.put("value2", data);
|
|
|
// obj.put("time2", recordDate);
|
|
|
// obj.put("id2", id);
|
|
|
// obj.put("deviceSn2", deviceSn);
|
|
|
// hadData = true;
|
|
|
// } else if (dataType.equals("3")) {
|
|
|
// obj.put("value3", data);
|
|
|
// obj.put("time3", recordDate);
|
|
|
// obj.put("id3", id);
|
|
|
// obj.put("deviceSn3", deviceSn);
|
|
|
// hadData = true;
|
|
|
// } else if (dataType.equals("4")) {
|
|
|
// obj.put("value4", data);
|
|
|
// obj.put("time4", recordDate);
|
|
|
// obj.put("id4", id);
|
|
|
// obj.put("deviceSn4", deviceSn);
|
|
|
// hadData = true;
|
|
|
// } else if (dataType.equals("5")) {
|
|
|
// obj.put("value5", data);
|
|
|
// obj.put("time5", recordDate);
|
|
|
// obj.put("id5", id);
|
|
|
// obj.put("deviceSn5", deviceSn);
|
|
|
// hadData = true;
|
|
|
// } else if (dataType.equals("6")) {
|
|
|
// obj.put("value6", data);
|
|
|
// obj.put("time6", recordDate);
|
|
|
// obj.put("id6", id);
|
|
|
// obj.put("deviceSn6", deviceSn);
|
|
|
// hadData = true;
|
|
|
// } else if (dataType.equals("7")) {
|
|
|
// obj.put("value7", data);
|
|
|
// obj.put("time7", recordDate);
|
|
|
// obj.put("id7", id);
|
|
|
// obj.put("deviceSn7", deviceSn);
|
|
|
// hadData = true;
|
|
|
// }
|
|
|
//
|
|
|
// //是否为补传数据(设备上传且测量时间和创建时间不匹配)
|
|
|
// judgeIsSupplement(obj, recordTime, createTime, deviceSn, dataType);
|
|
|
//
|
|
|
// obj.put("healthindexid", id);
|
|
|
// obj.put("valuedata", data);
|
|
|
// obj.put("dataType", dataType);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// if (hadData) {
|
|
|
// return obj;
|
|
|
// } else {
|
|
|
// return null;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 是否为补传数据(设备上传且测量时间和创建时间不匹配)
|
|
|
*
|
|
|
* @param obj
|
|
|
* @param recordDate
|
|
|
* @param createDate
|
|
|
* @param deviceSn
|
|
|
* @param num
|
|
|
*/
|
|
|
private void judgeIsSupplement(com.alibaba.fastjson.JSONObject obj, String recordDate, String createDate, String deviceSn, String num) {
|
|
|
if ("".equals(deviceSn)) {
|
|
|
obj.put("isSupplement" + num, 0);
|
|
|
} else {
|
|
|
if (recordDate.compareTo(createDate) == 0) {
|
|
|
obj.put("isSupplement" + num, 0);
|
|
|
} else {
|
|
|
obj.put("isSupplement" + num, 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private com.alibaba.fastjson.JSONArray getPatientXT_Json1(String patient, Integer page, Integer pageSize) {
|
|
|
com.alibaba.fastjson.JSONObject obj = new com.alibaba.fastjson.JSONObject();
|
|
|
obj.put("user", patient);
|
|
|
boolean hadData = false;
|
|
|
/***************** 按时间排序 ***************************/
|
|
|
|
|
|
String sql = "SELECT " +
|
|
|
"MIN(id) id" +
|
|
|
", user" +
|
|
|
",value1" +
|
|
|
",value2" +
|
|
|
",value3" +
|
|
|
",value4" +
|
|
|
",value5" +
|
|
|
",value6" +
|
|
|
",value7" +
|
|
|
",device_sn" +
|
|
|
",type" +
|
|
|
",DATE_FORMAT(record_date,'%Y-%m-%d') as record_date " +
|
|
|
",sort_date" +
|
|
|
",min(czrq) czrq " +
|
|
|
" from device.wlyy_patient_health_index " +
|
|
|
" WHERE `user` = '" + patient + "' " +
|
|
|
" and type = 1" +
|
|
|
" and del = '1' " +
|
|
|
" GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
" order by record_date,id desc limit " + page + "," + pageSize;
|
|
|
// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray();
|
|
|
if (list != null && list.size() > 0) {
|
|
|
for (Map<String, Object> item : list) {
|
|
|
obj.put("type", 1);
|
|
|
obj.put("czrq", item.get("czrq"));
|
|
|
obj.put("recordDate", item.get("record_date"));
|
|
|
obj.put("sortDate", item.get("sort_date"));
|
|
|
String data = item.get("value1").toString();
|
|
|
String dataType = item.get("value2").toString();
|
|
|
String deviceSn = item.get("device_sn") == null ? "" : item.get("device_sn").toString();
|
|
|
String recordDate = item.get("record_date").toString();
|
|
|
Long id = Long.parseLong(item.get("id") + "");
|
|
|
if (data != null && dataType != null) {
|
|
|
if (dataType.equals("1")) {
|
|
|
obj.put("value1", data);
|
|
|
obj.put("time1", recordDate);
|
|
|
obj.put("id1", id);
|
|
|
obj.put("deviceSn1", deviceSn);
|
|
|
} else if (dataType.equals("2")) {
|
|
|
obj.put("value2", data);
|
|
|
obj.put("time2", recordDate);
|
|
|
obj.put("id2", id);
|
|
|
obj.put("deviceSn2", deviceSn);
|
|
|
|
|
|
} else if (dataType.equals("3")) {
|
|
|
obj.put("value3", data);
|
|
|
obj.put("time3", recordDate);
|
|
|
obj.put("id3", id);
|
|
|
obj.put("deviceSn3", deviceSn);
|
|
|
|
|
|
} else if (dataType.equals("4")) {
|
|
|
obj.put("value4", data);
|
|
|
obj.put("time4", recordDate);
|
|
|
obj.put("id4", id);
|
|
|
obj.put("deviceSn4", deviceSn);
|
|
|
} else if (dataType.equals("5")) {
|
|
|
obj.put("value5", data);
|
|
|
obj.put("time5", recordDate);
|
|
|
obj.put("id5", id);
|
|
|
obj.put("deviceSn5", deviceSn);
|
|
|
} else if (dataType.equals("6")) {
|
|
|
obj.put("value6", data);
|
|
|
obj.put("time6", recordDate);
|
|
|
obj.put("id6", id);
|
|
|
obj.put("deviceSn6", deviceSn);
|
|
|
} else if (dataType.equals("7")) {
|
|
|
obj.put("value7", data);
|
|
|
obj.put("time7", recordDate);
|
|
|
obj.put("id7", id);
|
|
|
obj.put("deviceSn7", deviceSn);
|
|
|
}
|
|
|
obj.put("healthindexid", id);
|
|
|
obj.put("valuedata", data);
|
|
|
obj.put("dataType", dataType);
|
|
|
array.add(obj);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return array;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验指标是否超标,发送消息
|
|
|
*/
|
|
|
// public void verifyHealthIndex(Long id) {
|
|
|
// //指标信息
|
|
|
// DevicePatientHealthIndex data = findOne(id);
|
|
|
// String patientCode = data.getUser();
|
|
|
// //患者信息
|
|
|
// BasePatientDO patient = patientDao.findById(patientCode).orElse(null);
|
|
|
//
|
|
|
// int type = data.getType();
|
|
|
// String msgContent = "";
|
|
|
// String oldMsgContent = "";
|
|
|
// //血糖校验
|
|
|
// if (type == 1) {
|
|
|
// // 血糖记录,查询患者血糖预警值
|
|
|
// PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 1);
|
|
|
// Double maxValueBefore = SystemConf.HEALTH_STANDARD_ST_MAX_BEFORE;
|
|
|
// Double minValueBefore = SystemConf.HEALTH_STANDARD_ST_MIN_BEFORE;
|
|
|
// Double maxValueAfter = SystemConf.HEALTH_STANDARD_ST_MAX_AFTER;
|
|
|
// Double minValueAfter = SystemConf.HEALTH_STANDARD_ST_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)) {
|
|
|
// oldMsgContent += 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>";
|
|
|
// }
|
|
|
// //体征异常,更新体征数据状态
|
|
|
// updateStatus(data);
|
|
|
// }
|
|
|
// } else { //餐前
|
|
|
// if (!checkHealthIndex(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore)) {
|
|
|
// oldMsgContent += patient.getName() + "血糖异常(" + value1 + "mmol/L)";
|
|
|
// if (checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore) == 1) {
|
|
|
// msgContent = "<a>" + patient.getName() + "</a><span style=\"color: #FF4C4C;\">血糖偏高</span>";
|
|
|
// } else if (checkHealthIndexDetail(NumberUtils.toDouble(value1), maxValueBefore, minValueBefore) == 2) {
|
|
|
// msgContent = "<a>" + patient.getName() + "</a><span style=\"color: #FF4C4C;\">血糖偏低</span>";
|
|
|
// }
|
|
|
// updateStatus(data);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// //血压校验
|
|
|
// else if (type == 2) {
|
|
|
// String value1 = data.getValue1();
|
|
|
// String value2 = data.getValue2();
|
|
|
// // 血压记录,查询患者血压预警值
|
|
|
// PatientHealthStandard standard = patientHealthStandardDao.findByPatientType(patientCode, 2);
|
|
|
// Double maxValueSSY = SystemConf.HEALTH_STANDARD_SSY_MAX;
|
|
|
// Double minValueSSY = SystemConf.HEALTH_STANDARD_SSY_MIN;
|
|
|
// Double maxValueSZY = SystemConf.HEALTH_STANDARD_SZY_MAX;
|
|
|
// Double minValueSZY = SystemConf.HEALTH_STANDARD_SZY_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)) {
|
|
|
// oldMsgContent = 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>";
|
|
|
// }
|
|
|
// updateStatus(data);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// //超标则发送消息
|
|
|
// if (msgContent != null && msgContent.length() > 0) {
|
|
|
//// sendMessage(msgContent, patient, data,oldMsgContent);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/********************************************物联网 start***********************************************************/
|
|
|
/**
|
|
|
* 修改体征异常状态
|
|
|
*
|
|
|
* @param data
|
|
|
*/
|
|
|
// public void updateStatus(DevicePatientHealthIndex data) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// //物联网更新
|
|
|
// iotDeviceService.updateStatus(data.getId(), "1");
|
|
|
// } else {
|
|
|
// data.setStatus(1);
|
|
|
// patientHealthIndexDao.save(data);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 按id查找体征记录
|
|
|
*
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
// public DevicePatientHealthIndex findOne(Long id) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// return iotDeviceService.getById(id);
|
|
|
// } else {
|
|
|
// return patientHealthIndexDao.findById(id).orElse(null);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 体征保存
|
|
|
*
|
|
|
* @param data
|
|
|
* @return
|
|
|
*/
|
|
|
// public DevicePatientHealthIndex save(DevicePatientHealthIndex data) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// return iotDeviceService.save(data);
|
|
|
// } else {
|
|
|
// //数据双写
|
|
|
// try {
|
|
|
// iotDeviceService.save(data);
|
|
|
// } catch (Exception e) {
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
// return patientHealthIndexDao.save(data);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 体征修改
|
|
|
*
|
|
|
* @param data
|
|
|
* @return
|
|
|
*/
|
|
|
// public DevicePatientHealthIndex update(DevicePatientHealthIndex data) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// return iotDeviceService.update(data);
|
|
|
// } else {
|
|
|
// return patientHealthIndexDao.save(data);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 查询最近的一条体征数据
|
|
|
*
|
|
|
* @param sql
|
|
|
* @param patient
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<Map<String, Object>> findDataByPatient(String sql, String patient, Integer type) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// List<Map<String, Object>> re = new ArrayList<>();
|
|
|
// List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndType(patient, type, 1);
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// re.add(indexToMap(list.get(0)));
|
|
|
// }
|
|
|
// return re;
|
|
|
// } else {
|
|
|
// return jdbcTemplate.queryForList(sql, patient, type);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 患者最近填写的健康指标
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<DevicePatientHealthIndex> findRecentByPatientIterable(String patient) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// return iotDeviceService.findByPatientAndType(patient, null, 1000);
|
|
|
// } else {
|
|
|
// return patientHealthIndexDao.findRecentByPatient(patient);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 根据患者标志获取健康指标
|
|
|
* @param patient
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
// public DevicePatientHealthIndex findLastByPatienIot(String patient,Integer type){
|
|
|
// if(iotDeviceService.isUploadIot()){
|
|
|
// DevicePatientHealthIndex index = null;
|
|
|
// List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndType(patient,type,1);
|
|
|
// if(list!=null&&list.size()>0){
|
|
|
// index = list.get(0);
|
|
|
// }
|
|
|
// return index;
|
|
|
// }else {
|
|
|
// return findLastByPatien(patient,type);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 获取小康小屋数据
|
|
|
*
|
|
|
* @param patientCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
// public List<Map<String,Object>> selectByXiaoWu(String patientCode) throws Exception {
|
|
|
// Patient patient = patientDao.findByCode(patientCode);
|
|
|
// if (patient == null){
|
|
|
// throw new RuntimeException("该居民不存在!");
|
|
|
// }
|
|
|
// String idcard = patient.getIdcard();
|
|
|
// String sql = "SELECT * FROM xmiot.wlyy_iot_d d RIGHT JOIN " +
|
|
|
// "( SELECT * FROM xmiot.wlyy_iot_m m " +
|
|
|
// "WHERE m.id_card_no = '"+idcard+"' " +
|
|
|
// "ORDER BY m.measure_time DESC LIMIT 0,1 ) m2 ON m2.id = d.mid AND d.code = 'Result'";
|
|
|
// List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql);
|
|
|
// for (Map<String,Object> map:maps){
|
|
|
// map.put("typeName",wlyyIotTzDictDao.selectByCodeAndValue(map.get("type").toString(),map.get("type").toString()));
|
|
|
// map.put("valueName",wlyyIotTzDictDao.selectByCodeAndValue(map.get("type").toString()+"_"+map.get("code").toString(),map.get("value").toString()));
|
|
|
// }
|
|
|
// return maps;
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 血糖 、血压
|
|
|
*
|
|
|
* @param patientCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
// public List<Map<String, Object>> selectByTypeOfXiaoWu(String patientCode, String type) throws Exception {
|
|
|
// BasePatientDO patient = patientDao.findById(patientCode).orElse(null);
|
|
|
// if (patient == null) {
|
|
|
// throw new RuntimeException("该居民不存在!");
|
|
|
// }
|
|
|
// String idcard = patient.getIdcard();
|
|
|
// String sql = "SELECT * FROM xmiot.wlyy_iot_d d RIGHT JOIN ( " +
|
|
|
// "SELECT * FROM xmiot.wlyy_iot_m m " +
|
|
|
// "WHERE m.id_card_no = '" + idcard + "' " +
|
|
|
// "ORDER BY m.measure_time DESC LIMIT 0,1 ) m2 " +
|
|
|
// "ON m2.id = d.mid AND d.type = '" + type + "'";
|
|
|
// List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
|
|
|
// for (Map<String, Object> map : maps) {
|
|
|
// if (map.get("code").toString().equalsIgnoreCase("Result")) {
|
|
|
// map.put("typeName", wlyyIotTzDictDao.selectByCodeAndValue(map.get("type").toString(), map.get("type").toString()));
|
|
|
// map.put("valueName", wlyyIotTzDictDao.selectByCodeAndValue(map.get("type").toString() + "_" + map.get("code").toString(), map.get("value").toString()));
|
|
|
// }
|
|
|
// }
|
|
|
// return maps;
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 查询指标记录
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<String> findDateListIot(String patient, int type, Date startDate, Date endDate, Integer page, Integer size, String start, String end) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// List<String> re = new ArrayList<>();
|
|
|
// List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, null, page, size, null, start, end);
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// list.forEach(one -> {
|
|
|
// re.add(DateUtil.dateToStrShort(one.getRecordDate()));
|
|
|
// });
|
|
|
// }
|
|
|
// return re;
|
|
|
// } else {
|
|
|
// return patientHealthIndexDao.findDateList(patient, type, startDate, endDate, page, size);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
public List<String> findDateListIot1(String patient, Date startDate, Date endDate, Integer page, Integer size, String start, String end) {
|
|
|
|
|
|
return patientHealthIndexDao.findDateList(patient, startDate, endDate, page, size);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按时间查找
|
|
|
*
|
|
|
* @param sql
|
|
|
* @param patient
|
|
|
* @param type
|
|
|
* @param size
|
|
|
* @param gi_type
|
|
|
* @param begin
|
|
|
* @param end
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<Map<String, Object>> findByPatientAndTime(String sql, String patient, Integer type, Integer size, Integer gi_type, String begin, String end) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// List<Map<String, Object>> re = new ArrayList<>();
|
|
|
// List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, type, 1, size, gi_type, begin, end);
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// list.forEach(one -> {
|
|
|
// re.add(indexToMap(one));
|
|
|
// });
|
|
|
// }
|
|
|
// return re;
|
|
|
// } else {
|
|
|
// return jdbcTemplate.queryForList(sql);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 按时间查找
|
|
|
*
|
|
|
* @param sql
|
|
|
* @param patient
|
|
|
* @param date
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<Map<String, Object>> getPatientXT_JsonIot(String sql, String patient, String date) {
|
|
|
// String begin = date + " 00:00:00";
|
|
|
// String end = date + " 23:59:59";
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// List<Map<String, Object>> re = new ArrayList<>();
|
|
|
// List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, 1, 1, 100, null, begin, end);
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// list.forEach(one -> {
|
|
|
// re.add(indexToMap(one));
|
|
|
// });
|
|
|
// }
|
|
|
// return re;
|
|
|
// } else {
|
|
|
// return jdbcTemplate.queryForList(sql);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 按时间查找
|
|
|
*
|
|
|
* @param sql
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<Map<String, Object>> getPatientXT_JsonIot(String sql, String patient, Integer type, Integer page, Integer size, String begin, String end) {
|
|
|
// if (iotDeviceService.isUploadIot()) {
|
|
|
// List<Map<String, Object>> re = new ArrayList<>();
|
|
|
// List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, type, page, size, null, begin, end);
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// list.forEach(one -> {
|
|
|
// re.add(indexToMap(one));
|
|
|
// });
|
|
|
// }
|
|
|
// return re;
|
|
|
// } else {
|
|
|
// return jdbcTemplate.queryForList(sql);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 转map
|
|
|
*
|
|
|
* @param index
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, Object> indexToMap(DevicePatientHealthIndex index) {
|
|
|
Map<String, Object> map = new HashedMap();
|
|
|
map.put("value1", index.getValue1());
|
|
|
map.put("value2", index.getValue2());
|
|
|
map.put("value3", index.getValue3());
|
|
|
map.put("value4", index.getValue4());
|
|
|
map.put("value5", index.getValue5());
|
|
|
map.put("value6", index.getValue6());
|
|
|
map.put("value7", index.getValue7());
|
|
|
map.put("device_sn", index.getDeviceSn());
|
|
|
map.put("record_date", index.getRecordDate());
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
/********************************************物联网 end***********************************************************/
|
|
|
|
|
|
/**
|
|
|
* 新增患者指标
|
|
|
* 【血糖】{"time":"2016-09-09 17:00:00","gi":"血糖值(mmol/L)"}
|
|
|
* 【血压】{"time":"2016-09-09 17:00:00","sys":"收缩压(mmHg)","dia":"舒张压(mmHg)","pul":"脉搏(次/分)","ano":"有无心率不齐0否 1是","user":"身份标识"}
|
|
|
* 【体重/身高】{"time":"2016-09-09 17:00:00","weight":"体重值(kg)","height":"身高(cm)"}
|
|
|
* 【腰围】{"time":"2016-09-09 17:00:00","waistline":"腰围值(cm)"}
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
// public DevicePatientHealthIndex addPatientHealthIndex(String data, String type, String patientCode, String deviceSn) throws Exception {
|
|
|
// Map<String, String> map = (Map<String, String>) objectMapper.readValue(data, Map.class);
|
|
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
//
|
|
|
// DevicePatientHealthIndex obj = new DevicePatientHealthIndex();
|
|
|
// Date currentTime = new Date();
|
|
|
// obj.setCzrq(currentTime);
|
|
|
// obj.setDel("1");
|
|
|
// obj.setStatus(0);
|
|
|
// Date time = currentTime;
|
|
|
// if (map.containsKey("time")) {
|
|
|
// String da = map.get("time");
|
|
|
//// time = DateUtil.strToDate(da);
|
|
|
// time = sdf.parse(da);
|
|
|
// }
|
|
|
// obj.setRecordDate(time); //记录时间
|
|
|
// obj.setSortDate(time); //排序时间
|
|
|
//
|
|
|
// String idcard = "";
|
|
|
// BasePatientDO patient = null;
|
|
|
// if (deviceSn != null && deviceSn.length() > 0) //设备数据
|
|
|
// {
|
|
|
// obj.setDeviceSn(deviceSn);
|
|
|
// String userType = "-1";
|
|
|
// if (map.containsKey("user")) { //存在身份标识 ,多用户
|
|
|
// userType = map.get("user");
|
|
|
// }
|
|
|
// //根据设备获取患者(不同厂家sn码一样的问题未解决!!)
|
|
|
// PatientDevice device = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(deviceSn, type, userType);
|
|
|
// if (device != null) {
|
|
|
// patientCode = device.getUser();
|
|
|
// patient = patientDao.findByCode(patientCode);
|
|
|
// idcard = device.getUserIdcard();
|
|
|
// }
|
|
|
//
|
|
|
// DeviceDetail deviceDetail = deviceDetailDao.findBySn(deviceSn);
|
|
|
// if(deviceDetail!=null){
|
|
|
// obj.setHospital(deviceDetail.getGrantOrgCode());
|
|
|
// obj.setHospitalName(deviceDetail.getOrgName());
|
|
|
// }
|
|
|
// }
|
|
|
// //自输数据
|
|
|
// else {
|
|
|
// patient = patientDao.findByCode(patientCode);
|
|
|
// if (patient != null) {
|
|
|
// idcard = patient.getIdcard();
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// //身份证不为空
|
|
|
// if (patient != null) {
|
|
|
// obj.setUser(patientCode);
|
|
|
// obj.setName(patient.getName());
|
|
|
// obj.setIdcard(idcard);
|
|
|
//
|
|
|
// String msgContent = "";
|
|
|
// // 1血糖 2血压 3体重 4腰围
|
|
|
// switch (type) {
|
|
|
// case "1": {
|
|
|
// obj.setType(1);
|
|
|
// String value1 = map.get("gi"); //血糖值
|
|
|
// String gi_type = map.get("gi_type"); //血糖值类型对应1到7
|
|
|
// String recordDate = map.get("recordDate");
|
|
|
// obj.setValue1(value1);
|
|
|
// obj.setValue2(gi_type);
|
|
|
// if (StringUtils.isNotBlank(recordDate)) {
|
|
|
// obj.setRecordDate(DateUtil.strToDateAppendNowTime(recordDate, DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
// }
|
|
|
// break;
|
|
|
// }
|
|
|
// case "2": {
|
|
|
// obj.setType(2);
|
|
|
// String value1 = map.get("sys"); //收缩压
|
|
|
// String value2 = map.get("dia"); //舒张压
|
|
|
// obj.setValue1(value1);
|
|
|
// obj.setValue2(value2);
|
|
|
// obj.setValue3(map.get("pul")); //脉搏
|
|
|
// obj.setValue4(map.get("ano")); //有无心率不齐
|
|
|
// break;
|
|
|
// }
|
|
|
// case "3": {
|
|
|
// obj.setType(3);
|
|
|
//
|
|
|
// String weight = map.get("weight");
|
|
|
// String height = map.get("height");
|
|
|
//
|
|
|
// obj.setValue1(weight); //体重
|
|
|
// obj.setValue2(height); //身高
|
|
|
//
|
|
|
// PatientAimSports patientAimSports = new PatientAimSports();
|
|
|
// patientAimSports = patientAimSportsDao.getPatientAimSportsByPatientCode(patientCode);
|
|
|
// //如果该患者没有设置运动目标,则获取预置数据
|
|
|
// if (patientAimSports == null || StringUtils.isBlank(patientAimSports.getCode())) {
|
|
|
// patientAimSports = patientAimSportsDao.findByCode("default");
|
|
|
// }
|
|
|
//
|
|
|
// double bmi = CommonUtil.getBMIByWeightAndHeight(map.get("weight"), map.get("height"));
|
|
|
// DecimalFormat df1 = new DecimalFormat("###.00");
|
|
|
// obj.setValue3(df1.format(bmi));
|
|
|
//
|
|
|
// double bmiMin = new Double("18.5");
|
|
|
// double bmiMax = new Double("23.9");
|
|
|
//
|
|
|
// if (patientAimSports != null && StringUtils.isNoneEmpty(patientAimSports.getCode())) {
|
|
|
// bmiMin = Double.parseDouble(patientAimSports.getBmiMin());
|
|
|
// bmiMax = Double.parseDouble(patientAimSports.getBmiMax());
|
|
|
// }
|
|
|
//
|
|
|
// //设置BMI值
|
|
|
// if (bmi < bmiMin) {
|
|
|
// obj.setValue4("1");
|
|
|
// } else if (bmi > bmiMax) {
|
|
|
// obj.setValue4("-1");
|
|
|
// } else {
|
|
|
// obj.setValue4("0");
|
|
|
// }
|
|
|
//
|
|
|
// break;
|
|
|
// }
|
|
|
// case "4": {
|
|
|
// obj.setType(4);
|
|
|
// obj.setValue1(map.get("waistline")); //腰围
|
|
|
// obj.setValue2(map.get("hipline"));
|
|
|
// break;
|
|
|
// }
|
|
|
// default: {
|
|
|
// throw new RuntimeException("暂不支持该指标!");
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// obj = save(obj);
|
|
|
//
|
|
|
// //判断是否有未结束的续方咨询,发送消息给对应的医生
|
|
|
// sendPrescriptionHealthIndexMsgresult(obj,patient);
|
|
|
//
|
|
|
// //保存完后上传基卫
|
|
|
//// new Thread(new HealthIndexUploadTask(String.valueOf(obj.getId()))).start();
|
|
|
// } else {
|
|
|
// throw new RuntimeException("不存在该患者!");
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// return obj;
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 判断是否有未结束的续方咨询,发送消息给对应的医生
|
|
|
* @param result
|
|
|
* @param patient
|
|
|
*/
|
|
|
// private void sendPrescriptionHealthIndexMsgresult(DevicePatientHealthIndex result, Patient patient) {
|
|
|
//
|
|
|
// List<ConsultTeam> consultTeams = consultTeamDao.findUnfinishedConsultPrescription(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);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 判断居民的体征预警状态
|
|
|
*
|
|
|
* @param obj
|
|
|
*/
|
|
|
// public void handlePatientStandarStatus(DevicePatientHealthIndex obj) {
|
|
|
// //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
|
|
|
// String patientCode = obj.getUser();
|
|
|
// //患者信息
|
|
|
// BasePatientDO p = patientDao.findById(patientCode).orElse(null);
|
|
|
//
|
|
|
// PatientVO patient = new PatientVO();
|
|
|
// String patientsql = "select group_concat(label) disease from wlyy_sign_patient_label_info where label_type = 3 and status=1 and (label = 1 or label = 2) and patient = '"+p.getCode()+"' GROUP BY patient";
|
|
|
//
|
|
|
// String patientdisease = "";
|
|
|
// List<Map<String,Object>> diseases = jdbcTemplate.queryForList(patientsql);
|
|
|
// if(diseases!=null&&diseases.size()>0){
|
|
|
// patientdisease = (String)diseases.get(0).get("disease");
|
|
|
// }
|
|
|
//
|
|
|
// int bloodPressureBbnormalCount = 0;//血压异常次数
|
|
|
// int bloodSuggurBbnormalCount = 0;//血糖异常次数
|
|
|
// int stdbloodPressureBbnormalCount = 0;//血压次数
|
|
|
// int stdbloodSuggurBbnormalCount = 0;//血糖次数
|
|
|
//
|
|
|
// List<DevicePatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
|
|
|
// List<DevicePatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
|
|
|
//
|
|
|
// bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode, 2);
|
|
|
// bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode, 1);
|
|
|
//
|
|
|
// if(!bloodPressurepatientHealthIndices.isEmpty()){
|
|
|
// stdbloodPressureBbnormalCount = bloodPressurepatientHealthIndices.size();
|
|
|
// }
|
|
|
//
|
|
|
// if(!bloodSuggurpatientHealthIndices.isEmpty()){
|
|
|
// stdbloodSuggurBbnormalCount = bloodSuggurpatientHealthIndices.size();
|
|
|
// }
|
|
|
//
|
|
|
// for (DevicePatientHealthIndex index1 : bloodPressurepatientHealthIndices) {
|
|
|
// if (index1.getStatus() != null && 1 == index1.getStatus()) {
|
|
|
// bloodPressureBbnormalCount++;
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// for (DevicePatientHealthIndex index2 : bloodSuggurpatientHealthIndices) {
|
|
|
// if (index2.getStatus() != null && 1 == index2.getStatus()) {
|
|
|
// bloodSuggurBbnormalCount++;
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// //连续3次异常,修改用户为预警状态
|
|
|
// if ((bloodPressureBbnormalCount >= 3 || bloodSuggurBbnormalCount >= 3)) {
|
|
|
// p.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);
|
|
|
// if (errorCount >= 5) {//超过5次,记为预警状态
|
|
|
// p.setStandardStatus(1);
|
|
|
// //1.4.2加入重点关注逻辑
|
|
|
// setTrackPatientByDoctor(patientCode);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// //连续5次正常,修改用户为非预警状态
|
|
|
// if (StringUtils.isNotBlank(patientdisease)) {
|
|
|
// if ("1".equals(patientdisease)) {
|
|
|
// if (stdbloodPressureBbnormalCount==5&&0 == bloodPressureBbnormalCount) {
|
|
|
// p.setStandardStatus(0);
|
|
|
// //1.4.2加入重点关注逻辑
|
|
|
// cancalTrackPatientByDoctor(patientCode);
|
|
|
// }
|
|
|
// } else if ("2".equals(patientdisease)) {
|
|
|
// if (stdbloodSuggurBbnormalCount==5&&0 == bloodSuggurBbnormalCount) {
|
|
|
// p.setStandardStatus(0);
|
|
|
// //1.4.2加入重点关注逻辑
|
|
|
// cancalTrackPatientByDoctor(patientCode);
|
|
|
// }
|
|
|
// } else if ("1,2".equals(patientdisease) || "2,1".equals(patientdisease)) {
|
|
|
// if (stdbloodPressureBbnormalCount==5&&stdbloodSuggurBbnormalCount==5&&0 == bloodSuggurBbnormalCount && 0 == bloodPressureBbnormalCount) {
|
|
|
// p.setStandardStatus(0);
|
|
|
// //1.4.2加入重点关注逻辑
|
|
|
// cancalTrackPatientByDoctor(patientCode);
|
|
|
// }
|
|
|
// }
|
|
|
// } else {
|
|
|
// p.setStandardStatus(0);
|
|
|
// //1.4.2加入重点关注逻辑
|
|
|
// cancalTrackPatientByDoctor(patientCode);
|
|
|
// }
|
|
|
//
|
|
|
// patientDao.save(p);
|
|
|
// //连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 设置默认监控方案
|
|
|
*
|
|
|
* @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;
|
|
|
// }
|
|
|
// BasePatientDO p = patientDao.findById(patient).orElse(null);
|
|
|
// 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);
|
|
|
// //设置默认控制目标
|
|
|
// setDefaultAim(patient);
|
|
|
// } 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);
|
|
|
// //设置默认控制目标
|
|
|
// setDefaultAim(patient);
|
|
|
// } else {
|
|
|
// trackPatient.setDel("1");
|
|
|
// trackPatientDao.save(trackPatient);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// return 1;
|
|
|
// }
|
|
|
|
|
|
// public int cancalTrackPatientByDoctor(String patient){
|
|
|
// SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
|
|
|
// if(signFamily==null){
|
|
|
// return -1;
|
|
|
// }
|
|
|
// BasePatientDO 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);
|
|
|
// }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);
|
|
|
// }else{
|
|
|
// trackPatient.setDel("0");
|
|
|
// trackPatientDao.save(trackPatient);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// return 1;
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 按录入时间和患者标识查询健康记录
|
|
|
*
|
|
|
* @param patientCode
|
|
|
* @param date
|
|
|
* @return
|
|
|
*/
|
|
|
// public Iterable<DevicePatientHealthIndex> findByPatienDate(String patientCode, int type, Date date) {
|
|
|
// return patientHealthIndexDao.findByPatienDate(patientCode, type, date);
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 按时间段查询患者健康指标
|
|
|
*
|
|
|
* @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
|
|
|
* @param begin 开始时间
|
|
|
* @param end 结束时间
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<DevicePatientHealthIndex> findChartByPatien(String patient, int type, String begin, String end) {
|
|
|
// List<DevicePatientHealthIndex> re = new ArrayList<>();
|
|
|
//
|
|
|
// Date startDate = DateUtil.strToDate(begin, DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
// Date endDate = DateUtil.strToDate(end, DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
// if (type == 1) //血糖特殊处理
|
|
|
// {
|
|
|
// //根据时间过滤排序
|
|
|
// List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, null);
|
|
|
// if (dateList != null && dateList.size() > 0) {
|
|
|
// for (int i = dateList.size() - 1; i >= 0; i--) {
|
|
|
// String dateString = dateList.get(i);
|
|
|
// DevicePatientHealthIndex obj = getPatientXT(patient, dateString);
|
|
|
// if (obj != null) {
|
|
|
// re.add(obj);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// } else {
|
|
|
// // 排序
|
|
|
// Sort sort = new Sort(Direction.ASC, "recordDate");
|
|
|
// PageRequest pageRequest = new PageRequest(0, 1000, sort);
|
|
|
// re = patientHealthIndexDao.findIndexByPatient(patient, type, startDate, endDate, pageRequest).getContent();
|
|
|
// }
|
|
|
// return re;
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 按时间段查询患者健康指标
|
|
|
*
|
|
|
* @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
|
|
|
* @param gi_type 血糖就餐时间段(早餐前,早餐后等)
|
|
|
* @param begin 开始时间
|
|
|
* @param end 结束时间
|
|
|
* @return
|
|
|
*/
|
|
|
// public JSONArray findChartByPatient(String patient, int type, int gi_type, String begin, String end) {
|
|
|
// JSONArray re = new JSONArray();
|
|
|
// String sql = "SELECT " +
|
|
|
// "MIN(id) id" +
|
|
|
// ", user" +
|
|
|
// ",value1" +
|
|
|
// ",value2" +
|
|
|
// ",value3" +
|
|
|
// ",value4" +
|
|
|
// ",value5" +
|
|
|
// ",value6" +
|
|
|
// ",value7" +
|
|
|
// ",device_sn" +
|
|
|
// ",type" +
|
|
|
// ",record_date" +
|
|
|
// ",sort_date" +
|
|
|
// ",min(czrq) czrq " +
|
|
|
// " from device.wlyy_patient_health_index " +
|
|
|
// " WHERE `user` = '" + patient + "' " +
|
|
|
// " and type =" + type +
|
|
|
// " and record_date >= '" + begin + "'" +
|
|
|
// " and record_date <= '" + end + "' " +
|
|
|
// " and del = '1' ";
|
|
|
// String conditionApp = "";
|
|
|
// if (gi_type != 0) {
|
|
|
// conditionApp = " and value2 = '" + gi_type + "' ";
|
|
|
// }
|
|
|
// sql = sql + conditionApp +
|
|
|
// " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
// " order by record_date desc ,sort_date desc limit " + 0 + " ," + 1000 + " ";
|
|
|
//// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
// List<Map<String, Object>> list = findByPatientAndTime(sql, patient, type, 1000, gi_type, begin, end);
|
|
|
// for (Map<String, Object> map : list) {
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("id", map.get("id"));
|
|
|
// json.put("patient", map.get("user"));
|
|
|
// json.put("value1", map.get("value1"));
|
|
|
// json.put("value2", map.get("value2"));
|
|
|
// json.put("value3", map.get("value3"));
|
|
|
// json.put("value4", map.get("value4"));
|
|
|
// json.put("value5", map.get("value5"));
|
|
|
// json.put("value6", map.get("value6"));
|
|
|
// json.put("value7", map.get("value7"));
|
|
|
// json.put("deviceSn", map.get("device_sn") == null ? "" : map.get("device_sn"));
|
|
|
// json.put("type", map.get("type"));
|
|
|
//
|
|
|
// Date date = (Date) map.get("record_date");
|
|
|
// if (type == 2) {
|
|
|
// json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
// } else {
|
|
|
// json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD));
|
|
|
// }
|
|
|
// json.put("sortDate", map.get("sort_date"));
|
|
|
// json.put("czrq", map.get("czrq"));
|
|
|
//
|
|
|
// re.put(json);
|
|
|
// }
|
|
|
// return re;
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 按时间段查询患者健康指标
|
|
|
*
|
|
|
* @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
|
|
|
* @param gi_type 血糖就餐时间段(早餐前,早餐后等)
|
|
|
* @param begin 开始时间
|
|
|
* @param end 结束时间
|
|
|
* @return
|
|
|
*/
|
|
|
// public com.alibaba.fastjson.JSONObject findChartByPatientIot(String patient, int type, int gi_type, String begin, String end, String time) {
|
|
|
// com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
// com.alibaba.fastjson.JSONArray re = new com.alibaba.fastjson.JSONArray();
|
|
|
// int high = 0;//偏高
|
|
|
// int normal = 0;//正常
|
|
|
// int low = 0;//偏低
|
|
|
// boolean flag = false;//高危标志 true高危。
|
|
|
//
|
|
|
// String sql = "SELECT " +
|
|
|
// "MIN(id) id" +
|
|
|
// ", user" +
|
|
|
// ",value1" +
|
|
|
// ",value2" +
|
|
|
// ",value3" +
|
|
|
// ",value4" +
|
|
|
// ",value5" +
|
|
|
// ",value6" +
|
|
|
// ",value7" +
|
|
|
// ",device_sn" +
|
|
|
// ",type" +
|
|
|
// ",record_date" +
|
|
|
// ",sort_date" +
|
|
|
// ",min(czrq) czrq " +
|
|
|
// " from device.wlyy_patient_health_index " +
|
|
|
// " WHERE `user` = '" + patient + "' " +
|
|
|
// " and type =" + type +
|
|
|
// " and record_date >= '" + begin + "'" +
|
|
|
// " and record_date <= '" + end + "' " +
|
|
|
// " and del = '1' ";
|
|
|
// String conditionApp = "";
|
|
|
// if (gi_type != 0) {
|
|
|
// conditionApp = " and value2 = '" + gi_type + "' ";
|
|
|
// }
|
|
|
// sql = sql + conditionApp +
|
|
|
// " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
// " order by record_date desc ,sort_date desc limit " + 0 + " ," + 1000 + " ";
|
|
|
//// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
// List<Map<String, Object>> list = findByPatientAndTime(sql, patient, type, 1000, gi_type, begin, end);
|
|
|
// for (Map<String, Object> map : list) {
|
|
|
// String value1 = map.get("value1").toString();
|
|
|
// String value2 = map.get("value2").toString();
|
|
|
// com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
|
|
|
// json.put("id", map.get("id"));
|
|
|
// json.put("patient", map.get("user"));
|
|
|
// json.put("value1", value1);
|
|
|
// json.put("value2", value2);
|
|
|
// json.put("value3", map.get("value3"));
|
|
|
// json.put("value4", map.get("value4"));
|
|
|
// json.put("value5", map.get("value5"));
|
|
|
// json.put("value6", map.get("value6"));
|
|
|
// json.put("value7", map.get("value7"));
|
|
|
// json.put("deviceSn", map.get("device_sn") == null ? "" : map.get("device_sn"));
|
|
|
// json.put("type", map.get("type"));
|
|
|
//
|
|
|
// Date date = (Date) map.get("record_date");
|
|
|
// if (type == 2) {
|
|
|
// json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
// } else {
|
|
|
// json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD));
|
|
|
// }
|
|
|
// json.put("sortDate", map.get("sort_date"));
|
|
|
// json.put("czrq", map.get("czrq"));
|
|
|
//
|
|
|
//
|
|
|
// //统计加指标分析
|
|
|
// int returnInt = 0;
|
|
|
// if (type == 1) {
|
|
|
//// int age = 60;
|
|
|
//// Patient p = patientDao.findByCode(patient);
|
|
|
//// if(p!=null){
|
|
|
//// age = IdCardUtil.getAgeForIdcard(p.getIdcard());
|
|
|
//// }
|
|
|
// //血糖
|
|
|
// Double maxValueBefore = SystemConf.HEALTH_STANDARD_ST_MAX_BEFORE;
|
|
|
// Double minValueBefore = SystemConf.HEALTH_STANDARD_ST_MIN_BEFORE;
|
|
|
// Double maxValueAfter = SystemConf.HEALTH_STANDARD_ST_MAX_AFTER;
|
|
|
// Double minValueAfter = SystemConf.HEALTH_STANDARD_ST_MIN_AFTER;
|
|
|
// int index = Integer.parseInt(value2);
|
|
|
// Double intVlue1 = NumberUtils.toDouble(value1);
|
|
|
// if (index % 2 == 0) {
|
|
|
// //餐后
|
|
|
// returnInt = checkHealth(maxValueAfter, minValueAfter, intVlue1);
|
|
|
// switch (returnInt) {
|
|
|
// case 0:
|
|
|
// normal++;
|
|
|
// break;
|
|
|
// case 1:
|
|
|
// high++;
|
|
|
// break;
|
|
|
// default:
|
|
|
// low++;
|
|
|
// break;
|
|
|
// }
|
|
|
// if (intVlue1 >= maxValueAfter) {
|
|
|
// flag = true;
|
|
|
// }
|
|
|
// } else {
|
|
|
// //餐前
|
|
|
// returnInt = checkHealth(maxValueBefore, minValueBefore, intVlue1);
|
|
|
// switch (returnInt) {
|
|
|
// case 0:
|
|
|
// normal++;
|
|
|
// break;
|
|
|
// case 1:
|
|
|
// high++;
|
|
|
// break;
|
|
|
// default:
|
|
|
// low++;
|
|
|
// break;
|
|
|
// }
|
|
|
// if (intVlue1 >= maxValueBefore) {
|
|
|
// flag = true;
|
|
|
// }
|
|
|
// }
|
|
|
// } else if (type == 2) {
|
|
|
// //血压
|
|
|
// Double intVlue1 = NumberUtils.toDouble(value1);
|
|
|
// Double intVlue2 = NumberUtils.toDouble(value2);
|
|
|
// Double maxValueSSY = SystemConf.HEALTH_STANDARD_SSY_MAX;
|
|
|
// Double minValueSSY = SystemConf.HEALTH_STANDARD_SSY_MIN;
|
|
|
// Double maxValueSZY = SystemConf.HEALTH_STANDARD_SZY_MAX;
|
|
|
// Double minValueSZY = SystemConf.HEALTH_STANDARD_SZY_MIN;
|
|
|
//
|
|
|
// returnInt = checkHealth(maxValueSSY, minValueSSY, intVlue1);
|
|
|
// switch (returnInt) {
|
|
|
// case 0:
|
|
|
// normal++;
|
|
|
// break;
|
|
|
// case 1:
|
|
|
// high++;
|
|
|
// if (intVlue1 >= maxValueSSY) {
|
|
|
// flag = true;
|
|
|
// }
|
|
|
// break;
|
|
|
// default:
|
|
|
// low++;
|
|
|
// break;
|
|
|
// }
|
|
|
// returnInt = checkHealth(maxValueSZY, minValueSZY, intVlue2);
|
|
|
// switch (returnInt) {
|
|
|
// case 0:
|
|
|
// normal++;
|
|
|
// break;
|
|
|
// case 1:
|
|
|
// high++;
|
|
|
// if (intVlue2 >= maxValueSSY) {
|
|
|
// flag = true;
|
|
|
// }
|
|
|
// break;
|
|
|
// default:
|
|
|
// low++;
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// re.add(json);
|
|
|
// }
|
|
|
// jsonObject.put("list", re);
|
|
|
// com.alibaba.fastjson.JSONObject total = new com.alibaba.fastjson.JSONObject();
|
|
|
// total.put("high", high);
|
|
|
// total.put("normal", normal);
|
|
|
// total.put("low", low);
|
|
|
// jsonObject.put("total", total);
|
|
|
// String content = "";
|
|
|
// if (high > 0) {
|
|
|
// content = "居民" + time + "内有" + high + "次指标偏高";
|
|
|
// if (low > 0) {
|
|
|
// content += ",有" + low + "次指标偏低";
|
|
|
// } else {
|
|
|
// content += "。";
|
|
|
// }
|
|
|
// if (flag) {
|
|
|
// content += "居民" + time + "内控制不理想,可能伴有靶器官损害或其他并发症。建议由健管师进行电话随访不少于每月4次,至少每2周面对面随访一次,建议动员居民至医院全科医生就诊,特殊情况建议入户诊疗。病情严重建议转诊专科医师进行进一步治疗。";
|
|
|
// } else {
|
|
|
// content += "居民" + time + "内控制不理想但低于急危值,建议至少每2周面对面随访一次,建议动员居民至医院全科医生就诊,特殊情况建议入户诊疗。病情严重建议转诊专科医师进行进一步治疗。";
|
|
|
// }
|
|
|
// } else if (low > 0) {
|
|
|
// content = "居民" + time + "内有" + low + "次指标偏低。";
|
|
|
// content += "居民" + time + "内控制不理想但低于急危值,建议至少每2周面对面随访一次,建议动员居民至医院全科医生就诊,特殊情况建议入户诊疗。病情严重建议转诊专科医师进行进一步治疗。";
|
|
|
// } else {
|
|
|
// content = "居民" + time + "内指标没有异常。居民" + time + "内相对稳定,建议至少每周面对面随访一次,全科医生根据居民情况安排预约转诊专科医师,并跟踪治疗情况。";
|
|
|
// }
|
|
|
// jsonObject.put("content", content);
|
|
|
//
|
|
|
// return jsonObject;
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 指标验证
|
|
|
*
|
|
|
* @param max
|
|
|
* @param min
|
|
|
* @param value
|
|
|
* @return -1偏低,0正常,1偏高
|
|
|
*/
|
|
|
// private Integer checkHealth(Double max, Double min, Double value) {
|
|
|
// if (max < value) {
|
|
|
// return 1;
|
|
|
// } else if (min > value) {
|
|
|
// return -1;
|
|
|
// } else {
|
|
|
// return 0;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 查询指标记录
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param type
|
|
|
* @param start
|
|
|
* @param end
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
// public JSONArray findIndexByPatient(String patient, int type, String start, String end, int page, int pageSize) {
|
|
|
// JSONArray re = new JSONArray();
|
|
|
// if (page > 0) {
|
|
|
// page = page - 1;
|
|
|
// }
|
|
|
// if (type == 1) //血糖特殊处理
|
|
|
// {
|
|
|
//
|
|
|
// } else {
|
|
|
// // 排序
|
|
|
// Sort sort = Sort.by(Direction.DESC, "recordDate");
|
|
|
// PageRequest pageRequest = PageRequest.of(page, pageSize, sort);
|
|
|
// String sql = "SELECT " +
|
|
|
// "MIN(id) id" +
|
|
|
// ", user" +
|
|
|
// ",value1" +
|
|
|
// ",value2" +
|
|
|
// ",value3" +
|
|
|
// ",value4" +
|
|
|
// ",value5" +
|
|
|
// ",value6" +
|
|
|
// ",value7" +
|
|
|
// ",device_sn" +
|
|
|
// ",type" +
|
|
|
// ",record_date" +
|
|
|
// ",sort_date" +
|
|
|
// ",czrq as createDate" +
|
|
|
// ",min(czrq) czrq " +
|
|
|
// " from device.wlyy_patient_health_index " +
|
|
|
// " WHERE `user` = '" + patient + "' " +
|
|
|
// " and type =" + type +
|
|
|
// " and record_date >= '" + start + "'" +
|
|
|
// " and record_date <= '" + end + "' " +
|
|
|
// " and del = '1' " +
|
|
|
// " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
// " order by record_date desc ,sort_date desc limit " + pageRequest.getOffset() + " ," + pageRequest.getPageSize() + " ";
|
|
|
//// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
// List<Map<String, Object>> list = getPatientXT_JsonIot(sql, patient, type, Integer.parseInt(String.valueOf(pageRequest.getOffset())), pageRequest.getPageSize(), start, end);
|
|
|
// for (Map<String, Object> map : list) {
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("id", map.get("id"));
|
|
|
// json.put("healthindexid", map.get("id"));
|
|
|
// json.put("patient", map.get("user"));
|
|
|
// json.put("value1", map.get("value1"));
|
|
|
// json.put("value2", map.get("value2"));
|
|
|
// json.put("value3", map.get("value3"));
|
|
|
// json.put("value4", map.get("value4"));
|
|
|
// json.put("value5", map.get("value5"));
|
|
|
// json.put("value6", map.get("value6"));
|
|
|
// json.put("value7", map.get("value7"));
|
|
|
// json.put("deviceSn", map.get("device_sn") == null ? "" : map.get("device_sn"));
|
|
|
// json.put("type", map.get("type"));
|
|
|
//
|
|
|
// Date date = (Date) map.get("record_date");
|
|
|
// if (type == 2) {
|
|
|
// json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
// } else {
|
|
|
// json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD));
|
|
|
// }
|
|
|
// json.put("sortDate", map.get("sort_date"));
|
|
|
// json.put("czrq", map.get("czrq"));
|
|
|
//
|
|
|
// //是否为补传数据(设备上传且测量时间和创建时间不匹配)
|
|
|
// Date recordDate = (Date) map.get("record_date");
|
|
|
// Date createDate = (Date) map.get("createDate");
|
|
|
// String recordTime = DateUtil.dateToStr(recordDate, DateUtil.YYYY_MM_DD);
|
|
|
// String createTime = DateUtil.dateToStr(createDate, DateUtil.YYYY_MM_DD);
|
|
|
// if (map.get("device_sn") == null) {
|
|
|
// json.put("isSupplement", 0);
|
|
|
// } else {
|
|
|
// if (recordTime.compareToIgnoreCase(createTime) == 0) {
|
|
|
// json.put("isSupplement", 0);
|
|
|
// } else {
|
|
|
// json.put("isSupplement", 1);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// re.put(json);
|
|
|
// }
|
|
|
// }
|
|
|
// return re;
|
|
|
// }
|
|
|
|
|
|
public JSONObject findIndexByPatient1(String patient, int type, int page, int pageSize) {
|
|
|
JSONArray re = new JSONArray();
|
|
|
JSONObject object = new JSONObject();
|
|
|
if (page > 0) {
|
|
|
page = page - 1;
|
|
|
}
|
|
|
if (type == 1) //血糖特殊处理
|
|
|
{
|
|
|
|
|
|
} else {
|
|
|
// 排序
|
|
|
Sort sort = Sort.by(Direction.DESC, "recordDate");
|
|
|
PageRequest pageRequest = PageRequest.of(page, pageSize, sort);
|
|
|
String sql = "SELECT " +
|
|
|
"MIN(id) id" +
|
|
|
", user" +
|
|
|
",value1" +
|
|
|
",value2" +
|
|
|
",value3" +
|
|
|
",value4" +
|
|
|
",value5" +
|
|
|
",value6" +
|
|
|
",value7" +
|
|
|
",device_sn" +
|
|
|
",type" +
|
|
|
",record_date" +
|
|
|
",sort_date" +
|
|
|
",min(czrq) czrq " +
|
|
|
" from device.wlyy_patient_health_index " +
|
|
|
" WHERE `user` = '" + patient + "' " +
|
|
|
" and type =" + type +
|
|
|
" and del = '1' " +
|
|
|
" GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
" order by record_date desc ,sort_date desc limit " + pageRequest.getOffset() + " ," + pageRequest.getPageSize() + " ";
|
|
|
String sqlCount = "select count(1) as total from (SELECT " +
|
|
|
"MIN(id) id" +
|
|
|
", user" +
|
|
|
",value1" +
|
|
|
",value2" +
|
|
|
",value3" +
|
|
|
",value4" +
|
|
|
",value5" +
|
|
|
",value6" +
|
|
|
",value7" +
|
|
|
",device_sn" +
|
|
|
",type" +
|
|
|
",record_date" +
|
|
|
",sort_date" +
|
|
|
",min(czrq) czrq " +
|
|
|
" from device.wlyy_patient_health_index " +
|
|
|
" WHERE `user` = '" + patient + "' " +
|
|
|
" and type =" + type +
|
|
|
" and del = '1' " +
|
|
|
" GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
" order by record_date desc ,sort_date desc) phi ";
|
|
|
// List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
List<Map<String, Object>> rstotal2 = jdbcTemplate.queryForList(sqlCount);
|
|
|
Long taskCount = 0L;
|
|
|
if (rstotal2 != null && rstotal2.size() > 0) {
|
|
|
Object object1 = rstotal2.get(0).get("total");
|
|
|
if (object1 != null) {
|
|
|
taskCount = Long.parseLong(object1.toString());
|
|
|
}
|
|
|
}
|
|
|
object.put("totalCount", taskCount);
|
|
|
for (Map<String, Object> map : list) {
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id", map.get("id"));
|
|
|
json.put("healthindexid", map.get("id"));
|
|
|
json.put("patient", map.get("user"));
|
|
|
json.put("value1", map.get("value1"));
|
|
|
json.put("value2", map.get("value2"));
|
|
|
json.put("value3", map.get("value3"));
|
|
|
json.put("value4", map.get("value4"));
|
|
|
json.put("value5", map.get("value5"));
|
|
|
json.put("value6", map.get("value6"));
|
|
|
json.put("value7", map.get("value7"));
|
|
|
json.put("deviceSn", map.get("device_sn") == null ? "" : map.get("device_sn"));
|
|
|
json.put("type", map.get("type"));
|
|
|
|
|
|
Date date = (Date) map.get("record_date");
|
|
|
if (type == 2) {
|
|
|
json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
} else {
|
|
|
json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD));
|
|
|
}
|
|
|
json.put("sortDate", map.get("sort_date"));
|
|
|
json.put("czrq", map.get("czrq"));
|
|
|
|
|
|
re.put(json);
|
|
|
}
|
|
|
}
|
|
|
object.put("pageSize", pageSize);
|
|
|
object.put("currPage", page + 1);
|
|
|
object.put("detailModelList", re);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询指标记录
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param type
|
|
|
* @param start
|
|
|
* @param end
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
// public List<Object> findIndexByPatient2(String patient, int type, String start, String end, int page, int pageSize) {
|
|
|
// List<Object> re = new ArrayList<>();
|
|
|
// if (page > 0) {
|
|
|
// page = page - 1;
|
|
|
// }
|
|
|
//
|
|
|
// Date startDate = DateUtil.strToDate(start, DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
// Date endDate = DateUtil.strToDate(end, DateUtil.YYYY_MM_DD_HH_MM_SS);
|
|
|
// if (type == 1) //血糖特殊处理
|
|
|
// {
|
|
|
// PageRequest pageRequest = PageRequest.of(page, pageSize);
|
|
|
// //根据时间过滤排序
|
|
|
//// List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
|
|
|
// List<String> dateList = findDateListIot(patient, type, startDate, endDate, Integer.parseInt(String.valueOf(pageRequest.getOffset())), pageRequest.getPageSize(), start, end);
|
|
|
// if (dateList != null && dateList.size() > 0) {
|
|
|
// for (String dateString : dateList) {
|
|
|
// com.alibaba.fastjson.JSONObject obj = getPatientXT_Json(patient, dateString);
|
|
|
// if (obj != null) {
|
|
|
// re.add(obj);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// } else {
|
|
|
// // 排序
|
|
|
//
|
|
|
// }
|
|
|
// return re;
|
|
|
// }
|
|
|
|
|
|
|
|
|
public JSONObject findIndexByPatient3(String patient, int type, int page, int pageSize) {
|
|
|
List<Object> re = new ArrayList<>();
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
if (page > 0) {
|
|
|
page = page - 1;
|
|
|
}
|
|
|
|
|
|
if (type == 1) //血糖特殊处理
|
|
|
{
|
|
|
PageRequest pageRequest = PageRequest.of(page, pageSize);
|
|
|
jsonObject.put("currPage", page + 1);
|
|
|
com.alibaba.fastjson.JSONArray array = getPatientXT_Json1(patient, Integer.parseInt(String.valueOf(pageRequest.getOffset())), pageRequest.getPageSize());
|
|
|
jsonObject.put("detailModelList", array);
|
|
|
//根据时间过滤排序
|
|
|
// List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
|
|
|
String sql = "select count(1) as total from (SELECT " +
|
|
|
"MIN(id) id" +
|
|
|
", user" +
|
|
|
",value1" +
|
|
|
",value2" +
|
|
|
",value3" +
|
|
|
",value4" +
|
|
|
",value5" +
|
|
|
",value6" +
|
|
|
",value7" +
|
|
|
",device_sn" +
|
|
|
",type" +
|
|
|
",record_date" +
|
|
|
",sort_date" +
|
|
|
",min(czrq) czrq " +
|
|
|
" from device.wlyy_patient_health_index " +
|
|
|
" WHERE `user` = '" + patient + "' " +
|
|
|
" and type = 1" +
|
|
|
" and del = '1' " +
|
|
|
" GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
" order by record_date,id desc ) phi";
|
|
|
List<Map<String, Object>> rstotal2 = jdbcTemplate.queryForList(sql);
|
|
|
Long taskCount = 0L;
|
|
|
if (rstotal2 != null && rstotal2.size() > 0) {
|
|
|
Object object1 = rstotal2.get(0).get("total");
|
|
|
if (object1 != null) {
|
|
|
taskCount = Long.parseLong(object1.toString());
|
|
|
}
|
|
|
}
|
|
|
jsonObject.put("totalCount", taskCount);
|
|
|
|
|
|
} else {
|
|
|
// 排序
|
|
|
|
|
|
}
|
|
|
|
|
|
jsonObject.put("pageSize", pageSize);
|
|
|
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询患者健康指标预警值
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
public Iterable<PatientHealthStandard> findStandardByPatient(String patient) {
|
|
|
return patientHealthStandardDao.findByPatient(patient);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存患者健康指标预警值
|
|
|
*
|
|
|
* @param list
|
|
|
*/
|
|
|
public Iterable<PatientHealthStandard> saveStandard(List<PatientHealthStandard> list, String patient) {
|
|
|
// 先删除
|
|
|
patientHealthStandardDao.deleteByPatient(patient);
|
|
|
return patientHealthStandardDao.saveAll(list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询患者最近填写的血糖、血压等记录
|
|
|
*
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
|
// public JSONArray findRecentByPatient(String patient) {
|
|
|
// JSONArray array = new JSONArray();
|
|
|
//// List<DevicePatientHealthIndex> iterable = patientHealthIndexDao.findRecentByPatient(patient);
|
|
|
// List<DevicePatientHealthIndex> iterable = findRecentByPatientIterable(patient);
|
|
|
// if (iterable != null) {
|
|
|
// Iterator<DevicePatientHealthIndex> iterator = iterable.iterator();
|
|
|
// while (iterator != null && iterator.hasNext()) {
|
|
|
// DevicePatientHealthIndex phi = iterator.next();
|
|
|
// if (phi == null) {
|
|
|
// continue;
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// // 设置健康指标类型(1血糖,2血压,3体重,4腰围)
|
|
|
// json.put("type", phi.getType());
|
|
|
// if (1 == phi.getType() && StringUtils.isNotBlank(phi.getValue2())) {
|
|
|
// int gi_type = Integer.parseInt(phi.getValue2());
|
|
|
// switch (gi_type) {
|
|
|
// case 1:
|
|
|
// // 设置血糖/收缩压/体重/腰围/早餐前空腹
|
|
|
// json.put("value1", phi.getValue1());
|
|
|
// json.put("time1", phi.getRecordDate());
|
|
|
// break;
|
|
|
// case 2:
|
|
|
// // 设置舒张压/早餐后血糖
|
|
|
// json.put("value2", phi.getValue2());
|
|
|
// json.put("time2", phi.getRecordDate());
|
|
|
// break;
|
|
|
// case 3:
|
|
|
// // 设置午餐前血糖
|
|
|
// json.put("value3", phi.getValue3());
|
|
|
// json.put("time3", phi.getRecordDate());
|
|
|
// break;
|
|
|
// case 4:
|
|
|
// // 设置午餐后血糖
|
|
|
// json.put("value4", phi.getValue4());
|
|
|
// json.put("time4", phi.getRecordDate());
|
|
|
// break;
|
|
|
// case 5:
|
|
|
// // 设置晚餐前血糖
|
|
|
// json.put("value5", phi.getValue5());
|
|
|
// json.put("time5", phi.getRecordDate());
|
|
|
// break;
|
|
|
// case 6:
|
|
|
// // 设置晚餐后血糖
|
|
|
// json.put("value6", phi.getValue6());
|
|
|
// json.put("time6", phi.getRecordDate());
|
|
|
// break;
|
|
|
// case 7:
|
|
|
// // 设置睡前血糖
|
|
|
// json.put("value7", phi.getValue7());
|
|
|
// json.put("time7", phi.getRecordDate());
|
|
|
// break;
|
|
|
// }
|
|
|
// } else {
|
|
|
// json.put("value1", phi.getValue1());
|
|
|
// json.put("value2", phi.getValue2());
|
|
|
// // 设置午餐前血糖
|
|
|
// json.put("value3", phi.getValue3());
|
|
|
// // 设置午餐后血糖
|
|
|
// json.put("value4", phi.getValue4());
|
|
|
// // 设置晚餐前血糖
|
|
|
// json.put("value5", phi.getValue5());
|
|
|
// // 设置晚餐后血糖
|
|
|
// json.put("value6", phi.getValue6());
|
|
|
// // 设置睡前血糖
|
|
|
// json.put("value7", phi.getValue7());
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// json.put("date", DateUtil.dateToStrShort(phi.getRecordDate()));
|
|
|
// array.put(json);
|
|
|
// }
|
|
|
// }
|
|
|
// return array;
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 根据患者标志获取健康指标
|
|
|
*
|
|
|
* @param patientCode 患者标志
|
|
|
* @return 健康指标列表
|
|
|
*/
|
|
|
// public DevicePatientHealthIndex findLastByPatien(String patientCode, int type) {
|
|
|
// //最新血糖指标
|
|
|
// if (type == 1) {
|
|
|
// DevicePatientHealthIndex obj = patientHealthIndexDao.findLastData(patientCode, 1);
|
|
|
// return obj;
|
|
|
// } else if (type == 2) { //其他指标
|
|
|
// return patientHealthIndexDao.findLastData(patientCode, 2);
|
|
|
// } else {
|
|
|
// return patientHealthIndexDao.findLastData(patientCode, type);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 获取患者健康指标历史记录
|
|
|
* 1血糖,2血压,3体重,4腰围
|
|
|
*/
|
|
|
// public List<Map<String, String>> getHealthIndexHistory(String patientCode, int type, int page, int pagesize) throws Exception {
|
|
|
// List<Map<String, String>> re = new ArrayList<>();
|
|
|
//
|
|
|
// // 排序
|
|
|
// Sort sort = new Sort(Direction.DESC, "recordDate");
|
|
|
// PageRequest pageRequest = new PageRequest(page, pagesize, sort);
|
|
|
// List<DevicePatientHealthIndex> list = patientHealthIndexDao.findIndexByPatient(patientCode, type, pageRequest);
|
|
|
//
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// for (DevicePatientHealthIndex item : list) {
|
|
|
// Map<String, String> map = new HashMap<>();
|
|
|
// if (type == 1) //血糖
|
|
|
// {
|
|
|
// String gi = item.getValue1();
|
|
|
// String giType = item.getValue2();
|
|
|
// map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
|
|
|
// map.put("gi", gi); // 血糖值
|
|
|
// map.put("gi_type", giType); // 血糖值类型
|
|
|
// String text = gi + " mmol/L";
|
|
|
// if ("1".equals(giType)) {
|
|
|
// text += "(早餐前)";
|
|
|
// } else if ("2".equals(giType)) {
|
|
|
// text += "(早餐后)";
|
|
|
// } else if ("3".equals(giType)) {
|
|
|
// text += "(午餐前)";
|
|
|
// } else if ("4".equals(giType)) {
|
|
|
// text += "(午餐后)";
|
|
|
// } else if ("5".equals(giType)) {
|
|
|
// text += "(晚饭前)";
|
|
|
// } else if ("6".equals(giType)) {
|
|
|
// text += "(晚饭后)";
|
|
|
// } else if ("7".equals(giType)) {
|
|
|
// text += "(睡前)";
|
|
|
// }
|
|
|
// map.put("text", text); // 展示
|
|
|
// re.add(map);
|
|
|
// } else if (type == 2) //血压
|
|
|
// {
|
|
|
// String sys = item.getValue1(); //收缩压
|
|
|
// String dia = item.getValue2(); //舒张压
|
|
|
// String pul = item.getValue3(); //脉搏
|
|
|
// map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
|
|
|
// map.put("sys", sys);
|
|
|
// map.put("dia", dia);
|
|
|
// map.put("pul", pul);
|
|
|
// re.add(map);
|
|
|
// } else if (type == 3) //体重
|
|
|
// {
|
|
|
// String weight = item.getValue1(); //体重
|
|
|
// String height = item.getValue2(); //身高
|
|
|
// String bmi = item.getValue3(); //BMI
|
|
|
// map.put("time", DateUtil.dateToStrShort(item.getRecordDate()));
|
|
|
// map.put("weight", weight);
|
|
|
// map.put("height", height);
|
|
|
// map.put("bmi", bmi);
|
|
|
// map.put("text", weight + " kg");
|
|
|
// re.add(map);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// return re;
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 保存医生预警值方案
|
|
|
*
|
|
|
* @param doclist
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
public Iterable<DoctorHealthStandard> saveDocStandard(List<DoctorHealthStandard> doclist, String uid) throws Exception {
|
|
|
// 先删除
|
|
|
doctorHealthStandardDao.deleteByDoctor(uid);
|
|
|
return doctorHealthStandardDao.saveAll(doclist);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询患者健康指标预警值
|
|
|
*
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
public Iterable<DoctorHealthStandard> findDoctorStandardByDoctor(String code) {
|
|
|
return doctorHealthStandardDao.findByDoctor(code);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量保存患者预警方案
|
|
|
*
|
|
|
* @param list
|
|
|
* @param patients
|
|
|
* @return
|
|
|
*/
|
|
|
public Iterable<PatientHealthStandard> saveStandardPatients(List<PatientHealthStandard> list, List<BasePatientDO> patients) {
|
|
|
|
|
|
for (BasePatientDO patient : patients) {
|
|
|
// patientHealthStandardDao.deleteByPatient(patient.getCode());
|
|
|
patientHealthStandardDao.deleteByPatient(patient.getId());
|
|
|
|
|
|
}
|
|
|
return patientHealthStandardDao.saveAll(list);
|
|
|
}
|
|
|
|
|
|
// public List<Map<String, String>> getHealthIndexByPatientAndDate(String patientCode, String deviceSn, String choseDate,int type) throws Exception {
|
|
|
// List<Map<String, String>> re = new ArrayList<>();
|
|
|
//
|
|
|
// // 排序
|
|
|
// Sort sort = new Sort(Direction.DESC, "recordDate");
|
|
|
// List<DevicePatientHealthIndex> list = new ArrayList<>();
|
|
|
//
|
|
|
// if(choseDate.length() == 7){
|
|
|
// list = patientHealthIndexDao.findByDateMonthAndType(type,patientCode,choseDate,deviceSn);
|
|
|
// }else{
|
|
|
// list = patientHealthIndexDao.findByDateAndType(type,patientCode,choseDate,deviceSn);
|
|
|
// }
|
|
|
//
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// for (DevicePatientHealthIndex item : list) {
|
|
|
// Map<String, String> map = new HashMap<>();
|
|
|
// if (type == 1) //血糖
|
|
|
// {
|
|
|
// String gi = item.getValue1();
|
|
|
// String giType = item.getValue2();
|
|
|
// map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
|
|
|
// map.put("gi", gi); // 血糖值
|
|
|
// map.put("gi_type", giType); // 血糖值类型
|
|
|
// String text = gi + " mmol/L";
|
|
|
// if ("1".equals(giType)) {
|
|
|
// text += "(早餐前)";
|
|
|
// } else if ("2".equals(giType)) {
|
|
|
// text += "(早餐后)";
|
|
|
// } else if ("3".equals(giType)) {
|
|
|
// text += "(午餐前)";
|
|
|
// } else if ("4".equals(giType)) {
|
|
|
// text += "(午餐后)";
|
|
|
// } else if ("5".equals(giType)) {
|
|
|
// text += "(晚饭前)";
|
|
|
// } else if ("6".equals(giType)) {
|
|
|
// text += "(晚饭后)";
|
|
|
// } else if ("7".equals(giType)) {
|
|
|
// text += "(睡前)";
|
|
|
// }
|
|
|
// map.put("text", text); // 展示
|
|
|
//// re.add(map);
|
|
|
// } else if (type == 2) //血压
|
|
|
// {
|
|
|
// String sys = item.getValue1(); //收缩压
|
|
|
// String dia = item.getValue2(); //舒张压
|
|
|
// String pul = item.getValue3(); //脉搏
|
|
|
// map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
|
|
|
// map.put("sys", sys);
|
|
|
// map.put("dia", dia);
|
|
|
// map.put("pul", pul);
|
|
|
//// re.add(map);
|
|
|
// } else if (type == 3) //体重
|
|
|
// {
|
|
|
// String weight = item.getValue1(); //体重
|
|
|
// String height = item.getValue2(); //身高
|
|
|
// String bmi = item.getValue3(); //BMI
|
|
|
// map.put("time", DateUtil.dateToStrShort(item.getRecordDate()));
|
|
|
// map.put("weight", weight);
|
|
|
// map.put("height", height);
|
|
|
// map.put("bmi", bmi);
|
|
|
// map.put("text", weight + " kg");
|
|
|
//// re.add(map);
|
|
|
// }else if(type == 4){
|
|
|
// map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
|
|
|
// map.put("value1", item.getValue1());
|
|
|
// map.put("value2", item.getValue2());
|
|
|
// }
|
|
|
// map.put("type", item.getType().toString());
|
|
|
// re.add(map);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// return re;
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// public DevicePatientHealthIndex getHealthIndexById(Long id) {
|
|
|
// return patientHealthIndexDao.findOne(id);
|
|
|
// }
|
|
|
|
|
|
|
|
|
public String getCode() {
|
|
|
return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
}
|
|
|
}
|