/** * MessageServiceSoapImpl.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package net.gzsums.www.esb; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.jws.WebService; import net.sf.json.JSON; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.xml.XMLSerializer; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import com.forgon.directory.acegi.tools.AcegiHelper; import com.forgon.disinfectsystem.common.CssdUtils; import com.forgon.disinfectsystem.datasynchronization.dao.FindPatientInfoByHospitalNumDao; import com.forgon.disinfectsystem.datasynchronization.model.PatientInfoVO; import com.forgon.disinfectsystem.entity.operationreservation.OperationReservation; import com.forgon.disinfectsystem.entity.useRecord.OperationSchedule; import com.forgon.disinfectsystem.operationSchedule.service.OperationScheduleManager; import com.forgon.log.model.Log; import com.forgon.log.service.LogManager; import com.forgon.tools.date.DateTools; import com.forgon.tools.db.DatabaseUtil; import com.forgon.tools.db.InitDbConnection; import com.forgon.tools.hibernate.ObjectDao; /** * 中大附一手术预约接口 * @author shuyongfu * */ @WebService(endpointInterface = "net.gzsums.www.esb.MessageServiceSoap", serviceName = "/MessageService") public class MessageServiceSoapImpl implements net.gzsums.www.esb.MessageServiceSoap{ private OperationScheduleManager operationScheduleManager; private LogManager appLogManager; private FindPatientInfoByHospitalNumDao findPatientInfoByHospitalNumDao; private ObjectDao objectDao; private InitDbConnection dbConnection; public void setOperationScheduleManager( OperationScheduleManager operationScheduleManager) { this.operationScheduleManager = operationScheduleManager; } public void setAppLogManager(LogManager appLogManager) { this.appLogManager = appLogManager; } public void setFindPatientInfoByHospitalNumDao( FindPatientInfoByHospitalNumDao findPatientInfoByHospitalNumDao) { this.findPatientInfoByHospitalNumDao = findPatientInfoByHospitalNumDao; } public void setObjectDao(ObjectDao objectDao) { this.objectDao = objectDao; } public void setDbConnection(InitDbConnection dbConnection) { this.dbConnection = dbConnection; } private final Logger logger = Logger.getLogger(this.getClass()); //接口是否在运行中,防止重复调用 static boolean running = false; /** * 接口的入库方法 */ public net.gzsums.www.esb.Response sendMessage(net.gzsums.www.esb.Request req) throws java.rmi.RemoteException { Response response = new Response(); ResponseHeader responseHeader = new ResponseHeader(); RequestHeader requestHeader = req.getRequestHeader(); responseHeader.setSender(requestHeader.getSender()); responseHeader.setReceiver(requestHeader.getReceiver()); responseHeader.setResponseTime(requestHeader.getRequestTime()); responseHeader.setMsgType(requestHeader.getMsgType()); responseHeader.setMsgId(requestHeader.getMsgId()); responseHeader.setMsgPriority(requestHeader.getMsgPriority()); responseHeader.setMsgVersion(requestHeader.getMsgVersion()); if(running){ responseHeader.setErrCode("5001"); responseHeader.setErrMessage("接口正在运行中,请稍候再调用!"); }else{ running = true; try{ logger.debug("req.getRequestBody()=" + req.getRequestBody()); processOperationPatientData(req , response); responseHeader.setErrCode("0"); }catch(RuntimeException e){ e.printStackTrace(); responseHeader.setErrCode("1000"); responseHeader.setErrMessage(e.getMessage()); } running = false; } response.setResponseHeader(responseHeader); return response; } /** * 处理手术排班数据 * @param xmlData */ private JSONObject processOperationPatientData(Request req , Response response){ if(req != null && StringUtils.isNotBlank(req.getRequestBody())){ try{ XMLSerializer xmlSerializer = new XMLSerializer(); JSON listObject = xmlSerializer.read(req.getRequestBody()); JSONArray operationPatientInfoJsonArray = new JSONArray(); if(listObject instanceof JSONObject){ JSONObject operationJsonObject = (JSONObject)listObject; operationPatientInfoJsonArray.add(operationJsonObject.optJSONObject("OperationPatientInfo")); }else if(listObject instanceof JSONArray){ operationPatientInfoJsonArray = (JSONArray)listObject; }else{ throw new RuntimeException("requestBody下级的list参数有误"); } String resultXml = ""; for(int i = 0;i < operationPatientInfoJsonArray.size();i++){ JSONObject operationPatientInfoJsonObject = operationPatientInfoJsonArray.optJSONObject(i); Object patientId = operationPatientInfoJsonObject.opt("PATIENT_ID");//住院号 Object name = operationPatientInfoJsonObject.opt("NAME");//名称 Object sexCode = operationPatientInfoJsonObject.opt("SEX_CODE");//性别 Object birthday = operationPatientInfoJsonObject.opt("BIRTHDAY");//出生日期 Object idenNo = operationPatientInfoJsonObject.opt("IDENNO");//身份证号 Object operation = operationPatientInfoJsonObject.opt("OPERATION");//手术名称(如果有多个手术名称时,用+拼起来) Object operatingRoomName = operationPatientInfoJsonObject.opt("OPERATING_ROOM_NAME");//手术间 Object surgeon = operationPatientInfoJsonObject.opt("SURGEON");//手术医生 Object scheduledDateTime = operationPatientInfoJsonObject.opt("SCHEDULED_DATE_TIME");//手术时间 Object firstSupplyNurse = operationPatientInfoJsonObject.opt("FIRST_SUPPLY_NURSE");//巡回护士 Object firstOperationNurse = operationPatientInfoJsonObject.opt("FIRST_OPERATION_NURSE");//洗手护士 Object consoleName = operationPatientInfoJsonObject.opt("CONSOLE_NAME");//手术台次 Object scheduleId = operationPatientInfoJsonObject.opt("SCHEDULE_ID");//手术编号 /*************************/ OperationSchedule operationSchedule = new OperationSchedule(); operationSchedule.setSaveDate(new Date()); operationSchedule.setLastModifyDate(operationSchedule.getSaveDate()); operationSchedule.setPatientId(patientId instanceof String ? (String)patientId : null); operationSchedule.setHospitalNumber(operationSchedule.getPatientId()); operationSchedule.setName(name instanceof String ? (String)name : null); operationSchedule.setSexCode(sexCode instanceof String ? (String)sexCode : null); String birthdayStr = birthday instanceof String ? (String)birthday : null; Date birthdayDate = null; if(StringUtils.isNotBlank(birthdayStr)){ birthdayDate = DateTools.parseDateIfNotEmpty(birthdayStr, new SimpleDateFormat("yyyyMMddHHmmss"), null); if(birthdayDate == null){ birthdayDate = DateTools.parseDateIfNotEmpty(birthdayStr, new SimpleDateFormat("yyyy-MM-dd"), null); if(birthdayDate == null){ birthdayDate = DateTools.parseDateIfNotEmpty(birthdayStr, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), null); } } if(birthdayDate == null){ // } }else{ // } operationSchedule.setBirthday(birthdayDate); operationSchedule.setIdenNo(idenNo instanceof String ? (String)idenNo : null); operationSchedule.setOperation(operation instanceof String ? (String)operation : null); operationSchedule.setOperatingRoomName(operatingRoomName instanceof String ? (String)operatingRoomName : null); operationSchedule.setSurgeon(surgeon instanceof String ? (String)surgeon : null); operationSchedule.setScheduledDateTime(scheduledDateTime instanceof String ? (String)scheduledDateTime : null); operationSchedule.setFirstSupplyNurse(firstSupplyNurse instanceof String ? (String)firstSupplyNurse : null); operationSchedule.setFirstOperationNurse(firstOperationNurse instanceof String ? (String)firstOperationNurse : null); operationSchedule.setConsoleName(consoleName instanceof String ? (String)consoleName : null); operationSchedule.setScheduleId(scheduleId instanceof String ? (String)scheduleId : null); //科室(病区)代码与名称的数据根据住院号从住院患者接口调用出来 if(findPatientInfoByHospitalNumDao != null){ String hospitalNumParam = operationSchedule.getPatientId(); String hospitalNumberPrefix = CssdUtils.getSystemSetConfigByName("hospitalNumberPrefix"); if(StringUtils.isNotBlank(hospitalNumParam) && StringUtils.isNotBlank(hospitalNumberPrefix) && !hospitalNumParam.startsWith(hospitalNumberPrefix)){ hospitalNumParam = hospitalNumberPrefix + hospitalNumParam; } PatientInfoVO[] patientInfoArray = findPatientInfoByHospitalNumDao.findPatientInfoByHospitalNum(hospitalNumParam); if(patientInfoArray != null && patientInfoArray.length > 0){ PatientInfoVO patientInfoVO = patientInfoArray[0]; operationSchedule.setDeptName(patientInfoVO.getAscriptionDepartment()); operationSchedule.setPatientName(patientInfoVO.getPatientName());; operationSchedule.setHospitalNumber(patientInfoVO.getHospitalNumber());; } } resultXml += ""; resultXml += ""+ patientId +""; resultXml += ""+ operation +""; resultXml += ""+ scheduledDateTime +""; resultXml += ""+ operationSchedule.getScheduleId() +""; try{ appLogManager.saveLog(AcegiHelper.getLoginUser(), Log.MODEL_OPERATION_RESERVATION, "接口推送", JSONObject.fromObject(operationSchedule)); //根据手术编码、住院号、手术时间查询出已经存在且未审核的手术预约数据 String condition = "where hospitalNumber = '"+ operationSchedule.getPatientId() +"' and scheduleId = '"+ operationSchedule.getScheduleId() +"' and committedStatus = false"; if(DatabaseUtil.isSqlServer(CssdUtils.getConfigProperty("database"))){ condition += " and replace(replace(replace(CONVERT(varchar, operationTime, 120 ),'-',''),' ',''),':','') = '"+ operationSchedule.getScheduledDateTime() +"'"; }else if(DatabaseUtil.isOracle(CssdUtils.getConfigProperty("database"))){ condition += " and to_char(operationTime,'yyyymmddhh24miss') = '"+ operationSchedule.getScheduledDateTime() +"'"; }else if(DatabaseUtil.isMySQLOrTiDB(CssdUtils.getConfigProperty("database"))){ condition += " and DATE_FORMAT(operationTime,'%Y-%m-%d %H:%i:%s') = '"+ operationSchedule.getScheduledDateTime() +"'"; }else{ throw new RuntimeException("不支持的数据库类型!"); } @SuppressWarnings("unchecked") List operationReservationList = objectDao.findBySql(OperationReservation.class.getSimpleName(), condition); //去除重复处理(根据手术编码、住院号、手术时间) if(CollectionUtils.isEmpty(operationReservationList)){ operationScheduleManager.saveOrUpdate(operationSchedule); }else{ OperationReservation originalOperationReservation = operationReservationList.get(0); String orginalOperationName = originalOperationReservation.getOperationName(); if(StringUtils.isNotBlank(orginalOperationName)){ //如果原有数据的手术名称不包括+号,且和新推送的手术名称不一致时 if(orginalOperationName.indexOf("+") == -1 && !StringUtils.equals(orginalOperationName, operationSchedule.getOperation())){ originalOperationReservation.setOperationName(originalOperationReservation.getOperationName() + "+" + operationSchedule.getOperation()); objectDao.saveOrUpdate(originalOperationReservation); //重新设置物品申请项 operationScheduleManager.resetOperationUseTousseItem(originalOperationReservation); }else{ //因为已经有两个手术名称了,所以数据丢弃 logger.debug("patientId = '"+ operationSchedule.getPatientId() +"' and scheduleId = '"+ operationSchedule.getScheduleId() +"' and scheduledDateTime = '"+ operationSchedule.getScheduledDateTime() +"'的手术预约已经存在,手术名称为" + operationSchedule.getOperation() +"的数据丢弃"); } }else{ originalOperationReservation.setOperationName(operationSchedule.getOperation()); objectDao.saveOrUpdate(originalOperationReservation); } } //成功时,返回状态0 resultXml += "0"; }catch(Exception e){ e.printStackTrace(); //异常导致失败时,返回状态1 resultXml += "1"; } resultXml += ""; } resultXml += ""; response.setResponseBody(resultXml); }catch(Exception e){ e.printStackTrace(); throw new RuntimeException("requestBody参数有误"); } }else{ response.getResponseHeader().setErrCode("1000"); response.getResponseHeader().setErrMessage("requestBody参数为空"); } return null; } }