Search in sources :

Example 76 with Observation

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

the class ObservationTranslatorImplTest method toFhirResource_shouldConvertConceptToCodeableConcept.

@Test
public void toFhirResource_shouldConvertConceptToCodeableConcept() {
    Obs observation = new Obs();
    Concept concept = new Concept();
    concept.setUuid(CONCEPT_UUID);
    observation.setConcept(concept);
    CodeableConcept codeableConcept = new CodeableConcept();
    codeableConcept.setId(CONCEPT_UUID);
    when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept);
    Observation result = observationTranslator.toFhirResource(observation);
    assertThat(result.getCode(), notNullValue());
    assertThat(result.getCode().getId(), equalTo(CONCEPT_UUID));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 77 with Observation

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

the class ObservationTranslatorImplTest method toFhirResource_shouldAddReferenceRange.

@Test
public void toFhirResource_shouldAddReferenceRange() {
    ConceptNumeric conceptNumeric = new ConceptNumeric();
    conceptNumeric.setLowNormal(LOW_NORMAL_VALUE);
    conceptNumeric.setHiNormal(HIGH_NORMAL_VALUE);
    Obs observation = new Obs();
    observation.setConcept(conceptNumeric);
    observation.setValueNumeric((HIGH_NORMAL_VALUE + LOW_NORMAL_VALUE) / 2);
    Observation.ObservationReferenceRangeComponent referenceRangeComponent = new Observation.ObservationReferenceRangeComponent();
    referenceRangeComponent.setLow(new Quantity().setValue(LOW_NORMAL_VALUE));
    referenceRangeComponent.setHigh(new Quantity().setValue(HIGH_NORMAL_VALUE));
    List<Observation.ObservationReferenceRangeComponent> referenceRangeComponentList = new ArrayList<>();
    referenceRangeComponentList.add(referenceRangeComponent);
    when(referenceRangeTranslator.toFhirResource(conceptNumeric)).thenReturn(referenceRangeComponentList);
    Observation result = observationTranslator.toFhirResource(observation);
    assertThat(result.getReferenceRange(), notNullValue());
    assertThat(result.getReferenceRange(), hasItem(hasProperty("low", hasProperty("value", equalTo(BigDecimal.valueOf(LOW_NORMAL_VALUE))))));
    assertThat(result.getReferenceRange(), hasItem(hasProperty("high", hasProperty("value", equalTo(BigDecimal.valueOf(HIGH_NORMAL_VALUE))))));
}
Also used : Obs(org.openmrs.Obs) ConceptNumeric(org.openmrs.ConceptNumeric) Observation(org.hl7.fhir.r4.model.Observation) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.Test)

Example 78 with Observation

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

the class ObservationTranslatorImplTest method toOpenmrsType_shouldReturnNullObsOrderWhenFhirBasedOnIsNull.

@Test
public void toOpenmrsType_shouldReturnNullObsOrderWhenFhirBasedOnIsNull() {
    Observation observation = new Observation();
    Obs obs = new Obs();
    Obs result = observationTranslator.toOpenmrsType(obs, observation);
    assertThat(result.getOrder(), nullValue());
}
Also used : Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.Test)

Example 79 with Observation

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

the class ObservationTranslatorImplTest method toOpenmrsType_shouldTranslateBasedOnToObsOrder.

@Test
public void toOpenmrsType_shouldTranslateBasedOnToObsOrder() {
    Observation observation = new Observation();
    Reference orderReference = new Reference();
    orderReference.setType("Order");
    orderReference.setId(ORDER_UUID);
    observation.setBasedOn(Collections.singletonList(orderReference));
    Obs obs = new Obs();
    Order order = new Order();
    order.setUuid(ORDER_UUID);
    when(basedOnReferenceTranslator.toOpenmrsType(orderReference)).thenReturn(order);
    Obs result = observationTranslator.toOpenmrsType(obs, observation);
    assertThat(result, notNullValue());
    assertThat(result.getOrder(), notNullValue());
    assertThat(result.getOrder(), equalTo(order));
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) Reference(org.hl7.fhir.r4.model.Reference) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.Test)

Example 80 with Observation

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

the class ObservationTranslatorImplTest method toFhirResource_shouldConvertUuidToId.

@Test
public void toFhirResource_shouldConvertUuidToId() {
    Obs observation = new Obs();
    observation.setUuid(OBS_UUID);
    Observation result = observationTranslator.toFhirResource(observation);
    assertThat(result.getId(), equalTo(OBS_UUID));
}
Also used : Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) 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