|
@ -337,6 +337,67 @@ public class DeviceService {
|
|
|
return response.getBody();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 三诺设备数据上传
|
|
|
* @param type //设备类型2:血压 1:血糖
|
|
|
* @param json
|
|
|
* @return
|
|
|
*/
|
|
|
public Result threeNodeUpload(String type,JSONObject json){
|
|
|
try {
|
|
|
String deviceSn = "";//设备唯一码
|
|
|
String data = "";//体征值(血糖:data=血糖值 血压:data=收缩压,舒张压,脉搏)
|
|
|
String uploadTime = "";//体征上传时间yyyy-MM-dd HH:mm:ss
|
|
|
String userType = "";//按键号 即 userType
|
|
|
|
|
|
if ("1".equals(type)) {
|
|
|
userType = "-1";
|
|
|
deviceSn = json.getString("devid");//设备唯一码
|
|
|
data = json.getString("bloodGlu");//体征值(血糖:data=血糖值 血压:data=收缩压,舒张压,脉搏)
|
|
|
uploadTime = json.getString("testTime");//体征上传时间yyyy-MM-dd HH:mm:ss
|
|
|
uploadTime = DateUtil.formatDate(DateUtil.formatCharDateYMD(uploadTime,DateUtil.yyyyMMddHHmmss),DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
|
|
|
}else {
|
|
|
userType = json.getString("user");
|
|
|
deviceSn = json.getString("imei");//设备唯一码
|
|
|
data = json.getString("sys")+","+json.getString("dia");//体征值(血糖:data=血糖值 血压:data=收缩压,舒张压,脉搏)
|
|
|
if(json.get("pul")==null){
|
|
|
data += ","+json.getString("pul");
|
|
|
}
|
|
|
if(json.get("ano")==null){
|
|
|
data += ","+json.getString("ano");
|
|
|
}
|
|
|
uploadTime = json.getString("time").replace("/"," ");//体征上传时间yyyy-MM-dd HH:mm:ss
|
|
|
}
|
|
|
|
|
|
PatientHealthIndex result = savePatientDeviceData(deviceSn, type, data, uploadTime, userType, json);
|
|
|
if (result == null) {
|
|
|
throw new Exception("This device is not relate patient!");
|
|
|
} else {
|
|
|
//患者信息
|
|
|
String patientCode = result.getUser();
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
|
|
|
//血糖、血压数据需校验,如果超标,需要发送消息给医生
|
|
|
verifyHealthIndex(result);
|
|
|
//发送华三demo推送
|
|
|
|
|
|
//判断是否有未结束的续方咨询,发送消息给对应的医生----huangwenjie--2017.11.06
|
|
|
sendPrescriptionHealthIndexMsgresult(result,patient);
|
|
|
|
|
|
//指标数据上传基卫
|
|
|
uploadHealthIndex(result);
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
|
yujing(patientCode,patient);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
return Result.success("Device data incoming success");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 福州设备数据上传接口(标准协议)
|
|
|
*
|
|
@ -382,19 +443,14 @@ public class DeviceService {
|
|
|
userType = "-1";
|
|
|
}
|
|
|
|
|
|
PatientHealthIndex result = savePatientDeviceData(deviceSn, type, data, uploadTime, manufacturerCode, manufacturerName, unit, sendTime, userType, json);
|
|
|
PatientHealthIndex result = savePatientDeviceData(deviceSn, type, data, uploadTime, userType, json);
|
|
|
if (result == null) {
|
|
|
throw new Exception("This device is not relate patient!");
|
|
|
} else {
|
|
|
|
|
|
//患者信息
|
|
|
String patientCode = result.getUser();
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
|
|
|
String patientsql = "select group_concat(label) disease from wlyy.wlyy_sign_patient_label_info where label_type = 3 and status=1 and (label = 1 or label = 2) and patient = '"+patient.getCode()+"' GROUP BY patient";
|
|
|
|
|
|
String patientdisease = jdbcTemplate.queryForObject(patientsql,String.class);
|
|
|
|
|
|
//血糖、血压数据需校验,如果超标,需要发送消息给医生
|
|
|
if (1 == deviceType || 2 == deviceType) {
|
|
|
verifyHealthIndex(result);
|
|
@ -410,79 +466,92 @@ public class DeviceService {
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
|
yujing(patientCode,patient);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
//连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
|
|
|
return Result.success("Device data incoming success");
|
|
|
}
|
|
|
|
|
|
int bloodPressureBbnormalCount = 0;//血压异常次数
|
|
|
int bloodSuggurBbnormalCount = 0;//血糖异常次数
|
|
|
/**
|
|
|
* 预警
|
|
|
* @param patientCode
|
|
|
* @param patient
|
|
|
*/
|
|
|
public void yujing(String patientCode,Patient patient){
|
|
|
try{
|
|
|
String patientsql = "select group_concat(label) disease from wlyy.wlyy_sign_patient_label_info where label_type = 3 and status=1 and (label = 1 or label = 2) and patient = '"+patient.getCode()+"' GROUP BY patient";
|
|
|
|
|
|
List<PatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
|
|
|
List<PatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
|
|
|
String patientdisease = jdbcTemplate.queryForObject(patientsql,String.class);
|
|
|
|
|
|
bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,2);
|
|
|
bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,1);
|
|
|
//连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----START
|
|
|
|
|
|
for (PatientHealthIndex index1 : bloodPressurepatientHealthIndices) {
|
|
|
if(index1.getStatus() != null && 1 == index1.getStatus()){
|
|
|
bloodPressureBbnormalCount++;
|
|
|
}
|
|
|
}
|
|
|
int bloodPressureBbnormalCount = 0;//血压异常次数
|
|
|
int bloodSuggurBbnormalCount = 0;//血糖异常次数
|
|
|
|
|
|
for (PatientHealthIndex index2 : bloodSuggurpatientHealthIndices) {
|
|
|
if(index2.getStatus() != null && 1 == index2.getStatus()){
|
|
|
bloodSuggurBbnormalCount++;
|
|
|
}
|
|
|
}
|
|
|
List<PatientHealthIndex> bloodPressurepatientHealthIndices = new ArrayList<>();
|
|
|
List<PatientHealthIndex> bloodSuggurpatientHealthIndices = new ArrayList<>();
|
|
|
|
|
|
bloodPressurepatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,2);
|
|
|
bloodSuggurpatientHealthIndices = patientHealthIndexDao.findByPatientAndTypeByPage(patientCode,1);
|
|
|
|
|
|
//连续3次异常,修改用户为预警状态
|
|
|
if( (bloodPressureBbnormalCount >=3 || bloodSuggurBbnormalCount >=3) && (patient.getStandardStatus() == null || 0 == patient.getStandardStatus())){
|
|
|
for (PatientHealthIndex index1 : bloodPressurepatientHealthIndices) {
|
|
|
if(index1.getStatus() != null && 1 == index1.getStatus()){
|
|
|
bloodPressureBbnormalCount++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (PatientHealthIndex index2 : bloodSuggurpatientHealthIndices) {
|
|
|
if(index2.getStatus() != null && 1 == index2.getStatus()){
|
|
|
bloodSuggurBbnormalCount++;
|
|
|
}
|
|
|
}
|
|
|
//连续3次异常,修改用户为预警状态
|
|
|
if( (bloodPressureBbnormalCount >=3 || bloodSuggurBbnormalCount >=3) && (patient.getStandardStatus() == null || 0 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(1);
|
|
|
}else{
|
|
|
Date end = new Date();
|
|
|
Date start = DateUtil.setDateTime(end,-7);
|
|
|
//计算血糖或者血压一周内的异常记录数量
|
|
|
int errorCount = patientHealthIndexDao.getCountByTimeAndStatus(start,end,1,patientCode);
|
|
|
if(errorCount >= 5){//超过5次,记为预警状态
|
|
|
patient.setStandardStatus(1);
|
|
|
}else{
|
|
|
Date end = new Date();
|
|
|
Date start = DateUtil.setDateTime(end,-7);
|
|
|
//计算血糖或者血压一周内的异常记录数量
|
|
|
int errorCount = patientHealthIndexDao.getCountByTimeAndStatus(start,end,1,patientCode);
|
|
|
if(errorCount >= 5){//超过5次,记为预警状态
|
|
|
patient.setStandardStatus(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//连续5次正常,修改用户为非预警状态
|
|
|
if(StringUtils.isNotBlank(patientdisease)){
|
|
|
if("1".equals(patientdisease)){
|
|
|
if(0 == bloodPressureBbnormalCount && (patient.getStandardStatus() == null || 1 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
}else if("2".equals(patientdisease)){
|
|
|
if(0 == bloodSuggurBbnormalCount && (patient.getStandardStatus() == null || 1 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
}else if( "1,2".equals(patientdisease) || "2,1".equals(patientdisease)){
|
|
|
if( 0 == bloodSuggurBbnormalCount && 0 == bloodPressureBbnormalCount && (patient.getStandardStatus() == null || 1 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//连续5次正常,修改用户为非预警状态
|
|
|
if(StringUtils.isNotBlank(patientdisease)){
|
|
|
if("1".equals(patientdisease)){
|
|
|
if(0 == bloodPressureBbnormalCount && (patient.getStandardStatus() == null || 1 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
}else if("2".equals(patientdisease)){
|
|
|
if(0 == bloodSuggurBbnormalCount && (patient.getStandardStatus() == null || 1 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
}else if( "1,2".equals(patientdisease) || "2,1".equals(patientdisease)){
|
|
|
if( 0 == bloodSuggurBbnormalCount && 0 == bloodPressureBbnormalCount && (patient.getStandardStatus() == null || 1 == patient.getStandardStatus())){
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
}else{
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
|
|
|
patientDao.save(patient);
|
|
|
//连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
|
|
|
}else{
|
|
|
patient.setStandardStatus(0);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
patientDao.save(patient);
|
|
|
//连续5次体征值正常,则修改为非预警状态;连续5次异常,修改为预警状态-----END
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
return Result.success("Device data incoming success");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 保存设备数据
|
|
|
*/
|
|
|
public PatientHealthIndex savePatientDeviceData(String deviceSn, String type, String data, String uploadTime, String manufacturerCode
|
|
|
, String manufacturerName, String unit, String sendTime, String userType, JSONObject json) throws Exception {
|
|
|
public PatientHealthIndex savePatientDeviceData(String deviceSn, String type, String data, String uploadTime, String userType, JSONObject json) throws Exception {
|
|
|
Date currentTime = DateUtil.getSysDateTime();
|
|
|
Date time = currentTime;
|
|
|
if (!StringUtil.isEmpty(uploadTime)) {
|