From 8e36fb07d5d25263b7c8aa3406897e1cdd38acc4 Mon Sep 17 00:00:00 2001 From: Adam Stevenson Date: Fri, 16 Dec 2022 21:25:07 -0700 Subject: [PATCH 1/2] Updated the Cql FhirDal to implement Translator FhirDal and introduce JpaCRFhirDal for CR plugin --- .../org/opencds/cqf/ruler/cql/JpaFhirDal.java | 57 +++++++++++++----- .../opencds/cqf/ruler/cql/JpaFhirDalIT.java | 56 +++++++++++++++++ .../org/opencds/cqf/ruler/cr/CrConfig.java | 6 ++ .../opencds/cqf/ruler/cr/JpaCRFhirDal.java | 60 +++++++++++++++++++ .../cqf/ruler/cr/JpaCRFhirDalFactory.java | 7 +++ .../ruler/cr/dstu3/ExpressionEvaluation.java | 24 ++++---- .../cr/dstu3/service/MeasureService.java | 4 +- .../cqf/ruler/cr/r4/ExpressionEvaluation.java | 22 +++---- .../ruler/cr/r4/service/MeasureService.java | 4 +- 9 files changed, 199 insertions(+), 41 deletions(-) create mode 100644 plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java create mode 100644 plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDal.java create mode 100644 plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDalFactory.java diff --git a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java index afa7b5cdc..b1f6ccf5f 100644 --- a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java +++ b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java @@ -1,13 +1,20 @@ package org.opencds.cqf.ruler.cql; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; -import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal; - +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.UriParam; +import org.cqframework.fhir.api.FhirDal; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; +import java.util.UUID; @SuppressWarnings("unchecked") public class JpaFhirDal implements FhirDal { @@ -45,16 +52,38 @@ public void delete(IIdType theId) { } - // TODO: the search interfaces need some work @Override - public Iterable search(String theResourceType) { - return this.daoRegistry.getResourceDao(theResourceType).search(SearchParameterMap.newSynchronous()) - .getAllResources(); - } + public IBaseBundle search(String theResourceType, Map>> theSearchParameters) { + SearchParameterMap searchParameterMap = new SearchParameterMap(); + for(Map.Entry>> entry : theSearchParameters.entrySet()) { + String keyValue = entry.getKey(); - @Override - public Iterable searchByUrl(String theResourceType, String theUrl) { - return this.daoRegistry.getResourceDao(theResourceType) - .search(SearchParameterMap.newSynchronous().add("url", new UriParam(theUrl))).getAllResources(); + for(List value : entry.getValue()) { + for (IQueryParameterType query : value) { + searchParameterMap.add(keyValue, query); + } + } + } + + List searchResults = this.daoRegistry.getResourceDao(theResourceType).search(searchParameterMap).getAllResources(); + + FhirContext fhirContext = FhirContext.forR4Cached(); + ca.uhn.fhir.util.BundleBuilder builder = new ca.uhn.fhir.util.BundleBuilder(fhirContext); + builder + .setBundleField("type", "searchset") + .setBundleField("id", UUID.randomUUID().toString()) + .setMetaField("lastUpdated", builder.newPrimitive("instant", new java.util.Date())); + + for (var resource : searchResults) { + IBase entry = builder.addEntry(); + builder.addToEntry(entry, "resource", resource); + + // Add search results + IBase search = builder.addSearch(entry); + builder.setSearchField(search, "mode", "match"); + builder.setSearchField(search, "score", builder.newPrimitive("decimal", BigDecimal.ONE)); + } + + return builder.getBundle(); } } diff --git a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java new file mode 100644 index 000000000..3a842c5c5 --- /dev/null +++ b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java @@ -0,0 +1,56 @@ +package org.opencds.cqf.ruler.cql; + +import ca.uhn.fhir.jpa.partition.SystemRequestDetails; +import ca.uhn.fhir.model.api.IQueryParameterType; +import ca.uhn.fhir.rest.param.UriParam; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.DomainResource; +import org.hl7.fhir.r4.model.Library; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; +import org.opencds.cqf.ruler.test.DaoIntegrationTest; +import org.opencds.cqf.ruler.test.RestIntegrationTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { JpaFhirDalIT.class, CqlConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) +public class JpaFhirDalIT extends DaoIntegrationTest { + + @Autowired + private JpaFhirDalFactory fhirDalFactory; + + @Test + void testFhirDalSearch() throws Exception { + JpaFhirDal fhirDal = new JpaFhirDal(this.getDaoRegistry()); + + String url = "http://somewhere.org/fhir/Library/SpecificationLibrary"; + this.update(newResource(Library.class, "A123").setUrl(url)); + this.update(newResource(Library.class, "A234").setUrl(url)); + + Map>> searchParams = new HashMap<>(); + + List urlList = new ArrayList<>(); + urlList.add(new UriParam(Canonicals.getUrl(url))); + searchParams.put("url", List.of(urlList)); + + IBaseBundle searchResultsBundle = (IBaseBundle)fhirDal.search(Canonicals.getResourceType(url), searchParams); + + assertNotNull(searchResultsBundle); + assertTrue(((Bundle)searchResultsBundle).getEntry().size() == 2); + assertTrue(((Bundle)searchResultsBundle).getType() == Bundle.BundleType.SEARCHSET); + assertTrue(((Library)((Bundle)searchResultsBundle).getEntryFirstRep().getResource()).getUrl().equals(url)); + } +} diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/CrConfig.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/CrConfig.java index 2b5dbd02f..858129f3d 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/CrConfig.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/CrConfig.java @@ -2,6 +2,7 @@ import java.util.function.Function; +import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver; import org.opencds.cqf.cql.evaluator.measure.MeasureEvaluationOptions; import org.opencds.cqf.external.annotations.OnDSTU3Condition; @@ -36,6 +37,11 @@ SearchParameterResolver searchParameterResolver(FhirContext fhirContext) { return new SearchParameterResolver(fhirContext); } + @Bean + JpaCRFhirDalFactory jpaCRFhirDalFactory(DaoRegistry daoRegistry) { + return rd -> new JpaCRFhirDal(daoRegistry, rd); + } + @Bean @Conditional(OnDSTU3Condition.class) public org.opencds.cqf.ruler.cr.dstu3.provider.ActivityDefinitionApplyProvider dstu3ActivityDefinitionApplyProvider() { diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDal.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDal.java new file mode 100644 index 000000000..f6038f135 --- /dev/null +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDal.java @@ -0,0 +1,60 @@ +package org.opencds.cqf.ruler.cr; + +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; +import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal; + +import ca.uhn.fhir.jpa.api.dao.DaoRegistry; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.UriParam; + +@SuppressWarnings("unchecked") +public class JpaCRFhirDal implements FhirDal { + + protected final DaoRegistry daoRegistry; + protected final RequestDetails requestDetails; + + public JpaCRFhirDal(DaoRegistry daoRegistry) { + this(daoRegistry, null); + } + + public JpaCRFhirDal(DaoRegistry daoRegistry, RequestDetails requestDetails) { + this.daoRegistry = daoRegistry; + this.requestDetails = requestDetails; + } + + @Override + public void create(IBaseResource theResource) { + this.daoRegistry.getResourceDao(theResource.fhirType()).create(theResource, requestDetails); + } + + @Override + public IBaseResource read(IIdType theId) { + return this.daoRegistry.getResourceDao(theId.getResourceType()).read(theId, requestDetails); + } + + @Override + public void update(IBaseResource theResource) { + this.daoRegistry.getResourceDao(theResource.fhirType()).update(theResource, requestDetails); + } + + @Override + public void delete(IIdType theId) { + this.daoRegistry.getResourceDao(theId.getResourceType()).delete(theId, requestDetails); + + } + + // TODO: the search interfaces need some work + @Override + public Iterable search(String theResourceType) { + return this.daoRegistry.getResourceDao(theResourceType).search(SearchParameterMap.newSynchronous()) + .getAllResources(); + } + + @Override + public Iterable searchByUrl(String theResourceType, String theUrl) { + return this.daoRegistry.getResourceDao(theResourceType) + .search(SearchParameterMap.newSynchronous().add("url", new UriParam(theUrl))).getAllResources(); + } +} diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDalFactory.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDalFactory.java new file mode 100644 index 000000000..a482b057a --- /dev/null +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/JpaCRFhirDalFactory.java @@ -0,0 +1,7 @@ +package org.opencds.cqf.ruler.cr; + +import ca.uhn.fhir.rest.api.server.RequestDetails; + +public interface JpaCRFhirDalFactory { + JpaCRFhirDal create(RequestDetails requestDetails); +} diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluation.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluation.java index e0227c033..a922eba44 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluation.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluation.java @@ -25,8 +25,8 @@ import org.opencds.cqf.cql.evaluator.cql2elm.content.InMemoryLibrarySourceProvider; import org.opencds.cqf.ruler.cql.CqlProperties; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; -import org.opencds.cqf.ruler.cql.JpaFhirDal; -import org.opencds.cqf.ruler.cql.JpaFhirDalFactory; +import org.opencds.cqf.ruler.cr.JpaCRFhirDal; +import org.opencds.cqf.ruler.cr.JpaCRFhirDalFactory; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; import org.opencds.cqf.ruler.cql.LibraryLoaderFactory; @@ -47,7 +47,7 @@ public class ExpressionEvaluation { @Autowired private JpaTerminologyProviderFactory jpaTerminologyProviderFactory; @Autowired - private JpaFhirDalFactory jpaFhirDalFactory; + private JpaCRFhirDalFactory jpaCRFhirDalFactory; @Autowired private CqlProperties cqlProperties; @Autowired @@ -60,8 +60,8 @@ public class ExpressionEvaluation { */ public Object evaluateInContext(DomainResource instance, String cql, Boolean aliasedExpression, String patientId, RequestDetails theRequest) { - JpaFhirDal jpaFhirDal = jpaFhirDalFactory.create(theRequest); - List libraries = getLibraryReferences(instance, jpaFhirDal, theRequest); + JpaCRFhirDal jpaCRFhirDal = jpaCRFhirDalFactory.create(theRequest); + List libraries = getLibraryReferences(instance, jpaCRFhirDal, theRequest); // String fhirVersion = // this.context.getVersion().getVersion().getFhirVersionString(); String fhirVersion = "3.0.0"; @@ -90,7 +90,7 @@ public Object evaluateInContext(DomainResource instance, String cql, Boolean ali // log error } if (executionLibrary == null) { - Library library = (Library) jpaFhirDal.read(new IdType("Library", vi.getId())); + Library library = (Library) jpaCRFhirDal.read(new IdType("Library", vi.getId())); vi.setId(library.getName()); if (library.getVersion() != null) { vi.setVersion(library.getVersion()); @@ -104,7 +104,7 @@ public Object evaluateInContext(DomainResource instance, String cql, Boolean ali "library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", - buildIncludes(tempLibraryLoader, jpaFhirDal, libraries), instance.fhirType(), instance.fhirType(), + buildIncludes(tempLibraryLoader, jpaCRFhirDal, libraries), instance.fhirType(), instance.fhirType(), instance.fhirType(), vi.getId() + ".\"" + cql + "\""); // String source = String.format("library LocalLibrary using FHIR version '1.8' // include FHIRHelpers version '1.8' called FHIRHelpers %s parameter %s %s @@ -120,7 +120,7 @@ public Object evaluateInContext(DomainResource instance, String cql, Boolean ali "library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", - buildIncludes(tempLibraryLoader, jpaFhirDal, libraries), instance.fhirType(), instance.fhirType(), + buildIncludes(tempLibraryLoader, jpaCRFhirDal, libraries), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql); } @@ -149,7 +149,7 @@ public Object evaluateInContext(DomainResource instance, String cql, Boolean ali return context.resolveExpressionRef("Expression").evaluate(context); } - private List getLibraryReferences(DomainResource instance, JpaFhirDal jpaFhirDal, + private List getLibraryReferences(DomainResource instance, JpaCRFhirDal jpaCRFhirDal, RequestDetails theRequest) { List references = new ArrayList<>(); @@ -157,7 +157,7 @@ private List getLibraryReferences(DomainResource instance, JpaFhirDal for (Resource resource : instance.getContained()) { if (resource instanceof Library) { resource.setId(resource.getIdElement().getIdPart().replace("#", "")); - jpaFhirDal.update((Library) resource); + jpaCRFhirDal.update((Library) resource); // getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(), // getLibraryLoader().toElmLibrary((Library) resource)); } @@ -192,7 +192,7 @@ else if (instance instanceof Measure) { return cleanReferences(references); } - private String buildIncludes(LibraryLoader libraryLoader, JpaFhirDal jpaFhirDal, Iterable references) { + private String buildIncludes(LibraryLoader libraryLoader, JpaCRFhirDal jpaCRFhirDal, Iterable references) { StringBuilder builder = new StringBuilder(); for (Reference reference : references) { VersionedIdentifier vi = getVersionedIdentifierFromReference(reference); @@ -212,7 +212,7 @@ private String buildIncludes(LibraryLoader libraryLoader, JpaFhirDal jpaFhirDal, } // else check local data for Library to get name and version from else { - Library library = (Library) jpaFhirDal.read(reference.getReferenceElement()); + Library library = (Library) jpaCRFhirDal.read(reference.getReferenceElement()); builder.append(buildLibraryIncludeString(reference, library.getName(), library.getVersion())); } } diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java index 12326d310..0280618f9 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java @@ -20,7 +20,7 @@ import org.opencds.cqf.cql.evaluator.measure.MeasureEvaluationOptions; import org.opencds.cqf.ruler.behavior.DaoRegistryUser; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; -import org.opencds.cqf.ruler.cql.JpaFhirDalFactory; +import org.opencds.cqf.ruler.cr.JpaCRFhirDalFactory; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -44,7 +44,7 @@ public class MeasureService implements DaoRegistryUser { private JpaLibrarySourceProviderFactory libraryContentProviderFactory; @Autowired - private JpaFhirDalFactory fhirDalFactory; + private JpaCRFhirDalFactory fhirDalFactory; @Autowired private Map globalLibraryCache; diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java index f2b8111c1..a44ac612f 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java @@ -26,8 +26,8 @@ import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; import org.opencds.cqf.ruler.cql.CqlProperties; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; -import org.opencds.cqf.ruler.cql.JpaFhirDal; -import org.opencds.cqf.ruler.cql.JpaFhirDalFactory; +import org.opencds.cqf.ruler.cr.JpaCRFhirDal; +import org.opencds.cqf.ruler.cr.JpaCRFhirDalFactory; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; import org.opencds.cqf.ruler.cql.LibraryLoaderFactory; @@ -49,7 +49,7 @@ public class ExpressionEvaluation { @Autowired private JpaTerminologyProviderFactory jpaTerminologyProviderFactory; @Autowired - private JpaFhirDalFactory jpaFhirDalFactory; + private JpaCRFhirDalFactory jpaCRFhirDalFactory; @Autowired private CqlProperties cqlProperties; @Autowired @@ -72,7 +72,7 @@ public Object evaluateInContext(DomainResource instance, String cql, String pati private Context setupContext(DomainResource instance, String cql, String patientId, Boolean aliasedExpression, RequestDetails theRequest) { - JpaFhirDal jpaFhirDal = jpaFhirDalFactory.create(theRequest); + JpaCRFhirDal jpaCRFhirDal = jpaCRFhirDalFactory.create(theRequest); List libraries = getLibraryReferences(instance, theRequest); String fhirVersion = this.fhirContext.getVersion().getVersion().getFhirVersionString(); @@ -105,7 +105,7 @@ private Context setupContext(DomainResource instance, String cql, String patient // log error } if (executionLibrary == null) { - Library library = (Library) jpaFhirDal + Library library = (Library) jpaCRFhirDal .read(new IdType("Library", Canonicals.getIdPart(libraries.get(0)))); vi.setId(library.getName()); if (library.getVersion() != null) { @@ -116,7 +116,7 @@ private Context setupContext(DomainResource instance, String cql, String patient "library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", - buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), + buildIncludes(tempLibraryLoader, jpaCRFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), vi.getId() + ".\"" + cql + "\""); } else { @@ -124,7 +124,7 @@ private Context setupContext(DomainResource instance, String cql, String patient "library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", - buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), + buildIncludes(tempLibraryLoader, jpaCRFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql); } @@ -144,7 +144,7 @@ private List getLibraryReferences(DomainResource instance, Reques for (Resource resource : instance.getContained()) { if (resource instanceof Library) { resource.setId(resource.getIdElement().getIdPart().replace("#", "")); - this.jpaFhirDalFactory.create(theRequest).update((Library) resource); + this.jpaCRFhirDalFactory.create(theRequest).update((Library) resource); // getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(), // getLibraryLoader().toElmLibrary((Library) resource)); } @@ -179,8 +179,8 @@ else if (instance instanceof Measure) { return cleanReferences(references); } - private String buildIncludes(LibraryLoader libraryLoader, JpaFhirDal jpaFhirDal, Iterable references, - RequestDetails theRequest) { + private String buildIncludes(LibraryLoader libraryLoader, JpaCRFhirDal jpaCRFhirDal, Iterable references, + RequestDetails theRequest) { StringBuilder builder = new StringBuilder(); for (CanonicalType reference : references) { @@ -200,7 +200,7 @@ private String buildIncludes(LibraryLoader libraryLoader, JpaFhirDal jpaFhirDal, } // else check local data for Library to get name and version from else { - Library library = (Library) jpaFhirDal.read(new IdType("Library", Canonicals.getIdPart(reference))); + Library library = (Library) jpaCRFhirDal.read(new IdType("Library", Canonicals.getIdPart(reference))); builder.append(buildLibraryIncludeString( new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))); } diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java index 7a1b84b1f..dd584cf0d 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java @@ -20,7 +20,7 @@ import org.opencds.cqf.cql.evaluator.measure.MeasureEvaluationOptions; import org.opencds.cqf.ruler.behavior.r4.MeasureReportUser; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; -import org.opencds.cqf.ruler.cql.JpaFhirDalFactory; +import org.opencds.cqf.ruler.cr.JpaCRFhirDalFactory; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -44,7 +44,7 @@ public class MeasureService implements MeasureReportUser { private JpaLibrarySourceProviderFactory libraryContentProviderFactory; @Autowired - private JpaFhirDalFactory fhirDalFactory; + private JpaCRFhirDalFactory fhirDalFactory; @Autowired private Map globalLibraryCache; From f2d4633717faa7d6d0232e15d74f5c50be37d825 Mon Sep 17 00:00:00 2001 From: Adam Stevenson Date: Sat, 17 Dec 2022 17:11:11 -0700 Subject: [PATCH 2/2] updated fhirContext used by JpaFhirDal --- .../src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java | 4 +--- .../test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java | 6 ------ 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java index b1f6ccf5f..5a8e40bb7 100644 --- a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java +++ b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaFhirDal.java @@ -1,6 +1,5 @@ package org.opencds.cqf.ruler.cql; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.model.api.IQueryParameterType; @@ -67,8 +66,7 @@ public IBaseBundle search(String theResourceType, Map searchResults = this.daoRegistry.getResourceDao(theResourceType).search(searchParameterMap).getAllResources(); - FhirContext fhirContext = FhirContext.forR4Cached(); - ca.uhn.fhir.util.BundleBuilder builder = new ca.uhn.fhir.util.BundleBuilder(fhirContext); + ca.uhn.fhir.util.BundleBuilder builder = new ca.uhn.fhir.util.BundleBuilder(daoRegistry.getSystemDao().getContext()); builder .setBundleField("type", "searchset") .setBundleField("id", UUID.randomUUID().toString()) diff --git a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java index 3a842c5c5..1d778805f 100644 --- a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java +++ b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirDalIT.java @@ -1,19 +1,13 @@ package org.opencds.cqf.ruler.cql; -import ca.uhn.fhir.jpa.partition.SystemRequestDetails; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.rest.param.UriParam; import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.DomainResource; import org.hl7.fhir.r4.model.Library; -import org.hl7.fhir.r4.model.Patient; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; import org.opencds.cqf.ruler.test.DaoIntegrationTest; -import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;