Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/SyncOrgUnitAndUserDaoImpl.java
===================================================================
diff -u -r36473 -r39408
--- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/SyncOrgUnitAndUserDaoImpl.java (.../SyncOrgUnitAndUserDaoImpl.java) (revision 36473)
+++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/SyncOrgUnitAndUserDaoImpl.java (.../SyncOrgUnitAndUserDaoImpl.java) (revision 39408)
@@ -34,8 +34,8 @@
String inputXml = WebServiceClientHelper.buildInputStr(DatasyncConstant.ACTION_USER_INFO_QUERY, null, null);
logger.info("人员同步接口请求信息:" + inputXml);
String result = WebServiceClientHelper.axisInvokeWebservice(DatasyncConstant.WebserviceAddress, DatasyncConstant.targetNamespace, DatasyncConstant.soapAction, DatasyncConstant.method, DatasyncConstant.paramName, inputXml, "utf-8");
+ //String result = "0C7202023072020230720";
logger.info("人员同步接口返回信息:" + result);
- //String result = "0C7202023072020230720;"
int startIndex = result.indexOf("");
if(startIndex == -1){
return null;
@@ -105,8 +105,8 @@
String inputXml = WebServiceClientHelper.buildInputStr(DatasyncConstant.ACTION_ORGUNIT_INFO_QUERY, null, null);
logger.info("科室同步接口请求信息:" + inputXml);
String result = WebServiceClientHelper.axisInvokeWebservice(DatasyncConstant.WebserviceAddress, DatasyncConstant.targetNamespace, DatasyncConstant.soapAction, DatasyncConstant.method, DatasyncConstant.paramName, inputXml, "utf-8");
+ //String result = "0202307204009H20230720测试科室]]>";
logger.info("科室同步接口返回信息:" + result);
- //String result = " 0202307204009H20230720测试科室]]>;"
int startIndex = result.indexOf("");
if(startIndex == -1){
return null;
Index: forgon-core/src/main/java/com/forgon/directory/service/OrgUnitManagerImpl.java
===================================================================
diff -u -r39029 -r39408
--- forgon-core/src/main/java/com/forgon/directory/service/OrgUnitManagerImpl.java (.../OrgUnitManagerImpl.java) (revision 39029)
+++ forgon-core/src/main/java/com/forgon/directory/service/OrgUnitManagerImpl.java (.../OrgUnitManagerImpl.java) (revision 39408)
@@ -2902,4 +2902,43 @@
}
return values;
}
+
+ @Override
+ public Map loadOrgUnitCodingNameMapForSync(Set orgUnitCodeSet) {
+ Map orgOrgUnitCodingNameMap = new HashMap();
+ if(CollectionUtils.isEmpty(orgUnitCodeSet)){
+ return orgOrgUnitCodingNameMap;
+ }
+
+ StringBuffer sql = new StringBuffer();
+ boolean enableThirdPartyDepartmentCoding = ConfigUtils.getSystemSetConfigByNameBool("enableThirdPartyDepartmentCoding", false);
+ if(enableThirdPartyDepartmentCoding){
+ sql.append("select po.orgForeignKey code, po.name from ");
+ sql.append(OrgUnit.class.getSimpleName());
+ sql.append(" po where ");
+ sql.append(SqlUtils.getStringFieldInLargeCollectionsPredicate("po.orgForeignKey", orgUnitCodeSet));
+ }else{
+ sql.append("select po.orgUnitCoding code, po.name from ");
+ sql.append(OrgUnit.class.getSimpleName());
+ sql.append(" po where ");
+ sql.append(SqlUtils.getStringFieldInLargeCollectionsPredicate("po.orgUnitCoding", orgUnitCodeSet));
+ }
+
+ ResultSet rs = objectDao.executeSql(sql.toString());
+ if(rs != null){
+ try{
+ while(rs.next()){
+ String orgUnitCoding = rs.getString("code");
+ String name = rs.getString("name");
+ orgOrgUnitCodingNameMap.put(orgUnitCoding, name);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ DatabaseUtil.closeResultSetAndStatement(rs);
+ }
+ }
+
+ return orgOrgUnitCodingNameMap;
+ }
}
Index: forgon-core/src/main/java/com/forgon/directory/service/OrgUnitManager.java
===================================================================
diff -u -r39029 -r39408
--- forgon-core/src/main/java/com/forgon/directory/service/OrgUnitManager.java (.../OrgUnitManager.java) (revision 39029)
+++ forgon-core/src/main/java/com/forgon/directory/service/OrgUnitManager.java (.../OrgUnitManager.java) (revision 39408)
@@ -371,6 +371,13 @@
public Map loadOrgForeignKeyOrgUnitCodingMap(Set orgForeignKeySet);
/**
+ * 根据第三方平台传的科室编码,查询科室编码
+ * @param orgUnitCodeSet
+ * @return
+ */
+ public Map loadOrgUnitCodingNameMapForSync(Set orgUnitCodeSet);
+
+ /**
* 获取供应室和供应室服务科室
* @param cssdDepartCode 供应室编码 为空则查询所有服务科室 不为空 则查询指定供应室的服务科室
* @param showDisabled 显示停用科室
Index: ssts-web/src/main/webapp/disinfectsystem/config/bj309yy/spring/HIS.xml
===================================================================
diff -u -r36476 -r39408
--- ssts-web/src/main/webapp/disinfectsystem/config/bj309yy/spring/HIS.xml (.../HIS.xml) (revision 36476)
+++ ssts-web/src/main/webapp/disinfectsystem/config/bj309yy/spring/HIS.xml (.../HIS.xml) (revision 39408)
@@ -46,10 +46,37 @@
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
orgForeignKeyOrgUnitCodingMap = orgUnitManager.loadOrgForeignKeyOrgUnitCodingMap(orgUnitCodeSet);
+ Map orgForeignKeyOrgUnitCodingMap = orgUnitManager.loadOrgUnitCodingNameMapForSync(orgUnitCodeSet);
for (UserVo vo : allVos) {
if(StringUtils.isNotBlank(vo.getOrgUnitCoding())){
if(!orgForeignKeyOrgUnitCodingMap.containsKey(vo.getOrgUnitCoding())){
Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/FindPatientInfoByHospitalNumHiHisDaoImpl.java
===================================================================
diff -u
--- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/FindPatientInfoByHospitalNumHiHisDaoImpl.java (revision 0)
+++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/FindPatientInfoByHospitalNumHiHisDaoImpl.java (revision 39408)
@@ -0,0 +1,351 @@
+package com.forgon.disinfectsystem.datasynchronization.dao.bj309yy;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Node;
+import org.dom4j.XPath;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.forgon.disinfectsystem.datasynchronization.dao.FindPatientInfoByHospitalNumDao;
+import com.forgon.disinfectsystem.datasynchronization.model.PatientInfoVO;
+
+public class FindPatientInfoByHospitalNumHiHisDaoImpl implements FindPatientInfoByHospitalNumDao {
+
+ Logger logger = Logger.getLogger(this.getClass());
+
+ @Autowired
+ private HisInterfaceConfiguration hisInterfaceConfiguration;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public PatientInfoVO[] findPatientInfoByHospitalNum(String hospitalNum) {
+ try {
+ String inputXml = WebServiceClientHelper.buildHihisInputStr(hisInterfaceConfiguration, DatasyncConstant.hihisQueryOperationInfoService, hospitalNum);
+ logger.info("住院病人信息同步接口请求信息:" + inputXml);
+ String result = WebServiceClientHelper.doPostSoap1_2(hisInterfaceConfiguration.getWebserviceAddress(), inputXml);
+ /*String result = ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "true"
+ + ""
+ + "200
"
+ + ""
+ + ""
+ + ""
+ + "24123100003"
+ + "1001Q110000000V8WS2Q"
+ + "H70214372"
+ + "676faa01a073180015e02134"
+ + "114"
+ + "住院"
+ + ""
+ + "5"
+ + "11"
+ + "身份证"
+ + "370785198903290371"
+ + "刘力铭"
+ + "LLM"
+ + "1"
+ + "男"
+ + "1989-03-29 00:00:00"
+ + "35"
+ + "15812457845"
+ + ""
+ + "北京市 市辖区 海淀区 碧山镇前村"
+ + "BM000004"
+ + "手术室"
+ + ""
+ + ""
+ + "2024-12-31 11:06:17"
+ + ""
+ + ""
+ + ""
+ + "670667071b99280001d0005f"
+ + "测试科室"
+ + "1001A210000000UX5S6X"
+ + "脂肪瘤切除术1"
+ + "5d439a9eb7cef01a3ce401cb"
+ + "3"
+ + ""
+ + "A13122946000000000906291"
+ + "麻醉科"
+ + "0002"
+ + "内分泌测试医生"
+ + "2024-12-31 11:03:08"
+ + "5becdfa2e6387817ac9e0dfd"
+ + "1"
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "洗手护士"
+ + ""
+ + "巡回护士"
+ + ""
+ + ""
+ + "毒蛇咬伤"
+ + ""
+ + ""
+ + ""
+ + ""
+ + "0"
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "BM000003"
+ + "012"
+ + "1"
+ + "3"
+ + "5025"
+ + "1"
+ + ""
+ + ""
+ + ""
+ + ""
+ + "手术间号1"
+ + ""
+ + ""
+ + ""
+ + "24123100003"
+ + "1001Q110000000V8WS2Q"
+ + "H70214372"
+ + "676faa01a073180015e02134"
+ + "114"
+ + "住院"
+ + ""
+ + "5"
+ + "11"
+ + "身份证"
+ + "370785198903290371"
+ + "刘力铭"
+ + "LLM"
+ + "1"
+ + "男"
+ + "1989-03-29 00:00:00"
+ + "35"
+ + "15812457845"
+ + ""
+ + "北京市 市辖区 海淀区 碧山镇前村"
+ + "BM000004"
+ + "手术室"
+ + ""
+ + ""
+ + "2025-01-05 11:06:17"
+ + ""
+ + ""
+ + ""
+ + "670667071b99280001d0005f"
+ + "测试科室"
+ + "1001A210000000UX5S6X"
+ + "脂肪瘤切除术2"
+ + "5d439a9eb7cef01a3ce401cb"
+ + "3"
+ + ""
+ + "A13122946000000000906291"
+ + "麻醉科"
+ + "0002"
+ + "内分泌测试医生"
+ + "2024-12-31 11:03:08"
+ + "5becdfa2e6387817ac9e0dfd"
+ + "1"
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "洗手护士"
+ + ""
+ + "巡回护士"
+ + ""
+ + ""
+ + "毒蛇咬伤"
+ + ""
+ + ""
+ + ""
+ + ""
+ + "0"
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "BM000003"
+ + "012"
+ + "1"
+ + "3"
+ + "5025"
+ + "1"
+ + ""
+ + ""
+ + ""
+ + ""
+ + "手术间号2"
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "";*/
+ logger.info("病人信息同步接口返回信息:" + result);
+ int startIndex = result.indexOf("");
+ if(startIndex == -1){
+ logger.info("住院病人接口返回信息没有标签!");
+ return null;
+ }
+ int endIndex = result.indexOf("");
+ if(endIndex == -1 || endIndex < startIndex){
+ logger.info("住院病人接口返回信息没有标签");
+ return null;
+ }
+ String xmlString = result.substring(startIndex + "".length(), endIndex);
+ if(StringUtils.isBlank(xmlString)){
+ logger.info("住院病人接口返回信息为空!" + xmlString);
+ return null;
+ }
+ xmlString = "" + xmlString + "";
+ Document document = DocumentHelper.parseText(xmlString);
+ // 查询结果
+ String resultCodeXpath = "/BSXml/MsgBody/Code";
+ String resultCotentXpath = "/BSXml/MsgBody/Detail";
+ String resultCode = WebServiceClientHelper.processDataByXpath(document, resultCodeXpath);
+ String resultCotent = WebServiceClientHelper.processDataByXpath(document, resultCotentXpath);
+ logger.info("住院病人接口返回响应代码=" + resultCode + ",响应描述=" + resultCotent);
+ String itemXpath = "/BSXml/MsgBody/Data/SurgeryOrderList/SurgeryOrder"; // 返回结果可能存在多条住院病人信息
+ XPath xpath = document.createXPath(itemXpath);
+ List nodeList = xpath.selectNodes(document, xpath);
+ if(CollectionUtils.isEmpty(nodeList)){
+ logger.info("住院病人接口返回信息为空!" + xmlString);
+ return null;
+ }
+ List patientInfoVOList = new ArrayList();
+ for (int i = 1; i <= nodeList.size(); i++) {
+ String msgXpath = itemXpath + "[" + i + "]";
+ // 手术单号
+ String operationScheduleIdXpath = msgXpath + "/applyNo";
+ // 住院号
+ String hospitalNumberXpath = msgXpath + "/caseNo";
+ //住院次数
+ String visitIdXpath = msgXpath + "/hospitalizationTime";
+ //身份证
+ String patientIDCardXpath = msgXpath + "/certificateNo";
+ // 病人姓名
+ String patientNameXpath = msgXpath + "/name";
+ // 病人性别
+ String patientSexXpath = msgXpath + "/sexName";
+ // 病人年龄
+ String patientAgeXpath = msgXpath + "/age";
+ // 所属科室
+ String ascriptionDepartmentXpath = msgXpath + "/patientWardName";
+ // 手术名称
+ String operationXpath = msgXpath + "/surgeryServiceItemName";
+ // 医生姓名
+ String doctorNameXpath = msgXpath + "/surgeonName";
+ // 手术时间
+ String operationTimeXpath = msgXpath + "/surgeryConfirmTime";
+ //洗手护士
+ String washHandNurseXpath = msgXpath + "/washHandNurseName";
+ //巡回护士
+ String circuitNurseXpath = msgXpath + "/circuitNurseName";
+ //手术间号
+ String opRoomIdXpath = msgXpath + "/OperatingRoomNo";
+
+ String operationScheduleId = WebServiceClientHelper.processDataByXpath(document, operationScheduleIdXpath);
+ String hospitalNumber = WebServiceClientHelper.processDataByXpath(document, hospitalNumberXpath);
+ String visitIdStr = WebServiceClientHelper.processDataByXpath(document, visitIdXpath);
+ Long visitId = null;
+ try {
+ visitId = Long.valueOf(visitIdStr);
+ } catch (Exception e) {
+ }
+ String patientIDCard = WebServiceClientHelper.processDataByXpath(document, patientIDCardXpath);
+
+ String patientName = WebServiceClientHelper.processDataByXpath(document, patientNameXpath);
+ String patientSex = WebServiceClientHelper.processDataByXpath(document, patientSexXpath);
+ String patientAge = WebServiceClientHelper.processDataByXpath(document, patientAgeXpath);
+ String ascriptionDepartment = WebServiceClientHelper.processDataByXpath(document, ascriptionDepartmentXpath);
+
+ String operation = WebServiceClientHelper.processDataByXpath(document, operationXpath);
+ String doctorName = WebServiceClientHelper.processDataByXpath(document, doctorNameXpath);
+ String operationTime = WebServiceClientHelper.processDataByXpath(document, operationTimeXpath);
+ String washHandNurse = WebServiceClientHelper.processDataByXpath(document, washHandNurseXpath);
+
+ String circuitNurse = WebServiceClientHelper.processDataByXpath(document, circuitNurseXpath);
+ String opRoomId = WebServiceClientHelper.processDataByXpath(document, opRoomIdXpath);
+
+ PatientInfoVO patientInfoVO = new PatientInfoVO();
+ patientInfoVO.setOperationScheduleId(operationScheduleId);
+ patientInfoVO.setHospitalNumber(hospitalNumber);
+ patientInfoVO.setVisitId(visitId);
+ patientInfoVO.setPatientIDCard(patientIDCard);
+
+ patientInfoVO.setPatientName(patientName);
+ patientInfoVO.setPatientSex(patientSex);
+ patientInfoVO.setPatientAge(patientAge);
+ patientInfoVO.setAscriptionDepartment(ascriptionDepartment);
+
+ patientInfoVO.setOperation(operation);
+ patientInfoVO.setDoctorName(doctorName);
+ patientInfoVO.setOperationTime(operationTime);
+ patientInfoVO.setWashHandNurse(washHandNurse);
+
+ patientInfoVO.setCircuitNurse(circuitNurse);
+ patientInfoVO.setOpRoomId(opRoomId);
+
+ patientInfoVOList.add(patientInfoVO);
+ }
+ if (CollectionUtils.isNotEmpty(patientInfoVOList)) {
+ // 根据记录手术时间operationTime排序,只取最新记录
+ patientInfoVOList.sort(new Comparator() {
+ @Override
+ public int compare(PatientInfoVO o1, PatientInfoVO o2) {
+ if (StringUtils.isBlank(o1.getOperationTime()) && StringUtils.isNotBlank(o2.getOperationTime())) {
+ return 1;
+ }
+ if (StringUtils.isBlank(o2.getOperationTime()) && StringUtils.isNotBlank(o1.getOperationTime())) {
+ return -1;
+ }
+ return o2.getOperationTime().compareTo(o1.getOperationTime());
+ }
+ });
+ logger.debug("完成住院病人信息解析,病人住院号为:" + hospitalNum);
+ PatientInfoVO[] patientInfoArray = new PatientInfoVO[patientInfoVOList.size()];
+ for(int i=0;i");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+
+ reqBuffer.append("" + hihisService + "");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("3.0");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("3.0");
+ reqBuffer.append("" + hisInterfaceConfiguration.getVisitOrganization() + "");
+ reqBuffer.append("" + hisInterfaceConfiguration.getVisitBdmd() + "");
+ reqBuffer.append("" + hisInterfaceConfiguration.getVisitTenant() + "");
+ reqBuffer.append("" + hisInterfaceConfiguration.getVisitUser() + "");
+ reqBuffer.append("" + hisInterfaceConfiguration.getVisitDept() + "");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ if(StringUtils.equals(hihisService, DatasyncConstant.hihisQueryOperationInfoService)){
+ reqBuffer.append("");
+ reqBuffer.append("" + hisInterfaceConfiguration.getOrganizationId() + "");
+ reqBuffer.append("" + hisInterfaceConfiguration.getTenantId() + "");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("" + hospitalNum + "");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ //reqBuffer.append("20");
+ //reqBuffer.append("1");
+ reqBuffer.append("");
+ } else if(StringUtils.equals(hihisService, DatasyncConstant.hihisQueryDepartmentsService)){
+ reqBuffer.append("" + hisInterfaceConfiguration.getOrganizationId() + "");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("" + pageIndex + "");
+ reqBuffer.append("" + pageSize + "");
+ } else if(StringUtils.equals(hihisService, DatasyncConstant.hihisQueryDoctorsService)){
+ reqBuffer.append("" + hisInterfaceConfiguration.getOrganizationId() + "");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("1");
+ reqBuffer.append("" + pageIndex + "");
+ reqBuffer.append("" + pageSize + "");
+ } else {
+ throw new SystemException("不支持的服务标识:" + hihisService);
+ }
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("]]>");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ reqBuffer.append("");
+ return reqBuffer.toString();
+ }
+
+ /**
+ * 使用SOAP1.2发送消息
+ * @param postUrl
+ * @param soapXml
+ * @param soapAction
+ * @return
+ */
+ public static String doPostSoap1_2(String postUrl, String soapXml) {
+ String retStr = "";
+ // 创建HttpClientBuilder
+ HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
+ // HttpClient
+ CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
+ HttpPost httpPost = new HttpPost(postUrl);
+ // 设置请求和传输超时时间
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setSocketTimeout(100000)
+ .setConnectTimeout(100000).build();
+ httpPost.setConfig(requestConfig);
+ try {
+ httpPost.setHeader("Content-Type", "text/xml; charset=utf-8");
+ httpPost.setHeader("SOAPAction", "");
+ StringEntity data = new StringEntity(soapXml,Charset.forName("UTF-8"));
+ httpPost.setEntity(data);
+ CloseableHttpResponse response = closeableHttpClient.execute(httpPost);
+ HttpEntity httpEntity = response.getEntity();
+ if (httpEntity != null) {
+ // 打印响应内容
+ retStr = EntityUtils.toString(httpEntity, "UTF-8");
+ retStr = retStr.replaceAll("<", "<");
+ retStr = retStr.replaceAll(">", ">");
+ }
+ // 释放资源
+ closeableHttpClient.close();
+ } catch (Exception e) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(baos));
+ String exception = baos.toString();
+ logger.info("exception in doPostSoap1_2:" + exception);
+ }
+ return retStr;
+ }
+
}
Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/SyncOrgUnitAndUserHiHisDaoImpl.java
===================================================================
diff -u
--- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/SyncOrgUnitAndUserHiHisDaoImpl.java (revision 0)
+++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/bj309yy/SyncOrgUnitAndUserHiHisDaoImpl.java (revision 39408)
@@ -0,0 +1,395 @@
+package com.forgon.disinfectsystem.datasynchronization.dao.bj309yy;
+
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.json.JSONObject;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Node;
+import org.dom4j.XPath;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.forgon.directory.service.OrgUnitManager;
+import com.forgon.disinfectsystem.datasynchronization.dao.SyncOrgUnitAndUserDao;
+import com.forgon.disinfectsystem.datasynchronization.model.OrgUnitVo;
+import com.forgon.disinfectsystem.datasynchronization.model.UserVo;
+import com.forgon.tools.string.StringTools;
+
+/**
+ * 查询科室与人员信息(北京309医院)
+ * BJ309YY-35
+ */
+public class SyncOrgUnitAndUserHiHisDaoImpl implements SyncOrgUnitAndUserDao {
+
+ Logger logger = Logger.getLogger(SyncOrgUnitAndUserHiHisDaoImpl.class);
+
+ @Autowired
+ private HisInterfaceConfiguration hisInterfaceConfiguration;
+
+ @Autowired(required=false)
+ private SyncOrgUnitAndUserDao syncOrgUnitAndUserHisMessageServiceDao;
+
+ @Autowired
+ private OrgUnitManager orgUnitManager;
+
+ @Override
+ public UserVo[] getAllUser() {
+ UserVo[] userVoArray = null;
+ try {
+ //优先从新HIS接口获取,获取不到的再从旧的接口获取。
+ userVoArray = getAllHisUser();
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error("查询人员信息(" + hisInterfaceConfiguration.getWebserviceAddress() + ")失败:" + e);
+ }
+
+ if((userVoArray == null || userVoArray.length == 0) && syncOrgUnitAndUserHisMessageServiceDao != null){
+ //优先从新HIS接口获取,获取不到的再从旧的接口获取。
+ userVoArray = syncOrgUnitAndUserHisMessageServiceDao.getAllUser();
+ }
+
+ //检查所属科室是否存在
+ validateUserOrgUnitCode(userVoArray);
+
+ return userVoArray;
+ }
+
+ @SuppressWarnings("unchecked")
+ private UserVo[] getAllHisUser() throws Exception {
+ UserVo[] userVoArray = null;
+ List allUserVoList = new ArrayList();
+ //分页查询人员信息
+ Integer pageIndex = 1;
+ while(true){
+ List userVoList = new ArrayList();
+ String inputXml = WebServiceClientHelper.buildHihisInputStr(hisInterfaceConfiguration, DatasyncConstant.hihisQueryDoctorsService, null, pageIndex, DatasyncConstant.PAGESIZE);
+ logger.info("人员同步接口请求信息:" + inputXml);
+ String result = WebServiceClientHelper.doPostSoap1_2(hisInterfaceConfiguration.getWebserviceAddress(), inputXml);
+ /*String result = ""
+ + ""
+ + "true"
+ + ""
+ + "200
"
+ + ""
+ + "1"
+ + "1960"
+ + "2"
+ + "3920"
+ + ""
+ + ""
+ + "66fca4c7063ef80001a5d9c5"
+ + "0000"
+ + "信息管理员"
+ + ""
+ + ""
+ + "SSS1"
+ + "手术室1"
+ + ""
+ + ""
+ + "SSS2"
+ + "手术室2"
+ + ""
+ + ""
+ + "SSS3"
+ + "手术室3"
+ + ""
+ + ""
+ + ""
+ + ""
+ + "6706682c1b99280001d07ba4"
+ + "0001"
+ + "收费室测试"
+ + ""
+ + ""
+ + "SSS1"
+ + ""
+ + ""
+ + ""
+ + "SSS2"
+ + ""
+ + ""
+ + ""
+ + "SSS2"
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "";*/
+ logger.info("人员同步接口返回信息:" + result);
+ if(StringUtils.isBlank(result)){
+ throw new RuntimeException("人员同步接口返回信息为空!");
+ }
+ int startIndex = result.indexOf("");
+ if(startIndex == -1){
+ throw new RuntimeException("人员同步接口返回信息不包含标签!");
+ }
+ int endIndex = result.indexOf("");
+ if(endIndex == -1 || endIndex < startIndex){
+ throw new RuntimeException("人员同步接口返回信息不包含标签!");
+ }
+ String xmlString = result.substring(startIndex + "".length(), endIndex);
+ xmlString = "" + xmlString + "";
+ Document document = DocumentHelper.parseText(xmlString);
+ // 查询结果
+ String resultCodeXpath = "/BSXml/MsgBody/Code";
+ String resultCotentXpath = "/BSXml/MsgBody/Detail";
+ String resultCode = WebServiceClientHelper.processDataByXpath(document, resultCodeXpath);
+ String resultCotent = WebServiceClientHelper.processDataByXpath(document, resultCotentXpath);
+ logger.info("人员同步接口响应代码:" + resultCode + ";响应描述:" + resultCotent);
+ String itemXpath = "/BSXml/MsgBody/Data/EmployeeList/Employee"; // 返回结果可能存在多条用户信息
+ XPath xpath = document.createXPath(itemXpath);
+ List nodeList = xpath.selectNodes(document, xpath);
+ if(CollectionUtils.isNotEmpty(nodeList)){
+ for (int i = 1; i <= nodeList.size(); i++) {
+
+ String msgXpath = "/BSXml/MsgBody/Data/EmployeeList/Employee[" + i + "]";
+ // 工号
+ String codeXpath = msgXpath + "/EmployeeCode";
+ // 姓名
+ String nameXpath = msgXpath + "/EmployeeName";
+ // 上级科室编码
+ Set orgUnitCodeSet = new LinkedHashSet();
+ orgUnitCodeSet.add("0");
+ String servicedepartmentXpath = msgXpath + "/ServicedepartmentList/Servicedepartment";
+ XPath servicedepartmentNodeXpath = document.createXPath(servicedepartmentXpath);
+ List servicedepartmentNodeList = servicedepartmentNodeXpath.selectNodes(document, servicedepartmentNodeXpath);
+ if(CollectionUtils.isNotEmpty(servicedepartmentNodeList)){
+ for(int j=1;j<=servicedepartmentNodeList.size();j++){
+ String departmentCodeXpath = servicedepartmentXpath + "[" + j + "]/DepartmentCode";
+ String departmentCode = WebServiceClientHelper.processDataByXpath(document, departmentCodeXpath);
+ if(StringUtils.isNotBlank(departmentCode)){
+ orgUnitCodeSet.add(departmentCode);
+ }
+ }
+ }
+
+ String code = WebServiceClientHelper.processDataByXpath(document, codeXpath);
+ String name = WebServiceClientHelper.processDataByXpath(document, nameXpath);
+
+ UserVo userVo = new UserVo();
+ userVo.setCoding(code);
+ userVo.setName(name);
+ userVo.setOrgUnitCoding(StringTools.join(orgUnitCodeSet, ";"));
+
+ userVoList.add(userVo);
+ }
+ }
+ if(CollectionUtils.isNotEmpty(userVoList)){
+ allUserVoList.addAll(userVoList);
+ }
+ logger.info(String.format("第%s页共同步到%s条记录", pageIndex, userVoList.size()));
+ if(CollectionUtils.isEmpty(userVoList) || userVoList.size() < DatasyncConstant.PAGESIZE){
+ logger.info(String.format("第%s页返回%s条记录,查询完成", pageIndex, userVoList.size()));
+ break;
+ }
+ //继续查询下一页
+ pageIndex++;
+ }
+ //人员同步接口一共返回1000条记录,总页数为1
+ logger.info(String.format("人员同步接口返回的总记录数为%s", allUserVoList.size()));
+ if(CollectionUtils.isNotEmpty(allUserVoList)){
+ userVoArray = new UserVo[allUserVoList.size()];
+ allUserVoList.toArray(userVoArray);
+ }
+ return userVoArray;
+ }
+
+ /**
+ * 检查用户所属科室是否存在
+ * @param userVoArray
+ */
+ private void validateUserOrgUnitCode(UserVo[] userVoArray) {
+ if(userVoArray == null || userVoArray.length == 0){
+ return;
+ }
+ Set orgUnitCodeSet = new HashSet();
+ for (UserVo vo : userVoArray) {
+ String orgUnitCoding = vo.getOrgUnitCoding();
+ if(StringUtils.isBlank(orgUnitCoding)){
+ continue;
+ }
+ String[] orgUnitCodeArray = orgUnitCoding.split(";");
+ for (String code : orgUnitCodeArray) {
+ orgUnitCodeSet.add(code);
+ }
+ }
+ Map orgUnitCodingNameMap = orgUnitManager.loadOrgUnitCodingNameMapForSync(orgUnitCodeSet);
+ for (String orgUnitCode : orgUnitCodeSet) {
+ if(!orgUnitCodingNameMap.containsKey(orgUnitCode)){
+ throw new RuntimeException("科室编码为(" + orgUnitCode + ")的科室不存在");
+ }
+ }
+ }
+
+ @Override
+ public OrgUnitVo[] getAllOrgUnit() {
+ OrgUnitVo[] orgUnitVoArray = null;
+ try {
+ //优先从新HIS接口获取,获取不到的再从旧的接口获取。
+ orgUnitVoArray = getAllHisOrgUnit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error("科室信息(" + hisInterfaceConfiguration.getWebserviceAddress() + ")失败:" + e.getMessage());
+ }
+
+ if((orgUnitVoArray == null || orgUnitVoArray.length == 0) && syncOrgUnitAndUserHisMessageServiceDao != null){
+ //优先从新HIS接口获取,获取不到的再从旧的接口获取。
+ return syncOrgUnitAndUserHisMessageServiceDao.getAllOrgUnit();
+ }
+
+ return orgUnitVoArray;
+ }
+
+ @SuppressWarnings("unchecked")
+ private OrgUnitVo[] getAllHisOrgUnit() throws Exception {
+
+ OrgUnitVo[] orgUnitVoArray = null;
+ List allOrgUnitVoList = new ArrayList();
+ Integer pageIndex = 1;
+ while(true){
+ List orgUnitVoList = new ArrayList();
+ String inputXml = WebServiceClientHelper.buildHihisInputStr(hisInterfaceConfiguration, DatasyncConstant.hihisQueryDepartmentsService, null, pageIndex, DatasyncConstant.PAGESIZE);
+ logger.info("科室同步接口请求信息:" + inputXml);
+ String result = WebServiceClientHelper.doPostSoap1_2(hisInterfaceConfiguration.getWebserviceAddress(), inputXml);
+ /*String result = ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "true"
+ + ""
+ + "200
"
+ + ""
+ + "1"
+ + ""
+ + ""
+ + "610cf468bd06d3454cfa5703"
+ + "SSS1"
+ + "手术室1"
+ + ""
+ + ""
+ + ""
+ + "610cf468bd06d3454cfa56ff"
+ + "SSS2"
+ + "手术室2"
+ + "SSS1"
+ + ""
+ + ""
+ + "610cf468bd06d3454cfa5701"
+ + "SSS3"
+ + "手术室3"
+ + "SSS1"
+ + ""
+ + ""
+ + ""
+ + ""
+ + "";*/
+ logger.info("科室同步接口返回信息:" + result);
+ if(StringUtils.isBlank(result)){
+ throw new RuntimeException("科室同步接口返回信息为空!");
+ }
+ int startIndex = result.indexOf("");
+ if(startIndex == -1){
+ throw new RuntimeException("科室同步接口返回信息不包含标签!");
+ }
+ int endIndex = result.indexOf("");
+ if(endIndex == -1 || endIndex < startIndex){
+ throw new RuntimeException("科室同步接口返回信息不包含标签!");
+ }
+ String xmlString = result.substring(startIndex + "".length(), endIndex);
+ xmlString = "" + xmlString + "";
+ Document document = DocumentHelper.parseText(xmlString);
+ // 查询结果
+ String resultCodeXpath = "/BSXml/MsgBody/Code";
+ String resultCotentXpath = "/BSXml/MsgBody/Detail";
+ String resultCode = WebServiceClientHelper.processDataByXpath(document, resultCodeXpath);
+ String resultCotent = WebServiceClientHelper.processDataByXpath(document, resultCotentXpath);
+ logger.info("科室信息查询响应代码Code=" + resultCode + ";响应描述Detail=" + resultCotent);
+ String itemXpath = "/BSXml/MsgBody/Data/DepartmentList/Department"; // 返回结果可能存在多条科室信息
+ XPath xpath = document.createXPath(itemXpath);
+ List nodeList = xpath.selectNodes(document, xpath);
+ if(CollectionUtils.isNotEmpty(nodeList)){
+ for (int i = 1; i <= nodeList.size(); i++) {
+
+ String msgXpath = itemXpath + "[" + i + "]";
+ // 科室编码
+ String codeXpath = msgXpath + "/DepartmentCode";
+ // 科室名称
+ String nameXpath = msgXpath + "/DepartmentName";
+ // 上级科室编码
+ String parentCodingXpath = msgXpath + "/ParentDepartmentCode";
+
+ String code = WebServiceClientHelper.processDataByXpath(document, codeXpath);
+ String name = WebServiceClientHelper.processDataByXpath(document, nameXpath);
+ String parentCoding = WebServiceClientHelper.processDataByXpath(document, parentCodingXpath);
+ OrgUnitVo orgUnitVo = new OrgUnitVo();
+ orgUnitVo.setCoding(code);
+ orgUnitVo.setName(name);
+ orgUnitVo.setParentCoding(parentCoding);
+
+ //科室编码与上级科室编码相同时,默认其上级科室编码为空
+ if(StringUtils.equals(orgUnitVo.getCoding(), orgUnitVo.getParentCoding())){
+ orgUnitVo.setParentCoding(null);
+ }
+ orgUnitVoList.add(orgUnitVo);
+ }
+ } else {
+ logger.info("未找到科室数据");
+ }
+
+ if(CollectionUtils.isNotEmpty(orgUnitVoList)){
+ allOrgUnitVoList.addAll(orgUnitVoList);
+ }
+
+ logger.info(String.format("第%s页共同步到%s条科室记录", pageIndex, orgUnitVoList.size()));
+
+ //如果最后一页不足1000条记录,则证明查询到了最后一页,结束循环
+ if(CollectionUtils.isEmpty(orgUnitVoList) || orgUnitVoList.size() < DatasyncConstant.PAGESIZE){
+ logger.info(String.format("第%s页返回%s条记录,查询完成", pageIndex, orgUnitVoList.size()));
+ break;
+ }
+
+ //继续查询下一页
+ pageIndex++;
+ }
+ if(CollectionUtils.isNotEmpty(allOrgUnitVoList)){
+ orgUnitVoArray = new OrgUnitVo[allOrgUnitVoList.size()];
+ allOrgUnitVoList.toArray(orgUnitVoArray);
+ }
+ logger.info(String.format("科室同步接口返回的总记录数为%s", allOrgUnitVoList.size()));
+ return orgUnitVoArray;
+ }
+
+ @Override
+ public OrgUnitVo[] paramToOrgUnitVos(String param) {
+ return null;
+ }
+
+ @Override
+ public UserVo[] paramToUserVos(String param) {
+ return null;
+ }
+
+ @Override
+ public JSONObject buttjoinResponse(Boolean success, String message, String param) {
+ return null;
+ }
+
+
+}