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));
}
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);
}
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));
}
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))))));
}
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());
}
Aggregations