Search in sources :

Example 1 with RMAttributeInfo

use of com.nedap.archie.rminfo.RMAttributeInfo in project openEHR_SDK by ehrbase.

the class DtoToCompositionWalker method handleSingleValue.

private void handleSingleValue(Object value, String childName, Object child, Object parent) {
    if (value == null) {
    // NOP
    } else if (EnumValueSet.class.isAssignableFrom(value.getClass()) && DvCodedText.class.isAssignableFrom(parent.getClass())) {
        EnumValueSet valueSet = (EnumValueSet) value;
        DvCodedText dvCodedText = (DvCodedText) parent;
        dvCodedText.setValue(valueSet.getValue());
        dvCodedText.setDefiningCode(new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode()));
    } else if (EnumValueSet.class.isAssignableFrom(value.getClass()) && DvCodedText.class.isAssignableFrom(ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getType())) {
        EnumValueSet valueSet = (EnumValueSet) value;
        DvCodedText dvCodedText = new DvCodedText();
        dvCodedText.setValue(valueSet.getValue());
        dvCodedText.setDefiningCode(new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode()));
        RM_OBJECT_CREATOR.set(parent, childName, Collections.singletonList(dvCodedText));
    } else if (EnumValueSet.class.isAssignableFrom(value.getClass())) {
        EnumValueSet valueSet = (EnumValueSet) value;
        CodePhrase codePhrase = new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode());
        RM_OBJECT_CREATOR.set(parent, childName, Collections.singletonList(codePhrase));
    } else if (ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getTypeInCollection().isAssignableFrom(value.getClass()) || (ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getTypeInCollection().isAssignableFrom(boolean.class) && value.getClass().isAssignableFrom(Boolean.class))) {
        RMAttributeInfo attributeInfo = ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName);
        if (attributeInfo.isMultipleValued()) {
            try {
                Object invoke = attributeInfo.getGetMethod().invoke(parent);
                if (Collection.class.isAssignableFrom(invoke.getClass()) && child != null) {
                    ((Collection) invoke).remove(child);
                }
            } catch (IllegalAccessException | InvocationTargetException e) {
                logger.warn(e.getMessage(), e);
            }
        }
        RM_OBJECT_CREATOR.addElementToListOrSetSingleValues(parent, childName, Collections.singletonList(value));
    } else {
        logger.warn("Unhandled child {} in {}", childName, parent);
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) EnumValueSet(org.ehrbase.client.classgenerator.EnumValueSet) RMAttributeInfo(com.nedap.archie.rminfo.RMAttributeInfo) RMObject(com.nedap.archie.rm.RMObject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with RMAttributeInfo

use of com.nedap.archie.rminfo.RMAttributeInfo in project openEHR_SDK by ehrbase.

the class WebTemplateSkeletonBuilder method remove.

public static void remove(WebTemplateNode parentNode, RMObject parentObject, WebTemplateNode childNode, Object removeChildObject) {
    String attributeName = FlatPath.removeStart(new FlatPath(childNode.getAqlPath(true)), new FlatPath(parentNode.getAqlPath(true))).getLast().getName();
    RMAttributeInfo attributeInfo = ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parentObject.getClass(), attributeName);
    try {
        Object actualChild = attributeInfo.getGetMethod().invoke(parentObject);
        if (actualChild instanceof Collection) {
            ((Collection<?>) actualChild).remove(removeChildObject);
        } else if (Objects.equals(actualChild, removeChildObject)) {
            attributeInfo.getSetMethod().invoke(parentObject, (Object) null);
        }
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new SdkException(e.getMessage());
    }
}
Also used : RMAttributeInfo(com.nedap.archie.rminfo.RMAttributeInfo) SdkException(org.ehrbase.util.exception.SdkException) RMObject(com.nedap.archie.rm.RMObject) CComplexObject(com.nedap.archie.aom.CComplexObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) FlatPath(org.ehrbase.webtemplate.parser.FlatPath)

Aggregations

RMObject (com.nedap.archie.rm.RMObject)2 RMAttributeInfo (com.nedap.archie.rminfo.RMAttributeInfo)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CComplexObject (com.nedap.archie.aom.CComplexObject)1 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)1 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)1 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)1 EnumValueSet (org.ehrbase.client.classgenerator.EnumValueSet)1 SdkException (org.ehrbase.util.exception.SdkException)1 FlatPath (org.ehrbase.webtemplate.parser.FlatPath)1