Przeglądaj źródła

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

yeshijie 7 lat temu
rodzic
commit
8a562a82ae

+ 9 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/dict/Icd10Dict.java

@ -21,6 +21,7 @@ public class Icd10Dict {
    private Date createDate;
    private String updateUser;
    private Date updateDate;
    private String type;//类型(1高血压,2糖尿病)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -111,4 +112,12 @@ public class Icd10Dict {
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

+ 0 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SwaggerConfig.java

@ -180,7 +180,6 @@ public class SwaggerConfig {
                        regex("/qrcode/.*"),
                        regex("/onepay/.*"),
                        regex("/wlyy_service/.*"),
                        regex("/wlyy_service/.*"),
                        regex("/wechat/.*"),
                        regex("/nofilter/.*"),
                        regex("/idc10/.*"),

+ 13 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/dict/Icd10DictDao.java

@ -0,0 +1,13 @@
package com.yihu.wlyy.repository.dict;
import com.yihu.wlyy.entity.dict.Icd10Dict;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author yeshijie on 2018/2/24.
 */
public interface Icd10DictDao extends PagingAndSortingRepository<Icd10Dict, Long>, JpaSpecificationExecutor<Icd10Dict> {
    Icd10Dict findByCode(String code);
}

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

@ -5,21 +5,30 @@ import com.yihu.wlyy.entity.device.Device;
import com.yihu.wlyy.entity.device.PatientBloodSugger;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.device.PatientHealthTime;
import com.yihu.wlyy.entity.dict.Icd10Dict;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientEvent;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.health.repository.DeviceDetailDao;
import com.yihu.wlyy.repository.deviece.DeviceDao;
import com.yihu.wlyy.repository.deviece.PatientBloodSuggerDao;
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
import com.yihu.wlyy.repository.dict.Icd10DictDao;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamMemberDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
import com.yihu.wlyy.repository.doctor.SignPatientLabelInfoDao;
import com.yihu.wlyy.repository.patient.*;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.third.jw.JwSmjkService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.util.MyJdbcTemplate;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -30,6 +39,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
@ -37,6 +47,7 @@ import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import org.springside.modules.utils.Clock;
import javax.annotation.PostConstruct;
import java.util.*;
@Component
@ -53,10 +64,14 @@ public class PatientDeviceService extends BaseService {
    @Autowired
    private DeviceDao deviceDao;
    @Autowired
    private PatientHealthIndexService healthIndexService;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private SignPatientLabelInfoDao signPatientLabelInfoDao;
    @Autowired
    private DoctorAdminTeamMemberDao doctorAdminTeamMemberDao;
    @Autowired
@ -68,6 +83,8 @@ public class PatientDeviceService extends BaseService {
    @Autowired
    private PatientHealthTimeDao patientHealthTimeDao;
    @Autowired
    private PatientHealthStandardDao patientHealthStandardDao;
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Value("${yihu.yihu_OpenPlatform_url}")
@ -77,7 +94,31 @@ public class PatientDeviceService extends BaseService {
    @Value("${yihu.yihu_OpenPlatform_secret}")
    private String secret;
    private String registerDevice = "DeviceGateway/DeviceApi/registerDevice";//注册设备
    @Autowired
    private MyJdbcTemplate myJdbcTemplate;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private JwSmjkService jwSmjkService;
    @Autowired
    private PatientEventDao patientEventDao;
    @Autowired
    private Icd10DictDao icd10DictDao;
    Map<Integer, String> relations = new HashMap<>();
    @PostConstruct
    public void init() {
        relations.put(0, "其他");
        relations.put(1, "父亲");
        relations.put(2, "母亲");
        relations.put(3, "老公");
        relations.put(4, "老婆");
        relations.put(5, "儿子");
        relations.put(6, "女儿");
        relations.put(7, "未知");
        relations.put(8, "免疫关联");
    }
    /**
     * 验证sn码 先调总部接口 未注册才查询本地数据库,如果也没有才不能绑定
@ -612,4 +653,337 @@ public class PatientDeviceService extends BaseService {
    }
    /**************************远程健康监测平台*********************************************/
    /**
     * 设备发放情况
     */
    public List<com.alibaba.fastjson.JSONObject> equipmentDistribution(){
        StringBuffer sql = new StringBuffer("SELECT t.`code`,t.name,IFNULL(a.num,0) num from dm_town t ");
        sql.append("LEFT JOIN (SELECT h.town,COUNT(*) num ");
        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,dm_hospital h ");
        sql.append("WHERE t.hospital = h.code GROUP BY h.town) a on t.code = a.town ");
        sql.append(" WHERE city = '350200' ORDER BY num desc ");
        return myJdbcTemplate.queryJson(sql.toString());
    }
    /**
     * 慢病患者情况-统计
     * @param type 类型(2糖尿病,1高血压)
     * @return
     */
    public List<com.alibaba.fastjson.JSONObject> chronicDiseaseCount(String type){
        StringBuffer sql = new StringBuffer("SELECT p.disease_condition diseaseCondition,COUNT(*) num ");
        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 ");
        if(StringUtils.isNotBlank(type)){
            sql.append(",wlyy_sign_patient_label_info l ");
        }
        sql.append("WHERE t.patient = p.code ");
        if(StringUtils.isNotBlank(type)){
            sql.append("and p.code = l.patient and l.label =? and l.label_type = 3 ");
        }
        sql.append(" GROUP BY p.disease_condition");
        if(StringUtils.isNotBlank(type)){
            return myJdbcTemplate.queryJson(sql.toString(),new Object[]{type});
        }else {
            return myJdbcTemplate.queryJson(sql.toString());
        }
    }
    /**
     * 设备绑定情况
     * @param type 类型(1血糖仪,2血压计)
     * @return
     */
    public List<com.alibaba.fastjson.JSONObject> deviceBinding(String type){
        StringBuffer sql = new StringBuffer("SELECT IFNULL(p.standard_status,0) standardStatus,COUNT(*) num ");
        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` ");
        if(StringUtils.isNotBlank(type)){
            sql.append("and d.category_code = ? ");
        }
        sql.append(") t,wlyy_patient p WHERE t.patient = p.code ");
        sql.append(" GROUP BY IFNULL(p.standard_status,0)");
        if(StringUtils.isNotBlank(type)){
            return myJdbcTemplate.queryJson(sql.toString(),new Object[]{type});
        }else {
            return myJdbcTemplate.queryJson(sql.toString());
        }
    }
    /**
     * 预警信息警报
     * @param page
     * @param pageSize
     * @return
     */
    public List<com.alibaba.fastjson.JSONObject> warningInformationAlarm(Integer page,Integer pageSize){
        StringBuffer sql = new StringBuffer("SELECT m.sender,m.sender_name,m.create_time,m.value1,m.value2,m.tz_type,p.address ");
        sql.append("from wlyy_message m LEFT JOIN wlyy_patient p on m.sender=p.code ");
        sql.append("WHERE m.type = 2  ORDER BY m.id desc LIMIT ?,?");
        List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
        return list;
    }
    /**
     * 判断当前值是否在区间内
     */
    private String checkHealthIndex(Double current, Double max) {
        if (current > max ) {
            return "偏高";
        }
        return "偏低";
    }
    /**
     * 个人信息
     * @param patientCode
     */
    public com.alibaba.fastjson.JSONObject persionalInfo(String patientCode){
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
        if(signFamily==null){
            jsonObject.put("status",-1);
            return jsonObject;
        }
        Patient patient = patientDao.findByCode(patientCode);
        //标签
        List<SignPatientLabelInfo> labelInfoList = signPatientLabelInfoDao.findByPatientAndStatus(patientCode,1);
        com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
        labelInfoList.forEach(labelInfo->{
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            json.put("label",labelInfo.getLabel());
            json.put("labelName",labelInfo.getLabelName());
            json.put("labelType",labelInfo.getLabelType());
            jsonArray.add(json);
        });
        switch (patient.getDiseaseCondition()){
            case 0:
                com.alibaba.fastjson.JSONObject json1 = new com.alibaba.fastjson.JSONObject();
                json1.put("label","0");
                json1.put("labelName","绿标");
                json1.put("labelType","99");
                jsonArray.add(json1);
                break;
            case 1:
                com.alibaba.fastjson.JSONObject json2 = new com.alibaba.fastjson.JSONObject();
                json2.put("label",1);
                json2.put("labelName","黄标");
                json2.put("labelType","99");
                jsonArray.add(json2);
                break;
            case 2:
                com.alibaba.fastjson.JSONObject json3 = new com.alibaba.fastjson.JSONObject();
                json3.put("label",2);
                json3.put("labelName","红标");
                json3.put("labelType","99");
                jsonArray.add(json3);
                break;
            default:break;
        }
        jsonObject.put("labelList",jsonArray);
        //个人信息
        jsonObject.put("sex",patient.getSex());//性別,1男,2女
        jsonObject.put("name",patient.getName());
        jsonObject.put("doctorName",signFamily.getDoctorName());//全科医生
        jsonObject.put("hospitalName",signFamily.getHospitalName());//社区
        jsonObject.put("address",patient.getAddress());
        jsonObject.put("age", IdCardUtil.getAgeForIdcard(patient.getIdcard()));
        jsonObject.put("status",1);
        return jsonObject;
    }
    /**
     * 获取居民的家庭成员
     * @param patient 居民
     * @return
     */
    public JSONArray familyMember(String patient) {
        JSONArray resultArray = new JSONArray();
        String sql = "select * " +
                " from " +
                "    wlyy_patient_family_member t1, " +
                "    wlyy_patient t2 " +
                " where " +
                "    t2.code in (select family_member from wlyy_patient_family_member where patient = ? ) " +
                "    and t1.patient = ? " +
                "    and t1.family_member = t2.code ";
        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{patient, patient});
        if (result != null && result.size() > 0) {
            for (Map<String, Object> map : result) {
                JSONObject obj = new JSONObject();
                obj.put("code", map.get("code"));
                obj.put("name", map.get("name"));
                obj.put("sex", map.get("sex"));
                obj.put("birthday", map.get("birthday"));
                obj.put("idcard", StringUtils.isEmpty(String.valueOf(map.get("idcard"))) ? "" : map.get("idcard").toString());
                obj.put("photo", map.get("photo"));
                obj.put("mobile", map.get("mobile"));
                obj.put("address", StringUtils.isEmpty(String.valueOf(map.get("address"))) ? "" : map.get("address"));
                obj.put("familyRelation", map.get("family_relation"));
                obj.put("familyRelationName", relations.get(map.get("family_relation")));
                resultArray.put(obj);
            }
        }
        return resultArray;
    }
    /**
     * 健康设备
     * @param patient
     * @return
     */
    public JSONArray healthDevice(String patient){
        List<PatientDevice> list = patientDeviceDao.findByPatient(patient);
        JSONArray jsonArray = new JSONArray();
        list.forEach(device->{
            JSONObject json = new JSONObject();
            json.put("deviceName",device.getDeviceName());
            json.put("deviceSn",device.getDeviceSn());
            json.put("categoryCode",device.getCategoryCode());
            Device d = deviceDao.findOne(device.getDeviceId());
            json.put("photo",d.getPhoto());
            jsonArray.put(json);
        });
        return jsonArray;
    }
    /**
     * 获取门/急诊记录 + 住院记录
     * @param patientCode
     * @param type (1血糖,2血压)
     * @param page
     * @param pageSize
     * @return
     * @throws Exception
     */
    public com.alibaba.fastjson.JSONObject getAllEvent(String patientCode, String type, String page, String pageSize) throws Exception {
        List<Map<String, String>> re = new ArrayList<>();
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        //获取患者
        Patient patient = patientDao.findByCode(patientCode);
        //获取基卫数据
        String response = jwSmjkService.getResidentEventListJson(patient.getSsc(), null, page, pageSize);
        //获取app数据
        List<PatientEvent> eventList = new ArrayList<>();
        eventList = patientEventDao.findByPatient(patientCode);
        int year = 0;//患病年数
        int eventSize = 0;//就诊次数
        int times = 0;//住院次数
        if (!StringUtils.isEmpty(response)) {
            JSONArray array = new JSONArray(response);
            if (!"[{}]".equals(response)) {
                for (int i = 0; i < array.length(); i++) {
                    JSONObject item = array.getJSONObject(i);
                    Map<String, String> map = new HashMap<>();
                    map.put("id", item.optString("EVENT"));
                    map.put("patient", patientCode);
                    map.put("eventDate", item.optString("END_TIME"));
                    map.put("eventType", item.optString("TYPE"));
                    map.put("orgName", item.optString("ORG_NAME"));
                    map.put("dianosis", item.optString("DIAGNOSIS"));
                    map.put("createTime", item.optString("END_TIME"));
                    map.put("dataFrom", "1");//基卫数据
                    if(StringUtils.isNotBlank(type)){
                        //根据icd10过滤数据
                        String icdCode = item.optString("ICD_CODE");
                        Icd10Dict icd10Dict = icd10DictDao.findByCode(icdCode);
                        if(icd10Dict==null){
                            continue;
                        }
                        if("1".equals(type)){
                            //血糖
                            if(!"2".equals(icd10Dict.getType())){
                                continue;
                            }
                        }else {
                            //血压
                            if(!"1".equals(icd10Dict.getType())){
                                continue;
                            }
                        }
                    }
                    if("2".equals(item.optString("TYPE"))){
                        times++;
                    }
                    re.add(map);
                }
            }
        }
        if(StringUtils.isEmpty(type)){
            for (PatientEvent item : eventList) {
                Map<String, String> map = new HashMap<>();
                map.put("id", item.getId().toString());
                map.put("patient", item.getPatient());
                map.put("eventDate", DateUtil.dateToStrLong(item.getEventDate()));
                map.put("eventType", item.getEventType());
                map.put("orgName", item.getOrgName());
                map.put("dianosis", item.getDianosis());
                map.put("createTime", DateUtil.dateToStrLong(item.getCreateTime()));
                map.put("dataFrom", "2");   //APP数据
                re.add(map);
            }
            //排序
            re = sortMapList(re, "eventDate", "DESC");
        }
        eventSize = re.size();
        if(eventSize>0){
            //计算患病年数
            Date startTime = DateUtil.strToDateLong(re.get(0).get("eventDate"));
            Date endTime = DateUtil.strToDateLong(re.get(eventSize-1).get("eventDate"));
            year = DateUtil.compareYear(startTime,endTime);
        }
        //统计
        com.alibaba.fastjson.JSONObject statistics = new com.alibaba.fastjson.JSONObject();
        statistics.put("year",year);
        statistics.put("eventSize",eventSize);
        statistics.put("times",times);
        json.put("statistics",statistics);
        json.put("list",re);
        return json;
    }
    /**
     * 字符串List排序
     */
    public List<Map<String, String>> sortMapList(List<Map<String, String>> mapList, final String sort, final String order) {
        Collections.sort(mapList, new Comparator<Map<String, String>>() {
            @Override
            public int compare(Map<String, String> o1, Map<String, String> o2) {
                String map1value = o1.get(sort);
                String map2value = o2.get(sort);
                if ("DESC".equals(order.toUpperCase())) {
                    return map2value.compareTo(map1value);
                } else {
                    return map1value.compareTo(map2value);
                }
            }
        });
        return mapList;
    }
}

+ 25 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/DateUtil.java

@ -1273,4 +1273,29 @@ public class DateUtil {
		 return new Timestamp(calendar.getTimeInMillis());
	 }
	/**
	 * 比较2个时间相差月份
	 * @return
     */
	public static int compareYear(Date start,Date end){
		int re = 1;
		Calendar cal1 = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		cal1.setTime(start);
		cal2.setTime(end);
		int year = cal2.get(Calendar.YEAR)-cal1.get(Calendar.YEAR);
		int month = cal2.get(Calendar.MONTH)-cal1.get(Calendar.MONTH);
		int day = cal2.get(Calendar.DAY_OF_MONTH)-cal1.get(Calendar.DAY_OF_MONTH);
		if(year>0){
			re = year;
			if(month>0){
				re++;
			}else if(month==0&&day>=0){
				re++;
			}
		}
		return re;
	}
}

+ 81 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/MyJdbcTemplate.java

@ -0,0 +1,81 @@
package com.yihu.wlyy.util;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Component;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
 * @author yeshijie on 2018/2/12.
 */
@Component
public class MyJdbcTemplate {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * jdbc查询返回json
     * @param sql
     * @param args
     * @return
     * @throws DataAccessException
     */
    public List<JSONObject> queryJson(String sql, Object[] args) throws DataAccessException {
        return jdbcTemplate.query(sql, args, new ResultSetExtractor<List<JSONObject>>() {
            @Override
            public List<JSONObject> extractData(ResultSet rs) throws SQLException, DataAccessException {
                ResultSetMetaData rsd = rs.getMetaData();
                int clength = rsd.getColumnCount();
                List<JSONObject> li = new ArrayList<JSONObject>();
                try {
                    while (rs.next()) {
                        JSONObject jo = new JSONObject();
                        for (int i = 0; i < clength; i++) {
                            String columnName = rsd.getColumnLabel(i + 1);
                            jo.put(columnName, rs.getObject(i + 1));
                        }
                        li.add(jo);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return li;
            }
        });
    }
    public List<JSONObject> queryJson(String sql) throws DataAccessException {
        return jdbcTemplate.query(sql, new ResultSetExtractor<List<JSONObject>>() {
            @Override
            public List<JSONObject> extractData(ResultSet rs) throws SQLException, DataAccessException {
                ResultSetMetaData rsd = rs.getMetaData();
                int clength = rsd.getColumnCount();
                List<JSONObject> li = new ArrayList<JSONObject>();
                try {
                    while (rs.next()) {
                        JSONObject jo = new JSONObject();
                        for (int i = 0; i < clength; i++) {
                            String columnName = rsd.getColumnLabel(i + 1);
                            jo.put(columnName, rs.getObject(i + 1));
                        }
                        li.add(jo);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return li;
            }
        });
    }
}

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

@ -0,0 +1,190 @@
package com.yihu.wlyy.web.third.gateway.controller.iot;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * 提供 物联网 - 远程健康监测平台 新增接口
 * @author yeshijie on 2018/2/11.
 */
@RestController
@RequestMapping(value = "/wlyygc/iot_monitoring",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "远程健康监测平台")
public class IotMonitoringHealthController extends BaseController {
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private PatientHealthIndexService healthIndexService;
    @RequestMapping(value = "/equipmentDistribution",method = RequestMethod.GET)
    @ApiOperation("设备发放情况")
    public String equipmentDistribution(){
        try {
            return write(200,"查询成功","data",patientDeviceService.equipmentDistribution());
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/chronicDiseaseCount",method = RequestMethod.GET)
    @ApiOperation("慢病患者情况-统计")
    public String chronicDiseaseCount(
            @ApiParam(name="type",value="类型(2糖尿病,1高血压)",defaultValue = "")
            @RequestParam(value="type",required = false) String type){
        try {
            return write(200,"查询成功","data",patientDeviceService.chronicDiseaseCount(type));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/warningInformationAlarm",method = RequestMethod.GET)
    @ApiOperation("预警信息警报")
    public String warningInformationAlarm(
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
            @RequestParam(value="pageSize",required = false) Integer pageSize){
        try {
            if(page==null){
                page = 1;
            }
            if(pageSize==null){
                pageSize = 10;
            }
            return write(200,"查询成功","data",patientDeviceService.warningInformationAlarm(page,pageSize));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/deviceBinding",method = RequestMethod.GET)
    @ApiOperation("设备绑定情况")
    public String deviceBinding(
            @ApiParam(name="type",value="设备类型(1血糖仪,2血压计)",defaultValue = "")
            @RequestParam(value="type",required = false) String type){
        try {
            return write(200,"查询成功","data",patientDeviceService.deviceBinding(type));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/persionalInfo",method = RequestMethod.GET)
    @ApiOperation("个人信息")
    public String persionalInfo(@ApiParam(name="patient",value="居民code",defaultValue = "")
                                @RequestParam(value="patient",required = true) String patient){
        try {
            JSONObject jsonObject = patientDeviceService.persionalInfo(patient);
            Integer status = jsonObject.getInteger("status");
            if(status==-1){
                return error(-1,"居民未签约");
            }
            jsonObject.remove("status");
            return write(200,"查询成功","data",jsonObject);
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/familyMember",method = RequestMethod.GET)
    @ApiOperation("家人信息")
    public String familyMember(@ApiParam(name="patient",value="居民code",defaultValue = "")
                                @RequestParam(value="patient",required = true) String patient){
        try {
            return write(200,"查询成功","data",patientDeviceService.familyMember(patient));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/healthDevice",method = RequestMethod.GET)
    @ApiOperation("健康设备")
    public String healthDevice(@ApiParam(name="patient",value="居民code",defaultValue = "")
                               @RequestParam(value="patient",required = true) String patient){
        try {
            return write(200,"查询成功","data",patientDeviceService.healthDevice(patient));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "chart", method = RequestMethod.GET)
    @ApiOperation("根据患者标志获取健康指标(图表)")
    public String getHealthIndexChartByPatient(@ApiParam(name="patient",value="居民code",defaultValue = "")
                                               @RequestParam(value="patient",required = true) String patient,
                                               @ApiParam(name = "type", value = "指标类型(1血糖,2血压,3体重,4腰围)", defaultValue = "1")
                                               @RequestParam(value = "type", required = true) int type,
                                               @ApiParam(name = "gi_type", value = "就餐类型0全部", defaultValue = "1")
                                               @RequestParam(value = "gi_type", required = false) int gi_type,
                                               @ApiParam(name = "begin", value = "开始时间", defaultValue = "2017-05-22 00:00:00")
                                               @RequestParam(value = "begin", required = true) String begin,
                                               @ApiParam(name = "end", value = "结束时间", defaultValue = "2017-06-02 00:00:00")
                                               @RequestParam(value = "end", required = true) String end) {
        try {
            JSONArray jsonArray = healthIndexService.findChartByPatient(patient, type, gi_type, begin, end);
            if (jsonArray.length()==0) {
                return success("查询成功!");
            }
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
    @ApiOperation("获取门诊记录/住院记录(基卫+APP)")
    @RequestMapping(value = "/event", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public String getAllEvent(@ApiParam(name = "patient", value = "患者代码", defaultValue = "")
                              @RequestParam(value = "patient", required = true) String patient,
                              @ApiParam(name = "type", value = "类型(1血糖,2血压)", defaultValue = "")
                              @RequestParam(value = "type", required = false) String type,
                              @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) {
        try {
            JSONObject jsonObject = patientDeviceService.getAllEvent(patient, type, page, pageSize);
            return write(200, "获取就诊记录成功!", "data", jsonObject);
        } catch (Exception e) {
            error(e);
            if (e.getMessage().indexOf("卡号尚未在医疗机构注册过") > 0) {
                return error(-1, "对不起,您的社保卡有变更,请改天再试");
            } else if (e.getMessage().startsWith("error")) {
                return error(-1, e.getMessage());
            } else {
                return error(-1, "获取门/急诊数据失败!");
            }
        }
    }
}