Search in sources :

Example 1 with Filter

use of org.ehrbase.webtemplate.filter.Filter in project openEHR_SDK by ehrbase.

the class StdToCompositionWalker method isMatchingNode.

private boolean isMatchingNode(Map<FlatPathDto, String> subValues, Context<Map<FlatPathDto, String>> context, WebTemplateNode child, FlatPathDto currentFlatPath) {
    if (child.getRmType().equals("POINT_EVENT")) {
        return subValues.entrySet().stream().allMatch((e -> !e.getKey().getLast().getName().equals("width")));
    } else if (child.getRmType().equals("INTERVAL_EVENT")) {
        return subValues.entrySet().stream().anyMatch((e -> e.getKey().getLast().getName().equals("width")));
    } else if (visitChildren(child)) {
        for (WebTemplateNode n : child.getChildren()) {
            context.getNodeDeque().push(n);
            String path = context.getFlatHelper().buildNamePath(context, true);
            context.getNodeDeque().remove();
            subValues = subValues.entrySet().stream().filter(e -> !e.getKey().startsWith(path)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        }
        return subValues.isEmpty();
    } else if (child.getRmType().equals(DV_CODED_TEXT)) {
        return subValues.keySet().stream().anyMatch(e -> "code".equals(e.getLast().getAttributeName()) && currentFlatPath.getLast().getName().equals(e.getLast().getName()));
    } else if (child.getRmType().equals(DV_TEXT)) {
        return subValues.keySet().stream().allMatch((e -> !("code".equals(e.getLast().getAttributeName()) && currentFlatPath.getLast().getName().equals(e.getLast().getName()))));
    } else {
        // End Nodes which are Choice always have unique flat paths
        return true;
    }
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) ToCompositionWalker(org.ehrbase.serialisation.walker.ToCompositionWalker) DefaultRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.DefaultRMUnmarshaller) Element(com.nedap.archie.rm.datastructures.Element) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) WebTemplateSkeletonBuilder(org.ehrbase.building.webtemplateskeletnbuilder.WebTemplateSkeletonBuilder) HashSet(java.util.HashSet) Map(java.util.Map) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) UnmarshalPostprocessor(org.ehrbase.serialisation.flatencoding.std.umarshal.postprocessor.UnmarshalPostprocessor) DV_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_TEXT) Context(org.ehrbase.serialisation.walker.Context) ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) ELEMENT(org.ehrbase.util.rmconstants.RmConstants.ELEMENT) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) DvText(com.nedap.archie.rm.datavalues.DvText) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) DV_CODED_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_CODED_TEXT) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) UnmarshalException(org.ehrbase.serialisation.exception.UnmarshalException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) Objects(java.util.Objects) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) List(java.util.List) WebTemplateUtils(org.ehrbase.webtemplate.util.WebTemplateUtils) RMObject(com.nedap.archie.rm.RMObject) Optional(java.util.Optional) RMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.RMUnmarshaller) NodeId(org.ehrbase.serialisation.walker.NodeId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) Collections(java.util.Collections) Filter(org.ehrbase.webtemplate.filter.Filter) Entry(com.nedap.archie.rm.composition.Entry) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode)

Example 2 with Filter

use of org.ehrbase.webtemplate.filter.Filter in project openEHR_SDK by ehrbase.

the class StdToCompositionWalker method extract.

@Override
protected Map<FlatPathDto, String> extract(Context<Map<FlatPathDto, String>> context, WebTemplateNode child, boolean isChoice, Integer count) {
    context.getNodeDeque().push(child);
    Integer oldCount = null;
    if (count != null) {
        oldCount = context.getCountMap().get(new NodeId(child));
        context.getCountMap().put(new NodeId(child), count);
    }
    String path;
    path = buildNamePathWithElementHandling(context);
    context.getNodeDeque().remove();
    context.getCountMap().remove(new NodeId(child));
    if (oldCount != null) {
        context.getCountMap().put(new NodeId(child), oldCount);
    }
    Map<FlatPathDto, String> subValues = context.getObjectDeque().peek().entrySet().stream().filter(e -> e.getKey().startsWith(path)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    if (isChoice && !isMatchingNode(subValues, context, child, new FlatPathDto(path))) {
        subValues = Collections.emptyMap();
    }
    if (!subValues.isEmpty()) {
        return subValues;
    } else {
        return null;
    }
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) ToCompositionWalker(org.ehrbase.serialisation.walker.ToCompositionWalker) DefaultRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.DefaultRMUnmarshaller) Element(com.nedap.archie.rm.datastructures.Element) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) WebTemplateSkeletonBuilder(org.ehrbase.building.webtemplateskeletnbuilder.WebTemplateSkeletonBuilder) HashSet(java.util.HashSet) Map(java.util.Map) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) UnmarshalPostprocessor(org.ehrbase.serialisation.flatencoding.std.umarshal.postprocessor.UnmarshalPostprocessor) DV_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_TEXT) Context(org.ehrbase.serialisation.walker.Context) ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) ELEMENT(org.ehrbase.util.rmconstants.RmConstants.ELEMENT) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) DvText(com.nedap.archie.rm.datavalues.DvText) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) DV_CODED_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_CODED_TEXT) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) UnmarshalException(org.ehrbase.serialisation.exception.UnmarshalException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) Objects(java.util.Objects) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) List(java.util.List) WebTemplateUtils(org.ehrbase.webtemplate.util.WebTemplateUtils) RMObject(com.nedap.archie.rm.RMObject) Optional(java.util.Optional) RMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.RMUnmarshaller) NodeId(org.ehrbase.serialisation.walker.NodeId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) Collections(java.util.Collections) Filter(org.ehrbase.webtemplate.filter.Filter) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) NodeId(org.ehrbase.serialisation.walker.NodeId) Map(java.util.Map)

Example 3 with Filter

use of org.ehrbase.webtemplate.filter.Filter in project openEHR_SDK by ehrbase.

the class StdToCompositionWalker method calculateSize.

@Override
protected int calculateSize(Context<Map<FlatPathDto, String>> context, WebTemplateNode childNode) {
    Integer oldCount = context.getCountMap().get(new NodeId(childNode));
    String namePath = context.getFlatHelper().buildNamePath(context, true);
    String finalNamePath = namePath;
    Integer count = context.getObjectDeque().peek().keySet().stream().filter(s -> s.startsWith(finalNamePath)).map(s -> FlatPathDto.removeStart(s, new FlatPathDto(finalNamePath))).filter(n -> n != null && n.getName().equals(childNode.getId())).map(n -> Optional.ofNullable(n.getCount()).orElse(0)).sorted().reduce((first, second) -> second).map(i -> i + 1).orElse(0);
    if (oldCount != null) {
        context.getCountMap().put(new NodeId(childNode), oldCount);
    }
    return count;
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) ToCompositionWalker(org.ehrbase.serialisation.walker.ToCompositionWalker) DefaultRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.DefaultRMUnmarshaller) Element(com.nedap.archie.rm.datastructures.Element) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) WebTemplateSkeletonBuilder(org.ehrbase.building.webtemplateskeletnbuilder.WebTemplateSkeletonBuilder) HashSet(java.util.HashSet) Map(java.util.Map) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) UnmarshalPostprocessor(org.ehrbase.serialisation.flatencoding.std.umarshal.postprocessor.UnmarshalPostprocessor) DV_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_TEXT) Context(org.ehrbase.serialisation.walker.Context) ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) ELEMENT(org.ehrbase.util.rmconstants.RmConstants.ELEMENT) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) DvText(com.nedap.archie.rm.datavalues.DvText) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) DV_CODED_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_CODED_TEXT) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) UnmarshalException(org.ehrbase.serialisation.exception.UnmarshalException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) Objects(java.util.Objects) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) List(java.util.List) WebTemplateUtils(org.ehrbase.webtemplate.util.WebTemplateUtils) RMObject(com.nedap.archie.rm.RMObject) Optional(java.util.Optional) RMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.RMUnmarshaller) NodeId(org.ehrbase.serialisation.walker.NodeId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) Collections(java.util.Collections) Filter(org.ehrbase.webtemplate.filter.Filter) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) NodeId(org.ehrbase.serialisation.walker.NodeId)

Example 4 with Filter

use of org.ehrbase.webtemplate.filter.Filter in project openEHR_SDK by ehrbase.

the class OPTParserTest method parseGECCODiagnose.

@Test
public void parseGECCODiagnose() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.GECCO_DIAGNOSE.getStream()).getTemplate();
    OPTParser cut = new OPTParser(template);
    WebTemplate actual = cut.parse();
    actual = new Filter().filter(actual);
    ObjectMapper objectMapper = new ObjectMapper();
    WebTemplate expected = objectMapper.readValue(IOUtils.toString(WebTemplateTestData.GECCO_DIAGNOSE.getStream(), StandardCharsets.UTF_8), WebTemplate.class);
    List<String> errors = compareWebTemplate(actual, expected).stream().filter(f -> !f.startsWith("LocalizedDescriptions not equal") && !f.startsWith("LocalizedNames not equal") && !f.startsWith("Annotations not equal")).collect(Collectors.toList());
    checkErrors(errors, new String[] { "Extra Input code:TEXT in id=name_des_problems_der_diagnose aql=/content[openEHR-EHR-EVALUATION.problem_diagnosis.v1 and name/value='Vorliegende Diagnose']/data[at0001]/items[at0002]/value", "Extra Input value:TEXT in id=name_des_problems_der_diagnose aql=/content[openEHR-EHR-EVALUATION.problem_diagnosis.v1 and name/value='Vorliegende Diagnose']/data[at0001]/items[at0002]/value", "Missing Input null:TEXT in id=name_des_problems_der_diagnose aql=/content[openEHR-EHR-EVALUATION.problem_diagnosis.v1 and name/value='Vorliegende Diagnose']/data[at0001]/items[at0002]/value" });
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Tuple(org.assertj.core.groups.Tuple) java.util(java.util) SoftAssertions(org.assertj.core.api.SoftAssertions) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) Test(org.junit.Test) IOException(java.io.IOException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) StandardCharsets(java.nio.charset.StandardCharsets) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) IOUtils(org.apache.commons.io.IOUtils) WebTemplateInputValue(org.ehrbase.webtemplate.model.WebTemplateInputValue) XmlException(org.apache.xmlbeans.XmlException) WebTemplateTestData(org.ehrbase.test_data.webtemplate.WebTemplateTestData) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) Filter(org.ehrbase.webtemplate.filter.Filter) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) Filter(org.ehrbase.webtemplate.filter.Filter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with Filter

use of org.ehrbase.webtemplate.filter.Filter in project openEHR_SDK by ehrbase.

the class OPTParserTest method parseMultiOccurrence.

@Test
public void parseMultiOccurrence() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.MULTI_OCCURRENCE.getStream()).getTemplate();
    OPTParser cut = new OPTParser(template);
    WebTemplate actual = cut.parse();
    actual = new Filter().filter(actual);
    assertThat(actual).isNotNull();
    ObjectMapper objectMapper = new ObjectMapper();
    WebTemplate expected = objectMapper.readValue(IOUtils.toString(WebTemplateTestData.MULTI_OCCURRENCE.getStream(), StandardCharsets.UTF_8), WebTemplate.class);
    List<String> errors = compareWebTemplate(actual, expected);
    checkErrors(errors, new String[] { "Validation not equal WebTemplateValidation{precision=WebTemplateValidationInterval{min=1, minOp=GT_EQ, max=1, maxOp=LT_EQ}, range=WebTemplateValidationInterval{min=0.0, minOp=GT_EQ, max=100.0, maxOp=LT}, pattern='null'} != WebTemplateValidation{precision=WebTemplateValidationInterval{min=1, minOp=GT_EQ, max=1, maxOp=LT_EQ}, range=WebTemplateValidationInterval{min=0, minOp=GT_EQ, max=100, maxOp=LT}, pattern='null'} in inputValue.code:Cel id=temperature aql=/content[openEHR-EHR-OBSERVATION.body_temperature.v2]/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value", "Validation not equal WebTemplateValidation{precision=WebTemplateValidationInterval{min=1, minOp=GT_EQ, max=1, maxOp=LT_EQ}, range=WebTemplateValidationInterval{min=30.0, minOp=GT_EQ, max=200.0, maxOp=LT}, pattern='null'} != WebTemplateValidation{precision=WebTemplateValidationInterval{min=1, minOp=GT_EQ, max=1, maxOp=LT_EQ}, range=WebTemplateValidationInterval{min=30, minOp=GT_EQ, max=200, maxOp=LT}, pattern='null'} in inputValue.code:[degF] id=temperature aql=/content[openEHR-EHR-OBSERVATION.body_temperature.v2]/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value" });
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) Filter(org.ehrbase.webtemplate.filter.Filter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Filter (org.ehrbase.webtemplate.filter.Filter)18 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Test (org.junit.Test)12 OPERATIONALTEMPLATE (org.openehr.schemas.v1.OPERATIONALTEMPLATE)12 Collectors (java.util.stream.Collectors)7 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)7 CollectionUtils (org.apache.commons.collections4.CollectionUtils)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6 Composition (com.nedap.archie.rm.composition.Composition)5 WebTemplateInput (org.ehrbase.webtemplate.model.WebTemplateInput)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 RMObject (com.nedap.archie.rm.RMObject)4 Entry (com.nedap.archie.rm.composition.Entry)4 Element (com.nedap.archie.rm.datastructures.Element)4 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)4 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)4 DvText (com.nedap.archie.rm.datavalues.DvText)4 PartyRelated (com.nedap.archie.rm.generic.PartyRelated)4 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)4