Index: ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebServiceImpl.java =================================================================== diff -u -r26315 -r26623 --- ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebServiceImpl.java (.../HIPMessageWebServiceImpl.java) (revision 26315) +++ ssts-webservice/src/main/java/com/forgon/disinfectsystem/webservice/datasync/xmdxfsxayy/HIPMessageWebServiceImpl.java (.../HIPMessageWebServiceImpl.java) (revision 26623) @@ -78,15 +78,11 @@ */ - // 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”没有内容"); + logger.info("HIPMessageServer:XML文件的“action”或者“message”没有内容"); headerJSON.put("SourceSystem", "追溯系统"); headerJSON.put("MessageID", 0); bodyJSON.put("ResultCode", -1); @@ -134,66 +130,52 @@ headerJSON.put("MessageID", 0); bodyJSON.put("ResultCode", -1); bodyJSON.put("ResultContent", "失败"); - if(null != patientInfoVO && !checkObjAllFieldsIsNull(patientInfoVO)) { + if(null != patientInfoVO) { // 保存“患者基本信息” PatientAdmissionInfo patientAdmissionInfo = new PatientAdmissionInfo(); - patientAdmissionInfo.setHospitalSerialNumber(patientInfoVO.getSerialNumber()); + patientAdmissionInfo.setHospitalSerialNumber(patientInfoVO.getPatientNumber()); // 患者主索引 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:入院号患者 + // 患者类型:O/E/H:诊疗号患者;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()); + // 住院患者基本信息(I类型),先判断和当前“患者基本信息”对应的“住院病人信息”是否存在 + if("I".equals(patientType)) { + String number = patientInfoVO.getPatientNumber(); + // 通过患者主索引查询 + String hql = String.format("po.hospitalSerialNumber = '%s' and po.patientName is null and po.patientSex is null and po.patientAge is null and po.patientIDCard is null", number); + 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 + "】的“手术预约申请单”,更新记录"); + PatientAdmissionInfo obj = list.get(0); 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", "更新成功"); } - bodyJSON.put("ResultCode", 0); - bodyJSON.put("ResultContent", "更新成功"); - } + } else { + // 诊疗患者基本信息(O/E/H类型),直接新建记录 + logger.info("syncPatientInfo:新建“诊疗号病人信息”,诊疗号为【" + patientAdmissionInfo.getTreatmentNum() + "】"); + patientAdmissionInfoManager.save(patientAdmissionInfo); + headerJSON.put("MessageID", patientInfoVO.getSerialNumber()); + bodyJSON.put("ResultCode", 0); + bodyJSON.put("ResultContent", "保存成功"); + } } - } else { - logger.info("处理“患者基本信息”XML文档出错:\n" + xmlData); } responseJSON.put("Header", headerJSON); responseJSON.put("Body", bodyJSON); @@ -216,14 +198,16 @@ 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 patientID = processDataByXpath(document, patientIDXpath); // 患者主索引 + String serialNumber = processDataByXpath(document, serialNumberXpath); // 消息ID 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:住院号病人) + String typeCode = processDataByXpath(document, typeCodeXpath); // 患者类型(O/E/H:诊疗号病人;I:住院号病人) if(StringUtils.isEmpty(patientID)) { + logger.info("processPatientInfoByXmlData:患者主索引:【/Request/Body/PatientRegistryRt/PATPatientID】为NULL"); + logger.info("processPatientInfoByXmlData:处理“患者基本信息”出错:\n" + xmlData); return null; } PatientInfoVO patientInfoVO = new PatientInfoVO(); @@ -233,19 +217,23 @@ patientInfoVO.setPatientSex(patientSex); patientInfoVO.setPatientIDCard(patientIDCard); patientInfoVO.setType(typeCode); - if("O".equals(typeCode)) { + if ("I".equals(typeCode)) { + // 住院病人的患者主索引。不作为住院号,用于匹配患者基本信息 + patientInfoVO.setPatientNumber(patientID); + } else if ("O".equals(typeCode) || "E".equals(typeCode) || "H".equals(typeCode)){ // 诊疗号 patientInfoVO.setClinicNumber(patientID); - } else if("I".equals(typeCode)) { - // 住院号 - patientInfoVO.setHospitalNumber(patientID); } else { - logger.info("processPatientInfoByXmlData:患者类型不为“O”或“I”"); + logger.info("processPatientInfoByXmlData:患者类型[PAADMEncounterTypeCode]不是I/O/E/H,[PAADMEncounterTypeCode] = " + patientInfoVO.getType() + ","); + logger.info("processPatientInfoByXmlData:处理“患者基本信息”出错:\n" + xmlData); return null; } + logger.info("processPatientInfoByXmlData:患者类型[PAADMEncounterTypeCode] = " + patientInfoVO.getType() + + ",患者主索引:【" + patientID + "】"); + logger.info("processPatientInfoByXmlData:处理“患者基本信息”成功:\n" + xmlData); return patientInfoVO; } catch (DocumentException e) { - logger.info("处理“患者基本信息”XML文档出错:\n" + xmlData); + logger.info("处理“患者基本信息”出错:\n" + xmlData); e.printStackTrace(); } } @@ -271,9 +259,8 @@ bodyJSON.put("ResultContent", "失败"); if(null != patientInfoVO) { PatientAdmissionInfo patientAdmissionInfo = new PatientAdmissionInfo(); - patientAdmissionInfo.setTreatmentNum(patientInfoVO.getClinicNumber()); + patientAdmissionInfo.setHospitalSerialNumber(patientInfoVO.getPatientNumber()); patientAdmissionInfo.setHospitalNumber(patientInfoVO.getHospitalNumber()); - patientAdmissionInfo.setHospitalSerialNumber(patientInfoVO.getSerialNumber()); patientAdmissionInfo.setDoctorName(patientInfoVO.getDoctorName()); patientAdmissionInfo.setSurgeryName(patientInfoVO.getOperation()); patientAdmissionInfo.setBedNumber(patientInfoVO.getBedNumber()); @@ -282,40 +269,23 @@ 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()); + // 查找和当前“手术申请预约信息”相关的“住院病人信息” + String hql2 = String.format("po. hospitalSerialNumber = '%s' and po.doctorName is null and po.surgeryName is null and po.inDate is null and po.bedNumber is null", + patientAdmissionInfo.getHospitalSerialNumber()); List hospitalPatientList = patientAdmissionInfoManager.getByHql(hql2); if(CollectionUtils.isNotEmpty(hospitalPatientList)) { + logger.info("syncClinicPatientInfo:存在患者主索引为【" + patientAdmissionInfo.getHospitalSerialNumber() + "】的住院信息,更新记录"); PatientAdmissionInfo obj = hospitalPatientList.get(0); obj.setHospitalSerialNumber(patientAdmissionInfo.getHospitalSerialNumber()); + obj.setHospitalNumber(patientAdmissionInfo.getHospitalNumber()); 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", "更新成功"); @@ -324,7 +294,8 @@ return responseJSON; } // 不存在对应的“诊疗/住院病人信息” - if(CollectionUtils.isEmpty(clinicPatientList) && CollectionUtils.isEmpty(hospitalPatientList)) { + if(CollectionUtils.isEmpty(hospitalPatientList)) { + logger.info("syncClinicPatientInfo:不存在患者主索引为【" + patientAdmissionInfo.getHospitalSerialNumber() + "】的住院信息,新建记录"); patientAdmissionInfoManager.save(patientAdmissionInfo); headerJSON.put("MessageID", patientInfoVO.getSerialNumber()); bodyJSON.put("ResultCode", 0); @@ -346,19 +317,27 @@ if(!StringUtils.isBlank(xmlData)) { try { Document document = DocumentHelper.parseText(xmlData); + String PAPMIMedicareXpath = "/Request/Body/OperationArrangeRt/PAPMIMedicare"; 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 operationXpath = "/Request/Body/OperationArrangeRt/OPERATIONS/OPERATION"; 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); // 诊疗号/住院号 + if (null == PATPatientID) { + logger.info("processClinicPatientInfoByXmlData:患者主索引:【/Request/Body/OperationArrangeRt/PATPatientID】为NULL"); + logger.info("processClinicPatientInfoByXmlData:处理“手术申请预约信息”XML文档出错:\n" + xmlData); + return null; + } + String PAPMIMedicare = processDataByXpath(document, PAPMIMedicareXpath); // 患者住院号 String serialNumber = processDataByXpath(document, serialNumberXpath); // 住院流水号 String doctorNO = processDataByXpath(document, doctorNameXpath); String doctorName = null; if(null != userManager) { + // 根据医生的ID查找医生姓名 doctorName = userManager.getUserNameByUserId(doctorNO);// 医生 } String operation = processDataByXpath(document, operationXpath); // 手术名称 @@ -367,19 +346,23 @@ String washHandNurse = processDataByXpath(document, washHandNurseXpath); // 洗手护士 String circuitNurse = processDataByXpath(document, circuitNurseXpath); // 巡回护士 PatientInfoVO patientInfoVO = new PatientInfoVO(); - // PATPatientID对应“诊疗号”或者“住院号” - patientInfoVO.setClinicNumber(PATPatientID); - patientInfoVO.setHospitalNumber(PATPatientID); + // 住院号 + patientInfoVO.setHospitalNumber(PAPMIMedicare); + // 患者主索引,用于匹配手术预约申请单和患者基本信息 + patientInfoVO.setPatientNumber(PATPatientID); patientInfoVO.setSerialNumber(serialNumber); patientInfoVO.setDoctorName(doctorName); patientInfoVO.setOperation(operation); patientInfoVO.setOperationTime(operationTime); patientInfoVO.setBedNumber(bedNumber); patientInfoVO.setWashHandNurse(washHandNurse); patientInfoVO.setCircuitNurse(circuitNurse); + logger.info("processClinicPatientInfoByXmlData:患者主索引:【" + PATPatientID + "】"); + logger.info("processPatientInfoByXmlData:处理“手术预约信息”成功:\n" + xmlData); return patientInfoVO; } catch (DocumentException e) { e.printStackTrace(); + logger.info("processClinicPatientInfoByXmlData:处理“手术申请预约信息”出错:\n" + xmlData); } } return null;