Search in sources :

Example 46 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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 47 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class WebTemplateSkeletonBuilder method extractDefault.

public static <T> Optional<T> extractDefault(WebTemplateNode node, Class<T> clazz) {
    String rmclass = node.getRmType();
    Object defaultValue = null;
    switch(rmclass) {
        case "DV_CODED_TEXT":
            if (node.getMin() > 0) {
                Optional<WebTemplateInput> code = node.getInputs().stream().filter(i -> i.getSuffix().equals("code")).filter(i -> i.getList().size() == 1).findAny();
                if (code.isPresent()) {
                    defaultValue = new DvCodedText(code.get().getList().get(0).getLabel(), new CodePhrase(new TerminologyId(code.get().getTerminology()), code.get().getList().get(0).getValue()));
                }
            }
            break;
        default:
            defaultValue = null;
    }
    return Optional.ofNullable((T) defaultValue);
}
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) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) RMObject(com.nedap.archie.rm.RMObject) CComplexObject(com.nedap.archie.aom.CComplexObject) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput)

Example 48 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class WebTemplateSkeletonBuilderTest method build.

@Test
public void build() throws XmlException, IOException {
    org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE.getStream());
    OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
    WebTemplate webTemplate = new OPTParser(operationaltemplate).parse();
    Composition generate = WebTemplateSkeletonBuilder.build(webTemplate, true);
    assertThat(generate).isNotNull();
    assertThat(generate.getCategory().getDefiningCode()).extracting(CodePhrase::getCodeString, c -> c.getTerminologyId().getValue()).containsExactly("433", "openehr");
    assertThat(generate.itemAtPath("/composer")).isNotNull();
    assertThat(generate.itemAtPath("/context/end_time")).isNotNull();
    assertThat(generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]")).isNotNull();
    assertThat(((Observation) generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]")).getEncoding()).extracting(CodePhrase::getCodeString, c -> c.getTerminologyId().getValue()).containsExactly("UTF-8", "IANA_character-sets");
    assertThat(generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]/data[at0001]/events[at0002]/state[at0007]/items[at1005]/value")).isNotNull();
}
Also used : WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Observation(com.nedap.archie.rm.composition.Observation) Tuple(org.assertj.core.groups.Tuple) XmlException(org.apache.xmlbeans.XmlException) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) IOException(java.io.IOException) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Test(org.junit.Test)

Example 49 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class DvCodedTextIT method testValidate_FhirCodeSystem_WrongTerminologyId.

@Test
void testValidate_FhirCodeSystem_WrongTerminologyId() throws Exception {
    var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/name-use"), "usual");
    var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_codesystem.json");
    var result = validator.validate(new DvCodedText("Usual", codePhrase), node);
    assertEquals(1, result.size());
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Test(org.junit.jupiter.api.Test) AbstractRMObjectValidatorTest(org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)

Example 50 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class DvCodedTextIT method testValidate_FhirValueSet.

@Test
void testValidate_FhirValueSet() throws Exception {
    var codePhrase = new CodePhrase(new TerminologyId("http://terminology.hl7.org/CodeSystem/v3-EntityNameUseR2"), "ANON");
    var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_valueset.json");
    var result = validator.validate(new DvCodedText("Anonymous", codePhrase), node);
    assertTrue(result.isEmpty());
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Test(org.junit.jupiter.api.Test) AbstractRMObjectValidatorTest(org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)

Aggregations

CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)71 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)60 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)56 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)16 Composition (com.nedap.archie.rm.composition.Composition)12 DvText (com.nedap.archie.rm.datavalues.DvText)12 ArrayList (java.util.ArrayList)8 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 RMObject (com.nedap.archie.rm.RMObject)5 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)5 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)5 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)4 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)4 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)4 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)4 Entry (com.nedap.archie.rm.composition.Entry)3