Search in sources :

Example 41 with DvText

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));
    }
}
Also used : java.util(java.util) Composition(com.nedap.archie.rm.composition.Composition) RMObjectCreator(com.nedap.archie.creation.RMObjectCreator) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) SdkException(org.ehrbase.util.exception.SdkException) Archetyped(com.nedap.archie.rm.archetyped.Archetyped) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) RmConstants(org.ehrbase.util.rmconstants.RmConstants) Locatable(com.nedap.archie.rm.archetyped.Locatable) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvText(com.nedap.archie.rm.datavalues.DvText) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) ArchetypeID(com.nedap.archie.rm.support.identification.ArchetypeID) DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) RMAttributeInfo(com.nedap.archie.rminfo.RMAttributeInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) RM_VERSION_1_4_0(org.ehrbase.util.rmconstants.RmConstants.RM_VERSION_1_4_0) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) RMObject(com.nedap.archie.rm.RMObject) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) CComplexObject(com.nedap.archie.aom.CComplexObject) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) Composition(com.nedap.archie.rm.composition.Composition) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) CComplexObject(com.nedap.archie.aom.CComplexObject) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) DvText(com.nedap.archie.rm.datavalues.DvText) DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) Entry(com.nedap.archie.rm.composition.Entry) SdkException(org.ehrbase.util.exception.SdkException) RMObject(com.nedap.archie.rm.RMObject) CComplexObject(com.nedap.archie.aom.CComplexObject) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) Locatable(com.nedap.archie.rm.archetyped.Locatable)

Example 42 with DvText

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

Example 43 with DvText

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());
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) ItemTree(com.nedap.archie.rm.datastructures.ItemTree) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RMJacksonConfiguration(com.nedap.archie.json.RMJacksonConfiguration) DvText(com.nedap.archie.rm.datavalues.DvText) PartySelf(com.nedap.archie.rm.generic.PartySelf) Test(org.junit.Test)

Example 44 with DvText

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());
}
Also used : DvText(com.nedap.archie.rm.datavalues.DvText) Test(org.junit.jupiter.api.Test)

Example 45 with DvText

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());
}
Also used : DvText(com.nedap.archie.rm.datavalues.DvText) Test(org.junit.jupiter.api.Test)

Aggregations

DvText (com.nedap.archie.rm.datavalues.DvText)50 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)16 Test (org.junit.Test)14 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)11 PartySelf (com.nedap.archie.rm.generic.PartySelf)11 Composition (com.nedap.archie.rm.composition.Composition)10 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)9 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)9 ArrayList (java.util.ArrayList)9 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)9 EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)8 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)8 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)8 UUID (java.util.UUID)8 Participation (com.nedap.archie.rm.generic.Participation)6 Optional (java.util.Optional)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Folder (com.nedap.archie.rm.directory.Folder)5 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)5 URI (java.net.URI)5