Search in sources :

Example 31 with Quantity

use of org.hl7.fhir.r4.model.Quantity in project elexis-server by elexis.

the class ObservationTest method laboratoryObservations.

@Test
public void laboratoryObservations() throws FHIRException {
    // search by patient and category
    Bundle results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Condition.CATEGORY.exactly().code("laboratory")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    assertFalse(results.getEntry().isEmpty());
    @SuppressWarnings("unchecked") List<Observation> observations = (List<Observation>) ((List<?>) results.getEntry().parallelStream().map(be -> be.getResource()).collect(Collectors.toList()));
    for (Observation observation : observations) {
        assertTrue(observation.hasEffectiveDateTimeType());
        assertTrue(observation.hasValue());
        assertNotNull(observation.getCode());
        List<Coding> coding = observation.getCode().getCoding();
        assertFalse(coding.isEmpty());
        for (Coding code : coding) {
            if (code.getCode().contains("NUMERIC")) {
                if (observation.hasValueQuantity()) {
                    Quantity quantityValue = observation.getValueQuantity();
                    assertNotNull(quantityValue);
                } else if (observation.hasValueStringType()) {
                    StringType stringValue = observation.getValueStringType();
                    assertNotNull(stringValue);
                    assertTrue(Character.isDigit(stringValue.toString().charAt(0)));
                } else {
                    fail("Unexpected vaue type" + observation.getValue());
                }
                List<ObservationReferenceRangeComponent> refs = observation.getReferenceRange();
                assertFalse(refs.isEmpty());
            } else if (code.getCode().contains("TEXT")) {
                StringType stringValue = observation.getValueStringType();
                assertNotNull(stringValue);
            }
        }
    }
}
Also used : TransientCoding(ch.elexis.core.findings.util.model.TransientCoding) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) Quantity(org.hl7.fhir.r4.model.Quantity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 32 with Quantity

use of org.hl7.fhir.r4.model.Quantity 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 33 with Quantity

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

the class ObservationValueTranslatorImplTest method toOpenmrsType_shouldConvertQuantityToNumericValue.

@Test
public void toOpenmrsType_shouldConvertQuantityToNumericValue() {
    Quantity quantity = new Quantity();
    quantity.setValue(130d);
    Obs result = obsValueTranslator.toOpenmrsType(obs, quantity);
    assertThat(result, notNullValue());
    assertThat(result.getValueNumeric(), equalTo(130d));
}
Also used : Obs(org.openmrs.Obs) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 34 with Quantity

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

the class ObservationReferenceRangeTranslatorImpl method createObservationReferenceRange.

private Observation.ObservationReferenceRangeComponent createObservationReferenceRange(Double hiValue, Double lowValue, String code) {
    Observation.ObservationReferenceRangeComponent component = new Observation.ObservationReferenceRangeComponent();
    if (hiValue != null) {
        component.setHigh(new Quantity().setValue(hiValue));
    }
    if (lowValue != null) {
        component.setLow(new Quantity().setValue(lowValue));
    }
    CodeableConcept referenceRangeType = new CodeableConcept();
    Coding coding = referenceRangeType.addCoding().setCode(code);
    if (FhirConstants.OBSERVATION_REFERENCE_ABSOLUTE.equals(code)) {
        coding.setSystem(FhirConstants.OPENMRS_FHIR_EXT_OBSERVATION_REFERENCE_RANGE);
    } else {
        coding.setSystem(FhirConstants.OBSERVATION_REFERENCE_RANGE_SYSTEM_URI);
    }
    component.setType(referenceRangeType);
    return component;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) Quantity(org.hl7.fhir.r4.model.Quantity) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 35 with Quantity

use of org.hl7.fhir.r4.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class Questionnaire10_50 method convertQuestionnaireQuestionType.

public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> convertQuestionnaireQuestionType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat> src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemTypeEnumFactory());
    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
    tgt.addExtension(VersionConvertorConstants.EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL, new CodeType(src.getValueAsString()));
    switch(src.getValue()) {
        case BOOLEAN:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.BOOLEAN);
            break;
        case DECIMAL:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DECIMAL);
            break;
        case INTEGER:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.INTEGER);
            break;
        case DATE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATE);
            break;
        case DATETIME:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
            break;
        case INSTANT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
            break;
        case TIME:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TIME);
            break;
        case STRING:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.STRING);
            break;
        case TEXT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TEXT);
            break;
        case URL:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.URL);
            break;
        case CHOICE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
            break;
        case OPENCHOICE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
            break;
        case ATTACHMENT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.ATTACHMENT);
            break;
        case REFERENCE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.REFERENCE);
            break;
        case QUANTITY:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.QUANTITY);
            break;
        default:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.NULL);
            break;
    }
    return tgt;
}
Also used : CodeType(org.hl7.fhir.r5.model.CodeType)

Aggregations

Quantity (org.hl7.fhir.r4.model.Quantity)58 ArrayList (java.util.ArrayList)47 Test (org.junit.jupiter.api.Test)40 BigDecimal (java.math.BigDecimal)39 Quantity (org.hl7.fhir.dstu3.model.Quantity)39 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37 Test (org.junit.Test)25 List (java.util.List)24 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)23 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)23 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)18 Observation (org.hl7.fhir.r4.model.Observation)18 UcumException (org.fhir.ucum.UcumException)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)16 Resource (org.hl7.fhir.r4.model.Resource)16 Quantity (org.hl7.fhir.r5.model.Quantity)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Coding (org.hl7.fhir.r4.model.Coding)13