Просмотр исходного кода

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

wujunjie 7 лет назад
Родитель
Сommit
d553d6c190

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

@ -60,7 +60,7 @@ public interface DevicePatientHealthIndexDao
	List<DevicePatientHealthIndex> findIndexByPatient(String patient, int type, Pageable pageRequest);
	@Query("SELECT a FROM DevicePatientHealthIndex a where a.user = ?1 and a.del = '1' order by a.recordDate desc ")
	Iterable<DevicePatientHealthIndex> findRecentByPatient(String patient);
	List<DevicePatientHealthIndex> findRecentByPatient(String patient);
	@Query("select DATE_FORMAT(a.recordDate,'%Y-%m-%d') from DevicePatientHealthIndex a where a.user = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' group by DATE_FORMAT(a.recordDate,'%Y-%m-%d') order by DATE_FORMAT(a.recordDate,'%Y-%m-%d') desc")
	List<String> findDateList(String patient, Date start, Date end, Pageable pageRequest);

+ 13 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -766,7 +766,8 @@ public class PatientDeviceService extends BaseService {
     * @param page
     * @param pageSize
     */
    public List<com.alibaba.fastjson.JSONObject> searchPatient(String name,Integer page,Integer pageSize){
    public List<com.alibaba.fastjson.JSONObject> searchPatient(String name,Integer page,Integer pageSize,String idcards){
        Object o[] = null;
        StringBuffer sql = new StringBuffer("SELECT p.code,p.name,p.address,p.idcard,p.sex,GROUP_CONCAT(label_name) labelName,t.doctor_name doctorName ");
        sql.append("FROM ( SELECT DISTINCT f.* FROM wlyy_patient_device d, wlyy_sign_family f ");
        sql.append("WHERE f.`status` > 0 AND f.patient = d.`user` ) t, wlyy_patient p LEFT JOIN ");
@ -775,8 +776,17 @@ public class PatientDeviceService extends BaseService {
        if(StringUtils.isNotBlank(name)){
            sql.append(" and (p.`name` like '%"+name+"%' or t.doctor_name like '%"+name+"%') ");
        }
        sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex LIMIT ?,? ");
        List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
        if(StringUtils.isNotBlank(idcards)){
            idcards = "'"+idcards.replaceAll(",","','")+"'";
            sql.append(" and p.idcard in ("+idcards+") ");
            sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex ");
            o = new Object[]{};
        }else {
            sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex LIMIT ?,? ");
            o = new Object[]{(page-1)*pageSize,pageSize};
        }
        List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),o);
        list.forEach(json->{
            json.put("age", IdCardUtil.getAgeForIdcard(String.valueOf(json.get("idcard"))));
        });

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

@ -26,6 +26,7 @@ import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.*;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.NameValuePair;
@ -228,7 +229,8 @@ public class PatientHealthIndexService extends BaseService {
                " ORDER BY " +
                " a.record_date DESC " +
                "LIMIT 0,1 ";
        List<Map<String, Object>> devicePatient = jdbcTemplate.queryForList(sql, patient, type);
//        List<Map<String, Object>> devicePatient = jdbcTemplate.queryForList(sql, patient, type);
        List<Map<String, Object>> devicePatient = findDataByPatient(sql, patient, type);
        Map<String, Object> map = new HashMap<>();
        for (Map<String, Object> device : devicePatient) {
            String time = device.get("record_date") == null ? null : device.get("record_date").toString();
@ -429,7 +431,8 @@ public class PatientHealthIndexService extends BaseService {
                " and del = '1' " +
                " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
                " order by record_date,id desc ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
//        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = getPatientXT_JsonIot(sql,patient,dateString);
        if (list != null && list.size() > 0) {
            obj.put("type", 1);
            obj.put("czrq", date);
@ -639,6 +642,171 @@ public class PatientHealthIndexService extends BaseService {
        }
    }
    /**
     * 查询最近的一条体征数据
     * @param sql
     * @param patient
     * @param type
     * @return
     */
    public List<Map<String, Object>> findDataByPatient(String sql,String patient,Integer type){
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndType(patient,type,1);
            if(list!=null&&list.size()>0){
                re.add(indexToMap(list.get(0)));
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql, patient, type);
        }
    }
    /**
     * 患者最近填写的健康指标
     * @param patient
     * @return
     */
    public List<DevicePatientHealthIndex> findRecentByPatientIterable(String patient){
        if(iotDeviceService.isUploadIot()){
            return iotDeviceService.findByPatientAndType(patient,null,1000);
        }else {
            return patientHealthIndexDao.findRecentByPatient(patient);
        }
    }
    /**
     * 根据患者标志获取健康指标
     * @param patient
     * @param type
     * @return
     */
    public DevicePatientHealthIndex findLastByPatienIot(String patient,Integer type){
        if(iotDeviceService.isUploadIot()){
            DevicePatientHealthIndex index = null;
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndType(patient,type,1);
            if(list!=null&&list.size()>0){
                index = list.get(0);
            }
            return index;
        }else {
            return findLastByPatien(patient,type);
        }
    }
    /**
     * 查询指标记录
     * @param patient
     * @param startDate
     * @param endDate
     * @param page
     * @param size
     * @return
     */
    public List<String> findDateListIot(String patient,Date startDate,Date endDate, Integer page, Integer size,String start, String end){
        if(iotDeviceService.isUploadIot()){
            List<String> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, null,page, size, null, start, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(DateUtil.dateToStrShort(one.getRecordDate()));
                });
            }
            return re;
        }else {
            return patientHealthIndexDao.findDateList(patient,startDate,endDate,page,size);
        }
    }
    /**
     * 按时间查找
     * @param sql
     * @param patient
     * @param type
     * @param size
     * @param gi_type
     * @param begin
     * @param end
     * @return
     */
    public List<Map<String, Object>> findByPatientAndTime(String sql,String patient,Integer type,Integer size,Integer gi_type, String begin, String end){
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, type,1, size, gi_type, begin, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(indexToMap(one));
                });
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql);
        }
    }
    /**
     * 按时间查找
     * @param sql
     * @param patient
     * @param date
     * @return
     */
    public List<Map<String, Object>> getPatientXT_JsonIot(String sql,String patient, String date){
        String begin = date +" 00:00:00";
        String end= date +" 23:59:59";
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, 1,1, 100, null, begin, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(indexToMap(one));
                });
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql);
        }
    }
    /**
     * 按时间查找
     * @param sql
     * @param patient
     * @return
     */
    public List<Map<String, Object>> getPatientXT_JsonIot(String sql,String patient,Integer type,Integer page,Integer size, String begin,String end){
        if(iotDeviceService.isUploadIot()){
            List<Map<String, Object>> re = new ArrayList<>();
            List<DevicePatientHealthIndex> list = iotDeviceService.findByPatientAndTime(patient, type,page, size, null, begin, end);
            if(list!=null&&list.size()>0){
                list.forEach(one->{
                    re.add(indexToMap(one));
                });
            }
            return re;
        }else {
            return jdbcTemplate.queryForList(sql);
        }
    }
    /**
     * 转map
     * @param index
     * @return
     */
    private Map<String, Object> indexToMap(DevicePatientHealthIndex index){
        Map<String, Object> map = new HashedMap();
        map.put("value1",index.getValue1());
        map.put("value2",index.getValue2());
        map.put("value3",index.getValue3());
        map.put("value4",index.getValue4());
        map.put("value5",index.getValue5());
        map.put("value6",index.getValue6());
        map.put("value7",index.getValue7());
        map.put("device_sn",index.getDeviceSn());
        map.put("record_date",index.getRecordDate());
        return map;
    }
    /********************************************物联网 end***********************************************************/
@ -1177,7 +1345,8 @@ public class PatientHealthIndexService extends BaseService {
        sql = sql + conditionApp +
                " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
                " order by record_date desc ,sort_date desc limit " + 0 + " ," + 1000 + " ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
//        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = findByPatientAndTime(sql,patient,type,1000,gi_type,begin,end);
        for (Map<String, Object> map : list) {
            JSONObject json = new JSONObject();
            json.put("id", map.get("id"));
@ -1464,7 +1633,8 @@ public class PatientHealthIndexService extends BaseService {
                    " and del = '1' " +
                    " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
                    " order by record_date desc ,sort_date desc limit " + pageRequest.getOffset() + " ," + pageRequest.getPageSize() + " ";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
//            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            List<Map<String, Object>> list = getPatientXT_JsonIot(sql,patient,type,pageRequest.getOffset(),pageRequest.getPageSize(),start,end);
            for (Map<String, Object> map : list) {
                JSONObject json = new JSONObject();
                json.put("id", map.get("id"));
@ -1519,7 +1689,8 @@ public class PatientHealthIndexService extends BaseService {
        {
            PageRequest pageRequest = new PageRequest(page, pageSize);
            //根据时间过滤排序
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
//            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize());
            List<String> dateList = findDateListIot(patient, startDate, endDate, pageRequest.getOffset(), pageRequest.getPageSize(), start, end);
            if (dateList != null && dateList.size() > 0) {
                for (String dateString : dateList) {
                    com.alibaba.fastjson.JSONObject obj = getPatientXT_Json(patient, dateString);
@ -1564,7 +1735,8 @@ public class PatientHealthIndexService extends BaseService {
     */
    public JSONArray findRecentByPatient(String patient) {
        JSONArray array = new JSONArray();
        Iterable<DevicePatientHealthIndex> iterable = patientHealthIndexDao.findRecentByPatient(patient);
//        List<DevicePatientHealthIndex> iterable = patientHealthIndexDao.findRecentByPatient(patient);
        List<DevicePatientHealthIndex> iterable = findRecentByPatientIterable(patient);
        if (iterable != null) {
            Iterator<DevicePatientHealthIndex> iterator = iterable.iterator();
            while (iterator != null && iterator.hasNext()) {

+ 56 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -274,17 +274,70 @@ public class IotDeviceService {
     * @param type
     * @return
     */
    public List<DevicePatientHealthIndex> findByPatientAndType(String patient,Integer type){
    public List<DevicePatientHealthIndex> findByPatientAndType(String patient,Integer type,Integer size){
        List<DevicePatientHealthIndex> list = new ArrayList<>();
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",patient,jsonArray);
        field("and","del","=","1",jsonArray);
        field("and","type","=",String.valueOf(type),jsonArray);
        if(type!=null){
            field("and","type","=",String.valueOf(type),jsonArray);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        jsonObject.put("page","1");
        jsonObject.put("size","5");
        jsonObject.put("size",size);
        JSONArray sort = new JSONArray();
        sort(sort,"measure_time","desc");
        jsonObject.put("sort",sort);
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        try {
            JSONObject json = JSONObject.parseObject(response);
            JSONArray obj = json.getJSONArray("obj");
            if(obj!=null&&obj.size()>0){
                for (int i=0;i<obj.size();i++){
                    DevicePatientHealthIndex index = transforHealthIndex(obj.getJSONObject(i),null);
                    list.add(index);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 按时间段查找
     * @param patient 居民code
     * @param type    健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param gi_type 血糖就餐时间段(早餐前,早餐后等)
     * @param begin   开始时间
     * @param end     结束时间
     * @return
     */
    public List<DevicePatientHealthIndex> findByPatientAndTime(String patient,Integer type,Integer page,Integer size,Integer gi_type, String begin, String end){
        List<DevicePatientHealthIndex> list = new ArrayList<>();
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",patient,jsonArray);
        field("and","del","=","1",jsonArray);
        if(type!=null){
            field("and","type","=",String.valueOf(type),jsonArray);
        }
        if(gi_type!=null){
            field("and","blood_sugar_result","=",String.valueOf(gi_type),jsonArray);
        }
        field("and","measure_time",">=",begin,jsonArray);
        field("and","measure_time","<=",end,jsonArray);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        jsonObject.put("page",page);
        jsonObject.put("size",size);
        JSONArray sort = new JSONArray();
        sort(sort,"measure_time","desc");

+ 8 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java

@ -265,19 +265,23 @@ public class PatientHealthController extends BaseController {
            Map<String, Object> map = new HashMap<>();
            String patient = getRepUID();
//            String patient = getUID();
            DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
//            DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
            DevicePatientHealthIndex xt = healthIndexService.findLastByPatienIot(patient, 1);
            if (xt != null) {
                map.put("xt", xt);
            }
            DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
//            DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
            DevicePatientHealthIndex xy = healthIndexService.findLastByPatienIot(patient, 2);
            if (xy != null) {
                map.put("xy", xy);
            }
            DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
//            DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
            DevicePatientHealthIndex tz = healthIndexService.findLastByPatienIot(patient, 3);
            if (tz != null) {
                map.put("tz", tz);
            }
            DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
//            DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
            DevicePatientHealthIndex sg = healthIndexService.findLastByPatienIot(patient, 4);
            if (sg != null) {
                map.put("sg", sg);
            }

+ 3 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/iot/IotMonitoringHealthController.java

@ -86,6 +86,8 @@ public class IotMonitoringHealthController extends BaseController {
    public String searchPatient(
            @ApiParam(name="name",value="居民姓名")
            @RequestParam(value="name",required = false) String name,
            @ApiParam(name="idcards",value="身份证(多个用逗号间隔)")
            @RequestParam(value="idcards",required = false) String idcards,
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
@ -97,7 +99,7 @@ public class IotMonitoringHealthController extends BaseController {
            if(pageSize==null){
                pageSize = 10;
            }
            return write(200,"查询成功","data",patientDeviceService.searchPatient(name,page,pageSize));
            return write(200,"查询成功","data",patientDeviceService.searchPatient(name,page,pageSize,idcards));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -251,7 +251,7 @@ public class IotDeviceController extends BaseController{
                                                    @ApiParam(name="type",value = "类型")
                                                    @RequestParam(name="type",required = true)Integer type){
        try {
            return write(200,"查询成功","data",iotDeviceService.findByPatientAndType(patientCode,type));
            return write(200,"查询成功","data",iotDeviceService.findByPatientAndType(patientCode,type,5));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/application-test.yml

@ -30,7 +30,7 @@ im:
#物联网配置
iot:
  url: http://172.19.103.88:8088/svr-iot/
  url: http://172.19.103.33:8088/svr-iot/
wechat:
  appId: wx1f129f7b51701428