|
@ -1,13 +1,27 @@
|
|
|
package com.yihu.wlyy.statistics.etl.dataFilter;
|
|
|
|
|
|
import com.yihu.wlyy.statistics.dao.DoctorAdminTeamDao;
|
|
|
import com.yihu.wlyy.statistics.dao.HospitalDao;
|
|
|
import com.yihu.wlyy.statistics.dao.SignPatientLabelInfoDao;
|
|
|
import com.yihu.wlyy.statistics.dao.TownDao;
|
|
|
import com.yihu.wlyy.statistics.etl.model.ETLModel;
|
|
|
import com.yihu.wlyy.statistics.etl.model.FilterModel;
|
|
|
import com.yihu.wlyy.statistics.job.business.Constant;
|
|
|
import com.yihu.wlyy.statistics.model.hosptial.Hospital;
|
|
|
import com.yihu.wlyy.statistics.model.label.SignPatientLabelInfo;
|
|
|
import com.yihu.wlyy.statistics.model.signfamily.SignFamily;
|
|
|
import com.yihu.wlyy.statistics.model.system.Town;
|
|
|
import com.yihu.wlyy.statistics.model.team.AdminTeam;
|
|
|
import com.yihu.wlyy.statistics.util.IdCardUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by Administrator on 2016.10.16.
|
|
@ -17,23 +31,292 @@ import java.util.List;
|
|
|
@Scope("prototype")
|
|
|
public class SignDataFilter {
|
|
|
|
|
|
public FilterModel filter(List<SignFamily> signFamilies,String level1Key){
|
|
|
return filterCommon(signFamilies,level1Key,null,null);
|
|
|
public static String level2Sex="1";//性别
|
|
|
public static String level2Age="2";//年龄
|
|
|
public static String level2Group="3";//分组
|
|
|
public static String level2Expenses="4";//费用
|
|
|
public static String level2Health="5";//健康服务分布
|
|
|
|
|
|
public static String level3Disease="1";//疾病分组
|
|
|
|
|
|
private StringBuffer errorContent =new StringBuffer();//错误信息
|
|
|
private StringBuffer allContent=new StringBuffer();//完整信息
|
|
|
|
|
|
@Autowired
|
|
|
private HospitalDao hospitalDao;
|
|
|
@Autowired
|
|
|
private TownDao townDao;
|
|
|
@Autowired
|
|
|
private DoctorAdminTeamDao doctorAdminTeamDao;
|
|
|
@Autowired
|
|
|
private SignPatientLabelInfoDao signPatientLabelInfoDao;
|
|
|
/**
|
|
|
* 过滤数据
|
|
|
* @param signFamilies 签约列表
|
|
|
* @param filterDate 过滤的是哪天的数据 yyyy-MM-dd
|
|
|
* @return
|
|
|
*/
|
|
|
public FilterModel filter(List<SignFamily> signFamilies,String filterDate){
|
|
|
return filterCommon(signFamilies,null,null,filterDate);
|
|
|
}
|
|
|
public FilterModel filter(List<SignFamily> signFamilies,String level1Key,String level2Key){
|
|
|
return filterCommon(signFamilies,level1Key,level2Key,null);
|
|
|
/**
|
|
|
* 过滤数据
|
|
|
* @param signFamilies 签约列表
|
|
|
* @param level2Key 二级维度的key
|
|
|
* @param filterDate 过滤的是哪天的数据 yyyy-MM-dd
|
|
|
* @return
|
|
|
*/
|
|
|
public FilterModel filter(List<SignFamily> signFamilies,String level2Key,String filterDate){
|
|
|
return filterCommon(signFamilies,level2Key,null,filterDate);
|
|
|
}
|
|
|
public FilterModel filter(List<SignFamily> signFamilies,String level1Key,String level2Key,String level3Key){
|
|
|
return filterCommon(signFamilies,level1Key,level2Key,level3Key);
|
|
|
/**
|
|
|
* 过滤数据
|
|
|
* @param signFamilies 签约列表
|
|
|
* @param level2Key 二级维度的key
|
|
|
* @param level3Key 三级维度的key
|
|
|
* @param filterDate 过滤的是哪天的数据 yyyy-MM-dd
|
|
|
* @return
|
|
|
*/
|
|
|
public FilterModel filter(List<SignFamily> signFamilies,String level2Key,String level3Key,String filterDate){
|
|
|
return filterCommon(signFamilies,level2Key,level3Key,filterDate);
|
|
|
}
|
|
|
|
|
|
private FilterModel filterCommon(List<SignFamily> signFamilies,String level1Key,String level2Key,String level3Key) {
|
|
|
StringBuffer error =new StringBuffer();//错误信息
|
|
|
StringBuffer allContent=new StringBuffer();//完整信息
|
|
|
/**
|
|
|
* 公共的抽取方法
|
|
|
* @param signFamilies 签约列表
|
|
|
* @param level2Key 二级维度的key
|
|
|
* @param level3Key 三级维度的key
|
|
|
* @param filterDate 过滤的是哪天的数据 yyyy-MM-dd
|
|
|
* @return
|
|
|
*/
|
|
|
private FilterModel filterCommon(List<SignFamily> signFamilies ,String level2Key,String level3Key,String filterDate) {
|
|
|
//查找出系统全部的全科医生
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
|
|
|
List<ETLModel> etlModelList=new ArrayList<>();//返回的ETL數據
|
|
|
|
|
|
return FilterModel.getFiltrerMode(error,allContent,etlModelList);
|
|
|
int allCount=signFamilies.size();//全部的数据
|
|
|
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;//是否统计失败
|
|
|
for (int i=0;i<signFamilies.size();i++){
|
|
|
SignFamily signFamily=signFamilies.get(i);
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
ETLModel etlModel=new ETLModel();
|
|
|
String returnLevel2Key=getLevel2Key(level2Key,signFamily);
|
|
|
etlModel.setLevel2Key(returnLevel2Key);//设置二级维度的Key
|
|
|
etlModel.setAdminTeam(adminTeam.getId()+"");
|
|
|
etlModel.setHospital(orgCodeTemp);
|
|
|
etlModel.setTown(hospital.getTown());
|
|
|
etlModel.setCity(Constant.city);
|
|
|
etlModelList.add(etlModel);
|
|
|
//统计数目+1
|
|
|
cityCount++;
|
|
|
townCount++;
|
|
|
orgCount++;
|
|
|
adminCount++;
|
|
|
}
|
|
|
String message="";
|
|
|
return FilterModel.getFiltrerMode(message,etlModelList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 得到二级维度的key
|
|
|
* @param level2Key
|
|
|
* @return
|
|
|
*/
|
|
|
private String getLevel2Key(String level2Key,SignFamily signFamily) {
|
|
|
String returnLevel2Key=null;
|
|
|
if(StringUtils.isEmpty(level2Key)){
|
|
|
switch (level2Key){
|
|
|
//性别
|
|
|
case "1" :{
|
|
|
returnLevel2Key = getSex(signFamily);
|
|
|
break;
|
|
|
}
|
|
|
//年龄
|
|
|
case "2" :{
|
|
|
returnLevel2Key = getAge(signFamily);
|
|
|
break;
|
|
|
}
|
|
|
//分组
|
|
|
case "3" :{
|
|
|
//得到患者的分组标签
|
|
|
returnLevel2Key = getGroup(signFamily);
|
|
|
break;
|
|
|
}
|
|
|
//费用
|
|
|
case "4" :{
|
|
|
returnLevel2Key = getExpenses(signFamily);
|
|
|
break;
|
|
|
}
|
|
|
//健康服务分布
|
|
|
case "5" :{
|
|
|
returnLevel2Key = getHealth(signFamily);
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return returnLevel2Key;
|
|
|
}
|
|
|
|
|
|
private String getHealth(SignFamily signFamily) {
|
|
|
String returnLevel2Key="0";//查找每个患者的健康分布标签
|
|
|
List<SignPatientLabelInfo> signPatientLabelInfoList= signPatientLabelInfoDao.findByPatientAndLabelTypeAndStatus(signFamily.getPatient(),"2",1);
|
|
|
if(signPatientLabelInfoList!=null&&signPatientLabelInfoList.size()>0){
|
|
|
returnLevel2Key=signPatientLabelInfoList.get(0).getLabel();
|
|
|
}
|
|
|
return returnLevel2Key;
|
|
|
}
|
|
|
|
|
|
private String getExpenses(SignFamily signFamily) {
|
|
|
String returnLevel2Key;
|
|
|
returnLevel2Key= StringUtils.isEmpty(signFamily.getExpensesStatus())?"0":signFamily.getExpensesStatus();
|
|
|
return returnLevel2Key;
|
|
|
}
|
|
|
|
|
|
private String getGroup(SignFamily signFamily) {
|
|
|
String returnLevel2Key;
|
|
|
List<SignPatientLabelInfo> signPatientLabelInfoList= signPatientLabelInfoDao.findByPatientAndLabelTypeAndStatus(signFamily.getPatient(),"1",1);
|
|
|
StringBuffer returnLevel2KeyBuffer= new StringBuffer("1");
|
|
|
if(signPatientLabelInfoList!=null&&signPatientLabelInfoList.size()>0){
|
|
|
returnLevel2KeyBuffer.append(signPatientLabelInfoList.get(0).getLabel());
|
|
|
}
|
|
|
if("2".equals(returnLevel2KeyBuffer.toString())){
|
|
|
String returnLevel2KeyTemp="0";
|
|
|
boolean hasGXY=false;//有高血压
|
|
|
boolean hasTNB=false;//糖尿病
|
|
|
//得到患者的疾病标签
|
|
|
signPatientLabelInfoList= signPatientLabelInfoDao.findByPatientAndLabelTypeAndStatus(signFamily.getPatient(),"3",1);
|
|
|
for (SignPatientLabelInfo signPatientLabelInfo:signPatientLabelInfoList){
|
|
|
if("1".equals(signPatientLabelInfo.getLabel())){//判斷是否有高血壓
|
|
|
returnLevel2KeyTemp="4";
|
|
|
hasGXY=true;
|
|
|
}
|
|
|
if("2".equals(signPatientLabelInfo.getLabel())){//判斷是否有糖尿病
|
|
|
returnLevel2KeyTemp="5";
|
|
|
hasTNB=true;
|
|
|
}
|
|
|
}
|
|
|
if (hasTNB&&hasGXY){
|
|
|
returnLevel2KeyTemp="6";
|
|
|
}
|
|
|
returnLevel2KeyBuffer.append(","+returnLevel2KeyTemp);
|
|
|
}
|
|
|
returnLevel2Key=returnLevel2KeyBuffer.toString();
|
|
|
return returnLevel2Key;
|
|
|
}
|
|
|
|
|
|
private String getAge(SignFamily signFamily) {
|
|
|
String returnLevel2Key;
|
|
|
int age= IdCardUtil.getAgeForIdcard(signFamily.getIdcard());
|
|
|
if(0==age){
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",年龄是0");
|
|
|
}
|
|
|
returnLevel2Key=age+"";
|
|
|
return returnLevel2Key;
|
|
|
}
|
|
|
|
|
|
private String getSex(SignFamily signFamily) {
|
|
|
String returnLevel2Key;
|
|
|
returnLevel2Key= IdCardUtil.getSexForIdcard(signFamily.getIdcard());
|
|
|
if("3".equals(returnLevel2Key)){
|
|
|
errorContent.append("签约code:"+signFamily.getCode()+",IdCard解析错误,分到未知的组里");
|
|
|
}
|
|
|
return returnLevel2Key;
|
|
|
}
|
|
|
|
|
|
private String saveContent(Integer size, Long qkCount, Long orgCount, Long townCount, Long cityCount, boolean isAll, StringBuffer errorContent,Long errorCount,String sql,String filterDate) {
|
|
|
StringBuffer string=new StringBuffer("统计"+filterDate+" 的签约数据完成 ,数据库查询到签约数目:"+size);
|
|
|
string.append(",sql语句:"+sql);
|
|
|
string.append(",过滤的脏数据数目:"+errorCount);
|
|
|
string.append(",统计到市的数据总数:"+cityCount);
|
|
|
string.append(",统计到区的数据总数:"+townCount);
|
|
|
string.append(",统计到机构的数据总数:"+orgCount);
|
|
|
string.append(",统计到团队的数据总数:"+qkCount);
|
|
|
string.append(",是否统计成功:"+isAll);
|
|
|
if(!isAll){
|
|
|
string.append(",失败原因:"+errorContent);
|
|
|
}
|
|
|
return string.toString();
|
|
|
}
|
|
|
}
|