Search in sources :

Example 1 with Setting

use of org.ehrbase.client.classgenerator.shareddefinition.Setting in project openEHR_SDK by ehrbase.

the class ClassGenerator method addSimpleField.

private void addSimpleField(ClassGeneratorContext context, TypeSpec.Builder classBuilder, String path, WebTemplateNode endNode) {
    Class<?> clazz = extractClass(endNode);
    if (clazz == null) {
        logger.warn("No class for path {} ", path);
        return;
    }
    ValueSet valueSet = buildValueSet(endNode);
    RmClassGeneratorConfig classGeneratorConfig = configMap.get(clazz);
    if (classGeneratorConfig == null && !clazz.getName().contains("java.lang")) {
        logger.debug("No ClassGenerator for {}", clazz);
    }
    boolean expand = classGeneratorConfig != null && classGeneratorConfig.isExpandField();
    if (endNode.getRmType().equals("DV_CODED_TEXT") && !List.of("transition", "language", "setting", "category", "territory", "math_function", "null_flavour").contains(endNode.getId(false))) {
        expand = expand && endNode.getInputs().stream().filter(i -> i.getType().equals("CODED_TEXT")).map(WebTemplateInput::getList).flatMap(List::stream).findAny().isPresent();
    }
    if (!expand) {
        TypeName className = Optional.ofNullable(clazz).map(ClassName::get).orElse(ClassName.get(Object.class));
        if (endNode.isMulti() && !context.nodeDeque.peek().getRmType().equals("ELEMENT")) {
            className = ParameterizedTypeName.get(ClassName.get(List.class), className);
        }
        addField(context, classBuilder, path, endNode, className, valueSet, false);
    } else {
        Map<String, Field> fieldMap = Arrays.stream(FieldUtils.getAllFields(clazz)).filter(f -> !f.isSynthetic()).collect(Collectors.toMap(Field::getName, f -> f));
        Set<String> expandFields = classGeneratorConfig.getExpandFields();
        expandFields.forEach(fieldName -> addField(context, classBuilder, path + "|" + new SnakeCase(fieldName).camelToSnake(), endNode, ClassName.get(fieldMap.get(fieldName).getType()), valueSet, false));
    }
}
Also used : Arrays(java.util.Arrays) Language(org.ehrbase.client.classgenerator.shareddefinition.Language) Composition(com.nedap.archie.rm.composition.Composition) Modifier(javax.lang.model.element.Modifier) MathFunction(org.ehrbase.client.classgenerator.shareddefinition.MathFunction) VersionUid(org.ehrbase.client.openehrclient.VersionUid) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) LoggerFactory(org.slf4j.LoggerFactory) ClassName(com.squareup.javapoet.ClassName) StringUtils(org.apache.commons.lang3.StringUtils) Pair(org.apache.commons.lang3.tuple.Pair) Generated(javax.annotation.processing.Generated) Map(java.util.Map) Category(org.ehrbase.client.classgenerator.shareddefinition.Category) Locatable(com.nedap.archie.rm.archetyped.Locatable) Transition(org.ehrbase.client.classgenerator.shareddefinition.Transition) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) RMEntity(org.ehrbase.client.classgenerator.interfaces.RMEntity) Path(org.ehrbase.client.annotations.Path) Entry(com.nedap.archie.rm.composition.Entry) ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) IntervalEventEntity(org.ehrbase.client.classgenerator.interfaces.IntervalEventEntity) FilteredWebTemplate(org.ehrbase.webtemplate.model.FilteredWebTemplate) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) Set(java.util.Set) Collectors(java.util.stream.Collectors) Template(org.ehrbase.client.annotations.Template) WebTemplateInputValue(org.ehrbase.webtemplate.model.WebTemplateInputValue) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Type(java.lang.reflect.Type) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) TermDefinition(org.ehrbase.terminology.client.terminology.TermDefinition) Territory(org.ehrbase.client.classgenerator.shareddefinition.Territory) FieldSpec(com.squareup.javapoet.FieldSpec) Id(org.ehrbase.client.annotations.Id) HashMap(java.util.HashMap) Deque(java.util.Deque) CompositionEntity(org.ehrbase.client.classgenerator.interfaces.CompositionEntity) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PointEventEntity(org.ehrbase.client.classgenerator.interfaces.PointEventEntity) WebTemplateFilter(org.ehrbase.webtemplate.filter.WebTemplateFilter) SetUtils(org.apache.commons.collections4.SetUtils) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) OptionFor(org.ehrbase.client.annotations.OptionFor) EntryEntity(org.ehrbase.client.classgenerator.interfaces.EntryEntity) Logger(org.slf4j.Logger) MethodSpec(com.squareup.javapoet.MethodSpec) Walker(org.ehrbase.serialisation.walker.Walker) Archetype(org.ehrbase.client.annotations.Archetype) NullFlavour(org.ehrbase.client.classgenerator.shareddefinition.NullFlavour) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec) Field(java.lang.reflect.Field) PointEvent(com.nedap.archie.rm.datastructures.PointEvent) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RmClassGeneratorConfig(org.ehrbase.client.classgenerator.config.RmClassGeneratorConfig) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) SnakeCase(org.ehrbase.serialisation.util.SnakeCase) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) LocatableEntity(org.ehrbase.client.classgenerator.interfaces.LocatableEntity) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) Entity(org.ehrbase.client.annotations.Entity) Choice(org.ehrbase.client.annotations.Choice) ValueSet(org.ehrbase.terminology.client.terminology.ValueSet) IntervalEvent(com.nedap.archie.rm.datastructures.IntervalEvent) Collections(java.util.Collections) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) TypeName(com.squareup.javapoet.TypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) SnakeCase(org.ehrbase.serialisation.util.SnakeCase) Field(java.lang.reflect.Field) List(java.util.List) ArrayList(java.util.ArrayList) ValueSet(org.ehrbase.terminology.client.terminology.ValueSet) RmClassGeneratorConfig(org.ehrbase.client.classgenerator.config.RmClassGeneratorConfig)

Example 2 with Setting

use of org.ehrbase.client.classgenerator.shareddefinition.Setting in project openEHR_SDK by ehrbase.

the class EventContextValueInserter method insert.

@Override
public void insert(EventContext rmObject, DefaultValues defaultValues) {
    if (RMHelper.isEmpty(rmObject.getStartTime()) && defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
        rmObject.setStartTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getEndTime()) && defaultValues.containsDefaultValue(DefaultValuePath.END_TIME)) {
        rmObject.setEndTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.END_TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getHealthCareFacility()) && (defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_NAME) || defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_ID))) {
        rmObject.setHealthCareFacility(buildPartyIdentified(defaultValues, DefaultValuePath.HEALTHCARE_FACILITY_NAME, DefaultValuePath.HEALTHCARE_FACILITY_ID, rmObject.getHealthCareFacility()));
    }
    if (RMHelper.isEmpty(rmObject.getLocation()) && defaultValues.containsDefaultValue(DefaultValuePath.LOCATION)) {
        rmObject.setLocation(defaultValues.getDefaultValue(DefaultValuePath.LOCATION));
    }
    if (RMHelper.isEmpty(rmObject.getSetting()) && defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
        Setting defaultValue = defaultValues.getDefaultValue(DefaultValuePath.SETTING);
        rmObject.setSetting(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
    }
    if (RMHelper.isEmpty(rmObject.getParticipations()) && defaultValues.containsDefaultValue(DefaultValuePath.PARTICIPATION)) {
        rmObject.setParticipations(defaultValues.getDefaultValue(DefaultValuePath.PARTICIPATION));
    }
    if (rmObject.getParticipations() != null) {
        rmObject.getParticipations().stream().map(Participation::getPerformer).filter(Objects::nonNull).map(PartyProxy::getExternalRef).filter(Objects::nonNull).filter(ref -> ref.getId() != null).forEach(ref -> {
            if (ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_NAMESPACE)) {
                ref.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
            }
            if (ref.getId() instanceof GenericId && ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_SCHEME)) {
                ((GenericId) ref.getId()).setScheme(defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME));
            }
        });
    }
}
Also used : PartyProxy(com.nedap.archie.rm.generic.PartyProxy) Objects(java.util.Objects) EventContext(com.nedap.archie.rm.composition.EventContext) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RMHelper(org.ehrbase.serialisation.walker.RMHelper) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Participation(com.nedap.archie.rm.generic.Participation) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) Objects(java.util.Objects) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 3 with Setting

use of org.ehrbase.client.classgenerator.shareddefinition.Setting in project openEHR_SDK by ehrbase.

the class ClassGenerator method addField.

private void addField(ClassGeneratorContext context, TypeSpec.Builder classBuilder, String path, WebTemplateNode node, TypeName className, ValueSet valueSet, boolean addChoiceAnnotation) {
    if (CodePhrase.class.getName().equals(className.toString()))
        switch(node.getName()) {
            case "language":
                className = ClassName.get(Language.class);
                break;
            case "setting":
                className = ClassName.get(Setting.class);
                break;
            case "category":
                className = ClassName.get(Category.class);
                break;
            case "territory":
                className = ClassName.get(Territory.class);
                break;
            case "math_function":
                className = ClassName.get(MathFunction.class);
                break;
            case "transition":
                className = ClassName.get(Transition.class);
                break;
            case "null_flavour":
                className = ClassName.get(NullFlavour.class);
                break;
            default:
                if (CollectionUtils.isNotEmpty(valueSet.getTherms())) {
                    final TypeSpec enumValueSet = context.currentEnums.computeIfAbsent(valueSet, vs -> buildEnumValueSet(context, node, vs));
                    String enumPackage = context.currentPackageName + "." + context.currentMainClass.toLowerCase() + DEFINITION_PACKAGE;
                    context.classes.put(enumPackage, enumValueSet);
                    className = ClassName.get(enumPackage, enumValueSet.name);
                }
        }
    String fieldName = defaultNamingStrategy.buildFieldName(context, path, node);
    FieldSpec.Builder builder = FieldSpec.builder(className, fieldName).addAnnotation(AnnotationSpec.builder(Path.class).addMember(Path.VALUE, "$S", path).build()).addModifiers(Modifier.PRIVATE).addJavadoc(defaultNamingStrategy.buildFieldJavadoc(context, node));
    if (addChoiceAnnotation) {
        builder.addAnnotation(Choice.class);
    }
    FieldSpec fieldSpec = builder.build();
    classBuilder.addField(fieldSpec);
    classBuilder.addMethod(buildSetter(fieldSpec, false));
    classBuilder.addMethod(buildGetter(fieldSpec, false));
}
Also used : Arrays(java.util.Arrays) Language(org.ehrbase.client.classgenerator.shareddefinition.Language) Composition(com.nedap.archie.rm.composition.Composition) Modifier(javax.lang.model.element.Modifier) MathFunction(org.ehrbase.client.classgenerator.shareddefinition.MathFunction) VersionUid(org.ehrbase.client.openehrclient.VersionUid) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) LoggerFactory(org.slf4j.LoggerFactory) ClassName(com.squareup.javapoet.ClassName) StringUtils(org.apache.commons.lang3.StringUtils) Pair(org.apache.commons.lang3.tuple.Pair) Generated(javax.annotation.processing.Generated) Map(java.util.Map) Category(org.ehrbase.client.classgenerator.shareddefinition.Category) Locatable(com.nedap.archie.rm.archetyped.Locatable) Transition(org.ehrbase.client.classgenerator.shareddefinition.Transition) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) RMEntity(org.ehrbase.client.classgenerator.interfaces.RMEntity) Path(org.ehrbase.client.annotations.Path) Entry(com.nedap.archie.rm.composition.Entry) ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) IntervalEventEntity(org.ehrbase.client.classgenerator.interfaces.IntervalEventEntity) FilteredWebTemplate(org.ehrbase.webtemplate.model.FilteredWebTemplate) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) Set(java.util.Set) Collectors(java.util.stream.Collectors) Template(org.ehrbase.client.annotations.Template) WebTemplateInputValue(org.ehrbase.webtemplate.model.WebTemplateInputValue) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Type(java.lang.reflect.Type) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) TermDefinition(org.ehrbase.terminology.client.terminology.TermDefinition) Territory(org.ehrbase.client.classgenerator.shareddefinition.Territory) FieldSpec(com.squareup.javapoet.FieldSpec) Id(org.ehrbase.client.annotations.Id) HashMap(java.util.HashMap) Deque(java.util.Deque) CompositionEntity(org.ehrbase.client.classgenerator.interfaces.CompositionEntity) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PointEventEntity(org.ehrbase.client.classgenerator.interfaces.PointEventEntity) WebTemplateFilter(org.ehrbase.webtemplate.filter.WebTemplateFilter) SetUtils(org.apache.commons.collections4.SetUtils) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) OptionFor(org.ehrbase.client.annotations.OptionFor) EntryEntity(org.ehrbase.client.classgenerator.interfaces.EntryEntity) Logger(org.slf4j.Logger) MethodSpec(com.squareup.javapoet.MethodSpec) Walker(org.ehrbase.serialisation.walker.Walker) Archetype(org.ehrbase.client.annotations.Archetype) NullFlavour(org.ehrbase.client.classgenerator.shareddefinition.NullFlavour) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec) Field(java.lang.reflect.Field) PointEvent(com.nedap.archie.rm.datastructures.PointEvent) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RmClassGeneratorConfig(org.ehrbase.client.classgenerator.config.RmClassGeneratorConfig) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) SnakeCase(org.ehrbase.serialisation.util.SnakeCase) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) LocatableEntity(org.ehrbase.client.classgenerator.interfaces.LocatableEntity) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) Entity(org.ehrbase.client.annotations.Entity) Choice(org.ehrbase.client.annotations.Choice) ValueSet(org.ehrbase.terminology.client.terminology.ValueSet) IntervalEvent(com.nedap.archie.rm.datastructures.IntervalEvent) Collections(java.util.Collections) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) Path(org.ehrbase.client.annotations.Path) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) FieldSpec(com.squareup.javapoet.FieldSpec) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

Locatable (com.nedap.archie.rm.archetyped.Locatable)2 Composition (com.nedap.archie.rm.composition.Composition)2 Entry (com.nedap.archie.rm.composition.Entry)2 IntervalEvent (com.nedap.archie.rm.datastructures.IntervalEvent)2 PointEvent (com.nedap.archie.rm.datastructures.PointEvent)2 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)2 ArchieRMInfoLookup (com.nedap.archie.rminfo.ArchieRMInfoLookup)2 AnnotationSpec (com.squareup.javapoet.AnnotationSpec)2 ClassName (com.squareup.javapoet.ClassName)2 FieldSpec (com.squareup.javapoet.FieldSpec)2 MethodSpec (com.squareup.javapoet.MethodSpec)2 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)2 TypeName (com.squareup.javapoet.TypeName)2 TypeSpec (com.squareup.javapoet.TypeSpec)2 Field (java.lang.reflect.Field)2 Type (java.lang.reflect.Type)2 OffsetDateTime (java.time.OffsetDateTime)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2