Index: ssts-web/src/main/resources/config/xmdxfsxayy/mybatis/FindPatientInfoByHospitalNumMapper.xml =================================================================== diff -u -r26101 -r26315 --- ssts-web/src/main/resources/config/xmdxfsxayy/mybatis/FindPatientInfoByHospitalNumMapper.xml (.../FindPatientInfoByHospitalNumMapper.xml) (revision 26101) +++ ssts-web/src/main/resources/config/xmdxfsxayy/mybatis/FindPatientInfoByHospitalNumMapper.xml (.../FindPatientInfoByHospitalNumMapper.xml) (revision 26315) @@ -4,35 +4,46 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - Index: ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebService.java =================================================================== diff -u --- ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebService.java (revision 0) +++ ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebService.java (revision 26315) @@ -0,0 +1,33 @@ +package com.forgon.disinfectsystem.webservice.datasync.xmdxfsxayy; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; + +/** + * 厦门大学附属翔安医院同步科室人员、病人信息webservice接口定义 + * @author zhoupeimian + * @since 2019-04-28 + */ +@WebService +public interface HIPMessageWebService { + + /** + * 同步科室人员、病人信息webservice接口调用 + * @param action 服务编号 + * @param message XML数据 + * @return + * +
+ + +
+ + 0 + 成功 + +
+ */ + @WebMethod + public String HIPMessageServer(@WebParam(name="action") String action, @WebParam(name="message") String message); +} Index: ssts-web/src/main/resources/config/xmdxfsxayy/mybatis/FindPatientInfoByTreatmentNumMapper.xml =================================================================== diff -u -r26101 -r26315 --- ssts-web/src/main/resources/config/xmdxfsxayy/mybatis/FindPatientInfoByTreatmentNumMapper.xml (.../FindPatientInfoByTreatmentNumMapper.xml) (revision 26101) +++ ssts-web/src/main/resources/config/xmdxfsxayy/mybatis/FindPatientInfoByTreatmentNumMapper.xml (.../FindPatientInfoByTreatmentNumMapper.xml) (revision 26315) @@ -5,17 +5,23 @@ - Index: ssts-web/src/main/resources/spring/projects/xmdxfsxayy/HIS.xml =================================================================== diff -u -r26101 -r26315 --- ssts-web/src/main/resources/spring/projects/xmdxfsxayy/HIS.xml (.../HIS.xml) (revision 26101) +++ ssts-web/src/main/resources/spring/projects/xmdxfsxayy/HIS.xml (.../HIS.xml) (revision 26315) @@ -34,19 +34,18 @@ - - + - + - + - + @@ -77,7 +76,7 @@ value="com.forgon.disinfectsystem.datasynchronization.dao.FindPatientInfoByTreatmentNumDao" /> - + @@ -86,12 +85,12 @@ - + Index: ssts-web/src/main/resources/spring/projects/xmdxfsxayy/webservice-cxf.xml =================================================================== diff -u --- ssts-web/src/main/resources/spring/projects/xmdxfsxayy/webservice-cxf.xml (revision 0) +++ ssts-web/src/main/resources/spring/projects/xmdxfsxayy/webservice-cxf.xml (revision 26315) @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file Index: ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebServiceImpl.java =================================================================== diff -u --- ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebServiceImpl.java (revision 0) +++ ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebServiceImpl.java (revision 26315) @@ -0,0 +1,586 @@ +package com.forgon.disinfectsystem.webservice.datasync.xmdxfsxayy; + +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.jws.WebService; + +import net.sf.json.JSONObject; +import net.sf.json.xml.XMLSerializer; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Node; +import org.dom4j.io.SAXReader; +import org.springframework.beans.factory.annotation.Autowired; + +import com.forgon.disinfectsystem.datasynchronization.model.OrgUnitVo; +import com.forgon.disinfectsystem.datasynchronization.model.PatientInfoVO; +import com.forgon.disinfectsystem.datasynchronization.model.UserVo; +import com.forgon.disinfectsystem.datasynchronization.service.DataSynchronizationManager; +import com.forgon.disinfectsystem.entity.useRecord.gyey.PatientAdmissionInfo; +import com.forgon.disinfectsystem.useRecord.service.gyey.PatientAdmissionInfoManager; +import com.forgon.security.service.UserManager; +import com.forgon.tools.date.DateTools; + +/** + * 厦门大学附属翔安医院同步科室人员、病人信息webservice接口实现 + * @author zhoupeimian + * @since 2019-04-28 + */ +@WebService(endpointInterface = "com.forgon.disinfectsystem.webservice.datasync.xmdxfsxayy.HIPMessageWebService", serviceName = "/HIPMessageWebService") +public class HIPMessageWebServiceImpl implements HIPMessageWebService{ + + private Logger logger = Logger.getLogger(this.getClass()); + + /** + * 病人信息数据库操作 + */ + @Autowired + private PatientAdmissionInfoManager patientAdmissionInfoManager; + + /** + * 科室人员数据库操作 + */ + @Autowired + private DataSynchronizationManager dataSynchronizationManager; + + /** + * 人员数据库操作(根据手术医师工号查找手术医师姓名) + */ + @Autowired + private UserManager userManager; + + /** + * WebService调用接口 + * @param action 服务描述("T0004"--患者基本信息接收、“T0007”--手术申请预约信息接收、“MS004”--发送医护人员字典信息、“MS003”--发送科室字典信息) + * @param message XML文档 + */ + @Override + public String HIPMessageServer(String action, String message) { + /* 回复信息格式: + * +
+ + +
+ + 0 + 成功 + +
+ */ + // message = xmlFileToStr("D:/项目/厦门大学附属翔安医院webService接口/患者基本信息.xml"); + // message = xmlFileToStr("D:/项目/厦门大学附属翔安医院webService接口/手术申请预约信息.xml"); + // message = xmlFileToStr("D:/项目/厦门大学附属翔安医院webService接口/科室.xml"); + // message = xmlFileToStr("D:/项目/厦门大学附属翔安医院webService接口/人员.xml"); + JSONObject responseJSON = new JSONObject(); + JSONObject headerJSON = new JSONObject(); + JSONObject bodyJSON = new JSONObject(); + if (StringUtils.isBlank(action) || StringUtils.isBlank(message)) { + logger.info("XML文件的“action”或者“message”没有内容"); + headerJSON.put("SourceSystem", "追溯系统"); + headerJSON.put("MessageID", 0); + bodyJSON.put("ResultCode", -1); + bodyJSON.put("ResultContent", "action或者message为空"); + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + } else { + if("T0004".equals(action)) { + responseJSON = syncPatientInfo(message); + } else if("T0007".equals(action)) { + responseJSON = syncClinicPatientInfo(message); + } else if("MS004".equals(action)) { + responseJSON = syncUser(message); + } else if("MS003".equals(action)) { + responseJSON = syncOrgUnit(message); + } else { + logger.info("action值错误..."); + headerJSON.put("SourceSystem", "追溯系统"); + headerJSON.put("MessageID", 0); + bodyJSON.put("ResultCode", -1); + bodyJSON.put("ResultContent", "action错误"); + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + } + } + XMLSerializer xmlSerializer = new XMLSerializer(); + xmlSerializer.setRootName("Response"); + xmlSerializer.setTypeHintsEnabled(false); + return xmlSerializer.write(responseJSON); + } + + /** + * 同步患者基本信息 + * @param xmlData + * @return + */ + private JSONObject syncPatientInfo(String xmlData) { + // 解析xml获取“患者基本信息” + PatientInfoVO patientInfoVO = processPatientInfoByXmlData(xmlData); + JSONObject responseJSON = new JSONObject(); + JSONObject headerJSON = new JSONObject(); + JSONObject bodyJSON = new JSONObject(); + // 应答消息(默认解析失败) + headerJSON.put("SourceSystem", "追溯系统"); + headerJSON.put("MessageID", 0); + bodyJSON.put("ResultCode", -1); + bodyJSON.put("ResultContent", "失败"); + if(null != patientInfoVO && !checkObjAllFieldsIsNull(patientInfoVO)) { + // 保存“患者基本信息” + PatientAdmissionInfo patientAdmissionInfo = new PatientAdmissionInfo(); + patientAdmissionInfo.setHospitalSerialNumber(patientInfoVO.getSerialNumber()); + patientAdmissionInfo.setTreatmentNum(patientInfoVO.getClinicNumber()); + patientAdmissionInfo.setHospitalNumber(patientInfoVO.getHospitalNumber()); + patientAdmissionInfo.setPatientName(patientInfoVO.getPatientName()); + patientAdmissionInfo.setPatientAge(birthdayToAge(patientInfoVO.getPatientAge())); + patientAdmissionInfo.setPatientSex(patientInfoVO.getPatientSex()); + patientAdmissionInfo.setPatientIDCard(patientInfoVO.getPatientIDCard()); + if(null != patientAdmissionInfoManager && !checkObjAllFieldsIsNull(patientAdmissionInfo)) { + // 判断和当前“患者基本信息”对应的“诊疗/住院病人信息”是否存在 + // 患者类型:O:诊疗号患者;I:入院号患者 + String patientType = patientInfoVO.getType(); + String hql = null; + String number = null; + if("O".equals(patientType)) { + number = patientInfoVO.getClinicNumber(); + hql = String.format("po.treatmentNum = '%s' and po.patientName is null and po.patientSex is null and po.patientAge is null and po.patientIDCard is null", number); + } else if("I".equals(patientType)) { + number = patientInfoVO.getHospitalNumber(); + hql = String.format("po.hospitalNumber = '%s' and po.patientName is null and po.patientSex is null and po.patientAge is null and po.patientIDCard is null", number); + } else { + logger.info("syncPatientInfo: 患者类型不为“O”或“I”..."); + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + List list = patientAdmissionInfoManager.getByHql(hql); + // 1、不存在,直接插入新记录 + if(CollectionUtils.isEmpty(list)) { + logger.info("syncPatientInfo:不存在诊疗号/住院号为【" + number + "】的“诊疗号/住院号病人信息”,新建记录"); + patientAdmissionInfoManager.save(patientAdmissionInfo); + headerJSON.put("MessageID", patientInfoVO.getSerialNumber()); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "保存成功"); + } else { + // 2、存在,更新数据(批量更新) + logger.info("syncPatientInfo:存在诊疗号/住院号为【" + number + "】的“诊疗号/住院号病人信息”,更新记录"); + for(PatientAdmissionInfo obj : list) { + obj.setHospitalSerialNumber(patientAdmissionInfo.getHospitalSerialNumber()); + obj.setTreatmentNum(patientAdmissionInfo.getTreatmentNum()); + obj.setHospitalNumber(patientAdmissionInfo.getHospitalNumber()); + obj.setPatientName(patientAdmissionInfo.getPatientName()); + obj.setPatientAge(patientAdmissionInfo.getPatientAge()); + obj.setPatientSex(patientAdmissionInfo.getPatientSex()); + obj.setPatientIDCard(patientAdmissionInfo.getPatientIDCard()); + // 挂号病人的没有“洗手护士”和“巡回护士”字段 + if("O".equals(patientType)) { + obj.setWashHandNurse(null); + obj.setCircuitNurse(null); + } + patientAdmissionInfoManager.update(obj); + } + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "更新成功"); + } + } + } else { + logger.info("处理“患者基本信息”XML文档出错:\n" + xmlData); + } + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + + /** + * 处理“患者基本信息”XML文档 + * @param xmlData + * @return PatientInfoVO + */ + private PatientInfoVO processPatientInfoByXmlData(String xmlData) { + if(!StringUtils.isBlank(xmlData)) { + try { + Document document = DocumentHelper.parseText(xmlData); + String patientIDXpath = "/Request/Body/PatientRegistryRt/PATPatientID"; + String serialNumberXpath = "/Request/Header/MessageID"; + String patientNameXpath = "/Request/Body/PatientRegistryRt/PATName"; + String patientAgeXpath = "/Request/Body/PatientRegistryRt/PATDob"; + String patientSexXpath = "/Request/Body/PatientRegistryRt/PATSexDesc"; + String patientIDCardXpath = "/Request/Body/PatientRegistryRt/PATIdentityList/PATIdentity/PATIdentityNum"; + String typeCodeXpath = "/Request/Body/PatientRegistryRt/PAADMEncounterTypeCode"; + String patientID = processDataByXpath(document, patientIDXpath); // 诊疗号或者住院号 + String serialNumber = processDataByXpath(document, serialNumberXpath); // 当前诊疗/住院流水号 + String patientName = processDataByXpath(document, patientNameXpath); // 姓名 + String patientAge = processDataByXpath(document, patientAgeXpath); // 年龄 + String patientSex = processDataByXpath(document, patientSexXpath); // 性别 + String patientIDCard = processDataByXpath(document, patientIDCardXpath); // 身份证 + String typeCode = processDataByXpath(document, typeCodeXpath); // 患者类型(O:诊疗号病人;I:住院号病人) + if(StringUtils.isEmpty(patientID)) { + return null; + } + PatientInfoVO patientInfoVO = new PatientInfoVO(); + patientInfoVO.setSerialNumber(serialNumber); + patientInfoVO.setPatientName(patientName); + patientInfoVO.setPatientAge(patientAge); + patientInfoVO.setPatientSex(patientSex); + patientInfoVO.setPatientIDCard(patientIDCard); + patientInfoVO.setType(typeCode); + if("O".equals(typeCode)) { + // 诊疗号 + patientInfoVO.setClinicNumber(patientID); + } else if("I".equals(typeCode)) { + // 住院号 + patientInfoVO.setHospitalNumber(patientID); + } else { + logger.info("processPatientInfoByXmlData:患者类型不为“O”或“I”"); + return null; + } + return patientInfoVO; + } catch (DocumentException e) { + logger.info("处理“患者基本信息”XML文档出错:\n" + xmlData); + e.printStackTrace(); + } + } + logger.info("XML文档为空:\n" + xmlData); + return null; + } + + /** + * 同步患者诊疗信息 + * @param xmlData + * @return + */ + private JSONObject syncClinicPatientInfo(String xmlData) { + // 解析xml获取“手术申请预约信息” + PatientInfoVO patientInfoVO = processClinicPatientInfoByXmlData(xmlData); + JSONObject responseJSON = new JSONObject(); + JSONObject headerJSON = new JSONObject(); + JSONObject bodyJSON = new JSONObject(); + // 应答消息(默认解析失败) + headerJSON.put("SourceSystem", "追溯系统"); + headerJSON.put("MessageID", 0); + bodyJSON.put("ResultCode", -1); + bodyJSON.put("ResultContent", "失败"); + if(null != patientInfoVO) { + PatientAdmissionInfo patientAdmissionInfo = new PatientAdmissionInfo(); + patientAdmissionInfo.setTreatmentNum(patientInfoVO.getClinicNumber()); + patientAdmissionInfo.setHospitalNumber(patientInfoVO.getHospitalNumber()); + patientAdmissionInfo.setHospitalSerialNumber(patientInfoVO.getSerialNumber()); + patientAdmissionInfo.setDoctorName(patientInfoVO.getDoctorName()); + patientAdmissionInfo.setSurgeryName(patientInfoVO.getOperation()); + patientAdmissionInfo.setBedNumber(patientInfoVO.getBedNumber()); + Date operationTime = DateTools.coverStrToDate(patientInfoVO.getOperationTime(), "yyyy-MM-dd HH:mm:ss"); + patientAdmissionInfo.setInDate(operationTime); + patientAdmissionInfo.setCircuitNurse(patientInfoVO.getCircuitNurse()); + patientAdmissionInfo.setWashHandNurse(patientInfoVO.getWashHandNurse()); + if(null != patientAdmissionInfoManager && !checkObjAllFieldsIsNull(patientAdmissionInfo)) { + // “诊疗病人信息”相关的“手术申请预约信息” + String hql1 = String.format("po. treatmentNum = '%s' and po.doctorName is null and po.surgeryName is null and po.inDate is null and po.bedNumber is null", + patientAdmissionInfo.getTreatmentNum()); + List clinicPatientList = patientAdmissionInfoManager.getByHql(hql1); + if(CollectionUtils.isNotEmpty(clinicPatientList)) { + // 一次只影响一条记录 + PatientAdmissionInfo obj = clinicPatientList.get(0); + obj.setHospitalSerialNumber(patientAdmissionInfo.getHospitalSerialNumber()); + obj.setDoctorName(patientAdmissionInfo.getDoctorName()); + obj.setSurgeryName(patientAdmissionInfo.getSurgeryName()); + obj.setBedNumber(patientAdmissionInfo.getBedNumber()); + obj.setInDate(patientAdmissionInfo.getInDate()); + patientAdmissionInfoManager.update(obj); + headerJSON.put("MessageID", patientInfoVO.getSerialNumber()); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "更新成功"); + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + // “住院病人信息”相关的“手术申请预约信息” + String hql2 = String.format("po. hospitalNumber = '%s' and po.doctorName is null and po.surgeryName is null and po.inDate is null and po.bedNumber is null", + patientAdmissionInfo.getTreatmentNum()); + List hospitalPatientList = patientAdmissionInfoManager.getByHql(hql2); + if(CollectionUtils.isNotEmpty(hospitalPatientList)) { + PatientAdmissionInfo obj = hospitalPatientList.get(0); + obj.setHospitalSerialNumber(patientAdmissionInfo.getHospitalSerialNumber()); + obj.setDoctorName(patientAdmissionInfo.getDoctorName()); + obj.setSurgeryName(patientAdmissionInfo.getSurgeryName()); + obj.setBedNumber(patientAdmissionInfo.getBedNumber()); + obj.setInDate(patientAdmissionInfo.getInDate()); + obj.setWashHandNurse(patientAdmissionInfo.getWashHandNurse()); + obj.setCircuitNurse(patientAdmissionInfo.getCircuitNurse()); + patientAdmissionInfoManager.update(obj); + headerJSON.put("MessageID", patientInfoVO.getSerialNumber()); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "更新成功"); + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + // 不存在对应的“诊疗/住院病人信息” + if(CollectionUtils.isEmpty(clinicPatientList) && CollectionUtils.isEmpty(hospitalPatientList)) { + patientAdmissionInfoManager.save(patientAdmissionInfo); + headerJSON.put("MessageID", patientInfoVO.getSerialNumber()); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "保存成功"); + } + } + } + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + + /** + * 处理“手术申请预约信息接收”XML文档 + * @param xmlData + * @return PatientInfoVO + */ + private PatientInfoVO processClinicPatientInfoByXmlData(String xmlData) { + if(!StringUtils.isBlank(xmlData)) { + try { + Document document = DocumentHelper.parseText(xmlData); + String PATPatientIDXpath = "/Request/Body/OperationArrangeRt/PATPatientID"; + String serialNumberXpath = "/Request/Header/MessageID"; + String doctorNameXpath = "/Request/Body/OperationArrangeRt/SURGEON"; + String operationXpath = "/Request/Body/OperationArrangeRt/OPERATIONS/OPERATION_Name"; + String operationTimeXpath = "/Request/Body/OperationArrangeRt/SCHEDULED_DATE_TIME"; + String bedNumberXpath = "/Request/Body/OperationArrangeRt/BED_NO"; + String washHandNurseXpath = "/Request/Body/OperationArrangeRt/FIRST_OPERATION_NURSE"; + String circuitNurseXpath = "/Request/Body/OperationArrangeRt/FIRST_SUPPLY_NURSE"; + String PATPatientID = processDataByXpath(document, PATPatientIDXpath); // 诊疗号/住院号 + String serialNumber = processDataByXpath(document, serialNumberXpath); // 住院流水号 + String doctorNO = processDataByXpath(document, doctorNameXpath); + String doctorName = null; + if(null != userManager) { + doctorName = userManager.getUserNameByUserId(doctorNO);// 医生 + } + String operation = processDataByXpath(document, operationXpath); // 手术名称 + String operationTime = processDataByXpath(document, operationTimeXpath); // 手术时间 + String bedNumber = processDataByXpath(document, bedNumberXpath); // 床号 + String washHandNurse = processDataByXpath(document, washHandNurseXpath); // 洗手护士 + String circuitNurse = processDataByXpath(document, circuitNurseXpath); // 巡回护士 + PatientInfoVO patientInfoVO = new PatientInfoVO(); + // PATPatientID对应“诊疗号”或者“住院号” + patientInfoVO.setClinicNumber(PATPatientID); + patientInfoVO.setHospitalNumber(PATPatientID); + patientInfoVO.setSerialNumber(serialNumber); + patientInfoVO.setDoctorName(doctorName); + patientInfoVO.setOperation(operation); + patientInfoVO.setOperationTime(operationTime); + patientInfoVO.setBedNumber(bedNumber); + patientInfoVO.setWashHandNurse(washHandNurse); + patientInfoVO.setCircuitNurse(circuitNurse); + return patientInfoVO; + } catch (DocumentException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * 同步人员信息 + * @param xmlData + * @return + */ + private JSONObject syncUser(String xmlData) { + JSONObject responseJSON = new JSONObject(); + JSONObject headerJSON = new JSONObject(); + JSONObject bodyJSON = new JSONObject(); + headerJSON.put("SourceSystem", "追溯系统"); + headerJSON.put("MessageID", 0); + bodyJSON.put("ResultCode", -1); + bodyJSON.put("ResultContent", "失败"); + // 解析xml获取“用户信息” + UserVo userVo = processUserInfoByXmlData(xmlData); + if(null != userVo && !checkObjAllFieldsIsNull(userVo)) { + UserVo[] allVos = new UserVo[]{userVo}; + if(null != dataSynchronizationManager) { + dataSynchronizationManager.processSyncUserData(allVos); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "成功"); + } + } + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + + /** + * 处理“用户信息”XML文档 + * @param xmlData + * @return UserVo + */ + private UserVo processUserInfoByXmlData(String xmlData) { + if(StringUtils.isNotBlank(xmlData)) { + try { + Document document = DocumentHelper.parseText(xmlData); + String nameXpath = "/Request/Body/CT_CareProvList/CT_CareProv/CTCP_Desc"; + String codingXpath = "/Request/Body/CT_CareProvList/CT_CareProv/CTCP_Code"; + String orgUnitCodingXpath = "/Request/Body/CT_CareProvList/CT_CareProv/CTCP_DeptCode"; + String name = processDataByXpath(document, nameXpath); + String coding = processDataByXpath(document, codingXpath); + String orgUnitCoding = processDataByXpath(document, orgUnitCodingXpath); + UserVo userVo = new UserVo(); + userVo.setName(name); + userVo.setCoding(coding); + userVo.setOrgUnitCoding(orgUnitCoding); + return userVo; + } catch (DocumentException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * 同步科室信息 + * @param xmlData XML数据 + * @return + */ + private JSONObject syncOrgUnit(String xmlData) { + JSONObject responseJSON = new JSONObject(); + JSONObject headerJSON = new JSONObject(); + JSONObject bodyJSON = new JSONObject(); + headerJSON.put("SourceSystem", "追溯系统"); + headerJSON.put("MessageID", 0); + bodyJSON.put("ResultCode", -1); + bodyJSON.put("ResultContent", "失败"); + OrgUnitVo orgUnitVo = processDepartmentInfoByXmlData(xmlData); + if(null != orgUnitVo && !checkObjAllFieldsIsNull(orgUnitVo)){ + OrgUnitVo[] allVos = new OrgUnitVo[]{orgUnitVo}; + if(null != dataSynchronizationManager) { + dataSynchronizationManager.processSyncOrgUnitData(allVos); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "成功"); + } + } + responseJSON.put("Header", headerJSON); + responseJSON.put("Body", bodyJSON); + return responseJSON; + } + + /** + * 处理“组织机构信息”XML文档 + * @param xmlData + * @return OrgUnitVo + */ + private OrgUnitVo processDepartmentInfoByXmlData(String xmlData) { + if(StringUtils.isNotBlank(xmlData)) { + try { + Document document = DocumentHelper.parseText(xmlData); + String nameXpath = "/Request/Body/CT_DeptList/CT_Dept/CTD_Desc"; + String codingXpath = "/Request/Body/CT_DeptList/CT_Dept/CTD_Code"; + String parentCodingXpath = "/Request/Body/CT_DeptList/CT_Dept/CTD_ParentDeptCode"; + String name = processDataByXpath(document, nameXpath); + String coding = processDataByXpath(document, codingXpath); + String parentCoding = processDataByXpath(document, parentCodingXpath); + OrgUnitVo orgUnitVo = new OrgUnitVo(); + orgUnitVo.setName(name); + orgUnitVo.setCoding(coding); + orgUnitVo.setParentCoding(parentCoding); + return orgUnitVo; + } catch (DocumentException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * 根据document和Xpath表达式解析数据 + * @param document + * @param nameSpaceURIMap + * @param xpathExp + * @return + */ + private String processDataByXpath(Document document, String xpathExp) { + if ((StringUtils.isNotBlank(xpathExp)) && (document != null)) { + Node node = document.selectSingleNode(xpathExp); + if (node != null) { + return node.getStringValue(); + } + } + return null; + } + + /** + * 患者年龄处理: + * 根据患者出生日期(YYYY-MM-DD hh:mm:ss )计算年龄 + * @param birthday(YYYY-MM-DD hh:mm:ss ) + * @return age + */ + private String birthdayToAge(String birthday) { + if(StringUtils.isNotBlank(birthday)) { + String[] arr = birthday.split("-"); + Integer year = Integer.parseInt(arr[0]); + Integer month = Integer.parseInt(arr[1]); + Integer day = Integer.parseInt(arr[2].split(" ")[0]); + Calendar now = Calendar.getInstance(); + Integer currentYear = now.get(Calendar.YEAR); + Integer currentMonth = now.get(Calendar.MONTH) + 1; + Integer currentDay = now.get(Calendar.DAY_OF_MONTH); + Integer age = currentYear - year; + if(currentMonth == month) { + if(currentDay < day) { + age -= 1; + } + } else if(currentMonth < month) { + age -= 1; + } + return age.toString(); + } + return null; + } + + /** + * 判断实体对象是否为空、对象所有非静态属性是否都为空 + * @param object + * @return + */ + private boolean checkObjAllFieldsIsNull (Object object) { + if (null == object) { + return true; + } + try { + for (Field f : object.getClass().getDeclaredFields()) { + f.setAccessible(true); + if (f.get(object) != null && + StringUtils.isNotBlank(f.get(object).toString()) && + !Modifier.isStatic(f.getModifiers())) { + return false; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * 测试用:从xml文件读取xml字符串 + */ + @SuppressWarnings("unused") + private String xmlFileToStr(String path) { + String message = null; + try { + SAXReader saxReader = new SAXReader(); + File f = new File(path); + Document doc; + doc = saxReader.read(f); + message = doc.asXML(); + } catch (DocumentException e) { + logger.info("xml文件读取出错:" + path); + e.printStackTrace(); + } + return message; + } + +}