|
@@ -11,11 +11,19 @@ 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.utils.AccessTokenUtil;
|
|
|
+import org.thyy.thirdpartapi.inspection.config.PatientNumType;
|
|
|
+import org.thyy.thirdpartapi.inspection.inspectionImpl.ThyyInspectionImpl;
|
|
|
+import org.thyy.thirdpartapi.inspection.request.jy.JyIndexRequest;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.jy.JyDetailItem;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.jy.JyDetailOrder;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.jy.JyDetailResponse;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.jy.JyIndexResponse;
|
|
|
import org.thyy.utils.exception.BizException;
|
|
|
import org.thyy.utils.exception.ExceptionEnum;
|
|
|
|
|
@@ -31,12 +39,16 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class DpccHttp {
|
|
|
private final Dpcc dpcc;
|
|
|
+ private final DpccDao dao;
|
|
|
private final RestTemplate restTemplate;
|
|
|
+ private final ThyyInspectionImpl inspectionImpl;
|
|
|
|
|
|
@Autowired
|
|
|
- public DpccHttp(Dpcc dpcc, RestTemplate restTemplate) {
|
|
|
+ public DpccHttp(Dpcc dpcc, DpccDao dao, RestTemplate restTemplate, ThyyInspectionImpl inspectionImpl) {
|
|
|
this.dpcc = dpcc;
|
|
|
+ this.dao = dao;
|
|
|
this.restTemplate = restTemplate;
|
|
|
+ this.inspectionImpl = inspectionImpl;
|
|
|
}
|
|
|
|
|
|
public void getToken() {
|
|
@@ -93,7 +105,6 @@ public class DpccHttp {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
private ReportIndexInquiry getReportIndexInquiry() {
|
|
|
String now = DateUtil.formatDate(new Date());
|
|
|
String start = now + " 00:00:00";
|
|
@@ -105,34 +116,36 @@ public class DpccHttp {
|
|
|
return inquiry;
|
|
|
}
|
|
|
|
|
|
- private void uploadInpatientCheck(List<Patient> inpatientList, ReportIndexInquiry inquiry) throws Exception {
|
|
|
- inquiry.setPatType("InPatient");
|
|
|
+ private void uploadInpatientCheck(List<Patient> inpatientList, ReportIndexInquiry inquiry) {
|
|
|
+ inquiry.setPatType(PatientNumType.InPatient);
|
|
|
for (Patient inpatient : inpatientList) {
|
|
|
queryCheckAndUpload(inquiry, inpatient);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void uploadOutpatientCheck(List<Patient> outpatientList, ReportIndexInquiry inquiry) throws Exception {
|
|
|
- inquiry.setPatType("OutPatient");
|
|
|
+ private void uploadOutpatientCheck(List<Patient> outpatientList, ReportIndexInquiry inquiry) {
|
|
|
+ inquiry.setPatType(PatientNumType.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);
|
|
|
+ return inspectionImpl.queryExamIndex(json);
|
|
|
}
|
|
|
|
|
|
- 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");
|
|
|
+ return inspectionImpl.queryExamDetail(json);
|
|
|
}
|
|
|
|
|
|
- private boolean reportTimeValid(ExamDetailOrder order) {
|
|
|
+ private boolean reportTimeValid(JyDetailOrder order) {
|
|
|
Date auditTime = DateUtil.parse(order.getAudtTime());
|
|
|
if (null == auditTime) {
|
|
|
return false;
|
|
@@ -142,19 +155,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 +186,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 +204,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 +223,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,20 +244,17 @@ 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) {
|
|
@@ -271,25 +281,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());
|
|
|
+ }
|
|
|
}
|
|
|
}
|