|
@@ -8,6 +8,7 @@ import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import thyyxxk.webserver.api.dpcc.model.MedicalCheckResult;
|
|
@@ -15,8 +16,6 @@ import thyyxxk.webserver.api.dpcc.model.MedicalPrescription;
|
|
|
import thyyxxk.webserver.api.dpcc.model.PatientInfo;
|
|
|
import thyyxxk.webserver.api.medicallaboratory.model.Category;
|
|
|
import thyyxxk.webserver.config.auth.PassToken;
|
|
|
-import thyyxxk.webserver.config.exception.BizException;
|
|
|
-import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.webserver.dao.his.api.DpccDao;
|
|
|
import thyyxxk.webserver.entity.examinations.inspections.request.PatType;
|
|
|
import thyyxxk.webserver.entity.examinations.inspections.request.ReportIndexInquiry;
|
|
@@ -34,66 +33,64 @@ import java.util.List;
|
|
|
@RequestMapping("/api/dpcc")
|
|
|
public class DpccController {
|
|
|
|
|
|
- private static final String TOKEN_URL = "https://dpcctest.sinocare.com/api/sino-auth/oauth/token";
|
|
|
- private static final String CHECK_URL = "https://dpcctest.sinocare.com/api/sino-common/access-client/uploadHisCheckData";
|
|
|
- private static final String DRUG_URL = "https://dpcctest.sinocare.com/api/sino-common/access-client/uploadHisDrugData";
|
|
|
+ private static final String TOKEN_URL = "https://manage.national-dpcc.com/api/sino-auth/oauth/token";
|
|
|
+ private static final String CHECK_URL = "https://manage.national-dpcc.com/api/sino-common/access-client/uploadHisCheckData";
|
|
|
+ private static final String DRUG_URL = "https://manage.national-dpcc.com/api/sino-common/access-client/uploadHisDrugData";
|
|
|
|
|
|
private final DpccDao dao;
|
|
|
|
|
|
- private String TOKEN = "eyJhbGciOiJIUzI1Ni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Token
|
|
|
- @GetMapping("/uploadHisData")
|
|
|
- public String uploadHisData() throws Exception {
|
|
|
- List<PatientInfo> inpatientList = dao.getInpatientList();
|
|
|
- List<PatientInfo> outpatientList = dao.getOutpatientList();
|
|
|
- if (inpatientList.isEmpty() && outpatientList.isEmpty()) {
|
|
|
- return "OK";
|
|
|
- }
|
|
|
-
|
|
|
-// this.TOKEN = getToken();
|
|
|
-// log.info("获取token: {}", this.TOKEN);
|
|
|
-
|
|
|
- ReportIndexInquiry inquiry = getReportIndexInquiry();
|
|
|
-
|
|
|
- uploadInpatientCheck(inpatientList, inquiry);
|
|
|
- uploadOutpatientCheck(outpatientList, inquiry);
|
|
|
-
|
|
|
- uploadInpatientDrug(inpatientList);
|
|
|
- uploadOutpatientDrug(outpatientList);
|
|
|
- return "OK";
|
|
|
- }
|
|
|
-
|
|
|
- private String getToken() {
|
|
|
- String clientName = "sino-client-szlh";
|
|
|
- String clientSecret = "sino-client-szlh";
|
|
|
+ @GetMapping("/getToken")
|
|
|
+ public String getToken() {
|
|
|
+ String clientName = "sino-client-csthyy";
|
|
|
+ String clientSecret = "sino-client-csthyy";
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setBasicAuth(clientName, clientSecret);
|
|
|
|
|
|
String url = TOKEN_URL + "?grant_type=access_client&" +
|
|
|
- "username=sino-client-szlh&password=888e90bbe7d0b1e64122aeece0820c77564a09ec";
|
|
|
+ "username=sino-client-csthyy&" +
|
|
|
+ "password=d60dc4bf4acfa8956cd6819dba6966d0dab1ddac";
|
|
|
|
|
|
JSONObject response = new RestTemplate().postForObject(url,
|
|
|
new HttpEntity<>(null, headers), JSONObject.class);
|
|
|
log.info("DPCC获取TOKEN:{}", response);
|
|
|
if (null == response) {
|
|
|
- throw new BizException(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ return "ERROR:NETWORK_ERROR";
|
|
|
}
|
|
|
Integer code = response.getInteger("code");
|
|
|
if (null == code) {
|
|
|
- throw new BizException(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ return "ERROR:NETWORK_ERROR";
|
|
|
}
|
|
|
if (code != 200) {
|
|
|
- throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR, response.getString("msg"));
|
|
|
+ return "ERROR:" + response.getString("msg");
|
|
|
}
|
|
|
return response.getJSONObject("data").getString("access_token");
|
|
|
}
|
|
|
|
|
|
+ @PassToken
|
|
|
+ @GetMapping("/uploadHisData")
|
|
|
+ public String uploadHisData(@RequestParam("token") String token) throws Exception {
|
|
|
+ List<PatientInfo> inpatientList = dao.getInpatientList();
|
|
|
+ List<PatientInfo> outpatientList = dao.getOutpatientList();
|
|
|
+ if (inpatientList.isEmpty() && outpatientList.isEmpty()) {
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+
|
|
|
+ ReportIndexInquiry inquiry = getReportIndexInquiry();
|
|
|
+
|
|
|
+ uploadInpatientCheck(inpatientList, inquiry, token);
|
|
|
+ uploadOutpatientCheck(outpatientList, inquiry, token);
|
|
|
+
|
|
|
+ uploadInpatientDrug(inpatientList, token);
|
|
|
+ uploadOutpatientDrug(outpatientList, token);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+
|
|
|
private ReportIndexInquiry getReportIndexInquiry() {
|
|
|
String now = DateUtil.formatDate(new Date());
|
|
|
String start = now + " 00:00:00";
|
|
@@ -105,17 +102,17 @@ public class DpccController {
|
|
|
return inquiry;
|
|
|
}
|
|
|
|
|
|
- private void uploadInpatientCheck(List<PatientInfo> inpatientList, ReportIndexInquiry inquiry) throws Exception {
|
|
|
+ private void uploadInpatientCheck(List<PatientInfo> inpatientList, ReportIndexInquiry inquiry, String token) throws Exception {
|
|
|
inquiry.setPatType(PatType.InPatient);
|
|
|
for (PatientInfo inpatient : inpatientList) {
|
|
|
- queryCheckAndUpload(inquiry, inpatient);
|
|
|
+ queryCheckAndUpload(inquiry, inpatient, token);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void uploadOutpatientCheck(List<PatientInfo> outpatientList, ReportIndexInquiry inquiry) throws Exception {
|
|
|
+ private void uploadOutpatientCheck(List<PatientInfo> outpatientList, ReportIndexInquiry inquiry, String token) throws Exception {
|
|
|
inquiry.setPatType(PatType.OutPatient);
|
|
|
for (PatientInfo outpatient : outpatientList) {
|
|
|
- queryCheckAndUpload(inquiry, outpatient);
|
|
|
+ queryCheckAndUpload(inquiry, outpatient, token);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -142,7 +139,7 @@ public class DpccController {
|
|
|
return diff / 1000 / 60 <= 600;
|
|
|
}
|
|
|
|
|
|
- private void queryCheckAndUpload(ReportIndexInquiry inquiry, PatientInfo patient) throws Exception {
|
|
|
+ private void queryCheckAndUpload(ReportIndexInquiry inquiry, PatientInfo patient, String token) throws Exception {
|
|
|
List<MedicalCheckResult> checkResultBatches = new ArrayList<>();
|
|
|
inquiry.setPatNo(patient.getPatNo());
|
|
|
List<ExamIndexResponse> indexList = getExamIndex(inquiry);
|
|
@@ -163,13 +160,13 @@ public class DpccController {
|
|
|
}
|
|
|
checkResultBatches.add(getMedicalCheckResult(patient, item));
|
|
|
if (checkResultBatches.size() == 100) {
|
|
|
- executeUploadChecks(checkResultBatches);
|
|
|
+ executeUploadChecks(checkResultBatches, token);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!checkResultBatches.isEmpty()) {
|
|
|
- executeUploadChecks(checkResultBatches);
|
|
|
+ executeUploadChecks(checkResultBatches, token);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -191,7 +188,7 @@ public class DpccController {
|
|
|
return checkResult;
|
|
|
}
|
|
|
|
|
|
- private void uploadInpatientDrug(List<PatientInfo> inpatientList) throws Exception {
|
|
|
+ private void uploadInpatientDrug(List<PatientInfo> inpatientList, String token) throws Exception {
|
|
|
List<MedicalPrescription> drugBatches = new ArrayList<>();
|
|
|
for (PatientInfo inpatient : inpatientList) {
|
|
|
List<MedicalPrescription> drugs = dao.getInpatientDrugs(inpatient);
|
|
@@ -199,17 +196,17 @@ public class DpccController {
|
|
|
item.setIdCard(inpatient.getIdCard());
|
|
|
drugBatches.add(item);
|
|
|
if (drugBatches.size() == 100) {
|
|
|
- executeUploadDrugs(drugBatches);
|
|
|
+ executeUploadDrugs(drugBatches, token);
|
|
|
drugBatches.clear();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!drugBatches.isEmpty()) {
|
|
|
- executeUploadDrugs(drugBatches);
|
|
|
+ executeUploadDrugs(drugBatches, token);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void uploadOutpatientDrug(List<PatientInfo> outpatientList) throws Exception {
|
|
|
+ private void uploadOutpatientDrug(List<PatientInfo> outpatientList, String token) throws Exception {
|
|
|
List<MedicalPrescription> drugBatches = new ArrayList<>();
|
|
|
for (PatientInfo outpatient : outpatientList) {
|
|
|
List<MedicalPrescription> drugs = dao.getOutpatientDrugs(outpatient);
|
|
@@ -217,33 +214,33 @@ public class DpccController {
|
|
|
item.setIdCard(outpatient.getIdCard());
|
|
|
drugBatches.add(item);
|
|
|
if (drugBatches.size() == 100) {
|
|
|
- executeUploadDrugs(drugBatches);
|
|
|
+ executeUploadDrugs(drugBatches, token);
|
|
|
drugBatches.clear();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!drugBatches.isEmpty()) {
|
|
|
- executeUploadDrugs(drugBatches);
|
|
|
+ executeUploadDrugs(drugBatches, token);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void executeUploadChecks(List<MedicalCheckResult> checkBatches) throws Exception {
|
|
|
+ private void executeUploadChecks(List<MedicalCheckResult> checkBatches, String token) throws Exception {
|
|
|
String json = JSON.toJSONString(checkBatches);
|
|
|
log.info("DPCC上传检验明文:{}", json);
|
|
|
- uploadToSino(DpccEncryptUtil.encrypt(json), Type.CHECK);
|
|
|
+ uploadToSino(DpccEncryptUtil.encrypt(json), Type.CHECK, token);
|
|
|
}
|
|
|
|
|
|
- private void executeUploadDrugs(List<MedicalPrescription> drugBatches) throws Exception {
|
|
|
+ private void executeUploadDrugs(List<MedicalPrescription> drugBatches, String token) throws Exception {
|
|
|
String json = JSON.toJSONString(drugBatches);
|
|
|
log.info("DPCC上传药品明文:{}", json);
|
|
|
- uploadToSino(DpccEncryptUtil.encrypt(json), Type.DRUG);
|
|
|
+ uploadToSino(DpccEncryptUtil.encrypt(json), Type.DRUG, token);
|
|
|
}
|
|
|
|
|
|
- private void uploadToSino(String encrypt, Type type) {
|
|
|
+ private void uploadToSino(String encrypt, Type type, String token) {
|
|
|
String url = type == Type.CHECK ? CHECK_URL : DRUG_URL;
|
|
|
String label = type == Type.CHECK ? "检验" : "药品";
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("Sino-auth", this.TOKEN);
|
|
|
+ headers.add("Sino-auth", token);
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("data", encrypt);
|
|
|
HttpEntity<JSONObject> body = new HttpEntity<>(data, headers);
|