Commit e419256cab0768ae0255042a21fb4565e6ab9842

Authored by litao
1 parent 4a820382ab

建册统计相关代码

Showing 7 changed files with 395 additions and 1 deletions

platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java View file @ e419256
... ... @@ -11,6 +11,7 @@
11 11 public class DateUtil {
12 12 private static Lock lock = new ReentrantLock();
13 13 public static SimpleDateFormat dd = new SimpleDateFormat("dd");
  14 + public static SimpleDateFormat yyyy = new SimpleDateFormat("yyyy");
14 15 public static SimpleDateFormat ymd = new SimpleDateFormat("yyyyMMdd");
15 16 public static SimpleDateFormat y_m_d = new SimpleDateFormat("yyyy-MM-dd");
16 17 public static SimpleDateFormat md = new SimpleDateFormat("MM-dd");
... ... @@ -196,6 +197,28 @@
196 197 }
197 198 }
198 199  
  200 + public static Date getYearDate(String s) {
  201 + if (s == null) {
  202 + return null;
  203 + }
  204 + try {
  205 + return yyyy.parse(s);
  206 + } catch (Exception e) {
  207 + return null;
  208 + }
  209 + }
  210 +
  211 + public static Date getNextYearDate(String s) {
  212 + if (s == null) {
  213 + return null;
  214 + }
  215 + try {
  216 + return DateUtil.addYear(yyyy.parse(s), 1);
  217 + } catch (Exception e) {
  218 + return null;
  219 + }
  220 + }
  221 +
199 222 public static String getymdhm(Date d) {
200 223 if (d == null) {
201 224 return null;
... ... @@ -949,7 +972,9 @@
949 972 public static void main(String[] arg) throws Exception {
950 973 Date start = parseYMD("2017-05-11");
951 974 Date end = parseYMD("2017-06-02");
952   - System.err.println(getMonthDesc(start, end));
  975 +
  976 + System.out.println(getMonth(start));
  977 + System.out.println(getMonth(end));
953 978 }
954 979  
955 980  
... ... @@ -966,6 +991,17 @@
966 991 int month = getMonth(start, end);
967 992 int day = getExcludeMonthDay(start, end);
968 993 return month + "月龄+" + day + "天";
  994 + }
  995 +
  996 + /**
  997 + * 获取传入日期的月份
  998 + * @param date
  999 + * @return
  1000 + */
  1001 + public static Integer getMonth(Date date) {
  1002 + Calendar calendar = Calendar.getInstance();
  1003 + calendar.setTime(date);
  1004 + return calendar.get(Calendar.MONTH) + 1;
969 1005 }
970 1006 }
platform-operate-api/src/main/java/com/lyms/hospitalapi/pojo/ReportModel.java View file @ e419256
... ... @@ -32,6 +32,8 @@
32 32  
33 33 private List<Object> doctorInfo;
34 34  
  35 + private List<String> legend;
  36 +
35 37 /**
36 38 * 将 x 轴数据去重并把series数据合并
37 39 */
... ... @@ -150,6 +152,14 @@
150 152  
151 153 public void setSeries(List<Series> series) {
152 154 this.series = series;
  155 + }
  156 +
  157 + public List<String> getLegend() {
  158 + return legend;
  159 + }
  160 +
  161 + public void setLegend(List<String> legend) {
  162 + this.legend = legend;
153 163 }
154 164 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ e419256
... ... @@ -273,5 +273,24 @@
273 273 return reportService.couponInit(CollectionUtils.createMap("userId", getUserId(request), "couponType", couponType));
274 274 }
275 275  
  276 +
  277 + /**
  278 + * 把产前检查/产妇分娩/出院小结/产后复查/产前筛查里面所有的pid找出来去重
  279 + * 根据省市区条件返回统计数据
  280 + * @param request
  281 + * @param year
  282 + * @param provinceId
  283 + * @param cityId
  284 + * @param areaId
  285 + * @return
  286 + */
  287 + @ResponseBody
  288 +// @TokenRequired
  289 + @RequestMapping(value = "/patient", method = RequestMethod.GET)
  290 + public BaseObjectResponse patient(HttpServletRequest request, String year, String provinceId, String cityId, String areaId) {
  291 +// return reportService.patient(getUserId(request), year);
  292 + return reportService.patient(2144, year, provinceId, cityId, areaId);
  293 + }
  294 +
276 295 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java View file @ e419256
... ... @@ -74,5 +74,7 @@
74 74 BaseObjectResponse couponInfo(Map<String, Object> param);
75 75  
76 76 void exportCouponInfo(Map<String, Object> param, HttpServletResponse response);
  77 +
  78 + BaseObjectResponse patient(Integer userId, String s, String provinceId, String cityId, String year);
77 79 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ e419256
... ... @@ -20,6 +20,9 @@
20 20 import org.springframework.beans.factory.annotation.Autowired;
21 21 import org.springframework.data.domain.Sort;
22 22 import org.springframework.data.mongodb.core.MongoTemplate;
  23 +import org.springframework.data.mongodb.core.aggregation.Aggregation;
  24 +import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
  25 +import org.springframework.data.mongodb.core.aggregation.AggregationResults;
23 26 import org.springframework.data.mongodb.core.query.Criteria;
24 27 import org.springframework.data.mongodb.core.query.Query;
25 28 import org.springframework.stereotype.Service;
... ... @@ -54,6 +57,9 @@
54 57 @Autowired
55 58 private AccessPermissionFacade accessPermissionFacade;
56 59  
  60 + @Autowired
  61 + private MongoUtil mongoUtil;
  62 +
57 63 private static final Map<String, String> colorMap = new HashMap<>();
58 64  
59 65 /**
... ... @@ -1054,6 +1060,100 @@
1054 1060 exportChildUsedInfo(couponInfos == null ? userSendInfos : couponInfos, response);
1055 1061 }
1056 1062  
  1063 + }
  1064 +
  1065 + @Override
  1066 + public BaseObjectResponse patient(Integer userId, String year, String provinceId, String cityId, String areaId) {
  1067 + String hospitalId = autoMatchFacade.getHospitalId(userId);
  1068 +
  1069 + Set<String> patientIds = new HashSet<>();
  1070 +
  1071 + Criteria criteria = Criteria.where("created").gte(DateUtil.getYearDate(year))
  1072 + .lt(DateUtil.getNextYearDate(year))
  1073 + .and("hospitalId").is(hospitalId);
  1074 +
  1075 + /** 产前检查: lyms_antexc(初诊),lyms_antex(复诊)设置pid */
  1076 + List<AntenatalExaminationModel> antenatalExaminationModels = mongoUtil.findField(AntenatalExaminationModel.class, criteria, "parentId");
  1077 + for (AntenatalExaminationModel antenatalExaminationModel : antenatalExaminationModels) {
  1078 + patientIds.add(antenatalExaminationModel.getParentId());
  1079 + }
  1080 + List<AntExChuModel> antExChuModels = mongoUtil.findField(AntExChuModel.class, criteria, "parentId");
  1081 + for (AntExChuModel antExChuModel : antExChuModels) {
  1082 + patientIds.add(antExChuModel.getParentId());
  1083 + }
  1084 +
  1085 + /** 产妇分娩: lyms_matdeliver */
  1086 + List<MaternalDeliverModel> deliverModels = mongoUtil.findField(MaternalDeliverModel.class, criteria, "parentId");
  1087 + for (MaternalDeliverModel deliverModel : deliverModels) {
  1088 + patientIds.add(deliverModel.getParentId());
  1089 + }
  1090 +
  1091 + /** 出院小结: lyms_discharge_abstract_mother 医院需要确定下 */
  1092 + Criteria disCriteria = Criteria.where("createDate").gte(DateUtil.getYearDate(year))
  1093 + .lt(DateUtil.getNextYearDate(year));
  1094 + List<DischargeAbstractMotherModel> dischargeAbstractMotherModels = mongoUtil.findField(DischargeAbstractMotherModel.class, disCriteria, "patientId");
  1095 + for (DischargeAbstractMotherModel dischargeAbstractMotherModel : dischargeAbstractMotherModels) {
  1096 + patientIds.add(dischargeAbstractMotherModel.getPatientId());
  1097 + }
  1098 +
  1099 + /** 产后复查: lyms_postreview */
  1100 + List<PostReviewModel> postReviewModels = mongoUtil.findField(PostReviewModel.class, criteria, "parentId");
  1101 + for (PostReviewModel postReviewModel : postReviewModels) {
  1102 + patientIds.add(postReviewModel.getParentId());
  1103 + }
  1104 +
  1105 + /** 产前筛查: lyms_sieve */
  1106 + List<SieveModel> sieveModels = mongoUtil.findField(SieveModel.class, criteria, "parentId");
  1107 + for (SieveModel sieveModel : sieveModels) {
  1108 + patientIds.add(sieveModel.getParentId());
  1109 + }
  1110 +
  1111 + if(StringUtils.isNotEmpty(provinceId)) {
  1112 + criteria.and("provinceId").in(CollectionUtils.asList(provinceId));
  1113 + }
  1114 +
  1115 + List<Patients> patients = mongoTemplate.find(Query.query(criteria), Patients.class);
  1116 +
  1117 + /* AggregationOperation match = Aggregation.match(
  1118 + Criteria.where("hospitalId").is(hospitalId)
  1119 +// .and("bookbuildingDate").gte(DateUtil.getYearDate(year)).lt(DateUtil.getNextYearDate(year))
  1120 + .and("id").in(patientIds));
  1121 + AggregationOperation provinceGroup = Aggregation.group("bookbuildingDate").count().as("provinceCount");
  1122 +// AggregationOperation cityGroup = Aggregation.group("cityId").count().as("cityCount");
  1123 +// AggregationOperation areaGroup = Aggregation.group("areaId").count().as("areaCount");
  1124 + Aggregation aggregation = Aggregation.newAggregation(match, provinceGroup);
  1125 + AggregationResults<HashMap> result = mongoTemplate.aggregate(aggregation, Patients.class, HashMap.class);
  1126 + List<HashMap> mappedResults = result.getMappedResults();
  1127 +
  1128 + for (HashMap mappedResult : mappedResults) {
  1129 + System.out.println(mappedResult);
  1130 + }
  1131 +*/
  1132 + ReportModel reportModel = new ReportModel();
  1133 + reportModel.setLegend(Arrays.asList("秦皇岛市", "辖区外"));
  1134 +
  1135 + reportModel.setxAxis(Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"));
  1136 +
  1137 +
  1138 + List<Series> series = createPatientSeries(patients);
  1139 + List<Map<String, Object>> mapList = mongoUtil.getListByGroup(patients);
  1140 + return RespBuilder.buildSuccess("patients", mapList, "report", reportModel);
  1141 + }
  1142 +
  1143 + private List<Series> createPatientSeries(List<Patients> patients) {
  1144 + List<Series> series = new ArrayList<>();
  1145 + Series qhdSeries = new Series();
  1146 + qhdSeries.setName("秦皇岛市");
  1147 + qhdSeries.setType("bar");
  1148 + List<Integer> qhdDatas = new ArrayList<>();
  1149 + BasicConfig basicConfig = mongoTemplate.findOne(Query.query(Criteria.where("name").is("河北省")), BasicConfig.class);
  1150 + if(basicConfig != null) {}
  1151 + for (Patients patient : patients) {
  1152 +// if(patient.getProvinceId() == 1)
  1153 + }
  1154 +
  1155 + series.add(qhdSeries);
  1156 + return series;
1057 1157 }
1058 1158  
1059 1159 private void exportChildUsedInfo(List<Map<String, Object>> data, HttpServletResponse response) {
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java View file @ e419256
  1 +package com.lyms.platform.operate.web.utils;
  2 +
  3 +import com.lyms.platform.common.utils.DateUtil;
  4 +import com.lyms.platform.common.utils.StringUtils;
  5 +import com.lyms.platform.pojo.BasicConfig;
  6 +import com.lyms.platform.pojo.Patients;
  7 +import com.mongodb.BasicDBObject;
  8 +import com.mongodb.DBObject;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.data.mongodb.core.MongoTemplate;
  11 +import org.springframework.data.mongodb.core.query.BasicQuery;
  12 +import org.springframework.data.mongodb.core.query.Criteria;
  13 +import org.springframework.data.mongodb.core.query.Query;
  14 +import org.springframework.stereotype.Component;
  15 +
  16 +import java.util.*;
  17 +
  18 +/**
  19 + * @Author: litao
  20 + * @Date: 2017/6/13 0013
  21 + */
  22 +@Component
  23 +public class MongoUtil {
  24 + @Autowired
  25 + private MongoTemplate mongoTemplate;
  26 +
  27 + /**
  28 + * 查询mongo表中指定的字段
  29 + * @param clazz
  30 + * @param criteria
  31 + * @param fields
  32 + * @param <T>
  33 + * @return
  34 + */
  35 + public <T> List<T> findField(Class<T> clazz, Criteria criteria, String ... fields) {
  36 + DBObject dbObject = new BasicDBObject();
  37 + DBObject fieldObject = new BasicDBObject();
  38 + for (String field : fields) {
  39 + fieldObject.put(field, true);
  40 + }
  41 + Query query = new BasicQuery(dbObject, fieldObject);
  42 + query.addCriteria(criteria);
  43 + List<T> list = mongoTemplate.find(query, clazz);
  44 + return list;
  45 + }
  46 +
  47 + /**
  48 + * 按照月份、省市区统计总数
  49 + * 详见原型图建册人数统计
  50 + * @param patients
  51 + * @return
  52 + */
  53 + public List<Map<String, Object>> getListByGroup(List<Patients> patients) {
  54 + Map<String, Integer> codeMap = new HashMap<>(); /** key为 id_month */
  55 +
  56 + Map<String, Integer> otherCountMap = new HashMap<>();
  57 + Map<String, Integer> otherMonthMap = new HashMap<>();
  58 + for (int i = 1; i <= 12; i++) {
  59 + otherMonthMap.put(i + "", 0);
  60 + }
  61 + /*otherMonthMap.put("1", 0);
  62 + otherMonthMap.put("2", 0);
  63 + otherMonthMap.put("3", 0);
  64 + otherMonthMap.put("4", 0);
  65 + otherMonthMap.put("5", 0);
  66 + otherMonthMap.put("6", 0);
  67 + otherMonthMap.put("7", 0);
  68 + otherMonthMap.put("8", 0);
  69 + otherMonthMap.put("9", 0);
  70 + otherMonthMap.put("10", 0);
  71 + otherMonthMap.put("11", 0);
  72 + otherMonthMap.put("12", 0);*/
  73 +
  74 + Integer otherCount = 0;
  75 + /* for (Patients patient : patients) {
  76 + System.out.println("month:" + DateUtil.getMonth(patient.getBookbuildingDate()) + "\tprovinceId: " + patient.getProvinceId()
  77 + + "\tcityId: " + patient.getCityId() + "\tareaId:" + patient.getAreaId());
  78 + }*/
  79 + for (Patients patient : patients) {
  80 + Date bookbuildingDate = patient.getBookbuildingDate();
  81 + if(bookbuildingDate == null) {
  82 + bookbuildingDate = patient.getCreated();
  83 + }
  84 + if(bookbuildingDate != null) {
  85 + String provinceId = patient.getProvinceId();
  86 + String cityId = patient.getCityId();
  87 + String areaId = patient.getAreaId();
  88 + Integer month = DateUtil.getMonth(bookbuildingDate);
  89 +
  90 + if (StringUtils.isEmpty(provinceId) || StringUtils.isEmpty(cityId) || StringUtils.isEmpty(areaId)) {
  91 + otherMonthMap.put(month + "", otherMonthMap.get(month + "") + 1);
  92 + ++otherCount;
  93 + continue;
  94 + }
  95 +
  96 + if(codeMap.containsKey(provinceId + "_" + month)) {
  97 + codeMap.put(provinceId + "_" + month, codeMap.get(provinceId + "_" + month) + 1);
  98 + } else {
  99 + codeMap.put(provinceId + "_" + month, 1);
  100 + }
  101 + if(codeMap.containsKey(cityId + "_" + month)) {
  102 + codeMap.put(cityId + "_" + month, codeMap.get(cityId + "_" + month) + 1);
  103 + } else {
  104 + codeMap.put(cityId + "_" + month, 1);
  105 + }
  106 + if(codeMap.containsKey(areaId + "_" + month)) {
  107 + codeMap.put(areaId + "_" + month, codeMap.get(areaId + "_" + month) + 1);
  108 + } else {
  109 + codeMap.put(areaId + "_" + month, 1);
  110 + }
  111 + }
  112 + }
  113 +
  114 + List<Map<String, Map<Integer, Integer>>> datas = new ArrayList<>();
  115 + Set<Map.Entry<String, Integer>> entries = codeMap.entrySet();
  116 + for (Map.Entry<String, Integer> entry : entries) {
  117 + String key = entry.getKey();
  118 + String id = key.split("_")[0];
  119 + Integer month = Integer.parseInt(key.split("_")[1]);
  120 + Integer count = entry.getValue();
  121 +
  122 + boolean flag = true;
  123 + for (Map<String, Map<Integer, Integer>> data : datas) {
  124 + if(data.containsKey(id)) {
  125 + Map<Integer, Integer> map = data.get(id);
  126 + if(map.containsKey(month)) {
  127 + map.put(month, map.get(month) + count);
  128 + } else {
  129 + map.put(month, count);
  130 + }
  131 + flag = false;
  132 + }
  133 + }
  134 +
  135 + if(flag) {
  136 + Map<String, Map<Integer, Integer>> tempMap = new HashMap<>();
  137 + Map<Integer, Integer> map = new HashMap<>();
  138 + map.put(month, count);
  139 + tempMap.put(id, map);
  140 + datas.add(tempMap);
  141 + }
  142 + }
  143 +
  144 + System.out.println("===================================== codemap =================================");
  145 + Set<Map.Entry<String, Integer>> codeMapEntries = codeMap.entrySet();
  146 + for (Map.Entry<String, Integer> codeMapEntry : codeMapEntries) {
  147 + System.out.println(codeMapEntry.getKey() + " : " + codeMapEntry.getValue());
  148 + }
  149 + System.out.println("===================================== datas =================================");
  150 + for (Map<String, Map<Integer, Integer>> data : datas) {
  151 + Set<Map.Entry<String, Map<Integer, Integer>>> set = data.entrySet();
  152 + for (Map.Entry<String, Map<Integer, Integer>> mapEntry : set) {
  153 + System.out.println(mapEntry.getKey() + " : " + mapEntry.getValue());
  154 + }
  155 + }
  156 +
  157 + List<Map<String, Object>> restMap = new ArrayList<>();
  158 +
  159 + /** 设置没数据的月份为0 */
  160 + for (Map<String, Map<Integer, Integer>> data : datas) {
  161 + Integer count = 0;
  162 + Set<Map.Entry<String, Map<Integer, Integer>>> set = data.entrySet();
  163 + for (Map.Entry<String, Map<Integer, Integer>> entry : set) {
  164 + Map<Integer, Integer> map = entry.getValue();
  165 + Map<String, Object> tempMap = new HashMap<>();
  166 + for (int i = 1; i <= 12; i++) {
  167 + if(!map.containsKey(i)) {
  168 + map.put(i, 0);
  169 + tempMap.put(i + "", 0);
  170 + } else {
  171 + count += map.get(i);
  172 + tempMap.put(i + "", map.get(i));
  173 + }
  174 + }
  175 + map.put(0, count);
  176 + tempMap.put("count", count);
  177 + tempMap.put("id", entry.getKey());
  178 + tempMap.put("name", findName(entry.getKey()));
  179 + restMap.add(tempMap);
  180 + }
  181 + }
  182 +
  183 +
  184 + /** 处理 其他 数据 */
  185 + Map<String, Object> tempMap = new HashMap<>();
  186 + tempMap.put("count", otherCount);
  187 + tempMap.put("name", "其他");
  188 + tempMap.put("id", null);
  189 + for (int i = 1; i <= 12; i++) {
  190 + if(otherMonthMap.containsKey(i + "")) {
  191 + tempMap.put(i + "", otherMonthMap.get(i + ""));
  192 + } else {
  193 + tempMap.put(i + "", 0);
  194 + }
  195 + }
  196 + restMap.add(tempMap);
  197 +
  198 + /* for (Map<String, Map<Integer, Integer>> data : datas) {
  199 + System.out.println("data>>> " + data);
  200 + }
  201 + System.out.println("========================");
  202 + for (Map<String, Object> map : restMap) {
  203 + System.out.println("rest>> " + map);
  204 + }*/
  205 + return restMap;
  206 + }
  207 +
  208 + public String findName(Object id) {
  209 + if(id != null) {
  210 + BasicConfig basicConfig = mongoTemplate.findById(id, BasicConfig.class);
  211 + if(basicConfig != null) {
  212 + return basicConfig.getName();
  213 + }
  214 + }
  215 + return null;
  216 + }
  217 +
  218 +}
platform-reportData/src/main/java/com/lymsh/platform/reportdata/model/echarts/Series.java View file @ e419256
... ... @@ -13,6 +13,7 @@
13 13 private Boolean roam;
14 14 private Label label;
15 15 private List<Object> data;
  16 + private String stack;
16 17  
17 18 public String getName() {
18 19 return name;
... ... @@ -60,6 +61,14 @@
60 61  
61 62 public void setData(List<Object> data) {
62 63 this.data = data;
  64 + }
  65 +
  66 + public String getStack() {
  67 + return stack;
  68 + }
  69 +
  70 + public void setStack(String stack) {
  71 + this.stack = stack;
63 72 }
64 73 }