Search in sources :

Example 41 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class CanonicalXML method marshalInline.

public String marshalInline(RMObject rmObject, QName qName) {
    try {
        JAXBElement<RMObject> root = new JAXBElement<>(qName, RMObject.class, rmObject);
        Marshaller marshaller = JAXBUtil.getArchieJAXBContext().createMarshaller();
        DOMResult res = new DOMResult();
        marshaller.marshal(root, res);
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
        transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        Node rootNode = res.getNode().getFirstChild();
        NodeList childNodes = rootNode.getChildNodes();
        StringWriter stringWriter = new StringWriter();
        for (int i = 0; i < childNodes.getLength(); i++) {
            transformer.transform(new DOMSource(childNodes.item(i)), new StreamResult(stringWriter));
        }
        return stringWriter.toString();
    } catch (JAXBException | TransformerException e) {
        throw new org.ehrbase.serialisation.exception.MarshalException(e.getMessage(), e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) StringWriter(java.io.StringWriter) TransformerException(javax.xml.transform.TransformerException) RMObject(com.nedap.archie.rm.RMObject)

Example 42 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class FromCompositionWalker method extractPair.

protected ImmutablePair<T, RMObject> extractPair(Context<T> context, WebTemplateNode currentNode, Map<String, List<WebTemplateNode>> choices, WebTemplateNode childNode, Integer i) {
    RMObject currentChild = null;
    T childObject = null;
    currentChild = (RMObject) extractRMChild(context.getRmObjectDeque().peek(), currentNode, childNode, choices.containsKey(childNode.getAqlPath()), i);
    if (currentChild != null) {
        childObject = extract(context, childNode, choices.containsKey(childNode.getAqlPath()), i);
    }
    ImmutablePair<T, RMObject> pair = new ImmutablePair<>(childObject, currentChild);
    return pair;
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RMObject(com.nedap.archie.rm.RMObject)

Example 43 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class FromCompositionWalker method extractRMChild.

protected Object extractRMChild(RMObject currentRM, WebTemplateNode currentNode, WebTemplateNode childNode, boolean isChoice, Integer count) {
    ItemExtractor itemExtractor = new ItemExtractor(currentRM, currentNode, childNode, isChoice && count == null).invoke();
    Object child = itemExtractor.getChild();
    if (count != null && child instanceof List) {
        child = ((List<RMObject>) child).get(count);
        if (isChoice && !ARCHIE_RM_INFO_LOOKUP.getTypeInfo(childNode.getRmType()).getJavaClass().isAssignableFrom(child.getClass())) {
            child = null;
        }
    }
    child = wrap(child);
    return child;
}
Also used : RMObject(com.nedap.archie.rm.RMObject) List(java.util.List) RMObject(com.nedap.archie.rm.RMObject)

Example 44 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class ToCompositionWalker method extractPair.

protected ImmutablePair<T, RMObject> extractPair(Context<T> context, WebTemplateNode currentNode, Map<String, List<WebTemplateNode>> choices, WebTemplateNode childNode, Integer i) {
    RMObject currentChild = null;
    T childObject = null;
    childObject = extract(context, childNode, choices.containsKey(childNode.getAqlPath()), i);
    if (childObject != null) {
        boolean isChoice = choices.containsKey(childNode.getAqlPath());
        if (currentNode.getRmType().equals("ELEMENT") && childNode.getRmType().equals("DV_CODED_TEXT") && childNode.getInputs().stream().anyMatch(in -> "other".equals(in.getSuffix()))) {
            isChoice = true;
        }
        currentChild = (RMObject) extractRMChild(context.getRmObjectDeque().peek(), currentNode, childNode, isChoice, i);
    }
    return new ImmutablePair<>(childObject, currentChild);
}
Also used : ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) java.util(java.util) Logger(org.slf4j.Logger) com.nedap.archie.rm.datastructures(com.nedap.archie.rm.datastructures) Archetyped(com.nedap.archie.rm.archetyped.Archetyped) DefaultValueInserter(org.ehrbase.serialisation.walker.defaultvalues.defaultinserter.DefaultValueInserter) LoggerFactory(org.slf4j.LoggerFactory) ArchetypeID(com.nedap.archie.rm.support.identification.ArchetypeID) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WebTemplateSkeletonBuilder(org.ehrbase.building.webtemplateskeletnbuilder.WebTemplateSkeletonBuilder) NodeId(org.ehrbase.webtemplate.parser.NodeId) RM_VERSION_1_4_0(org.ehrbase.util.rmconstants.RmConstants.RM_VERSION_1_4_0) com.nedap.archie.rm.composition(com.nedap.archie.rm.composition) FeederAuditDetails(com.nedap.archie.rm.archetyped.FeederAuditDetails) RMObject(com.nedap.archie.rm.RMObject) Locatable(com.nedap.archie.rm.archetyped.Locatable) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RMObject(com.nedap.archie.rm.RMObject)

Example 45 with RMObject

use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.

the class DtoToCompositionWalker method postHandle.

@Override
protected void postHandle(Context<Map<String, Object>> context) {
    super.postHandle(context);
    RMObject rmObject = context.getRmObjectDeque().peek();
    if (rmObject instanceof Activity) {
        context.getObjectDeque().peek().entrySet().stream().filter(e -> e.getKey().endsWith("/action_archetype_id")).map(Map.Entry::getValue).map(String.class::cast).findAny().ifPresent(((Activity) rmObject)::setActionArchetypeId);
    }
}
Also used : Activity(com.nedap.archie.rm.composition.Activity) RMObject(com.nedap.archie.rm.RMObject)

Aggregations

RMObject (com.nedap.archie.rm.RMObject)57 Test (org.junit.Test)19 Composition (com.nedap.archie.rm.composition.Composition)10 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)9 QueryResponseData (org.ehrbase.response.openehr.QueryResponseData)8 Locatable (com.nedap.archie.rm.archetyped.Locatable)7 List (java.util.List)7 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)6 Collectors (java.util.stream.Collectors)5 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Map (java.util.Map)4 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)4 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Archetyped (com.nedap.archie.rm.archetyped.Archetyped)3 Version (com.nedap.archie.rm.changecontrol.Version)3 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3