Search in sources :

Example 1 with Link

use of com.nedap.archie.rm.archetyped.Link 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 Link

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

the class LinksEncodingTest method testToDb.

public void testToDb() {
    LinksEncoding encoding = new LinksEncoding();
    Link link = new Link(new DvText("something"), new DvText("something else"), new DvEHRURI("ehr://target"));
    String encoded = encoding.toDB(Collections.singletonList(link));
    assertNotNull(encoded);
}
Also used : DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) Link(com.nedap.archie.rm.archetyped.Link) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 3 with Link

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

the class LinksEncodingTest method testFromDbOneLink.

public void testFromDbOneLink() {
    LinksEncoding encoding = new LinksEncoding();
    Link link = new Link(new DvText("something"), new DvText("something else"), new DvEHRURI("ehr://target"));
    List<Link> list = Collections.singletonList(link);
    String encoded = encoding.toDB(list);
    assertNotNull(encoded);
    List<Link> result1 = encoding.fromDB(encoded);
    assertEquals(list, result1);
}
Also used : DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) Link(com.nedap.archie.rm.archetyped.Link) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 4 with Link

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

the class LinksEncodingTest method testFromDbTwoLinks.

public void testFromDbTwoLinks() {
    LinksEncoding encoding = new LinksEncoding();
    Link link = new Link(new DvText("something"), new DvText("something else"), new DvEHRURI("ehr://target"));
    List<Link> list = Collections.singletonList(link);
    String encoded = encoding.toDB(list);
    assertNotNull(encoded);
    Link link2 = new Link(new DvText("something2"), new DvText("something else2"), new DvEHRURI("ehr://target2"));
    List<Link> list2 = new ArrayList<Link>();
    list2.add(link);
    list2.add(link2);
    String encoded2 = encoding.toDB(list2);
    List<Link> result2 = encoding.fromDB(encoded2);
    assertEquals(list2, result2);
}
Also used : DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) ArrayList(java.util.ArrayList) Link(com.nedap.archie.rm.archetyped.Link) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 5 with Link

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

the class LinksAttributes method toMap.

public List<Map<String, Object>> toMap() {
    List<Map<String, Object>> links = new ArrayList<>();
    for (Link link : linkList) {
        Map<String, Object> valuemap = PathMap.getInstance();
        valuemap.put(TAG_CLASS, new SimpleClassName(link).toString());
        valuemap.put("meaning", link.getMeaning());
        valuemap.put("type", link.getType());
        valuemap.put("target", link.getTarget());
        links.add(valuemap);
    }
    return links;
}
Also used : ArrayList(java.util.ArrayList) SimpleClassName(org.ehrbase.serialisation.dbencoding.SimpleClassName) Map(java.util.Map) PathMap(org.ehrbase.serialisation.dbencoding.PathMap) Link(com.nedap.archie.rm.archetyped.Link)

Aggregations

Link (com.nedap.archie.rm.archetyped.Link)5 DvEHRURI (com.nedap.archie.rm.datavalues.DvEHRURI)4 DvText (com.nedap.archie.rm.datavalues.DvText)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Locatable (com.nedap.archie.rm.archetyped.Locatable)1 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 IntStream (java.util.stream.IntStream)1 PathMap (org.ehrbase.serialisation.dbencoding.PathMap)1 SimpleClassName (org.ehrbase.serialisation.dbencoding.SimpleClassName)1 Context (org.ehrbase.serialisation.walker.Context)1 FlatHelper (org.ehrbase.serialisation.walker.FlatHelper)1 RmConstants (org.ehrbase.util.rmconstants.RmConstants)1 PATH_DIVIDER (org.ehrbase.webtemplate.parser.OPTParser.PATH_DIVIDER)1