Search in sources :

Example 91 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderTest method getLastnEncountersObservations_shouldReturnRecentNEncountersObservationsWhenNoCodeIsSpecified.

@Test
public void getLastnEncountersObservations_shouldReturnRecentNEncountersObservationsWhenNoCodeIsSpecified() {
    NumberParam max = new NumberParam(2);
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_UUID);
    referenceParam.addValue(new ReferenceOrListParam().add(patient));
    TokenAndListParam categories = new TokenAndListParam().addAnd(new TokenParam().setValue("laboratory"));
    when(observationService.getLastnEncountersObservations(max, referenceParam, categories, null)).thenReturn(new MockIBundleProvider<>(Collections.singletonList(observation), 10, 1));
    IBundleProvider results = resourceProvider.getLastnEncountersObservations(max, referenceParam, null, categories, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(resultList.get(0), notNullValue());
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.OBSERVATION));
    assertThat(resultList.get(0).getIdElement().getIdPart(), equalTo(OBSERVATION_UUID));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) NumberParam(ca.uhn.fhir.rest.param.NumberParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 92 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderTest method getLastnEncountersObservations_shouldReturnRecentNEncountersObservationsWhenBothCodeAndCategoryIsNotSpecified.

@Test
public void getLastnEncountersObservations_shouldReturnRecentNEncountersObservationsWhenBothCodeAndCategoryIsNotSpecified() {
    NumberParam max = new NumberParam(2);
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_UUID);
    referenceParam.addValue(new ReferenceOrListParam().add(patient));
    when(observationService.getLastnEncountersObservations(max, referenceParam, null, null)).thenReturn(new MockIBundleProvider<>(Collections.singletonList(observation), 10, 1));
    IBundleProvider results = resourceProvider.getLastnEncountersObservations(max, referenceParam, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(resultList.get(0), notNullValue());
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.OBSERVATION));
    assertThat(resultList.get(0).getIdElement().getIdPart(), equalTo(OBSERVATION_UUID));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) NumberParam(ca.uhn.fhir.rest.param.NumberParam) 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)

Example 93 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderTest method deleteObservation_shouldDeleteObservation.

@Test
public void deleteObservation_shouldDeleteObservation() {
    when(observationService.delete(OBSERVATION_UUID)).thenReturn(observation);
    OperationOutcome result = resourceProvider.deleteObservationResource(new IdType().setValue(OBSERVATION_UUID));
    assertThat(result, notNullValue());
    assertThat(result.getIssue(), notNullValue());
    assertThat(result.getIssueFirstRep().getSeverity(), equalTo(OperationOutcome.IssueSeverity.INFORMATION));
    assertThat(result.getIssueFirstRep().getDetails().getCodingFirstRep().getCode(), equalTo("MSG_DELETED"));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 94 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderTest method getPatientResourceHistory_shouldReturnProvenanceResources.

@Test
public void getPatientResourceHistory_shouldReturnProvenanceResources() {
    IdType id = new IdType();
    id.setValue(OBSERVATION_UUID);
    when(observationService.get(OBSERVATION_UUID)).thenReturn(observation);
    List<Resource> resources = resourceProvider.getObservationHistoryById(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 95 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class PatientFhirResourceProviderTest method searchForPatients_shouldAddRelatedResourcesForRevInclude.

@Test
public void searchForPatients_shouldAddRelatedResourcesForRevInclude() {
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include("Observation:patient"));
    when(patientService.searchForPatients(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(revIncludes)))).thenReturn(new MockIBundleProvider<>(Arrays.asList(patient, new Observation()), 10, 1));
    IBundleProvider results = resourceProvider.searchPatients(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = getResources(results);
    assertThat(results, notNullValue());
    assertThat(resultList.size(), greaterThanOrEqualTo(2));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.PATIENT));
    assertThat(resultList.get(1).fhirType(), equalTo(FhirConstants.OBSERVATION));
    assertThat(((Patient) resultList.iterator().next()).getId(), equalTo(PATIENT_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)

Aggregations

Observation (org.hl7.fhir.r4.model.Observation)237 Test (org.junit.Test)235 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)114 Test (org.junit.jupiter.api.Test)107 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)106 Observation (org.hl7.fhir.dstu3.model.Observation)94 Bundle (org.hl7.fhir.r4.model.Bundle)88 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)64 ArrayList (java.util.ArrayList)62 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)59 Resource (org.hl7.fhir.r4.model.Resource)55 Bundle (org.hl7.fhir.dstu3.model.Bundle)53 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)47 Coding (org.hl7.fhir.r4.model.Coding)46 Reference (org.hl7.fhir.r4.model.Reference)41 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)37 TokenParam (ca.uhn.fhir.rest.param.TokenParam)37 Date (java.util.Date)34 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)32 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)32