Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/FindPatientInfoByTreatmentNumDaoImpl.java =================================================================== diff -u --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/FindPatientInfoByTreatmentNumDaoImpl.java (revision 0) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/FindPatientInfoByTreatmentNumDaoImpl.java (revision 35669) @@ -0,0 +1,164 @@ +package com.forgon.disinfectsystem.datasynchronization.dao.gzs12rmyy; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import com.forgon.disinfectsystem.datasynchronization.dao.FindPatientInfoByTreatmentNumDao; +import com.forgon.disinfectsystem.datasynchronization.model.PatientInfoVO; + +/** + * 广州市第十二人民医院门诊病人信息接口开发GZS12RMYY-50 + */ +public class FindPatientInfoByTreatmentNumDaoImpl implements + FindPatientInfoByTreatmentNumDao { + + Logger logger = Logger.getLogger(FindPatientInfoByTreatmentNumDaoImpl.class); + + @Override + public PatientInfoVO[] findPatientInfoByTreatmentNum(String treatmentNum) { + if(StringUtils.isBlank(treatmentNum)){ + return null; + } + try { + String request = HttpClientHelper.buildRequest(treatmentNum); + logger.info("门诊病人信息同步接口请求信息:" + request); + String responce = HttpClientHelper.sendPost(DatasyncConstant.queryURL, request); + logger.info("门诊病人信息同步接口返回信息:" + responce); + List patientInfoVOList = buildPatientInfoVOList(responce); + if(CollectionUtils.isNotEmpty(patientInfoVOList)){ + PatientInfoVO[] patientInfoArray = {patientInfoVOList.get(0)}; + return patientInfoArray; + } + } catch (Exception e) { + e.printStackTrace(); + logger.info("门诊病人信息接口查询失败:" + e.getMessage()); + } + return null; + } + + /** + * 解析并返回患者信息 + * @param responce + * @return + */ + private List buildPatientInfoVOList(String responce) { + List patientInfoVOList = new ArrayList(); + if(StringUtils.isBlank(responce)){ + return patientInfoVOList; + } + JSONObject json = new JSONObject(); + try { + json = JSONObject.fromObject(responce); + } catch (Exception e) { + e.printStackTrace(); + logger.info("门诊病人信息同步接口解析返回消息失败:" + e.getMessage()); + } + if(json == null){ + return patientInfoVOList; + } + + JSONArray data = json.optJSONArray("data"); + if(data == null || data.size() == 0){ + return patientInfoVOList; + } + + for(int i=0;i() { + @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; + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + Date date1 = sdf.parse(o1.getOperationTime()); + Date date2 = sdf.parse(o2.getOperationTime()); + return date2.compareTo(date1); + } catch (ParseException e) { + logger.debug("病人信息排序出错(手术时间【OPERATIONTIME】字段格式错误)!"); + e.printStackTrace(); + } + return 0; + } + }); + } + + return patientInfoVOList; + } + + /** + * 根据出生日期计算年龄 + * @param birthday + * @return + */ + private static String getAgeByBirthday(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; + } + +} Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/service/DataSynchronizationManagerImpl.java =================================================================== diff -u -r35657 -r35669 --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/service/DataSynchronizationManagerImpl.java (.../DataSynchronizationManagerImpl.java) (revision 35657) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/service/DataSynchronizationManagerImpl.java (.../DataSynchronizationManagerImpl.java) (revision 35669) @@ -143,6 +143,11 @@ private FindPatientInfoByTreatmentNumDao findPatientInfoByTreatmentNumDao2; /** + * 根据诊疗号查询病人信息(第3个数据源) + */ + private FindPatientInfoByTreatmentNumDao findPatientInfoByTreatmentNumDao3; + + /** * 物资数据同步 */ private InventoryDao inventoryDao; @@ -225,6 +230,11 @@ FindPatientInfoByTreatmentNumDao findPatientInfoByTreatmentNumDao2) { this.findPatientInfoByTreatmentNumDao2 = findPatientInfoByTreatmentNumDao2; } + + public void setFindPatientInfoByTreatmentNumDao3( + FindPatientInfoByTreatmentNumDao findPatientInfoByTreatmentNumDao3) { + this.findPatientInfoByTreatmentNumDao3 = findPatientInfoByTreatmentNumDao3; + } public void setInventoryDao(InventoryDao inventoryDao) { this.inventoryDao = inventoryDao; @@ -584,6 +594,16 @@ "根据疹疗号"+ treatmentNum +"(第2个数据源)同步到的结果为:" + JSONArray.fromObject(patientInfoVOArray)); } } + + //判断如果第二个数据源未查到相应病人数据时,则从第三个数据源查询病人信息 + if(patientInfoVOArray == null || patientInfoVOArray.length == 0){ + if(findPatientInfoByTreatmentNumDao3 != null){ + patientInfoVOArray = + findPatientInfoByTreatmentNumDao3.findPatientInfoByTreatmentNum(treatmentNum); + appLogManager.saveLog(AcegiHelper.getLoginUser(), Log.MODEL_SYNC, Log.TYPE_QUERY, + "根据疹疗号"+ treatmentNum +"(第3个数据源)同步到的结果为:" + JSONArray.fromObject(patientInfoVOArray)); + } + } return patientInfoVOArray; } Index: ssts-web/src/main/webapp/disinfectsystem/config/gzs12rmyy/spring/applicationContext-his-gzs12rmyy.xml =================================================================== diff -u -r35657 -r35669 --- ssts-web/src/main/webapp/disinfectsystem/config/gzs12rmyy/spring/applicationContext-his-gzs12rmyy.xml (.../applicationContext-his-gzs12rmyy.xml) (revision 35657) +++ ssts-web/src/main/webapp/disinfectsystem/config/gzs12rmyy/spring/applicationContext-his-gzs12rmyy.xml (.../applicationContext-his-gzs12rmyy.xml) (revision 35669) @@ -95,6 +95,9 @@ + + + Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/HttpClientHelper.java =================================================================== diff -u --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/HttpClientHelper.java (revision 0) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/HttpClientHelper.java (revision 35669) @@ -0,0 +1,58 @@ +package com.forgon.disinfectsystem.datasynchronization.dao.gzs12rmyy; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import net.sf.json.JSONObject; + +import org.apache.log4j.Logger; + +/** + * 广州市第十二人民医院门诊病人信息接口GZS12RMYY-50 + */ +public class HttpClientHelper { + + public static Logger logger = Logger.getLogger(HttpClientHelper.class); + + public static String sendPost(String url, String content) throws Exception { + BufferedReader in = null; + String result = ""; + URL realUrl = new URL(url); + HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setDoOutput(true); + conn.setDoInput(true); + conn.setInstanceFollowRedirects(true); + conn.getOutputStream().write(content.getBytes("UTF-8")); + conn.getOutputStream().flush(); + InputStream is = conn.getInputStream(); + in = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String line; + while ((line = in.readLine()) != null) { + result += line; + } + try{is.close();}catch(Exception e){} + try{in.close();}catch(Exception e){} + return result; + } + + /** + * 创建请求参数 + * @param treatmentNum 门诊号 + * @return + */ + public static String buildRequest(String treatmentNum) { + JSONObject request = new JSONObject(); + request.put("beginTime", ""); + request.put("cardNo", ""); + request.put("clinicCode", treatmentNum); + request.put("endTime", ""); + request.put("idNo", ""); + request.put("patientName", ""); + return request.toString(); + } + +} Index: ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/DatasyncConstant.java =================================================================== diff -u --- ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/DatasyncConstant.java (revision 0) +++ ssts-datasync-default-impl/src/main/java/com/forgon/disinfectsystem/datasynchronization/dao/gzs12rmyy/DatasyncConstant.java (revision 35669) @@ -0,0 +1,13 @@ +package com.forgon.disinfectsystem.datasynchronization.dao.gzs12rmyy; + +/** + * 广州市第十二人民医院接口相关常量 + */ +public class DatasyncConstant { + + /** + * 门诊病人信息接口地址 + */ + public final static String queryURL = "http://192.168.7.183:7800/roc/patient-service/api/v1/register/patient/getFinOprRegList"; + +}