|
@ -24,6 +24,7 @@ import com.yihu.wlyy.repository.patient.*;
|
|
import com.yihu.wlyy.service.BaseService;
|
|
import com.yihu.wlyy.service.BaseService;
|
|
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
|
|
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
|
|
import com.yihu.wlyy.service.app.team.AdminTeamService;
|
|
import com.yihu.wlyy.service.app.team.AdminTeamService;
|
|
|
|
import com.yihu.wlyy.service.third.iot.IotDeviceService;
|
|
import com.yihu.wlyy.service.third.jw.JwSmjkService;
|
|
import com.yihu.wlyy.service.third.jw.JwSmjkService;
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
@ -103,6 +104,8 @@ public class PatientDeviceService extends BaseService {
|
|
@Autowired
|
|
@Autowired
|
|
private PatientEventDao patientEventDao;
|
|
private PatientEventDao patientEventDao;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
private IotDeviceService iotDeviceService;
|
|
|
|
@Autowired
|
|
private Icd10DictDao icd10DictDao;
|
|
private Icd10DictDao icd10DictDao;
|
|
|
|
|
|
Map<Integer, String> relations = new HashMap<>();
|
|
Map<Integer, String> relations = new HashMap<>();
|
|
@ -152,42 +155,41 @@ public class PatientDeviceService extends BaseService {
|
|
* 保存患者设备
|
|
* 保存患者设备
|
|
*/
|
|
*/
|
|
public boolean saveDevice(PatientDevice patientDevice) throws Exception {
|
|
public boolean saveDevice(PatientDevice patientDevice) throws Exception {
|
|
synchronized (patientDevice.getDeviceSn()) {
|
|
|
|
//判断sn码是否被使用
|
|
|
|
String sn = patientDevice.getDeviceSn();
|
|
|
|
String type = patientDevice.getCategoryCode();
|
|
|
|
Long deviceId = patientDevice.getDeviceId();
|
|
|
|
String userType = patientDevice.getUserType();
|
|
|
|
if (userType == null) {
|
|
|
|
userType = "-1";
|
|
|
|
patientDevice.setUserType("-1");
|
|
|
|
}
|
|
|
|
|
|
//判断sn码是否被使用
|
|
|
|
String sn = patientDevice.getDeviceSn();
|
|
|
|
String type = patientDevice.getCategoryCode();
|
|
|
|
Long deviceId = patientDevice.getDeviceId();
|
|
|
|
String userType = patientDevice.getUserType();
|
|
|
|
if (userType == null) {
|
|
|
|
userType = "-1";
|
|
|
|
patientDevice.setUserType("-1");
|
|
|
|
}
|
|
|
|
|
|
boolean needVerify = true;
|
|
|
|
//修改操作
|
|
|
|
if (patientDevice.getId() != null) {
|
|
|
|
PatientDevice deviceOld = patientDeviceDao.findOne(patientDevice.getId());
|
|
|
|
if (deviceOld != null) {
|
|
|
|
if (deviceOld.getDeviceSn().equals(sn)) {
|
|
|
|
needVerify = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Exception("不存在该条记录!");
|
|
|
|
|
|
boolean needVerify = true;
|
|
|
|
//修改操作
|
|
|
|
if (patientDevice.getId() != null) {
|
|
|
|
PatientDevice deviceOld = patientDeviceDao.findOne(patientDevice.getId());
|
|
|
|
if (deviceOld != null) {
|
|
|
|
if (deviceOld.getDeviceSn().equals(sn)) {
|
|
|
|
needVerify = false;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Exception("不存在该条记录!");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//校验sn码是否被使用
|
|
|
|
if (needVerify) {
|
|
|
|
|
|
//校验sn码是否被使用
|
|
|
|
if (needVerify) {
|
|
// PatientDevice device = patientDeviceDao.findByDeviceIdAndDeviceSnAndUserType(deviceId, sn, userType);
|
|
// PatientDevice device = patientDeviceDao.findByDeviceIdAndDeviceSnAndUserType(deviceId, sn, userType);
|
|
PatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
|
|
|
|
if (device != null && !device.getId().equals(patientDevice.getId())) {
|
|
|
|
throw new Exception("sn码" + sn + "已被使用!");
|
|
|
|
}
|
|
|
|
|
|
PatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
|
|
|
|
if (device != null && !device.getId().equals(patientDevice.getId())) {
|
|
|
|
throw new Exception("sn码" + sn + "已被使用!");
|
|
}
|
|
}
|
|
patientDevice.setCzrq(clock.getCurrentDate());
|
|
|
|
//当前用户的身份证
|
|
|
|
Patient patient = patientDao.findByCode(patientDevice.getUser());
|
|
|
|
patientDevice.setUserIdcard(patient.getIdcard());
|
|
|
|
|
|
}
|
|
|
|
patientDevice.setCzrq(clock.getCurrentDate());
|
|
|
|
//当前用户的身份证
|
|
|
|
Patient patient = patientDao.findByCode(patientDevice.getUser());
|
|
|
|
patientDevice.setUserIdcard(patient.getIdcard());
|
|
|
|
|
|
// //注册设备
|
|
// //注册设备
|
|
// Map<String, String> params = new HashMap<>();
|
|
// Map<String, String> params = new HashMap<>();
|
|
@ -205,15 +207,28 @@ public class PatientDeviceService extends BaseService {
|
|
// String message = json.get("Message").toString();
|
|
// String message = json.get("Message").toString();
|
|
// throw new Exception(message);
|
|
// throw new Exception(message);
|
|
// }
|
|
// }
|
|
if(checkDeviceSn(sn)){
|
|
|
|
patientDeviceDao.save(patientDevice);
|
|
|
|
}else {
|
|
|
|
String message = "设备不存在";
|
|
|
|
throw new Exception(message);
|
|
|
|
}
|
|
|
|
|
|
if(checkDeviceSn(sn)){
|
|
|
|
// patientDeviceDao.save(patientDevice);
|
|
|
|
savePatientDevice(patientDevice,patient.getAddress(),patient.getName());
|
|
|
|
}else {
|
|
|
|
String message = "设备不存在";
|
|
|
|
throw new Exception(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
/**
|
|
|
|
* 设备绑定
|
|
|
|
* @param patientDevice
|
|
|
|
*/
|
|
|
|
public void savePatientDevice(PatientDevice patientDevice,String address,String patientName){
|
|
|
|
if(iotDeviceService.isUploadIot()){
|
|
|
|
iotDeviceService.saveDevice(patientDevice,address,patientName);
|
|
|
|
}else {
|
|
|
|
patientDeviceDao.save(patientDevice);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@ -727,6 +742,9 @@ public class PatientDeviceService extends BaseService {
|
|
sql.append("WHERE m.type = 2 ORDER BY m.id desc LIMIT ?,?");
|
|
sql.append("WHERE m.type = 2 ORDER BY m.id desc LIMIT ?,?");
|
|
|
|
|
|
List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
|
|
List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
|
|
|
|
list.forEach(json->{
|
|
|
|
json.put("value2Name",getTypeName(json.getString("tz_type"),json.getString("value2")));
|
|
|
|
});
|
|
|
|
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
@ -986,4 +1004,43 @@ public class PatientDeviceService extends BaseService {
|
|
});
|
|
});
|
|
return mapList;
|
|
return mapList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 名字转换
|
|
|
|
* @param type
|
|
|
|
* @param value
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private String getTypeName(String type,String value){
|
|
|
|
String name = "";
|
|
|
|
//1早餐前、2早餐后、3午餐前、4午餐后、5晚餐前 6晚餐后 7睡前)
|
|
|
|
if ("1".equals(type)){
|
|
|
|
switch (value){
|
|
|
|
case "1":
|
|
|
|
name = "早餐前";
|
|
|
|
break;
|
|
|
|
case "2":
|
|
|
|
name = "早餐后";
|
|
|
|
break;
|
|
|
|
case "3":
|
|
|
|
name = "午餐前";
|
|
|
|
break;
|
|
|
|
case "4":
|
|
|
|
name = "午餐后";
|
|
|
|
break;
|
|
|
|
case "5":
|
|
|
|
name = "晚餐前";
|
|
|
|
break;
|
|
|
|
case "6":
|
|
|
|
name = "晚餐后";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
name = "睡前";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
name = "舒张压";
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
}
|
|
}
|