|
@ -15,7 +15,6 @@ import com.yihu.jw.hospital.module.health.service.PatientHealthIndexService;
|
|
|
import com.yihu.jw.hospital.module.wx.dao.WechatTemplateConfigDao;
|
|
|
import com.yihu.jw.hospital.task.PushMsgTask;
|
|
|
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.jw.message.dao.MessageDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.entity.ServiceException;
|
|
@ -33,7 +32,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 患者端:设备管理控制类
|
|
@ -66,17 +68,20 @@ public class PatientDeviceController extends BaseController {
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
@Autowired
|
|
|
private PatientDeviceLogService patientDeviceLogService;
|
|
|
@Autowired
|
|
|
private MessageDao messageDao;
|
|
|
|
|
|
private ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
@ApiOperation("获取居民标准体征预警值")
|
|
|
@RequestMapping(value = "getDeviceStandard", method = RequestMethod.GET)
|
|
|
public String getDeviceStandard(@ApiParam(name = "type", value = "类型1血糖,2血压", defaultValue = "1")
|
|
|
public String getDeviceStandard(@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId,
|
|
|
@ApiParam(name = "type", value = "类型1血糖,2血压", defaultValue = "1")
|
|
|
@RequestParam(value = "type", required = true) Integer type){
|
|
|
try {
|
|
|
JSONObject json = patientHealthIndexService.getealthStandard(type,getRepUID());
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
JSONObject json = patientHealthIndexService.getealthStandard(type,patientId);
|
|
|
return write(200,"获取成功","data",json);
|
|
|
} catch (Exception ex) {
|
|
|
error(ex);
|
|
@ -116,14 +121,18 @@ public class PatientDeviceController extends BaseController {
|
|
|
@RequestParam String deviceSN,
|
|
|
@RequestParam String categoryCode,
|
|
|
@RequestParam String userType,
|
|
|
@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId,
|
|
|
@RequestParam(required = false) String newDeviceSN,
|
|
|
@RequestParam(required = false) String hospital,
|
|
|
@RequestParam(required = false) String hospitalName,
|
|
|
@RequestParam(required = false) String checkDoctorName) {
|
|
|
|
|
|
try {
|
|
|
// String user = getUID();
|
|
|
String user = getRepUID();
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
String user = patientId;
|
|
|
|
|
|
if (StringUtils.isNotEmpty(newDeviceSN)) {
|
|
|
// 校验新的sn码 1.是否被占用 2.是否是真的设备码
|
|
@ -133,10 +142,6 @@ public class PatientDeviceController extends BaseController {
|
|
|
if (device != null) {
|
|
|
throw new Exception("sn码" + newDeviceSN + "已被使用!");
|
|
|
}
|
|
|
|
|
|
// if(!patientDeviceService.checkDeviceSn(newDeviceSN)){
|
|
|
// return error(-1,"设备不存在");
|
|
|
// }
|
|
|
}
|
|
|
if ("1".equals(categoryCode)) {
|
|
|
// 先修改患者设备绑定表
|
|
@ -174,19 +179,22 @@ public class PatientDeviceController extends BaseController {
|
|
|
@RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
|
|
|
public String saveDevice(@ApiParam(name = "json", value = "设备数据json", defaultValue = "{\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"06B52305030267\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
|
|
|
@RequestParam(value = "json", required = true) String json,
|
|
|
@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId,
|
|
|
@ApiParam(name="isScan",value="是否扫一扫 1是0否,默认否",required = false)
|
|
|
@RequestParam(value="isScan",required = false) String isScan) {
|
|
|
try {
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
DevicePatientDevice device = objectMapper.readValue(json, DevicePatientDevice.class);
|
|
|
if(StringUtils.isBlank(device.getDeviceSn())){
|
|
|
return write(-1,"sn码不能为空!");
|
|
|
}
|
|
|
// 设置患者标识
|
|
|
if(StringUtils.isBlank(device.getUser())){
|
|
|
device.setUser(getRepUID());
|
|
|
device.setUser(patientId);
|
|
|
}
|
|
|
|
|
|
// device.setUser(getUID());
|
|
|
//患者和设备是否首绑
|
|
|
Map<String,Object> checkMap = patientDeviceService.checkBindingFirstAndType(device);
|
|
|
boolean flag = (Boolean)checkMap.get("flag");
|
|
@ -195,11 +203,11 @@ public class PatientDeviceController extends BaseController {
|
|
|
return write(-1,"设备不存在或者数据存在错误!");
|
|
|
}
|
|
|
|
|
|
BasePatientDO patient = patientService.findById(getRepUID()).orElse(null);
|
|
|
if(!getUID().equals(getRepUID())&&device.getId()==null){
|
|
|
device.setAgent(getRepUID());
|
|
|
device.setAgentName(patient.getName());
|
|
|
}
|
|
|
BasePatientDO patient = patientService.findById(patientId).orElse(null);
|
|
|
// if(!getUID().equals(patientId)&&device.getId()==null){
|
|
|
// device.setAgent(patientId);
|
|
|
// device.setAgentName(patient.getName());
|
|
|
// }
|
|
|
String sn = device.getDeviceSn();
|
|
|
synchronized (sn.intern()){
|
|
|
patientDeviceService.saveDevice(device,isScan);
|
|
@ -252,10 +260,15 @@ public class PatientDeviceController extends BaseController {
|
|
|
@RequestMapping(value = "PatientDeviceList", method = RequestMethod.GET)
|
|
|
public String getDeviceByPatient(@ApiParam(name = "id", value = "分页起始id", defaultValue = "0")
|
|
|
@RequestParam(value = "id", required = true) long id,
|
|
|
@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId,
|
|
|
@ApiParam(name = "pagesize", value = "每页条数", defaultValue = "10")
|
|
|
@RequestParam(value = "pagesize", required = true) int pagesize) {
|
|
|
try {
|
|
|
Page<DevicePatientDevice> list = patientDeviceService.findByPatient(getRepUID(), id, pagesize);
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
Page<DevicePatientDevice> list = patientDeviceService.findByPatient(patientId, id, pagesize);
|
|
|
|
|
|
return write(200, "查询成功", "data", list);
|
|
|
} catch (Exception ex) {
|
|
@ -293,13 +306,15 @@ public class PatientDeviceController extends BaseController {
|
|
|
@RequestMapping(value = "PatientDeviceIdcard", method = RequestMethod.GET)
|
|
|
public String getDeviceUser(@ApiParam(name = "type", value = "设备类型", defaultValue = "1")
|
|
|
@RequestParam(value = "type", required = true) String type,
|
|
|
@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId,
|
|
|
@ApiParam(name = "device_sn", value = "设备SN码", defaultValue = "15L000002")
|
|
|
@RequestParam(value = "device_sn", required = true) String deviceSn) {
|
|
|
try {
|
|
|
// if (!"11".equals(type)&&deviceDetailService.findByDeviceSn(deviceSn)==null){
|
|
|
// return write(-1,"设备不存在!");
|
|
|
// }
|
|
|
List<Map<String, String>> list = patientDeviceService.getDeviceUser(getRepUID(), deviceSn, type);
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
List<Map<String, String>> list = patientDeviceService.getDeviceUser(patientId, deviceSn, type);
|
|
|
return write(200, "获取设备绑定信息成功!", "data", list);
|
|
|
} catch (Exception ex) {
|
|
|
error(ex);
|
|
@ -314,50 +329,27 @@ public class PatientDeviceController extends BaseController {
|
|
|
@RequestMapping(value = "sendDeviceReviewMessage",method = RequestMethod.POST)
|
|
|
public String sendDeviceReviewMessage(@ApiParam(name = "id", value = "删除设备关联ID")
|
|
|
@RequestParam(value = "id", required = true) String id,
|
|
|
@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId,
|
|
|
@ApiParam(name = "reson", value = "解绑理由")
|
|
|
@RequestParam(value = "reson", required = true) String reson){
|
|
|
try {
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
DevicePatientDevice pd = patientDeviceService.findById(id);
|
|
|
if (pd != null) {
|
|
|
// if (!StringUtils.equals(pd.getUser(), getUID())) {
|
|
|
if (!StringUtils.equals(pd.getUser(), getRepUID())) {
|
|
|
if (!StringUtils.equals(pd.getUser(), patientId)) {
|
|
|
return error(-1, "只允许删除自己的设备!");
|
|
|
}
|
|
|
//居民自主解绑设备时发送消息给医生
|
|
|
BasePatientDO patient = patientService.findById(getRepUID()).orElse(null);
|
|
|
BasePatientDO patient = patientService.findById(patientId).orElse(null);
|
|
|
String messageContent = "您的居民"+patient.getName()+"申请解绑智能设备:"+pd.getDeviceName()+",请及时处理";
|
|
|
// if ("1".equals(pd.getCategoryCode())){
|
|
|
// messageContent +="血糖仪,点击下方查看居民详情";
|
|
|
// }else if ("2".equals(pd.getCategoryCode())){
|
|
|
// messageContent +="血压计,点击下方查看居民详情";
|
|
|
// }else if ("4".equals(pd.getCategoryCode())){
|
|
|
// messageContent +="智能手表,点击下方查看居民详情";
|
|
|
// }
|
|
|
|
|
|
|
|
|
JSONObject contentObj = new JSONObject();
|
|
|
contentObj.put("reason",reson);
|
|
|
contentObj.put("messageContent",messageContent);
|
|
|
contentObj.put("patientName",patient.getName());
|
|
|
|
|
|
/* Message message = new Message();
|
|
|
message.setCzrq(new Date());
|
|
|
message.setCreateTime(new Date());
|
|
|
message.setContent(contentObj.toString());
|
|
|
message.setRead(1);//设置未读
|
|
|
message.setReceiver(signFamily.getDoctor());//设置接受医生的code
|
|
|
message.setSender("admin");//设置发送的用户
|
|
|
message.setSenderName("系统");
|
|
|
message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
message.setSenderPhoto("");
|
|
|
message.setTitle("解绑设备审核消息");
|
|
|
message.setType(302);//解绑设备消息
|
|
|
message.setReadonly(1);//是否只读消息
|
|
|
message.setSex(1);
|
|
|
message.setRelationCode(id);
|
|
|
message.setOver("1");//未处理
|
|
|
message.setData("");
|
|
|
message.setDel("1");
|
|
|
messageDao.save(message);*/
|
|
|
|
|
|
pd.setApplyStatus(1);//审核中
|
|
|
pd.setApplyReason(reson);
|
|
@ -379,47 +371,20 @@ public class PatientDeviceController extends BaseController {
|
|
|
@ApiOperation("设备删除")
|
|
|
@RequestMapping(value = "DeletePatientDevice",method = {RequestMethod.GET,RequestMethod.POST})
|
|
|
public String delete(@ApiParam(name = "id", value = "删除设备关联ID")
|
|
|
@RequestParam(value = "id", required = true) String id) {
|
|
|
@RequestParam(value = "id", required = true) String id,
|
|
|
@ApiParam(name = "patientId", value = "居民id", defaultValue = "0")
|
|
|
@RequestParam(value = "patientId", required = false) String patientId) {
|
|
|
try {
|
|
|
if(StringUtils.isBlank(patientId)){
|
|
|
patientId = getRepUID();
|
|
|
}
|
|
|
DevicePatientDevice pd = patientDeviceService.findById(id);
|
|
|
if (pd != null) {
|
|
|
// if (!StringUtils.equals(pd.getUser(), getUID())) {
|
|
|
if (!StringUtils.equals(pd.getUser(), getRepUID())) {
|
|
|
if (!StringUtils.equals(pd.getUser(), patientId)) {
|
|
|
return error(-1, "只允许删除自己的设备!");
|
|
|
}
|
|
|
// 删除设备
|
|
|
patientDeviceService.deleteDevice(id, getRepUID());
|
|
|
// patientDeviceService.deleteDevice(id, getUID());
|
|
|
//居民自主解绑设备时发送消息给医生
|
|
|
BasePatientDO patient = patientService.findById(getRepUID()).orElse(null);
|
|
|
|
|
|
String messageContent = "您的居民"+patient.getName()+"解绑了";
|
|
|
if ("1".equals(pd.getCategoryCode())){
|
|
|
messageContent +="血糖仪,点击下方查看居民详情";
|
|
|
}else if ("2".equals(pd.getCategoryCode())){
|
|
|
messageContent +="血压计,点击下方查看居民详情";
|
|
|
}else if ("4".equals(pd.getCategoryCode())){
|
|
|
messageContent +="智能手表,点击下方查看居民详情";
|
|
|
}
|
|
|
/* Message message = new Message();
|
|
|
message.setCzrq(new Date());
|
|
|
message.setCreateTime(new Date());
|
|
|
message.setContent(messageContent);
|
|
|
message.setRead(1);//设置未读
|
|
|
message.setReceiver(signFamily.getDoctor());//设置接受医生的code
|
|
|
message.setSender("admin");//设置发送的用户
|
|
|
message.setSenderName("系统");
|
|
|
message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
message.setSenderPhoto("");
|
|
|
message.setTitle("解绑设备消息");
|
|
|
message.setType(301);//解绑设备消息
|
|
|
message.setReadonly(1);//是否只读消息
|
|
|
message.setSex(1);
|
|
|
message.setRelationCode(patient.getCode());
|
|
|
message.setOver("1");//未处理
|
|
|
message.setData("");
|
|
|
message.setDel("1");
|
|
|
messageDao.save(message);*/
|
|
|
patientDeviceService.deleteDevice(id, patientId);
|
|
|
//全部解绑后去判断就更新设备表中是否绑定字段
|
|
|
patientDeviceLogService.savePatientDeviceLog(pd,pd.getDeviceSn(),2,2);
|
|
|
deviceDetailService.unBindUpdateIsBinding(pd.getDeviceSn());
|