|
|
package com.xkl.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.xkl.domain.AMPReport;
|
|
|
import com.xkl.domain.AMPReportDetail;
|
|
|
import com.xkl.domain.ReportData;
|
|
|
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.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by zhao yue on 2016/11/13.
|
|
|
*/
|
|
|
@Service
|
|
|
public class ReportService {
|
|
|
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>();
|
|
|
|
|
|
/*
|
|
|
1. 验证md5
|
|
|
3. 获取report
|
|
|
4. 获取detail
|
|
|
5. 评判detail
|
|
|
1. 验证member
|
|
|
2. 获取admin
|
|
|
验证md5
|
|
|
获取report
|
|
|
获取detail
|
|
|
评判detail
|
|
|
验证member
|
|
|
获取admin
|
|
|
*/
|
|
|
// 需要程喆增加 title,account字段,String,修改set字段为int,0男,1女。
|
|
|
// 需要程喆增加 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;
|
|
|
|
|
|
/*
|
|
|
* 获取report基础信息
|
|
|
* 2. 获取report基础信息
|
|
|
*/
|
|
|
try {
|
|
|
JSONObject rpJson = JSONObject.parseObject(reportJson);
|
|
|
sex = rpJson.getInteger("sex").intValue();
|
|
|
ampReport.setReport(rpJson.getString("name"),
|
|
|
rpJson.getString("title"),/// "AMP快速无创身心健康评估报告",
|
|
|
rpJson.getTimestamp("report_date"),
|
|
|
Timestamp.valueOf(rpJson.getString("report_date")),
|
|
|
new Timestamp(System.currentTimeMillis()),
|
|
|
rpJson.getString("account"),///
|
|
|
rpJson.getInteger("sex").intValue(),///
|
...
|
...
|
@@ -43,7 +59,7 @@ public class ReportService { |
|
|
rpJson.getInteger("weight").intValue(),
|
|
|
rpJson.getInteger("pulse").intValue(),
|
|
|
rpJson.getInteger("respiratory_rate").intValue(),
|
|
|
rpJson.getInteger("atmospheric_pressure").intValue(),
|
|
|
rpJson.getFloat("atmospheric_pressure").floatValue(),
|
|
|
rpJson.getFloat("LCA").floatValue(),
|
|
|
rpJson.getFloat("RCA").floatValue(),
|
|
|
rpJson.getFloat("LAC").floatValue(),
|
...
|
...
|
@@ -51,28 +67,77 @@ public class ReportService { |
|
|
rpJson.getFloat("ABD").floatValue(),
|
|
|
rpJson.getFloat("total").floatValue(),
|
|
|
rpJson.getInteger("stable").intValue(),
|
|
|
md5, rpJson.getString("basic_result"));
|
|
|
md5, rpJson.getString("machine_num"), rpJson.getString("basic_result"));
|
|
|
/*
|
|
|
* 获取detail信息
|
|
|
* 3. 获取detail信息,id,float类型
|
|
|
*/
|
|
|
JSONObject rpDetails = rpJson.getJSONObject("detail");
|
|
|
for (int item_id = 1; item_id <= 125; item_id++) {
|
|
|
String val = rpDetails.getString(String.valueOf(item_id));
|
|
|
if (val == null || val.equals("")) {
|
|
|
continue;
|
|
|
}
|
|
|
val = val.trim().replace(" ", "").replace("``", "").replace("`", ".");
|
|
|
float valFloat = Float.parseFloat(val);
|
|
|
float val = rpDetails.getFloat(String.valueOf(item_id)).floatValue();
|
|
|
AMPReportDetail detail = new AMPReportDetail();
|
|
|
detail.setItem_value(valFloat);
|
|
|
detail.setItem_id(item_id);
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|