12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694 |
- package com.yihu.wlyy.job;
- import com.yihu.wlyy.entity.address.Hospital;
- import com.yihu.wlyy.entity.address.Town;
- import com.yihu.wlyy.entity.doctor.profile.Doctor;
- import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
- import com.yihu.wlyy.entity.job.QuartzJobLog;
- import com.yihu.wlyy.entity.patient.Patient;
- import com.yihu.wlyy.entity.patient.SignFamily;
- import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
- import com.yihu.wlyy.repository.address.TownDao;
- import com.yihu.wlyy.repository.doctor.DoctorDao;
- import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
- import com.yihu.wlyy.repository.job.QuartzJobLogDao;
- import com.yihu.wlyy.repository.organization.HospitalDao;
- import com.yihu.wlyy.repository.patient.PatientDao;
- import com.yihu.wlyy.repository.patient.SignFamilyDao;
- import com.yihu.wlyy.repository.statistics.WlyyQuotaResultDao;
- import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
- import com.yihu.wlyy.util.IdCardUtil;
- import com.yihu.wlyy.web.quota.WlyyJobConfigVO;
- import com.yihu.wlyy.web.quota.WlyyQuotaVO;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import org.quartz.Job;
- import org.quartz.JobDataMap;
- import org.quartz.JobExecutionContext;
- import org.quartz.JobExecutionException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Component;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import org.springframework.web.context.support.SpringBeanAutowiringSupport;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 签约的指标执行类
- */
- @Component
- public class SignJob implements Job {
- private WlyyQuotaVO wlyyQuota;//指标对象
- private WlyyJobConfigVO wlyyJobConfig;//配置对象
- @Autowired
- private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao
- @Autowired
- private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
- @Autowired
- private SignFamilyDao signFamilyDao;
- @Autowired
- private DoctorDao doctorDao;
- @Autowired
- private HospitalDao hospitalDao;
- @Autowired
- private TownDao townDao;
- @Autowired
- private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
- @Autowired
- private PatientDao patientDao;
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private PatientDiseaseService patientDiseaseService;
- @Autowired
- private StringRedisTemplate redisTemplate;
- String yesterday;
- String now;
- @Override
- public void execute(JobExecutionContext context)
- throws JobExecutionException {
- SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
- //初始化参数
- JobDataMap map = context.getJobDetail().getJobDataMap();
- wlyyQuota = (WlyyQuotaVO) map.get("quota");
- wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
- now = StringUtils.isEmpty(map.get("now")) ? SignJob.getDayString(0) : map.get("now").toString();
- yesterday = StringUtils.isEmpty(map.get("yesterday")) ? SignJob.getDayString(-1) : map.get("yesterday").toString();
- String level1 = wlyyQuota.getLevel1();//得到一级维度
- String level2 = wlyyQuota.getLevel2();//得到二级维度
- //如果一级维度为空 不进行统计
- if (!StringUtils.isEmpty(level1)) {
- if (StringUtils.isEmpty(level2)) {
- //線刪除今天的数据
- //2级维度是空按照一级的机构唯独计算指标
- computequota();
- } else {
- switch (level2) {
- case "1": {
- //線刪除今天的数据
- //患者性别
- computequotaByPatientSex();
- break;
- }
- case "2": {
- //患者分组
- computequotaByPatientGroup();
- break;
- }
- case "3": {
- //患者年龄
- computequotaByPatientAge();
- break;
- }
- }
- }
- }
- }
- /**
- * 机构维度下患者性别维度计算指标
- */
- @Transactional
- private void computequotaByPatientSex() {
- jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 6 + "'");
- try {
- //新建任务日志对象
- QuartzJobLog quartzJobLog = new QuartzJobLog();
- quartzJobLog.setJobStartTime(new Date());
- quartzJobLog.setJobId(wlyyJobConfig.getId());
- quartzJobLog.setJobName(wlyyJobConfig.getJobName());
- //查找出系统全部的机构
- List<Hospital> hospitals = hospitalDao.findHospitalzxFWZ();
- 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<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
- //数组里面第一个是女 第二个是男 第三个是未知
- Map<String, Map<String, Long>> citySexMap = new HashMap<String, Map<String, Long>>();//key是市行政代码 目前只有厦门市
- citySexMap.put(Constant.city, new HashMap<String, Long>());
- Map<String, Map<String, Long>> townSexMap = new HashMap<String, Map<String, Long>>();//key是区行政代码
- Map<String, Map<String, Long>> orgSexMap = new HashMap<String, Map<String, Long>>();//key是机构代码
- //统计有签约的
- for (SignFamily signFamily : signFamilys) {
- String idcard = signFamily.getIdcard();//得到签约中患者的身份证号
- Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
- String town = hospital.getTown();//得到患者签约的机构的区号
- String hospitalCode = hospital.getCode();//得到患者签约的机构号
- String sex = IdCardUtil.getSexForIdcard(idcard);//根据身份证得到性别
- //统计市 目前只统计厦门市 所以先写死 后期再改造
- if (citySexMap.containsKey(Constant.city)) {
- Map<String, Long> sexMap = citySexMap.get(Constant.city);
- sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
- citySexMap.put(Constant.city, sexMap);
- } else {
- Map<String, Long> sexMap = new HashMap<String, Long>();
- sexMap.put(sex, 1L);
- citySexMap.put(Constant.city, sexMap);
- }
- //统计区
- if (townSexMap.containsKey(town)) {
- Map<String, Long> sexMap = townSexMap.get(town);
- sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
- townSexMap.put(town, sexMap);
- } else {
- Map<String, Long> sexMap = new HashMap<String, Long>();
- sexMap.put(sex, 1L);
- townSexMap.put(town, sexMap);
- }
- //统计机构
- //统计站
- if (!"00".equals(hospitalCode.substring(8))) {
- String orgCodeTemp = hospitalCode.substring(0, 8) + "00";
- if (orgSexMap.containsKey(orgCodeTemp)) {
- Map<String, Long> sexMap = orgSexMap.get(orgCodeTemp);
- sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
- orgSexMap.put(orgCodeTemp, sexMap);
- } else {
- Map<String, Long> sexMap = new HashMap<String, Long>();
- sexMap.put(sex, 1L);
- orgSexMap.put(orgCodeTemp, sexMap);
- }
- } else {
- //统计社区
- if (orgSexMap.containsKey(hospitalCode)) {
- Map<String, Long> sexMap = orgSexMap.get(hospitalCode);
- sexMap.put(sex, (sexMap.get(sex) == null ? 0l : sexMap.get(sex)) + 1);
- orgSexMap.put(hospitalCode, sexMap);
- } else {
- Map<String, Long> sexMap = new HashMap<String, Long>();
- sexMap.put(sex, 1L);
- orgSexMap.put(hospitalCode, sexMap);
- }
- }
- }
- //保存统计数据
- //保存市统计数据
- for (Map.Entry<String, Map<String, Long>> entry : citySexMap.entrySet()) {
- //保存女
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_1_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_1)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_sex_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存男
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_2_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_2)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_sex_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存位置
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_3_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_sex_3)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_sex_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存区的统计数据
- for (Map.Entry<String, Town> townEntry : townsMap.entrySet()) {
- //判断该区是否有统计数据
- Map<String, Long> oneTownSexMap = townSexMap.get(townEntry.getKey());//得到当个区的统计数据
- Town town = townEntry.getValue();//得到区级信息
- //保存女
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_1_name);
- if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_1)) {
- wlyyQuotaResult.setResult(oneTownSexMap.get(Constant.level_sex_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存男
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_2_name);
- if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_2)) {
- wlyyQuotaResult.setResult(oneTownSexMap.get(Constant.level_sex_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存未知的统计信息
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_3_name);
- if (oneTownSexMap != null && oneTownSexMap.containsKey(Constant.level_sex_3)) {
- wlyyQuotaResult.setResult(oneTownSexMap.get(Constant.level_sex_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //统计机构
- for (Map.Entry<String, Hospital> hospitalEntry : hospitalsMap.entrySet()) {
- //判断该机构是否有统计数据
- Map<String, Long> oneorgSexMap = orgSexMap.get(hospitalEntry.getKey());//得到当个机构的统计数据
- Hospital hospital = hospitalEntry.getValue();//得到区级信息
- //保存女
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_1_name);
- if (oneorgSexMap != null && oneorgSexMap.containsKey(Constant.level_sex_1)) {
- wlyyQuotaResult.setResult(oneorgSexMap.get(Constant.level_sex_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存男
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_2_name);
- if (oneorgSexMap != null && oneorgSexMap.containsKey(Constant.level_sex_2)) {
- wlyyQuotaResult.setResult(oneorgSexMap.get(Constant.level_sex_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存未知
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_sex_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_sex_3_name);
- if (oneorgSexMap != null && oneorgSexMap.containsKey(Constant.level_sex_3)) {
- wlyyQuotaResult.setResult(oneorgSexMap.get(Constant.level_sex_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- quartzJobLog.setJobEndTime(new Date());
- quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约性别数据完成 ");
- quartzJobLog.setJobType("1");
- quartzJobLogDao.save(quartzJobLog);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 机构维度患者分组维度计算指标
- */
- @Transactional
- private void computequotaByPatientGroup() {
- jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 7 + "'");
- try {
- //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
- Map<String, Map<String, Long>> cityGroupMap = new HashMap<String, Map<String, Long>>();//key是市行政代码 目前只有厦门市
- cityGroupMap.put(Constant.city, new HashMap<String, Long>());
- Map<String, Map<String, Long>> townGroupMap = new HashMap<String, Map<String, Long>>();//key是区行政代码
- Map<String, Map<String, Long>> orgGroupMap = new HashMap<String, Map<String, Long>>();//key是机构代码
- //新建任务日志对象
- QuartzJobLog quartzJobLog = new QuartzJobLog();
- quartzJobLog.setJobStartTime(new Date());
- quartzJobLog.setJobId(wlyyJobConfig.getId());
- quartzJobLog.setJobName(wlyyJobConfig.getJobName());
- //查找出系统全部的机构
- List<Hospital> hospitals = hospitalDao.findHospital2();
- Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
- for (Hospital hospital : hospitals) {
- hospitalsMap.put(hospital.getCode(), hospital);
- Map<String, Long> one = new HashMap<String, Long>();
- one.put("1", 0L);
- one.put("2", 0L);
- one.put("3", 0L);
- one.put("4", 0L);
- one.put("5", 0L);
- one.put("100", 0L);
- orgGroupMap.put(hospital.getCode(), one);
- }
- //查找出系统全部的患者
- List<Patient> patients = patientDao.findAllSignPatient();
- Map<String, Patient> patientsMap = new HashMap<String, Patient>();
- for (Patient patient : patients) {
- patientsMap.put(patient.getCode(), patient);
- }
- //查找出厦门市全部的区
- List<Town> towns = townDao.findByCityCode(Constant.city);
- Map<String, Town> townsMap = new HashMap<String, Town>();
- for (Town town : towns) {
- townsMap.put(town.getCode(), town);
- Map<String, Long> one = new HashMap<String, Long>();
- one.put("1", 0L);
- one.put("2", 0L);
- one.put("3", 0L);
- one.put("4", 0L);
- one.put("5", 0L);
- one.put("100", 0L);
- townGroupMap.put(town.getCode(), one);
- }
- //得到所有的签约病人的分组信息
- List<DoctorPatientGroupInfo> doctorPatientGroupInfos = doctorPatientGroupInfoDao.findAllPatient();
- Map<String, String> groupMap = new HashMap<String, String>();
- for (DoctorPatientGroupInfo doctorPatientGroupInfo : doctorPatientGroupInfos) {
- groupMap.put(doctorPatientGroupInfo.getPatient(), doctorPatientGroupInfo.getGroup());
- }
- //找出今天的签约信息
- List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
- //统计有签约的
- for (SignFamily signFamily : signFamilys) {
- String patient = signFamily.getPatient();
- String group = groupMap.get(patient);//得到该签约病人的所在分组 1 普通 2 慢病 3是 65岁以上人群 4是 高血压 5是糖尿病 100是高血压和糖尿病
- Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
- if (hospital == null) {
- continue;
- }
- String town = hospital.getTown();
- //统计市 现在只有厦门市 默认先写死 后面再改
- if (cityGroupMap.containsKey(Constant.city)) {
- Map<String, Long> groupMapTemp = cityGroupMap.get(Constant.city);
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- cityGroupMap.put(Constant.city, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- cityGroupMap.put(Constant.city, groupMapTemp);
- }
- //统计区
- if (townGroupMap.containsKey(town)) {
- Map<String, Long> groupMapTemp = townGroupMap.get(town);
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- townGroupMap.put(town, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- townGroupMap.put(town, groupMapTemp);
- }
- //统计站
- if (!"00".equals(hospital.getCode().substring(8))) {
- String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
- //统计机构
- if (orgGroupMap.containsKey(orgCodeTemp)) {
- Map<String, Long> groupMapTemp = orgGroupMap.get(orgCodeTemp);
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- orgGroupMap.put(orgCodeTemp, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- orgGroupMap.put(orgCodeTemp, groupMapTemp);
- }
- } else {
- //统计机构
- if (orgGroupMap.containsKey(hospital.getCode())) {
- Map<String, Long> groupMapTemp = orgGroupMap.get(hospital.getCode());
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- orgGroupMap.put(hospital.getCode(), groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- orgGroupMap.put(hospital.getCode(), groupMapTemp);
- }
- }
- boolean hasGXY = false;//有高血压
- boolean hasTNB = false;//有糖尿病
- if ("2".equals(group)) {
- //如果是慢病的 统计高血压的 糖尿病 1高血压,2糖尿病
- String jsonString = redisTemplate.opsForValue().get("disease:" + patient);
- if (StringUtils.isEmpty(jsonString)) {
- continue;
- }
- //排除数据 只留下高血压和糖尿病
- List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
- JSONArray redisValues = new JSONArray(jsonString);
- for (Object obj : redisValues) {
- JSONObject redisValue = new JSONObject(obj);
- //排除掉三师签约
- if ("1".equals(redisValue.get("signType").toString())) {
- continue;
- }
- String disease = redisValue.get("disease").toString();
- if (Integer.valueOf(disease).equals("1")) {
- jsonObjects.add(redisValue);
- hasGXY = true;//设置有高血压
- }
- if (Integer.valueOf(disease).equals("2")) {
- jsonObjects.add(redisValue);
- hasTNB = true;//设置有糖尿病
- }
- }
- if(jsonObjects.size()==0){
- continue;//如果没有高血压和糖尿病 不统计
- }
- if (hasGXY && hasTNB) {
- group = "100";//有高血压又有糖尿病
- } else {
- group = Integer.valueOf(jsonObjects.get(0).get("disease").toString()) + 3 + "";//4高血压,5糖尿病
- }
- if (cityGroupMap.containsKey(Constant.city)) {
- Map<String, Long> groupMapTemp = cityGroupMap.get(Constant.city);
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- cityGroupMap.put(Constant.city, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- cityGroupMap.put(Constant.city, groupMapTemp);
- }
- //统计区
- if (townGroupMap.containsKey(town)) {
- Map<String, Long> groupMapTemp = townGroupMap.get(town);
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- townGroupMap.put(town, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- townGroupMap.put(town, groupMapTemp);
- }
- //统计机构
- //统计站
- if (!"00".equals(hospital.getCode().substring(8))) {
- String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
- //统计机构
- if (orgGroupMap.containsKey(orgCodeTemp)) {
- Map<String, Long> groupMapTemp = orgGroupMap.get(orgCodeTemp);
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- orgGroupMap.put(orgCodeTemp, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- orgGroupMap.put(orgCodeTemp, groupMapTemp);
- }
- } else {
- //统计机构
- if (orgGroupMap.containsKey(hospital.getCode())) {
- Map<String, Long> groupMapTemp = orgGroupMap.get(hospital.getCode());
- groupMapTemp.put(group, (groupMapTemp.get(group) == null ? 0l : groupMapTemp.get(group)) + 1);
- orgGroupMap.put(hospital.getCode(), groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(group, 1L);
- orgGroupMap.put(hospital.getCode(), groupMapTemp);
- }
- }
- }
- }
- //保存统计数据
- //保存市的统计数据
- for (Map.Entry<String, Map<String, Long>> entry : cityGroupMap.entrySet()) {
- //保存健康人群
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_1_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_1)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存慢病人群
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_2_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_2)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存65岁以上人群
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_3_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_3)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存高血压
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_4);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_4_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_4)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_4) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存糖尿病
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_5);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_5_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_5)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_5) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存糖尿病和高血压
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_100);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_100_name);
- if (entry.getValue() != null && entry.getValue().containsKey(Constant.level_group_100)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_group_100) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存区级
- //保存区的统计数据
- for (Map.Entry<String, Town> townEntry : townsMap.entrySet()) {
- //判断该区是否有统计数据
- Map<String, Long> oneTownGroupMap = townGroupMap.get(townEntry.getKey());//得到当个区的统计数据
- Town town = townEntry.getValue();//得到区级信息
- //保存健康人群
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_1_name);
- if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_1)) {
- wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存慢病人群
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_2_name);
- if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_2)) {
- wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存65岁以上人群
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_3_name);
- if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_3)) {
- wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存高血压
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_4);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_4_name);
- if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_4)) {
- wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_4) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存糖尿病
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_5);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_5_name);
- if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_5)) {
- wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_5) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存糖尿病
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_100);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_100_name);
- if (oneTownGroupMap != null && oneTownGroupMap.containsKey(Constant.level_group_100)) {
- wlyyQuotaResult.setResult(oneTownGroupMap.get(Constant.level_group_100) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存机构
- for (Map.Entry<String, Hospital> hospitalEntry : hospitalsMap.entrySet()) {
- //判断该机构是否有统计数据
- Map<String, Long> oneOrgGroupMap = orgGroupMap.get(hospitalEntry.getKey());//得到当个机构的统计数据
- Hospital hospital = hospitalEntry.getValue();//得到区级信息
- //保存健康人群
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_1_name);
- if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_1)) {
- wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存慢病
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_2_name);
- if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_2)) {
- wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存65岁以上人群
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_3_name);
- if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_3)) {
- wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存高血压
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_4);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_4_name);
- if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_4)) {
- wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_4) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存糖尿病
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_5);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_5_name);
- if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_5)) {
- wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_5) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存糖尿病和高血压
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_group_100);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_group_100_name);
- if (oneOrgGroupMap != null && oneOrgGroupMap.containsKey(Constant.level_group_100)) {
- wlyyQuotaResult.setResult(oneOrgGroupMap.get(Constant.level_group_100) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- quartzJobLog.setJobEndTime(new Date());
- quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约病人分组数据完成 ");
- quartzJobLog.setJobType("1");
- quartzJobLogDao.save(quartzJobLog);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 机构维度患者年龄维度计算指标
- */
- @Transactional
- private void computequotaByPatientAge() {
- try {
- jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 8 + "'");
- //新建任务日志对象
- QuartzJobLog quartzJobLog = new QuartzJobLog();
- quartzJobLog.setJobStartTime(new Date());
- quartzJobLog.setJobId(wlyyJobConfig.getId());
- quartzJobLog.setJobName(wlyyJobConfig.getJobName());
- //查找出系统全部的机构
- 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<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
- //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
- Map<String, Map<String, Long>> cityAgeMap = new HashMap<String, Map<String, Long>>();//key是市行政代码 目前只有厦门市
- cityAgeMap.put(Constant.city, new HashMap<String, Long>());
- Map<String, Map<String, Long>> townAgeMap = new HashMap<String, Map<String, Long>>();//key是区行政代码
- Map<String, Map<String, Long>> orgAgeMap = new HashMap<String, Map<String, Long>>();//key是机构代码
- //统计有签约的
- for (SignFamily signFamily : signFamilys) {
- Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
- String town = hospital.getTown();
- int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄
- String ageCode = getAgeCode(age);//得到年龄的code
- //统计市
- if (cityAgeMap.containsKey(Constant.city)) {
- Map<String, Long> groupMapTemp = cityAgeMap.get(Constant.city);
- groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
- cityAgeMap.put(Constant.city, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(ageCode, 1L);
- cityAgeMap.put(Constant.city, groupMapTemp);
- }
- //统计区
- if (townAgeMap.containsKey(town)) {
- Map<String, Long> groupMapTemp = townAgeMap.get(town);
- groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
- townAgeMap.put(town, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(ageCode, 1L);
- townAgeMap.put(town, groupMapTemp);
- }
- //统计机构
- //统计站
- if (!"00".equals(hospital.getCode().substring(8))) {
- String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
- //统计机构
- if (orgAgeMap.containsKey(orgCodeTemp)) {
- Map<String, Long> groupMapTemp = orgAgeMap.get(hospital.getCode());
- groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
- orgAgeMap.put(orgCodeTemp, groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(ageCode, 1L);
- orgAgeMap.put(orgCodeTemp, groupMapTemp);
- }
- } else {
- //统计机构
- if (orgAgeMap.containsKey(hospital.getCode())) {
- Map<String, Long> groupMapTemp = orgAgeMap.get(hospital.getCode());
- groupMapTemp.put(ageCode, (groupMapTemp.get(ageCode) == null ? 0l : groupMapTemp.get(ageCode)) + 1);
- orgAgeMap.put(hospital.getCode(), groupMapTemp);
- } else {
- Map<String, Long> groupMapTemp = new HashMap<String, Long>();
- groupMapTemp.put(ageCode, 1L);
- orgAgeMap.put(hospital.getCode(), groupMapTemp);
- }
- }
- }
- //保存统计数据
- // 保存市的统计数据
- for (Map.Entry<String, Map<String, Long>> entry : cityAgeMap.entrySet()) {
- Map<String, Long> oneAgeMap = entry.getValue();
- //保存0~6
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_1_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_1)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存7~18
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_2_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_2)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存18~30
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_3_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_3)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存30~50
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_4);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_4_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_4)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_4) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存50~65
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_5);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_5_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_5)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_5) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存18~30
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");//市级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_6);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_6_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_6)) {
- wlyyQuotaResult.setResult(entry.getValue().get(Constant.level_age_6) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存区级
- for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
- //判断该区是否有统计数据
- Map<String, Long> oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据
- Town town = entry.getValue();//得到区级信息
- //保存0~6
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_1_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_1)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存7~18
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_2_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_2)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存18~30
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_3_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_3)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存30~50
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_4);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_4_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_4)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_4) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存50~65
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_5);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_5_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_5)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_5) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存18~30
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(entry.getKey());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_6);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_6_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_6)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_6) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- for (Map.Entry<String, Hospital> hospitalEntry : hospitalsMap.entrySet()) {
- //判断该机构是否有统计数据
- Map<String, Long> oneAgeMap = orgAgeMap.get(hospitalEntry.getKey());//得到当个机构的统计数据
- Hospital hospital = hospitalEntry.getValue();//得到区级信息
- //保存0~6
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//区级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_1);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_1_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_1)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_1) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存7~18
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_2);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_2_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_2)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_2) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存18~30
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_3);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_3_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_3)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_3) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存30~50
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_4);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_4_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_4)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_4) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存50~65
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_5);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_5_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_5)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_5) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- //保存18~30
- wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");//机构级
- wlyyQuotaResult.setLevel2Type(Constant.level_age_6);
- wlyyQuotaResult.setLevel2TypeName(Constant.level_age_6_name);
- if (oneAgeMap != null && oneAgeMap.containsKey(Constant.level_age_6)) {
- wlyyQuotaResult.setResult(oneAgeMap.get(Constant.level_age_6) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- quartzJobLog.setJobEndTime(new Date());
- quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约患者年龄数据完成 ");
- quartzJobLog.setJobType("1");
- quartzJobLogDao.save(quartzJobLog);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 机构维度计算指标
- */
- @Transactional
- private void computequota() {
- jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + yesterday + "' and quato_code='" + 1 + "'");
- //新建任务日志对象
- QuartzJobLog quartzJobLog = new QuartzJobLog();
- quartzJobLog.setJobStartTime(new Date());
- quartzJobLog.setJobId(wlyyJobConfig.getId());
- quartzJobLog.setJobName(wlyyJobConfig.getJobName());
- //查找出系统全部的全科医生
- List<Doctor> doctors = doctorDao.findAllQKDoctot();
- Map<String, Doctor> doctorsMap = new HashMap<String, Doctor>();
- for (Doctor doctor : doctors) {
- doctorsMap.put(doctor.getCode(), doctor);
- }
- //查找出系统全部的机构
- List<Hospital> hospitals = hospitalDao.findHospitalzxFWZ();
- 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);
- }
- //找出今天的签约信息 yesterday,now
- List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
- Map<String, Long> tjTownMap = new HashMap<String, Long>();//区级的统计map key 是区行政区划350200
- Map<String, Long> tjOrgMap = new HashMap<String, Long>();//机构的统计map key 是机构的code
- Map<String, Long> tjQkdoctorMap = new HashMap<String, Long>();//团队级的统计map 目前没有团队 先用全科医生统一 key doctorCode
- Long cityCount = 0L;
- //统计有签约的
- for (SignFamily signFamily : signFamilys) {
- String doctorCode = signFamily.getDoctor();//得到签约中全科医生的code
- //统计团队
- if (tjQkdoctorMap.containsKey(doctorCode)) {
- tjQkdoctorMap.put(doctorCode, tjQkdoctorMap.get(doctorCode) + 1);
- } else {
- tjQkdoctorMap.put(doctorCode, 1L);
- }
- //判断医生属于哪个机构
- Doctor doctor = doctorsMap.get(doctorCode);
- if (doctor == null) {
- continue;
- }
- String orgCode = doctor.getHospital();
- //统计机构
- //统计站
- if (!"00".equals(orgCode.substring(8))) {
- String orgCodeTemp = orgCode.substring(0, 8) + "00";
- if (tjOrgMap.containsKey(orgCodeTemp)) {
- tjOrgMap.put(orgCodeTemp, tjOrgMap.get(orgCodeTemp) + 1);
- } else {
- tjOrgMap.put(orgCodeTemp, 1L);
- }
- } else {
- //统计社区
- if (tjOrgMap.containsKey(orgCode)) {
- tjOrgMap.put(orgCode, tjOrgMap.get(orgCode) + 1);
- } else {
- tjOrgMap.put(orgCode, 1L);
- }
- }
- String townCode = doctor.getTown();
- //统计区
- if (tjTownMap.containsKey(townCode)) {
- tjTownMap.put(townCode, tjTownMap.get(townCode) + 1);
- } else {
- tjTownMap.put(townCode, 1L);
- }
- //统计市
- cityCount++;
- }
- //保存统计的结果
- //保存全科医生的签约统计
- for (Map.Entry<String, Doctor> entry : doctorsMap.entrySet()) {
- Doctor doctor = doctorsMap.get(entry.getKey());//得到全科医生
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setOrgCode(doctor.getHospital());
- wlyyQuotaResult.setOrgName(doctor.getHosptialName());
- wlyyQuotaResult.setCity(doctor.getCity());
- wlyyQuotaResult.setCityName(doctor.getCityName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setQkdoctorJobName(doctor.getJobName());
- wlyyQuotaResult.setQkdoctorName(doctor.getName());
- wlyyQuotaResult.setQkdoctorCode(doctor.getCode());
- wlyyQuotaResult.setTown(doctor.getTown());
- wlyyQuotaResult.setTownName(doctor.getTownName());
- wlyyQuotaResult.setLevel1Type("1");
- //判断全科医生是否有签约量
- if (tjQkdoctorMap.containsKey(doctor.getCode())) {
- wlyyQuotaResult.setResult(tjQkdoctorMap.get(doctor.getCode()) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存机构的签约统计
- for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
- Hospital hospital = hospitalsMap.get(entry.getKey());//得到全科医生
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setOrgCode(hospital.getCode());
- wlyyQuotaResult.setOrgName(hospital.getName());
- wlyyQuotaResult.setCity(hospital.getCity());
- wlyyQuotaResult.setCityName(hospital.getCityName());
- wlyyQuotaResult.setTown(hospital.getTown());
- wlyyQuotaResult.setTownName(hospital.getTownName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("2");
- //判断全科医生是否有签约量
- if (tjOrgMap.containsKey(hospital.getCode())) {
- wlyyQuotaResult.setResult(tjOrgMap.get(hospital.getCode()) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存区级的签约统计
- for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
- Town town = townsMap.get(entry.getKey());//得到全科医生
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(town.getCity());
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setTown(town.getCode());
- wlyyQuotaResult.setTownName(town.getName());
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("3");
- //判断全科医生是否有签约量
- if (tjTownMap.containsKey(town.getCode())) {
- wlyyQuotaResult.setResult(tjTownMap.get(town.getCode()) + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- //保存市级的统计
- {
- WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
- wlyyQuotaResult.setDel("1");
- wlyyQuotaResult.setCity(Constant.city);
- wlyyQuotaResult.setCityName(Constant.cityName);
- wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
- wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
- wlyyQuotaResult.setQuotaDate(getYesterday());
- wlyyQuotaResult.setCreateTime(new Date());
- wlyyQuotaResult.setLevel1Type("4");
- //判断全科医生是否有签约量
- if (cityCount > 0) {
- wlyyQuotaResult.setResult(cityCount + "");
- } else {
- wlyyQuotaResult.setResult("0");
- }
- wlyyQuotaResultDao.save(wlyyQuotaResult);
- }
- quartzJobLog.setJobEndTime(new Date());
- quartzJobLog.setJobContent("统计" + getYesterday() + " 的签约数据完成 ");
- quartzJobLog.setJobType("1");
- quartzJobLogDao.save(quartzJobLog);
- }
- /*
- 得到昨天的日期字符串 yyyy-MM-dd
- */
- public String getYesterday() {
- return yesterday;
- }
- /**
- * 根据年龄得到对应的code
- *
- * @param age
- * @return
- */
- public String getAgeCode(int age) {
- if (age < 7) {
- return Constant.level_age_1;
- } else if (age >= 7 && age < 18) {
- return Constant.level_age_2;
- } else if (age >= 18 && age < 30) {
- return Constant.level_age_3;
- } else if (age >= 30 && age < 50) {
- return Constant.level_age_4;
- } else if (age >= 50 && age < 65) {
- return Constant.level_age_5;
- } else {
- return Constant.level_age_6;
- }
- }
- public static String getDayString(Integer size) {
- Date date = new Date();//取时间
- Calendar calendar = new GregorianCalendar();
- calendar.setTime(date);
- calendar.add(calendar.DATE, size);//把日期往后增加一天.整数往后推,负数往前移动
- date = calendar.getTime(); //这个时间就是日期往后推一天的结果
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- String dateString = formatter.format(date);
- return dateString;
- }
- public static void main(String[] args) {
- getDayString(0);
- }
- }
|