use of com.nedap.archie.rm.datavalues.DvCodedText 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.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class EventContextValueInserter method insert.
@Override
public void insert(EventContext rmObject, DefaultValues defaultValues) {
if (RMHelper.isEmpty(rmObject.getStartTime()) && defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
rmObject.setStartTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.TIME)));
}
if (RMHelper.isEmpty(rmObject.getEndTime()) && defaultValues.containsDefaultValue(DefaultValuePath.END_TIME)) {
rmObject.setEndTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.END_TIME)));
}
if (RMHelper.isEmpty(rmObject.getHealthCareFacility()) && (defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_NAME) || defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_ID))) {
rmObject.setHealthCareFacility(buildPartyIdentified(defaultValues, DefaultValuePath.HEALTHCARE_FACILITY_NAME, DefaultValuePath.HEALTHCARE_FACILITY_ID, rmObject.getHealthCareFacility()));
}
if (RMHelper.isEmpty(rmObject.getLocation()) && defaultValues.containsDefaultValue(DefaultValuePath.LOCATION)) {
rmObject.setLocation(defaultValues.getDefaultValue(DefaultValuePath.LOCATION));
}
if (RMHelper.isEmpty(rmObject.getSetting()) && defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
Setting defaultValue = defaultValues.getDefaultValue(DefaultValuePath.SETTING);
rmObject.setSetting(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
}
if (RMHelper.isEmpty(rmObject.getParticipations()) && defaultValues.containsDefaultValue(DefaultValuePath.PARTICIPATION)) {
rmObject.setParticipations(defaultValues.getDefaultValue(DefaultValuePath.PARTICIPATION));
}
if (rmObject.getParticipations() != null) {
rmObject.getParticipations().stream().map(Participation::getPerformer).filter(Objects::nonNull).map(PartyProxy::getExternalRef).filter(Objects::nonNull).filter(ref -> ref.getId() != null).forEach(ref -> {
if (ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_NAMESPACE)) {
ref.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
}
if (ref.getId() instanceof GenericId && ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_SCHEME)) {
((GenericId) ref.getId()).setScheme(defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME));
}
});
}
}
use of com.nedap.archie.rm.datavalues.DvCodedText 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.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method extractDefault.
public static <T> Optional<T> extractDefault(WebTemplateNode node, Class<T> clazz) {
String rmclass = node.getRmType();
Object defaultValue = null;
switch(rmclass) {
case "DV_CODED_TEXT":
if (node.getMin() > 0) {
Optional<WebTemplateInput> code = node.getInputs().stream().filter(i -> i.getSuffix().equals("code")).filter(i -> i.getList().size() == 1).findAny();
if (code.isPresent()) {
defaultValue = new DvCodedText(code.get().getList().get(0).getLabel(), new CodePhrase(new TerminologyId(code.get().getTerminology()), code.get().getList().get(0).getValue()));
}
}
break;
default:
defaultValue = null;
}
return Optional.ofNullable((T) defaultValue);
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class DvCodedTextIT method testValidate_FhirCodeSystem_WrongTerminologyId.
@Test
void testValidate_FhirCodeSystem_WrongTerminologyId() throws Exception {
var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/name-use"), "usual");
var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_codesystem.json");
var result = validator.validate(new DvCodedText("Usual", codePhrase), node);
assertEquals(1, result.size());
}
Aggregations