Search in sources :

Example 1 with CComplexObject

use of com.nedap.archie.aom.CComplexObject in project archetype-languageserver by nedap.

the class PartialAOMPathQuery method findLSPPartial.

// TODO: check if/how this is different from AOMPathQuery.findPartial, and potentially remove
public PartialMatch findLSPPartial(CComplexObject root) {
    List<ArchetypeModelObject> result = new ArrayList<>();
    boolean findThroughDifferentialPaths = true, matchSpecializedNodes = true;
    result.add(root);
    List<PathSegment> pathSegments = getPathSegments();
    for (int i = 0; i < pathSegments.size(); i++) {
        List<ArchetypeModelObject> previousResult = result;
        PathSegment segment = pathSegments.get(i);
        CAttribute differentialAttribute = null;
        if (findThroughDifferentialPaths) {
            differentialAttribute = findMatchingDifferentialPath(pathSegments.subList(i, pathSegments.size()), result);
        }
        if (differentialAttribute != null) {
            // skip a few pathsegments for this differential path match
            i = i + new APathQuery(differentialAttribute.getDifferentialPath()).getPathSegments().size() - 1;
            PathSegment lastPathSegment = pathSegments.get(i);
            ArchetypeModelObject oneMatchingObject = findOneMatchingObject(differentialAttribute, lastPathSegment, matchSpecializedNodes);
            if (oneMatchingObject != null) {
                result = Lists.newArrayList(oneMatchingObject);
            } else {
                result = findOneSegment(segment, result, matchSpecializedNodes);
            }
        } else {
            result = findOneSegment(segment, result, matchSpecializedNodes);
        }
        List<ArchetypeModelObject> returnValue = previousResult.stream().filter((object) -> object != null).collect(Collectors.toList());
        if (result.isEmpty()) {
            // we have to return our partial match here
            return new PartialMatch(pathSegments, pathSegments.subList(i, pathSegments.size()), returnValue);
        }
    }
    List<ArchetypeModelObject> returnValue = result.stream().filter((object) -> object != null).collect(Collectors.toList());
    return new PartialMatch(pathSegments, new ArrayList<>(), returnValue);
}
Also used : CAttribute(com.nedap.archie.aom.CAttribute) ArchetypeModelObject(com.nedap.archie.aom.ArchetypeModelObject) List(java.util.List) Lists(com.google.common.collect.Lists) AOMPathQuery(com.nedap.archie.query.AOMPathQuery) CComplexObject(com.nedap.archie.aom.CComplexObject) PathSegment(com.nedap.archie.paths.PathSegment) APathQuery(com.nedap.archie.query.APathQuery) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) APathQuery(com.nedap.archie.query.APathQuery) ArrayList(java.util.ArrayList) ArchetypeModelObject(com.nedap.archie.aom.ArchetypeModelObject) PathSegment(com.nedap.archie.paths.PathSegment) CAttribute(com.nedap.archie.aom.CAttribute)

Example 2 with CComplexObject

use of com.nedap.archie.aom.CComplexObject in project archetype-languageserver by nedap.

the class ArchetypeHoverInfo method extractHoverInfo.

private void extractHoverInfo(DocumentInformation documentInformation, CAttribute attribute, Archetype archetypeForTerms) {
    for (CObject object : attribute.getChildren()) {
        try {
            if (object instanceof CComplexObject) {
                extractHoverInfo(documentInformation, (CComplexObject) object, archetypeForTerms);
            } else if (object instanceof CTerminologyCode) {
                extractHoverInfo(documentInformation, (CTerminologyCode) object, archetypeForTerms);
            } else if (object instanceof ArchetypeSlot) {
                getHoverInfoForCObject(documentInformation, object, archetypeForTerms);
            }
        // for the other primitives, hovers should not be important
        } catch (Exception e) {
            // If this fails, fine, continue with the rest of the file!
            // TODO: report to client?
            e.printStackTrace();
        }
    }
    try {
        CAttribute flatAttribute = archetypeForTerms.itemAtPath(attribute.getPath());
        if (flatAttribute == null) {
            flatAttribute = attribute;
        }
        Cardinality cardinality = null;
        MultiplicityInterval existence = null;
        // TODO: do a proper path lookup through the RM model?
        CAttribute defaults = new BMMConstraintImposer(metaModels.getSelectedBmmModel()).getDefaultAttribute(flatAttribute.getParent().getRmTypeName(), flatAttribute.getRmAttributeName());
        if (flatAttribute.getCardinality() != null) {
            cardinality = flatAttribute.getCardinality();
        } else {
            if (defaults != null) {
                cardinality = defaults.getCardinality();
            }
        }
        if (flatAttribute.getExistence() != null) {
            existence = flatAttribute.getExistence();
        } else {
            if (defaults != null) {
                existence = flatAttribute.getExistence();
            }
        }
        boolean multiple = flatAttribute.isMultiple();
        StringBuilder content = new StringBuilder();
        if (cardinality != null) {
            content.append("Cardinality: ");
            content.append(cardinality.toString());
        }
        if (existence != null) {
            content.append(", existence: " + existence.toString());
        }
        content.append(multiple ? "\n multiple valued attribute" : "\n single valued attribute");
        BmmClass classDefinition = metaModels.getSelectedBmmModel().getClassDefinition(flatAttribute.getParent().getRmTypeName());
        if (classDefinition != null) {
            BmmProperty bmmProperty = classDefinition.getFlatProperties().get(flatAttribute.getRmAttributeName());
            if (bmmProperty != null) {
                content.append("\n\nRM type name: *" + bmmProperty.getType().toDisplayString() + "*");
            }
        }
        content.append("\n\n path: " + attribute.getPath());
        Hover hover = new Hover();
        hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
        Range range = getHoverRange(documentInformation, attribute);
        if (range != null) {
            hoverRanges.addRange(range, hover);
        }
    } catch (Exception e) {
        // TODO: report to client?
        e.printStackTrace();
    }
}
Also used : BmmClass(org.openehr.bmm.core.BmmClass) Cardinality(com.nedap.archie.base.Cardinality) CObject(com.nedap.archie.aom.CObject) CComplexObject(com.nedap.archie.aom.CComplexObject) CAttribute(com.nedap.archie.aom.CAttribute) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent) MultiplicityInterval(com.nedap.archie.base.MultiplicityInterval) BMMConstraintImposer(com.nedap.archie.adlparser.modelconstraints.BMMConstraintImposer) ArchetypeSlot(com.nedap.archie.aom.ArchetypeSlot) BmmProperty(org.openehr.bmm.core.BmmProperty) CTerminologyCode(com.nedap.archie.aom.primitives.CTerminologyCode) Hover(org.eclipse.lsp4j.Hover)

Example 3 with CComplexObject

use of com.nedap.archie.aom.CComplexObject in project openEHR_SDK by ehrbase.

the class WebTemplateSkeletonBuilder method build.

@SuppressWarnings("unchecked")
public static <T> T build(WebTemplateNode node, boolean withChildren, Class<T> clazz) {
    String rmclass = node.getRmType();
    CComplexObject elementConstraint = new CComplexObject();
    elementConstraint.setRmTypeName(rmclass);
    Object skeleton;
    switch(rmclass) {
        case "UID_BASED_ID":
            skeleton = new HierObjectId();
            break;
        case "PARTY_PROXY":
            skeleton = new PartyIdentified();
            break;
        case "STRING":
        case "LONG":
            skeleton = null;
            break;
        case "BOOLEAN":
            skeleton = false;
            break;
        default:
            skeleton = RM_OBJECT_CREATOR.create(elementConstraint);
            break;
    }
    if (withChildren) {
        node.getChildren().stream().filter(n -> !List.of("name", "archetype_node_id", "offset").contains(n.getId())).forEach(c -> {
            Object childObject = build(c, true, Object.class);
            insert(node, (RMObject) skeleton, c, childObject);
        });
    }
    if (skeleton instanceof Locatable) {
        Optional<WebTemplateNode> name = node.findChildById("name");
        if (name.isPresent()) {
            if (name.get().getRmType().equals(RmConstants.DV_CODED_TEXT)) {
                ((Locatable) skeleton).setName(extractDefault(name.get(), DvCodedText.class).orElseThrow());
            } else {
                ((Locatable) skeleton).setName(extractDefault(name.get(), DvText.class).orElse(new DvText(node.getName())));
            }
        } else {
            ((Locatable) skeleton).setName(new DvText(node.getName()));
        }
        ((Locatable) skeleton).setArchetypeNodeId(node.getNodeId());
    }
    if (skeleton instanceof Entry) {
        ((Entry) skeleton).setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8"));
        node.findChildById("subject").map(n -> build(n, false, PartyProxy.class)).ifPresent(((Entry) skeleton)::setSubject);
    }
    if (skeleton instanceof Composition) {
        node.findChildById("category").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((Composition) skeleton)::setCategory);
    }
    if (skeleton instanceof DvInterval) {
        ((DvInterval<?>) skeleton).setLowerIncluded(true);
        ((DvInterval<?>) skeleton).setUpperIncluded(true);
    }
    if (skeleton instanceof PartyRelated) {
        node.findChildById("relationship").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((PartyRelated) skeleton)::setRelationship);
    }
    if (skeleton == null || clazz.isAssignableFrom(skeleton.getClass())) {
        return (T) skeleton;
    } else {
        throw new SdkException(String.format("%s not assignable from %s", skeleton.getClass(), clazz));
    }
}
Also used : java.util(java.util) Composition(com.nedap.archie.rm.composition.Composition) RMObjectCreator(com.nedap.archie.creation.RMObjectCreator) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) SdkException(org.ehrbase.util.exception.SdkException) Archetyped(com.nedap.archie.rm.archetyped.Archetyped) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) RmConstants(org.ehrbase.util.rmconstants.RmConstants) Locatable(com.nedap.archie.rm.archetyped.Locatable) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvText(com.nedap.archie.rm.datavalues.DvText) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) ArchetypeID(com.nedap.archie.rm.support.identification.ArchetypeID) DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) RMAttributeInfo(com.nedap.archie.rminfo.RMAttributeInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) RM_VERSION_1_4_0(org.ehrbase.util.rmconstants.RmConstants.RM_VERSION_1_4_0) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) RMObject(com.nedap.archie.rm.RMObject) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) CComplexObject(com.nedap.archie.aom.CComplexObject) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) Composition(com.nedap.archie.rm.composition.Composition) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) CComplexObject(com.nedap.archie.aom.CComplexObject) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) DvText(com.nedap.archie.rm.datavalues.DvText) DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) Entry(com.nedap.archie.rm.composition.Entry) SdkException(org.ehrbase.util.exception.SdkException) RMObject(com.nedap.archie.rm.RMObject) CComplexObject(com.nedap.archie.aom.CComplexObject) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) Locatable(com.nedap.archie.rm.archetyped.Locatable)

Aggregations

CComplexObject (com.nedap.archie.aom.CComplexObject)3 CAttribute (com.nedap.archie.aom.CAttribute)2 Lists (com.google.common.collect.Lists)1 BMMConstraintImposer (com.nedap.archie.adlparser.modelconstraints.BMMConstraintImposer)1 ArchetypeModelObject (com.nedap.archie.aom.ArchetypeModelObject)1 ArchetypeSlot (com.nedap.archie.aom.ArchetypeSlot)1 CObject (com.nedap.archie.aom.CObject)1 CTerminologyCode (com.nedap.archie.aom.primitives.CTerminologyCode)1 Cardinality (com.nedap.archie.base.Cardinality)1 MultiplicityInterval (com.nedap.archie.base.MultiplicityInterval)1 RMObjectCreator (com.nedap.archie.creation.RMObjectCreator)1 PathSegment (com.nedap.archie.paths.PathSegment)1 AOMPathQuery (com.nedap.archie.query.AOMPathQuery)1 APathQuery (com.nedap.archie.query.APathQuery)1 RMObject (com.nedap.archie.rm.RMObject)1 Archetyped (com.nedap.archie.rm.archetyped.Archetyped)1 Locatable (com.nedap.archie.rm.archetyped.Locatable)1 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)1 Composition (com.nedap.archie.rm.composition.Composition)1 Entry (com.nedap.archie.rm.composition.Entry)1