Search in sources :

Example 11 with Range

use of org.molgenis.api.metadata.v3.model.Range in project molgenis by molgenis.

the class AttributeResponseMapperImpl method mapInternal.

private AttributeResponseData mapInternal(Attribute attr, boolean i18n) {
    Builder builder = AttributeResponseData.builder();
    builder.setId(attr.getIdentifier());
    builder.setName(attr.getName());
    builder.setSequenceNr(attr.getSequenceNumber());
    builder.setType(getValueString(attr.getDataType()));
    Optional.ofNullable(attr.getMaxLength()).ifPresent(builder::setMaxLength);
    builder.setIdAttribute(attr.isIdAttribute());
    builder.setLabelAttribute(attr.isLabelAttribute());
    builder.setLookupAttributeIndex(attr.getLookupAttributeIndex());
    if (EntityTypeUtils.isReferenceType(attr)) {
        builder.setRefEntityType(LinksResponse.create(null, createEntityTypeResponseUri(attr.getRefEntity()), null));
    }
    builder.setCascadeDelete(attr.getCascadeDelete());
    builder.setMappedBy(attr.getMappedBy() != null ? toAttributeResponse(attr.getMappedBy(), i18n) : null);
    if (attr.getDataType() == ONE_TO_MANY && attr.isMappedBy()) {
        builder.setOrderBy(map(attr));
    }
    builder.setLabel(attr.getLabel(LocaleContextHolder.getLocale().getLanguage()));
    builder.setDescription(attr.getDescription(LocaleContextHolder.getLocale().getLanguage()));
    if (i18n) {
        builder.setLabelI18n(getI18nAttrLabel(attr));
        getI18nAttrDesc(attr).ifPresent(builder::setDescriptionI18n);
    }
    builder.setNullable(attr.isNillable());
    builder.setAuto(attr.isAuto());
    builder.setVisible(attr.isVisible());
    builder.setUnique(attr.isUnique());
    builder.setReadOnly(attr.isReadOnly());
    builder.setAggregatable(attr.isAggregatable());
    builder.setExpression(attr.getExpression());
    if (attr.getDataType() == AttributeType.ENUM) {
        builder.setEnumOptions(attr.getEnumOptions());
    }
    if (attr.getDataType() == AttributeType.CATEGORICAL || attr.getDataType() == AttributeType.CATEGORICAL_MREF) {
        builder.setCategoricalOptions(getCategories(attr.getRefEntity()));
    }
    org.molgenis.data.Range range = attr.getRange();
    if (range != null) {
        builder.setRange(Range.create(range.getMin(), range.getMax()));
    }
    Attribute parent = attr.getParent();
    builder.setParentAttributeId(parent != null ? parent.getIdentifier() : null);
    builder.setNullableExpression(attr.getNullableExpression());
    builder.setVisibleExpression(attr.getVisibleExpression());
    builder.setValidationExpression(attr.getValidationExpression());
    builder.setDefaultValue(attr.getDefaultValue());
    return builder.build();
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Builder(org.molgenis.api.metadata.v3.model.AttributeResponseData.Builder)

Example 12 with Range

use of org.molgenis.api.metadata.v3.model.Range in project FAAAST-Service by FraunhoferIOSB.

the class TypeExtractor method extractTypeInfo.

public static TypeInfo extractTypeInfo(Object obj) {
    if (obj == null) {
        return null;
    }
    Class<?> type = obj.getClass();
    if (SubmodelElement.class.isAssignableFrom(type)) {
        ElementValueTypeInfo.Builder builder = ElementValueTypeInfo.builder();
        SubmodelElement submodelElement = (SubmodelElement) obj;
        builder.type(ElementValueMapper.getValueClass(submodelElement.getClass()));
        if (AnnotatedRelationshipElement.class.isAssignableFrom(type)) {
            AnnotatedRelationshipElement annotatedRelationshipElement = (AnnotatedRelationshipElement) obj;
            annotatedRelationshipElement.getAnnotations().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        } else if (SubmodelElementCollection.class.isAssignableFrom(type)) {
            SubmodelElementCollection submodelElementCollection = (SubmodelElementCollection) obj;
            submodelElementCollection.getValues().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        } else if (Entity.class.isAssignableFrom(type)) {
            Entity entity = (Entity) obj;
            entity.getStatements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        } else if (Property.class.isAssignableFrom(obj.getClass())) {
            Property property = (Property) obj;
            builder.datatype(Datatype.fromName(property.getValueType()));
        } else if (Range.class.isAssignableFrom(obj.getClass())) {
            Range range = (Range) obj;
            builder.datatype(Datatype.fromName(range.getValueType()));
        }
        return builder.build();
    }
    if (Submodel.class.isAssignableFrom(type)) {
        Submodel submodel = (Submodel) obj;
        ContainerTypeInfo.Builder<Object> builder = ContainerTypeInfo.<Object>builder();
        builder.type(Submodel.class);
        submodel.getSubmodelElements().forEach(x -> builder.element(x.getIdShort(), extractTypeInfo(x)));
        return builder.build();
    }
    if (Collection.class.isAssignableFrom(type)) {
        Collection collection = (Collection) obj;
        ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
        builder.type(Collection.class);
        builder.contentType(TypeToken.of(type).resolveType(COLLECTION_GENERIC_TOKEN).getRawType());
        Iterator iterator = collection.iterator();
        int i = 0;
        while (iterator.hasNext()) {
            builder.element(i, extractTypeInfo(iterator.next()));
            i++;
        }
        return builder.build();
    }
    if (Map.class.isAssignableFrom(type)) {
        Map map = (Map) obj;
        ContainerTypeInfo.Builder<String> builder = ContainerTypeInfo.<String>builder();
        builder.type(Map.class);
        builder.contentType(TypeToken.of(type).resolveType(MAP_GENERIC_TOKEN).getRawType());
        map.forEach((key, value) -> builder.element(key.toString(), extractTypeInfo(value)));
        return builder.build();
    }
    if (type.isArray()) {
        Object[] array = (Object[]) obj;
        ContainerTypeInfo.Builder<Integer> builder = ContainerTypeInfo.<Integer>builder();
        builder.type(Array.class);
        builder.contentType(type.getComponentType());
        for (int i = 0; i < array.length; i++) {
            builder.element(i, extractTypeInfo(array[i]));
        }
        return builder.build();
    }
    return ContainerTypeInfo.<Object>builder().build();
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Array(java.lang.reflect.Array) Iterator(java.util.Iterator) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) Collection(java.util.Collection) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) TypeToken(com.google.common.reflect.TypeToken) Property(io.adminshell.aas.v3.model.Property) Type(java.lang.reflect.Type) Range(io.adminshell.aas.v3.model.Range) Map(java.util.Map) Entity(io.adminshell.aas.v3.model.Entity) Submodel(io.adminshell.aas.v3.model.Submodel) Submodel(io.adminshell.aas.v3.model.Submodel) Entity(io.adminshell.aas.v3.model.Entity) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) AnnotatedRelationshipElement(io.adminshell.aas.v3.model.AnnotatedRelationshipElement) Range(io.adminshell.aas.v3.model.Range) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Iterator(java.util.Iterator) Collection(java.util.Collection) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Property(io.adminshell.aas.v3.model.Property) Map(java.util.Map)

Example 13 with Range

use of org.molgenis.api.metadata.v3.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestDoseRangeRXE.

@Test
void dosageInstructionTestDoseRangeRXE() {
    // Test dosageInstruction.DoseRange using RXE segment WITH a range
    String hl7message = "MSH|^~\\&||||||S1|RDE^O11||T|2.6|||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|NW|||||E|||||||||||||||||||||||I\n" + // RXE.6 through RXE.44 not used.
    "RXE||DUONEB3INH^3 ML PLAS CONT : IPRATROPIUM-ALBUTEROL 0.5-2.5 (3) MG/3ML IN SOLN^ADS|3|6|mL||||||||||||||||||||||||||||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Range doseRange = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getDoseRange();
    // doseRange.low(RXE.3)
    // RXE.3
    assertThat(doseRange.getLow().getValue()).hasToString("3.0");
    // RXE.5
    assertThat(doseRange.getLow().getUnit()).isEqualTo("mL");
    // Defaulted
    assertThat(doseRange.getLow().getSystem()).isEqualTo("http://unitsofmeasure.org");
    // doseRange.high(RXE.4)
    assertThat(doseRange.getHigh().getValue()).hasToString("6.0");
    // RXE.5
    assertThat(doseRange.getHigh().getUnit()).isEqualTo("mL");
    assertThat(doseRange.getHigh().getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Range(org.hl7.fhir.r4.model.Range) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Range

use of org.molgenis.api.metadata.v3.model.Range in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.

public static Parameter toCohortParameter(Extension extension) {
    Parameter parameter;
    Type extensionValue = extension.getValue();
    if (extensionValue instanceof Base64BinaryType) {
        parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
    } else if (extensionValue instanceof BooleanType) {
        parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
    } else if (extensionValue instanceof DateType) {
        parameter = new DateParameter(((DateType) extensionValue).asStringValue());
    } else if (extensionValue instanceof DateTimeType) {
        parameter = convertDateTimeType((DateTimeType) extensionValue);
    } else if (extensionValue instanceof DecimalType) {
        parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof InstantType) {
        parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof IntegerType) {
        parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
    } else if (extensionValue instanceof StringType) {
        parameter = new StringParameter(((StringType) extensionValue).getValue());
    } else if (extensionValue instanceof TimeType) {
        parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
    } else if (extensionValue instanceof UriType) {
        parameter = new StringParameter(((UriType) extensionValue).getValue());
    } else if (extensionValue instanceof Coding) {
        parameter = convertCoding((Coding) extensionValue);
    } else if (extensionValue instanceof CodeableConcept) {
        parameter = convertCodeableConcept((CodeableConcept) extensionValue);
    } else if (extensionValue instanceof Period) {
        Period castValue = (Period) extensionValue;
        parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
    } else if (extensionValue instanceof Quantity) {
        parameter = convertQuantity((Quantity) extensionValue);
    } else if (extensionValue instanceof Range) {
        Range castValue = (Range) extensionValue;
        parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
    } else if (extensionValue instanceof Ratio) {
        Ratio castValue = (Ratio) extensionValue;
        parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
    } else {
        throw new UnsupportedFhirTypeException(extensionValue);
    }
    return parameter;
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringType(org.hl7.fhir.r4.model.StringType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) UriType(org.hl7.fhir.r4.model.UriType) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Coding(org.hl7.fhir.r4.model.Coding) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) BooleanType(org.hl7.fhir.r4.model.BooleanType) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) Range(org.hl7.fhir.r4.model.Range) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) IntegerType(org.hl7.fhir.r4.model.IntegerType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) StringType(org.hl7.fhir.r4.model.StringType) DecimalType(org.hl7.fhir.r4.model.DecimalType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) InstantType(org.hl7.fhir.r4.model.InstantType) UriType(org.hl7.fhir.r4.model.UriType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DecimalType(org.hl7.fhir.r4.model.DecimalType) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 15 with Range

use of org.molgenis.api.metadata.v3.model.Range in project quality-measure-and-cohort-service by Alvearie.

the class FHIRRestUtils method complicatedTypeValueConstructor.

static String complicatedTypeValueConstructor(ParameterDefinition parameterDefinition) {
    FhirContext context = FhirContext.forCached(FhirVersionEnum.R4);
    IParser parser = context.newJsonParser();
    String valueKey;
    // In order to use the hapi parser, we cannot translate an extension by itself. The patient object wraps the extension
    Patient patient = new Patient();
    Extension extension = new Extension();
    switch(parameterDefinition.getType()) {
        case "Period":
            Period period = (Period) parameterDefinition.getExtension().get(0).getValue();
            extension.setValue(period);
            patient.addExtension(extension);
            valueKey = "valuePeriod";
            break;
        case "Range":
            Range range = (Range) parameterDefinition.getExtension().get(0).getValue();
            extension.setValue(range);
            patient.addExtension(extension);
            valueKey = "valueRange";
            break;
        case "Quantity":
            Quantity quantity = (Quantity) parameterDefinition.getExtension().get(0).getValue();
            extension.setValue(quantity);
            patient.addExtension(extension);
            valueKey = "valueQuantity";
            break;
        default:
            throw new RuntimeException("Complicated Type" + parameterDefinition.getType() + " not yet implemented");
    }
    String intermediateValue = parser.encodeResourceToString(patient);
    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode root = mapper.readTree(intermediateValue);
        JsonNode nameNode = root.path("extension");
        return nameNode.get(0).path(valueKey).toString();
    } catch (JsonProcessingException e) {
        throw new RuntimeException("There was an issue with json translation", e);
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) FhirContext(ca.uhn.fhir.context.FhirContext) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Range(org.hl7.fhir.r4.model.Range) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser)

Aggregations

Range (org.hl7.fhir.r4.model.Range)8 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 Quantity (org.hl7.fhir.r4.model.Quantity)4 Test (org.junit.Test)4 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)3 QuantityParameter (com.ibm.cohort.cql.evaluation.parameters.QuantityParameter)3 Base64 (org.apache.commons.codec.binary.Base64)3 ParameterDefinition (org.hl7.fhir.r4.model.ParameterDefinition)3 BooleanParameter (com.ibm.cohort.cql.evaluation.parameters.BooleanParameter)2 CodeParameter (com.ibm.cohort.cql.evaluation.parameters.CodeParameter)2 ConceptParameter (com.ibm.cohort.cql.evaluation.parameters.ConceptParameter)2 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)2 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)2 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)2 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)2 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)2 RatioParameter (com.ibm.cohort.cql.evaluation.parameters.RatioParameter)2 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)2 TimeParameter (com.ibm.cohort.cql.evaluation.parameters.TimeParameter)2 UnsupportedFhirTypeException (com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException)2