Search in sources :

Example 36 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class TerminologyAccessTest method testTerminologyAccess.

@Test
public void testTerminologyAccess() throws Exception {
    assertEquals("openehr", terminologyAccess.id());
    Set<CodePhrase> codePhrases = terminologyAccess.allCodes();
    assertEquals(216, codePhrases.size());
    codePhrases = terminologyAccess.codesForGroupId("setting");
    assertEquals(13, codePhrases.size());
    // nursing home care
    assertTrue(terminologyAccess.hasCodeForGroupId("setting", new CodePhrase(new TerminologyId("openehr"), "237")));
    // bad code string
    assertFalse(terminologyAccess.hasCodeForGroupId("setting", new CodePhrase(new TerminologyId("openehr"), "240")));
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Test(org.junit.Test)

Example 37 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class SimpleTerminologyAccess method addGroup.

/**
 * Adds a group of codes with language dependent names
 *
 * @param groupId not null
 * @param codes   not null
 * @param names   <lang, name>  not null
 */
void addGroup(String groupId, Collection<String> codes, Map<String, String> names) {
    Set<CodePhrase> group = new HashSet<>();
    for (String c : codes) {
        CodePhrase code = new CodePhrase(new TerminologyId(id), c);
        group.add(code);
    }
    groups.put(groupId, group);
    for (Map.Entry<String, String> entry : names.entrySet()) {
        String lang = entry.getKey();
        Map<String, String> nameToId = groupLangNameToId.get(lang);
        if (nameToId == null) {
            nameToId = new HashMap<>();
        }
        String name = entry.getValue();
        nameToId.put(name, groupId);
        groupLangNameToId.put(lang, nameToId);
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase)

Example 38 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class DvCodedTextAdapter method write.

@Override
public void write(JsonWriter writer, DvCodedText dvalue) throws IOException {
    if (!Optional.ofNullable(dvalue).map(DvCodedText::getDefiningCode).map(CodePhrase::getCodeString).isPresent()) {
        writer.nullValue();
        return;
    }
    TermMappingAdapter termMappingAdapter = new TermMappingAdapter();
    if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
        writer.beginObject();
        writer.name(VALUE).value(dvalue.getValue());
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(DvCodedText.class.getSimpleName()).camelToUpperSnake());
        writer.name("definingCode");
        writer.beginObject();
        writer.name("codeString").value(dvalue.getDefiningCode().getCodeString());
        writer.name("terminologyId");
        writer.beginObject();
        writer.name(VALUE).value(dvalue.getDefiningCode().getTerminologyId().getValue());
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(TerminologyId.class.getSimpleName()).camelToUpperSnake());
        writer.endObject();
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
        writer.endObject();
        termMappingAdapter.write(writer, dvalue.getMappings());
        writer.endObject();
    } else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
        writer.beginObject();
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(dvalue).camelToUpperSnake());
        writer.name(VALUE).value(dvalue.getValue());
        CodePhrase codePhrase = dvalue.getDefiningCode();
        writer.name("defining_code").value(gson.toJson(codePhrase));
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
        writer.endObject();
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) SnakeCase(org.ehrbase.serialisation.util.SnakeCase) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase)

Example 39 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class DtoToCompositionWalker method handleSingleValue.

private void handleSingleValue(Object value, String childName, Object child, Object parent) {
    if (value == null) {
    // NOP
    } else if (EnumValueSet.class.isAssignableFrom(value.getClass()) && DvCodedText.class.isAssignableFrom(parent.getClass())) {
        EnumValueSet valueSet = (EnumValueSet) value;
        DvCodedText dvCodedText = (DvCodedText) parent;
        dvCodedText.setValue(valueSet.getValue());
        dvCodedText.setDefiningCode(new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode()));
    } else if (EnumValueSet.class.isAssignableFrom(value.getClass()) && DvCodedText.class.isAssignableFrom(ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getType())) {
        EnumValueSet valueSet = (EnumValueSet) value;
        DvCodedText dvCodedText = new DvCodedText();
        dvCodedText.setValue(valueSet.getValue());
        dvCodedText.setDefiningCode(new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode()));
        RM_OBJECT_CREATOR.set(parent, childName, Collections.singletonList(dvCodedText));
    } else if (EnumValueSet.class.isAssignableFrom(value.getClass())) {
        EnumValueSet valueSet = (EnumValueSet) value;
        CodePhrase codePhrase = new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode());
        RM_OBJECT_CREATOR.set(parent, childName, Collections.singletonList(codePhrase));
    } else if (ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getTypeInCollection().isAssignableFrom(value.getClass()) || (ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getTypeInCollection().isAssignableFrom(boolean.class) && value.getClass().isAssignableFrom(Boolean.class))) {
        RMAttributeInfo attributeInfo = ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName);
        if (attributeInfo.isMultipleValued()) {
            try {
                Object invoke = attributeInfo.getGetMethod().invoke(parent);
                if (Collection.class.isAssignableFrom(invoke.getClass()) && child != null) {
                    ((Collection) invoke).remove(child);
                }
            } catch (IllegalAccessException | InvocationTargetException e) {
                logger.warn(e.getMessage(), e);
            }
        }
        RM_OBJECT_CREATOR.addElementToListOrSetSingleValues(parent, childName, Collections.singletonList(value));
    } else {
        logger.warn("Unhandled child {} in {}", childName, parent);
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) EnumValueSet(org.ehrbase.client.classgenerator.EnumValueSet) RMAttributeInfo(com.nedap.archie.rminfo.RMAttributeInfo) RMObject(com.nedap.archie.rm.RMObject) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 40 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId 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)

Aggregations

TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)62 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)60 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)50 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)13 DvText (com.nedap.archie.rm.datavalues.DvText)10 Composition (com.nedap.archie.rm.composition.Composition)8 ArrayList (java.util.ArrayList)7 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)6 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)5 RMObject (com.nedap.archie.rm.RMObject)4 EventContext (com.nedap.archie.rm.composition.EventContext)4 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)4 List (java.util.List)4 Locatable (com.nedap.archie.rm.archetyped.Locatable)3 Entry (com.nedap.archie.rm.composition.Entry)3 DvURI (com.nedap.archie.rm.datavalues.DvURI)3 DvOrdinal (com.nedap.archie.rm.datavalues.quantity.DvOrdinal)3 PartyRelated (com.nedap.archie.rm.generic.PartyRelated)3