use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class TermMappingRMUnmarshaller method handle.
/**
* {@inheritDoc}
*/
@Override
public void handle(String currentTerm, TermMapping rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, "match", currentValues, s -> Optional.ofNullable(s).map(c -> c.charAt(0)).ifPresent(rmObject::setMatch), String.class, consumedPaths);
Map<FlatPathDto, String> targetValues = FlatHelper.filter(currentValues, currentTerm + "/target", false);
if (!targetValues.isEmpty()) {
rmObject.setTarget(new CodePhrase());
context.getNodeDeque().push(buildDummyChild("target", context.getNodeDeque().peek()));
CODE_PHRASE_RM_UNMARSHALLER.handle(currentTerm + "/target", rmObject.getTarget(), targetValues, context, consumedPaths);
context.getNodeDeque().poll();
}
Map<FlatPathDto, String> purposeValues = FlatHelper.filter(currentValues, currentTerm + "/purpose", false);
if (!purposeValues.isEmpty()) {
rmObject.setPurpose(new DvCodedText());
context.getNodeDeque().push(buildDummyChild("purpose", context.getNodeDeque().peek()));
DV_CODED_TEXT_RM_UNMARSHALLER.handle(currentTerm + "/purpose", rmObject.getPurpose(), purposeValues, context, consumedPaths);
context.getNodeDeque().poll();
}
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class TermMappingTestOverwritten method testTermMappingFromMap.
@Override
@Test
public void testTermMappingFromMap() throws Exception {
String template = this.getFileContent("/res/Demo Vitals.xml");
String rawJson = this.getFileContent("/res/TmComposition.json");
Composition unmarshal = new CanonicalJson().unmarshal(rawJson.replace("\"@class\"", "\"_type\""), Composition.class);
String flatJson = getFlatJson(template, FlatFormat.SIM_SDT).marshal(unmarshal);
Composition actualComposition = getFlatJson(template, FlatFormat.SIM_SDT).unmarshal(flatJson);
List<TermMapping> termMappings = ((DvText) actualComposition.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.body_temperature-zn.v1]/data[at0002]/events/data/items[at0.63]/value").get(0)).getMappings();
assertThat(termMappings).extracting(TermMapping::getMatch, t -> t.getTarget().getCodeString(), t -> t.getTarget().getTerminologyId().getValue(), TermMapping::getPurpose).containsExactlyInAnyOrder(new Tuple('=', "21794005", "SNOMED-CT", null), new Tuple('=', "W.11.7", "RTX", null));
List<TermMapping> termMappings2 = ((DvText) actualComposition.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.body_temperature-zn.v1]/data[at0002]/events/state/items[at0041]/value").get(0)).getMappings();
assertThat(termMappings2).extracting(TermMapping::getMatch, t -> t.getTarget().getCodeString(), t -> t.getTarget().getTerminologyId().getValue(), TermMapping::getPurpose).containsExactlyInAnyOrder(new Tuple('=', "99.1", "IAXA", new DvCodedText("Purpose 1", new CodePhrase(new TerminologyId("Purposes"), "p.0.63.1"))));
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class SimpleValidationTest method testSimpleValidation.
@Test
public void testSimpleValidation() throws Exception {
TerminologyInterface simpleTerminologyInterface = new SimpleTerminologyInterface("en");
AttributeCodesetMapping codesetMapping = AttributeCodesetMapping.getInstance();
CodePhrase codePhrase = new CodePhrase(new TerminologyId("openehr"), "433");
DvCodedText category = new DvCodedText("event", codePhrase);
// get the actual attribute
String attribute = codesetMapping.actualAttributeId("openehr", "category", "en");
ContainerType containerType = codesetMapping.containerType("openehr", "category");
switch(containerType) {
case // a code string defined within a group of a codeset
GROUP:
boolean valid = simpleTerminologyInterface.terminology("openehr").hasCodeForGroupId(attribute, codePhrase);
// check if the supplied value matches codephrase
String rubric = simpleTerminologyInterface.terminology("openehr").rubricForCode(codePhrase.getCodeString(), "en");
valid = rubric.equals("event");
break;
case // a codestring defined in a codeset
CODESET:
valid = simpleTerminologyInterface.codeSet(attribute).hasCode(codePhrase);
break;
default:
throw new IllegalArgumentException("undefined container type");
}
}
use of com.nedap.archie.rm.datavalues.DvCodedText 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.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class DvOrdinalConfig method buildChildValues.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> buildChildValues(String currentTerm, DvOrdinal rmObject, Context<Map<String, Object>> context) {
Map<String, Object> result = new HashMap<>();
String codeString = Optional.of(rmObject).map(DvOrdinal::getSymbol).map(DvCodedText::getDefiningCode).map(CodePhrase::getCodeString).orElse(null);
addValue(result, currentTerm, "code", codeString);
WebTemplateInputValue value = context.getNodeDeque().peek().getInputs().get(0).getList().stream().filter(o -> o.getValue().equals(codeString)).findAny().orElseThrow(() -> new SdkException(String.format("Unknown Ordinal with code %s", codeString)));
addValue(result, currentTerm, "ordinal", value.getOrdinal());
addValue(result, currentTerm, "value", value.getLabel());
return result;
}
Aggregations