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;
}
}
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;
}
}
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;
}
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" });
}
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" });
}
Aggregations