use of com.nedap.archie.rm.datavalues.DvText in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method build.
@SuppressWarnings("unchecked")
public static <T> T build(WebTemplateNode node, boolean withChildren, Class<T> clazz) {
String rmclass = node.getRmType();
CComplexObject elementConstraint = new CComplexObject();
elementConstraint.setRmTypeName(rmclass);
Object skeleton;
switch(rmclass) {
case "UID_BASED_ID":
skeleton = new HierObjectId();
break;
case "PARTY_PROXY":
skeleton = new PartyIdentified();
break;
case "STRING":
case "LONG":
skeleton = null;
break;
case "BOOLEAN":
skeleton = false;
break;
default:
skeleton = RM_OBJECT_CREATOR.create(elementConstraint);
break;
}
if (withChildren) {
node.getChildren().stream().filter(n -> !List.of("name", "archetype_node_id", "offset").contains(n.getId())).forEach(c -> {
Object childObject = build(c, true, Object.class);
insert(node, (RMObject) skeleton, c, childObject);
});
}
if (skeleton instanceof Locatable) {
Optional<WebTemplateNode> name = node.findChildById("name");
if (name.isPresent()) {
if (name.get().getRmType().equals(RmConstants.DV_CODED_TEXT)) {
((Locatable) skeleton).setName(extractDefault(name.get(), DvCodedText.class).orElseThrow());
} else {
((Locatable) skeleton).setName(extractDefault(name.get(), DvText.class).orElse(new DvText(node.getName())));
}
} else {
((Locatable) skeleton).setName(new DvText(node.getName()));
}
((Locatable) skeleton).setArchetypeNodeId(node.getNodeId());
}
if (skeleton instanceof Entry) {
((Entry) skeleton).setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8"));
node.findChildById("subject").map(n -> build(n, false, PartyProxy.class)).ifPresent(((Entry) skeleton)::setSubject);
}
if (skeleton instanceof Composition) {
node.findChildById("category").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((Composition) skeleton)::setCategory);
}
if (skeleton instanceof DvInterval) {
((DvInterval<?>) skeleton).setLowerIncluded(true);
((DvInterval<?>) skeleton).setUpperIncluded(true);
}
if (skeleton instanceof PartyRelated) {
node.findChildById("relationship").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((PartyRelated) skeleton)::setRelationship);
}
if (skeleton == null || clazz.isAssignableFrom(skeleton.getClass())) {
return (T) skeleton;
} else {
throw new SdkException(String.format("%s not assignable from %s", skeleton.getClass(), clazz));
}
}
use of com.nedap.archie.rm.datavalues.DvText 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);
}
use of com.nedap.archie.rm.datavalues.DvText in project openEHR_SDK by ehrbase.
the class ItemStructureVisitorTest method ehrVisitorTest.
@Test
public void ehrVisitorTest() throws Throwable {
String value = IOUtils.toString(ItemStruktureTestDataCanonicalJson.SIMPLE_EHR_OTHER_Details.getStream(), UTF_8);
RMJacksonConfiguration configuration = new RMJacksonConfiguration();
configuration.setTypePropertyName("_type");
ObjectMapper objectMapper = JacksonUtil.getObjectMapper(configuration);
ItemTree otherDetails = objectMapper.readValue(value, ItemTree.class);
EhrStatus ehrStatus = new EhrStatus("ehr_status", new DvText("ehr_status"), new PartySelf(new PartyRef()), true, true, otherDetails);
itemStructureVisitor.validate(ehrStatus);
assertEquals(3, itemStructureVisitor.getElementOccurrences());
}
use of com.nedap.archie.rm.datavalues.DvText in project openEHR_SDK by ehrbase.
the class DvTextValidatorTest method testValidate_ListOpen.
@Test
void testValidate_ListOpen() throws Exception {
var node = parseNode("/webtemplate_nodes/dv_text_list_open.json");
var result = validator.validate(new DvText("No known allergies"), node);
assertTrue(result.isEmpty());
result = validator.validate(new DvText("Test value"), node);
assertTrue(result.isEmpty());
}
use of com.nedap.archie.rm.datavalues.DvText in project openEHR_SDK by ehrbase.
the class DvTextValidatorTest method testValidate_Pattern.
@Test
void testValidate_Pattern() throws Exception {
var node = parseNode("/webtemplate_nodes/dv_text_pattern.json");
var result = validator.validate(new DvText("No known allergies"), node);
assertTrue(result.isEmpty());
result = validator.validate(new DvText("No known medication allergies"), node);
assertTrue(result.isEmpty());
result = validator.validate(new DvText("Test value"), node);
assertEquals(1, result.size());
}
Aggregations