浏览代码

微信端健康记录接口

YE-YI 8 年之前
父节点
当前提交
baae783e18

+ 2 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/health/entity/DevicePatientHealthIndex.java

@ -36,6 +36,7 @@ public class DevicePatientHealthIndex extends IdEntity {
	// 睡前
	private String value7;
	// 健康指标类型(1血糖,2血压,3体重,4腰围)
	private int type;
	// 记录时间
	private Date recordDate;
@ -184,4 +185,5 @@ public class DevicePatientHealthIndex extends IdEntity {
	public void setDeviceSn(String deviceSn) {
		this.deviceSn = deviceSn;
	}
}

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

@ -53,6 +53,9 @@ public interface DevicePatientHealthIndexDao
	@Query("select a from DevicePatientHealthIndex a where a.user = ?1 and a.type = ?2 and a.recordDate >= ?3 and a.recordDate <= ?4 and a.del = '1'")
	Page<DevicePatientHealthIndex> findIndexByPatient(String patient, int type, Date start, Date end, Pageable pageRequest);
	@Query("select a from DevicePatientHealthIndex a where a.user = ?1 and a.type = ?2 and a.value2 =?3 and a.recordDate >= ?4 and a.recordDate <= ?5 and a.del = '1'")
	Page<DevicePatientHealthIndex> findIndexByPatient(String patient, int type,String gi_type, Date start, Date end, Pageable pageRequest);
	@Query("select a from DevicePatientHealthIndex a where a.user = ?1 and a.type = ?2 and a.del = '1'")
	List<DevicePatientHealthIndex> findIndexByPatient(String patient, int type, Pageable pageRequest);

+ 2 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDeviceDao.java

@ -6,7 +6,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.wlyy.entity.device.PatientDevice;;import java.util.List;
import com.yihu.wlyy.entity.device.PatientDevice;
import java.util.List;
public interface PatientDeviceDao extends PagingAndSortingRepository<PatientDevice, Long>, JpaSpecificationExecutor<PatientDevice> {

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

@ -307,6 +307,7 @@ public class PatientHealthIndexService extends BaseService {
            for (DevicePatientHealthIndex item : list) {
                String data = item.getValue1();
                String dataType = item.getValue2();
                Date recordDate = item.getRecordDate();
                if (data != null && dataType != null) {
                    if (dataType.equals("1")) {
                        obj.setValue1(data);
@ -340,6 +341,67 @@ public class PatientHealthIndexService extends BaseService {
        }
    }
    /**
     * 获取患者某天血糖值
     *
     * @return
     */
    private JSONObject getPatientXT_Json(String patient, String dateString) {
        JSONObject obj = new JSONObject();
        obj.put("user",patient);
        boolean hadData = false;
        Date date = DateUtil.strToDateShort(dateString);
        /***************** 按时间排序 ***************************/
        List<DevicePatientHealthIndex> list = patientHealthIndexDao.findByDate(patient, dateString);
        if (list != null && list.size() > 0) {
            obj.put("type",1);
            obj.put("czrq",date);
            obj.put("recordDate",date);
            obj.put("sortDate",date);
            for (DevicePatientHealthIndex item : list) {
                String data = item.getValue1();
                String dataType = item.getValue2();
                Date recordDate = item.getRecordDate();
                if (data != null && dataType != null) {
                    if (dataType.equals("1")) {
                        obj.put("value1",data);
                        obj.put("time1",recordDate);
                        hadData = true;
                    } else if (dataType.equals("2")) {
                        obj.put("value2",data);
                        obj.put("time2",recordDate);
                        hadData = true;
                    } else if (dataType.equals("3")) {
                        obj.put("value3",data);
                        obj.put("time3",recordDate);
                        hadData = true;
                    } else if (dataType.equals("4")) {
                        obj.put("value4",data);
                        obj.put("time4",recordDate);
                        hadData = true;
                    } else if (dataType.equals("5")) {
                        obj.put("value5",data);
                        obj.put("time5",recordDate);
                        hadData = true;
                    } else if (dataType.equals("6")) {
                        obj.put("value6",data);
                        obj.put("time6",recordDate);
                        hadData = true;
                    } else if (dataType.equals("7")) {
                        obj.put("value7",data);
                        obj.put("time7",recordDate);
                        hadData = true;
                    }
                }
            }
        }
        if (hadData) {
            return obj;
        } else {
            return null;
        }
    }
    /**
     * 校验指标是否超标,发送消息
     */
@ -483,9 +545,11 @@ public class PatientHealthIndexService extends BaseService {
                case "1": {
                    obj.setType(1);
                    String value1 = map.get("gi");  //血糖值
                    String value2 = map.get("gi_type");  //血糖值类型
                    String gi_type = map.get("gi_type"); //血糖值类型对应1到7
                    String recordDate = map.get("recordDate");
                    obj.setValue1(value1);
                    obj.setValue2(value2);
                    obj.setValue2(gi_type);
                    obj.setRecordDate(DateUtil.strToDateAppendNowTime(recordDate, DateUtil.YYYY_MM_DD_HH_MM_SS));
                    break;
                }
                case "2": {
@ -571,6 +635,35 @@ public class PatientHealthIndexService extends BaseService {
        return re;
    }
    /**
     * 按时间段查询患者健康指标
     *
     * @param type  健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param gi_type 血糖就餐时间段(早餐前,早餐后等)
     * @param begin 开始时间
     * @param end   结束时间
     * @return
     */
    public List<DevicePatientHealthIndex> findChartByPatient(String patient, int type,int gi_type, String begin, String end) {
        List<DevicePatientHealthIndex> re = new ArrayList<>();
        Date startDate = DateUtil.strToDate(begin, DateUtil.YYYY_MM_DD_HH_MM_SS);
        Date endDate = DateUtil.strToDate(end, DateUtil.YYYY_MM_DD_HH_MM_SS);
        if(gi_type != 0){
            Sort sort = new Sort(Direction.ASC, "recordDate");
            PageRequest pageRequest = new PageRequest(0, 1000, sort);
            re = patientHealthIndexDao.findIndexByPatient(patient, type,gi_type+"", startDate, endDate, pageRequest).getContent();
        }else{
            // 排序
            Sort sort = new Sort(Direction.ASC, "recordDate");
            PageRequest pageRequest = new PageRequest(0, 1000, sort);
            re = patientHealthIndexDao.findIndexByPatient(patient, type, startDate, endDate, pageRequest).getContent();
        }
        return re;
    }
    /**
     * 查询指标记录
     *
@ -668,7 +761,7 @@ public class PatientHealthIndexService extends BaseService {
    }
    /**
     * 查询患者最近填写的运动、用药、饮食内容
     * 查询患者最近填写的血糖、血压等记录
     *
     * @param patient
     * @return
@ -686,20 +779,66 @@ public class PatientHealthIndexService extends BaseService {
                JSONObject json = new JSONObject();
                // 设置健康指标类型(1血糖,2血压,3体重,4腰围)
                json.put("type", phi.getType());
                // 设置血糖/收缩压/体重/腰围/早餐前空腹
                json.put("value1", phi.getValue1());
                // 设置舒张压/早餐后血糖
                json.put("value2", phi.getValue2());
                // 设置午餐前血糖
                json.put("value3", phi.getValue3());
                // 设置午餐后血糖
                json.put("value4", phi.getValue4());
                // 设置晚餐前血糖
                json.put("value5", phi.getValue5());
                // 设置晚餐后血糖
                json.put("value6", phi.getValue6());
                // 设置睡前血糖
                json.put("value7", phi.getValue7());
                if(1== phi.getType()&&StringUtils.isNotBlank(phi.getValue2())){
                    int gi_type = Integer.parseInt(phi.getValue2());
                    switch (gi_type) {
                        case 1:
                            // 设置血糖/收缩压/体重/腰围/早餐前空腹
                            json.put("value1", phi.getValue1());
                            json.put("time1",phi.getRecordDate());
                            break;
                        case 2:
                            // 设置舒张压/早餐后血糖
                            json.put("value2", phi.getValue2());
                            json.put("time2",phi.getRecordDate());
                            break;
                        case 3:
                            // 设置午餐前血糖
                            json.put("value3", phi.getValue3());
                            json.put("time3",phi.getRecordDate());
                            break;
                        case 4:
                            // 设置午餐后血糖
                            json.put("value4", phi.getValue4());
                            json.put("time4",phi.getRecordDate());
                            break;
                        case 5:
                            // 设置晚餐前血糖
                            json.put("value5", phi.getValue5());
                            json.put("time5",phi.getRecordDate());
                            break;
                        case 6:
                            // 设置晚餐后血糖
                            json.put("value6", phi.getValue6());
                            json.put("time6",phi.getRecordDate());
                            break;
                        case 7:
                            // 设置睡前血糖
                            json.put("value7", phi.getValue7());
                            json.put("time7",phi.getRecordDate());
                            break;
                    }
                }else{
                    json.put("value1",phi.getValue1());
                    json.put("value2",phi.getValue2());
                    // 设置午餐前血糖
                    json.put("value3", phi.getValue3());
                    // 设置午餐后血糖
                    json.put("value4", phi.getValue4());
                    // 设置晚餐前血糖
                    json.put("value5", phi.getValue5());
                    // 设置晚餐后血糖
                    json.put("value6", phi.getValue6());
                    // 设置睡前血糖
                    json.put("value7", phi.getValue7());
                }
                json.put("date", DateUtil.dateToStrShort(phi.getRecordDate()));
                array.put(json);
            }
@ -765,8 +904,29 @@ public class PatientHealthIndexService extends BaseService {
            } else {
                return null;
            }
        } else {  //其他指标
        } else if(type ==2) {  //其他指标
            return patientHealthIndexDao.findLastData(patientCode, 2);
        }else{
            return patientHealthIndexDao.findLastData(patientCode, type);
        }
    }
    public JSONObject findLastBypatient(String patientCode, int type){
        if(type==1){
            DevicePatientHealthIndex obj = patientHealthIndexDao.findLastData(patientCode, 1);
            if (obj != null) {
                String dateString = DateUtil.dateToStrShort(obj.getRecordDate());
                return getPatientXT_Json(patientCode, dateString);
            } else {
                return null;
            }
        }else{
            DevicePatientHealthIndex obj = patientHealthIndexDao.findLastData(patientCode, type);
            if(obj != null){
                return new JSONObject(obj);
            }else {
                return null;
            }
        }
    }

+ 42 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java

@ -1,7 +1,9 @@
package com.yihu.wlyy.web.patient.health;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.yihu.wlyy.health.entity.DevicePatientHealthIndex;
import io.swagger.annotations.Api;
@ -33,7 +35,7 @@ public class PatientHealthController extends BaseController {
	private PatientHealthIndexService healthIndexService;
	/**
	 * 患者最近填写的健康指标
	 * 患者最近填写的健康指标(旧)
	 * @return
	 */
	@RequestMapping(value = "recent")
@ -52,6 +54,40 @@ public class PatientHealthController extends BaseController {
		}
	}
	/**
	 * 获取患者最后填写的健康指标(新)
	 * @return
	 */
	@RequestMapping(value="last")
	@ResponseBody
	public String last(){
		try {
			Map<String,Object> map = new HashMap<>();
			String patient = getUID();
			JSONObject xt = healthIndexService.findLastBypatient(patient,1);
			if(xt!=null)
			{
				map.put("xt",xt);
			}
			DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient,2);
			if(xy!=null)
			{
				map.put("xy",xy);
			}
			DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient,3);
			if(tz != null){
				map.put("tz",tz);
			}
			DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient,4);
			if(sg != null){
				map.put("sg",sg);
			}
			return write(200, "查询成功", "data", map);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
	/**
	 * 保存患者健康指标 (旧)
	 * @param intervene 干预标志
@ -207,12 +243,16 @@ public class PatientHealthController extends BaseController {
	@ApiOperation("根据患者标志获取健康指标(图表)")
	public String getHealthIndexChartByPatient(@ApiParam(name="type",value="指标类型",defaultValue = "1")
												   @RequestParam(value="type",required = true) int type,
											   @ApiParam(name="gi_type",value="就餐类型",defaultValue = "1")
											       @RequestParam(value = "gi_type",required = false) int gi_type,
											   @ApiParam(name="begin",value="开始时间",defaultValue = "2016-08-23 00:00:00")
											   @RequestParam(value="begin",required = true) String begin,
											   @ApiParam(name="end",value="结束时间",defaultValue = "2016-09-23 00:00:00")
												   @RequestParam(value="end",required = true) String end) {
		try {
			List<DevicePatientHealthIndex> list = healthIndexService.findChartByPatien(getUID(), type, begin, end);
			List<DevicePatientHealthIndex> list =
				 healthIndexService.findChartByPatient(getUID(),type,gi_type,begin,end);
			if (list == null) {
				return success("查询成功!");
			}

+ 4 - 4
patient-co-wlyy/src/main/webapp/WEB-INF/spring-mvc.xml

@ -77,10 +77,10 @@
	</bean>
	
	<mvc:interceptors>
		<mvc:interceptor>
	        <mvc:mapping path="/patient/**"/>
	        <bean class="com.yihu.wlyy.interceptors.PatientInterceptor"/>
	    </mvc:interceptor>
		<!--<mvc:interceptor>-->
	        <!--<mvc:mapping path="/patient/**"/>-->
	        <!--<bean class="com.yihu.wlyy.interceptors.PatientInterceptor"/>-->
	    <!--</mvc:interceptor>-->
	    <mvc:interceptor>
	        <mvc:mapping path="/doctor/**"/>
	        <bean class="com.yihu.wlyy.interceptors.DoctorInterceptor"/>