use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.
the class TerminologyCheckTest method testSimpleValidationWrongValue.
@Test
public void testSimpleValidationWrongValue() throws Exception {
DvCodedText category = new DvCodedText("not quite sure what to put here", new CodePhrase(new TerminologyId("openehr"), "433"));
try {
org.ehrbase.validation.terminology.validator.DvCodedText.validate(localizedTerminologies.locale("en"), codesetMapping, "category", category, "en");
fail("should have detected a wrong value");
} catch (Exception e) {
}
}
use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.
the class CodePhraseAdapter method write.
@Override
public void write(JsonWriter writer, CodePhrase codePhrase) throws IOException {
if (codePhrase == null) {
writer.nullValue();
return;
}
if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
writer.beginObject();
writer.name("codeString").value(codePhrase.getCodeString());
writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
writer.name("terminologyId");
writer.beginObject();
writer.name("value").value(codePhrase.getTerminologyId().getValue());
writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(TerminologyId.class.getSimpleName()).camelToUpperSnake());
writer.endObject();
writer.endObject();
} else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
writer.beginObject();
writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(codePhrase).camelToUpperSnake());
writer.name("code_string").value(codePhrase.getCodeString());
writer.name("terminology_id").value(gson.toJson(codePhrase.getTerminologyId()));
writer.endObject();
}
}
use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.
the class CodePhraseRMUnmarshaller method handle.
/**
* {@inheritDoc}
*/
@Override
public void handle(String currentTerm, CodePhrase rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, "code", currentValues, rmObject::setCodeString, String.class, consumedPaths);
rmObject.setTerminologyId(new TerminologyId());
setValue(currentTerm, "terminology", currentValues, t -> rmObject.getTerminologyId().setValue(t), String.class, consumedPaths);
setValue(currentTerm, "preferred_term", currentValues, rmObject::setPreferredTerm, String.class, consumedPaths);
}
use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.
the class DvCodedTextRMUnmarshaller method handle.
/**
* {@inheritDoc}
*/
@Override
public void handle(String currentTerm, DvCodedText rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, "value", currentValues, rmObject::setValue, String.class, consumedPaths);
rmObject.setDefiningCode(new CodePhrase());
setValue(currentTerm, "code", currentValues, c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
rmObject.getDefiningCode().setTerminologyId(new TerminologyId());
setValue(currentTerm, "terminology", currentValues, t -> rmObject.getDefiningCode().getTerminologyId().setValue(t), String.class, consumedPaths);
if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() == null) {
setValue(currentTerm, null, currentValues, c -> {
if (c != null) {
// try to interpret as code
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), c));
if (rmObject.getValue() == null) {
// try to interpret as value
setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), c));
}
}
}, String.class, consumedPaths);
} else if (rmObject.getDefiningCode().getCodeString() == null) {
setValue(currentTerm, null, currentValues, // It is the code
c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
}
// Set terminology from Node
Optional.of(context.getNodeDeque().peek().getInputs()).stream().flatMap(List::stream).filter(i -> "code".equals(i.getSuffix())).findAny().map(WebTemplateInput::getTerminology).ifPresent(t -> rmObject.getDefiningCode().getTerminologyId().setValue(t));
// Set value from Node
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
// set code from value if not set
if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() != null) {
setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), rmObject.getValue()));
}
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
// consume strange legacy paths
if (rmObject.getDefiningCode() != null && rmObject.getDefiningCode().getCodeString() != null) {
currentValues.keySet().stream().map(FlatPathDto::format).filter(k -> StringUtils.substringAfter(k, "|").equals(rmObject.getDefiningCode().getCodeString())).forEach(consumedPaths::add);
}
setValue(currentTerm, "formatting", currentValues, rmObject::setFormatting, String.class, consumedPaths);
}
use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.
the class DvOrderedPostprocessor method process.
/**
* {@inheritDoc}
*/
@Override
public void process(String term, DvOrdered rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
handleNormalRange(values, consumedPaths, context, term + "/_normal_range", rmObject::setNormalRange);
FlatHelper.extractMultiValuedFullPath(term, "_other_reference_ranges", values).forEach((k, v) -> {
ReferenceRange referenceRange = new ReferenceRange();
rmObject.addOtherReferenceRange(referenceRange);
Map<FlatPathDto, String> meaningValues = FlatHelper.filter(values, term + "/_other_reference_ranges:" + k + "/meaning", false);
if (!meaningValues.isEmpty()) {
final DvText meaning;
String meaningAttributeName = "meaning";
boolean isDvCodedText = isDvCodedText(meaningValues, term + "/_other_reference_ranges:" + k + "/meaning");
if (isDvCodedText) {
meaning = new DvCodedText();
} else {
meaning = new DvText();
}
referenceRange.setMeaning(meaning);
callUnmarshal(term + "/_other_reference_ranges:" + k, meaningAttributeName, meaning, meaningValues, consumedPaths, context, context.getNodeDeque().peek().findChildById(meaningAttributeName).orElse(buildDummyChild(meaningAttributeName, context.getNodeDeque().peek())));
callPostProcess(term + "/_other_reference_ranges:" + k, meaningAttributeName, meaning, meaningValues, consumedPaths, context, context.getNodeDeque().peek().findChildById(meaningAttributeName).orElse(buildDummyChild(meaningAttributeName, context.getNodeDeque().peek())));
}
handleNormalRange(v, consumedPaths, context, term + "/_other_reference_ranges:" + k, referenceRange::setRange);
});
setValue(term, "normal_status", values, s -> {
if (s != null) {
rmObject.setNormalStatus(new CodePhrase(new TerminologyId("openehr_normal_statuses"), s));
}
}, String.class, consumedPaths);
}
Aggregations