use of com.nedap.archie.rm.datatypes.CodePhrase 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.datatypes.CodePhrase 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.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class FeederAuditDetailsAttributesTest method toMap.
@Test
public void toMap() throws Exception {
String value = IOUtils.toString(CompositionTestDataCanonicalJson.FEEDER_AUDIT_DETAILS.getStream(), UTF_8);
CanonicalJson cut = new CanonicalJson();
Composition composition = cut.unmarshal(value, Composition.class);
assertNotNull(composition);
assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
// with real data
FeederAuditDetailsAttributes attributes = new FeederAuditDetailsAttributes(composition.getFeederAudit().getFeederSystemAudit());
Map<String, Object> map = attributes.toMap();
assertNotNull(map);
assertNotNull(map.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]"));
// valid fabricated data without brackets
FeederAuditDetails details = new FeederAuditDetails();
ItemSingle single = new ItemSingle("test", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
details.setOtherDetails(single);
details.setSystemId("system");
attributes = new FeederAuditDetailsAttributes(details);
map = attributes.toMap();
assertNotNull(map.get("other_details[test]"));
// valid fabricated data with brackets
details = new FeederAuditDetails();
single = new ItemSingle("[test]", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
details.setOtherDetails(single);
details.setSystemId("system");
attributes = new FeederAuditDetailsAttributes(details);
map = attributes.toMap();
assertNotNull(map.get("other_details[test]"));
// invalid data with one [
details = new FeederAuditDetails();
single = new ItemSingle("[test", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
details.setOtherDetails(single);
details.setSystemId("system");
attributes = new FeederAuditDetailsAttributes(details);
assertThrows(IllegalArgumentException.class, attributes::toMap);
// invalid data with one ]
details = new FeederAuditDetails();
single = new ItemSingle("test]", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
details.setOtherDetails(single);
details.setSystemId("system");
attributes = new FeederAuditDetailsAttributes(details);
assertThrows(IllegalArgumentException.class, attributes::toMap);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class DtoFromCompositionWalker method writeField.
private void writeField(Field field, Object dto, Object value) {
try {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dto.getClass());
Object dtoList = value;
if (EnumValueSet.class.isAssignableFrom(field.getType()) && value != null && CodePhrase.class.isAssignableFrom(value.getClass())) {
CodePhrase codePhrase = (CodePhrase) value;
EnumValueSet enumValueSet = Arrays.stream(field.getType().getEnumConstants()).map(o -> (EnumValueSet) o).filter(v -> {
String terminologyId = Optional.ofNullable(codePhrase.getTerminologyId()).map(ObjectId::getValue).orElse(null);
return v.getTerminologyId().equals(terminologyId);
}).filter(v -> v.getCode().equals(codePhrase.getCodeString())).findAny().orElse(null);
dtoList = enumValueSet;
}
if (dtoList instanceof RmPrimitive) {
dtoList = ((RmPrimitive<?>) dtoList).getValue();
}
if (List.class.isAssignableFrom(field.getType())) {
dtoList = propertyDescriptor.getReadMethod().invoke(dto);
if (dtoList == null) {
dtoList = new ArrayList<>();
}
((List) dtoList).add(value);
}
propertyDescriptor.getWriteMethod().invoke(dto, dtoList);
} catch (IllegalAccessException | InvocationTargetException | IntrospectionException | IllegalArgumentException e) {
throw new ClientException(e.getMessage(), e);
}
}
use of com.nedap.archie.rm.datatypes.CodePhrase 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);
}
}
Aggregations