SysConfig.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package com.yihu.ehr.common.config;
  2. import com.yihu.ehr.model.PatientIdentity;
  3. import com.yihu.ehr.util.log.LogUtil;
  4. import com.yihu.ehr.util.operator.StringUtil;
  5. import org.dom4j.Document;
  6. import org.dom4j.DocumentException;
  7. import org.dom4j.Element;
  8. import org.dom4j.io.SAXReader;
  9. import java.io.InputStream;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. public class SysConfig {
  13. public static final String HOS_RESOURCES_CONFIG = "/config/sys.config.xml";
  14. public static String publicKey;
  15. public static String orgCode;
  16. public static String tempFile;
  17. public static String registerDataSet;
  18. public static String registerIdCardNo;
  19. private static volatile SysConfig instance = null;
  20. private HashMap<String, PatientIdentity> patientIdentityHashMap;
  21. private SysConfig() {
  22. patientIdentityHashMap = new HashMap<>();
  23. init();
  24. }
  25. public static SysConfig getInstance() {
  26. if (instance == null) {
  27. synchronized (SysConfig.class) {
  28. if (instance == null) {
  29. try {
  30. instance = new SysConfig();
  31. } catch (Exception e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. }
  36. }
  37. return instance;
  38. }
  39. public void finalize() throws Throwable {
  40. }
  41. public String getTempFile() {
  42. return this.tempFile;
  43. }
  44. public void setTempFile(String tempFile) {
  45. this.tempFile = tempFile;
  46. }
  47. public String getPublicKey() {
  48. return publicKey;
  49. }
  50. public void setPublicKey(String publicKey) {
  51. this.publicKey = publicKey;
  52. }
  53. public PatientIdentity getPatientIdentity(String dataSetCode) {
  54. return patientIdentityHashMap.get(dataSetCode);
  55. }
  56. public HashMap<String, PatientIdentity> getPatientIdentityHashMap() {
  57. return patientIdentityHashMap;
  58. }
  59. public String getRegisterDataSet() {
  60. return registerDataSet;
  61. }
  62. public String getRegisterIdCardNo() {
  63. return registerIdCardNo;
  64. }
  65. private Document getDocument() throws DocumentException {
  66. SAXReader reader = new SAXReader();
  67. Document document = null;
  68. try {
  69. InputStream inputStream = SysConfig.class.getResourceAsStream(HOS_RESOURCES_CONFIG);
  70. document = reader.read(inputStream);
  71. return document;
  72. } catch (DocumentException de) {
  73. LogUtil.fatal("读取classpath下的xml文档路径发生异常");
  74. return null;
  75. }
  76. }
  77. private void init() {
  78. try {
  79. Document document = this.getDocument();
  80. Element rootElement = null;
  81. if (document != null) {
  82. rootElement = document.getRootElement();
  83. }
  84. if (rootElement == null) {
  85. return;
  86. }
  87. this.initCrawler(rootElement);
  88. this.initEventNo(rootElement);
  89. } catch (Exception e) {
  90. LogUtil.error(e);
  91. }
  92. }
  93. private void initCrawler(Element rootElement) {
  94. List queueDataSets = rootElement.element("patient_queue").elements("dataset");
  95. for (Object obj : queueDataSets) {
  96. if (obj instanceof Element) {
  97. Element element = (Element) obj;
  98. String dataSetCode = element.attributeValue("code");
  99. String eventNo = element.elementTextTrim("event_no");
  100. String refTime = element.elementTextTrim("ref_time");
  101. PatientIdentity patientIdentity = new PatientIdentity(eventNo, refTime);
  102. patientIdentityHashMap.put(dataSetCode, patientIdentity);
  103. }
  104. }
  105. Element registerDataSet = rootElement.element("register").element("dataset");
  106. this.registerDataSet = registerDataSet.attributeValue("code");
  107. this.registerIdCardNo = registerDataSet.elementTextTrim("id_card");
  108. }
  109. private void initEventNo(Element rootElement) {
  110. List eventItems = rootElement.element("event_no").elements("item");
  111. for (Object obj : eventItems) {
  112. if (obj instanceof Element) {
  113. Element element = (Element) obj;
  114. String eventNoCode = element.getTextTrim();
  115. PatientIdentity.addEventNoCode(eventNoCode);
  116. }
  117. }
  118. }
  119. public void setOrgCode(String orgCode) {
  120. this.orgCode = orgCode;
  121. }
  122. public String getOrgCode() {
  123. return orgCode;
  124. }
  125. public Boolean isEmptyOrgCode() {
  126. if (StringUtil.isEmpty(orgCode)) {
  127. return true;
  128. } else {
  129. return false;
  130. }
  131. }
  132. }//end SysConfig