12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478 |
- package com.yihu.jw.iot;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.yihu.jw.device.dao.DevicePatientHealthIndexDao;
- import com.yihu.jw.device.dao.PatientDeviceDao;
- import com.yihu.jw.entity.care.device.DeviceHealthyInfoMapping;
- import com.yihu.jw.entity.care.device.DevicePatientHealthIndex;
- import com.yihu.jw.entity.patient.PatientDevice;
- import com.yihu.jw.patient.dao.BasePatientDao;
- import com.yihu.jw.util.date.DateUtil;
- import com.yihu.jw.util.http.HttpClientUtil;
- import org.apache.commons.lang.StringUtils;
- import org.apache.http.Consts;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.utils.URLEncodedUtils;
- import org.apache.http.message.BasicNameValuePair;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.*;
- /**
- * 物联网设备对接
- *
- * @author yeshijie on 2018/1/3.
- */
- @Service
- public class IotDeviceService {
- private Logger logger = LoggerFactory.getLogger(IotDeviceService.class);
- // @Value("${iot.url}")
- private String baseUrl;
- // @Value("${iot.appid}")
- private String appid;
- // @Value("${iot.appsecret}")
- private String appSecret;
- // @Value("${spring.profiles}")
- private String profiles;
- public static Map<String,String> tokenMap = new HashMap<>();
- private String grantType = "client_credentials";
- private String clientId = "Va5yQRHlA4Fq4eR3LT0vuXV4";
- private String clientSecret = "0rDSjzQ20XUj5itV7WRtznPQSzr5pVw2";
- private String dataSource = "iHealth";
- private String accessToken = "iHealth";
- private String bloodSugarUnit = "mmol/L";
- private String bloodPressureUnit = "mmHg";
- private String pulseUnit = "bpm";
- private String heightUnit = "cm";
- private String weightUnit = "kg";
- private String bmiUnit = "kg/m^2";
- private String waistUnit = "cm";
- @Autowired
- private HttpClientUtil httpClientUtil;
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private PatientDeviceDao patientDeviceDao;
- @Autowired
- private BasePatientDao patientDao;
- @Autowired
- private DevicePatientHealthIndexDao devicePatientHealthIndexDao;
- // @Autowired
- // private WlyyIotUploadDataLogDao wlyyIotUploadDataLogDao;
- // @Autowired
- // private MyJdbcTemplate myJdbcTemplate;
- // @Autowired
- // private SignFamilyDao signFamilyDao;
- // @Autowired
- // private SystemDictDao systemDictDao;
- // @Autowired
- // private DeviceHealthyInfoMappingDao deviceHealthyInfoMappingDao;
- // @Autowired
- // private SkJsonFormDao skJsonFormDao;
- /**
- * 判断是否数据上传到物联网
- * @return
- */
- // public Boolean isUploadIot(){
- // String value = systemDictDao.findByDictNameAndCode("SYSTEM_PARAMS","DEVICE_UPLOAD_IOT");
- // return "1".equals(value)?true:false;
- // }
- //
- // public Boolean isIotSearch(){
- // String value = systemDictDao.findByDictNameAndCode("SYSTEM_PARAMS","isIotSearch");
- // return "1".equals(value)?true:false;
- // }
- //
- public String getOauthAccessToken(){
- String url = baseUrl+"/oauth/2.0/token";
- List<NameValuePair> params = new ArrayList<>();
- params.add(new BasicNameValuePair("grant_type",grantType));
- params.add(new BasicNameValuePair("client_id",clientId));
- params.add(new BasicNameValuePair("client_secret",clientSecret));
- String response = httpClientUtil.post(url, params, "UTF-8");
- return null;
- }
- /**
- * 设备注册及绑定
- * @return
- */
- public String registedevice(JSONObject json){
- json.put("access_token",accessToken);
- json.put("data_source",dataSource);
- String url = baseUrl+"/dataInput/userBind";
- String response = sendPost(url, json.toString());
- return response;
- }
- /**
- * 设备绑定
- * @param patientDevice
- * @param address
- * @param name
- * @param diseaseCondition 病情:0绿标,1黄标,2红标
- * @return
- */
- public String saveDevice(PatientDevice patientDevice, String address, String name, Integer diseaseCondition, String hospitalName){
- JSONObject json = new JSONObject();
- json.put("categoryCode",patientDevice.getCategoryCode());
- json.put("address",address);
- json.put("hospitalName",hospitalName);
- json.put("patient",patientDevice.getUser());
- json.put("patientName",name);
- json.put("diseaseCondition",diseaseCondition);
- json.put("idcard",patientDevice.getUserIdcard());
- json.put("deviceId",patientDevice.getDeviceId());
- json.put("deviceName",patientDevice.getDeviceName());
- json.put("deviceSn",patientDevice.getDeviceSn());
- json.put("userType",patientDevice.getUserType());
- json.put("sim",patientDevice.getSim());
- json.put("agent",patientDevice.getAgent());
- json.put("doctor",patientDevice.getDoctor());
- return saveDevice(json.toString());
- }
- private String saveDevice(String json){
- String url = baseUrl+"/open/monitorPlatform/addPatientDevice";
- List<NameValuePair> params = new ArrayList<>();
- params.add(new BasicNameValuePair("jsonData",json));
- String response = httpClientUtil.post(url, params, "UTF-8");
- return response;
- }
- /**
- * 数据上传
- * @param json
- * @return
- */
- public String upload(JSONObject json){
- json.put("data_source",dataSource);
- String url = baseUrl+"/open/gc/uploadData";
- String response = sendPost(url, json.toString());
- return response;
- }
- /**
- * 保存i健康查询体征记录的记录
- */
- @Async
- // public void iHealthDataSearch(){
- // try{
- // if(isIotSearch()){
- // JSONObject json = new JSONObject();
- // String url = baseUrl+"/open/gc/iHealthDataSearch";
- // String response = sendPost(url, json.toString());
- // }
- // }catch (Exception e){
- // logger.error("调物联网接口报错:"+e.getMessage());
- // e.printStackTrace();
- // }
- // }
- /**
- * 访问i健康接口,自带登录信息
- * @param url
- * @return
- */
- private String sendGet(String url,String jsonData){
- String response = null;
- try{
- Map<String, Object> params = new HashMap();
- params.put("accesstoken",getAccessToken());
- params.put("jsonData",jsonData);
- params.put("appId",appid);
- List<BasicNameValuePair> jsonParams = new ArrayList<>();
- //配置参数
- if(params!=null) {
- for (String key : params.keySet()) {
- if (!StringUtils.isEmpty(String.valueOf(params.get(key))) && !"null".equals( String.valueOf(params.get(key)))) {
- jsonParams.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
- }
- }
- }
- response = httpClientUtil.get(url+"?"+ URLEncodedUtils.format(jsonParams, Consts.UTF_8),"utf-8");
- }catch (Exception e){
- e.printStackTrace();
- }
- return response;
- }
- private String sendPost(String url,String jsonData){
- String response = null;
- try{
- Map<String, Object> params = new HashMap();
- params.put("accesstoken",getAccessToken());
- List<NameValuePair> jsonParams = new ArrayList<>();
- if(StringUtils.isNotEmpty(jsonData)){
- jsonParams.add(new BasicNameValuePair("jsonData", jsonData));
- }
- jsonParams.add(new BasicNameValuePair("appId", appid));
- response = httpClientUtil.headerPost(url, jsonParams,"utf-8",params);
- }catch (Exception e){
- e.printStackTrace();
- }
- return response;
- }
- /**
- * 查询重复数据
- * @return
- */
- public String findRepeat(String user,String deviceSn,String value1,String value2,String type,String time){
- JSONArray jsonArray = new JSONArray();
- field("and","usercode","=",user,jsonArray);
- field("and","sn","=",deviceSn,jsonArray);
- field("and","del","=","1",jsonArray);
- if("1".equals(type)){
- //血糖
- field("and","value1","=",value1,jsonArray);
- }else {
- //血压
- field("and","value1","=",value1,jsonArray);
- if(StringUtils.isNotBlank(value2)){
- field("and","value2","=",value2,jsonArray);
- }
- }
- field("and","measure_time","=",time,jsonArray);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("filter",jsonArray);
- String url = baseUrl+"/dataSearch/getById";
- String response = sendPost(url, jsonObject.toString());
- return response;
- }
- /**
- * 按条件统计数量
- * @param start
- * @param end
- * @param status
- * @param patientCode
- * @return
- */
- public int getCountByTimeAndStatusAndPatient(String start,String end,Integer status,String patientCode){
- int re = 0;
- JSONArray jsonArray = new JSONArray();
- field("and","usercode","=",patientCode,jsonArray);
- field("and","status","=",String.valueOf(status),jsonArray);
- field("and","del","=","1",jsonArray);
- field("and","measure_time",">=",start,jsonArray);
- field("and","measure_time","<=",end,jsonArray);
- field("and","type",">=","1",jsonArray);
- field("and","type","<=","2",jsonArray);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("filter",jsonArray);
- jsonObject.put("page","1");
- jsonObject.put("size","50");
- String url = baseUrl+"/dataSearch/getById";
- String response = sendPost(url, jsonObject.toString());
- JSONObject json = JSONObject.parseObject(response);
- JSONArray ja = json.getJSONArray("obj");
- if(ja!=null){
- re = ja.size();
- }
- return re;
- }
- /**
- * 按居民code和类型查找
- * @param patient
- * @param type
- * @return
- */
- // 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);
- // 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",size);
- //
- // JSONArray sort = new JSONArray();
- // sort(sort,"measure_time","desc");
- // jsonObject.put("sort",sort);
- // String url = baseUrl+"/dataSearch/getById";
- // String response = sendPost(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","value2","=",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");
- // jsonObject.put("sort",sort);
- // String url = baseUrl+"/dataSearch/getById";
- // String response = sendPost(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;
- // }
- /**
- * 添加条件
- * 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
- * @param andOr
- * @param field
- * @param condition
- * @param value
- * @param jsonArray
- */
- private void field(String andOr,String field,String condition,String value,JSONArray jsonArray){
- JSONObject json = new JSONObject();
- json.put("andOr",andOr);
- json.put("field",field);
- json.put("condition",condition);
- json.put("value",value);
- jsonArray.add(json);
- }
- /**
- * 排序[{"key1":{"order":"asc|desc"}},{"key2":{"order":"asc|desc"}}]
- * @param jsonArray
- * @param key
- * @param order
- */
- private void sort(JSONArray jsonArray,String key,String order){
- JSONObject json = new JSONObject();
- json.put("order",order);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put(key,json);
- jsonArray.add(jsonObject);
- }
- /**
- * 查询单条
- * @param rid
- * @return
- */
- public String getById(String rid){
- JSONObject json = new JSONObject();
- JSONArray filters = new JSONArray();
- field("and","rid","=",rid,filters);
- json.put("filter",filters);
- String url = baseUrl+"/dataSearch/getById";
- String response = sendPost(url, json.toString());
- return response;
- }
- /**
- * 查询
- * filter
- * - 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
- * - 参数说明:andOr跟数据库的中的AND和OR相似;condition指条件匹配程度,?相当于数据库中的like;filed指检索的字段;value为检索的值
- * page - 参数说明:页码
- * size - 参数说明:分页大小 默认1
- * sort - 参数格式:排序,key要排序的字段,order固定,取值asc或desc,不需要排序,传""
- * 排序[{"key1":{"order":"asc|desc"}},{"key2":{"order":"asc|desc"}}]
- * @param json
- * @return
- */
- public String searchList(JSONObject json){
- String url = baseUrl+"/dataSearch/searchList";
- String response = sendPost(url, json.toString());
- return response;
- }
- /**
- *
- * @param json
- * @return
- */
- // public String listPage(JSONObject json){
- // String url = baseUrl+"/dataSearch/listPage";
- // String response = httpClientUtil.iotPostBody(url, json.toString());
- // return response;
- // }
- /**
- * 获取最近5条数据
- * @param json
- * @param sort
- * @return
- */
- public String recent5(JSONObject json,JSONObject sort){
- json.put("access_token",accessToken);
- String url = baseUrl+"/dataSearch/recent5";
- String response = sendPost(url, json.toString());
- return response;
- }
- /**
- * 获取居民一周内体征数据异常次数
- * @param json
- * @param sort
- * @return
- */
- public String recent1(JSONObject json,JSONObject sort){
- json.put("access_token",accessToken);
- String url = baseUrl+"/dataSearch/recent1";
- String response = sendPost(url, json.toString());
- return response;
- }
- /**
- * 初始化设备绑定数据
- * @return
- */
- // public void initPatientDevice(){
- // List<PatientDevice> list = patientDeviceDao.findAll();
- // list.forEach(patientDevice -> {
- // Patient patient = patientDao.findByCode(patientDevice.getUser());
- // if(patient!=null){
- // String address = patient.getAddress();
- // String hospital = null;
- // if(StringUtils.isBlank(address)){
- // //居民地址为空,默认取居民的社区,如果社区为空默认填写签约的社区医院
- // SignFamily signFamily = signFamilyDao.findByPatient(patientDevice.getUser());
- // if(signFamily!=null){
- // hospital = StringUtils.isBlank(signFamily.getSickVillageName())?signFamily.getHospitalName():signFamily.getSickVillageName();
- // }
- // }
- // String response = saveDevice(patientDevice,address,patient.getName(),patient.getDiseaseCondition(),hospital);
- // if(StringUtils.isNotBlank(response)){
- // JSONObject re = JSONObject.parseObject(response);
- // if(re.getInteger("status")!=200){
- // logger.error("id:"+patientDevice.getId()+" "+re.getString("errorMsg"));
- // }
- // }
- // }
- // });
- // }
- /**
- * 导入正式环境的坐标信息
- * @return
- */
- // public void exportNormalPatientDevice(){
- // String sql = "SELECT * from wlyy_device_location_tmp";
- // List<JSONObject> list = myJdbcTemplate.queryJson(sql);
- // list.forEach(device -> {
- // JSONObject json = new JSONObject();
- // json.put("categoryCode",device.getString("category_code"));
- // json.put("hospitalName",device.getString("hospital_name"));
- // json.put("address",device.getString("address"));
- // json.put("patient",device.getString("user"));
- // json.put("patientName",device.getString("name"));
- // json.put("diseaseCondition",device.getString("disease_condition"));
- // json.put("idcard",device.getString("user_idcard"));
- // json.put("deviceId",device.getString("device_id"));
- // json.put("deviceName",device.getString("device_name"));
- // json.put("deviceSn",device.getString("device_sn"));
- // json.put("userType",device.getString(""));
- // json.put("sim",device.getString("sim"));
- // json.put("agent",device.getString("agent"));
- // json.put("doctor",device.getString("doctor"));
- // saveDevice(json.toString());
- // });
- // }
- /**
- * 测试设备绑定
- * @return
- */
- // public String testSaveDevice(){
- // List<PatientDevice> list = patientDeviceDao.findAll();
- // PatientDevice patientDevice = list.get(0);
- // Patient patient = patientDao.findByCode(patientDevice.getUser());
- // SignFamily signFamily = signFamilyDao.findByPatient(patientDevice.getUser());
- // String hospital = null;
- // if(signFamily!=null){
- // hospital = StringUtils.isBlank(signFamily.getSickVillageName())?signFamily.getHospitalName():signFamily.getSickVillageName();
- // }
- // String response = saveDevice(patientDevice,patient.getAddress(),patient.getName(),patient.getDiseaseCondition(),hospital);
- // return response;
- // }
- /**
- * 初始化上传
- * @param jsonObject
- * @return
- */
- public String initUpload(JSONObject jsonObject){
- JSONObject json = new JSONObject();
- Integer type = jsonObject.getInteger("type");
- json.put("data_source","iHealth");
- json.put("sn",StringUtils.trimToEmpty(jsonObject.getString("device_sn")));
- json.put("ext_code",StringUtils.trimToEmpty(jsonObject.getString("user_type")));
- if(StringUtils.isNotEmpty(jsonObject.getString("device_name"))){
- json.put("device_name",StringUtils.trimToEmpty(jsonObject.getString("device_name")));
- json.put("device_model",StringUtils.trimToEmpty(jsonObject.getString("device_name")));
- }else{
- //历史数据未绑定居民
- if(StringUtils.isNotEmpty(jsonObject.getString("device_sn"))){
- String sql = "SELECT i.device_code,i.device_model,i.device_name from device.wlyy_devices i WHERE device_code = '"+jsonObject.getString("device_sn")+"'";
- List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
- if(list.size()>0){
- json.put("device_name",StringUtils.trimToEmpty(list.get(0).get("device_name").toString()));
- json.put("device_model",StringUtils.trimToEmpty(list.get(0).get("device_model").toString()));
- }
- }
- }
- json.put("idcard",StringUtils.trimToEmpty(jsonObject.getString("idcard")));
- json.put("username",StringUtils.trimToEmpty(jsonObject.getString("name")));
- json.put("usercode",StringUtils.trimToEmpty(jsonObject.getString("user")));
- json.put("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
- json.put("status",getStatus(jsonObject.getString("status")));
- JSONArray jsonArray = new JSONArray();
- String measure_time = subStringTime(jsonObject.getString("record_date"));
- switch (type){
- case 1:
- //血糖
- JSONObject blood_sugar = new JSONObject();
- blood_sugar.put("measure_time",measure_time);
- blood_sugar.put("type","BloodSugar");
- blood_sugar.put("sign_name","blood_sugar");
- blood_sugar.put("sign_value",jsonObject.getString("value1"));
- blood_sugar.put("sign_unit",bloodSugarUnit);
- jsonArray.add(blood_sugar);
- JSONObject blood_sugar_result = new JSONObject();
- blood_sugar_result.put("measure_time",measure_time);
- blood_sugar_result.put("type","BloodSugar");
- blood_sugar_result.put("sign_name","blood_sugar_result");
- blood_sugar_result.put("sign_value",jsonObject.getString("value2"));
- jsonArray.add(blood_sugar_result);
- break;
- case 2:
- //血压
- JSONObject systolic = new JSONObject();
- systolic.put("measure_time",measure_time);
- systolic.put("type","BloodPressure");
- systolic.put("sign_name","systolic");
- systolic.put("sign_value",jsonObject.getString("value1"));
- systolic.put("sign_unit",bloodPressureUnit);
- jsonArray.add(systolic);
- JSONObject diastolic = new JSONObject();
- diastolic.put("measure_time",measure_time);
- diastolic.put("type","BloodPressure");
- diastolic.put("sign_name","diastolic");
- diastolic.put("sign_value",jsonObject.getString("value2"));
- diastolic.put("sign_unit",bloodPressureUnit);
- jsonArray.add(diastolic);
- if(StringUtils.isNotBlank(jsonObject.getString("value3"))){
- JSONObject pulse = new JSONObject();
- pulse.put("measure_time",measure_time);
- pulse.put("type","BloodPressure");
- pulse.put("sign_name","pulse");
- pulse.put("sign_value",jsonObject.getString("value3"));
- pulse.put("sign_unit",pulseUnit);
- jsonArray.add(pulse);
- }
- break;
- case 3:
- //体重/身高/BMI
- JSONObject height = new JSONObject();
- height.put("measure_time",measure_time);
- height.put("type","Height");
- height.put("sign_name","height");
- height.put("sign_value",jsonObject.getString("value1"));
- height.put("sign_unit",heightUnit);
- jsonArray.add(height);
- JSONObject weight = new JSONObject();
- weight.put("measure_time",measure_time);
- weight.put("type","Height");
- weight.put("sign_name","weight");
- weight.put("sign_value",jsonObject.getString("value2"));
- weight.put("sign_unit",weightUnit);
- jsonArray.add(weight);
- if(StringUtils.isNotBlank(jsonObject.getString("value3"))){
- JSONObject bmi = new JSONObject();
- bmi.put("measure_time",measure_time);
- bmi.put("type","Height");
- bmi.put("sign_name","bmi");
- bmi.put("sign_value",jsonObject.getString("value3"));
- bmi.put("sign_unit",bmiUnit);
- jsonArray.add(bmi);
- }
- break;
- case 4:
- //腰围
- JSONObject waist = new JSONObject();
- waist.put("measure_time",measure_time);
- waist.put("type","Waist");
- waist.put("sign_name","waist");
- waist.put("sign_value",jsonObject.getString("value1"));
- waist.put("sign_unit",waistUnit);
- jsonArray.add(waist);
- break;
- default:
- break;
- }
- json.put("measure_data",jsonArray);
- //上传
- return json.toJSONString();
- }
- /************************************i健康业务相关 start************************************************************/
- /**
- * 更新状态
- * @param id
- */
- // public void updateStatus(Long id,String status){
- // DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(id,id);
- // if(mapping == null){
- // logger.error("未找到映射关系,id:"+id);
- // }else {
- // JSONObject json = new JSONObject();
- // json.put("rid",mapping.getRid());
- // json.put("status",status);
- // String url = baseUrl+"/open/gc/updateData";
- // String response = sendPost(url, json.toString());
- // JSONObject res = JSONObject.parseObject(response);
- // }
- // }
- /**
- * 查询单条
- * @param id
- * @return
- */
- // public DevicePatientHealthIndex getById(Long id){
- // DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(id,id);
- // if(mapping == null){
- // logger.error("未找到映射关系,id:"+id);
- // return null;
- // }else {
- // return transforOne(getById(mapping.getRid()),id);
- // }
- // }
- /**
- * 更新
- * @param obj
- * @return
- */
- // public DevicePatientHealthIndex update(DevicePatientHealthIndex obj){
- //
- // DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(obj.getId(),obj.getId());
- // if(mapping == null){
- // logger.error("未找到映射关系,id:"+obj.getId());
- // }else {
- // JSONObject json = new JSONObject();
- // json.put("rid",mapping.getRid());
- // json.put("del",obj.getDel());
- // transforIot(obj,json);
- // String url = baseUrl+"/open/gc/updateData";
- // String response = sendPost(url, json.toString());
- // JSONObject res = JSONObject.parseObject(response);
- // }
- //
- // return obj;
- // }
- /**
- * 删除
- * @param id
- */
- // public void delete(Long id){
- // DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(id,id);
- // if(mapping == null){
- // logger.error("未找到映射关系,id:"+id);
- // }else {
- // JSONObject json = new JSONObject();
- // json.put("rid",mapping.getRid());
- // json.put("del","0");
- // String url = baseUrl+"/open/gc/deleteData";
- // String response = sendPost(url, json.toString());
- //
- // JSONObject res = JSONObject.parseObject(response);
- // if("true".equals(res.getString("obj"))){
- // logger.info("删除成功!");
- // }else {
- // logger.error("删除失败,id="+id+",rid="+mapping.getRid()+",msg="+res.getString("errorMsg"));
- // }
- //
- // }
- // }
- /**
- * 测试上传
- * @param id
- */
- // public void testUpload(Long id){
- // DevicePatientHealthIndex index = devicePatientHealthIndexDao.findOne(id);
- // save(index);
- // }
- /**
- * 体征上传
- * @param obj
- * @return
- */
- // public DevicePatientHealthIndex save(DevicePatientHealthIndex obj){
- // JSONObject json = new JSONObject();
- // if(StringUtils.isNotBlank(obj.getDeviceSn())){
- // json.put("sn",obj.getDeviceSn());
- // List<PatientDevice> devices = patientDeviceDao.findByPatientAndDeviceSn(obj.getUser(),obj.getDeviceSn());
- // if(devices!=null&&devices.size()>0){
- // PatientDevice device = devices.get(0);
- // json.put("ext_code",device.getUserType());
- // json.put("device_name",transfor(device.getDeviceName(),1,obj.getType()));
- // json.put("device_model",transfor(device.getDeviceName(),2,obj.getType()));
- // }
- // }
- // Patient patient = patientDao.findByCode(obj.getUser());
- // json.put("idcard",patient.getIdcard());
- // json.put("idcard_type","1");
- // json.put("username",patient.getName());
- // json.put("usercode",patient.getCode());
- // json.put("del",obj.getDel());
- // json.put("status",obj.getStatus());
- // transforIot(obj,json);
- // //上传
- // String response = upload(json);
- // JSONObject re = JSONObject.parseObject(response);
- // String errorMsg = re.getString("errorMsg");//错误信息(请求失败才有错误消息)
- // if(StringUtils.isBlank(errorMsg)){
- // String rid = re.getJSONObject("obj").getJSONArray("rid").getString(0);
- // DeviceHealthyInfoMapping mapping = new DeviceHealthyInfoMapping();
- // mapping.setCreateTime(new Date());
- // mapping.setRid(rid);
- // deviceHealthyInfoMappingDao.save(mapping);
- // obj.setId(mapping.getId());
- // }else {
- // logger.error(errorMsg);
- // return null;
- // }
- // return obj;
- // }
- /************************************i健康业务相关 end ************************************************************/
- /*****************************************工具方法 start************************************************************/
- /**
- * 单条转换
- * @param res
- * @return
- */
- // public DevicePatientHealthIndex transforOne(String res,Long id){
- // if(StringUtils.isBlank(res)){
- // return null;
- // }
- // JSONObject jsonObject = JSONObject.parseObject(res);
- // if(jsonObject.getInteger("status")!=200||jsonObject.getJSONArray("obj").size()==0){
- // logger.error(jsonObject.getString("errorMsg"));
- // return null;
- // }
- // JSONObject obj = jsonObject.getJSONArray("obj").getJSONObject(0);
- // return transforHealthIndex(obj,id);
- // }
- /**
- * 转化成数据库对象
- * @param obj
- * @param id
- * @return
- */
- // private DevicePatientHealthIndex transforHealthIndex(JSONObject obj,Long id){
- // DevicePatientHealthIndex index = new DevicePatientHealthIndex();
- //
- // index.setDeviceSn(obj.getString("sn"));
- // index.setUser(obj.getString("usercode"));
- // index.setIdcard(obj.getString("idcard"));
- //
- // //{"errorCode":null,"errorMsg":null,"successMsg":"search success","status":200,"pageSize":10,"currPage":0,"totalPage":0,"totalCount":0,"detailModelList":null,
- // // "obj":[{"access_token":"test","data_source":"iHealth","sn":"867967022337804","ext_code":"","device_name":"","device_model":"",
- // // "data":[{"rid":"lwKBG349zj/XBIJOP8CpyoFxFKl0xyxLLzxpN/l9+1U=","del":1,"measure_time":"2016-08-26 12:32:04","systolic":"115.00","systolic_unit":"mmHg","diastolic":"105.00","pulse":"105.00","pulse_unit":"bpm"}],
- // // "idCard":"350122198601145513","username":"谢挺盛","usercode":"443a196ef8744536a531260eb26c05d7"}]}
- //
- // JSONObject data = obj.getJSONArray("data").getJSONObject(0);
- // if(id==null){
- // //从数据库中取id
- // DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByRid(data.getString("rid"));
- // if(mapping!=null){
- // id = mapping.getIndexId()==null?mapping.getId():mapping.getIndexId();
- // }
- // }
- // index.setId(id);
- // index.setRecordDate(DateUtil.strToDate(data.getString("measure_time")));
- // index.setSortDate(index.getRecordDate());
- // index.setType(data.getInteger("type"));
- // index.setDel(data.getString("del"));
- // index.setStatus(data.getInteger("status"));
- // if(data.getInteger("type")==1){
- // index.setValue1(data.getString("value1"));
- // index.setValue2(data.getString("value2"));
- // }else if(data.getInteger("type")==2){
- // index.setValue1(data.getString("value1"));
- // index.setValue2(data.getString("value2"));
- // index.setValue3(data.getString("value3"));
- // }else if(data.getInteger("type")==3){
- // index.setValue1(data.getString("value1"));
- // index.setValue2(data.getString("value2"));
- // index.setValue3(data.getString("value3"));
- // }else if(data.getInteger("type")==4){
- // index.setValue1(data.getString("value1"));
- // }
- // return index;
- // }
- /**
- * 字符串分割
- * @param name
- * @param type 1品牌,2 型号
- * @param deviceType 1血糖,2 血压
- * @return
- */
- private String transfor(String name,Integer type,Integer deviceType){
- String re = "";
- String[] brand = {"康为","爱奥乐","优瑞恩","三诺","云湃"};
- String[] model = {"A206G","G-777G","U80EH","亲智","RBP-980"};
- String model2 = "G-426-3";
- if(StringUtils.isBlank(name)){
- return re;
- }
- for(int i=0;i<brand.length;i++){
- String one = brand[i];
- if(name.contains(one)){
- re = type == 1? one:((i==0&&deviceType==1)?model2:model[i]);
- }
- }
- return re;
- }
- /**
- * 时间处理
- * @param time
- * @return
- */
- private String subStringTime(String time){
- return StringUtils.isBlank(time)? "":time.substring(0,19);
- }
- /**
- * 状态默认值
- * @param status
- * @return
- */
- private String getStatus(String status){
- return StringUtils.isBlank(status)?"0":status;
- }
- /**
- * 转化成物联网格式
- * @param obj
- * @param json
- * @return
- */
- public JSONObject transforIot(DevicePatientHealthIndex obj,JSONObject json){
- JSONArray jsonArray = new JSONArray();
- String measure_time = DateUtil.dateToStrLong(obj.getRecordDate());
- switch (obj.getType()){
- case 1:
- //血糖
- JSONObject blood_sugar = new JSONObject();
- blood_sugar.put("measure_time",measure_time);
- blood_sugar.put("type","BloodSugar");
- blood_sugar.put("sign_name","blood_sugar");
- blood_sugar.put("sign_value",obj.getValue1());
- blood_sugar.put("sign_unit",bloodSugarUnit);
- jsonArray.add(blood_sugar);
- JSONObject blood_sugar_result = new JSONObject();
- blood_sugar_result.put("measure_time",measure_time);
- blood_sugar_result.put("type","BloodSugar");
- blood_sugar_result.put("sign_name","blood_sugar_result");
- blood_sugar_result.put("sign_value",obj.getValue2());
- jsonArray.add(blood_sugar_result);
- break;
- case 2:
- //血压
- JSONObject systolic = new JSONObject();
- systolic.put("measure_time",measure_time);
- systolic.put("type","BloodPressure");
- systolic.put("sign_name","systolic");
- systolic.put("sign_value",obj.getValue1());
- systolic.put("sign_unit",bloodPressureUnit);
- jsonArray.add(systolic);
- JSONObject diastolic = new JSONObject();
- diastolic.put("measure_time",measure_time);
- diastolic.put("type","BloodPressure");
- diastolic.put("sign_name","diastolic");
- diastolic.put("sign_value",obj.getValue2());
- diastolic.put("sign_unit",bloodPressureUnit);
- jsonArray.add(diastolic);
- if(StringUtils.isNotBlank(obj.getValue3())){
- JSONObject pulse = new JSONObject();
- pulse.put("measure_time",measure_time);
- pulse.put("type","BloodPressure");
- pulse.put("sign_name","pulse");
- pulse.put("sign_value",obj.getValue3());
- pulse.put("sign_unit",pulseUnit);
- jsonArray.add(pulse);
- }
- break;
- case 3:
- //体重/身高/BMI
- JSONObject height = new JSONObject();
- height.put("measure_time",measure_time);
- height.put("type","Height");
- height.put("sign_name","height");
- height.put("sign_value",obj.getValue1());
- height.put("sign_unit",heightUnit);
- jsonArray.add(height);
- JSONObject weight = new JSONObject();
- weight.put("measure_time",measure_time);
- weight.put("type","Height");
- weight.put("sign_name","weight");
- weight.put("sign_value",obj.getValue2());
- weight.put("sign_unit",weightUnit);
- jsonArray.add(weight);
- if(StringUtils.isNotBlank(obj.getValue3())){
- JSONObject bmi = new JSONObject();
- bmi.put("measure_time",measure_time);
- bmi.put("type","Height");
- bmi.put("sign_name","bmi");
- bmi.put("sign_value",obj.getValue3());
- bmi.put("sign_unit",bmiUnit);
- jsonArray.add(bmi);
- }
- break;
- case 4:
- //腰围
- JSONObject waist = new JSONObject();
- waist.put("measure_time",measure_time);
- waist.put("type","Waist");
- waist.put("sign_name","waist");
- waist.put("sign_value",obj.getValue1());
- waist.put("sign_unit",waistUnit);
- jsonArray.add(waist);
- break;
- default:
- break;
- }
- json.put("measure_data",jsonArray);
- return json;
- }
- /**
- * 返回accessToken
- * @return
- */
- private synchronized String getAccessToken(){
- String token = "";
- if(tokenMap.get("token")!=null){
- token = tokenMap.get("token");
- Long outTime = Long.valueOf(tokenMap.get("outTime"));
- if(new Date().getTime()<outTime){
- return token;
- }
- }
- try {
- Map params = new HashMap();
- params.put("appid", appid);
- params.put("appSecret", appSecret);
- String url = "/open/gc/accesstoken";
- String response = httpClientUtil.httpPost(baseUrl + url, params);
- JSONObject jsonObject = JSON.parseObject(response);
- if(jsonObject.getInteger("status")==10000){
- String accesstoken = jsonObject.getJSONObject("result").getString("accesstoken");
- tokenMap.put("token",accesstoken);
- tokenMap.put("outTime", jsonObject.getJSONObject("result").getLong("outTime")+"");
- return accesstoken;
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- return null;
- }
- // public String iotDataImportJob(String idcard){
- // try {
- // String dayStr = DateUtil.getStringDateShort();
- // List<DevicePatientHealthIndex> healthIndices = new ArrayList<>();
- //
- // logger.info(":start IOT_DATA_IMPORT_JOB===============");
- //// 获取access token
- // String tokenUrl = "http://iot.xmtyw.cn:9660/cityihealth/iot/svr-iot/open/gc/accesstoken";
- // if ("prod".equals(profiles)){
- // tokenUrl = "http://27.155.102.211:9660/cityihealth/iot/svr-iot/open/gc/accesstoken";
- // }
- // if ("local".equals(profiles)){
- // tokenUrl = "http://10.95.22.10:9661/cityihealth/iot/svr-iot/open/gc/accesstoken";
- // }
- //
- // Map params = new HashMap();
- // params.put("appid", "b5125656570011ec8771005056ab2351");
- // params.put("appSecret", "b5125668570011ec8771005056ab2351");
- // String response = httpClientUtil.httpPost(tokenUrl, params);
- // JSONObject jsonObject = JSON.parseObject(response);
- // if(jsonObject.getInteger("status")==10000){
- // String accesstoken = jsonObject.getJSONObject("result").getString("accesstoken");
- // //获取体征数据
- // String searchUrl = "http://iot.xmtyw.cn:9660/cityihealth/iot/svr-iot/open/gc/searchList";
- // if ("prod".equals(profiles)){//外网
- // searchUrl = "http://27.155.102.211:9660/cityihealth/iot/svr-iot/open/gc/searchList2";
- // }
- // if ("local".equals(profiles)){//内网
- // searchUrl = "http://10.95.22.10:9661/cityihealth/iot/svr-iot/open/gc/searchList";
- // }
- // params = new HashMap();
- // params.put("accesstoken",accesstoken);
- // List<NameValuePair> bodyParams = new ArrayList<>();
- // if (StringUtils.isNotBlank(idcard)){
- // bodyParams.add(new BasicNameValuePair("idcard", idcard));
- // }
- // bodyParams.add(new BasicNameValuePair("startTime", dayStr+" 00:00:00"));
- // bodyParams.add(new BasicNameValuePair("endTime", dayStr+" 23:59:59"));
- // response = httpClientUtil.headerPost(searchUrl, bodyParams,"utf-8",params);
- // jsonObject = JSONObject.parseObject(response);
- //
- // if(jsonObject.getInteger("status")==200){
- // JSONArray array = jsonObject.getJSONArray("detailModelList");
- // for (int i=0;i<array.size();i++){
- // try {
- // JSONObject tmp = array.getJSONObject(i);
- // String sn = tmp.getString("sn");
- // String userName = tmp.getString("username");
- // idcard = tmp.getString("idcard");
- // Patient patient = patientDao.findByIdcard(idcard);
- // SignFamily sf = signFamilyDao.findByIdcard(idcard);
- // if (null!=patient){
- // JSONArray measureDatas = tmp.getJSONArray("measure_data");
- // if (measureDatas.size()>0){
- // try {
- // JSONObject dataInfo = measureDatas.getJSONObject(0);
- // //血压 BloodPressure 收缩压systolic 舒张压diastolic
- // //血糖 BloodSugar blood_sugar
- // //数据类型
- // String dataType = dataInfo.getString("type");
- // String sign_value = dataInfo.get("sign_value").toString();
- // String sign_name = dataInfo.get("sign_name").toString();
- // String measure_time = dataInfo.get("measure_time").toString();
- // Date measureDate = DateUtil.strToDate(measure_time);
- // String sign_unit = dataInfo.get("sign_unit").toString();
- // if ("BloodPressure".equals(dataType)){
- // DevicePatientHealthIndex index = new DevicePatientHealthIndex();
- // index.setUser(patient.getCode());
- // index.setDel("1");
- // index.setRecordDate(measureDate); //记录时间
- // index.setSortDate(measureDate); //排序时间
- // index.setCzrq(measureDate); //排序时间
- // index.setDeviceSn(sn);
- // index.setIdcard(idcard);
- // index.setStatus(0);
- // index.setName(userName);
- // if (null!=sf){
- // index.setHospital(sf.getHospital());
- // index.setHospitalName(sf.getHospitalName());
- // }
- // if ("systolic".equals(sign_name)){
- // index.setValue1(sign_value);//收缩压
- // }
- // if ("diastolic".equals(sign_name)){
- // index.setValue2(sign_value);//舒张压
- // }
- // if (measureDatas.size()>1){
- // JSONObject dataInfo2 = measureDatas.getJSONObject(1);
- // String sign_value2 = dataInfo2.get("sign_value").toString();
- // String sign_name2 = dataInfo2.get("sign_name").toString();
- // if ("systolic".equals(sign_name2)){
- // index.setValue1(sign_value2);//收缩压
- // }
- // if ("diastolic".equals(sign_name2)){
- // index.setValue2(sign_value2);//舒张压
- // }
- // }
- // index.setType(2);//1血糖,2血压
- // String sql = " select count(id) from device.wlyy_patient_health_index where `user`='"+patient.getCode()+"' " +
- // "and type='2' and value1='"+index.getValue1()+"' and value2='"+index.getValue2()+"' and record_date='"+measure_time+"' ";
- // if (0==jdbcTemplate.queryForObject(sql,Integer.class)){
- // healthIndices.add(index);
- // }
- // } else if ("BloodSugar".equals(dataType)) {
- // DevicePatientHealthIndex index = new DevicePatientHealthIndex();
- // index.setUser(patient.getCode());
- // index.setDel("1");
- // index.setRecordDate(measureDate); //记录时间
- // index.setSortDate(measureDate); //排序时间
- // index.setCzrq(measureDate); //排序时间
- // index.setDeviceSn(sn);
- // index.setIdcard(idcard);
- // index.setStatus(0);
- // index.setName(userName);
- // if (null!=sf){
- // index.setHospital(sf.getHospital());
- // index.setHospitalName(sf.getHospitalName());
- // }
- // index.setValue1(sign_value);//血糖
- // index.setValue2("1");//血糖类型
- // index.setType(1);//1血糖,2血压
- // String sql = " select count(id) from device.wlyy_patient_health_index where `user`='"+patient.getCode()+"' " +
- // "and type='1' and value1='"+index.getValue1()+"' and value2='1' and record_date='"+measure_time+"' ";
- // if (0==jdbcTemplate.queryForObject(sql,Integer.class)){
- // healthIndices.add(index);
- // }
- // }
- // }catch (Exception e){}
- // }
- // }
- // }catch (Exception e){}
- // }
- // }
- // }else {
- // throw new Exception("获取access token失败");
- // }
- // if (healthIndices.size()>0){
- // devicePatientHealthIndexDao.save(healthIndices);
- // }
- // logger.info(":start IOT_DATA_IMPORT_JOB success===============");
- // }catch (Exception e){
- // e.printStackTrace();
- // logger.info(":start IOT_DATA_IMPORT_JOB error==============message:"+e.getMessage());
- // }
- // return "success";
- // }
- // public String iotDataImportData(String json){
- // List<DevicePatientHealthIndex> healthIndices = new ArrayList<>();
- // try {
- // WlyyIotUploadDataLogDO uploadDataLogDO = new WlyyIotUploadDataLogDO();
- //
- // JSONObject jsonObject = null;
- // try {
- // jsonObject = JSONObject.parseObject(json);
- // } catch (Exception e) {
- // uploadDataLogDO.setJson(json);
- // uploadDataLogDO.setCreateTime(new Date());
- // wlyyIotUploadDataLogDao.save(uploadDataLogDO);
- // throw new Exception("json参数转换失败");
- // }
- // String deviceSn = jsonObject.getString("sn");
- // String userName = jsonObject.getString("username");
- // String idcard = jsonObject.getString("idcard");
- // uploadDataLogDO.setJson(json);
- // uploadDataLogDO.setDeviceSn(deviceSn);
- // uploadDataLogDO.setUserName(userName);
- // uploadDataLogDO.setIdcard(idcard);
- // uploadDataLogDO.setCreateTime(new Date());
- // wlyyIotUploadDataLogDao.save(uploadDataLogDO);
- //
- // Patient patient = patientDao.findByIdcard(idcard);
- // SignFamily sf = signFamilyDao.findByIdcard(idcard);
- // if (null!=patient){
- // JSONArray measureDatas = jsonObject.getJSONArray("measure_data");
- // if (measureDatas.size()>0){
- // try {
- // JSONObject dataInfo = measureDatas.getJSONObject(0);
- // //数据类型
- // String dataType = dataInfo.getString("type");
- // if (StringUtils.isNotBlank(dataType)){
- // switch (dataType){
- // case "BloodPressure": //血压
- // healthIndices.addAll(BloodPressureHandle(patient,sf,deviceSn,idcard,userName,measureDatas));
- // break;
- // case "BloodSugar"://血糖
- // healthIndices.addAll(BloodSugarHandle(patient,sf,deviceSn,idcard,userName,measureDatas));
- // break;
- // }
- // }
- // }catch (Exception e){}
- // }
- // }
- // }catch (Exception e){
- // e.printStackTrace();
- // }
- // if (healthIndices.size()>0){
- // devicePatientHealthIndexDao.save(healthIndices);
- // }
- // return "success";
- // }
- // public List<DevicePatientHealthIndex> BloodPressureHandle(Patient patient,SignFamily sf,String deviceSn,String idcard,String userName,JSONArray measureDatas){
- // List<DevicePatientHealthIndex> result = new ArrayList<>();
- // DevicePatientHealthIndex index = new DevicePatientHealthIndex();
- // JSONObject dataInfo = measureDatas.getJSONObject(0);
- //
- // String sign_value = dataInfo.get("sign_value").toString();
- // String sign_name = dataInfo.get("sign_name").toString();
- // String measure_time = dataInfo.get("measure_time").toString();
- // Date measureDate = DateUtil.strToDate(measure_time);
- // String sign_unit = dataInfo.get("sign_unit").toString();
- // //血压 BloodPressure 收缩压systolic 舒张压diastolic
- //
- // index.setUser(patient.getCode());
- // index.setDel("1");
- // index.setRecordDate(measureDate); //记录时间
- // index.setSortDate(measureDate); //排序时间
- // index.setCzrq(measureDate); //排序时间
- // index.setDeviceSn(deviceSn);
- // index.setIdcard(idcard);
- // index.setStatus(0);
- // index.setName(userName);
- // if (null!=sf){
- // index.setHospital(sf.getHospital());
- // index.setHospitalName(sf.getHospitalName());
- // }
- // if ("systolic".equals(sign_name)){
- // index.setValue1(sign_value);//收缩压
- // }
- // if ("diastolic".equals(sign_name)){
- // index.setValue2(sign_value);//舒张压
- // }
- // if (measureDatas.size()>1){
- // JSONObject dataInfo2 = measureDatas.getJSONObject(1);
- // String sign_value2 = dataInfo2.get("sign_value").toString();
- // String sign_name2 = dataInfo2.get("sign_name").toString();
- // if ("systolic".equals(sign_name2)){
- // index.setValue1(sign_value2);//收缩压
- // }
- // if ("diastolic".equals(sign_name2)){
- // index.setValue2(sign_value2);//舒张压
- // }
- // }
- // index.setType(2);//1血糖,2血压
- // String sql = " select count(id) from device.wlyy_patient_health_index where `user`='"+patient.getCode()+"' " +
- // "and type='2' and value1='"+index.getValue1()+"' and value2='"+index.getValue2()+"' and record_date='"+measure_time+"' ";
- // if (0==jdbcTemplate.queryForObject(sql,Integer.class)){
- // result.add(index);
- // }
- // return result;
- // }
- // public List<DevicePatientHealthIndex> BloodSugarHandle(Patient patient,SignFamily sf,String deviceSn,String idcard,String userName,JSONArray measureDatas){
- // List<DevicePatientHealthIndex> result = new ArrayList<>();
- // DevicePatientHealthIndex index = new DevicePatientHealthIndex();
- // JSONObject dataInfo = measureDatas.getJSONObject(0);
- // //血糖 BloodSugar blood_sugar
- //
- // String sign_value = dataInfo.get("sign_value").toString();
- // String sign_name = dataInfo.get("sign_name").toString();
- // String measure_time = dataInfo.get("measure_time").toString();
- // Date measureDate = DateUtil.strToDate(measure_time);
- // String sign_unit = dataInfo.get("sign_unit").toString();
- //
- //
- // index.setUser(patient.getCode());
- // index.setDel("1");
- // index.setRecordDate(measureDate); //记录时间
- // index.setSortDate(measureDate); //排序时间
- // index.setCzrq(measureDate); //排序时间
- // index.setDeviceSn(deviceSn);
- // index.setIdcard(idcard);
- // index.setStatus(0);
- // index.setName(userName);
- // if (null!=sf){
- // index.setHospital(sf.getHospital());
- // index.setHospitalName(sf.getHospitalName());
- // }
- // index.setValue1(sign_value);//血糖
- // index.setValue2("1");//血糖类型
- // index.setType(1);//1血糖,2血压
- // String sql = " select count(id) from device.wlyy_patient_health_index where `user`='"+patient.getCode()+"' " +
- // "and type='1' and value1='"+index.getValue1()+"' and value2='1' and record_date='"+measure_time+"' ";
- // if (0==jdbcTemplate.queryForObject(sql,Integer.class)){
- // result.add(index);
- // }
- // return result;
- // }
- /*****************************************工具方法 end ************************************************************/
- /*****************************************塞克上传接口***********************************************************/
- // @Transactional(rollbackFor = Exception.class)
- // public void skJsonSave(String idcard, Integer type, String json) {
- // SkJsonFormEntity skJsonFormEntity = new SkJsonFormEntity();
- // skJsonFormEntity.setJson(json);
- // skJsonFormEntity.setIdcard(idcard);
- // skJsonFormEntity.setType(type);
- // skJsonFormEntity.setStatus(0);
- // skJsonFormEntity.setCreateTime(new Date());
- // skJsonFormDao.save(skJsonFormEntity);
- // }
- public JSONObject getJoinPatient(String startTime,String endTime,String status,Integer page,Integer pageSize,String idcard) {
- JSONObject jsonObject = new JSONObject();
- String sql = "SELECT " +
- " DISTINCT cp.idcard,cp.`name`,cp.hospital,cp.hospital_name AS hospitalName,DATE_FORMAT(cp.create_time,'%Y-%m-%d %H:%i:%S') AS createTime" +
- ",DATE_FORMAT(cp.update_time,'%Y-%m-%d %H:%i:%S') AS updateTime" +
- ",cp.group_screening_code as groupScreeningCode,cp.status,cp.group_screening_status groupScreeningStatus," +
- " IF(mod(MID(cp.idcard,17,1),2),1,2) AS sex,p.birthday,p.mobile,cp.entry_time,cp.group_watch,cp.exit_time " +
- ",vi1.bracelet_date,rr2.return_time return_time2,rr3.return_time return_time3,rr4.return_time return_time4" +
- ",rr5.return_time return_time5,rr6.return_time return_time6,vi6.fill_date " +
- "FROM wlyy_copd_patient cp " +
- "LEFT JOIN wlyy_patient p ON cp.patient = p.`code` " +
- "LEFT JOIN wlyy_followup f1 on f1.patient_code = cp.patient and f1.type='4' and f1.visit_count='1' " +
- "LEFT JOIN wlyy_followup f2 on f2.patient_code = cp.patient and f2.type='4' and f2.visit_count='2' " +
- "LEFT JOIN wlyy_followup f3 on f3.patient_code = cp.patient and f3.type='4' and f3.visit_count='3' " +
- "LEFT JOIN wlyy_followup f4 on f4.patient_code = cp.patient and f4.type='4' and f4.visit_count='4' " +
- "LEFT JOIN wlyy_followup f5 on f5.patient_code = cp.patient and f5.type='4' and f5.visit_count='5' " +
- "LEFT JOIN wlyy_followup f6 on f6.patient_code = cp.patient and f6.type='4' and f6.visit_count='6' " +
- "LEFT JOIN copd_information_of_this_visit vi1 on f1.id = vi1.followup_id " +
- "LEFT JOIN copd_information_of_this_visit vi6 on f6.id = vi6.followup_id " +
- "LEFT JOIN copd_device_return_record rr2 on f2.id = rr2.followup_id " +
- "LEFT JOIN copd_device_return_record rr3 on f3.id = rr3.followup_id " +
- "LEFT JOIN copd_device_return_record rr4 on f4.id = rr4.followup_id " +
- "LEFT JOIN copd_device_return_record rr5 on f5.id = rr5.followup_id " +
- "LEFT JOIN copd_device_return_record rr6 on f6.id = rr6.followup_id " +
- " WHERE 1=1 ";
- String sqlTotal = "SELECT " +
- " count(DISTINCT idcard) " +
- "FROM " +
- " wlyy_copd_patient " +
- "WHERE 1=1 ";
- if("1".equals(status)){
- sql += " and cp.status = '1'";
- sqlTotal += " and status = '1'";
- }else if("2".equals(status)){
- sql += " AND group_screening_status <> '0' " +
- " AND group_screening_status IS NOT NULL " +
- " AND group_screening_status <> '' " ;
- sqlTotal += " AND group_screening_status <> '0' " +
- " AND group_screening_status IS NOT NULL " +
- " AND group_screening_status <> '' " ;
- }
- if (StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime)) {
- // String start = startTime.replace("-","").substring(0,8);
- // String end = endTime.replace("-","").substring(0,8);
- endTime += " 23:59:59";
- sql += " and ((cp.update_time >= '"+startTime+"' and cp.update_time <= '"+endTime+"') " +
- " or (cp.inclusion_time>='"+startTime+"' and cp.inclusion_time <='"+endTime+"') " +
- " or (cp.exit_time>='"+startTime+"' and cp.exit_time <='"+endTime+"') " +
- " or (vi6.fill_date>='"+startTime+"' and vi6.fill_date <='"+endTime+"') " +
- " or (second_inclusion_time>='"+startTime+"' and second_inclusion_time <='"+endTime+"')) ";
- sqlTotal += " and ((update_time >= '"+startTime+"' and update_time <= '"+endTime+"') " +
- " or (inclusion_time>='"+startTime+"' and inclusion_time <='"+endTime+"') " +
- " or (exit_time>='"+startTime+"' and exit_time <='"+endTime+"') " +
- " or (second_inclusion_time>='"+startTime+"' and second_inclusion_time <='"+endTime+"')) ";
- }
- if(StringUtils.isNotBlank(idcard)){
- sql += " and cp.idcard='"+idcard+"'";
- sqlTotal += " and idcard='"+idcard+"'";
- }
- sql +=" and hospital <> '5351e9756eb011e69f7c005056850d66' and hospital <> 'ac02a9b87a3611e69f7c005056850d66' and hospital is not null ";
- sql += " order by cp.id ";
- if (page==null&&pageSize==null) {
- page = 1;
- pageSize = 100;
- }
- sql += " LIMIT "+(page-1)*pageSize+","+pageSize;
- Integer total = jdbcTemplate.queryForObject(sqlTotal, Integer.class);
- List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
- jsonObject.put("total",total);
- jsonObject.put("listData",list);
- jsonObject.put("pageNum",Math.ceil(Double.valueOf(total)/Double.valueOf(pageSize)));
- return jsonObject;
- }
- }
|