fix bug on hapifhirdal searchbyurl to account for version (#5087)

* fix bug on hapifhirdal searchbyurl to account for version

* update return type to bundleIterable, update test to validate

* add clinical-reasoning 3.0.0-PRE5

* added test comments, updated search, explicit variables

* add example comment to search cases

* fix typo

* spotless apply edits

---------

Co-authored-by: justin.mckelvy <justin.mckelvy@smilecdr.com>
This commit is contained in:
Justin McKelvy 2023-07-14 12:17:13 -06:00 committed by GitHub
parent 633a2d156d
commit d6fae7c673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 354 additions and 5 deletions

View File

@ -21,7 +21,10 @@ package ca.uhn.fhir.cr.common;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
@ -74,9 +77,28 @@ public class HapiFhirDal implements FhirDal {
@Override @Override
public Iterable<IBaseResource> searchByUrl(String theResourceType, String theUrl) { public Iterable<IBaseResource> searchByUrl(String theResourceType, String theUrl) {
var b = this.myDaoRegistry // version example "http://content.smilecdr.com/fhir/dqm/Library/ImmunizationStatusRoutine|2.0.1"
.getResourceDao(theResourceType) if (theUrl.contains("|")) {
.search(new SearchParameterMap().add("url", new UriParam(theUrl)), myRequestDetails); String[] urlSplit = theUrl.split("\\|");
return new BundleIterable(myRequestDetails, b); String urlBase = urlSplit[0];
String urlVersion = urlSplit[1];
IBundleProvider versionResource = this.myDaoRegistry
.getResourceDao(theResourceType)
.search(
SearchParameterMap.newSynchronous()
.add("url", new UriParam(urlBase))
.add("version", new TokenParam(urlVersion)),
new SystemRequestDetails());
return new BundleIterable(myRequestDetails, versionResource);
} else {
// standard example "http://content.smilecdr.com/fhir/dqm/Library/ImmunizationStatusRoutine"
IBundleProvider standardResource = this.myDaoRegistry
.getResourceDao(theResourceType)
.search(
SearchParameterMap.newSynchronous().add("url", new UriParam(theUrl)),
new SystemRequestDetails());
return new BundleIterable(myRequestDetails, standardResource);
}
} }
} }

View File

@ -3,12 +3,18 @@ package ca.uhn.fhir.cr.r4;
import ca.uhn.fhir.cr.BaseCrR4Test; import ca.uhn.fhir.cr.BaseCrR4Test;
import ca.uhn.fhir.cr.common.HapiFhirDal; import ca.uhn.fhir.cr.common.HapiFhirDal;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.Iterator;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* This class tests the functionality of HapiFhirDal operations inside the cr module * This class tests the functionality of HapiFhirDal operations inside the cr module
*/ */
@ -37,4 +43,24 @@ public class HapiFhirDalR4Test extends BaseCrR4Test {
assertEquals(63, counter, "Patient search results don't match available resources"); assertEquals(63, counter, "Patient search results don't match available resources");
} }
@Test
void canSearchVersionURL(){
// load measure resource with Library url containing "|", this is the only component of test resource used.
loadBundle("ca/uhn/fhir/cr/r4/Bundle-HapiFhirDalTestLibrary.json");
HapiFhirDal hapiFhirDal = new HapiFhirDal(this.getDaoRegistry(), null);
// library url from loaded measure resource
String url = "http://content.smilecdr.com/fhir/dqm/Library/ImmunizationStatusRoutine|2.0.1";
// search for resource given url
Iterable<IBaseResource> result = hapiFhirDal.searchByUrl("Library", url);
Iterator<IBaseResource> resultIter = result.iterator();
// validate Iterable contains a resource
assertTrue(resultIter.hasNext());
// get resource
IBaseResource finalResult = resultIter.next();
// validate resource exists
assertNotNull(finalResult);
}
} }

File diff suppressed because one or more lines are too long

View File

@ -987,7 +987,7 @@
<elastic_apm_version>1.28.4</elastic_apm_version> <elastic_apm_version>1.28.4</elastic_apm_version>
<!-- CQL Support --> <!-- CQL Support -->
<clinical-reasoning.version>3.0.0-PRE4</clinical-reasoning.version> <clinical-reasoning.version>3.0.0-PRE5</clinical-reasoning.version>
<!-- Site properties --> <!-- Site properties -->
<fontawesomeVersion>5.4.1</fontawesomeVersion> <fontawesomeVersion>5.4.1</fontawesomeVersion>