Explorar el Código

三诺设备数据对接

yeshijie hace 7 años
padre
commit
27f2f7ffdc

+ 1 - 0
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/util/DateUtil.java

@ -44,6 +44,7 @@ public class DateUtil {
    public final static String DEFAULT_YMDHMSDATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
    public static final String DEFAULT_NOW_STRING_FORMAT = "yyyyMMddHHmmssSSS";
    public static final String yyyyMMddHHmmss = "yyyyMMddHHmmss";
    public static final String DATE_MDY_FORMAT = "MMddyyyy";
    public static final String DATE_MY_FORMAT = "MMyyyy";
    public static final String DATE_WORLD_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

+ 101 - 0
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/controller/DeviceController.java

@ -7,6 +7,7 @@ import com.yihu.hos.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -64,6 +65,106 @@ public class DeviceController {
        }
    }
    /**
     * imei=865328025053108&tel=15911017043&iccid=10011003100403120073&imsi=012345678901234&user=1&sys=125&dia=85&pul=65&ano=0&time="2017-11-30/15:20:12"
     * @param imei
     * @param tel
     * @param iccid
     * @param imsi
     * @param user
     * @param sys
     * @param dia
     * @param pul
     * @param ano
     * @param time
     * @return
     */
    @ApiOperation("三诺血压设备数据上传接口(标准协议)")
    @RequestMapping(value = "/threeNodUploadXY", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public Result threeNodUploadXY(@ApiParam(value="设备号",defaultValue = "865328025053108")
                                    @RequestParam(value = "imei", required = true) String imei,
                                    @ApiParam(value="电话",defaultValue = "15911017043")
                                    @RequestParam(value = "tel", required = false) String tel,
                                    @ApiParam(value="iccid",defaultValue = "10011003100403120073")
                                    @RequestParam(value = "iccid", required = false) String iccid,
                                    @ApiParam(value="imsi",defaultValue = "012345678901234")
                                    @RequestParam(value = "imsi", required = false) String imsi,
                                    @ApiParam(value="用户 1爸爸 2妈妈",defaultValue = "1")
                                    @RequestParam(value = "user", required = true) String user,
                                    @ApiParam(value="高压",defaultValue = "125")
                                    @RequestParam(value = "sys", required = true) String sys,
                                    @ApiParam(value="低压",defaultValue = "85")
                                    @RequestParam(value = "dia", required = true) String dia,
                                    @ApiParam(value="心跳次数/分钟",defaultValue = "65")
                                    @RequestParam(value = "pul", required = false) String pul,
                                    @ApiParam(value="心率 齐0 不齐1",defaultValue = "0")
                                    @RequestParam(value = "ano", required = false) String ano,
                                    @ApiParam(value="时间",defaultValue = "2017-11-30/15:20:12")
                                    @RequestParam(value = "time", required = true) String time){
        try{
            JSONObject json = new JSONObject();
            json.put("imei",imei);
            json.put("tel",tel);
            json.put("iccid",iccid);
            json.put("imsi",imsi);
            json.put("user",user);
            json.put("sys",sys);
            json.put("dia",dia);
            json.put("pul",pul);
            json.put("ano",ano);
            json.put("time",time);
            return deviceService.threeNodeUpload("2",json);
        }
        catch (Exception ex)
        {
            return Result.error("Device data incoming failure!"+ex.getMessage());
        }
    }
    /**
     * act=bloodGlu&devid=1234123&bloodGlu=4.9&bgState=2&testTime=20171116091015&tempTur=23.4&codeNum=019
     * @param act
     * @param devid
     * @param bloodGlu
     * @param bgState
     * @param testTime
     * @param tempTur
     * @param codenum
     * @return
     */
    @ApiOperation("三诺血糖设备数据上传接口(标准协议)")
    @RequestMapping(value = "/threeNodUploadXT", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public Result threeNodUploadXT(@ApiParam(value="标识为血糖数据",defaultValue = "bloodGlu")
                                    @RequestParam(value = "act", required = false) String act ,
                                    @ApiParam(value="设备id",defaultValue = "1234123")
                                    @RequestParam(value = "devid", required = true) String devid ,
                                    @ApiParam(value="血糖值",defaultValue = "4.9")
                                    @RequestParam(value = "bloodGlu", required = true) String bloodGlu ,
                                    @ApiParam(value="1饭后,2饭前",defaultValue = "2")
                                    @RequestParam(value = "bgState", required = false) String bgState ,
                                    @ApiParam(value="测量时间",defaultValue = "20171116091015")
                                    @RequestParam(value = "testTime", required = true) String testTime ,
                                    @ApiParam(value="温度值",defaultValue = "23.4")
                                    @RequestParam(value = "tempTur", required = false) String tempTur ,
                                    @ApiParam(value="codenum",defaultValue = "019")
                                    @RequestParam(value = "codenum", required = false) String codenum){
        try{
            JSONObject json = new JSONObject();
            json.put("act",act);
            json.put("devid",devid);
            json.put("bloodGlu",bloodGlu);
            json.put("bgState",bgState);
            json.put("testTime",testTime);
            json.put("tempTur",tempTur);
            json.put("codenum",codenum);
            return deviceService.threeNodeUpload("1",json);
        }
        catch (Exception ex)
        {
            return Result.error("Device data incoming failure!"+ex.getMessage());
        }
    }
    @ApiOperation("设备数据查询接口")
    @RequestMapping(value = "/data", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public Result getData(

+ 127 - 58
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java

@ -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)) {