-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* repository search by id * apply formatting * separate InMemory test * remove redundancy * search by id update * search by id update test * search by id update test script * reformat * Fix repository and tests * Fixes for repo api --------- Co-authored-by: Jonathan Percival <jonathan.i.percival@gmail.com> Co-authored-by: JP <jonathan.percival@smilecdr.com>
- Loading branch information
1 parent
a9af518
commit 4e7500e
Showing
4 changed files
with
119 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...utility/src/test/java/org/opencds/cqf/fhir/utility/repository/InMemoryRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.opencds.cqf.fhir.utility.repository; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.hl7.fhir.r4.model.Encounter; | ||
import org.hl7.fhir.r4.model.IdType; | ||
import org.hl7.fhir.r4.model.Library; | ||
import org.junit.jupiter.api.Test; | ||
import org.opencds.cqf.fhir.api.Repository; | ||
import org.opencds.cqf.fhir.utility.search.Searches; | ||
|
||
public class InMemoryRepositoryTest { | ||
|
||
Repository repository; | ||
|
||
public InMemoryRepositoryTest() { | ||
repository = new InMemoryFhirRepository(FhirContext.forR4Cached()); | ||
repository.update(new Library().setId("Library/example1")); | ||
repository.update(new Library().setUrl("http://example.com/123").setId("Library/example2")); | ||
repository.update(new Encounter().setId("Encounter/example3")); | ||
} | ||
|
||
@Test | ||
public void testRead() { | ||
IBaseResource res = repository.read(Library.class, new IdType("Library/example1"), null); | ||
assertEquals("example1", res.getIdElement().getIdPart()); | ||
} | ||
|
||
@Test | ||
public void testSearchWithId() { | ||
|
||
var search = Searches.byId("example1"); | ||
var resources = repository.search(Bundle.class, Library.class, search); | ||
// The _id parameter will be consumed if the index is being used. | ||
assertTrue(search.isEmpty()); | ||
assertEquals(1, resources.getEntry().size()); | ||
|
||
search = Searches.byId("example3"); | ||
resources = repository.search(Bundle.class, Encounter.class, search); | ||
assertTrue(search.isEmpty()); | ||
assertEquals(1, resources.getEntry().size()); | ||
|
||
search = Searches.byId("2345"); | ||
resources = repository.search(Bundle.class, Encounter.class, search); | ||
assertTrue(search.isEmpty()); | ||
assertEquals(0, resources.getEntry().size()); | ||
|
||
search = Searches.byId("example1", "example2"); | ||
resources = repository.search(Bundle.class, Library.class, search); | ||
assertTrue(search.isEmpty()); | ||
assertEquals(2, resources.getEntry().size()); | ||
} | ||
|
||
@Test | ||
public void testSearchWithUrl() { | ||
var resources = repository.search(Bundle.class, Library.class, Searches.byUrl("http://example.com/123")); | ||
assertEquals(1, resources.getEntry().size()); | ||
} | ||
} |