Search in sources :

Example 46 with Range

use of org.hl7.fhir.dstu2.model.Range in project molgenis by molgenis.

the class AttributeRequestMapperImpl method toAttribute.

private Attribute toAttribute(CreateAttributeRequest attributeRequest, EntityType entityType, @Nullable @CheckForNull Integer index) {
    Attribute attribute = attributeFactory.create();
    // set id/label/lookupIndex before setting other properties
    attribute.setIdAttribute(attributeRequest.getIdAttribute());
    attribute.setLabelAttribute(attributeRequest.getLabelAttribute());
    attribute.setLookupAttributeIndex(attributeRequest.getLookupAttributeIndex());
    String id = attributeRequest.getId();
    if (id != null) {
        attribute.setIdentifier(id);
    }
    attribute.setName(attributeRequest.getName());
    attribute.setEntity(entityType);
    Integer sequenceNumber = attributeRequest.getSequenceNr();
    if (sequenceNumber == null) {
        sequenceNumber = index;
    }
    if (sequenceNumber != null) {
        attribute.setSequenceNumber(sequenceNumber);
    }
    String type = attributeRequest.getType();
    if (type != null) {
        attribute.setDataType(AttributeType.toEnum(type));
    }
    Optional.ofNullable(attributeRequest.getMaxLength()).ifPresent(attribute::setMaxLength);
    EntityType refEntityType;
    String refEntityTypeId = attributeRequest.getRefEntityType();
    if (refEntityTypeId != null) {
        refEntityType = (EntityType) entityManager.getReference(entityTypeMetadata, refEntityTypeId);
        attribute.setRefEntity(refEntityType);
    }
    if (attributeRequest.getCascadeDelete() != null) {
        attribute.setCascadeDelete(attributeRequest.getCascadeDelete());
    }
    ImmutableList<Order> orderBy = attributeRequest.getOrderBy();
    attribute.setOrderBy(orderBy != null ? sortMapper.map(Sort.create(orderBy), entityType) : null);
    attribute.setExpression(attributeRequest.getExpression());
    Boolean nullable = attributeRequest.getNullable();
    if (nullable != null) {
        attribute.setNillable(nullable);
    }
    Boolean auto = attributeRequest.getAuto();
    if (auto != null) {
        attribute.setAuto(auto);
    }
    Boolean visible = attributeRequest.getVisible();
    if (visible != null) {
        attribute.setVisible(visible);
    }
    processI18nLabel(attributeRequest.getLabel(), attribute);
    processI18nDescription(attributeRequest.getDescription(), attribute);
    Boolean aggregatable = attributeRequest.getAggregatable();
    if (aggregatable != null) {
        attribute.setAggregatable(aggregatable);
    }
    List<String> enumOptions = attributeRequest.getEnumOptions();
    if (enumOptions != null) {
        attribute.setEnumOptions(enumOptions);
    }
    Range range = attributeRequest.getRange();
    if (range != null) {
        attribute.setRange(map(range));
    }
    Boolean readonly = attributeRequest.getReadonly();
    if (readonly != null) {
        attribute.setReadOnly(readonly);
    }
    Boolean unique = attributeRequest.getUnique();
    if (unique != null) {
        attribute.setUnique(unique);
    }
    attribute.setNullableExpression(attributeRequest.getNullableExpression());
    attribute.setVisibleExpression(attributeRequest.getVisibleExpression());
    attribute.setValidationExpression(attributeRequest.getValidationExpression());
    attribute.setDefaultValue(attributeRequest.getDefaultValue());
    return attribute;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntityType(org.molgenis.data.meta.model.EntityType) Order(org.molgenis.api.model.Order) Attribute(org.molgenis.data.meta.model.Attribute) Range(org.molgenis.api.metadata.v3.model.Range)

Example 47 with Range

use of org.hl7.fhir.dstu2.model.Range in project dpc-app by CMSgov.

the class GroupResourceUnitTest method makeTestPatients.

private Map<UUID, Patient> makeTestPatients(int count, UUID orgId) {
    if (count > 88) {
        throw new IllegalStateException("Don't support building more than 88 patients..yet (need a better mbi generator)");
    }
    final Map<UUID, Patient> patients = Maps.newHashMap();
    while (count > 0) {
        UUID id = UUID.randomUUID();
        Patient patient = FHIRPatientBuilder.newBuild().withMbi(// makes MBI in range 4S41C00AA10 -> 4S41C00AA99
        "4S41C00AA" + (count + 10)).withId(id).withTestData().build();
        patients.put(id, patient);
        count--;
    }
    return patients;
}
Also used : Patient(org.hl7.fhir.dstu3.model.Patient) UUID(java.util.UUID)

Example 48 with Range

use of org.hl7.fhir.dstu2.model.Range in project clinical_quality_language by cqframework.

the class DataRequirementsProcessor method toFhirValue.

private DataType toFhirValue(ElmRequirementsContext context, Expression value) {
    if (value == null) {
        return null;
    }
    if (value instanceof Interval) {
        // TODO: Handle lowclosed/highclosed
        return new Period().setStartElement(toFhirDateTimeValue(context, ((Interval) value).getLow())).setEndElement(toFhirDateTimeValue(context, ((Interval) value).getHigh()));
    } else if (value instanceof Literal) {
        if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
            return new DateTimeType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isDateType(value.getResultType())) {
            return new DateType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
            return new IntegerType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
            return new DecimalType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isStringType(value.getResultType())) {
            return new StringType(((Literal) value).getValue());
        }
    } else if (value instanceof DateTime) {
        DateTime dateTime = (DateTime) value;
        return new DateTimeType(toDateTimeString(toFhirValue(context, dateTime.getYear()), toFhirValue(context, dateTime.getMonth()), toFhirValue(context, dateTime.getDay()), toFhirValue(context, dateTime.getHour()), toFhirValue(context, dateTime.getMinute()), toFhirValue(context, dateTime.getSecond()), toFhirValue(context, dateTime.getMillisecond()), toFhirValue(context, dateTime.getTimezoneOffset())));
    } else if (value instanceof org.hl7.elm.r1.Date) {
        org.hl7.elm.r1.Date date = (org.hl7.elm.r1.Date) value;
        return new DateType(toDateString(toFhirValue(context, date.getYear()), toFhirValue(context, date.getMonth()), toFhirValue(context, date.getDay())));
    } else if (value instanceof Start) {
        DataType operand = toFhirValue(context, ((Start) value).getOperand());
        if (operand != null) {
            Period period = (Period) operand;
            return period.getStartElement();
        }
    } else if (value instanceof End) {
        DataType operand = toFhirValue(context, ((End) value).getOperand());
        if (operand != null) {
            Period period = (Period) operand;
            return period.getEndElement();
        }
    } else if (value instanceof ParameterRef) {
        if (context.getTypeResolver().isIntervalType(value.getResultType())) {
            Extension e = toExpression(context, (ParameterRef) value);
            org.hl7.cql.model.DataType pointType = ((IntervalType) value.getResultType()).getPointType();
            if (context.getTypeResolver().isDateTimeType(pointType) || context.getTypeResolver().isDateType(pointType)) {
                Period period = new Period();
                period.addExtension(e);
                return period;
            } else if (context.getTypeResolver().isQuantityType(pointType) || context.getTypeResolver().isIntegerType(pointType) || context.getTypeResolver().isDecimalType(pointType)) {
                Range range = new Range();
                range.addExtension(e);
                return range;
            } else {
                throw new IllegalArgumentException(String.format("toFhirValue not implemented for interval of %s", pointType.toString()));
            }
        } else // Boolean, Integer, Decimal, String, Quantity, Date, DateTime, Time, Coding, CodeableConcept
        if (context.getTypeResolver().isBooleanType(value.getResultType())) {
            BooleanType result = new BooleanType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
            IntegerType result = new IntegerType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
            DecimalType result = new DecimalType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isQuantityType(value.getResultType())) {
            Quantity result = new Quantity();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isCodeType(value.getResultType())) {
            Coding result = new Coding();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isConceptType(value.getResultType())) {
            CodeableConcept result = new CodeableConcept();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDateType(value.getResultType())) {
            DateType result = new DateType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
            DateTimeType result = new DateTimeType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isTimeType(value.getResultType())) {
            TimeType result = new TimeType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else {
            throw new IllegalArgumentException(String.format("toFhirValue not implemented for parameter of type %s", value.getResultType().toString()));
        }
    }
    throw new IllegalArgumentException(String.format("toFhirValue not implemented for %s", value.getClass().getSimpleName()));
}
Also used : IntervalType(org.hl7.cql.model.IntervalType) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) Quantity(org.hl7.fhir.r5.model.Quantity) org.hl7.elm.r1(org.hl7.elm.r1)

Example 49 with Range

use of org.hl7.fhir.dstu2.model.Range in project clinical_quality_language by cqframework.

the class Cql2ElmVisitor method parseDateTimeLiteral.

private Expression parseDateTimeLiteral(String input) {
    /*
DATETIME
        : '@'
            [0-9][0-9][0-9][0-9] // year
            (
                (
                    '-'[0-9][0-9] // month
                    (
                        (
                            '-'[0-9][0-9] // day
                            ('T' TIMEFORMAT?)?
                        )
                        | 'T'
                    )?
                )
                | 'T'
            )?
            ('Z' | ('+' | '-') [0-9][0-9]':'[0-9][0-9])? // timezone offset
        ;
*/
    Pattern dateTimePattern = Pattern.compile("(\\d{4})(((-(\\d{2}))(((-(\\d{2}))((T)((\\d{2})(\\:(\\d{2})(\\:(\\d{2})(\\.(\\d+))?)?)?)?)?)|(T))?)|(T))?((Z)|(([+-])(\\d{2})(\\:(\\d{2}))))?");
    // 1-------234-5--------678-9--------11--11-------1---1-------1---1-------1---1-----------------2------2----22---22-----2-------2---2-----------
    // ----------------------------------01--23-------4---5-------6---7-------8---9-----------------0------1----23---45-----6-------7---8-----------
    /*
            year - group 1
            month - group 5
            day - group 9
            day dateTime indicator - group 11
            hour - group 13
            minute - group 15
            second - group 17
            millisecond - group 19
            month dateTime indicator - group 20
            year dateTime indicator - group 21
            utc indicator - group 23
            timezone offset polarity - group 25
            timezone offset hour - group 26
            timezone offset minute - group 28
         */
    /*
        Pattern dateTimePattern =
                Pattern.compile("(\\d{4})(-(\\d{2}))?(-(\\d{2}))?((Z)|(T((\\d{2})(\\:(\\d{2})(\\:(\\d{2})(\\.(\\d+))?)?)?)?((Z)|(([+-])(\\d{2})(\\:?(\\d{2}))?))?))?");
                               //1-------2-3---------4-5---------67---8-91-------1---1-------1---1-------1---1-------------11---12-----2-------2----2---------------
                               //----------------------------------------0-------1---2-------3---4-------5---6-------------78---90-----1-------2----3---------------
*/
    Matcher matcher = dateTimePattern.matcher(input);
    if (matcher.matches()) {
        try {
            GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance();
            DateTime result = of.createDateTime();
            int year = Integer.parseInt(matcher.group(1));
            int month = -1;
            int day = -1;
            int hour = -1;
            int minute = -1;
            int second = -1;
            int millisecond = -1;
            result.setYear(libraryBuilder.createLiteral(year));
            if (matcher.group(5) != null) {
                month = Integer.parseInt(matcher.group(5));
                if (month < 0 || month > 12) {
                    throw new IllegalArgumentException(String.format("Invalid month in date/time literal (%s).", input));
                }
                result.setMonth(libraryBuilder.createLiteral(month));
            }
            if (matcher.group(9) != null) {
                day = Integer.parseInt(matcher.group(9));
                int maxDay = 31;
                switch(month) {
                    case 2:
                        maxDay = calendar.isLeapYear(year) ? 29 : 28;
                        break;
                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        maxDay = 30;
                        break;
                    default:
                        break;
                }
                if (day < 0 || day > maxDay) {
                    throw new IllegalArgumentException(String.format("Invalid day in date/time literal (%s).", input));
                }
                result.setDay(libraryBuilder.createLiteral(day));
            }
            if (matcher.group(13) != null) {
                hour = Integer.parseInt(matcher.group(13));
                if (hour < 0 || hour > 24) {
                    throw new IllegalArgumentException(String.format("Invalid hour in date/time literal (%s).", input));
                }
                result.setHour(libraryBuilder.createLiteral(hour));
            }
            if (matcher.group(15) != null) {
                minute = Integer.parseInt(matcher.group(15));
                if (minute < 0 || minute >= 60 || (hour == 24 && minute > 0)) {
                    throw new IllegalArgumentException(String.format("Invalid minute in date/time literal (%s).", input));
                }
                result.setMinute(libraryBuilder.createLiteral(minute));
            }
            if (matcher.group(17) != null) {
                second = Integer.parseInt(matcher.group(17));
                if (second < 0 || second >= 60 || (hour == 24 && second > 0)) {
                    throw new IllegalArgumentException(String.format("Invalid second in date/time literal (%s).", input));
                }
                result.setSecond(libraryBuilder.createLiteral(second));
            }
            if (matcher.group(19) != null) {
                millisecond = Integer.parseInt(matcher.group(19));
                if (millisecond < 0 || (hour == 24 && millisecond > 0)) {
                    throw new IllegalArgumentException(String.format("Invalid millisecond in date/time literal (%s).", input));
                }
                result.setMillisecond(libraryBuilder.createLiteral(millisecond));
            }
            if (matcher.group(23) != null && matcher.group(23).equals("Z")) {
                result.setTimezoneOffset(libraryBuilder.createLiteral(0.0));
            }
            if (matcher.group(25) != null) {
                int offsetPolarity = matcher.group(25).equals("+") ? 1 : -1;
                if (matcher.group(28) != null) {
                    int hourOffset = Integer.parseInt(matcher.group(26));
                    if (hourOffset < 0 || hourOffset > 14) {
                        throw new IllegalArgumentException(String.format("Timezone hour offset is out of range in date/time literal (%s).", input));
                    }
                    int minuteOffset = Integer.parseInt(matcher.group(28));
                    if (minuteOffset < 0 || minuteOffset >= 60 || (hourOffset == 14 && minuteOffset > 0)) {
                        throw new IllegalArgumentException(String.format("Timezone minute offset is out of range in date/time literal (%s).", input));
                    }
                    result.setTimezoneOffset(libraryBuilder.createLiteral((double) (hourOffset + (minuteOffset / 60)) * offsetPolarity));
                } else {
                    if (matcher.group(26) != null) {
                        int hourOffset = Integer.parseInt(matcher.group(26));
                        if (hourOffset < 0 || hourOffset > 14) {
                            throw new IllegalArgumentException(String.format("Timezone hour offset is out of range in date/time literal (%s).", input));
                        }
                        result.setTimezoneOffset(libraryBuilder.createLiteral((double) (hourOffset * offsetPolarity)));
                    }
                }
            }
            if (result.getHour() == null && matcher.group(11) == null && matcher.group(20) == null && matcher.group(21) == null) {
                org.hl7.elm.r1.Date date = of.createDate();
                date.setYear(result.getYear());
                date.setMonth(result.getMonth());
                date.setDay(result.getDay());
                date.setResultType(libraryBuilder.resolveTypeName("System", "Date"));
                return date;
            }
            result.setResultType(libraryBuilder.resolveTypeName("System", "DateTime"));
            return result;
        } catch (RuntimeException e) {
            throw new IllegalArgumentException(String.format("Invalid date-time input (%s). Use ISO 8601 date time representation (yyyy-MM-ddThh:mm:ss.fff(Z|(+/-hh:mm)).", input), e);
        }
    } else {
        throw new IllegalArgumentException(String.format("Invalid date-time input (%s). Use ISO 8601 date time representation (yyyy-MM-ddThh:mm:ss.fff(Z|+/-hh:mm)).", input));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) org.hl7.elm.r1(org.hl7.elm.r1)

Example 50 with Range

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

Aggregations

Test (org.junit.jupiter.api.Test)18 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)15 Quantity (org.hl7.fhir.r4.model.Quantity)14 Resource (org.hl7.fhir.r4.model.Resource)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Search (ca.uhn.fhir.rest.annotation.Search)11 Trace (com.newrelic.api.agent.Trace)10 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)9 ArrayList (java.util.ArrayList)9 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)8 Operation (gov.cms.bfd.server.war.Operation)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 Date (java.util.Date)8 Range (org.hl7.fhir.r4.model.Range)8 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)7 List (java.util.List)7 Bundle (org.hl7.fhir.r4.model.Bundle)7