ReportService.java
5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.xkl.service;
import com.alibaba.fastjson.JSONObject;
import com.xkl.config.Constants;
import com.xkl.domain.*;
import com.xkl.repository.ReportDetailRepository;
import com.xkl.repository.ReportMetaItemsRepository;
import com.xkl.repository.ReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.*;
/**
* Created by zhao yue on 2016/11/13.
*/
@Service
public class ReportService implements IReportService {
@Autowired
private ReportMetaItemsRepository reportMetaItemsRepository;
@Autowired
private ReportRepository reportRepository;
@Autowired
private ReportDetailRepository reportDetailRepository;
private static Map<Integer, ReportMetaItem> rpMetaItemMap = new HashMap<Integer, ReportMetaItem>();
/*
验证md5
获取report
获取detail
评判detail
验证member
获取admin
*/
// 需要程喆增加 title,account,machine_num字段 String; 修改set字段为int,0男,1女。
// 125项目,改为float类型。
public ReportData parseReport(String reportJson, String md5) {
ReportData reportData = new ReportData();
AMPReport ampReport = new AMPReport();
List<AMPReportDetail> detailList = new ArrayList<>();
int sex;
/*
* 2. 获取report基础信息
*/
try {
JSONObject rpJson = JSONObject.parseObject(reportJson);
sex = rpJson.getInteger("sex").intValue();
ampReport.setReport(rpJson.getString("name"),
rpJson.getString("title"),/// "AMP快速无创身心健康评估报告",
Timestamp.valueOf(rpJson.getString("report_date")),
new Timestamp(System.currentTimeMillis()),
rpJson.getString("account"),///
rpJson.getInteger("sex").intValue(),///
rpJson.getInteger("age").intValue(),
rpJson.getInteger("weight").intValue(),
rpJson.getInteger("pulse").intValue(),
rpJson.getInteger("respiratory_rate").intValue(),
rpJson.getFloat("atmospheric_pressure").floatValue(),
rpJson.getFloat("LCA").floatValue(),
rpJson.getFloat("RCA").floatValue(),
rpJson.getFloat("LAC").floatValue(),
rpJson.getFloat("RAC").floatValue(),
rpJson.getFloat("ABD").floatValue(),
rpJson.getFloat("total").floatValue(),
rpJson.getInteger("stable").intValue(),
md5, rpJson.getString("machine_num"), rpJson.getString("basic_result"));
/*
* 3. 获取detail信息,id,float类型
*/
JSONObject rpDetails = rpJson.getJSONObject("detail");
for (int item_id = 1; item_id <= 125; item_id++) {
float val = rpDetails.getFloat(String.valueOf(item_id)).floatValue();
AMPReportDetail detail = new AMPReportDetail();
detail.setItemValue(val);
detail.setItemId(item_id);
detailList.add(detail);
}
} catch (Exception e) {
return null;
}
markItemStatus(sex, detailList);
reportData.setAmpReport(ampReport);
reportData.setRpDetailList(detailList);
return reportData;
}
/*
* 存储报告
*/
public int saveReport(ReportData report, Admin admin, User user) {
report.getAmpReport().setCreate_by((int) admin.getId());
report.getAmpReport().setCompany_id(admin.getCoid());
report.getAmpReport().setMember_id(user.getMemberId());
AMPReport ampReport = reportRepository.save(report.getAmpReport());
for (AMPReportDetail detail : report.getRpDetailList()) {
detail.setReportId(ampReport.getId());
}
reportDetailRepository.save(report.getRpDetailList());
return ampReport.getId();
}
/*
* 判断detail是正常,高于标准或低于标准。
*/
private void markItemStatus(int sex, List<AMPReportDetail> detailList) {
// load ReportMetaItems into memory.
synchronized (this) {
if (rpMetaItemMap.size() == 0) {
Iterator<ReportMetaItem> rpMetaIter = reportMetaItemsRepository.findAll().iterator();
while (rpMetaIter.hasNext()) {
ReportMetaItem rpMetaItem = rpMetaIter.next();
rpMetaItemMap.put(rpMetaItem.getItem_id(), rpMetaItem);
}
}
}
// mark status
for (AMPReportDetail detail : detailList) {
float lowSt;
float highSt;
// get standard
if (sex == Constants.MALE) { // male
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_male();
highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_male();
} else { // female
lowSt = rpMetaItemMap.get(detail.getItemId()).getStandard_low_female();
highSt = rpMetaItemMap.get(detail.getItemId()).getStandard_high_female();
}
int status;
if (detail.getItemValue() < lowSt) {
status = Constants.LOWER;
} else if (detail.getItemValue() > highSt) {
status = Constants.HIGHER;
} else {
status = Constants.NORMAL;
}
detail.setStatus(status);
}
}
}