|
|
@@ -11,13 +11,20 @@ import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.thyy.scheduled.config.constant.Dpcc;
|
|
|
+import org.thyy.scheduled.dao.DpccDao;
|
|
|
import org.thyy.scheduled.entity.dpcc.MedicalCheckResult;
|
|
|
import org.thyy.scheduled.entity.dpcc.MedicalPrescription;
|
|
|
import org.thyy.scheduled.entity.dpcc.Patient;
|
|
|
import org.thyy.scheduled.entity.dpcc.ReportIndexInquiry;
|
|
|
+import org.thyy.scheduled.entity.dpcc.jyreq.JyIndexRequest;
|
|
|
+import org.thyy.scheduled.entity.dpcc.jyrs.JyDetailItem;
|
|
|
+import org.thyy.scheduled.entity.dpcc.jyrs.JyDetailOrder;
|
|
|
+import org.thyy.scheduled.entity.dpcc.jyrs.JyDetailResponse;
|
|
|
+import org.thyy.scheduled.entity.dpcc.jyrs.JyIndexResponse;
|
|
|
import org.thyy.scheduled.utils.AccessTokenUtil;
|
|
|
import org.thyy.utils.exception.BizException;
|
|
|
import org.thyy.utils.exception.ExceptionEnum;
|
|
|
+import org.thyy.utils.result.ResultVo;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
@@ -29,13 +36,15 @@ import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class DpccHttp {
|
|
|
+public class DpccService {
|
|
|
private final Dpcc dpcc;
|
|
|
+ private final DpccDao dao;
|
|
|
private final RestTemplate restTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
- public DpccHttp(Dpcc dpcc, RestTemplate restTemplate) {
|
|
|
+ public DpccService(Dpcc dpcc, DpccDao dao, RestTemplate restTemplate) {
|
|
|
this.dpcc = dpcc;
|
|
|
+ this.dao = dao;
|
|
|
this.restTemplate = restTemplate;
|
|
|
}
|
|
|
|
|
|
@@ -75,11 +84,11 @@ public class DpccHttp {
|
|
|
uploadHisData();
|
|
|
}
|
|
|
|
|
|
- public String uploadHisData() {
|
|
|
+ public void uploadHisData() {
|
|
|
List<Patient> inpatientList = dao.getInpatientList();
|
|
|
List<Patient> outpatientList = dao.getOutpatientList();
|
|
|
if (inpatientList.isEmpty() && outpatientList.isEmpty()) {
|
|
|
- return "没有需要上传的数据。";
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
ReportIndexInquiry inquiry = getReportIndexInquiry();
|
|
|
@@ -89,11 +98,9 @@ public class DpccHttp {
|
|
|
|
|
|
uploadInpatientDrug(inpatientList);
|
|
|
uploadOutpatientDrug(outpatientList);
|
|
|
- return "OK";
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
private ReportIndexInquiry getReportIndexInquiry() {
|
|
|
String now = DateUtil.formatDate(new Date());
|
|
|
String start = now + " 00:00:00";
|
|
|
@@ -105,34 +112,46 @@ public class DpccHttp {
|
|
|
return inquiry;
|
|
|
}
|
|
|
|
|
|
- private void uploadInpatientCheck(List<Patient> inpatientList, ReportIndexInquiry inquiry) throws Exception {
|
|
|
+ private void uploadInpatientCheck(List<Patient> inpatientList, ReportIndexInquiry inquiry) {
|
|
|
inquiry.setPatType("InPatient");
|
|
|
for (Patient inpatient : inpatientList) {
|
|
|
queryCheckAndUpload(inquiry, inpatient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void uploadOutpatientCheck(List<Patient> outpatientList, ReportIndexInquiry inquiry) throws Exception {
|
|
|
+ private void uploadOutpatientCheck(List<Patient> outpatientList, ReportIndexInquiry inquiry) {
|
|
|
inquiry.setPatType("OutPatient");
|
|
|
for (Patient outpatient : outpatientList) {
|
|
|
queryCheckAndUpload(inquiry, outpatient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<ExamIndexResponse> getExamIndex(ReportIndexInquiry inquiry) {
|
|
|
- ExamIndexRequest request = new ExamIndexRequest.Builder()
|
|
|
+ private List<JyIndexResponse> getJyIndex(ReportIndexInquiry inquiry) {
|
|
|
+ JyIndexRequest request = new JyIndexRequest.Builder()
|
|
|
.patientNumType(inquiry.getPatType()).patientNum(inquiry.getPatNo())
|
|
|
.startDate(inquiry.getReqStartTime()).endDate(inquiry.getReqEndTime()).build();
|
|
|
- ExamReportService examReportService = new ExamReportService();
|
|
|
- return examReportService.queryExamIndex(request);
|
|
|
+ JSONObject json = JSONObject.from(request);
|
|
|
+ ResultVo<List<JyIndexResponse>> resultVo =
|
|
|
+ restTemplate.postForObject(dpcc.getJyApi() + "/queryExamIndex", json, ResultVo.class);
|
|
|
+ if (null == resultVo) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return resultVo.getData();
|
|
|
}
|
|
|
|
|
|
- private ExamDetailResponse getExamDetail(String reportId) {
|
|
|
- ExamReportService examReportService = new ExamReportService();
|
|
|
- return examReportService.queryExamDetail(reportId);
|
|
|
+ private JyDetailResponse getJyDetail(String reportId) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("reportId", reportId);
|
|
|
+ json.put("responseMode", "Json");
|
|
|
+ ResultVo<JyDetailResponse> resultVo =
|
|
|
+ restTemplate.postForObject(dpcc.getJyApi() + "/queryExamDetail", json, ResultVo.class);
|
|
|
+ if (null == resultVo) {
|
|
|
+ throw new BizException(ExceptionEnum.API_ERROR);
|
|
|
+ }
|
|
|
+ return resultVo.getData();
|
|
|
}
|
|
|
|
|
|
- private boolean reportTimeValid(ExamDetailOrder order) {
|
|
|
+ private boolean reportTimeValid(JyDetailOrder order) {
|
|
|
Date auditTime = DateUtil.parse(order.getAudtTime());
|
|
|
if (null == auditTime) {
|
|
|
return false;
|
|
|
@@ -142,19 +161,19 @@ public class DpccHttp {
|
|
|
return diff / 1000 / 60 / 60 <= 72;
|
|
|
}
|
|
|
|
|
|
- private void queryCheckAndUpload(ReportIndexInquiry inquiry, Patient patient) throws Exception {
|
|
|
+ private void queryCheckAndUpload(ReportIndexInquiry inquiry, Patient patient) {
|
|
|
List<MedicalCheckResult> checkResultBatches = new ArrayList<>();
|
|
|
inquiry.setPatNo(patient.getPatNo());
|
|
|
- List<ExamIndexResponse> indexList = getExamIndex(inquiry);
|
|
|
- for (ExamIndexResponse index : indexList) {
|
|
|
- ExamDetailResponse detail = getExamDetail(index.getReportId());
|
|
|
+ List<JyIndexResponse> indexList = getJyIndex(inquiry);
|
|
|
+ for (JyIndexResponse index : indexList) {
|
|
|
+ JyDetailResponse detail = getJyDetail(index.getReportId());
|
|
|
if (reportTimeValid(detail.getOrder())) {
|
|
|
patient.setReportId(index.getReportId());
|
|
|
patient.setInspectTime(detail.getOrder().getInspectTime());
|
|
|
if (StrUtil.isBlank(patient.getInspectTime())) {
|
|
|
patient.setInspectTime(detail.getOrder().getAudtTime());
|
|
|
}
|
|
|
- for (ExamDetailItem item : detail.getItems()) {
|
|
|
+ for (JyDetailItem item : detail.getItems()) {
|
|
|
if (StrUtil.isBlank(item.getItmUnit())) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -173,7 +192,7 @@ public class DpccHttp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private MedicalCheckResult getMedicalCheckResult(Patient patient, ExamDetailItem item) {
|
|
|
+ private MedicalCheckResult getMedicalCheckResult(Patient patient, JyDetailItem item) {
|
|
|
MedicalCheckResult checkResult = new MedicalCheckResult();
|
|
|
checkResult.setSource(patient.getSource());
|
|
|
checkResult.setIdCard(patient.getIdCard());
|
|
|
@@ -191,7 +210,7 @@ public class DpccHttp {
|
|
|
return checkResult;
|
|
|
}
|
|
|
|
|
|
- private void uploadInpatientDrug(List<Patient> inpatientList) throws Exception {
|
|
|
+ private void uploadInpatientDrug(List<Patient> inpatientList) {
|
|
|
List<MedicalPrescription> drugBatches = new ArrayList<>();
|
|
|
for (Patient inpatient : inpatientList) {
|
|
|
String patNo = inpatient.getPatNo();
|
|
|
@@ -210,7 +229,7 @@ public class DpccHttp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void uploadOutpatientDrug(List<Patient> outpatientList) throws Exception {
|
|
|
+ private void uploadOutpatientDrug(List<Patient> outpatientList) {
|
|
|
for (Patient outpatient : outpatientList) {
|
|
|
String patNo = outpatient.getPatNo();
|
|
|
int times = outpatient.getTimes();
|
|
|
@@ -231,23 +250,20 @@ public class DpccHttp {
|
|
|
}
|
|
|
|
|
|
private void executeUploadChecks(List<MedicalCheckResult> checkBatches,
|
|
|
- String patNo, int times) throws Exception {
|
|
|
+ String patNo, int times) {
|
|
|
String json = JSON.toJSONString(checkBatches);
|
|
|
log.info("DPCC上传检验:{}, {}", patNo, times);
|
|
|
uploadToSino(encrypt(json), Type.CHECK);
|
|
|
}
|
|
|
|
|
|
private void executeUploadDrugs(List<MedicalPrescription> drugBatches,
|
|
|
- String patNo, int times) throws Exception {
|
|
|
+ String patNo, int times) {
|
|
|
String json = JSON.toJSONString(drugBatches);
|
|
|
log.info("DPCC上传药品:{}, {}", patNo, times);
|
|
|
- int res = uploadToSino(encrypt(json), Type.DRUG);
|
|
|
- if (res == 200 && times != -1) {
|
|
|
- dao.updateDpccFlag(patNo, times);
|
|
|
- }
|
|
|
+ uploadToSino(encrypt(json), Type.DRUG);
|
|
|
}
|
|
|
|
|
|
- private int uploadToSino(String encrypt, Type type) {
|
|
|
+ private void uploadToSino(String encrypt, Type type) {
|
|
|
String url = type == Type.CHECK ? dpcc.getCheckUrl() : dpcc.getDrugUrl();
|
|
|
String label = type == Type.CHECK ? "检验" : "药品";
|
|
|
String dpccToken = AccessTokenUtil.getInstance().get("dpccToken");
|
|
|
@@ -258,12 +274,10 @@ public class DpccHttp {
|
|
|
HttpEntity<JSONObject> body = new HttpEntity<>(data, headers);
|
|
|
String response = new RestTemplate().postForObject(url, body, String.class);
|
|
|
log.info("DPCC上传{}返回:{}", label, response);
|
|
|
- if (StrUtil.isNotBlank(response)) {
|
|
|
- JSONObject json = JSON.parseObject(response);
|
|
|
- Integer code = json.getInteger("code");
|
|
|
- return null == code ? -1 : code;
|
|
|
- }
|
|
|
- return -1;
|
|
|
+// if (StrUtil.isNotBlank(response)) {
|
|
|
+// JSONObject json = JSON.parseObject(response);
|
|
|
+// Integer code = json.getInteger("code");
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
enum Type {
|
|
|
@@ -271,25 +285,31 @@ public class DpccHttp {
|
|
|
DRUG,
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private String encrypt(String plainText) throws Exception {
|
|
|
+ private String encrypt(String plainText) {
|
|
|
byte[] keyBytes = dpcc.getEncryptKey().getBytes(StandardCharsets.UTF_8);
|
|
|
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
|
|
|
- Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
- cipher.init(Cipher.ENCRYPT_MODE, keySpec);
|
|
|
- byte[] plainTextBytes = plainText.getBytes(StandardCharsets.UTF_8);
|
|
|
- byte[] cipherTextBytes = cipher.doFinal(plainTextBytes);
|
|
|
- return Base64.getEncoder().encodeToString(cipherTextBytes);
|
|
|
+ try {
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
+ cipher.init(Cipher.ENCRYPT_MODE, keySpec);
|
|
|
+ byte[] plainTextBytes = plainText.getBytes(StandardCharsets.UTF_8);
|
|
|
+ byte[] cipherTextBytes = cipher.doFinal(plainTextBytes);
|
|
|
+ return Base64.getEncoder().encodeToString(cipherTextBytes);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private String decrypt(String cipherTextBase64) throws Exception {
|
|
|
+ private String decrypt(String cipherTextBase64) {
|
|
|
byte[] keyBytes = dpcc.getEncryptKey().getBytes(StandardCharsets.UTF_8);
|
|
|
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
|
|
|
- Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
- cipher.init(Cipher.DECRYPT_MODE, keySpec);
|
|
|
- byte[] cipherTextBytes = Base64.getDecoder().decode(cipherTextBase64);
|
|
|
- byte[] plainTextBytes = cipher.doFinal(cipherTextBytes);
|
|
|
- return new String(plainTextBytes, StandardCharsets.UTF_8);
|
|
|
+ try {
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, keySpec);
|
|
|
+ byte[] cipherTextBytes = Base64.getDecoder().decode(cipherTextBase64);
|
|
|
+ byte[] plainTextBytes = cipher.doFinal(cipherTextBytes);
|
|
|
+ return new String(plainTextBytes, StandardCharsets.UTF_8);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|