|
@ -5,7 +5,6 @@ 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;
|
|
@ -23,7 +22,9 @@ 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.prescription.PrescriptionService;
|
|
|
import com.yihu.wlyy.service.app.team.AdminTeamService;
|
|
|
import com.yihu.wlyy.service.system.Icd10DictServcie;
|
|
|
import com.yihu.wlyy.service.third.iot.IotDeviceService;
|
|
|
import com.yihu.wlyy.service.third.jw.JwSmjkService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
@ -59,7 +60,8 @@ public class PatientDeviceService extends BaseService {
|
|
|
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
|
|
|
@Autowired
|
|
|
private Icd10DictServcie icd10DictServcie;
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
|
|
@ -87,7 +89,8 @@ public class PatientDeviceService extends BaseService {
|
|
|
private PatientHealthStandardDao patientHealthStandardDao;
|
|
|
@Autowired
|
|
|
private HttpClientUtil HttpClientUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionService prescriptionService;
|
|
|
@Value("${yihu.yihu_OpenPlatform_url}")
|
|
|
private String url;
|
|
|
@Value("${yihu.yihu_OpenPlatform_appId}")
|
|
@ -107,7 +110,10 @@ public class PatientDeviceService extends BaseService {
|
|
|
private IotDeviceService iotDeviceService;
|
|
|
@Autowired
|
|
|
private Icd10DictDao icd10DictDao;
|
|
|
|
|
|
//健康问题 高血压
|
|
|
private static final String gxy = "HP0093";
|
|
|
//健康问题 糖尿病
|
|
|
private static final String tnb = "HP0047";
|
|
|
Map<Integer, String> relations = new HashMap<>();
|
|
|
|
|
|
@PostConstruct
|
|
@ -209,7 +215,12 @@ public class PatientDeviceService extends BaseService {
|
|
|
// }
|
|
|
if(checkDeviceSn(sn)){
|
|
|
// patientDeviceDao.save(patientDevice);
|
|
|
savePatientDevice(patientDevice,patient.getAddress(),patient.getName());
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patient.getCode());
|
|
|
String hospital = null;
|
|
|
if(signFamily!=null){
|
|
|
hospital = signFamily.getHospitalName();
|
|
|
}
|
|
|
savePatientDevice(patientDevice,patient.getAddress(),patient.getName(),patient.getDiseaseCondition(),hospital);
|
|
|
}else {
|
|
|
String message = "设备不存在";
|
|
|
throw new Exception(message);
|
|
@ -222,9 +233,9 @@ public class PatientDeviceService extends BaseService {
|
|
|
* 设备绑定
|
|
|
* @param patientDevice
|
|
|
*/
|
|
|
public void savePatientDevice(PatientDevice patientDevice,String address,String patientName){
|
|
|
public void savePatientDevice(PatientDevice patientDevice,String address,String patientName,Integer diseaseCondition,String hospitalName){
|
|
|
if(iotDeviceService.isUploadIot()){
|
|
|
iotDeviceService.saveDevice(patientDevice,address,patientName);
|
|
|
iotDeviceService.saveDevice(patientDevice,address,patientName,diseaseCondition,hospitalName);
|
|
|
}else {
|
|
|
patientDeviceDao.save(patientDevice);
|
|
|
}
|
|
@ -689,7 +700,7 @@ public class PatientDeviceService extends BaseService {
|
|
|
* @return
|
|
|
*/
|
|
|
public List<com.alibaba.fastjson.JSONObject> chronicDiseaseCount(String type){
|
|
|
StringBuffer sql = new StringBuffer("SELECT p.disease_condition diseaseCondition,COUNT(*) num ");
|
|
|
StringBuffer sql = new StringBuffer("SELECT ifnull(p.disease_condition,-1) 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)){
|
|
@ -749,6 +760,30 @@ public class PatientDeviceService extends BaseService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 居民 医生搜索
|
|
|
* @param name
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
*/
|
|
|
public List<com.alibaba.fastjson.JSONObject> searchPatient(String name,Integer page,Integer pageSize){
|
|
|
StringBuffer sql = new StringBuffer("SELECT p.code,p.name,p.address,p.idcard,p.sex,GROUP_CONCAT(label_name) labelName,t.doctor_name doctorName ");
|
|
|
sql.append("FROM ( SELECT DISTINCT f.* FROM wlyy_patient_device d, wlyy_sign_family f ");
|
|
|
sql.append("WHERE f.`status` > 0 AND f.patient = d.`user` ) t, wlyy_patient p LEFT JOIN ");
|
|
|
sql.append("wlyy_sign_patient_label_info l on p. CODE = l.patient and l.`status`=1 ");
|
|
|
sql.append("AND l.label_type = 3 and (l.label=2 or l.label=1) WHERE t.patient = p. CODE ");
|
|
|
if(StringUtils.isNotBlank(name)){
|
|
|
sql.append(" and (p.`name` like '%"+name+"%' or t.doctor_name like '%"+name+"%') ");
|
|
|
}
|
|
|
sql.append("GROUP BY p.code,p.name,p.address,p.idcard,p.sex LIMIT ?,? ");
|
|
|
List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
|
|
|
list.forEach(json->{
|
|
|
json.put("age", IdCardUtil.getAgeForIdcard(String.valueOf(json.get("idcard"))));
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断当前值是否在区间内
|
|
|
*/
|
|
@ -908,6 +943,9 @@ public class PatientDeviceService extends BaseService {
|
|
|
int eventSize = 0;//就诊次数
|
|
|
int times = 0;//住院次数
|
|
|
|
|
|
int num = 10;//查找10次后就不找了。
|
|
|
int ni = 0;
|
|
|
String drugs = "";
|
|
|
if (!StringUtils.isEmpty(response)) {
|
|
|
JSONArray array = new JSONArray(response);
|
|
|
if (!"[{}]".equals(response)) {
|
|
@ -925,22 +963,45 @@ public class PatientDeviceService extends BaseService {
|
|
|
|
|
|
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;
|
|
|
String icdCode = item.optString("DIAGNOSIS");
|
|
|
String icd10 = icd10DictServcie.getHealthProblemsByIcd10Code(icdCode);
|
|
|
if(StringUtils.isNotBlank(icd10)){
|
|
|
com.alibaba.fastjson.JSONObject icd = com.alibaba.fastjson.JSONObject.parseObject(icd10);
|
|
|
String key = icd.getString("key");
|
|
|
if ("1".equals(type)) {
|
|
|
//主诊断为糖尿病
|
|
|
if(!tnb.equals(key)){
|
|
|
continue;
|
|
|
}
|
|
|
} else if("2".equals(type)){
|
|
|
//主诊断为高血压
|
|
|
if(!gxy.equals(key)){
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
//血压
|
|
|
if(!"1".equals(icd10Dict.getType())){
|
|
|
continue;
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
// 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;
|
|
|
// }
|
|
|
// }
|
|
|
ni++;
|
|
|
if(ni<num&&StringUtils.isEmpty(drugs)){
|
|
|
drugs = prescriptionService.findPatientMedicationRecords(patientCode,item.optString("END_TIME").toString(),type);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if("2".equals(item.optString("TYPE"))){
|
|
|
times++;
|
|
@ -982,6 +1043,7 @@ public class PatientDeviceService extends BaseService {
|
|
|
statistics.put("times",times);
|
|
|
json.put("statistics",statistics);
|
|
|
json.put("list",re);
|
|
|
json.put("drugs",drugs);
|
|
|
|
|
|
return json;
|
|
|
}
|
|
@ -1043,4 +1105,39 @@ public class PatientDeviceService extends BaseService {
|
|
|
}
|
|
|
return name;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据病种类型,搜索已绑定设备的居民设备SN码
|
|
|
* @param type 1高血压 2糖尿病
|
|
|
*/
|
|
|
public com.alibaba.fastjson.JSONObject iotSearchPatientDeviceSN(String type,Integer page,Integer pageSize){
|
|
|
|
|
|
if(page != 0){
|
|
|
page = page - 1;
|
|
|
}
|
|
|
|
|
|
StringBuffer sql = new StringBuffer("select t.device_sn from");
|
|
|
sql.append(" ( SELECT DISTINCT d.* FROM wlyy_patient_device d, wlyy_sign_family f WHERE f.`status` > 0 AND f.patient = d.`user` ) t, ");
|
|
|
sql.append(" wlyy_patient p " );
|
|
|
sql.append(" LEFT JOIN wlyy_sign_patient_label_info l on p. CODE = l.patient");
|
|
|
sql.append(" and l.`status`=1 AND l.label_type = 3 and l.label='"+type+"'");
|
|
|
sql.append(" WHERE t.user = p. CODE limit "+page+","+pageSize);
|
|
|
List<String> list = jdbcTemplate.queryForList(sql.toString(),String.class);
|
|
|
|
|
|
Integer count = 0;
|
|
|
|
|
|
StringBuffer countsql = new StringBuffer("select count(t.device_sn) total from");
|
|
|
countsql.append(" ( SELECT DISTINCT d.* FROM wlyy_patient_device d, wlyy_sign_family f WHERE f.`status` > 0 AND f.patient = d.`user` ) t, ");
|
|
|
countsql.append(" wlyy_patient p " );
|
|
|
countsql.append(" LEFT JOIN wlyy_sign_patient_label_info l on p. CODE = l.patient");
|
|
|
countsql.append(" and l.`status`=1 AND l.label_type = 3 and l.label='"+type+"'");
|
|
|
countsql.append(" WHERE t.user = p. CODE ");
|
|
|
|
|
|
count = jdbcTemplate.queryForObject(countsql.toString(),Integer.class);
|
|
|
|
|
|
com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
|
|
|
result.put("total",count);
|
|
|
result.put("list",list);
|
|
|
return result;
|
|
|
}
|
|
|
}
|