|
@ -5,8 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.care.dao.device.BasePatientOutBedDao;
|
|
|
import com.yihu.jw.care.dao.device.PatientDeviceDao;
|
|
|
import com.yihu.jw.care.dao.device.*;
|
|
|
import com.yihu.jw.care.dao.security.*;
|
|
|
import com.yihu.jw.care.dao.team.BaseTeamMemberDao;
|
|
|
import com.yihu.jw.care.service.common.DictService;
|
|
@ -26,8 +25,7 @@ import com.yihu.jw.entity.base.im.ConsultDo;
|
|
|
import com.yihu.jw.entity.base.im.ConsultTeamDo;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
|
|
|
import com.yihu.jw.entity.care.device.BasePatientOutBed;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientDevice;
|
|
|
import com.yihu.jw.entity.care.device.*;
|
|
|
import com.yihu.jw.entity.care.securitymonitoring.*;
|
|
|
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
|
|
|
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
|
|
@ -47,6 +45,8 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@ -117,6 +117,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
private ObjectMapper objectMapper;
|
|
|
@Autowired
|
|
|
private BasePatientOutBedDao outBedDao;
|
|
|
@Autowired
|
|
|
private BaseSleepPlanDao sleepPlanDao;
|
|
|
@Autowired
|
|
|
private BaseSleepPlanDetailDao sleepPlanDetailDao;
|
|
|
@Autowired
|
|
|
private BaseSleepNightRecordDao nightRecordDao;
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
|
|
|
|
|
@ -351,6 +357,19 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
if (5==orderDO.getOrderSource()){//睡眠带工单
|
|
|
try {
|
|
|
JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
|
|
|
List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patientDO.getId());
|
|
|
if (sleepPlans.size()>0){
|
|
|
BaseSleepPlan sleepPlan = sleepPlans.get(0);
|
|
|
String endTime = DateUtil.getNextMin(sleepPlan.getGetUpTime(),-1);
|
|
|
monitorInfo.put("sleepPlan",true);
|
|
|
monitorInfo.put("getUpTime",sleepPlan.getGetUpTime());
|
|
|
monitorInfo.put("siestaTime",sleepPlan.getNapTime());
|
|
|
monitorInfo.put("nightRestTime",sleepPlan.getNightRestTime());
|
|
|
monitorInfo.put("nightRecordTime",sleepPlan.getNightRestTime()+"-隔日"+endTime);
|
|
|
|
|
|
}else {
|
|
|
monitorInfo.put("sleepPlan",false);
|
|
|
}
|
|
|
monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
|
|
|
emergencyOrderVO.setInformation(monitorInfo);
|
|
|
}catch (Exception e){
|
|
@ -1211,18 +1230,51 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("location",null);
|
|
|
result.put("fences",null);
|
|
|
result.put("smoke",null);
|
|
|
result.put("gasLeakage",null);
|
|
|
result.put("fire",null);
|
|
|
result.put("fall",null);
|
|
|
result.put("sleep",null);
|
|
|
result.put("deviceSn",null);
|
|
|
result.put("monitorInfo",null);
|
|
|
String sql = " select count(id) from base_security_monitoring_order where patient='"+patient+"' and topic_item='preventFall' and status="+SecurityMonitoringOrderDO.Status.apply.getType();
|
|
|
Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
if (count>0){
|
|
|
result.put("fall",true);
|
|
|
}
|
|
|
else {
|
|
|
result.put("fall",false);
|
|
|
String sql = " select dict.code,count(ord.id) total from base_system_dict_entry dict LEFT JOIN base_security_monitoring_order ord " +
|
|
|
" on dict.code = ord.topic_item COLLATE utf8_unicode_ci and ord.status="+SecurityMonitoringOrderDO.Status.apply.getType()+" where dict.dict_code='service_item' " +
|
|
|
"and dict.remark='security' GROUP BY dict.code ";
|
|
|
List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String,Object>tmp:sqlResult){
|
|
|
switch (tmp.get("code").toString()){
|
|
|
case "preventGasLeakage":
|
|
|
Integer count = Integer.parseInt(tmp.get("total").toString());
|
|
|
if (count>0){
|
|
|
result.put("gasLeakage",true);
|
|
|
}else {
|
|
|
result.put("gasLeakage",false);
|
|
|
}
|
|
|
break;
|
|
|
case "preventFire":
|
|
|
count = Integer.parseInt(tmp.get("total").toString());
|
|
|
if (count>0){
|
|
|
result.put("fire",true);
|
|
|
}else {
|
|
|
result.put("fire",false);
|
|
|
}
|
|
|
break;
|
|
|
case "preventFall":
|
|
|
count = Integer.parseInt(tmp.get("total").toString());
|
|
|
if (count>0){
|
|
|
result.put("fall",true);
|
|
|
}else {
|
|
|
result.put("fall",false);
|
|
|
}
|
|
|
break;
|
|
|
case "preventOutOfBed":
|
|
|
count = Integer.parseInt(tmp.get("total").toString());
|
|
|
if (count>0){
|
|
|
result.put("sleep",true);
|
|
|
}else {
|
|
|
result.put("sleep",false);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
result = patientSignTopicInfo(result,patient,topicItem);
|
|
|
return result;
|
|
@ -1284,7 +1336,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void preventOutOfBed(JSONObject result,String patient){
|
|
|
public void preventOutOfBed(JSONObject result,String patient,boolean video){
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
|
|
|
if (devicePatientDeviceDos.size()==0){}
|
|
|
else {
|
|
@ -1297,10 +1349,34 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
result.put("sleepStatus",true);
|
|
|
JSONObject tmp = objInfo.getJSONObject(0);
|
|
|
JSONObject sleepInfo = new JSONObject();
|
|
|
String dayTime = getSleepMonitoringDay(new Date(),patient);
|
|
|
List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient,dayTime);
|
|
|
if (planDetails.size()>0){
|
|
|
BaseSleepPlanDetail planDetail = planDetails.get(0);
|
|
|
String jsonStr = JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
|
|
|
sleepInfo = JSONObject.parseObject(jsonStr);
|
|
|
sleepInfo.put("day",dayTime);
|
|
|
}
|
|
|
List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
|
|
|
if (sleepPlans.size()>0){
|
|
|
BaseSleepPlan sleepPlan = sleepPlans.get(0);
|
|
|
String endTime = DateUtil.getNextMin(sleepPlan.getGetUpTime(),-1);
|
|
|
sleepInfo.put("sleepPlan",true);
|
|
|
sleepInfo.put("getUpTime",sleepPlan.getGetUpTime());
|
|
|
sleepInfo.put("siestaTime",sleepPlan.getNapTime());
|
|
|
sleepInfo.put("nightRestTime",sleepPlan.getNightRestTime());
|
|
|
sleepInfo.put("nightRecordTime",sleepPlan.getNightRestTime()+"-隔日"+endTime);
|
|
|
}else {
|
|
|
sleepInfo.put("sleepPlan",false);
|
|
|
}
|
|
|
sleepInfo.put("online",tmp.getBooleanValue("online"));
|
|
|
sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
|
|
|
sleepInfo.put("heartrate",tmp.getString("heartrate"));
|
|
|
sleepInfo.put("breathrate",tmp.getString("breathrate"));
|
|
|
if(tmp.getBooleanValue("onbed")){
|
|
|
sleepInfo.put("bedStatus",1);
|
|
|
}else {
|
|
|
sleepInfo.put("bedStatus",0);
|
|
|
}
|
|
|
sleepInfo.put("heartRate",tmp.getString("heartrate"));
|
|
|
sleepInfo.put("breath",tmp.getString("breathrate"));
|
|
|
BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
|
|
|
if (null!=outBed){
|
|
|
String outBedTime = "";
|
|
@ -1326,10 +1402,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
result.put("sleepInfo","获取睡眠带数据失败");
|
|
|
}
|
|
|
}
|
|
|
monitorInfo(result, patient);
|
|
|
if (video){
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void preventFire(JSONObject result,String patient){
|
|
|
public void preventFire(JSONObject result,String patient,boolean video){
|
|
|
String sql = "SELECT r.value from wlyy_patient_device pd,base_device_health_index r " +
|
|
|
"WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' ";
|
|
|
sql += " and pd.category_code='15' ORDER BY r.create_time desc LIMIT 1";
|
|
@ -1341,7 +1419,9 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
result.put("smoke",list1.get(0).get("value"));
|
|
|
}
|
|
|
result.put("smokeOrderNum",getOrder(patient,"preventFire"));
|
|
|
monitorInfo(result, patient);
|
|
|
if (video){
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Integer getOrder(String patient,String topicItem){
|
|
@ -1351,7 +1431,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
public void preventGasLeakage(JSONObject result,String patient){
|
|
|
public void preventGasLeakage(JSONObject result,String patient,boolean video){
|
|
|
String sql = "SELECT r.value from wlyy_patient_device pd,base_device_health_index r " +
|
|
|
"WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' ";
|
|
|
sql += " and pd.category_code='14' ORDER BY r.create_time desc LIMIT 1";
|
|
@ -1363,7 +1443,9 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
result.put("methane",list1.get(0).get("value"));
|
|
|
}
|
|
|
result.put("methaneOrderNum",getOrder(patient,"preventGasLeakage"));
|
|
|
monitorInfo(result, patient);
|
|
|
if (video){
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void monitorInfo(JSONObject result,String patient){
|
|
@ -1401,13 +1483,13 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventOutOfBed(result, patient);
|
|
|
preventOutOfBed(result, patient,true);
|
|
|
}
|
|
|
if ("preventFire".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventFire(result, patient);
|
|
|
preventFire(result, patient,true);
|
|
|
}
|
|
|
if ("preventGasLeakage".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventGasLeakage(result, patient);
|
|
|
preventGasLeakage(result, patient,true);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@ -1492,6 +1574,66 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*获取居民睡眠计划
|
|
|
*/
|
|
|
public BaseSleepPlan getPatientSleepPlan(String patient){
|
|
|
List<BaseSleepPlan> list = sleepPlanDao.findByPatient(patient);
|
|
|
if (list.size()>0){
|
|
|
return list.get(0);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*获取居民睡眠监护列表
|
|
|
*/
|
|
|
public JSONObject getPatientSleepDetainList(String patient,String begin,String end,Integer page,Integer pageSize){
|
|
|
page=page>0?page-1:0;
|
|
|
PageRequest pageRequest = new PageRequest(page, pageSize);
|
|
|
if (StringUtils.isBlank(end)){
|
|
|
end = begin;
|
|
|
}
|
|
|
JSONArray array = new JSONArray();
|
|
|
Page<BaseSleepPlanDetail> list = sleepPlanDetailDao.findByListByPage(patient,begin,end,pageRequest);
|
|
|
List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
|
|
|
BaseSleepPlan sleepPlan=null;
|
|
|
if (sleepPlans.size()>0){
|
|
|
sleepPlan = sleepPlans.get(0);
|
|
|
}
|
|
|
for (BaseSleepPlanDetail tmp:list){
|
|
|
List<BaseSleepNightRecord> records = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,tmp.getDay());
|
|
|
tmp.setSleepNightRecordList(records);
|
|
|
String str = JSON.toJSONStringWithDateFormat(tmp, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(str);
|
|
|
if (null==sleepPlan){
|
|
|
jsonObject.put("sleepPlan",false);
|
|
|
}else {
|
|
|
jsonObject.put("sleepPlan",true);
|
|
|
String endTime = DateUtil.getNextMin(sleepPlan.getGetUpTime(),-1);
|
|
|
jsonObject.put("getUpTime",sleepPlan.getGetUpTime());
|
|
|
jsonObject.put("siestaTime",sleepPlan.getNapTime());
|
|
|
jsonObject.put("nightRestTime",sleepPlan.getNightRestTime());
|
|
|
jsonObject.put("nightRecordTime",sleepPlan.getNightRestTime()+"-隔日"+endTime);
|
|
|
array.add(jsonObject);
|
|
|
}
|
|
|
}
|
|
|
JSONObject result = (JSONObject) JSONObject.toJSON(list);
|
|
|
result.put("content",array);
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*获取居民起夜记录
|
|
|
*/
|
|
|
public List<BaseSleepNightRecord> getPatientSleepNightRecord(String patient, String day){
|
|
|
|
|
|
List<BaseSleepNightRecord> records = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,day);
|
|
|
return records;
|
|
|
}
|
|
|
|
|
|
private String getRandomIntStr(){
|
|
|
Random rand = new Random();
|
|
|
int i = rand.nextInt(); //int范围类的随机数
|
|
@ -1506,4 +1648,20 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
one.setUpdateUserName(one.getDoctorName());
|
|
|
}
|
|
|
|
|
|
private String getSleepMonitoringDay(Date date,String patient){
|
|
|
List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
|
|
|
if (sleepPlans.size()>0){
|
|
|
BaseSleepPlan sleepPlan = sleepPlans.get(0);
|
|
|
String bedUpStr = sleepPlans.get(0).getGetUpTime();
|
|
|
Date bedUp = DateUtil.strToDate(DateUtil.getStringDateShort()+" "+bedUpStr+":00");// 起床时间 起床前一小时内算为起床
|
|
|
if (date.before(bedUp)&&bedUp.getTime()-date.getTime()>1000*1*3600){
|
|
|
bedUp = DateUtil.getNextDay1(bedUp,-1);
|
|
|
}
|
|
|
String dayTime = DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD);//监测日期
|
|
|
return dayTime;
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|