Search in sources :

Example 96 with Observation

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

the class ObservationTranslatorImplTest method toFhirResource_shouldConvertPatientToReference.

@Test
public void toFhirResource_shouldConvertPatientToReference() {
    Obs observation = new Obs();
    Patient patient = new Patient();
    patient.setUuid(PATIENT_UUID);
    observation.setPerson(patient);
    Reference patientReference = new Reference();
    patientReference.setType("Patient");
    patientReference.setId(PATIENT_UUID);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    Observation result = observationTranslator.toFhirResource(observation);
    assertThat(result.getSubject(), notNullValue());
    assertThat(result.getSubject().getType(), equalTo("Patient"));
    assertThat(result.getSubject().getId(), equalTo(PATIENT_UUID));
}
Also used : Obs(org.openmrs.Obs) Reference(org.hl7.fhir.r4.model.Reference) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.openmrs.Patient) Test(org.junit.Test)

Example 97 with Observation

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

the class ObservationTranslatorImplTest method toOpenmrsType_shouldThrowExceptionIfObsNull.

@Test(expected = NullPointerException.class)
public void toOpenmrsType_shouldThrowExceptionIfObsNull() {
    Observation observation = new Observation();
    observationTranslator.toOpenmrsType(null, observation);
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.Test)

Example 98 with Observation

use of org.hl7.fhir.r4.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 99 with Observation

use of org.hl7.fhir.r4.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 100 with Observation

use of org.hl7.fhir.r4.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)

Aggregations

Observation (org.hl7.fhir.r4.model.Observation)237 Test (org.junit.Test)235 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)114 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)106 Test (org.junit.jupiter.api.Test)102 Observation (org.hl7.fhir.dstu3.model.Observation)88 Bundle (org.hl7.fhir.r4.model.Bundle)88 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)64 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)59 ArrayList (java.util.ArrayList)58 Resource (org.hl7.fhir.r4.model.Resource)55 Bundle (org.hl7.fhir.dstu3.model.Bundle)52 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)33 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)32 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)32