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