use of org.hl7.fhir.dstu2.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);
}
}
}
}
use of org.hl7.fhir.dstu2.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))))));
}
use of org.hl7.fhir.dstu2.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));
}
use of org.hl7.fhir.dstu2.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;
}
use of org.hl7.fhir.dstu2.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;
}
Aggregations