123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- package com.yihu.ehr.profile.service;
- import com.yihu.ehr.profile.family.ResourceCells;
- import com.yihu.ehr.profile.model.InspectionInfo;
- import com.yihu.ehr.profile.util.NumberValidationUtils;
- import com.yihu.ehr.profile.util.SimpleSolrQueryUtil;
- import com.yihu.ehr.util.rest.Envelop;
- import org.springframework.stereotype.Service;
- import org.springframework.util.StringUtils;
- import java.util.*;
- /**
- * @author progr1mmer
- * @date Created on 2018/3/13.
- */
- @Service
- public class ProfileInspectionService extends ProfileBasicService {
- public List inspectionRecords(String demographicId, String filter, String date, String searchParam) throws Exception {
- List<Map<String, Object>> resultList = new ArrayList<>();
- Map<String, String> typeMap = new HashMap<>();
- typeMap.put("HDSD00_79", "inspect");
- typeMap.put("HDSD00_77", "examine");
- Map<String, String> nameMap = new HashMap<>();
- //检查名称
- nameMap.put("HDSD00_79", "EHR_002883");
- //检验项目
- nameMap.put("HDSD00_77", "EHR_000352");
- Map<String, String> numMap = new HashMap<>();
- //检查报告单号
- numMap.put("HDSD00_79", "EHR_000316");
- //检验报告单号
- numMap.put("HDSD00_77", "EHR_000363");
- for (String dataset : typeMap.keySet()) {
- String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
- query = SimpleSolrQueryUtil.getQuery(filter, date, query);
- Envelop masterEnvelop = resource.getMasterData(query, 1, 1000, null);
- if (masterEnvelop.isSuccessFlg()) {
- List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
- //循环获取结果集
- for (Map<String, Object> temp : masterList) {
- String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$" + dataset + "$*\"}";
- Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
- List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
- subList.forEach(item -> {
- Map<String, Object> resultMap = simpleEvent(temp, searchParam);
- if (resultMap != null) {
- String healthProblemName = (String) resultMap.get("healthProblemName");
- String itemName = (String) item.get(nameMap.get(dataset));
- if (itemName != null) {
- resultMap.put("projectName", itemName);
- } else {
- if (dataset.equals("HDSD00_79")) {
- resultMap.put("projectName", "检查报告-" + healthProblemName);
- } else {
- resultMap.put("projectName", "检验报告-" + healthProblemName);
- }
- }
- resultMap.put("type", typeMap.get(dataset));
- resultMap.put("mark", item.get(numMap.get(dataset)));
- resultList.add(resultMap);
- }
- });
- }
- }
- }
- return resultList;
- }
- public List<InspectionInfo> inspectionStatistics(String demographicId, String table) throws Exception {
- String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
- query = SimpleSolrQueryUtil.getQuery(null, null, query);
- Envelop masterEnvelop = resource.getMasterData(query, 1, 1000, null);
- Map<String, Integer> dataMap = new HashMap<>();
- Map<String, String> firstMap = new HashMap<>();
- Map<String, String> lastMap = new HashMap<>();
- Map<String, Integer> exMap = new HashMap<>();
- if (masterEnvelop.isSuccessFlg()) {
- List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
- //循环获取结果集
- for (Map<String, Object> temp : masterList) {
- String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$" + table + "$*\"}";
- Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
- List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
- for (int i = 0; i < subList.size(); i ++) {
- Map<String, Object> item = subList.get(i);
- //检查名称
- if (!StringUtils.isEmpty(item.get("EHR_002883"))) {
- String name = item.get("EHR_002883").toString();
- //影像结论
- String result = item.get("EHR_000347") == null ? "-" : item.get("EHR_000347").toString();
- if (dataMap.containsKey(name)) {
- Integer count = dataMap.get(name);
- dataMap.put(name, count + 1);
- lastMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + result);
- } else {
- dataMap.put(name, 1);
- firstMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + result);
- }
- if (!StringUtils.isEmpty(item.get("EHR_000344"))) {
- String ex = item.get("EHR_000344").toString();
- if ("1".equals(ex)) {
- if (exMap.containsKey(name)) {
- Integer count = exMap.get(name);
- exMap.put(name, count + 1);
- } else {
- exMap.put(name, 1);
- }
- }
- }
- //检验项目
- } else if (!StringUtils.isEmpty(item.get("EHR_000352"))) {
- String name = item.get("EHR_000352").toString();
- if (dataMap.containsKey(name)) {
- Integer count = dataMap.get(name);
- dataMap.put(name, count + 1);
- lastMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + "-");
- } else {
- dataMap.put(name, 1);
- firstMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + "-");
- }
- }
- }
- }
- }
- Map<String, Integer> newDataMap = sortByValue(dataMap);
- List<InspectionInfo> inspectionInfos = new ArrayList<>();
- newDataMap.forEach((key, val) -> {
- InspectionInfo inspectionInfo = new InspectionInfo();
- inspectionInfo.setName(key);
- inspectionInfo.setCount(val);
- inspectionInfo.setFirstTime(firstMap.get(key).split("&")[0]);
- if (exMap.containsKey(key)) {
- inspectionInfo.setExCount(exMap.get(key));
- }
- if (lastMap.get(key) != null) {
- inspectionInfo.setLastTime(lastMap.get(key).split("&")[0]);
- inspectionInfo.setLastOrg(lastMap.get(key).split("&")[1]);
- inspectionInfo.setLastRecord(lastMap.get(key).split("&")[2]);
- inspectionInfo.setResult(lastMap.get(key).split("&")[3]);
- } else {
- inspectionInfo.setLastTime(firstMap.get(key).split("&")[0]);
- inspectionInfo.setLastOrg(firstMap.get(key).split("&")[1]);
- inspectionInfo.setLastRecord(firstMap.get(key).split("&")[2]);
- inspectionInfo.setResult(firstMap.get(key).split("&")[3]);
- }
- inspectionInfos.add(inspectionInfo);
- });
- return inspectionInfos;
- }
- public Map<String, String> inspectionStatisticsOneSub(String profileId) throws Exception {
- Map<String, String> dataMap = new HashMap<>();
- String subQ = "{\"q\":\"rowkey:" + profileId + "\"}";
- Envelop subData = resource.getSubData(subQ, 1, 1, null);
- List<Map<String, Object>> subList = subData.getDetailModelList();
- if (subList.size() > 0) {
- Map<String, Object> temp = subList.get(0);
- //检验报告单号
- String reportNo = temp.get("EHR_000363").toString();
- subQ = "{\"q\":\"rowkey:" + profileId.split("\\$")[0] + "$HDSD00_75$*" + "\"}";
- subData = resource.getSubData(subQ, 1, 1000, null);
- List<Map<String, Object>> subItems = subData.getDetailModelList();
- subItems.forEach(item -> {
- //子项所属的报告单号
- if (reportNo.equals(item.get("EHR_006339"))) {
- //结果值
- if (item.get("EHR_000387") != null) {
- //结果值
- String result = item.get("EHR_000387").toString();
- if (item.get("EHR_000391") != null && item.get("EHR_000390")!= null) {
- //下限
- String low = item.get("EHR_000391").toString();
- //上限
- String high = item.get("EHR_000390").toString();
- if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
- Double _result = Double.parseDouble(result);
- Double _row = Double.parseDouble(low);
- Double _high = Double.parseDouble(high);
- if (_result < _row) {
- dataMap.put(item.get("EHR_000394").toString(), "偏低");
- } else if (_result > _high) {
- dataMap.put(item.get("EHR_000394").toString(), "偏高");
- } else {
- dataMap.put(item.get("EHR_000394").toString(), "正常");
- }
- } else {
- dataMap.put(item.get("EHR_000394").toString(), item.get("EHR_000387").toString());
- }
- } else {
- dataMap.put(item.get("EHR_000394").toString(), item.get("EHR_000387").toString());
- }
- } else {
- dataMap.put(item.get("EHR_000394").toString(), "");
- }
- }
- });
- }
- return dataMap;
- }
- public Map<String, Map<String, Integer>> inspectionStatisticsAllSub(String demographicId, String name) throws Exception {
- String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
- query = SimpleSolrQueryUtil.getQuery(null, null, query);
- Envelop masterEnvelop = resource.getMasterData(query, 1, 1000, null);
- List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
- //循环获取结果集
- Set<String> data = new HashSet<>();
- Map<String, Integer> lowMap = new HashMap<>();
- Map<String, Integer> highMap = new HashMap<>();
- Map<String, Integer> normalMap = new HashMap<>();
- Map<String, Integer> unknownMap = new HashMap<>();
- Map<String, Integer> positiveMap = new HashMap<>();
- Map<String, Integer> negativeMap = new HashMap<>();
- for (Map<String, Object> masterItem : masterList) {
- String subQ = "{\"q\":\"rowkey:" + masterItem.get("rowkey") + "$HDSD00_77$*\"}";
- Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
- List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
- for (Map<String, Object> subItem : subList) {
- //检验项目
- if (name.equals(subItem.get("EHR_000352"))) {
- //检验报告单号
- String reportNo = subItem.get("EHR_000363").toString();
- subQ = "{\"q\":\"rowkey:" + masterItem.get(ResourceCells.ROWKEY) + "$HDSD00_75$*" + "\"}";
- subEnvelop = resource.getSubData(subQ, 1, 1000, null);
- List<Map<String, Object>> subItems = subEnvelop.getDetailModelList();
- subItems.forEach(item -> {
- //子项所属的报告单号
- if (reportNo.equals(item.get("EHR_006339"))) {
- //子项名称
- String itemName = item.get("EHR_000394").toString();
- data.add(itemName);
- //结果值
- if (item.get("EHR_000387") != null) {
- String result = item.get("EHR_000387").toString();
- if (item.get("EHR_000391") != null && item.get("EHR_000390")!= null) {
- //上限
- String low = item.get("EHR_000391").toString();
- //下限
- String high = item.get("EHR_000390").toString();
- if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
- Double _result = Double.parseDouble(result);
- Double _row = Double.parseDouble(low);
- Double _high = Double.parseDouble(high);
- if (_result < _row) {
- if (lowMap.containsKey(itemName)) {
- lowMap.put(itemName, lowMap.get(itemName) + 1);
- } else {
- lowMap.put(itemName, 1);
- }
- } else if (_result > _high) {
- if (highMap.containsKey(itemName)) {
- highMap.put(itemName, highMap.get(itemName) + 1);
- } else {
- highMap.put(itemName, 1);
- }
- } else {
- if (normalMap.containsKey(itemName)) {
- normalMap.put(itemName, normalMap.get(itemName) + 1);
- } else {
- normalMap.put(itemName, 1);
- }
- }
- } else {
- if (unknownMap.containsKey(itemName)) {
- unknownMap.put(itemName, unknownMap.get(itemName) + 1);
- } else {
- unknownMap.put(itemName, 1);
- }
- }
- //参考值备注
- } else if (item.get("EHR_000382") != null) {
- String range = item.get("EHR_000382").toString();
- //上限
- if (range.split("-").length == 2) {
- String low = range.split("-")[0];
- //下限
- String high = range.split("-")[1];
- if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
- Double _result = Double.parseDouble(result);
- Double _row = Double.parseDouble(low);
- Double _high = Double.parseDouble(high);
- if (_result < _row) {
- if (lowMap.containsKey(itemName)) {
- lowMap.put(itemName, lowMap.get(itemName) + 1);
- } else {
- lowMap.put(itemName, 1);
- }
- } else if (_result > _high) {
- if (highMap.containsKey(itemName)) {
- highMap.put(itemName, highMap.get(itemName) + 1);
- } else {
- highMap.put(itemName, 1);
- }
- } else {
- if (normalMap.containsKey(itemName)) {
- normalMap.put(itemName, normalMap.get(itemName) + 1);
- } else {
- normalMap.put(itemName, 1);
- }
- }
- } else {
- if (unknownMap.containsKey(itemName)) {
- unknownMap.put(itemName, unknownMap.get(itemName) + 1);
- } else {
- unknownMap.put(itemName, 1);
- }
- }
- } else {
- if (unknownMap.containsKey(itemName)) {
- unknownMap.put(itemName, unknownMap.get(itemName) + 1);
- } else {
- unknownMap.put(itemName, 1);
- }
- }
- } else {
- if (result.equals("阳性")) {
- if (positiveMap.containsKey(itemName)) {
- positiveMap.put(itemName, positiveMap.get(itemName) + 1);
- } else {
- positiveMap.put(itemName, 1);
- }
- } else if (result.equals("阴性")) {
- if (negativeMap.containsKey(itemName)) {
- negativeMap.put(itemName, negativeMap.get(itemName) + 1);
- } else {
- negativeMap.put(itemName, 1);
- }
- } else {
- if (unknownMap.containsKey(itemName)) {
- unknownMap.put(itemName, unknownMap.get(itemName) + 1);
- } else {
- unknownMap.put(itemName, 1);
- }
- }
- }
- } else {
- if (unknownMap.containsKey(itemName)) {
- unknownMap.put(itemName, unknownMap.get(itemName) + 1);
- } else {
- unknownMap.put(itemName, 1);
- }
- }
- }
- });
- }
- }
- }
- Map<String, Map<String, Integer>> result = new HashMap<>();
- data.forEach(item -> {
- Map<String, Integer> details = new HashMap<>();
- if (lowMap.containsKey(item)) {
- details.put("偏低", lowMap.get(item));
- }
- if (highMap.containsKey(item)) {
- details.put("偏高", highMap.get(item));
- }
- if (normalMap.containsKey(item)) {
- details.put("正常", normalMap.get(item));
- }
- if (unknownMap.containsKey(item)) {
- details.put("未知", unknownMap.get(item));
- }
- if (positiveMap.containsKey(item)) {
- details.put("阳性", positiveMap.get(item));
- }
- if (negativeMap.containsKey(item)) {
- details.put("阴性", negativeMap.get(item));
- }
- result.put(item, details);
- });
- return result;
- }
- private Map<String, Integer> sortByValue(Map<String, Integer> sourceMap) {
- if (sourceMap == null || sourceMap.isEmpty()) {
- return sourceMap;
- }
- Map<String, Integer> sortedMap = new LinkedHashMap<>();
- List<Map.Entry<String, Integer>> entryList = new ArrayList<>(sourceMap.entrySet());
- Collections.sort(entryList, new MapValueComparator());
- Iterator<Map.Entry<String, Integer>> iterator = entryList.iterator();
- while (iterator.hasNext()) {
- Map.Entry<String, Integer> tmpEntry = iterator.next();
- sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
- }
- return sortedMap;
- }
- class MapValueComparator implements Comparator<Map.Entry<String, Integer>> {
- @Override
- public int compare(Map.Entry<String, Integer> me1, Map.Entry<String, Integer> me2) {
- return - me1.getValue().compareTo(me2.getValue());
- }
- }
- }
|