Search in sources :

Example 1 with DvInterval

use of com.nedap.archie.rm.datavalues.quantity.DvInterval 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 2 with DvInterval

use of com.nedap.archie.rm.datavalues.quantity.DvInterval in project openEHR_SDK by ehrbase.

the class DvOrderedPostprocessor method handleNormalRange.

private void handleNormalRange(Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context, String term, Consumer<DvInterval> rangeConsumer) {
    Map<FlatPathDto, String> rangeValues = FlatHelper.filter(values, term, false);
    if (!rangeValues.isEmpty()) {
        DvInterval range = new DvInterval();
        rangeConsumer.accept(range);
        handleBorder(values, consumedPaths, context, "upper", range::setUpper, term);
        handleBorder(values, consumedPaths, context, "lower", range::setLower, term);
        callPostProcess(term, null, range, rangeValues, consumedPaths, context, context.getNodeDeque().peek().findChildById("range").orElse(FlatHelper.buildDummyChild("range", context.getNodeDeque().peek())));
    }
}
Also used : DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto)

Example 3 with DvInterval

use of com.nedap.archie.rm.datavalues.quantity.DvInterval in project openEHR_SDK by ehrbase.

the class DBEncodeTest method testDBDecodeDvIntervalCompositeClass.

@Test
public void testDBDecodeDvIntervalCompositeClass() throws Exception {
    String db_encoded = IOUtils.resourceToString("/composition/canonical_json/composition_with_dvinterval_composite.json", UTF_8);
    assertNotNull(db_encoded);
    JsonElement converted = new LightRawJsonEncoder(db_encoded).encodeContentAsJson(null);
    // see if this can be interpreted by Archie
    Composition composition = new CanonicalJson().unmarshal(converted.toString(), Composition.class);
    // hack the composition to figure out what is the format of DvInterval...
    ((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setLower(new DvDateTime("2019-11-22T00:00+01:00"));
    ((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setUpper(new DvDateTime("2019-12-22T00:00+01:00"));
    assertNotNull(composition);
    String toJson = new CanonicalJson().marshal(composition);
    String interpreted = new CanonicalXML().marshal(composition);
    assertNotNull(interpreted);
}
Also used : DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) JsonElement(com.google.gson.JsonElement) AdminEntry(com.nedap.archie.rm.composition.AdminEntry) CanonicalXML(org.ehrbase.serialisation.xmlencoding.CanonicalXML) CompositionTestDataCanonicalXML(org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Test(org.junit.Test)

Example 4 with DvInterval

use of com.nedap.archie.rm.datavalues.quantity.DvInterval 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

DvInterval (com.nedap.archie.rm.datavalues.quantity.DvInterval)4 Locatable (com.nedap.archie.rm.archetyped.Locatable)2 Composition (com.nedap.archie.rm.composition.Composition)2 SdkException (org.ehrbase.util.exception.SdkException)2 FlatPath (org.ehrbase.webtemplate.parser.FlatPath)2 JsonElement (com.google.gson.JsonElement)1 CComplexObject (com.nedap.archie.aom.CComplexObject)1 RMObjectCreator (com.nedap.archie.creation.RMObjectCreator)1 RMObject (com.nedap.archie.rm.RMObject)1 Archetyped (com.nedap.archie.rm.archetyped.Archetyped)1 Pathable (com.nedap.archie.rm.archetyped.Pathable)1 TemplateId (com.nedap.archie.rm.archetyped.TemplateId)1 AdminEntry (com.nedap.archie.rm.composition.AdminEntry)1 Entry (com.nedap.archie.rm.composition.Entry)1 Element (com.nedap.archie.rm.datastructures.Element)1 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)1 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)1 DvText (com.nedap.archie.rm.datavalues.DvText)1 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)1 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)1