Преглед изворни кода

Merge branch 'dev' of zd_123/patient-co-management into dev

trick9191 пре 7 година
родитељ
комит
bd6b397199

+ 14 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/device/PatientDevice.java

@ -47,6 +47,9 @@ public class PatientDevice extends IdEntity {
    //设备活动类型
    private String deviceActivityType;
    //上传的协议图片地址
    private String agreementPhoto;
    //========================非表字段======================
    //患者居住地址
    private String address;
@ -225,6 +228,17 @@ public class PatientDevice extends IdEntity {
        this.deviceActivityType = deviceActivityType;
    }
    @Column(name = "agreement_photo")
    public String getAgreementPhoto() {
        return agreementPhoto;
    }
    public void setAgreementPhoto(String agreementPhoto) {
        this.agreementPhoto = agreementPhoto;
    }
    @Transient
    public String getAddress() {
        return address;

+ 43 - 1
common/common-entity/src/main/java/com/yihu/wlyy/entity/device/PatientDeviceLog.java

@ -13,6 +13,8 @@ import java.util.Date;
@Table(name = "wlyy_patient_device_log")
public class PatientDeviceLog extends IdEntity {
    //dm_device表主键
    private long deviceId;
    //患者id
    private String patient;
    //设备sn码
@ -23,13 +25,27 @@ public class PatientDeviceLog extends IdEntity {
    private String categoryCode;
    //操作人code
    private String operator;
    //操作人姓名
    private String operatorName;
    // 医生或者患者(1医生 2患者)
    private Integer role;
    //操作动作(1绑定 2解绑)
    private Integer operateCode;
    // 创建时间
    private Date createTime;
    //是否有效(0无效1有效)
    private int isDel;
    //上传的协议图片地址
    private String agreementPhoto;
    @Column(name = "device_id")
    public long getDeviceId() {
        return deviceId;
    }
    public void setDeviceId(long deviceId) {
        this.deviceId = deviceId;
    }
    @Column(name = "patient")
    public String getPatient() {
@ -76,6 +92,15 @@ public class PatientDeviceLog extends IdEntity {
        this.operator = operator;
    }
    @Column(name = "operator_name")
    public String getOperatorName() {
        return operatorName;
    }
    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }
    @Column(name = "role")
    public Integer getRole() {
        return role;
@ -104,8 +129,25 @@ public class PatientDeviceLog extends IdEntity {
        this.createTime = createTime;
    }
    public PatientDeviceLog() {
    @Column(name = "is_del")
    public int getIsDel() {
        return isDel;
    }
    public void setIsDel(int isDel) {
        this.isDel = isDel;
    }
    @Column(name = "agreement_photo")
    public String getAgreementPhoto() {
        return agreementPhoto;
    }
    public void setAgreementPhoto(String agreementPhoto) {
        this.agreementPhoto = agreementPhoto;
    }
    public PatientDeviceLog() {
    }
}

+ 6 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/health/repository/DevicePatientHealthIndexDao.java

@ -74,6 +74,12 @@ public interface DevicePatientHealthIndexDao
	@Query(value = "select a.* from device.wlyy_patient_health_index a where a.user=?1 and a.type=?2 and a.del='1' order by a.record_date desc limit 0,1",nativeQuery = true)
	DevicePatientHealthIndex findLastData(String patient, Integer type);
	/**
	 * 获取患者一天的具体某个类型的数据
	 */
	@Query("select a from DevicePatientHealthIndex a where a.type=?1 and a.user = ?2 and DATE_FORMAT(a.recordDate,'%Y-%m-%d') = ?3 and a.deviceSn = ?4 and a.del = '1' order by a.recordDate,a.id")
	List<DevicePatientHealthIndex> findByDateAndType(int type,String patient, String date,String devicesn);
	/**
	 * 上次血糖值
	 */

+ 58 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceLogService.java

@ -7,12 +7,18 @@ import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.patient.PatientDeviceLogDao;
import com.yihu.wlyy.service.BaseService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component
@Transactional(rollbackFor = Exception.class)
@ -24,9 +30,11 @@ public class PatientDeviceLogService extends BaseService {
    private PatientDeviceLogDao patientDeviceLogDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     *
     * 绑定和解绑的时候会保存一条数据
     * @param patientDevice
     * @param role
     * @param operateCode
@ -37,19 +45,68 @@ public class PatientDeviceLogService extends BaseService {
           patientDevice = patientDeviceDao.findByDeviceSn(deviceSn).get(0);
       }
        PatientDeviceLog patientDeviceLog = new PatientDeviceLog();
        patientDeviceLog.setDeviceId(patientDevice.getDeviceId());
        patientDeviceLog.setPatient(patientDevice.getUser());
        patientDeviceLog.setCategoryCode(patientDevice.getCategoryCode());
        patientDeviceLog.setDeviceName(patientDevice.getDeviceName());
        patientDeviceLog.setDeviceSn(patientDevice.getDeviceSn());
        patientDeviceLog.setRole(role);
        patientDeviceLog.setOperateCode(operateCode);
        patientDeviceLog.setAgreementPhoto(patientDevice.getAgreementPhoto());
        if (role==1){
            patientDeviceLog.setOperatorName(patientDevice.getDoctorName());
            patientDeviceLog.setOperator(patientDevice.getDoctor());
        }else if (role==2){
            patientDeviceLog.setOperatorName(patientDevice.getAgentName());
            patientDeviceLog.setOperator(patientDevice.getAgent());
        }
        patientDeviceLog.setCreateTime(new Date());
        patientDeviceLogDao.save(patientDeviceLog);
    }
    public Map<String,Object> getDevicesList(String noGaugeDay,String isBinding,String categoryCode,int pageNo,int pageSize){
        List<Map<String,Object>> resultList =  new ArrayList<>();
        Map<String,Object> resultMap = new HashedMap();
        int start = (pageNo-1)*pageSize;
        String sql ="SELECT b.*,dd.photo FROM (SELECT a.* FROM (" +
                "  SELECT sf.name, pd.* FROM wlyy_patient_device_log pd" +
                "  LEFT JOIN wlyy_sign_family sf ON pd.patient = sf.patient" +
                "  WHERE" +
                "   pd.is_del = 1" +
                "  AND sf.`status` > 0" +
                "  ORDER BY" +
                "  create_time DESC) a" +
                " GROUP BY a.device_sn) b" +
                " LEFT JOIN dm_device dd ON b.device_id = dd.id where 1=1 ";
        resultList = jdbcTemplate.queryForList(sql);
        resultMap.put("tatalCount",resultList.size());
        //筛选条件--是否绑定
        if (!StringUtils.isEmpty(isBinding)){
            sql += " and b.operate_code= "+isBinding;
        }
        //筛选条件--设备类型
        if (!StringUtils.isEmpty(categoryCode)){
            sql += " and b.category_code= "+categoryCode;
        }
        //筛选条件--今日未测量
        if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("1",noGaugeDay)){
            sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE TO_DAYS(record_date)=TO_DAYS(NOW()))";
        }
        //筛选条件--七天内未测量
        if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("2",noGaugeDay)){
            sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= DATE(record_date))";
        }
        //筛选条件--一个月内未测量
        if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("3",noGaugeDay)){
            sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= DATE(record_date))";
        }
        //筛选条件--超过一个月未测量
        if (!StringUtils.isEmpty(noGaugeDay) && StringUtils.equals("4",noGaugeDay)){
            sql += " and b.patient NOT IN (SELECT user FROM device.wlyy_patient_health_index WHERE  DATE_SUB(CURDATE(), INTERVAL 1 MONTH) > DATE(record_date))";
        }
        resultList = jdbcTemplate.queryForList(sql,new Object[]{start,pageSize});
        resultMap.put("data",resultList);
        return resultMap;
    }
}

+ 63 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -1933,4 +1933,67 @@ public class PatientHealthIndexService extends BaseService {
        }
        return patientHealthStandardDao.save(list);
    }
    public List<Map<String, String>> getHealthIndexByPatientAndDate(String patientCode, String deviceSn, String choseDate,int type) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        // 排序
        Sort sort = new Sort(Direction.DESC, "recordDate");
        List<DevicePatientHealthIndex> list = patientHealthIndexDao.findByDateAndType(type,patientCode,choseDate,deviceSn);
        if (list != null && list.size() > 0) {
            for (DevicePatientHealthIndex item : list) {
                Map<String, String> map = new HashMap<>();
                if (type == 1)    //血糖
                {
                    String gi = item.getValue1();
                    String giType = item.getValue2();
                    map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
                    map.put("gi", gi); //  血糖值
                    map.put("gi_type", giType); //  血糖值类型
                    String text = gi + " mmol/L";
                    if ("1".equals(giType)) {
                        text += "(早餐前)";
                    } else if ("2".equals(giType)) {
                        text += "(早餐后)";
                    } else if ("3".equals(giType)) {
                        text += "(午餐前)";
                    } else if ("4".equals(giType)) {
                        text += "(午餐后)";
                    } else if ("5".equals(giType)) {
                        text += "(晚饭前)";
                    } else if ("6".equals(giType)) {
                        text += "(晚饭后)";
                    } else if ("7".equals(giType)) {
                        text += "(睡前)";
                    }
                    map.put("text", text); //  展示
                    re.add(map);
                } else if (type == 2) //血压
                {
                    String sys = item.getValue1();   //收缩压
                    String dia = item.getValue2();    //舒张压
                    String pul = item.getValue3();    //脉搏
                    map.put("time", DateUtil.dateToStrLong(item.getRecordDate()));
                    map.put("sys", sys);
                    map.put("dia", dia);
                    map.put("pul", pul);
                    re.add(map);
                } else if (type == 3) //体重
                {
                    String weight = item.getValue1();   //体重
                    String height = item.getValue2();   //身高
                    String bmi = item.getValue3();      //BMI
                    map.put("time", DateUtil.dateToStrShort(item.getRecordDate()));
                    map.put("weight", weight);
                    map.put("height", height);
                    map.put("bmi", bmi);
                    map.put("text", weight + " kg");
                    re.add(map);
                }
            }
        }
        return re;
    }
}

+ 28 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -18,6 +18,7 @@ import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.CommonUtil;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
@ -73,6 +74,8 @@ public class DoctorDeviceController extends BaseController {
	private DoctorService doctorService;
	@Autowired
	private PatientDeviceLogService patientDeviceLogService;
	@Autowired
	private CommonUtil commonUtil;
	private ObjectMapper  objectMapper=new ObjectMapper();
@ -101,7 +104,7 @@ public class DoctorDeviceController extends BaseController {
	@RequestMapping(value = "SavePatientDeviceAndCredit",method = RequestMethod.POST)
	@ResponseBody
	@ObserverRequired
	public String SavePatientDeviceAndCredit(@ApiParam(name="data",value="设备数据json",defaultValue = "{\"user\":\"915cca0a-5b1d-11e6-834 4-fa163e8aee56\",\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"16C000337\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
	public String SavePatientDeviceAndCredit(@ApiParam(name="data",value="设备数据json",defaultValue = "{\"user\":\"915cca0a-5b1d-11e6-834 4-fa163e8aee56\",\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"16C000337\",\"categoryCode\": \"1\",\"userType\": \"-1\",\"agreementPhoto\":\"www.baidu.com\"}")
							 @RequestParam(value="data",required = true) String data) {
		try {
			PatientDevice device = objectMapper.readValue(data,PatientDevice.class);
@ -111,6 +114,9 @@ public class DoctorDeviceController extends BaseController {
			if (doctor!=null){
				device.setDoctorName(doctor.getName());
			}
			if (StringUtils.isNotEmpty(device.getAgreementPhoto())){
				device.setAgreementPhoto(commonUtil.copyTempImage(device.getAgreementPhoto()));
			}
			//首绑和设备类型判断  判断是否可以增加积分
			Map<String,Object> checkMap = patientDeviceService.checkBindingFirstAndType(device);
			boolean flag = (Boolean)checkMap.get("flag");
@ -391,4 +397,25 @@ public class DoctorDeviceController extends BaseController {
		}
	}
	@RequestMapping(value = "/getDevicesList",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "医生端-设备管理中设备列表",notes = "设备列表")
	public String getDevicesList(@ApiParam(value = "未测量天数(1今日为测量 2七天未测量 3本月未测量 4超过一个月未测量)", name = "noGaugeDay") @RequestParam(value = "noGaugeDay",required = false)String noGaugeDay,
								 @ApiParam(value = "是否绑定(1绑定 2解绑)", name = "isBinding") @RequestParam(value = "isBinding",required = false)String isBinding,
								 @ApiParam(value = "设备类型(1血糖仪 2血压计)", name = "categoryCode") @RequestParam(value = "categoryCode",required = false)String categoryCode,
								 @ApiParam(name="page",value="第几页",defaultValue = "1") @RequestParam(value="page",required = true) String page,
								 @ApiParam(name="pageSize",value="",defaultValue = "10") @RequestParam(value="pageSize",required = true) String pageSize) {
		if (StringUtils.isBlank(pageSize)) {
			pageSize = "10";
		}
		if (page.equals("0")) {
			page = "1";
		}
		try {
			return  write(200,"查找成功!","data",patientDeviceLogService.getDevicesList(noGaugeDay,isBinding,categoryCode,Integer.valueOf(page),Integer.valueOf(pageSize)));
		} catch (Exception e) {
			error(e);
			return error( -1, "查询失败!");
		}
	}
}

+ 14 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/health/DoctorHealthController.java

@ -456,4 +456,18 @@ public class DoctorHealthController extends BaseController {
		}
	}
	@RequestMapping(value = "/patientHealthIndexByDateAndDeviceSn",method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation("医生端--根据时间和设备sn码查询某个居民的体征记录")
	public String patientHealthIndexByDateAndDeviceSn(@ApiParam(value = "居民code)", name = "patientCode") @RequestParam(value = "patientCode",required = true)String patientCode,
													  @ApiParam(value = "设备sn码", name = "deviceSn") @RequestParam(value = "deviceSn",required = true)String deviceSn,
													  @ApiParam(value = "日期", name = "choseDay") @RequestParam(value = "choseDay",required = true)String choseDay,
													  @ApiParam(value = "健康指标类型(1血糖,2血压,3体重,4腰围)",name = "type")@RequestParam(value = "type",required = true)int type){
		try {
			List<Map<String,String>> list = healthIndexService.getHealthIndexByPatientAndDate(patientCode,deviceSn,choseDay,type);
			return write(200, "获取健康指标历史记录成功", "data", list);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
}