package com.yihu.ehr.common.config; import com.yihu.ehr.model.PatientIdentity; import com.yihu.ehr.util.log.LogUtil; import com.yihu.ehr.util.operator.StringUtil; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import java.io.InputStream; import java.util.HashMap; import java.util.List; public class SysConfig { public static final String HOS_RESOURCES_CONFIG = "/config/sys.config.xml"; public static String publicKey; public static String orgCode; public static String tempFile; public static String registerDataSet; public static String registerIdCardNo; private static volatile SysConfig instance = null; private HashMap patientIdentityHashMap; private SysConfig() { patientIdentityHashMap = new HashMap<>(); init(); } public static SysConfig getInstance() { if (instance == null) { synchronized (SysConfig.class) { if (instance == null) { try { instance = new SysConfig(); } catch (Exception e) { e.printStackTrace(); } } } } return instance; } public void finalize() throws Throwable { } public String getTempFile() { return this.tempFile; } public void setTempFile(String tempFile) { this.tempFile = tempFile; } public String getPublicKey() { return publicKey; } public void setPublicKey(String publicKey) { this.publicKey = publicKey; } public PatientIdentity getPatientIdentity(String dataSetCode) { return patientIdentityHashMap.get(dataSetCode); } public HashMap getPatientIdentityHashMap() { return patientIdentityHashMap; } public String getRegisterDataSet() { return registerDataSet; } public String getRegisterIdCardNo() { return registerIdCardNo; } private Document getDocument() throws DocumentException { SAXReader reader = new SAXReader(); Document document = null; try { InputStream inputStream = SysConfig.class.getResourceAsStream(HOS_RESOURCES_CONFIG); document = reader.read(inputStream); return document; } catch (DocumentException de) { LogUtil.fatal("读取classpath下的xml文档路径发生异常"); return null; } } private void init() { try { Document document = this.getDocument(); Element rootElement = null; if (document != null) { rootElement = document.getRootElement(); } if (rootElement == null) { return; } this.initCrawler(rootElement); this.initEventNo(rootElement); } catch (Exception e) { LogUtil.error(e); } } private void initCrawler(Element rootElement) { List queueDataSets = rootElement.element("patient_queue").elements("dataset"); for (Object obj : queueDataSets) { if (obj instanceof Element) { Element element = (Element) obj; String dataSetCode = element.attributeValue("code"); String eventNo = element.elementTextTrim("event_no"); String refTime = element.elementTextTrim("ref_time"); PatientIdentity patientIdentity = new PatientIdentity(eventNo, refTime); patientIdentityHashMap.put(dataSetCode, patientIdentity); } } Element registerDataSet = rootElement.element("register").element("dataset"); this.registerDataSet = registerDataSet.attributeValue("code"); this.registerIdCardNo = registerDataSet.elementTextTrim("id_card"); } private void initEventNo(Element rootElement) { List eventItems = rootElement.element("event_no").elements("item"); for (Object obj : eventItems) { if (obj instanceof Element) { Element element = (Element) obj; String eventNoCode = element.getTextTrim(); PatientIdentity.addEventNoCode(eventNoCode); } } } public void setOrgCode(String orgCode) { this.orgCode = orgCode; } public String getOrgCode() { return orgCode; } public Boolean isEmptyOrgCode() { if (StringUtil.isEmpty(orgCode)) { return true; } else { return false; } } }//end SysConfig