|
@ -1,6 +1,9 @@
|
|
|
package com.yihu.wlyy.statistics.job.business;
|
|
|
|
|
|
import com.yihu.wlyy.statistics.dao.*;
|
|
|
import com.yihu.wlyy.statistics.etl.model.ETLModel;
|
|
|
import com.yihu.wlyy.statistics.etl.role.*;
|
|
|
import com.yihu.wlyy.statistics.etl.storage.DBStorage;
|
|
|
import com.yihu.wlyy.statistics.model.hosptial.Hospital;
|
|
|
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
|
|
|
import com.yihu.wlyy.statistics.model.job.WlyyQuotaResult;
|
|
@ -52,8 +55,15 @@ public class SignAgeGroupDiseaseJob implements Job {
|
|
|
private TownDao townDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private Level1Role levelRole;
|
|
|
@Autowired
|
|
|
private Level2Role level2Role;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
private Level3Role level3Role;
|
|
|
@Autowired
|
|
|
private DBStorage dbStorage;
|
|
|
@Autowired
|
|
|
private SignPatientLabelInfoDao signPatientLabelInfoDao;
|
|
|
|
|
@ -84,214 +94,153 @@ public class SignAgeGroupDiseaseJob implements Job {
|
|
|
*/
|
|
|
@Transactional
|
|
|
private void computequotaByPatientAge() {
|
|
|
try {
|
|
|
jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+12+"'");
|
|
|
//新建任务日志对象
|
|
|
QuartzJobLog wlyyJobLog = new QuartzJobLog();
|
|
|
wlyyJobLog.setJobStartTime(new Date());
|
|
|
wlyyJobLog.setJobId(wlyyJobConfig.getId());
|
|
|
wlyyJobLog.setJobName(wlyyJobConfig.getJobName());
|
|
|
List<AdminTeam> adminTeams=doctorAdminTeamDao.findAllTeam();
|
|
|
Map<String, AdminTeam> adminTeamMap = new HashMap<String, AdminTeam>();
|
|
|
for (AdminTeam adminTeam : adminTeams) {
|
|
|
adminTeamMap.put(adminTeam.getId()+"", adminTeam);
|
|
|
jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+12+"'");
|
|
|
//新建任务日志对象
|
|
|
QuartzJobLog quartzJobLog = new QuartzJobLog();
|
|
|
quartzJobLog.setJobStartTime(new Date());
|
|
|
quartzJobLog.setJobId(wlyyJobConfig.getId());
|
|
|
quartzJobLog.setJobName(wlyyJobConfig.getJobName());
|
|
|
List<AdminTeam> adminTeams=doctorAdminTeamDao.findAllTeam();
|
|
|
Map<String, AdminTeam> adminTeamMap = new HashMap<String, AdminTeam>();
|
|
|
for (AdminTeam adminTeam : adminTeams) {
|
|
|
adminTeamMap.put(adminTeam.getId()+"", adminTeam);
|
|
|
}
|
|
|
//查找出系统全部的机构
|
|
|
List<Hospital> hospitals = hospitalDao.findHospital2();
|
|
|
Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
|
|
|
for (Hospital hospital : hospitals) {
|
|
|
hospitalsMap.put(hospital.getCode(), hospital);
|
|
|
}
|
|
|
//查找出厦门市全部的区
|
|
|
List<Town> towns = townDao.findByCityCode(Constant.city);
|
|
|
Map<String, Town> townsMap = new HashMap<String, Town>();
|
|
|
for (Town town : towns) {
|
|
|
townsMap.put(town.getCode(), town);
|
|
|
}
|
|
|
//找出今天的签约信息
|
|
|
String sql=" select code,idcard,hospital,admin_team_code,patient from wlyy_sign_family a where a.type =2 and a.status =1 and a.apply_date>= '"+daybefore+ Constant.quota_date_last+"' and a.apply_date< '"+yesterday+ Constant.quota_date_last+"' and a.expenses_status=1 ";
|
|
|
List<SignFamily> signFamilys = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily .class));
|
|
|
Long cityCount = new Long(0L); //统计到市的数目
|
|
|
Long townCount = new Long(0L); //统计到所有区的数目
|
|
|
Long orgCount =new Long(0L);//统计到所有机构的数目
|
|
|
Long adminCount = new Long(0L);//统计到所有团队的数目
|
|
|
Long errorCount=new Long(0L);//脏数据
|
|
|
Boolean isAll=true;//是否统计失败
|
|
|
StringBuffer errorContent=new StringBuffer();
|
|
|
//统计有已改簽的
|
|
|
List<ETLModel> etlModels=new ArrayList<ETLModel>();
|
|
|
//数据过滤清洗出脏数据 -----------start
|
|
|
for(SignFamily signFamily:signFamilys){
|
|
|
ETLModel etlModel=new ETLModel();
|
|
|
String orgCode = signFamily.getHospital();
|
|
|
if(StringUtils.isEmpty(orgCode)) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的hospital数据为空");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
//查找出系统全部的机构
|
|
|
List<Hospital> hospitals = hospitalDao.findHospital2();
|
|
|
Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
|
|
|
for (Hospital hospital : hospitals) {
|
|
|
hospitalsMap.put(hospital.getCode(), hospital);
|
|
|
String orgCodeTemp="";
|
|
|
if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){
|
|
|
//站
|
|
|
orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00";
|
|
|
}else{
|
|
|
//社区
|
|
|
orgCodeTemp=orgCode;
|
|
|
}
|
|
|
//查找出厦门市全部的区
|
|
|
List<Town> towns = townDao.findByCityCode(Constant.city);
|
|
|
Map<String, Town> townsMap = new HashMap<String, Town>();
|
|
|
for (Town town : towns) {
|
|
|
townsMap.put(town.getCode(), town);
|
|
|
//判断社区有没有值
|
|
|
Hospital hospital=hospitalsMap.get(orgCodeTemp);
|
|
|
if(hospital == null) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的hospital数据不存在");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
//找出今天的签约信息
|
|
|
String sql=" select code,idcard,hospital,admin_team_code,patient from wlyy_sign_family a where a.type =2 and a.status =1 and a.apply_date>= '"+daybefore+ Constant.quota_date_last+"' and a.apply_date< '"+yesterday+ Constant.quota_date_last+"' and a.expenses_status=1 ";
|
|
|
List<SignFamily> signFamilys = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamily .class));
|
|
|
//数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
|
|
|
Map<String, Map<String, Map>> cityAgeMap = new HashMap<String, Map<String, Map>>();//key是市行政代码 目前只有厦门市
|
|
|
Map<String,Map> temp =new HashMap<String,Map>();
|
|
|
cityAgeMap.put(Constant.city, temp);
|
|
|
|
|
|
Map<String, Map<String, Map>> townAgeMap = new HashMap<String, Map<String, Map>>();//key是区行政代码
|
|
|
Map<String, Map<String, Map>> orgAgeMap = new HashMap<String, Map<String, Map>>();//key是机构代码
|
|
|
//统计有签约的
|
|
|
Long cityCount = 0L; //统计到市的数目
|
|
|
Long townCount = 0L; //统计到所有区的数目
|
|
|
Long orgCount = 0L;//统计到所有机构的数目
|
|
|
Long qkCount = 0L;//统计到所有全科医生的数目
|
|
|
Long errorCount=0L;
|
|
|
boolean isAll=true;//是否统计失败
|
|
|
StringBuffer errorContent=new StringBuffer();
|
|
|
for (SignFamily signFamily : signFamilys) {
|
|
|
String orgCode = signFamily.getHospital();
|
|
|
if(StringUtils.isEmpty(orgCode)) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的hospital数据为空");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
String orgCodeTemp="";
|
|
|
if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){
|
|
|
//站
|
|
|
orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00";
|
|
|
}else{
|
|
|
//社区
|
|
|
orgCodeTemp=orgCode;
|
|
|
}
|
|
|
//判断社区有没有值
|
|
|
Hospital hospital=hospitalsMap.get(orgCodeTemp);
|
|
|
if(hospital == null) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的hospital数据不存在");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
Long adminId=signFamily.getAdminTeamCode();
|
|
|
if(adminId == null||adminId<=0) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的Admin_Team_Id数据为空");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
AdminTeam adminTeam=adminTeamMap.get(signFamily.getAdminTeamCode()+"");
|
|
|
if(adminTeam == null) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的Admin_Team_Id数据不存在");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
String idCard=signFamily.getIdcard();
|
|
|
if(idCard == null||((idCard.length()!=18&&idCard.length()!=15))) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的idCard数据异常");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
String town =hospital.getTown();
|
|
|
if(StringUtils.isEmpty(town)) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",机构表的中的town为空");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
Town townObj =townsMap.get(town);
|
|
|
if(townObj==null) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",机构表的中的town不存在");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
Integer age = IdCardUtil.getAgeForIdcard(idCard);//根据card解析年龄
|
|
|
String ageCode = getAgeCode(age);//得到年龄的code
|
|
|
|
|
|
boolean hasGXY = false;//有高血压
|
|
|
boolean hasTNB = false;//有糖尿病
|
|
|
//如果是慢病的 统计高血压的 糖尿病 1高血压,2糖尿病 3 糖尿病和高血压 4健康人群数
|
|
|
String diseaseType="4";
|
|
|
//得到患者的疾病标签
|
|
|
List<SignPatientLabelInfo> signPatientLabelInfoList= signPatientLabelInfoDao.findByPatientAndLabelTypeAndStatus(signFamily.getPatient(),"3",1);
|
|
|
for (SignPatientLabelInfo signPatientLabelInfo:signPatientLabelInfoList){
|
|
|
if("1".equals(signPatientLabelInfo.getLabel())){
|
|
|
diseaseType="1";
|
|
|
hasGXY=true;
|
|
|
}
|
|
|
if("2".equals(signPatientLabelInfo.getLabel())){
|
|
|
diseaseType="2";
|
|
|
hasTNB=true;
|
|
|
}
|
|
|
}
|
|
|
if (hasTNB&&hasGXY){
|
|
|
diseaseType="3";
|
|
|
}
|
|
|
|
|
|
//统计市
|
|
|
compute(cityAgeMap, Constant.city, ageCode, diseaseType);
|
|
|
cityCount++;
|
|
|
//统计区
|
|
|
compute(townAgeMap, town, ageCode, diseaseType);
|
|
|
townCount++;
|
|
|
//统计机构
|
|
|
//统计站
|
|
|
orgCode=hospital.getCode();
|
|
|
if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){
|
|
|
//统计站
|
|
|
orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00";
|
|
|
//统计机构
|
|
|
compute(orgAgeMap, orgCodeTemp, ageCode, diseaseType);
|
|
|
} else {
|
|
|
compute(orgAgeMap, hospital.getCode(), ageCode, diseaseType);
|
|
|
}
|
|
|
orgCount++;
|
|
|
Long adminId=signFamily.getAdminTeamCode();
|
|
|
if(adminId == null||adminId<=0) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的Admin_Team_Id数据为空");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
//保存统计数据
|
|
|
// 保存市的统计数据
|
|
|
for (Map.Entry<String, Map<String, Map>> entry : cityAgeMap.entrySet()) {
|
|
|
Map<String, Map> oneAgeMap = entry.getValue();
|
|
|
for(int i=1;i<7;i++){
|
|
|
for(int j=1;j<5;j++){
|
|
|
String key_2=i+"";
|
|
|
String key_3=j+"";
|
|
|
String city=Constant.city;
|
|
|
String cityName=Constant.cityName;
|
|
|
String town="";
|
|
|
String townName="";
|
|
|
String org="";
|
|
|
String orgName="";
|
|
|
save(oneAgeMap, key_2, key_3, city, cityName, town, townName, org, orgName,"4");
|
|
|
}
|
|
|
}
|
|
|
AdminTeam adminTeam=adminTeamMap.get(signFamily.getAdminTeamCode()+"");
|
|
|
if(adminTeam == null) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的Admin_Team_Id数据不存在");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
//保存区级
|
|
|
for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
|
|
|
//判断该区是否有统计数据
|
|
|
Map<String, Map> oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据
|
|
|
Town townObj = entry.getValue();//得到区级信息
|
|
|
for(int i=1;i<7;i++){
|
|
|
for(int j=1;j<5;j++){
|
|
|
String key_2=i+"";
|
|
|
String key_3=j+"";
|
|
|
String city=Constant.city;
|
|
|
String cityName=Constant.cityName;
|
|
|
String town=townObj.getCode();
|
|
|
String townName=townObj.getName();
|
|
|
String org="";
|
|
|
String orgName="";
|
|
|
save(oneAgeMap, key_2, key_3, city, cityName, town, townName, org, orgName,"3");
|
|
|
}
|
|
|
}
|
|
|
String idCard=signFamily.getIdcard();
|
|
|
if(idCard == null||((idCard.length()!=18&&idCard.length()!=15))) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",签约表中(wlyy_sign_family)中的idCard数据异常");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
|
|
|
//判断该机构是否有统计数据
|
|
|
Map<String, Map> oneAgeMap = orgAgeMap.get(entry.getKey());//得到当个机构的统计数据
|
|
|
Hospital hospital = entry.getValue();//得到机构信息
|
|
|
for(int i=1;i<7;i++){
|
|
|
for(int j=1;j<5;j++){
|
|
|
Hospital hospital1=entry.getValue();
|
|
|
if(hospital1==null)continue;
|
|
|
String key_2=i+"";
|
|
|
String key_3=j+"";
|
|
|
String city=Constant.city;
|
|
|
String cityName=Constant.cityName;
|
|
|
String town=hospital.getTown();
|
|
|
String townName=hospital.getTownName();
|
|
|
String org=hospital.getCode();
|
|
|
String orgName=hospital.getName();
|
|
|
save(oneAgeMap, key_2, key_3, city, cityName, town, townName, org, orgName,"2");
|
|
|
}
|
|
|
String town =hospital.getTown();
|
|
|
if(StringUtils.isEmpty(town)) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",机构表的中的town为空");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
Town townObj =townsMap.get(town);
|
|
|
if(townObj==null) {
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",机构表的中的town不存在");
|
|
|
isAll=false;
|
|
|
errorCount++;
|
|
|
continue;
|
|
|
}
|
|
|
boolean hasGXY = false;//有高血压
|
|
|
boolean hasTNB = false;//有糖尿病
|
|
|
//如果是慢病的 统计高血压的 糖尿病 1高血压,2糖尿病 3 糖尿病和高血压 4健康人群数
|
|
|
String diseaseType="4";
|
|
|
//得到患者的疾病标签
|
|
|
List<SignPatientLabelInfo> signPatientLabelInfoList= signPatientLabelInfoDao.findByPatientAndLabelTypeAndStatus(signFamily.getPatient(),"3",1);
|
|
|
for (SignPatientLabelInfo signPatientLabelInfo:signPatientLabelInfoList){
|
|
|
if("1".equals(signPatientLabelInfo.getLabel())){
|
|
|
diseaseType="1";
|
|
|
hasGXY=true;
|
|
|
}
|
|
|
if("2".equals(signPatientLabelInfo.getLabel())){
|
|
|
diseaseType="2";
|
|
|
hasTNB=true;
|
|
|
}
|
|
|
}
|
|
|
if (hasTNB&&hasGXY){
|
|
|
diseaseType="3";
|
|
|
}
|
|
|
wlyyJobLog.setJobEndTime(new Date());
|
|
|
wlyyJobLog.setJobContent(saveContent(signFamilys,qkCount,orgCount,townCount,cityCount,isAll,errorContent,errorCount,sql));
|
|
|
wlyyJobLog.setJobType(isAll?"1":"0");
|
|
|
quartzJobLogDao.save(wlyyJobLog);
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
etlModel.setLevel2Key(IdCardUtil.getAgeForIdcard(signFamily.getIdcard())+"");
|
|
|
etlModel.setLevel3Key(diseaseType);
|
|
|
etlModel.setAdminTeam(adminTeam.getId()+"");
|
|
|
etlModel.setHospital(orgCodeTemp);
|
|
|
etlModel.setTown(hospital.getTown());
|
|
|
etlModel.setCity(Constant.city);
|
|
|
etlModel.setIdcard(signFamily.getIdcard());
|
|
|
etlModels.add(etlModel);
|
|
|
//统计数目+1
|
|
|
cityCount++;
|
|
|
townCount++;
|
|
|
orgCount++;
|
|
|
adminCount++;
|
|
|
}
|
|
|
//数据过滤清洗出脏数据 -----------end
|
|
|
try{
|
|
|
//统计数据
|
|
|
List<Map<String, List<ETLModel>>> returnDatas= levelRole.elt(etlModels);
|
|
|
List<Map<String, Map<String, List<ETLModel>>>> patientSexRoleData= level2Role.elt(returnDatas);
|
|
|
List<Map<String, Map<String, Map<String, List<ETLModel>>>>> returnD=level3Role.elt(patientSexRoleData);
|
|
|
//保存数据
|
|
|
dbStorage.saveByLevel3(returnD,yesterday,wlyyQuota,6,4,1);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
errorContent.append("统计失败:"+e.getMessage());
|
|
|
}
|
|
|
//保存日志
|
|
|
quartzJobLog.setJobEndTime(new Date());
|
|
|
quartzJobLog.setJobContent(saveContent(signFamilys,adminCount,orgCount,townCount,cityCount,isAll,errorContent,errorCount,sql));
|
|
|
quartzJobLog.setJobType(isAll?"1":"0");
|
|
|
quartzJobLogDao.save(quartzJobLog);
|
|
|
}
|
|
|
private String saveContent(List<SignFamily> signFamilys, Long qkCount, Long orgCount, Long townCount, Long cityCount, boolean isAll, StringBuffer errorContent,long errorCount,String sql) {
|
|
|
StringBuffer string=new StringBuffer("统计"+yesterday+" 的签约数据完成 ,数据库查询到签约数目:"+signFamilys.size());
|