|
@ -5,7 +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.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;
|
|
@ -17,41 +17,43 @@ import com.yihu.jw.care.service.family.PatientFamilyMemberService;
|
|
|
import com.yihu.jw.care.service.sign.ServicePackageService;
|
|
|
import com.yihu.jw.care.util.ConstantUtil;
|
|
|
import com.yihu.jw.care.util.CountDistance;
|
|
|
import com.yihu.jw.care.util.MessageUtil;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
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.*;
|
|
|
import com.yihu.jw.entity.care.securitymonitoring.*;
|
|
|
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
|
|
|
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
|
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
|
import com.yihu.jw.im.dao.ConsultTeamDao;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.restmodel.emergency.EmergencyOrderVO;
|
|
|
import com.yihu.jw.restmodel.web.PageEnvelop;
|
|
|
import com.yihu.jw.util.common.GpsUtil;
|
|
|
import com.yihu.jw.care.util.MessageUtil;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientDevice;
|
|
|
import com.yihu.jw.entity.care.securitymonitoring.*;
|
|
|
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.entity.EntityUtils;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import jdk.management.resource.internal.inst.FileOutputStreamRMHooks;
|
|
|
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;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* Created by Bing on 2021/4/6.
|
|
@ -111,6 +113,16 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
private BaseEmergencyWarnLogDao logDao;
|
|
|
@Autowired
|
|
|
private ContactsService contactsService;
|
|
|
@Autowired
|
|
|
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);
|
|
|
|
|
@ -165,8 +177,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
}
|
|
|
|
|
|
//签约防走失服务包
|
|
|
String sql ="SELECT i.code,i.team_code,i.org_code,i.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i \n" +
|
|
|
"where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and i.del = 1 and sr.`status`=1 \n" +
|
|
|
String sql ="SELECT i.code,r.team_code,pack.org_code,pack.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack \n" +
|
|
|
"where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id and i.del = 1 and sr.`status`=1 \n" +
|
|
|
"and sr.patient = '"+orderDO.getPatient()+"' and i.code='preventLost' ";
|
|
|
List<Map<String,Object>> items = jdbcTemplate.queryForList(sql);
|
|
|
if (items.size()==0) {
|
|
@ -342,8 +354,46 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
//TODO 火灾、燃气、离床专题返回值
|
|
|
// http://192.168.1.103:85/%E5%8C%BB%E5%85%BB%E7%BB%93%E5%90%88/V0.7.0/#g=1&p=%E6%96%B0%E5%AE%89%E9%98%B2%E5%8C%85
|
|
|
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){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
if (6==orderDO.getOrderSource()){//气感工单
|
|
|
try {
|
|
|
JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
|
|
|
monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
|
|
|
emergencyOrderVO.setInformation(monitorInfo);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
if (7==orderDO.getOrderSource()){//烟感工单
|
|
|
try {
|
|
|
JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
|
|
|
monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
|
|
|
emergencyOrderVO.setInformation(monitorInfo);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//通知对象
|
|
|
List<Map<String,Object>> noticePersons = new ArrayList<>();
|
|
@ -377,8 +427,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
noticePersons.add(noticeObj);
|
|
|
}
|
|
|
//医生信息
|
|
|
String sql ="SELECT i.code,i.team_code,i.org_code,i.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i \n" +
|
|
|
"where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and i.del = 1 and sr.`status`=1 \n" +
|
|
|
String sql ="SELECT i.code,r.team_code,pack.org_code,pack.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack \n" +
|
|
|
"where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id and i.del = 1 and sr.`status`=1 \n" +
|
|
|
"and sr.patient = '"+orderDO.getPatient()+"' and i.code='preventLost' ";
|
|
|
List<Map<String,Object>> items = jdbcTemplate.queryForList(sql);
|
|
|
if (items.size()>0){
|
|
@ -410,14 +460,14 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
if (StringUtils.isBlank(doc.getDoctorLat()) || StringUtils.isBlank(doc.getDoctorLon())) {
|
|
|
continue;
|
|
|
}
|
|
|
double distanceTmp = countDistance.getDistance(Double.parseDouble(orderDO.getServeLat()),Double.parseDouble(orderDO.getServeLon()),Double.parseDouble(doc.getDoctorLat()),Double.parseDouble(doc.getDoctorLon()));
|
|
|
//double distanceTmp = countDistance.getDistance(Double.parseDouble(orderDO.getServeLat()),Double.parseDouble(orderDO.getServeLon()),Double.parseDouble(doc.getDoctorLat()),Double.parseDouble(doc.getDoctorLon()));
|
|
|
otherDoctorDistanceObj = new JSONObject();
|
|
|
otherDoctorDistanceObj.put("doctor",doc.getId());
|
|
|
otherDoctorDistanceObj.put("doctorName",doc.getName());
|
|
|
otherDoctorDistanceObj.put("doctorAddress",doc.getDoctorLocateAddress());
|
|
|
otherDoctorDistanceObj.put("doctorLon",doc.getDoctorLon());
|
|
|
otherDoctorDistanceObj.put("doctorLat",doc.getDoctorLat());
|
|
|
otherDoctorDistanceObj.put("distance",distanceTmp);//两点距离
|
|
|
otherDoctorDistanceObj.put("distance",null);//两点距离
|
|
|
otherDoctorDistance.add(otherDoctorDistanceObj);
|
|
|
}
|
|
|
emergencyOrderVO.setOtherDoctorDistance(otherDoctorDistance.toJSONString());
|
|
@ -1157,7 +1207,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
|
|
|
public List<Map<String,Object>> getSecurityServerDoctor(String patient,String topicItem){
|
|
|
//获取患者签约防走失服务的团队
|
|
|
String sql="SELECT DISTINCT i.team_code from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i \n" +
|
|
|
String sql="SELECT DISTINCT r.team_code from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i \n" +
|
|
|
"where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and i.del = 1 and sr.`status`=1 \n" +
|
|
|
"and sr.patient = '"+patient+"' and i.code='"+topicItem+"'";
|
|
|
List<String> teams = jdbcTemplate.queryForList(sql,String.class);
|
|
@ -1166,7 +1216,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
return new ArrayList<>();
|
|
|
}else {
|
|
|
for (String team:teams){
|
|
|
sql = "select DISTINCT doc.id doctor,CONCAT(doc.`name`,\n" +
|
|
|
sql = "select DISTINCT doc.id doctor,doc.name as doctorName,CONCAT(doc.`name`,\n" +
|
|
|
"CASE WHEN doc.doctor_level=1 THEN '(社区医生)' ELSE '(助老员)' END) as name,doc.photo,doc.mobile from base_team_member mem " +
|
|
|
"INNER JOIN base_doctor doc on mem.doctor_code = doc.id and mem.del=1 and mem.team_code='"+team+"'";
|
|
|
List<Map<String,Object>>tmp = jdbcTemplate.queryForList(sql);
|
|
@ -1180,96 +1230,273 @@ 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);
|
|
|
if ((StringUtils.isNotBlank(topicItem)&&"preventLost".equals(topicItem))||StringUtils.isBlank(topicItem)){
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
|
|
|
if (devicePatientDeviceDos.size()==0){
|
|
|
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' and ord.patient='"+patient+"' 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;
|
|
|
}
|
|
|
else {
|
|
|
DevicePatientDevice device = devicePatientDeviceDos.get(0);
|
|
|
result.put("deviceSn",device.getDeviceSn());
|
|
|
try {
|
|
|
JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
|
|
|
if (response!=null){
|
|
|
//定位信息
|
|
|
if (response.containsKey("last_location")&&response.get("last_location")!=null){
|
|
|
JSONObject locationTmp = response.getJSONObject("last_location");
|
|
|
Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
|
|
|
Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
|
|
|
JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
|
|
|
tmp.put("city",response.getString("last_city"));
|
|
|
tmp.put("province",response.getString("last_province"));
|
|
|
tmp.put("address",response.getString("last_address"));
|
|
|
result.put("location",tmp);
|
|
|
}
|
|
|
//围栏信息
|
|
|
if (response.containsKey("fences")&&response.get("fences")!=null){
|
|
|
JSONArray fencesArr = response.getJSONArray("fences");
|
|
|
JSONArray fencesEnables = new JSONArray();
|
|
|
for (int i=0;i<fencesArr.size();i++){
|
|
|
JSONObject tmp = fencesArr.getJSONObject(i);
|
|
|
if (tmp.getBooleanValue("enable")){//围栏生效
|
|
|
JSONObject fenceTmp = new JSONObject();
|
|
|
fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
|
|
|
fenceTmp.put("name",tmp.getString("name"));
|
|
|
JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
|
|
|
JSONArray fenceLocation = new JSONArray();
|
|
|
for (int j=0;j<fenceLocationTmp.size();j++){
|
|
|
Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
|
|
|
Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
|
|
|
JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
|
|
|
fenceLocation.add(positionTmp);
|
|
|
}
|
|
|
fenceTmp.put("location",fenceLocation);
|
|
|
fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
|
|
|
fencesEnables.add(fenceTmp);
|
|
|
}
|
|
|
}
|
|
|
if (fencesEnables.size()>0){
|
|
|
result.put("fences",fencesEnables);
|
|
|
}
|
|
|
result = patientSignTopicInfo(result,patient,topicItem);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public void preventLost(JSONObject result,String patient){
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
|
|
|
if (devicePatientDeviceDos.size()==0){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
DevicePatientDevice device = devicePatientDeviceDos.get(0);
|
|
|
result.put("deviceSn",device.getDeviceSn());
|
|
|
try {
|
|
|
JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
|
|
|
if (response!=null){
|
|
|
//定位信息
|
|
|
if (response.containsKey("last_location")&&response.get("last_location")!=null){
|
|
|
JSONObject locationTmp = response.getJSONObject("last_location");
|
|
|
Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
|
|
|
Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
|
|
|
JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
|
|
|
tmp.put("city",response.getString("last_city"));
|
|
|
tmp.put("province",response.getString("last_province"));
|
|
|
tmp.put("address",response.getString("last_address"));
|
|
|
result.put("location",tmp);
|
|
|
}
|
|
|
//围栏信息
|
|
|
if (response.containsKey("fences")&&response.get("fences")!=null){
|
|
|
JSONArray fencesArr = response.getJSONArray("fences");
|
|
|
JSONArray fencesEnables = new JSONArray();
|
|
|
for (int i=0;i<fencesArr.size();i++){
|
|
|
JSONObject tmp = fencesArr.getJSONObject(i);
|
|
|
if (tmp.getBooleanValue("enable")){//围栏生效
|
|
|
JSONObject fenceTmp = new JSONObject();
|
|
|
fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
|
|
|
fenceTmp.put("name",tmp.getString("name"));
|
|
|
JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
|
|
|
JSONArray fenceLocation = new JSONArray();
|
|
|
for (int j=0;j<fenceLocationTmp.size();j++){
|
|
|
Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
|
|
|
Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
|
|
|
JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
|
|
|
fenceLocation.add(positionTmp);
|
|
|
}
|
|
|
fenceTmp.put("location",fenceLocation);
|
|
|
fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
|
|
|
fencesEnables.add(fenceTmp);
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
result.put("location",null);
|
|
|
if (fencesEnables.size()>0){
|
|
|
result.put("fences",fencesEnables);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
result.put("location",null);
|
|
|
}
|
|
|
if ((StringUtils.isNotBlank(topicItem)&&"preventFall".equals(topicItem))||StringUtils.isBlank(topicItem)){
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
|
|
|
if (devicePatientDeviceDos.size()==0){
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
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);
|
|
|
}
|
|
|
try {
|
|
|
JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,devicePatientDeviceDos.get(0).getDeviceSn(),1,null);
|
|
|
result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
|
|
|
result.put("patientAddress",devicePatientDeviceDos.get(0).getSosAddress());
|
|
|
if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
|
|
|
result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
|
|
|
public void preventOutOfBed(JSONObject result,String patient,boolean video,String dayTime){
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
|
|
|
if (devicePatientDeviceDos.size()==0){}
|
|
|
else {
|
|
|
DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
|
|
|
JSONObject deviceInfo = patientDeviceService.getSleepDeviceInfo(deviceDo.getDeviceSn());
|
|
|
if(deviceInfo.getBooleanValue("success")){
|
|
|
result.put("patientAddress",deviceDo.getSosAddress());
|
|
|
JSONArray objInfo = deviceInfo.getJSONArray("objs");
|
|
|
if (objInfo.size()>0){
|
|
|
result.put("sleepStatus",true);
|
|
|
JSONObject tmp = objInfo.getJSONObject(0);
|
|
|
JSONObject sleepInfo = new JSONObject();
|
|
|
if (StringUtils.isBlank(dayTime)){
|
|
|
dayTime = getSleepMonitoringDay(new Date(),patient);
|
|
|
}
|
|
|
else {
|
|
|
result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
|
|
|
List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient,dayTime);
|
|
|
if (planDetails.size()>0){
|
|
|
BaseSleepPlanDetail planDetail = planDetails.get(0);
|
|
|
List<BaseSleepNightRecord> sleepNightRecordList = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,dayTime);
|
|
|
planDetail.setSleepNightRecordList(sleepNightRecordList);
|
|
|
String jsonStr = JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
|
|
|
sleepInfo = JSONObject.parseObject(jsonStr);
|
|
|
sleepInfo.put("day",dayTime);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
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"));
|
|
|
if(tmp.getBooleanValue("onbed")){
|
|
|
sleepInfo.put("bedStatus",1);
|
|
|
sleepInfo.put("heartRate",tmp.getString("heartrate"));
|
|
|
sleepInfo.put("breath",tmp.getString("breathrate"));
|
|
|
}else {
|
|
|
sleepInfo.put("bedStatus",0);
|
|
|
sleepInfo.put("heartRate",null);
|
|
|
sleepInfo.put("breath",null);
|
|
|
}
|
|
|
BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
|
|
|
if (null!=outBed){
|
|
|
String outBedTime = "";
|
|
|
Date date = new Date();
|
|
|
long millisecondsDiff = date.getTime() - outBed.getCreateTime().getTime();
|
|
|
long minutesDiff = millisecondsDiff / TimeUnit.MINUTES.toMillis(1L);
|
|
|
long hoursDiff = millisecondsDiff / TimeUnit.HOURS.toMillis(1L);
|
|
|
long minuteFieldDiff = minutesDiff - TimeUnit.HOURS.toMinutes(hoursDiff);
|
|
|
if (hoursDiff > 0L) {
|
|
|
outBedTime += String.format("%d小时", hoursDiff);
|
|
|
}
|
|
|
if (minuteFieldDiff>0){
|
|
|
outBedTime +=String.format("%d分钟", minuteFieldDiff);
|
|
|
}
|
|
|
sleepInfo.put("outBedTime",outBedTime);
|
|
|
}else {
|
|
|
sleepInfo.put("outBedTime","无");
|
|
|
}
|
|
|
result.put("sleepInfo",sleepInfo);
|
|
|
}
|
|
|
}else {
|
|
|
result.put("sleepStatus",false);
|
|
|
result.put("sleepInfo","获取睡眠带数据失败");
|
|
|
}
|
|
|
}
|
|
|
if (video){
|
|
|
monitorInfo(result, 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";
|
|
|
|
|
|
List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql);
|
|
|
if(list1.size()==0){
|
|
|
result.put("smoke","-1");
|
|
|
}else{
|
|
|
result.put("smoke",list1.get(0).get("value"));
|
|
|
}
|
|
|
result.put("smokeOrderNum",getOrder(patient,"preventFire"));
|
|
|
if (video){
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Integer getOrder(String patient,String topicItem){
|
|
|
String sql = "select count(1) from base_security_monitoring_order " +
|
|
|
"WHERE patient = '"+patient+"' and `status` = 1 and topic_item = '"+topicItem+"'";
|
|
|
Integer num = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
return num;
|
|
|
}
|
|
|
|
|
|
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";
|
|
|
|
|
|
List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql);
|
|
|
if(list1.size()==0){
|
|
|
result.put("methane","-1");
|
|
|
}else{
|
|
|
result.put("methane",list1.get(0).get("value"));
|
|
|
}
|
|
|
result.put("methaneOrderNum",getOrder(patient,"preventGasLeakage"));
|
|
|
if (video){
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void monitorInfo(JSONObject result,String patient){
|
|
|
//监控
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
|
|
|
if (devicePatientDeviceDos.size()==0){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
|
|
|
JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
|
|
|
result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
|
|
|
result.put("patientAddress",deviceDo.getSosAddress());
|
|
|
if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
|
|
|
result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
|
|
|
}
|
|
|
else {
|
|
|
result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem){
|
|
|
if (null==result){
|
|
|
result = new JSONObject();
|
|
|
}
|
|
|
if ("preventLost".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventLost(result, patient);
|
|
|
}
|
|
|
if ("preventFall".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
monitorInfo(result, patient);
|
|
|
}
|
|
|
if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventOutOfBed(result, patient,true,null);
|
|
|
}
|
|
|
if ("preventFire".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventFire(result, patient,true);
|
|
|
}
|
|
|
if ("preventGasLeakage".equals(topicItem)||StringUtils.isBlank(topicItem)){
|
|
|
preventGasLeakage(result, patient,true);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@ -1353,6 +1580,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范围类的随机数
|
|
@ -1367,4 +1654,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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|