Search in sources :

Example 61 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class DvCodedTextTest method testFailOnError_Enabled.

@Test
void testFailOnError_Enabled() throws Exception {
    var validationSupport = new FhirTerminologyValidation("https://wrong.terminology.server/fhir");
    var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/observation-status"), "B");
    var dvCodedText = new DvCodedText("Buccal", codePhrase);
    var validator = new DvCodedTextValidator(validationSupport);
    var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_valueset.json");
    assertThrows(ExternalTerminologyValidationException.class, () -> validator.validate(dvCodedText, node));
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) FhirTerminologyValidation(org.ehrbase.validation.terminology.FhirTerminologyValidation) Test(org.junit.jupiter.api.Test)

Example 62 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class DvCodedTextTest method testValidate.

@Test
void testValidate() throws Exception {
    var validator = new DvCodedTextValidator();
    var node = parseNode("/webtemplate_nodes/dv_codedtext.json");
    var dvCodedText = new DvCodedText("First", new CodePhrase(new TerminologyId("local"), "at0028"));
    var result = validator.validate(dvCodedText, node);
    assertTrue(result.isEmpty());
    dvCodedText = new DvCodedText("Test", new CodePhrase(new TerminologyId("local"), "at0028"));
    result = validator.validate(dvCodedText, node);
    assertEquals(1, result.size());
    dvCodedText = new DvCodedText("First", new CodePhrase(new TerminologyId("local"), "at0029"));
    result = validator.validate(dvCodedText, node);
    assertEquals(1, result.size());
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Test(org.junit.jupiter.api.Test)

Example 63 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class DvCodedTextTest method testValidate_FhirCodeSystem_WrongTerminologyId.

@Test
void testValidate_FhirCodeSystem_WrongTerminologyId() throws Exception {
    var codePhrase = new CodePhrase(new TerminologyId("http://hl7.org/fhir/name-use"), "usual");
    // 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_value_set", "The terminology http://hl7.org/fhir/name-use must be 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("Usual", codePhrase), node);
    assertEquals(1, result.size());
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ConstraintViolation(org.ehrbase.validation.ConstraintViolation) ConstraintViolationException(org.ehrbase.validation.ConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 64 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class DvCodedTextTest method testValidate_FhirValueSet.

@Test
void testValidate_FhirValueSet() throws Exception {
    var codePhrase = new CodePhrase(new TerminologyId("http://terminology.hl7.org/CodeSystem/v3-EntityNameUseR2"), "UKN");
    // Mockito initialization
    Mockito.when(fhirTerminologyValidationMock.supports("//fhir.hl7.org/ValueSet/$expand?url=http://terminology.hl7.org/ValueSet/v3-EntityNameUseR2")).thenReturn(true);
    Mockito.doNothing().when(fhirTerminologyValidationMock).validate("/test/dv_coded_text_fhir_value_set", "//fhir.hl7.org/ValueSet/$expand?url=http://terminology.hl7.org/ValueSet/v3-EntityNameUseR2", codePhrase);
    var validator = new DvCodedTextValidator(fhirTerminologyValidationMock);
    var node = parseNode("/webtemplate_nodes/dv_codedtext_fhir_valueset.json");
    var result = validator.validate(new DvCodedText("Anonymous", codePhrase), node);
    assertTrue(result.isEmpty());
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Test(org.junit.jupiter.api.Test)

Example 65 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class DvCodedTextValidator method validateInternalCode.

private List<ConstraintViolation> validateInternalCode(String aqlPath, DvCodedText dvCodedText, WebTemplateInput input) {
    List<ConstraintViolation> result = new ArrayList<>();
    var definingCode = dvCodedText.getDefiningCode();
    if (input.getTerminology() != null && !Objects.equals(input.getTerminology(), definingCode.getTerminologyId().getValue())) {
        result.add(new ConstraintViolation(aqlPath, MessageFormat.format("CodePhrase terminology does not match, expected: {0}, found: {1}", input.getTerminology(), definingCode.getTerminologyId().getValue())));
    }
    if (WebTemplateValidationUtils.hasList(input)) {
        var matching = input.getList().stream().filter(inputValue -> Objects.equals(inputValue.getValue(), definingCode.getCodeString())).findFirst();
        if (matching.isEmpty()) {
            result.add(new ConstraintViolation(aqlPath, MessageFormat.format("CodePhrase codeString does not match any option, found: {0}", definingCode.getCodeString())));
        } else {
            if (!matching.get().getLabel().equals(dvCodedText.getValue())) {
                result.add(new ConstraintViolation(aqlPath, MessageFormat.format("CodePhrase codeString does not match any option, found: {0}", definingCode.getCodeString())));
            }
        }
    }
    return result;
}
Also used : Objects(java.util.Objects) List(java.util.List) ConstraintViolationException(org.ehrbase.validation.ConstraintViolationException) ExternalTerminologyValidation(org.ehrbase.validation.terminology.ExternalTerminologyValidation) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ConstraintViolation(org.ehrbase.validation.ConstraintViolation) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ConstraintViolation(org.ehrbase.validation.ConstraintViolation) ArrayList(java.util.ArrayList)

Aggregations

DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)74 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)56 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)50 Test (org.junit.jupiter.api.Test)25 DvText (com.nedap.archie.rm.datavalues.DvText)17 Test (org.junit.Test)15 Composition (com.nedap.archie.rm.composition.Composition)9 ArrayList (java.util.ArrayList)9 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)8 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)8 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)7 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)7 List (java.util.List)7 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 IOException (java.io.IOException)6 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)6 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)6 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)6 EventContext (com.nedap.archie.rm.composition.EventContext)4 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)4