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