Commit b9d7a9f4bc66055d3798cc36a07e6d97c0ff3233

Authored by liquanyu
1 parent c096cab61a

统计

Showing 5 changed files with 995 additions and 32 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RiskReportController.java View file @ b9d7a9f
... ... @@ -5,6 +5,7 @@
5 5 import com.lyms.platform.common.base.LoginContext;
6 6 import com.lyms.platform.common.result.BaseResponse;
7 7 import com.lyms.platform.operate.web.facade.RiskReportFacade;
  8 +import com.lyms.platform.operate.web.request.RiskPatientsCountRequest;
8 9 import com.lyms.platform.operate.web.request.RiskPatientsQueryRequest;
9 10 import org.springframework.beans.factory.annotation.Autowired;
10 11 import org.springframework.stereotype.Controller;
... ... @@ -13,6 +14,7 @@
13 14 import org.springframework.web.bind.annotation.ResponseBody;
14 15  
15 16 import javax.servlet.http.HttpServletRequest;
  17 +import javax.servlet.http.HttpServletResponse;
16 18 import javax.validation.Valid;
17 19  
18 20  
... ... @@ -26,7 +28,7 @@
26 28 private RiskReportFacade riskReportFacade;
27 29  
28 30 /**
29   - * 高危统计报表
  31 + * 院内高危统计报表
30 32 * @return
31 33 */
32 34 @RequestMapping(method = RequestMethod.GET, value = "/queryRiskReportCount")
33 35  
... ... @@ -39,21 +41,40 @@
39 41 }
40 42  
41 43  
42   -// /**
43   -// * 高危孕妇统计报表
44   -// * @return
45   -// */
46   -// @RequestMapping(method = RequestMethod.GET, value = "/queryRiskPatientReport")
47   -// @ResponseBody
48   -// public BaseResponse queryRiskPatientReport(@RequestParam(value = "dueDate", required = false) String dueDate,
49   -// @RequestParam(value = "rLevel", required = false) String rLevel,
50   -// @RequestParam(value = "checkDoctor", required = false) String checkDoctor,
51   -// @RequestParam(value = "buildDate", required = false) String buildDate,
52   -// @RequestParam(value = "riskId", required = false) String riskId) {
  44 + /**
  45 + * 区域高危孕妇统计报表
  46 + * @return
  47 + */
  48 + @RequestMapping(method = RequestMethod.GET, value = "/queryAreaRiskPatientReport")
  49 + @ResponseBody
  50 + @TokenRequired
  51 + public BaseResponse queryAreaRiskPatientReport(@Valid RiskPatientsCountRequest riskPatientsCountRequest,
  52 + HttpServletRequest request) {
  53 + LoginContext loginState = (LoginContext) request.getAttribute("loginContext");
  54 + return riskReportFacade.queryAreaRiskPatientReport(riskPatientsCountRequest, loginState.getId());
  55 +
  56 + }
  57 +
  58 +
  59 + /**
  60 + * 区域高危导出
  61 + * @param riskPatientsCountRequest
  62 + * @param request
  63 + * @return
  64 + */
  65 + @RequestMapping(method = RequestMethod.GET, value = "/exportAreaHighRisk")
  66 +// @TokenRequired
  67 + public void exportAreaHighRisk(@Valid RiskPatientsCountRequest riskPatientsCountRequest,
  68 + HttpServletRequest request,
  69 + HttpServletResponse response) {
  70 +// LoginContext loginState = (LoginContext) request.getAttribute("loginContext");
  71 +// riskReportFacade.exportAreaHighRisk(riskPatientsCountRequest,
  72 +// loginState.getId(), response);
53 73 //
54   -// return riskReportFacade.queryRiskPatientReport(dueDate, rLevel, checkDoctor, buildDate, riskId);
55   -//
56   -// }
  74 +
  75 + riskReportFacade.exportAreaHighRisk(riskPatientsCountRequest,
  76 + 1000000185, response);
  77 + }
57 78  
58 79  
59 80 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AreaCountFacade.java View file @ b9d7a9f
... ... @@ -91,7 +91,7 @@
91 91 * @param areaId
92 92 * @return
93 93 */
94   - private List<String> getCurrentUserHospPermissions(Integer userId, String provinceId, String cityId, String areaId) {
  94 + public List<String> getCurrentUserHospPermissions(Integer userId, String provinceId, String cityId, String areaId) {
95 95 List<String> hospitalList = new ArrayList<>();
96 96 // String hospital = autoMatchFacade.getHospitalId(userId);
97 97 // if (null != hospital) {
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/RiskReportFacade.java View file @ b9d7a9f
1 1 package com.lyms.platform.operate.web.facade;
2 2  
3 3 import com.lyms.platform.biz.service.*;
4   -import com.lyms.platform.common.base.LoginContext;
5 4 import com.lyms.platform.common.constants.ErrorCodeConstants;
6   -import com.lyms.platform.common.enums.FyTypeEnums;
7   -import com.lyms.platform.common.enums.SexEnum;
8   -import com.lyms.platform.common.enums.WyTypeEnums;
9   -import com.lyms.platform.common.enums.YnEnums;
  5 +import com.lyms.platform.common.enums.*;
10 6 import com.lyms.platform.common.result.BaseListResponse;
11 7 import com.lyms.platform.common.result.BaseObjectResponse;
12 8 import com.lyms.platform.common.result.BaseResponse;
13 9 import com.lyms.platform.common.utils.*;
14   -import com.lyms.platform.operate.web.request.BabyCheckRequest;
  10 +import com.lyms.platform.common.utils.StringUtils;
  11 +import com.lyms.platform.operate.web.request.RiskPatientsCountRequest;
15 12 import com.lyms.platform.operate.web.request.RiskPatientsQueryRequest;
16 13 import com.lyms.platform.operate.web.result.*;
  14 +import com.lyms.platform.operate.web.utils.AreaHighRiskCountExportTask;
17 15 import com.lyms.platform.operate.web.utils.HiskCountTask;
  16 +import com.lyms.platform.operate.web.utils.MongoUtil;
18 17 import com.lyms.platform.permission.model.Organization;
19   -import com.lyms.platform.permission.model.Users;
  18 +import com.lyms.platform.permission.model.OrganizationQuery;
20 19 import com.lyms.platform.permission.service.OrganizationService;
21 20 import com.lyms.platform.permission.service.UsersService;
22 21 import com.lyms.platform.pojo.*;
23 22  
... ... @@ -24,10 +23,12 @@
24 23 import org.apache.commons.collections.CollectionUtils;
25 24 import org.springframework.beans.factory.annotation.Autowired;
26 25 import org.springframework.beans.factory.annotation.Qualifier;
27   -import org.springframework.data.domain.Sort;
28 26 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
29 27 import org.springframework.stereotype.Component;
30 28  
  29 +import javax.servlet.http.HttpServletResponse;
  30 +import java.io.IOException;
  31 +import java.io.OutputStream;
31 32 import java.text.DecimalFormat;
32 33 import java.util.*;
33 34 import java.util.concurrent.*;
... ... @@ -43,6 +44,8 @@
43 44 @Autowired
44 45 private PatientsService patientsService;
45 46  
  47 + @Autowired
  48 + private UsersService usersService;
46 49  
47 50 @Autowired
48 51 private BasicConfigService basicConfigService;
... ... @@ -51,6 +54,15 @@
51 54 @Autowired
52 55 private AutoMatchFacade autoMatchFacade;
53 56  
  57 + @Autowired
  58 + private OrganizationService organizationService;
  59 +
  60 + @Autowired
  61 + private AreaCountFacade areaCountFacade;
  62 +
  63 + @Autowired
  64 + private MongoUtil mongoUtil;
  65 +
54 66 /**
55 67 * 查询高危统计,该统计的高危是已经有孕妇有此高危
56 68 * @return
... ... @@ -83,7 +95,7 @@
83 95 }
84 96  
85 97 // 0未终止妊娠 1终止妊娠
86   - // patientsQuery.setDueStatus(0);
  98 + // patientsQuery.setDueStatus(0);
87 99  
88 100 //预产期
89 101 if (org.apache.commons.lang.StringUtils.isNotEmpty(riskPatientsQueryRequest.getDueDate())) {
90 102  
... ... @@ -161,9 +173,9 @@
161 173 continue;
162 174 }
163 175 Callable c = new HiskCountTask( basicConfigService,
164   - patientsService, levelConfig,
  176 + patientsService, levelConfig,
165 177 patientsQuery,
166   - allPatientCount);
  178 + allPatientCount);
167 179 Future f = commonThreadPool.submit(c);
168 180 futures.add(f);
169 181 }
170 182  
171 183  
... ... @@ -221,13 +233,564 @@
221 233 return results;
222 234 }
223 235  
  236 + public BaseResponse queryAreaRiskPatientReport(RiskPatientsCountRequest countRequest, Integer userId) {
  237 +
  238 +
  239 + //获取用户权限医院和筛选条件的交集
  240 + List<String> currentUserHospPermissions = areaCountFacade.getCurrentUserHospPermissions(userId, countRequest.getProvinceId(),
  241 + countRequest.getCityId(), countRequest.getAreaId());
  242 +
  243 + currentUserHospPermissions.clear();
  244 + currentUserHospPermissions.add("216");
  245 +
  246 + //孕妇基础查询对象
  247 + PatientsQuery patientsQuery = new PatientsQuery();
  248 + patientsQuery.setYn(YnEnums.YES.getId());
  249 +
  250 + //孕妇
  251 + patientsQuery.setType(1);
  252 + List buildType = new ArrayList();
  253 + buildType.add(0);
  254 + buildType.add(2);
  255 + //建档类型
  256 + patientsQuery.setBuildTypeList(buildType);
  257 +
  258 +
  259 + //查询高危分类
  260 + List<BasicConfig> riskLevelConfig = basicConfigService.queryByParentId(SystemConfig.HIGH_RISK_ID);
  261 +
  262 + Map<String,Object> datas = new HashMap<>();
  263 +
  264 + List<Map> result = new ArrayList<>();
  265 +
  266 + BasicConfigQuery basicQuery = new BasicConfigQuery();
  267 + basicQuery.setYn(YnEnums.YES.getId());
  268 + basicQuery.setTypeId("b7ea005c-dfac-4c2a-bdae-25239b3f44fd");
  269 +
  270 +
  271 + List<Map<String, Object>> list = null;
  272 +
  273 + if (StringUtils.isNotEmpty(countRequest.getProvinceId()))
  274 + {
  275 + basicQuery.setParentId(countRequest.getProvinceId());
  276 + countRequest.setExportType(1);
  277 +
  278 + list = mongoUtil.getChilds(countRequest.getProvinceId());
  279 + }
  280 +
  281 + if (StringUtils.isNotEmpty(countRequest.getCityId()))
  282 + {
  283 + basicQuery.setParentId(countRequest.getCityId());
  284 + countRequest.setExportType(2);
  285 + list = mongoUtil.getChilds(countRequest.getCityId());
  286 + }
  287 +
  288 + if (StringUtils.isNotEmpty(countRequest.getAreaId()))
  289 + {
  290 + basicQuery.setParentId(countRequest.getAreaId());
  291 + countRequest.setExportType(3);
  292 + }
  293 +
  294 + int addrType = countRequest.getExportType();
  295 +
  296 + Map<String,Object> title = new HashMap<>();
  297 + title.put("seq","序号");
  298 + if (addrType == 1)
  299 + {
  300 + title.put("name","地市名称");
  301 + }
  302 + else if(addrType == 2)
  303 + {
  304 + title.put("name","区县名称");
  305 + }
  306 + else
  307 + {
  308 + title.put("name","医院名称");
  309 + }
  310 +
  311 + if (addrType < 3)
  312 + {
  313 + title.put("orgNum","机构数");
  314 + }
  315 +
  316 + title.put("countItem","统计指标(人)");
  317 + title.put("sumNum", "合计");
  318 + result.add(title);
  319 +
  320 +
  321 + int seq = 0;
  322 +
  323 + //统计城市和区县表格数据
  324 + if (addrType < 3)
  325 + {
  326 + List<BasicConfig> configList = basicConfigService.queryBasicConfig(basicQuery);
  327 + OrganizationQuery query = new OrganizationQuery();
  328 + query.setYn(YnEnums.YES.getId());
  329 + if (CollectionUtils.isNotEmpty(configList))
  330 + {
  331 + for(BasicConfig c : configList)
  332 + {
  333 + if (addrType == 1)
  334 + {
  335 + query.setCityId(c.getId());
  336 + }
  337 + else if(addrType == 2)
  338 + {
  339 + query.setAreaId(c.getId());
  340 + }
  341 + //查询机构数
  342 + List<Organization> orgs = organizationService.queryOrganization(query);
  343 +
  344 + List<String> hids = getConditionHospitalIds(currentUserHospPermissions,orgs);
  345 +
  346 + for (BasicConfig level : riskLevelConfig)
  347 + {
  348 +
  349 + Map<String,Object> topMap = new HashMap<>();
  350 + topMap.put("seq", ++seq);
  351 + topMap.put("name", c .getName());
  352 + topMap.put("orgNum", orgs == null ? 0 : orgs.size());
  353 + topMap.put("countItem", level.getName());
  354 +
  355 + int riskPatientCount = 0;
  356 + //权限和筛选条件不未空的时候就查询孕妇高危数量
  357 + if (CollectionUtils.isNotEmpty(hids))
  358 + {
  359 +
  360 + //权限
  361 + patientsQuery.setHospitalList(hids);
  362 +
  363 + //高危等级
  364 + patientsQuery.setrLevel(level.getId());
  365 + //单个高危因素孕产妇条数
  366 + riskPatientCount = patientsService.queryPatientCount(patientsQuery);
  367 + }
  368 +
  369 + topMap.put("sumNum", riskPatientCount);
  370 + result.add(topMap);
  371 + }
  372 + }
  373 + }
  374 + }
  375 + //统计医院的表格数据
  376 + else
  377 + {
  378 + OrganizationQuery query = new OrganizationQuery();
  379 + query.setYn(YnEnums.YES.getId());
  380 + query.setAreaId(countRequest.getAreaId());
  381 + List<Organization> orgs = organizationService.queryOrganization(query);
  382 + if (CollectionUtils.isNotEmpty(orgs)) {
  383 + for (Organization org : orgs) {
  384 + for (BasicConfig level : riskLevelConfig) {
  385 + Map<String, Object> topMap = new HashMap<>();
  386 + topMap.put("seq", ++seq);
  387 + topMap.put("name", org.getName());
  388 + topMap.put("countItem", level.getName());
  389 +
  390 + int riskPatientCount = 0;
  391 + if (currentUserHospPermissions.contains(String.valueOf(org.getId())))
  392 + {
  393 + //权限
  394 + patientsQuery.setHospitalId(String.valueOf(org.getId()));
  395 + //高危等级
  396 + patientsQuery.setrLevel(level.getId());
  397 + //单个高危因素孕产妇条数
  398 + riskPatientCount = patientsService.queryPatientCount(patientsQuery);
  399 + }
  400 +
  401 + topMap.put("sumNum", riskPatientCount);
  402 + result.add(topMap);
  403 + }
  404 + }
  405 + }
  406 + }
  407 +
  408 + //表格合计计算
  409 +// if(CollectionUtils.isNotEmpty(result))
  410 +// {
  411 +// List<Map<String,Object>> totalMapList = new ArrayList<>();
  412 +// for (BasicConfig level : riskLevelConfig)
  413 +// {
  414 +// Map<String,Object> totalMap = new HashMap<>();
  415 +// totalMap.put("seq", ++seq);
  416 +// totalMap.put("name", "合计");
224 417 //
225   -// public BaseResponse queryRiskPatientReport(Integer userId,) {
226   -// LoginContext loginState = (LoginContext) request.getAttribute("loginContext");
227   -// patientFacade.queryHighRisk(patientsQueryRequest, Boolean.TRUE, 1, loginState.getId(), "true",Boolean.FALSE);
  418 +// totalMap.put("countItem", level.getName());
  419 +// int orgNumTotal = 0;
  420 +// int levelTotal = 0;
  421 +// if (addrType < 3)
  422 +// {
228 423 //
229   -// return null;
230   -// }
  424 +// for (Map map : result)
  425 +// {
  426 +// if ("序号".equals(map.get("seq")))
  427 +// {
  428 +// continue;
  429 +// }
  430 +// Integer orgNum = Integer.valueOf(String.valueOf(map.get("orgNum")));
  431 +// orgNumTotal+=orgNum;
  432 +//
  433 +// if (map.get("countItem").equals(level.getName()))
  434 +// {
  435 +// Integer sumNum =Integer.valueOf(String.valueOf(map.get("sumNum")));
  436 +// levelTotal+=sumNum;
  437 +// }
  438 +// }
  439 +// }
  440 +//
  441 +// totalMap.put("orgNum", orgNumTotal);
  442 +// totalMap.put("sumNum", levelTotal);
  443 +// totalMapList.add(totalMap);
  444 +// }
  445 +// result.addAll(totalMapList);
  446 +// }
  447 +
  448 +
  449 +
  450 +
  451 +
  452 + //统计柱状图数据封装--------------------------------
  453 +
  454 + //图标数据
  455 + List<Map<String,Object>> series = new ArrayList<>();
  456 +
  457 + //x轴标题数据
  458 + List<String> xAxis = new ArrayList<>();
  459 +
  460 + //分类标题
  461 + List<String> titleItems = new ArrayList<>();
  462 +
  463 +
  464 +// //获取分类标题数据
  465 +// if (CollectionUtils.isNotEmpty(riskLevelConfig))
  466 +// {
  467 +// for (BasicConfig conf : riskLevelConfig)
  468 +// {
  469 +// titleItems.add(conf.getName());
  470 +// }
  471 +// }
  472 +//
  473 +//
  474 +// if (addrType < 3)
  475 +// {
  476 +// if (CollectionUtils.isNotEmpty(list))
  477 +// {
  478 +// for (Map<String, Object> addr : list)
  479 +// {
  480 +// xAxis.add(String.valueOf(addr.get("name")));
  481 +// }
  482 +// for (BasicConfig config : riskLevelConfig)
  483 +// {
  484 +// Map<String,Object> map = new HashMap();
  485 +// map.put("name",config.getName());
  486 +// map.put("type","bar");
  487 +//
  488 +//
  489 +// OrganizationQuery idQuery = new OrganizationQuery();
  490 +// idQuery.setYn(YnEnums.YES.getId());
  491 +//
  492 +// List<String> items = new ArrayList<>();
  493 +// for (Map<String, Object> addr : list)
  494 +// {
  495 +// List<String> hids = new ArrayList<>();
  496 +// String id = String.valueOf(addr.get("id"));
  497 +// if (addrType == 1)
  498 +// {
  499 +// idQuery.setCityId(id);
  500 +// }
  501 +// else if(addrType == 2)
  502 +// {
  503 +// idQuery.setAreaId(id);
  504 +// }
  505 +//
  506 +// //查询机构数
  507 +// List<Organization> orgs = organizationService.queryOrganization(idQuery);
  508 +//
  509 +// if (CollectionUtils.isNotEmpty(orgs))
  510 +// {
  511 +// for (Organization org : orgs)
  512 +// {
  513 +// hids.add(String.valueOf(org.getId()));
  514 +// }
  515 +// }
  516 +//
  517 +// PatientsQuery query1 = new PatientsQuery();
  518 +// query1.setHospitalList(hids);
  519 +// query1.setYn(YnEnums.YES.getId());
  520 +// query1.setType(1);
  521 +// //高危等级
  522 +// query1.setrLevel(config.getId());
  523 +// List buildType = new ArrayList();
  524 +// buildType.add(0);
  525 +// buildType.add(2);
  526 +// query1.setBuildTypeList(buildType);
  527 +// Integer count = patientsService.queryPatientCount(query1);
  528 +// items.add(count == null ? "0" : String.valueOf(count));
  529 +// }
  530 +// map.put("data",items);
  531 +//
  532 +// series.add(map);
  533 +// }
  534 +// }
  535 +// }
  536 +// else if (addrType == 3)
  537 +// {
  538 +// OrganizationQuery organizationQuery = new OrganizationQuery();
  539 +// organizationQuery.setYn(YnEnums.YES.getId());
  540 +// organizationQuery.setAreaId(countRequest.getAreaId());
  541 +//
  542 +// //TODO权限
  543 +// // List<Organization> press = getCurrentOrgs( countRequest, userId);
  544 +// List<Organization> orgs = organizationService.queryOrganization(organizationQuery);
  545 +//
  546 +// if (CollectionUtils.isNotEmpty(list))
  547 +// {
  548 +// for (Organization org : orgs)
  549 +// {
  550 +// xAxis.add(org.getName());
  551 +//
  552 +// Map<String,Object> map = new HashMap();
  553 +// map.put("name",org.getName());
  554 +// map.put("type", "bar");
  555 +// List<String> items = new ArrayList<>();
  556 +// for (BasicConfig config : riskLevelConfig)
  557 +// {
  558 +// PatientsQuery query1 = new PatientsQuery();
  559 +// query1.setHospitalId(String.valueOf(org.getId()));
  560 +// query1.setYn(YnEnums.YES.getId());
  561 +// query1.setType(1);
  562 +// //高危等级
  563 +// query1.setrLevel(config.getId());
  564 +// List buildType = new ArrayList();
  565 +// buildType.add(0);
  566 +// buildType.add(2);
  567 +// query1.setBuildTypeList(buildType);
  568 +// Integer count = patientsService.queryPatientCount(query1);
  569 +// items.add(count == null ? "0" : String.valueOf(count));
  570 +// map.put("data",items);
  571 +// }
  572 +// series.add(map);
  573 +// }
  574 +// }
  575 +// }
  576 +
  577 + datas.put("series",series);
  578 + datas.put("xAxis",xAxis);
  579 + datas.put("legend",titleItems);
  580 + datas.put("tableDatas",result);
  581 + return new BaseObjectResponse()
  582 + .setErrormsg("成功").setErrorcode(ErrorCodeConstants.SUCCESS).setData(datas);
  583 + }
  584 +
  585 + public void exportAreaHighRisk(RiskPatientsCountRequest countRequest,
  586 + Integer userId, HttpServletResponse response) {
  587 + try {
  588 + //获取用户权限
  589 + List<String> currentUserHospPermissions = areaCountFacade.getCurrentUserHospPermissions(userId, countRequest.getProvinceId(),
  590 + countRequest.getCityId(), countRequest.getAreaId());
  591 + List<Map<String, Object>> datas = new ArrayList<>();
  592 +
  593 + if(countRequest.getProvinceId() != null && countRequest.getCityId() == null && countRequest.getAreaId() == null)
  594 + {
  595 + countRequest.setExportType(1);
  596 + }
  597 + else if (countRequest.getProvinceId() != null && countRequest.getCityId() != null && countRequest.getAreaId() == null)
  598 + {
  599 + countRequest.setExportType(2);
  600 + }
  601 + else if (countRequest.getProvinceId() != null && countRequest.getCityId() != null && countRequest.getAreaId() != null)
  602 + {
  603 + countRequest.setExportType(3);
  604 + }
  605 +// currentUserHospPermissions.clear();
  606 +// currentUserHospPermissions.add("216");
  607 +
  608 + BasicConfigQuery basicConfigQuery = new BasicConfigQuery();
  609 + basicConfigQuery.setYn(YnEnums.YES.getId());
  610 + basicConfigQuery.setParentId(SystemConfig.HIGH_RISK_ID);
  611 + List<BasicConfig> riskLevelConfig = basicConfigService.queryBasicConfig(basicConfigQuery);
  612 +
  613 + List<Future> futures = new ArrayList<>();
  614 + if (CollectionUtils.isNotEmpty(currentUserHospPermissions))
  615 + {
  616 + int batchSize = 5;
  617 + int end = 0;
  618 + for (int i = 0; i < currentUserHospPermissions.size(); i += batchSize) {
  619 + end = (end + batchSize);
  620 + if (end > currentUserHospPermissions.size()) {
  621 + end = currentUserHospPermissions.size();
  622 + }
  623 + final List<String> organizations = currentUserHospPermissions.subList(i, end);
  624 + Callable callable = new AreaHighRiskCountExportTask(basicConfigService,usersService,patientsService,organizationService,
  625 + riskLevelConfig,organizations,countRequest.getExportType());
  626 + Future f = commonThreadPool.submit(callable);
  627 + futures.add(f);
  628 + }
  629 + }
  630 +
  631 + if (CollectionUtils.isNotEmpty(futures))
  632 + {
  633 + for(Future f : futures)
  634 + {
  635 + try {
  636 + List list = (List)f.get(2,TimeUnit.MINUTES);
  637 + datas.addAll(list);
  638 + } catch (InterruptedException e) {
  639 + e.printStackTrace();
  640 + } catch (ExecutionException e) {
  641 + e.printStackTrace();
  642 + } catch (TimeoutException e) {
  643 + e.printStackTrace();
  644 + }
  645 + }
  646 + }
  647 +
  648 + OutputStream out = response.getOutputStream();
  649 + Map<String, String> cnames = new LinkedHashMap<>();
  650 + if (countRequest.getExportType() == 1)
  651 + {
  652 + cnames.put("cityName", "地市名称");
  653 + cnames.put("areaName", "区县名称");
  654 + cnames.put("streetName", "乡镇名称");
  655 + cnames.put("hospitalName", "机构名称");
  656 + cnames.put("highRiskPatTotal", "高危孕妇总数");
  657 + cnames.put("dfx", "低风险");
  658 + cnames.put("ybfx", "一般风险");
  659 + cnames.put("jgfx", "较高风险");
  660 + cnames.put("gfx", "高风险");
  661 + cnames.put("crb", "传染病");
  662 + }
  663 + else if (countRequest.getExportType() == 2)
  664 + {
  665 + cnames.put("areaName", "区县名称");
  666 + cnames.put("streetName", "乡镇名称");
  667 + cnames.put("hospitalName", "机构名称");
  668 + cnames.put("highRiskPatTotal", "高危孕妇总数");
  669 + cnames.put("dfx", "低风险");
  670 + cnames.put("ybfx", "一般风险");
  671 + cnames.put("jgfx", "较高风险");
  672 + cnames.put("gfx", "高风险");
  673 + cnames.put("crb", "传染病");
  674 + }
  675 + else if (countRequest.getExportType() == 3)
  676 + {
  677 + cnames.put("hospitalName", "医院名称");
  678 + cnames.put("vcCardNo","就诊卡号");
  679 + cnames.put("username", "姓名");
  680 + cnames.put("birth","出生日期");
  681 + cnames.put("phone", "手机号");
  682 + cnames.put("cardNo","证件号");
  683 + cnames.put("age","年龄");
  684 + cnames.put("hjAddress", "户籍地");
  685 + cnames.put("jzAddress","居住地");
  686 + cnames.put("buildWeek","建档孕周");
  687 + cnames.put("lastMenses","末次月经");
  688 + cnames.put("dueDate","预产期");
  689 + cnames.put("highType","高危类型");
  690 + cnames.put("rFactor","高危因素");
  691 + cnames.put("riskScore","高危评分");
  692 + cnames.put("lastCheckTime","检查日期");
  693 + cnames.put("checkWeek","检查孕周");
  694 + cnames.put("checkDoctor","检查医生");
  695 + }
  696 +
  697 + response.setContentType("application/octet-stream");
  698 + response.setCharacterEncoding("UTF-8");
  699 + response.setHeader("Content-Disposition", "attachment;fileName=data.xls");
  700 + ExcelUtil.toExcel(out, datas, cnames);
  701 +
  702 + } catch (IOException e) {
  703 + e.printStackTrace();
  704 + }
  705 + }
  706 +
  707 +
  708 + /**
  709 + * 获取当前权限和查询条件的医院
  710 + * @param countRequest
  711 + * @param userId
  712 + * @return
  713 + */
  714 + private List<Organization> getCurrentOrgs(RiskPatientsCountRequest countRequest,Integer userId)
  715 + {
  716 + //获取用户权限
  717 + List<String> currentUserHospPermissions = areaCountFacade.getCurrentUserHospPermissions(userId, countRequest.getProvinceId(),
  718 + countRequest.getCityId(), countRequest.getAreaId());
  719 +
  720 + OrganizationQuery query = new OrganizationQuery();
  721 + query.setYn(YnEnums.YES.getId());
  722 +
  723 + if (StringUtils.isNotEmpty(countRequest.getProvinceId()))
  724 + {
  725 + //省市查询条件
  726 + query.setProvinceId(countRequest.getProvinceId());
  727 + }
  728 +
  729 + if (StringUtils.isNotEmpty(countRequest.getCityId()))
  730 + {
  731 + query.setCityId(countRequest.getCityId());
  732 + }
  733 +
  734 + if (StringUtils.isNotEmpty(countRequest.getAreaId()))
  735 + {
  736 + query.setAreaId(countRequest.getAreaId());
  737 + }
  738 +
  739 + List<Organization> queryHospitals = new ArrayList<>();
  740 +
  741 + List<Organization> orgs = organizationService.queryOrganization(query);
  742 + if (CollectionUtils.isNotEmpty(orgs) && CollectionUtils.isNotEmpty(currentUserHospPermissions))
  743 + {
  744 + for (Organization org : orgs)
  745 + {
  746 + if (org.getId() != null && currentUserHospPermissions.contains(String.valueOf(org.getId())))
  747 + {
  748 + queryHospitals.add(org);
  749 + }
  750 + }
  751 + }
  752 +
  753 + return queryHospitals;
  754 + }
  755 +
  756 +
  757 + /**
  758 + * 用户当前权限的用户id 和查询条件的交集
  759 + * @param countRequest
  760 + * @param userId
  761 + * @return
  762 + */
  763 + private List<String> currentUserHospitalIds(RiskPatientsCountRequest countRequest,Integer userId)
  764 + {
  765 + List<String> hids = new ArrayList<>();
  766 + List<Organization> queryHospitals = getCurrentOrgs(countRequest, userId);
  767 + if (CollectionUtils.isNotEmpty(hids))
  768 + {
  769 + for (Organization org : queryHospitals)
  770 + {
  771 + hids.add(String.valueOf(org.getId()));
  772 + }
  773 + }
  774 + return hids;
  775 + }
  776 +
  777 +
  778 + /**
  779 + * 获取权限和条件
  780 + * @param conditionHospitals
  781 + * @return
  782 + */
  783 + private List<String> getConditionHospitalIds(List<String> currentUserHospPermissions,List<Organization> conditionHospitals)
  784 + {
  785 + List<String> hids = new ArrayList<>();
  786 + for (Organization org : conditionHospitals)
  787 + {
  788 + hids.add(String.valueOf(org.getId()));
  789 + }
  790 + hids.retainAll(currentUserHospPermissions);
  791 +
  792 + return hids;
  793 + }
231 794  
232 795 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/RiskPatientsCountRequest.java View file @ b9d7a9f
  1 +package com.lyms.platform.operate.web.request;
  2 +
  3 +import com.lyms.platform.common.core.annotation.form.Form;
  4 +import com.lyms.platform.common.core.annotation.form.FormParam;
  5 +import com.lyms.platform.common.utils.DateUtil;
  6 +import com.lyms.platform.common.utils.StringUtils;
  7 +import org.apache.commons.lang.math.NumberUtils;
  8 +
  9 +import java.util.Date;
  10 +import java.util.Map;
  11 +
  12 +/**
  13 + * 高危孕妇统计查询
  14 + */
  15 +@Form
  16 +public class RiskPatientsCountRequest extends BasePageQueryRequest {
  17 +
  18 + //省市区地址
  19 + private String provinceId;
  20 + private String cityId;
  21 + private String areaId;
  22 + private String streetId;
  23 +
  24 + //医院id
  25 + private String hospitalId;
  26 +
  27 + //年龄范围 0:全部 1:20岁一下 2:25-30 3:30-40 4:40岁以上
  28 + private Integer ageRange;
  29 +
  30 + //时间范围
  31 + private String time;
  32 +
  33 + //高危等级{}
  34 + private Map<String,String> riskLevel;
  35 +
  36 + //导出类型 1 省导出 2 地区导出 3医院导出
  37 + private Integer exportType;
  38 +
  39 + //对比指标 1 占比 2 环比
  40 + private Integer compareType;
  41 +
  42 + //环比 周 1月 2 季度 3半年 4年
  43 + private Integer hbType;
  44 +
  45 + //孕周 0 全部孕周 1:孕12周前 2:13-19 3:20-25 4:26-30 5:31-36 6:37-40 7:40-分娩前
  46 + private Integer week;
  47 +
  48 + public Integer getHbType() {
  49 + return hbType;
  50 + }
  51 +
  52 + public void setHbType(Integer hbType) {
  53 + this.hbType = hbType;
  54 + }
  55 +
  56 + public Integer getWeek() {
  57 + return week;
  58 + }
  59 +
  60 + public void setWeek(Integer week) {
  61 + this.week = week;
  62 + }
  63 +
  64 + public Integer getExportType() {
  65 + return exportType;
  66 + }
  67 +
  68 + public void setExportType(Integer exportType) {
  69 + this.exportType = exportType;
  70 + }
  71 +
  72 + public String getTime() {
  73 + return time;
  74 + }
  75 +
  76 + public void setTime(String time) {
  77 + this.time = time;
  78 + }
  79 +
  80 + public Integer getCompareType() {
  81 + return compareType;
  82 + }
  83 +
  84 + public void setCompareType(Integer compareType) {
  85 + this.compareType = compareType;
  86 + }
  87 +
  88 + public String getProvinceId() {
  89 + return provinceId;
  90 + }
  91 +
  92 + public void setProvinceId(String provinceId) {
  93 + this.provinceId = provinceId;
  94 + }
  95 +
  96 + public String getCityId() {
  97 + return cityId;
  98 + }
  99 +
  100 + public void setCityId(String cityId) {
  101 + this.cityId = cityId;
  102 + }
  103 +
  104 + public String getAreaId() {
  105 + return areaId;
  106 + }
  107 +
  108 + public void setAreaId(String areaId) {
  109 + this.areaId = areaId;
  110 + }
  111 +
  112 + public String getStreetId() {
  113 + return streetId;
  114 + }
  115 +
  116 + public void setStreetId(String streetId) {
  117 + this.streetId = streetId;
  118 + }
  119 +
  120 + public String getHospitalId() {
  121 + return hospitalId;
  122 + }
  123 +
  124 + public void setHospitalId(String hospitalId) {
  125 + this.hospitalId = hospitalId;
  126 + }
  127 +
  128 + public Integer getAgeRange() {
  129 + return ageRange;
  130 + }
  131 +
  132 + public void setAgeRange(Integer ageRange) {
  133 + this.ageRange = ageRange;
  134 + }
  135 +
  136 + public Map<String, String> getRiskLevel() {
  137 + return riskLevel;
  138 + }
  139 +
  140 + public void setRiskLevel(Map<String, String> riskLevel) {
  141 + this.riskLevel = riskLevel;
  142 + }
  143 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/AreaHighRiskCountExportTask.java View file @ b9d7a9f
  1 +package com.lyms.platform.operate.web.utils;
  2 +
  3 +import com.lyms.platform.biz.service.BasicConfigService;
  4 +import com.lyms.platform.biz.service.PatientsService;
  5 +import com.lyms.platform.common.enums.RiskDefaultTypeEnum;
  6 +import com.lyms.platform.common.enums.YnEnums;
  7 +import com.lyms.platform.common.utils.DateUtil;
  8 +import com.lyms.platform.common.utils.ExceptionUtils;
  9 +import com.lyms.platform.common.utils.StringUtils;
  10 +import com.lyms.platform.operate.web.result.RiskReportResult;
  11 +import com.lyms.platform.permission.model.Organization;
  12 +import com.lyms.platform.permission.model.OrganizationQuery;
  13 +import com.lyms.platform.permission.model.Users;
  14 +import com.lyms.platform.permission.service.OrganizationService;
  15 +import com.lyms.platform.permission.service.UsersService;
  16 +import com.lyms.platform.pojo.BasicConfig;
  17 +import com.lyms.platform.pojo.Patients;
  18 +import com.lyms.platform.query.BasicConfigQuery;
  19 +import com.lyms.platform.query.PatientsQuery;
  20 +import org.apache.commons.collections.CollectionUtils;
  21 +import org.apache.commons.lang.time.DateUtils;
  22 +
  23 +import java.text.DecimalFormat;
  24 +import java.util.*;
  25 +import java.util.concurrent.*;
  26 +
  27 +/**
  28 + * 导出区域高危统计导出
  29 + * Created by Administrator on 2016/11/30.
  30 + */
  31 +public class AreaHighRiskCountExportTask implements Callable {
  32 + private PatientsService patientsService;
  33 + private UsersService usersService;
  34 + private OrganizationService organizationService;
  35 + private BasicConfigService basicConfigService;
  36 + private Integer exportType;
  37 + private List<String> organizations;
  38 +
  39 + private List<BasicConfig> riskLevelConfig;
  40 +
  41 + public AreaHighRiskCountExportTask(BasicConfigService basicConfigService,
  42 + UsersService usersService,
  43 + PatientsService patientsService,
  44 + OrganizationService organizationService,
  45 + List<BasicConfig> riskLevelConfig,
  46 + List<String> organizations,
  47 + Integer exportType)
  48 + {
  49 + this.basicConfigService = basicConfigService;
  50 + this.organizationService = organizationService;
  51 + this.usersService = usersService;
  52 + this.patientsService = patientsService;
  53 + this.organizations = organizations;
  54 + this.riskLevelConfig = riskLevelConfig;
  55 + this.exportType = exportType;
  56 + }
  57 + @Override
  58 + public List<Map<String, Object>> call() throws Exception {
  59 + List<Map<String, Object>> datas = new ArrayList<>();
  60 +
  61 +
  62 + OrganizationQuery organizationQuery = new OrganizationQuery();
  63 + organizationQuery.setYn(YnEnums.YES.getId());
  64 +
  65 + for (String hid : organizations)
  66 + {
  67 + Map<String, Object> data = new HashMap<>();
  68 +
  69 + Organization organization = organizationService.getOrganization(Integer.valueOf(hid));
  70 +
  71 + BasicConfig city = basicConfigService.getOneBasicConfigById(organization.getCityId());
  72 + BasicConfig area = basicConfigService.getOneBasicConfigById(organization.getAreaId());
  73 + BasicConfig street = basicConfigService.getOneBasicConfigById(organization.getStreetId());
  74 +
  75 +
  76 + int highRiskPatTotal = 0;
  77 +
  78 + if (CollectionUtils.isNotEmpty(riskLevelConfig)) {
  79 + for (BasicConfig config : riskLevelConfig) {
  80 +
  81 + if (exportType == 1)
  82 + {
  83 + data.put("cityName", city == null ? "" : city.getName());
  84 + data.put("areaName", area == null ? "" : area.getName());
  85 + data.put("streetName", street == null ? "" : street.getName());
  86 + }
  87 + else if (exportType == 2)
  88 + {
  89 + data.put("areaName", area == null ? "" : area.getName());
  90 + data.put("streetName", street == null ? "" : street.getName());
  91 + }
  92 +
  93 + data.put("hospitalName", organization.getName());
  94 +
  95 + int riskPatientCount = 0;
  96 +
  97 + PatientsQuery query1 = new PatientsQuery();
  98 + query1.setHospitalId(String.valueOf(organization.getId()));
  99 + query1.setYn(YnEnums.YES.getId());
  100 + query1.setType(1);
  101 + //高危等级
  102 + query1.setrLevel(config.getId());
  103 + List buildType = new ArrayList();
  104 + buildType.add(0);
  105 + buildType.add(2);
  106 + query1.setBuildTypeList(buildType);
  107 +
  108 + if (exportType == 3)
  109 + {
  110 + List<Patients> patientses = patientsService.queryPatient(query1);
  111 + if (CollectionUtils.isNotEmpty(patientses))
  112 + {
  113 + for (Patients pat : patientses)
  114 + {
  115 + data = new HashMap<>();
  116 + data.put("hospitalName", organization.getName());
  117 + data.put("vcCardNo",pat.getVcCardNo());
  118 + data.put("username", pat.getUsername());
  119 + data.put("birth", DateUtil.getyyyy_MM_dd(pat.getBirth()));
  120 + data.put("phone", StringUtils.encryPhone(pat.getPhone()));
  121 + data.put("cardNo",pat.getCardNo());
  122 + data.put("age",DateUtil.getAge(pat.getBirth()));
  123 + data.put("hjAddress", CommonsHelper.getResidence(pat.getProvinceId(), pat.getCityId(),
  124 + pat.getAreaId(), pat.getStreetId(), pat.getAddress(),
  125 + basicConfigService));
  126 + data.put("jzAddress",CommonsHelper.getResidence(pat.getProvinceRegisterId(), pat.getCityRegisterId(),
  127 + pat.getAreaRegisterId(), pat.getStreetRegisterId(), pat.getAddressRegister(),
  128 + basicConfigService));
  129 +
  130 + data.put("buildWeek",DateUtil.getWeekDesc(pat.getLastMenses(), pat.getCreated()));
  131 + data.put("lastMenses",DateUtil.getyyyy_MM_dd(pat.getLastMenses()));
  132 +
  133 + Date dueDate = DateUtil.addMonth(pat.getLastMenses(), 9);
  134 + dueDate = DateUtil.addDay(dueDate, 7);
  135 + data.put("dueDate",DateUtil.getyyyy_MM_dd(dueDate));
  136 + data.put("highType",config.getName());
  137 +
  138 +
  139 + //高危因素
  140 + List<String> factor = pat.getRiskFactorId();
  141 +
  142 + String rFactor = "";
  143 +
  144 + if (CollectionUtils.isNotEmpty(factor)) {
  145 + StringBuilder sb = new StringBuilder(56);
  146 + for (String srt : factor) {
  147 + if (org.apache.commons.lang.StringUtils.isNotEmpty(srt)) {
  148 + BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(srt);
  149 + if (null != basicConfig && sb.indexOf(basicConfig.getName()) == -1) {
  150 + sb.append(basicConfig.getName()).append(',');
  151 + }
  152 + }
  153 + }
  154 + if (sb.toString().endsWith(",")) {
  155 + rFactor = sb.substring(0, sb.length() - 1);
  156 + } else {
  157 + rFactor = sb.toString();
  158 + }
  159 +
  160 + if (!"-".equals(rFactor) && org.apache.commons.lang.StringUtils.isNotEmpty(pat.getoRiskFactor())) {
  161 + rFactor = rFactor+","+pat.getoRiskFactor();
  162 + }else if (org.apache.commons.lang.StringUtils.isNotEmpty(pat.getoRiskFactor()))
  163 + {
  164 + rFactor = pat.getoRiskFactor();
  165 + }
  166 + }
  167 + else if (org.apache.commons.lang.StringUtils.isNotEmpty(pat.getoRiskFactor()))
  168 + {
  169 + rFactor = pat.getoRiskFactor();
  170 + }
  171 +
  172 + data.put("rFactor",rFactor);
  173 + data.put("riskScore",pat.getRiskScore());
  174 + data.put("lastCheckTime",DateUtil.getyyyy_MM_dd(pat.getLastCTime()));
  175 + data.put("checkWeek",DateUtil.getWeekDesc(pat.getLastMenses(), pat.getLastCTime()));
  176 + String checkDoctor = "";
  177 + try {
  178 + Users users = usersService.getUsers(Integer.parseInt(pat.getLastCheckEmployeeId()));
  179 + if (users != null && users.getYn() == YnEnums.YES.getId()) {
  180 + checkDoctor = users.getName();
  181 + }
  182 + }
  183 + catch (Exception e)
  184 + {
  185 + System.out.print(e+pat.getLastCheckEmployeeId());
  186 + }
  187 +
  188 + data.put("checkDoctor",checkDoctor);
  189 + datas.add(data);
  190 + }
  191 + }
  192 + }
  193 + else
  194 + {
  195 + riskPatientCount = patientsService.queryPatientCount(query1);
  196 +
  197 + highRiskPatTotal += riskPatientCount;
  198 +
  199 + if (config.getName().contains("绿")) {
  200 + data.put("dfx",riskPatientCount);
  201 + }
  202 + else if (config.getName().contains("黄"))
  203 + {
  204 + data.put("ybfx", riskPatientCount);
  205 + }
  206 + else if (config.getName().contains("橙"))
  207 + {
  208 + data.put("jgfx", riskPatientCount);
  209 + }
  210 + else if (config.getName().contains("红"))
  211 + {
  212 + data.put("gfx", riskPatientCount);
  213 + }
  214 + else if (config.getName().contains("紫"))
  215 + {
  216 + data.put("crb", riskPatientCount);
  217 + }
  218 + }
  219 +
  220 + }
  221 + }
  222 +
  223 + if (exportType < 3)
  224 + {
  225 + data.put("highRiskPatTotal", highRiskPatTotal);
  226 + datas.add(data);
  227 + }
  228 +
  229 + }
  230 + return datas;
  231 + }
  232 +
  233 +
  234 +}