Search in sources :

Example 96 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method searchEncounters_shouldNotAddResourcesForEmptyRevInclude.

@Test
public void searchEncounters_shouldNotAddResourcesForEmptyRevInclude() {
    when(encounterService.searchForEncounters(any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(encounter), PREFERRED_SIZE, COUNT));
    HashSet<Include> revIncludes = new HashSet<>();
    IBundleProvider results = resourceProvider.searchEncounter(null, null, null, null, null, null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.size(), equalTo(1));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.ENCOUNTER));
    assertThat(((Encounter) resultList.iterator().next()).getId(), equalTo(ENCOUNTER_UUID));
}
Also used : Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 97 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method updateEncounter_shouldThrowInvalidRequestForMissingId.

@Test(expected = InvalidRequestException.class)
public void updateEncounter_shouldThrowInvalidRequestForMissingId() {
    Encounter noIdEncounter = new Encounter();
    when(encounterService.update(ENCOUNTER_UUID, noIdEncounter)).thenThrow(InvalidRequestException.class);
    resourceProvider.updateEncounter(new IdType().setValue(ENCOUNTER_UUID), noIdEncounter);
}
Also used : Encounter(org.hl7.fhir.r4.model.Encounter) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 98 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method searchEncounters_shouldAddRelatedResourcesForRevInclude.

@Test
public void searchEncounters_shouldAddRelatedResourcesForRevInclude() {
    when(encounterService.searchForEncounters(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Arrays.asList(encounter, new Observation()), PREFERRED_SIZE, COUNT));
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include("Observation:encounter"));
    IBundleProvider results = resourceProvider.searchEncounter(null, null, null, null, null, null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.size(), greaterThanOrEqualTo(2));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.ENCOUNTER));
    assertThat(resultList.get(1).fhirType(), equalTo(FhirConstants.OBSERVATION));
    assertThat(((Encounter) resultList.iterator().next()).getId(), equalTo(ENCOUNTER_UUID));
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 99 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method getEncounterHistory_shouldReturnProvenanceResources.

@Test
public void getEncounterHistory_shouldReturnProvenanceResources() {
    IdType id = new IdType();
    id.setValue(ENCOUNTER_UUID);
    when(encounterService.get(ENCOUNTER_UUID)).thenReturn(encounter);
    List<Resource> resources = resourceProvider.getEncounterHistoryById(id);
    assertThat(resources, not(empty()));
    assertThat(resources.stream().findAny().isPresent(), is(true));
    assertThat(resources.stream().findAny().get().getResourceType().name(), Matchers.equalTo(Provenance.class.getSimpleName()));
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 100 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method searchEncounters_shouldReturnMatchingEncounters.

@Test
public void searchEncounters_shouldReturnMatchingEncounters() {
    List<Encounter> encounters = new ArrayList<>();
    encounters.add(encounter);
    when(encounterService.searchForEncounters(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(encounters, PREFERRED_SIZE, COUNT));
    ReferenceAndListParam subjectReference = new ReferenceAndListParam();
    subjectReference.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)));
    IBundleProvider results = resourceProvider.searchEncounter(null, null, null, subjectReference, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.ENCOUNTER));
    assertThat(((Encounter) resultList.iterator().next()).getId(), equalTo(ENCOUNTER_UUID));
}
Also used : ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.r4.model.Encounter) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)238 Encounter (org.hl7.fhir.r4.model.Encounter)166 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)100 Test (org.junit.jupiter.api.Test)93 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)87 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)79 Reference (org.hl7.fhir.r4.model.Reference)71 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)66 ArrayList (java.util.ArrayList)64 Resource (org.hl7.fhir.r4.model.Resource)61 Bundle (org.hl7.fhir.r4.model.Bundle)60 Date (java.util.Date)57 Encounter (org.hl7.fhir.dstu3.model.Encounter)55 Coding (org.hl7.fhir.r4.model.Coding)51 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)49 Reference (org.hl7.fhir.dstu3.model.Reference)48 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)43 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)41 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)38 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37