Search in sources :

Example 6 with Element

use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.

the class StdToCompositionWalker method replaceRmObject.

private void replaceRmObject(Context<Map<FlatPathDto, String>> context, RMObject newRmObject) {
    RMObject oldRM = context.getRmObjectDeque().poll();
    RMObject parentRM = context.getRmObjectDeque().peek();
    WebTemplateNode currentNode = context.getNodeDeque().poll();
    WebTemplateNode parentNode = context.getNodeDeque().peek();
    // since flat skips Elements we might need to keep it
    if (oldRM instanceof Element && !(newRmObject instanceof Element)) {
        WebTemplateNode valueNode = currentNode.getChildren().stream().filter(n -> n.getId().contains("value")).findAny().orElseThrow();
        WebTemplateSkeletonBuilder.insert(currentNode, oldRM, valueNode, newRmObject);
        context.getRmObjectDeque().push(oldRM);
    } else {
        WebTemplateSkeletonBuilder.remove(parentNode, parentRM, currentNode, oldRM);
        WebTemplateSkeletonBuilder.insert(parentNode, parentRM, currentNode, newRmObject);
        context.getRmObjectDeque().push(newRmObject);
    }
    context.getNodeDeque().push(currentNode);
}
Also used : WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) Element(com.nedap.archie.rm.datastructures.Element) RMObject(com.nedap.archie.rm.RMObject)

Example 7 with Element

use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.

the class NullFlavorTestOverwritten method nullFlavourJsonBuild.

@Override
@Test
public void nullFlavourJsonBuild() throws Exception {
    String template = this.getFileContent("/res/Demo Vitals.xml");
    String json = this.getFileContent("/res/NullFlavor3.json");
    Composition unmarshal = getFlatJson(template, FlatFormat.STRUCTURED).unmarshal(json);
    assertThat(unmarshal).isNotNull();
    Element element1 = (Element) unmarshal.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.lab_test-hba1c.v1,1]/data/events[at0002]/data/items[at0005]").get(0);
    assertThat(element1.getValue()).isNull();
    assertThat(element1.getNullFlavour()).isEqualTo(NullFlavour.NOT_APPLICABLE.toCodedText());
    Element element2 = (Element) unmarshal.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.lab_test-hba1c.v1,2]/data/events[at0003]/data/items[at0004]").get(0);
    assertThat(element2.getValue()).isNull();
    assertThat(element2.getNullFlavour()).isEqualTo(NullFlavour.MASKED.toCodedText());
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) Element(com.nedap.archie.rm.datastructures.Element) Test(org.junit.jupiter.api.Test) NullFlavorTest(care.better.platform.web.template.NullFlavorTest)

Example 8 with Element

use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.

the class FeederAuditDetailsAttributesTest method toMap.

@Test
public void toMap() throws Exception {
    String value = IOUtils.toString(CompositionTestDataCanonicalJson.FEEDER_AUDIT_DETAILS.getStream(), UTF_8);
    CanonicalJson cut = new CanonicalJson();
    Composition composition = cut.unmarshal(value, Composition.class);
    assertNotNull(composition);
    assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
    // with real data
    FeederAuditDetailsAttributes attributes = new FeederAuditDetailsAttributes(composition.getFeederAudit().getFeederSystemAudit());
    Map<String, Object> map = attributes.toMap();
    assertNotNull(map);
    assertNotNull(map.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]"));
    // valid fabricated data without brackets
    FeederAuditDetails details = new FeederAuditDetails();
    ItemSingle single = new ItemSingle("test", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    map = attributes.toMap();
    assertNotNull(map.get("other_details[test]"));
    // valid fabricated data with brackets
    details = new FeederAuditDetails();
    single = new ItemSingle("[test]", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    map = attributes.toMap();
    assertNotNull(map.get("other_details[test]"));
    // invalid data with one [
    details = new FeederAuditDetails();
    single = new ItemSingle("[test", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    assertThrows(IllegalArgumentException.class, attributes::toMap);
    // invalid data with one ]
    details = new FeederAuditDetails();
    single = new ItemSingle("test]", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    assertThrows(IllegalArgumentException.class, attributes::toMap);
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) Composition(com.nedap.archie.rm.composition.Composition) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Element(com.nedap.archie.rm.datastructures.Element) DvText(com.nedap.archie.rm.datavalues.DvText) FeederAuditDetails(com.nedap.archie.rm.archetyped.FeederAuditDetails) ItemSingle(com.nedap.archie.rm.datastructures.ItemSingle) Test(org.junit.Test)

Example 9 with Element

use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.

the class CanonicalJsonMarshallingTest method UnmarshalMultimediaElement.

@Test
public void UnmarshalMultimediaElement() throws IOException {
    String value = new String(Files.readAllBytes(Paths.get("src/test/resources/sample_data/element_multimedia.json")));
    CanonicalJson cut = new CanonicalJson();
    Element element = cut.unmarshal(value, Element.class);
    assertNotNull(element);
}
Also used : Element(com.nedap.archie.rm.datastructures.Element) Test(org.junit.Test)

Example 10 with Element

use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.

the class NumericTestsIT method setUp.

@Before
public void setUp() throws IOException {
    super.setUp(null);
    // build a number of compositions with different DvQuantity values and different names
    aComposition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.MINIMAL_EVAL.getStream(), StandardCharsets.UTF_8), Composition.class);
    for (int i = 0; i < 10; i++) {
        Element element = (Element) aComposition.itemsAtPath("/content[openEHR-EHR-EVALUATION.minimal.v1]/data[at0001]/items[at0002]").get(0);
        element.setValue(new DvQuantity("kg", Double.valueOf("" + (i + 1)), 0L));
        element.setName(new DvText("value-" + i + 1));
        Flattener flattener = new Flattener(new TestDataTemplateProvider());
        MinimalEvaluationEnV1Composition minimalEvaluationEnV1Composition = flattener.flatten(aComposition, MinimalEvaluationEnV1Composition.class);
        // create the composition
        MinimalEvaluationEnV1Composition comp = compositionEndpoint.mergeCompositionEntity(minimalEvaluationEnV1Composition);
    }
    numericQuery = new NumericQuery(ehrUUID, openEhrClient);
}
Also used : NumericQuery(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.NumericQuery) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) Composition(com.nedap.archie.rm.composition.Composition) MinimalEvaluationEnV1Composition(org.ehrbase.client.classgenerator.examples.minimalevaluationenv1composition.MinimalEvaluationEnV1Composition) DvQuantity(com.nedap.archie.rm.datavalues.quantity.DvQuantity) Element(com.nedap.archie.rm.datastructures.Element) Flattener(org.ehrbase.client.flattener.Flattener) MinimalEvaluationEnV1Composition(org.ehrbase.client.classgenerator.examples.minimalevaluationenv1composition.MinimalEvaluationEnV1Composition) DvText(com.nedap.archie.rm.datavalues.DvText) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) Before(org.junit.Before)

Aggregations

Element (com.nedap.archie.rm.datastructures.Element)10 Composition (com.nedap.archie.rm.composition.Composition)7 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)5 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)5 Test (org.junit.Test)5 DvText (com.nedap.archie.rm.datavalues.DvText)4 Locatable (com.nedap.archie.rm.archetyped.Locatable)3 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)3 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)3 DvQuantity (com.nedap.archie.rm.datavalues.quantity.DvQuantity)3 List (java.util.List)3 NullFlavorTest (care.better.platform.web.template.NullFlavorTest)2 AdminEntry (com.nedap.archie.rm.composition.AdminEntry)2 Observation (com.nedap.archie.rm.composition.Observation)2 IntervalEvent (com.nedap.archie.rm.datastructures.IntervalEvent)2 PointEvent (com.nedap.archie.rm.datastructures.PointEvent)2 DvURI (com.nedap.archie.rm.datavalues.DvURI)2 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)2 PartySelf (com.nedap.archie.rm.generic.PartySelf)2