diff --git a/.gitignore b/.gitignore
index 1fbf608..4871089 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@
api/.settings/
omod/.settings/
target/
+.idea/
+*.iml
\ No newline at end of file
diff --git a/api/pom.xml b/api/pom.xml
index f67fc79..ed7211f 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -5,7 +5,7 @@
org.openmrs.module
shr-contenthandler
- 2.1.0
+ 2.2.0
shr-contenthandler-api
diff --git a/api/src/main/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandler.java b/api/src/main/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandler.java
index 8826782..a8f3136 100644
--- a/api/src/main/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandler.java
+++ b/api/src/main/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandler.java
@@ -13,11 +13,7 @@
*/
package org.openmrs.module.shr.contenthandler;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -99,14 +95,42 @@ private Obs createUnstructuredDataObs(Content content) {
return res;
}
+ private static final Map conceptCache = Collections.synchronizedMap(new HashMap());
+ private static final String GP_CACHE_CONCEPTS_BY_NAME = "shr.contenthandler.cacheConceptsByName";
+ private static Boolean cacheConceptsByName = null;
+
private Concept getUnstructuredAttachmentConcept(CodedValue formatCode) {
- ConceptService cs = Context.getConceptService();
- String conceptName = getUnstructuredAttachmentConceptName(formatCode);
+ synchronized (this) {
+ if (cacheConceptsByName == null) {
+ if (Context.getAdministrationService().getGlobalProperty(GP_CACHE_CONCEPTS_BY_NAME).equalsIgnoreCase("true")) {
+ cacheConceptsByName = true;
+ } else {
+ cacheConceptsByName = false;
+ }
+ }
+ }
+
+ ConceptService cs = Context.getConceptService();
+ String conceptName = getUnstructuredAttachmentConceptName(formatCode);
+
+ if (cacheConceptsByName) {
+ Integer conceptId = conceptCache.get(conceptName);
+
+ if (conceptId != null) {
+ return cs.getConcept(conceptId);
+ }
+ }
+
Concept res = cs.getConceptByName(conceptName);
- if (res==null) {
+ if (res == null) {
res = buildUnstructuredAttachmentConcept(conceptName);
- cs.saveConcept(res);
+ res = cs.saveConcept(res);
}
+
+ if (cacheConceptsByName) {
+ conceptCache.put(conceptName, res.getConceptId());
+ }
+
return res;
}
diff --git a/api/src/test/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandlerTest.java b/api/src/test/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandlerTest.java
index 12e6d80..ff8ed0a 100644
--- a/api/src/test/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandlerTest.java
+++ b/api/src/test/java/org/openmrs/module/shr/contenthandler/UnstructuredDataHandlerTest.java
@@ -60,6 +60,7 @@ public class UnstructuredDataHandlerTest extends BaseModuleContextSensitiveTest
public void before() {
//Use our in-memory complex obs handler
Context.getAdministrationService().setGlobalProperty(UnstructuredDataHandler.UNSTRUCTURED_DATA_HANDLER_GLOBAL_PROP, "InMemoryComplexObsHandler");
+ Context.getAdministrationService().setGlobalProperty("shr.contenthandler.cacheConceptsByName", "false");
}
/**
diff --git a/omod/pom.xml b/omod/pom.xml
index daccbc1..12628b9 100644
--- a/omod/pom.xml
+++ b/omod/pom.xml
@@ -5,7 +5,7 @@
org.openmrs.module
shr-contenthandler
- 2.1.0
+ 2.2.0
shr-contenthandler-omod
diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml
index c82e8d6..de301fc 100644
--- a/omod/src/main/resources/config.xml
+++ b/omod/src/main/resources/config.xml
@@ -27,6 +27,13 @@
The complex obs handler to use for unstructured data.
+
+ shr.contenthandler.cacheConceptsByName
+ false
+
+ Enables unstructured attachment concepts to be cached by name. This greatly improves performance. You MUST restart the module for this to take effect. Note: changes to concept names will only be picked up on server restart.
+
+
diff --git a/pom.xml b/pom.xml
index 32b3fce..eafd39c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
org.openmrs.module
shr-contenthandler
- 2.1.0
+ 2.2.0
pom
SHR Content Handler Module
Provides interfaces and services for dynamically linking content processors with particular content types.