|
@ -2102,78 +2102,83 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
} 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);
|
|
|
}
|
|
|
List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient, dayTime);
|
|
|
BaseSleepPlanDetail planDetail = new BaseSleepPlanDetail();
|
|
|
if (planDetails.size() > 0) {
|
|
|
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);
|
|
|
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("online")){
|
|
|
sleepInfo.put("contactStatus", 1);
|
|
|
}
|
|
|
else {
|
|
|
sleepInfo.put("contactStatus", 0);
|
|
|
}
|
|
|
if (null!=deviceInfo){
|
|
|
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);
|
|
|
}
|
|
|
List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient, dayTime);
|
|
|
BaseSleepPlanDetail planDetail = new BaseSleepPlanDetail();
|
|
|
if (planDetails.size() > 0) {
|
|
|
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);
|
|
|
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("online")){
|
|
|
sleepInfo.put("contactStatus", 1);
|
|
|
}
|
|
|
else {
|
|
|
sleepInfo.put("contactStatus", 0);
|
|
|
}
|
|
|
|
|
|
|
|
|
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 (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);
|
|
|
}
|
|
|
if (minuteFieldDiff > 0) {
|
|
|
outBedTime += String.format("%d分钟", minuteFieldDiff);
|
|
|
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("outBedTimeCrzq", outBed.getCreateTime());
|
|
|
sleepInfo.put("outBedTime", outBedTime);
|
|
|
} else {
|
|
|
sleepInfo.put("outBedTime", "无");
|
|
|
}
|
|
|
sleepInfo.put("outBedTimeCrzq", outBed.getCreateTime());
|
|
|
sleepInfo.put("outBedTime", outBedTime);
|
|
|
} else {
|
|
|
sleepInfo.put("outBedTime", "无");
|
|
|
result.put("sleepInfo", sleepInfo);
|
|
|
}
|
|
|
result.put("sleepInfo", sleepInfo);
|
|
|
} else {
|
|
|
result.put("sleepStatus", false);
|
|
|
result.put("sleepInfo", "获取睡眠带数据失败");
|
|
|
}
|
|
|
} else {
|
|
|
}else {
|
|
|
result.put("sleepStatus", false);
|
|
|
result.put("sleepInfo", "获取睡眠带数据失败");
|
|
|
}
|