use of com.nedap.archie.rm.datavalues.DvCodedText 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.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class TermMappingTestOverwritten method testTermMappingFromJson.
@Override
@Test
public void testTermMappingFromJson() 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 structuredJson = getFlatJson(template, FlatFormat.STRUCTURED).marshal(unmarshal);
Composition actualComposition = getFlatJson(template, FlatFormat.STRUCTURED).unmarshal(structuredJson);
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 DvCodedTextTest method testValidate_FhirCodeSystem.
@Test
void testValidate_FhirCodeSystem() throws Exception {
var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/observation-status"), "final");
// Mockito initialization
Mockito.when(fhirTerminologyValidationMock.supports("//fhir.hl7.org/CodeSystem?url=http://hl7.org/fhir/observation-status")).thenReturn(true);
Mockito.doNothing().when(fhirTerminologyValidationMock).validate("/test/dv_coded_text_fhir_code_system", "//fhir.hl7.org/CodeSystem?url=http://hl7.org/fhir/observation-status", codePhrase);
var validator = new DvCodedTextValidator(fhirTerminologyValidationMock);
var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_codesystem.json");
var result = validator.validate(new DvCodedText("Final", codePhrase), node);
assertTrue(result.isEmpty());
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class DvCodedTextTest method testValidate_UnsupportedExternalTerminology.
@Test
void testValidate_UnsupportedExternalTerminology() throws Exception {
Mockito.when(fhirTerminologyValidationMock.supports("ICD10")).thenReturn(false);
var node = parseNode("/webtemplate_nodes/dv_codedtext_unsupported.json");
var dvCodedText = new DvCodedText("Iodine-deficiency related thyroid disorders and allied conditions", new CodePhrase(new TerminologyId("ICD10"), "E01"));
var result = new DvCodedTextValidator(fhirTerminologyValidationMock).validate(dvCodedText, node);
assertTrue(result.isEmpty());
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.
the class DvCodedTextTest method testValidate_FhirCodeSystem_WrongCode.
@Test
void testValidate_FhirCodeSystem_WrongCode() throws Exception {
var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/observation-status"), "casual");
// Mockito initialization
Mockito.when(fhirTerminologyValidationMock.supports("//fhir.hl7.org/CodeSystem?url=http://hl7.org/fhir/observation-status")).thenReturn(true);
Mockito.doThrow(new ConstraintViolationException(List.of(new ConstraintViolation("/test/dv_coded_text_fhir_code_system", "The specified code 'casual' is not known to belong to the specified code system 'http://hl7.org/fhir/observation-status'")))).when(fhirTerminologyValidationMock).validate("/test/dv_coded_text_fhir_code_system", "//fhir.hl7.org/CodeSystem?url=http://hl7.org/fhir/observation-status", codePhrase);
var validator = new DvCodedTextValidator(fhirTerminologyValidationMock);
var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_codesystem.json");
var result = validator.validate(new DvCodedText("Casual", codePhrase), node);
assertEquals(1, result.size());
}
Aggregations