Skip to content

Commit

Permalink
tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
melihaydogd committed Jun 27, 2024
1 parent 146e41e commit 858bb60
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.model.entity.StorageSettings;
import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.extractor.ISearchParamExtractor;
import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR5;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorService;
Expand Down Expand Up @@ -123,7 +124,7 @@ PartitionSettings partitionSettings() {
}

@Bean
SearchParamExtractorR5 searchParamExtractorR5() {
ISearchParamExtractor searchParamExtractorR5() {
return new SearchParamExtractorR5();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import ca.uhn.fhir.jpa.cache.ResourceChangeResult;
import ca.uhn.fhir.jpa.cache.ResourceVersionMap;
import ca.uhn.fhir.jpa.cache.config.RegisteredResourceListenerFactoryConfig;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.entity.StorageSettings;
import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.extractor.ISearchParamExtractor;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR4;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorService;
import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult;
import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryResourceMatcher;
Expand Down Expand Up @@ -375,6 +378,17 @@ private SearchParameter buildSearchParameter(Enumerations.PublicationStatus theS
@Configuration
@Import(RegisteredResourceListenerFactoryConfig.class)
static class SpringConfig {

@Bean
PartitionSettings partitionSettings() {
return new PartitionSettings();
}

@Bean
ISearchParamExtractor searchParamExtractorR5() {
return new SearchParamExtractorR4();
}

@Bean
FhirContext fhirContext() {
return ourFhirContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test
@Autowired
StorageSettings myStorageSettings;

private void assertSupported(IBaseResource resource, String criteria) {
assertTrue(mySearchParamMatcher.match(criteria, resource, null).supported());
assertEquals(SubscriptionMatchingStrategy.IN_MEMORY, mySubscriptionStrategyEvaluator.determineStrategy(criteria));
}

private void assertUnsupported(IBaseResource resource, String criteria) {
assertFalse(mySearchParamMatcher.match(criteria, resource, null).supported());
assertEquals(SubscriptionMatchingStrategy.DATABASE, mySubscriptionStrategyEvaluator.determineStrategy(criteria));
Expand Down Expand Up @@ -185,17 +190,17 @@ public void testProcedureRequest() {
}

@Test
public void testObservationContextTypeUnsupported() {
public void testObservationContextTypeSupported() {
String criteria = "Observation?code=17861-6&context.type=IHD";
{
Observation obs = new Observation();
obs.getCode().addCoding().setCode("XXX");
assertNotMatched(obs, criteria, SubscriptionMatchingStrategy.DATABASE);
assertNotMatched(obs, criteria, SubscriptionMatchingStrategy.IN_MEMORY);
}
{
Observation obs = new Observation();
obs.getCode().addCoding().setCode("17861-6");
assertUnsupported(obs, criteria);
assertSupported(obs, criteria);
}
}

Expand All @@ -206,12 +211,12 @@ public void testObservationContextTypeUnsupportedReverse() {
{
Observation obs = new Observation();
obs.getCode().addCoding().setCode("XXX");
assertNotMatched(obs, criteria, SubscriptionMatchingStrategy.DATABASE);
assertNotMatched(obs, criteria, SubscriptionMatchingStrategy.IN_MEMORY);
}
{
Observation obs = new Observation();
obs.getCode().addCoding().setCode("17861-6");
assertUnsupported(obs, criteria);
assertSupported(obs, criteria);
}
}

Expand Down Expand Up @@ -299,12 +304,12 @@ public void testBloodTest() {
{
Observation obs = new Observation();
obs.getCode().addCoding().setCode("FR_Org1Blood2nd");
assertUnsupported(obs, criteria);
assertSupported(obs, criteria);
}
{
Observation obs = new Observation();
obs.getCode().addCoding().setCode("XXX");
assertNotMatched(obs, criteria, SubscriptionMatchingStrategy.DATABASE);
assertNotMatched(obs, criteria, SubscriptionMatchingStrategy.IN_MEMORY);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testInMemory() {
assertInMemory("ProcedureRequest?intent=original-order");
assertInMemory("MedicationRequest?intent=instance-order&category=outpatient&date==2018-10-19");
assertInMemory("MedicationRequest?intent=plan&category=outpatient&status=suspended,entered-in-error,cancelled,stopped");
assertDatabase("Observation?code=FR_Org1Blood2nd,FR_Org1Blood3rd,FR_Org%201BldCult,FR_Org2Blood2nd,FR_Org2Blood3rd,FR_Org%202BldCult,FR_Org3Blood2nd,FR_Org3Blood3rd,FR_Org3BldCult,FR_Org4Blood2nd,FR_Org4Blood3rd,FR_Org4BldCult,FR_Org5Blood2nd,FR_Org5Blood3rd,FR_Org%205BldCult,FR_Org6Blood2nd,FR_Org6Blood3rd,FR_Org6BldCult,FR_Org7Blood2nd,FR_Org7Blood3rd,FR_Org7BldCult,FR_Org8Blood2nd,FR_Org8Blood3rd,FR_Org8BldCult,FR_Org9Blood2nd,FR_Org9Blood3rd,FR_Org9BldCult,FR_Bld2ndCulture,FR_Bld3rdCulture,FR_Blood%20Culture,FR_Com1Bld3rd,FR_Com1BldCult,FR_Com2Bld2nd,FR_Com2Bld3rd,FR_Com2BldCult,FR_CultureBld2nd,FR_CultureBld3rd,FR_CultureBldCul,FR_GmStainBldCul,FR_GramStain2Bld,FR_GramStain3Bld,FR_GramStNegBac&context.type=IHD");
assertInMemory("Observation?code=FR_Org1Blood2nd,FR_Org1Blood3rd,FR_Org%201BldCult,FR_Org2Blood2nd,FR_Org2Blood3rd,FR_Org%202BldCult,FR_Org3Blood2nd,FR_Org3Blood3rd,FR_Org3BldCult,FR_Org4Blood2nd,FR_Org4Blood3rd,FR_Org4BldCult,FR_Org5Blood2nd,FR_Org5Blood3rd,FR_Org%205BldCult,FR_Org6Blood2nd,FR_Org6Blood3rd,FR_Org6BldCult,FR_Org7Blood2nd,FR_Org7Blood3rd,FR_Org7BldCult,FR_Org8Blood2nd,FR_Org8Blood3rd,FR_Org8BldCult,FR_Org9Blood2nd,FR_Org9Blood3rd,FR_Org9BldCult,FR_Bld2ndCulture,FR_Bld3rdCulture,FR_Blood%20Culture,FR_Com1Bld3rd,FR_Com1BldCult,FR_Com2Bld2nd,FR_Com2Bld3rd,FR_Com2BldCult,FR_CultureBld2nd,FR_CultureBld3rd,FR_CultureBldCul,FR_GmStainBldCul,FR_GramStain2Bld,FR_GramStain3Bld,FR_GramStNegBac&context.type=IHD");
assertInMemory("Procedure?category=Hemodialysis");
assertInMemory("Procedure?code=HD_Standard&status=completed&location=Lab123");
assertInMemory("Procedure?code=HD_Standard&status=completed");
Expand All @@ -33,8 +33,8 @@ public void testInMemory() {
assertInMemory("Observation?code=111111111&_format=xml");
assertInMemory("Observation?code=SNOMED-CT|123&_format=xml");

assertDatabase("Observation?code=17861-6&context.type=IHD");
assertDatabase("Observation?context.type=IHD&code=17861-6");
assertInMemory("Observation?code=17861-6&context.type=IHD");
assertInMemory("Observation?context.type=IHD&code=17861-6");

try {
mySubscriptionStrategyEvaluator.determineStrategy("Observation?codeee=SNOMED-CT|123&_format=xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testDatabaseStrategyMeta() throws InterruptedException {
Subscription subscription = createSubscription(databaseCriteria, null, ourNotificationListenerServer);
List<Coding> tag = subscription.getMeta().getTag();
assertEquals(HapiExtensions.EXT_SUBSCRIPTION_MATCHING_STRATEGY, tag.get(0).getSystem());
assertEquals(SubscriptionMatchingStrategy.DATABASE.toString(), tag.get(0).getCode());
assertEquals(SubscriptionMatchingStrategy.IN_MEMORY.toString(), tag.get(0).getCode());
}

@Test
Expand Down Expand Up @@ -607,8 +607,8 @@ public void testSubscriptionActivatesDatabaseTag() throws Exception {
assertThat(tags).hasSize(1);
Coding tag = tags.get(0);
assertEquals(HapiExtensions.EXT_SUBSCRIPTION_MATCHING_STRATEGY, tag.getSystem());
assertEquals(SubscriptionMatchingStrategy.DATABASE.toString(), tag.getCode());
assertEquals("Database", tag.getDisplay());
assertEquals(SubscriptionMatchingStrategy.IN_MEMORY.toString(), tag.getCode());
assertEquals("In-memory", tag.getDisplay());

// Wait for subscription to be moved to active
await().until(() -> Subscription.SubscriptionStatus.ACTIVE.equals(myClient.read().resource(Subscription.class).withId(subscriptionId.toUnqualifiedVersionless()).execute().getStatus()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,19 +1183,16 @@ public void testValidateParameters_InvalidPostFetch_InvalidResourceType() {
}

@Test
public void testValidateParameters_InvalidPostFetch_UnsupportedParam() {
public void testValidateParameters_ValidPostFetch_SupportedParam() {
// Setup
final BulkExportJobParameters options = createOptionsWithPostFetchFilterUrl("Observation?subject.identifier=blah");

// Test
try {
startNewJob(options);
fail();
} catch (InvalidRequestException e) {

// Verify
assertThat(e.getMessage()).contains("Chained parameters are not supported");

// Fail
fail();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ private InMemoryMatchResult match(String criteria, Resource theResource) {
return mySearchParamMatcher.match(criteria, theResource, null);
}

private void assertSupported(Resource resource, SearchParameterMap theParams) {
InMemoryMatchResult result = match(resource, theParams);
assertTrue(result.supported());
assertEquals(SubscriptionMatchingStrategy.IN_MEMORY, mySubscriptionStrategyEvaluator.determineStrategy(getCriteria(resource, theParams)));
}

private void assertUnsupported(Resource resource, SearchParameterMap theParams) {
InMemoryMatchResult result = match(resource, theParams);
assertFalse(result.supported());
Expand All @@ -155,7 +161,7 @@ private void assertUnsupported(Resource resource, SearchParameterMap theParams)
*/

@Test
public void testChainReferenceUnsupported() {
public void testChainReferenceSupported() {
Encounter enc1 = new Encounter();
IIdType pid1 = new IdType("Patient", 1L);
enc1.getSubject().setReference(pid1.getValue());
Expand All @@ -164,15 +170,15 @@ public void testChainReferenceUnsupported() {

map = new SearchParameterMap();
map.add(Encounter.SP_SUBJECT, new ReferenceParam("subject", "foo|bar").setChain("identifier"));
assertUnsupported(enc1, map);
assertSupported(enc1, map);

MedicationAdministration ma = new MedicationAdministration();
IIdType mid1 = new IdType("Medication", 1L);
ma.setMedication(new Reference(mid1));

map = new SearchParameterMap();
map.add(MedicationAdministration.SP_MEDICATION, new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("code", "04823543"))));
assertUnsupported(ma, map);
assertSupported(ma, map);
}

@Test
Expand Down Expand Up @@ -597,7 +603,7 @@ public void testSearchResourceLinkWithChainUnsupported() {
obs02.setSubject(new Reference(patientId02));

SearchParameterMap params = new SearchParameterMap().add(Observation.SP_SUBJECT, new ReferenceParam(Patient.SP_IDENTIFIER, "urn:system|testSearchResourceLinkWithChain01"));
assertUnsupported(obs01, params);
assertSupported(obs01, params);
}

@Test
Expand Down

0 comments on commit 858bb60

Please sign in to comment.