use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class CanonicalUtil method getAttributePathValue.
/**
* Retrieve the value of an attribute identified by a path.
* NB. This is not supposed to replace Locatable.itemsAtPath(), but instead it should be used
* to resolve values in non locatable RMObject
*
* @param root
* @param attributePath
* @return
* @see com.nedap.archie.rm.archetyped.Locatable
*/
private static Object getAttributePathValue(Object root, String attributePath, boolean keepArray) {
Object rmObject = root;
if (rmObject instanceof Locatable) {
try {
List<Object> items = ((Locatable) root).itemsAtPath(attributePath);
if (!items.isEmpty())
rmObject = keepArray ? items : items.get(0);
else
rmObject = null;
} catch (Exception e) {
throw new IllegalArgumentException("Invalid path:" + attributePath);
}
} else {
if (!attributePath.contains("/"))
rmObject = getAttributeValue(root, attributePath);
else {
String[] pathItems = attributePath.split("/");
int iteration = 0;
for (String item : pathItems) {
rmObject = getAttributeValue(rmObject, item);
iteration++;
if (rmObject instanceof Locatable) {
// f.e. items in other_details
rmObject = locatableValueItem((RMObject) rmObject, iteration, Arrays.asList(pathItems).subList(iteration, pathItems.length));
break;
}
}
}
}
if (rmObject instanceof RMObject)
return new CanonicalJson().marshal((RMObject) rmObject);
else
return rmObject;
}
use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class FlattenerTest method testFlattenEhrbaseBloodPressureSimpleDeV0.
@Test
public void testFlattenEhrbaseBloodPressureSimpleDeV0() {
Flattener cut = new Flattener(new TestDataTemplateProvider());
EhrbaseBloodPressureSimpleDeV0Composition bloodPressureSimpleDeV0 = TestData.buildEhrbaseBloodPressureSimpleDeV0();
RMObject rmObject = new Unflattener(new TestDataTemplateProvider()).unflatten(bloodPressureSimpleDeV0);
EhrbaseBloodPressureSimpleDeV0Composition actual = cut.flatten((Locatable) rmObject, EhrbaseBloodPressureSimpleDeV0Composition.class);
assertThat(actual).isNotNull();
assertThat(actual.getComposer()).isNotNull().extracting(Object::getClass).isEqualTo(PartyIdentified.class);
PartyIdentified composer = (PartyIdentified) actual.getComposer();
assertThat(composer.getName()).isEqualTo("Test");
assertThat(actual.getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getFunction().getValue()).containsExactlyInAnyOrder(new Tuple("Test", "Pos1"), new Tuple("Test2", "Pos2"));
assertThat(actual.getBloodPressureTrainingSample()).size().isEqualTo(1);
assertThat(actual.getBloodPressureTrainingSample().get(0).getSubject()).isNotNull().extracting(Object::getClass).isEqualTo(PartySelf.class);
assertThat(actual.getBloodPressureTrainingSample().get(0).getSystolicMagnitude()).isEqualTo(22d);
assertThat(actual.getBloodPressureTrainingSample().get(0).getSystolicUnits()).isEqualTo("mm[Hg]");
assertThat(actual.getBloodPressureTrainingSample().get(0).getKorotkoffSoundsDefiningCode()).isEqualTo(KorotkoffSoundsDefiningCode.FIFTH_SOUND);
assertThat(actual.getBloodPressureTrainingSample().get(0).getMeanArterialPressureNullFlavourDefiningCode()).isNull();
}
use of com.nedap.archie.rm.archetyped.Locatable in project openEHR_SDK by ehrbase.
the class FlattenerTest method testFlattenEhrbaseMultiOccurrenceDeV1.
@Test
public void testFlattenEhrbaseMultiOccurrenceDeV1() {
Flattener cut = new Flattener(new TestDataTemplateProvider());
EhrbaseMultiOccurrenceDeV1Composition bloodPressureSimpleDeV0 = TestData.buildEhrbaseMultiOccurrenceDeV1();
RMObject rmObject = new Unflattener(new TestDataTemplateProvider()).unflatten(bloodPressureSimpleDeV0);
EhrbaseMultiOccurrenceDeV1Composition actual = cut.flatten((Locatable) rmObject, EhrbaseMultiOccurrenceDeV1Composition.class);
assertThat(actual).isNotNull();
assertThat(actual.getBodyTemperature()).size().isEqualTo(2);
BodyTemperatureObservation bodyTemperature1 = actual.getBodyTemperature().get(0);
assertThat(bodyTemperature1.getAnyEvent()).extracting(e -> ((BodyTemperatureAnyEventPointEvent) e).getTemperatureMagnitude()).containsExactlyInAnyOrder(11d, 22d);
BodyTemperatureLocationOfMeasurementChoice locationOfMeasurement1 = bodyTemperature1.getLocationOfMeasurement();
assertThat(locationOfMeasurement1.getClass()).isEqualTo(BodyTemperatureLocationOfMeasurementDvCodedText.class);
assertThat(((BodyTemperatureLocationOfMeasurementDvCodedText) locationOfMeasurement1).getLocationOfMeasurementDefiningCode()).isEqualTo(LocationOfMeasurementDefiningCode.FOREHEAD);
BodyTemperatureObservation bodyTemperature2 = actual.getBodyTemperature().get(1);
BodyTemperatureLocationOfMeasurementChoice locationOfMeasurement2 = bodyTemperature2.getLocationOfMeasurement();
assertThat(locationOfMeasurement2.getClass()).isEqualTo(BodyTemperatureLocationOfMeasurementDvText.class);
assertThat(((BodyTemperatureLocationOfMeasurementDvText) locationOfMeasurement2).getLocationOfMeasurementValue()).isEqualTo("location");
}
use of com.nedap.archie.rm.archetyped.Locatable 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