diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java index 1669b66..0503c85 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java @@ -11,6 +11,7 @@ import java.util.concurrent.locks.ReentrantLock; public class DateUtil { private static Lock lock = new ReentrantLock(); public static SimpleDateFormat dd = new SimpleDateFormat("dd"); + public static SimpleDateFormat yyyy = new SimpleDateFormat("yyyy"); public static SimpleDateFormat ymd = new SimpleDateFormat("yyyyMMdd"); public static SimpleDateFormat y_m_d = new SimpleDateFormat("yyyy-MM-dd"); public static SimpleDateFormat md = new SimpleDateFormat("MM-dd"); @@ -196,6 +197,28 @@ public class DateUtil { } } + public static Date getYearDate(String s) { + if (s == null) { + return null; + } + try { + return yyyy.parse(s); + } catch (Exception e) { + return null; + } + } + + public static Date getNextYearDate(String s) { + if (s == null) { + return null; + } + try { + return DateUtil.addYear(yyyy.parse(s), 1); + } catch (Exception e) { + return null; + } + } + public static String getymdhm(Date d) { if (d == null) { return null; @@ -949,7 +972,9 @@ public class DateUtil { public static void main(String[] arg) throws Exception { Date start = parseYMD("2017-05-11"); Date end = parseYMD("2017-06-02"); - System.err.println(getMonthDesc(start, end)); + + System.out.println(getMonth(start)); + System.out.println(getMonth(end)); } @@ -967,4 +992,15 @@ public class DateUtil { int day = getExcludeMonthDay(start, end); return month + "月龄+" + day + "天"; } + + /** + * 获取传入日期的月份 + * @param date + * @return + */ + public static Integer getMonth(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + return calendar.get(Calendar.MONTH) + 1; + } } diff --git a/platform-operate-api/src/main/java/com/lyms/hospitalapi/pojo/ReportModel.java b/platform-operate-api/src/main/java/com/lyms/hospitalapi/pojo/ReportModel.java index 1ece89a..9875ef6 100644 --- a/platform-operate-api/src/main/java/com/lyms/hospitalapi/pojo/ReportModel.java +++ b/platform-operate-api/src/main/java/com/lyms/hospitalapi/pojo/ReportModel.java @@ -32,6 +32,8 @@ public class ReportModel { private List doctorInfo; + private List legend; + /** * 将 x 轴数据去重并把series数据合并 */ @@ -151,4 +153,12 @@ public class ReportModel { public void setSeries(List series) { this.series = series; } + + public List getLegend() { + return legend; + } + + public void setLegend(List legend) { + this.legend = legend; + } } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java index d98d7dc..854dee9 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java @@ -273,4 +273,23 @@ public class ReportController extends BaseController { return reportService.couponInit(CollectionUtils.createMap("userId", getUserId(request), "couponType", couponType)); } + + /** + * 把产前检查/产妇分娩/出院小结/产后复查/产前筛查里面所有的pid找出来去重 + * 根据省市区条件返回统计数据 + * @param request + * @param year + * @param provinceId + * @param cityId + * @param areaId + * @return + */ + @ResponseBody +// @TokenRequired + @RequestMapping(value = "/patient", method = RequestMethod.GET) + public BaseObjectResponse patient(HttpServletRequest request, String year, String provinceId, String cityId, String areaId) { +// return reportService.patient(getUserId(request), year); + return reportService.patient(2144, year, provinceId, cityId, areaId); + } + } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java index faa031f..f447e2f 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java @@ -74,4 +74,6 @@ public interface IReportService extends IBaseService { BaseObjectResponse couponInfo(Map param); void exportCouponInfo(Map param, HttpServletResponse response); + + BaseObjectResponse patient(Integer userId, String s, String provinceId, String cityId, String year); } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java index 36a183d..5014a46 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java @@ -20,6 +20,9 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; @@ -54,6 +57,9 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService @Autowired private AccessPermissionFacade accessPermissionFacade; + @Autowired + private MongoUtil mongoUtil; + private static final Map colorMap = new HashMap<>(); /** @@ -1056,6 +1062,100 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService } + @Override + public BaseObjectResponse patient(Integer userId, String year, String provinceId, String cityId, String areaId) { + String hospitalId = autoMatchFacade.getHospitalId(userId); + + Set patientIds = new HashSet<>(); + + Criteria criteria = Criteria.where("created").gte(DateUtil.getYearDate(year)) + .lt(DateUtil.getNextYearDate(year)) + .and("hospitalId").is(hospitalId); + + /** 产前检查: lyms_antexc(初诊),lyms_antex(复诊)设置pid */ + List antenatalExaminationModels = mongoUtil.findField(AntenatalExaminationModel.class, criteria, "parentId"); + for (AntenatalExaminationModel antenatalExaminationModel : antenatalExaminationModels) { + patientIds.add(antenatalExaminationModel.getParentId()); + } + List antExChuModels = mongoUtil.findField(AntExChuModel.class, criteria, "parentId"); + for (AntExChuModel antExChuModel : antExChuModels) { + patientIds.add(antExChuModel.getParentId()); + } + + /** 产妇分娩: lyms_matdeliver */ + List deliverModels = mongoUtil.findField(MaternalDeliverModel.class, criteria, "parentId"); + for (MaternalDeliverModel deliverModel : deliverModels) { + patientIds.add(deliverModel.getParentId()); + } + + /** 出院小结: lyms_discharge_abstract_mother 医院需要确定下 */ + Criteria disCriteria = Criteria.where("createDate").gte(DateUtil.getYearDate(year)) + .lt(DateUtil.getNextYearDate(year)); + List dischargeAbstractMotherModels = mongoUtil.findField(DischargeAbstractMotherModel.class, disCriteria, "patientId"); + for (DischargeAbstractMotherModel dischargeAbstractMotherModel : dischargeAbstractMotherModels) { + patientIds.add(dischargeAbstractMotherModel.getPatientId()); + } + + /** 产后复查: lyms_postreview */ + List postReviewModels = mongoUtil.findField(PostReviewModel.class, criteria, "parentId"); + for (PostReviewModel postReviewModel : postReviewModels) { + patientIds.add(postReviewModel.getParentId()); + } + + /** 产前筛查: lyms_sieve */ + List sieveModels = mongoUtil.findField(SieveModel.class, criteria, "parentId"); + for (SieveModel sieveModel : sieveModels) { + patientIds.add(sieveModel.getParentId()); + } + + if(StringUtils.isNotEmpty(provinceId)) { + criteria.and("provinceId").in(CollectionUtils.asList(provinceId)); + } + + List patients = mongoTemplate.find(Query.query(criteria), Patients.class); + + /* AggregationOperation match = Aggregation.match( + Criteria.where("hospitalId").is(hospitalId) +// .and("bookbuildingDate").gte(DateUtil.getYearDate(year)).lt(DateUtil.getNextYearDate(year)) + .and("id").in(patientIds)); + AggregationOperation provinceGroup = Aggregation.group("bookbuildingDate").count().as("provinceCount"); +// AggregationOperation cityGroup = Aggregation.group("cityId").count().as("cityCount"); +// AggregationOperation areaGroup = Aggregation.group("areaId").count().as("areaCount"); + Aggregation aggregation = Aggregation.newAggregation(match, provinceGroup); + AggregationResults result = mongoTemplate.aggregate(aggregation, Patients.class, HashMap.class); + List mappedResults = result.getMappedResults(); + + for (HashMap mappedResult : mappedResults) { + System.out.println(mappedResult); + } +*/ + ReportModel reportModel = new ReportModel(); + reportModel.setLegend(Arrays.asList("秦皇岛市", "辖区外")); + + reportModel.setxAxis(Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月")); + + + List series = createPatientSeries(patients); + List> mapList = mongoUtil.getListByGroup(patients); + return RespBuilder.buildSuccess("patients", mapList, "report", reportModel); + } + + private List createPatientSeries(List patients) { + List series = new ArrayList<>(); + Series qhdSeries = new Series(); + qhdSeries.setName("秦皇岛市"); + qhdSeries.setType("bar"); + List qhdDatas = new ArrayList<>(); + BasicConfig basicConfig = mongoTemplate.findOne(Query.query(Criteria.where("name").is("河北省")), BasicConfig.class); + if(basicConfig != null) {} + for (Patients patient : patients) { +// if(patient.getProvinceId() == 1) + } + + series.add(qhdSeries); + return series; + } + private void exportChildUsedInfo(List> data, HttpServletResponse response) { Map cnames = new LinkedHashMap<>(); cnames.put("id", "#"); diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java new file mode 100644 index 0000000..3f97647 --- /dev/null +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java @@ -0,0 +1,218 @@ +package com.lyms.platform.operate.web.utils; + +import com.lyms.platform.common.utils.DateUtil; +import com.lyms.platform.common.utils.StringUtils; +import com.lyms.platform.pojo.BasicConfig; +import com.lyms.platform.pojo.Patients; +import com.mongodb.BasicDBObject; +import com.mongodb.DBObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.BasicQuery; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Component; + +import java.util.*; + +/** + * @Author: litao + * @Date: 2017/6/13 0013 + */ +@Component +public class MongoUtil { + @Autowired + private MongoTemplate mongoTemplate; + + /** + * 查询mongo表中指定的字段 + * @param clazz + * @param criteria + * @param fields + * @param + * @return + */ + public List findField(Class clazz, Criteria criteria, String ... fields) { + DBObject dbObject = new BasicDBObject(); + DBObject fieldObject = new BasicDBObject(); + for (String field : fields) { + fieldObject.put(field, true); + } + Query query = new BasicQuery(dbObject, fieldObject); + query.addCriteria(criteria); + List list = mongoTemplate.find(query, clazz); + return list; + } + + /** + * 按照月份、省市区统计总数 + * 详见原型图建册人数统计 + * @param patients + * @return + */ + public List> getListByGroup(List patients) { + Map codeMap = new HashMap<>(); /** key为 id_month */ + + Map otherCountMap = new HashMap<>(); + Map otherMonthMap = new HashMap<>(); + for (int i = 1; i <= 12; i++) { + otherMonthMap.put(i + "", 0); + } + /*otherMonthMap.put("1", 0); + otherMonthMap.put("2", 0); + otherMonthMap.put("3", 0); + otherMonthMap.put("4", 0); + otherMonthMap.put("5", 0); + otherMonthMap.put("6", 0); + otherMonthMap.put("7", 0); + otherMonthMap.put("8", 0); + otherMonthMap.put("9", 0); + otherMonthMap.put("10", 0); + otherMonthMap.put("11", 0); + otherMonthMap.put("12", 0);*/ + + Integer otherCount = 0; + /* for (Patients patient : patients) { + System.out.println("month:" + DateUtil.getMonth(patient.getBookbuildingDate()) + "\tprovinceId: " + patient.getProvinceId() + + "\tcityId: " + patient.getCityId() + "\tareaId:" + patient.getAreaId()); + }*/ + for (Patients patient : patients) { + Date bookbuildingDate = patient.getBookbuildingDate(); + if(bookbuildingDate == null) { + bookbuildingDate = patient.getCreated(); + } + if(bookbuildingDate != null) { + String provinceId = patient.getProvinceId(); + String cityId = patient.getCityId(); + String areaId = patient.getAreaId(); + Integer month = DateUtil.getMonth(bookbuildingDate); + + if (StringUtils.isEmpty(provinceId) || StringUtils.isEmpty(cityId) || StringUtils.isEmpty(areaId)) { + otherMonthMap.put(month + "", otherMonthMap.get(month + "") + 1); + ++otherCount; + continue; + } + + if(codeMap.containsKey(provinceId + "_" + month)) { + codeMap.put(provinceId + "_" + month, codeMap.get(provinceId + "_" + month) + 1); + } else { + codeMap.put(provinceId + "_" + month, 1); + } + if(codeMap.containsKey(cityId + "_" + month)) { + codeMap.put(cityId + "_" + month, codeMap.get(cityId + "_" + month) + 1); + } else { + codeMap.put(cityId + "_" + month, 1); + } + if(codeMap.containsKey(areaId + "_" + month)) { + codeMap.put(areaId + "_" + month, codeMap.get(areaId + "_" + month) + 1); + } else { + codeMap.put(areaId + "_" + month, 1); + } + } + } + + List>> datas = new ArrayList<>(); + Set> entries = codeMap.entrySet(); + for (Map.Entry entry : entries) { + String key = entry.getKey(); + String id = key.split("_")[0]; + Integer month = Integer.parseInt(key.split("_")[1]); + Integer count = entry.getValue(); + + boolean flag = true; + for (Map> data : datas) { + if(data.containsKey(id)) { + Map map = data.get(id); + if(map.containsKey(month)) { + map.put(month, map.get(month) + count); + } else { + map.put(month, count); + } + flag = false; + } + } + + if(flag) { + Map> tempMap = new HashMap<>(); + Map map = new HashMap<>(); + map.put(month, count); + tempMap.put(id, map); + datas.add(tempMap); + } + } + + System.out.println("===================================== codemap ================================="); + Set> codeMapEntries = codeMap.entrySet(); + for (Map.Entry codeMapEntry : codeMapEntries) { + System.out.println(codeMapEntry.getKey() + " : " + codeMapEntry.getValue()); + } + System.out.println("===================================== datas ================================="); + for (Map> data : datas) { + Set>> set = data.entrySet(); + for (Map.Entry> mapEntry : set) { + System.out.println(mapEntry.getKey() + " : " + mapEntry.getValue()); + } + } + + List> restMap = new ArrayList<>(); + + /** 设置没数据的月份为0 */ + for (Map> data : datas) { + Integer count = 0; + Set>> set = data.entrySet(); + for (Map.Entry> entry : set) { + Map map = entry.getValue(); + Map tempMap = new HashMap<>(); + for (int i = 1; i <= 12; i++) { + if(!map.containsKey(i)) { + map.put(i, 0); + tempMap.put(i + "", 0); + } else { + count += map.get(i); + tempMap.put(i + "", map.get(i)); + } + } + map.put(0, count); + tempMap.put("count", count); + tempMap.put("id", entry.getKey()); + tempMap.put("name", findName(entry.getKey())); + restMap.add(tempMap); + } + } + + + /** 处理 其他 数据 */ + Map tempMap = new HashMap<>(); + tempMap.put("count", otherCount); + tempMap.put("name", "其他"); + tempMap.put("id", null); + for (int i = 1; i <= 12; i++) { + if(otherMonthMap.containsKey(i + "")) { + tempMap.put(i + "", otherMonthMap.get(i + "")); + } else { + tempMap.put(i + "", 0); + } + } + restMap.add(tempMap); + + /* for (Map> data : datas) { + System.out.println("data>>> " + data); + } + System.out.println("========================"); + for (Map map : restMap) { + System.out.println("rest>> " + map); + }*/ + return restMap; + } + + public String findName(Object id) { + if(id != null) { + BasicConfig basicConfig = mongoTemplate.findById(id, BasicConfig.class); + if(basicConfig != null) { + return basicConfig.getName(); + } + } + return null; + } + +} diff --git a/platform-reportData/src/main/java/com/lymsh/platform/reportdata/model/echarts/Series.java b/platform-reportData/src/main/java/com/lymsh/platform/reportdata/model/echarts/Series.java index 237ec08..d20c53d 100644 --- a/platform-reportData/src/main/java/com/lymsh/platform/reportdata/model/echarts/Series.java +++ b/platform-reportData/src/main/java/com/lymsh/platform/reportdata/model/echarts/Series.java @@ -13,6 +13,7 @@ public class Series { private Boolean roam; private Label label; private List data; + private String stack; public String getName() { return name; @@ -61,4 +62,12 @@ public class Series { public void setData(List data) { this.data = data; } + + public String getStack() { + return stack; + } + + public void setStack(String stack) { + this.stack = stack; + } }