|
@ -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;
|
|
|
}
|
|
|
}
|