use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class DefaultRestAqlEndpoint method extractValue.
private Object extractValue(String valueAsString, Class<?> aClass) throws com.fasterxml.jackson.core.JsonProcessingException {
Object object;
if (StringUtils.isBlank(valueAsString) || "null".equals(valueAsString)) {
object = null;
} else if (aClass.isAnnotationPresent(Entity.class)) {
RMObject locatable = AQL_OBJECT_MAPPER.readValue(valueAsString, RMObject.class);
object = new Flattener(defaultRestClient.getTemplateProvider()).flatten(locatable, aClass);
if (locatable instanceof Composition) {
Flattener.addVersion(object, new VersionUid(((Composition) locatable).getUid().getValue()));
}
} else if (EnumValueSet.class.isAssignableFrom(aClass)) {
RMObject rmObject = AQL_OBJECT_MAPPER.readValue(valueAsString, RMObject.class);
final String codeString;
if (CodePhrase.class.isAssignableFrom(rmObject.getClass())) {
codeString = ((CodePhrase) rmObject).getCodeString();
} else {
codeString = ((DvCodedText) rmObject).getDefiningCode().getCodeString();
}
object = Arrays.stream(aClass.getEnumConstants()).map(e -> (EnumValueSet) e).filter(e -> e.getCode().equals(codeString)).findAny().orElseThrow(() -> new ClientException(String.format("Unknown code %s for %s", codeString, aClass.getSimpleName())));
} else {
object = AQL_OBJECT_MAPPER.readValue(valueAsString, aClass);
}
return object;
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class CanonicalEhrQuery3IT method testEhrAttributesDrillDown.
@Test
public void testEhrAttributesDrillDown() {
String rootPath = "e/ehr_status";
RMObject referenceNode = referenceEhrStatus;
String[] attributePaths = { "archetype_node_id", "archetype_details", "archetype_details/archetype_id", "archetype_details/archetype_id/value", "archetype_details/template_id", "archetype_details/template_id/value", "subject", "subject/external_ref", "subject/external_ref/id", "subject/external_ref/id/value", "subject/external_ref/id/scheme", "subject/external_ref/namespace", "subject/external_ref/type", "other_details", "other_details/name", "other_details/name/value", "other_details/items[at0001]", "other_details/items[at0001]/archetype_node_id", "other_details/items[at0001]/name", "other_details/items[at0001]/name/value", "other_details/items[at0001]/value", "other_details/items[at0001]/value/id", "other_details/items[at0001]/value/type", "other_details/items[at0001]/value/issuer", "other_details/items[at0001]/value/assigner", "is_queryable", "is_modifiable" };
for (String attributePath : attributePaths) {
String aqlSelect = rootPath + "/" + attributePath;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("select ");
stringBuilder.append(aqlSelect);
stringBuilder.append(" from EHR e[ehr_id/value = $ehr_id]");
Query<Record1<Map>> query = Query.buildNativeQuery(stringBuilder.toString(), Map.class);
QueryResponseData result = openEhrClient.aqlEndpoint().executeRaw(query, new ParameterValue("ehr_id", ehrUUID));
List<Object> objectList = result.getRows().get(0);
// Mapped object(s) from JSON
Object actual = valueObject(objectList.get(0));
if (actual instanceof List) {
// RMObject(s)
Object expected = attributeArrayValueAt(referenceNode, attributePath);
assertThat(toRmObjectList((List<Object>) actual).toArray()).as(aqlSelect).containsExactlyInAnyOrder(((List<?>) expected).toArray());
} else {
assertThat(valueObject(objectList.get(0))).as(aqlSelect).isEqualTo(attributeValueAt(referenceNode, attributePath));
}
}
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class StdFromCompositionWalker method preHandle.
@Override
protected void preHandle(Context<Map<String, Object>> context) {
// Handle if at a End-Node
if (!visitChildren(context.getNodeDeque().peek()) && !context.getFlatHelper().skip(context)) {
RMObject currentObject = context.getRmObjectDeque().peek();
StdConfig stdConfig = findStdConfig(currentObject.getClass());
context.getObjectDeque().peek().putAll(stdConfig.buildChildValues(context.getFlatHelper().buildNamePath(context, true), currentObject, context));
}
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class AbstractsStdConfig method buildChildValues.
@Override
public /**
* {@inheritDoc}
*/
Map<String, Object> buildChildValues(String currentTerm, T rmObject, Context<Map<String, Object>> context) {
Map<String, Object> result = new HashMap<>();
Set<String> expandFields = Optional.ofNullable(configMap.get(rmObject.getClass())).map(RmIntrospectConfig::getNonTemplateFields).orElse(Collections.emptySet());
if (!expandFields.isEmpty()) {
if (expandFields.size() == 1 && expandFields.contains("value")) {
try {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor("value", rmObject.getClass());
Object property = propertyDescriptor.getReadMethod().invoke(rmObject);
result.put(currentTerm, property);
} catch (IllegalAccessException | InvocationTargetException | IntrospectionException e) {
throw new SdkException(e.getMessage(), e);
}
} else {
for (String propertyName : expandFields) {
try {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyName, rmObject.getClass());
Object property = propertyDescriptor.getReadMethod().invoke(rmObject);
result.put(currentTerm + "|" + propertyName, property);
} catch (IllegalAccessException | InvocationTargetException | IntrospectionException e) {
throw new SdkException(e.getMessage(), e);
}
}
}
} else {
result.put(currentTerm, rmObject);
}
return result;
}
use of com.nedap.archie.rm.RMObject in project openEHR_SDK by ehrbase.
the class CanonicalUtil method getAttributeValue.
/**
* resolves an attribute of a RMObject
* NB. borrowed from CAttribute.java in validation
*
* @param obj
* @param attributePath
* @return
*/
private static Object getAttributeValue(Object obj, String attributePath) {
if (obj == null)
return null;
Class rmClass = obj.getClass();
Object value;
Method getter;
String getterName;
if (attributePath.startsWith("is_")) {
// conventionally, a getter for a boolean uses 'is' as a prefix
getterName = "is" + new SnakeToCamel(attributePath.substring(3)).convert();
} else
getterName = "get" + new SnakeToCamel(attributePath).convert();
try {
getter = rmClass.getMethod(getterName);
value = getter.invoke(obj, null);
} catch (Exception e) {
throw new IllegalStateException("unresolved attribute:" + attributePath + " for class:" + rmClass);
}
return value;
}
Aggregations