Skip to content

Commit

Permalink
Cache cds-service definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Sep 18, 2021
1 parent 9dd6b61 commit 21f8d18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class CdsHooksServlet extends HttpServlet {

private LibraryHelper libraryHelper;

private JsonArray services;

@SuppressWarnings("unchecked")
@Override
public void init() {
Expand Down Expand Up @@ -277,8 +279,16 @@ private void printStackTrack(Exception e, HttpServletResponse response) throws I
response.getWriter().println(exceptionAsString);
}

private synchronized JsonArray getServicesArray() {
if (this.services == null) {
this.services = getServices().get("services").getAsJsonArray();
}

return this.services;
}

private JsonObject getService(String service) {
JsonArray services = getServices().get("services").getAsJsonArray();
JsonArray services = getServicesArray();
List<String> ids = new ArrayList<>();
for (JsonElement element : services) {
if (element.isJsonObject() && element.getAsJsonObject().has("id")) {
Expand Down
27 changes: 1 addition & 26 deletions r4/src/main/java/org/opencds/cqf/r4/helpers/LibraryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,6 @@ public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(
TranslatingLibraryLoader translatingLibraryLoader = new TranslatingLibraryLoader(modelManager, contentProviders,
translatorOptions);

return new CacheAwareLibraryLoaderDecorator(translatingLibraryLoader, libraryCache) {
@Override
protected Boolean translatorOptionsMatch(Library library) {
return true;
}
};
}

@Override
public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(
org.cqframework.cql.cql2elm.LibrarySourceProvider provider) {
ModelManager modelManager = new CacheAwareModelManager(this.modelCache);
LibraryManager libraryManager = new LibraryManager(modelManager);
libraryManager.getLibrarySourceLoader().clearProviders();

libraryManager.getLibrarySourceLoader().registerProvider(provider);

TranslatingLibraryLoader translatingLibraryLoader = new TranslatingLibraryLoader(modelManager, null,
translatorOptions);

return new CacheAwareLibraryLoaderDecorator(translatingLibraryLoader, libraryCache) {
@Override
protected Boolean translatorOptionsMatch(Library library) {
return true;
}
};
return new CacheAwareLibraryLoaderDecorator(translatingLibraryLoader, libraryCache);
}
}
12 changes: 11 additions & 1 deletion r4/src/main/java/org/opencds/cqf/r4/servlet/CdsHooksServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class CdsHooksServlet extends HttpServlet {

private LibraryHelper libraryHelper;

private JsonArray services;

@SuppressWarnings("unchecked")
@Override
public void init() {
Expand Down Expand Up @@ -284,7 +286,7 @@ private void printStackTrack(Exception e, HttpServletResponse response) throws I
}

private JsonObject getService(String service) {
JsonArray services = getServices().get("services").getAsJsonArray();
JsonArray services = getServicesArray();
List<String> ids = new ArrayList<>();
for (JsonElement element : services) {
if (element.isJsonObject() && element.getAsJsonObject().has("id")) {
Expand All @@ -298,6 +300,14 @@ private JsonObject getService(String service) {
"Cannot resolve service: " + service + "\nAvailable services: " + ids.toString());
}

private synchronized JsonArray getServicesArray() {
if (this.services == null) {
this.services = getServices().get("services").getAsJsonArray();
}

return this.services;
}

private JsonObject getServices() {
DiscoveryResolutionR4 discoveryResolutionR4 = new DiscoveryResolutionR4(
FhirContext.forCached(FhirVersionEnum.R4).newRestfulGenericClient(HapiProperties.getServerAddress()));
Expand Down

0 comments on commit 21f8d18

Please sign in to comment.