Search in sources :

Example 1 with Locatable

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

the class LocatableMarshalPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, Locatable rmObject, Map<String, Object> values, Context<Map<String, Object>> context) {
    if (RmConstants.ELEMENT.equals(context.getNodeDeque().peek().getRmType()) || !context.getFlatHelper().skip(context)) {
        addValue(values, term + PATH_DIVIDER + "_uid", null, Optional.of(rmObject).map(Locatable::getUid).map(ObjectId::getValue).orElse(null));
        if (rmObject.getLinks() != null) {
            IntStream.range(0, rmObject.getLinks().size()).forEach(i -> {
                Link link = rmObject.getLinks().get(i);
                String termLoop = term + PATH_DIVIDER + "_link:" + i;
                addValue(values, termLoop, "meaning", Optional.of(link).map(Link::getMeaning).map(DvText::getValue).orElse(null));
                addValue(values, termLoop, "type", Optional.of(link).map(Link::getType).map(DvText::getValue).orElse(null));
                addValue(values, termLoop, "target", Optional.of(link).map(Link::getTarget).map(DvEHRURI::getValue).orElse(null));
            });
        }
        if (rmObject.getFeederAudit() != null) {
            callMarshal(term, "_feeder_audit", rmObject.getFeederAudit(), values, context, context.getNodeDeque().peek().findChildById("feeder_audit").orElse(FlatHelper.buildDummyChild("feeder_audit", context.getNodeDeque().peek())));
        }
        if (Optional.ofNullable(rmObject.getName()).map(DvText::getValue).filter(n -> !Objects.equals(context.getNodeDeque().peek().getName(), n)).isPresent()) {
            handleRmAttribute(term, rmObject.getName(), values, context, "name");
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Context(org.ehrbase.serialisation.walker.Context) FlatHelper(org.ehrbase.serialisation.walker.FlatHelper) DvText(com.nedap.archie.rm.datavalues.DvText) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) Objects(java.util.Objects) PATH_DIVIDER(org.ehrbase.webtemplate.parser.OPTParser.PATH_DIVIDER) Map(java.util.Map) RmConstants(org.ehrbase.util.rmconstants.RmConstants) Locatable(com.nedap.archie.rm.archetyped.Locatable) Optional(java.util.Optional) Link(com.nedap.archie.rm.archetyped.Link) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) Link(com.nedap.archie.rm.archetyped.Link) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 2 with Locatable

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

the class OptSkeletonBuilderTest method testGenerateCorona.

@Test
public void testGenerateCorona() throws Exception {
    org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream());
    OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
    OptSkeletonBuilder cut = new OptSkeletonBuilder();
    Composition generate = (Composition) cut.generate(operationaltemplate);
    assertThat(generate.getContent()).extracting(Locatable::getName).extracting(DvText::getValue).containsExactlyInAnyOrder("Geschichte/Historie", "Symptome", "Kontakt", "Risikogebiet", "Allgemeine Angaben");
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) Locatable(com.nedap.archie.rm.archetyped.Locatable) Test(org.junit.Test)

Example 3 with Locatable

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

the class DefaultValidator method validate.

private List<ConstraintViolation> validate(Locatable locatable, WebTemplateNode node) {
    List<ConstraintViolation> result = new ArrayList<>();
    node.getChildren().forEach(childNode -> {
        var count = 0;
        for (var item : locatable.itemsAtPath(node.buildRelativePath(childNode))) {
            if (item instanceof Locatable) {
                if (!node.isRelativePathNameDependent(childNode) || Objects.equals(((Locatable) item).getNameAsString(), childNode.getName())) {
                    count++;
                }
            } else {
                count++;
            }
        }
        var interval = getMultiplicityInterval(childNode, node);
        if (!interval.has(count)) {
            String message = RMObjectValidationMessageIds.rm_OCCURRENCE_MISMATCH.getMessage(count, interval.toString());
            result.add(new ConstraintViolation(childNode.getAqlPath(), message));
        }
    });
    return result;
}
Also used : ConstraintViolation(org.ehrbase.validation.ConstraintViolation) ArrayList(java.util.ArrayList) Locatable(com.nedap.archie.rm.archetyped.Locatable)

Example 4 with Locatable

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

the class ItemExtractor method invoke.

public ItemExtractor invoke() {
    relativeAql = StringUtils.removeEnd(StringUtils.removeStart(childNode.getAqlPath(), currentNode.getAqlPath()), "/");
    FlatPath childPath = new FlatPath(relativeAql);
    parentAql = StringUtils.removeEnd(childPath.format(false), childPath.format(false).substring(childPath.format(false).lastIndexOf("/")));
    if (StringUtils.isBlank(parentAql)) {
        parentAql = "/";
    }
    if (currentRM instanceof Pathable) {
        try {
            child = ((Pathable) currentRM).itemsAtPath(childPath.format(false));
            if (child == null || ((List) child).isEmpty()) {
                child = ((Pathable) currentRM).itemAtPath(childPath.format(false));
            }
        } catch (RuntimeException e) {
            child = null;
        }
        parent = ((Pathable) currentRM).itemAtPath(parentAql);
    } else if (currentRM instanceof DvInterval) {
        if (relativeAql.contains("upper_included")) {
            child = new RmBoolean(((DvInterval<?>) currentRM).isUpperIncluded());
        } else if (relativeAql.contains("lower_included")) {
            child = new RmBoolean(((DvInterval<?>) currentRM).isLowerIncluded());
        } else if (relativeAql.contains("lower")) {
            child = ((DvInterval<?>) currentRM).getLower();
        } else if (relativeAql.contains("upper")) {
            child = ((DvInterval<?>) currentRM).getUpper();
        }
        parent = currentRM;
    } else {
        throw new SdkException(String.format("Can not extract from class %s", currentRM.getClass().getSimpleName()));
    }
    if (StringUtils.isNotBlank(childPath.findOtherPredicate("name/value")) && child instanceof List && Locatable.class.isAssignableFrom(Walker.ARCHIE_RM_INFO_LOOKUP.getClass(childNode.getRmType()))) {
        child = ((List) child).stream().filter(c -> childPath.findOtherPredicate("name/value").equals(((Locatable) c).getNameAsString())).collect(Collectors.toList());
        // if name not found return null
        if (((List<?>) child).isEmpty()) {
            child = null;
        }
    }
    if (isChoice && child instanceof List) {
        child = ((List) child).stream().filter(c -> Walker.ARCHIE_RM_INFO_LOOKUP.getTypeInfo(c.getClass()).getRmName().equals(childNode.getRmType())).collect(Collectors.toList());
        // if rmType not found return null
        if (((List<?>) child).isEmpty()) {
            child = null;
        }
    }
    if ((childNode.getMax() == 1 || currentNode.getRmType().equals(RmConstants.ELEMENT)) && child instanceof List) {
        if (((List<?>) child).isEmpty()) {
            child = null;
        } else {
            child = ((List) child).get(0);
        }
    }
    if (child instanceof Element && !childNode.getRmType().equals(RmConstants.ELEMENT)) {
        child = ((Element) child).getValue();
    }
    return this;
}
Also used : DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) SdkException(org.ehrbase.util.exception.SdkException) Element(com.nedap.archie.rm.datastructures.Element) List(java.util.List) Pathable(com.nedap.archie.rm.archetyped.Pathable) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) Locatable(com.nedap.archie.rm.archetyped.Locatable)

Example 5 with Locatable

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

the class ToCompositionWalker method postHandle.

@Override
protected void postHandle(Context<T> context) {
    RMObject currentRM = context.getRmObjectDeque().peek();
    WebTemplateNode currentNode = context.getNodeDeque().peek();
    if (currentRM instanceof Locatable) {
        org.ehrbase.webtemplate.parser.NodeId nodeId = new NodeId(currentNode.getNodeId());
        if (nodeId.isArchetypeId()) {
            Archetyped archetyped = new Archetyped();
            archetyped.setArchetypeId(new ArchetypeID(nodeId.getNodeId()));
            archetyped.setRmVersion(RM_VERSION_1_4_0);
            TemplateId templateId = new TemplateId();
            templateId.setValue(context.getTemplateId());
            archetyped.setTemplateId(templateId);
            ((Locatable) currentRM).setArchetypeDetails(archetyped);
            ((Locatable) currentRM).setArchetypeNodeId(nodeId.getNodeId());
        }
    }
    normalise(currentRM);
}
Also used : NodeId(org.ehrbase.webtemplate.parser.NodeId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) NodeId(org.ehrbase.webtemplate.parser.NodeId) Archetyped(com.nedap.archie.rm.archetyped.Archetyped) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) RMObject(com.nedap.archie.rm.RMObject) Locatable(com.nedap.archie.rm.archetyped.Locatable) ArchetypeID(com.nedap.archie.rm.support.identification.ArchetypeID)

Aggregations

Locatable (com.nedap.archie.rm.archetyped.Locatable)9 RMObject (com.nedap.archie.rm.RMObject)5 Composition (com.nedap.archie.rm.composition.Composition)4 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)3 List (java.util.List)3 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)3 ContentItem (com.nedap.archie.rm.composition.ContentItem)2 Observation (com.nedap.archie.rm.composition.Observation)2 Event (com.nedap.archie.rm.datastructures.Event)2 IntervalEvent (com.nedap.archie.rm.datastructures.IntervalEvent)2 ItemStructure (com.nedap.archie.rm.datastructures.ItemStructure)2 PointEvent (com.nedap.archie.rm.datastructures.PointEvent)2 DvQuantity (com.nedap.archie.rm.datavalues.quantity.DvQuantity)2 PartySelf (com.nedap.archie.rm.generic.PartySelf)2 IOException (java.io.IOException)2 URI (java.net.URI)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Duration (java.time.Duration)2 OffsetDateTime (java.time.OffsetDateTime)2 ZoneOffset (java.time.ZoneOffset)2