Search in sources :

Example 1 with WebTemplateInputValue

use of org.ehrbase.webtemplate.model.WebTemplateInputValue in project openEHR_SDK by ehrbase.

the class OPTParserTest method parseAllTypes.

@Test
public void parseAllTypes() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.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.ALL_TYPES.getStream(), StandardCharsets.UTF_8), WebTemplate.class);
    List<WebTemplateNode> dvOrdinalList = actual.getTree().findMatching(n -> n.getRmType().equals("DV_ORDINAL"));
    assertThat(dvOrdinalList).size().isEqualTo(1);
    assertThat(dvOrdinalList.get(0).getInputs()).flatExtracting(WebTemplateInput::getList).extracting(WebTemplateInputValue::getLabel, WebTemplateInputValue::getValue, WebTemplateInputValue::getOrdinal).containsExactlyInAnyOrder(new Tuple("ord1", "at0014", 0), new Tuple("ord1", "at0015", 1), new Tuple("ord3", "at0016", 2));
    List<WebTemplateNode> dvQuantityList = actual.getTree().findMatching(n -> n.getRmType().equals("DV_QUANTITY"));
    assertThat(dvQuantityList).flatExtracting(WebTemplateNode::getInputs).flatExtracting(WebTemplateInput::getList).extracting(WebTemplateInputValue::getLabel, WebTemplateInputValue::getValue).containsExactlyInAnyOrder(new Tuple("mg", "mg"), new Tuple("kg", "kg"), new Tuple("mm[H20]", "mm[H20]"), new Tuple("mm[Hg]", "mm[Hg]"));
    List<WebTemplateNode> dvCodedTextList = actual.getTree().findMatching(n -> n.getRmType().equals("DV_CODED_TEXT"));
    assertThat(dvCodedTextList).flatExtracting(WebTemplateNode::getInputs).extracting(WebTemplateInput::getTerminology, i -> i.getList().stream().map(v -> v.getValue() + ":" + v.getLabel()).collect(Collectors.joining(";"))).containsExactlyInAnyOrder(new Tuple("openehr", "433:event"), new Tuple("local", "at0006:value1;at0007:value2;at0008:value3"), new Tuple("local", ""), new Tuple("local", ""), new Tuple("SNOMED-CT", ""), new Tuple("SNOMED-CT", ""), new Tuple("local", "at0003:Planned;at0004:Active;at0005:Completed"), new Tuple("openehr", "526:planned;245:active;532:completed"), new Tuple(null, ""), new Tuple(null, ""), new Tuple(null, ""), new Tuple(null, ""));
    List<String> errors = compareWebTemplate(actual, expected);
    checkErrors(errors, new String[] { "LocalizedNames not equal [en=active] != [] in inputValue.code:245 id=current_state aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/current_state", "LocalizedNames not equal [en=completed] != [] in inputValue.code:532 id=current_state aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/current_state", "LocalizedNames not equal [en=planned] != [] in inputValue.code:526 id=current_state aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/current_state", "LocalizedDescriptions not equal {en=*} != {} in inputValue.code:at0005 id=careflow_step aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/careflow_step", "LocalizedDescriptions not equal {en=*} != {} in inputValue.code:at0004 id=careflow_step aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/careflow_step", "LocalizedDescriptions not equal {en=*} != {} in inputValue.code:at0003 id=careflow_step aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-ACTION.test_all_types.v1]/ism_transition/careflow_step", "InContext not equal true != null in  id=action_archetype_id aql=/content[openEHR-EHR-SECTION.test_all_types.v1]/items[at0001]/items[at0002]/items[openEHR-EHR-INSTRUCTION.test_all_types.v1]/activities[at0001]/action_archetype_id" });
}
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) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 2 with WebTemplateInputValue

use of org.ehrbase.webtemplate.model.WebTemplateInputValue in project openEHR_SDK by ehrbase.

the class DvOrdinalConfig method buildChildValues.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Object> buildChildValues(String currentTerm, DvOrdinal rmObject, Context<Map<String, Object>> context) {
    Map<String, Object> result = new HashMap<>();
    String codeString = Optional.of(rmObject).map(DvOrdinal::getSymbol).map(DvCodedText::getDefiningCode).map(CodePhrase::getCodeString).orElse(null);
    addValue(result, currentTerm, "code", codeString);
    WebTemplateInputValue value = context.getNodeDeque().peek().getInputs().get(0).getList().stream().filter(o -> o.getValue().equals(codeString)).findAny().orElseThrow(() -> new SdkException(String.format("Unknown Ordinal with code %s", codeString)));
    addValue(result, currentTerm, "ordinal", value.getOrdinal());
    addValue(result, currentTerm, "value", value.getLabel());
    return result;
}
Also used : DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) HashMap(java.util.HashMap) SdkException(org.ehrbase.util.exception.SdkException) WebTemplateInputValue(org.ehrbase.webtemplate.model.WebTemplateInputValue)

Aggregations

WebTemplateInputValue (org.ehrbase.webtemplate.model.WebTemplateInputValue)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 IOUtils (org.apache.commons.io.IOUtils)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 XmlException (org.apache.xmlbeans.XmlException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 SoftAssertions (org.assertj.core.api.SoftAssertions)1 Tuple (org.assertj.core.groups.Tuple)1 OperationalTemplateTestData (org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData)1 WebTemplateTestData (org.ehrbase.test_data.webtemplate.WebTemplateTestData)1 SdkException (org.ehrbase.util.exception.SdkException)1 Filter (org.ehrbase.webtemplate.filter.Filter)1