Search in sources :

Example 16 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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());
}
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 17 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class TerminologyCheckTest method testSimpleValidationLanguage.

@Test
public void testSimpleValidationLanguage() throws Exception {
    CodePhrase codePhrase = new CodePhrase(new TerminologyId("ISO_3166-1"), "AU");
    org.ehrbase.validation.terminology.validator.CodePhrase.validate(localizedTerminologies.getDefault(), codesetMapping, "territory", codePhrase);
    org.ehrbase.validation.terminology.validator.CodePhrase.validate(localizedTerminologies.getDefault(), codesetMapping, null, codePhrase);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Test(org.junit.Test)

Example 18 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class TerminologyCheckTest method testSimpleValidationSymbol.

@Test
public void testSimpleValidationSymbol() {
    DvCodedText symbol = new DvCodedText("autogenerated (node doesn't have a constraint)", new CodePhrase(new TerminologyId("http://hl7.org/fhir/contact-point-use"), "BCDWXMEORP"));
    org.ehrbase.validation.terminology.validator.DvOrdinal.validate(localizedTerminologies.locale("en"), codesetMapping, "symbol", symbol, "en");
}
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.Test)

Example 19 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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) {
    }
}
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.Test)

Example 20 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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();
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) SnakeCase(org.ehrbase.serialisation.util.SnakeCase) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase)

Aggregations

CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)71 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)60 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)56 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)16 Composition (com.nedap.archie.rm.composition.Composition)12 DvText (com.nedap.archie.rm.datavalues.DvText)12 ArrayList (java.util.ArrayList)8 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 RMObject (com.nedap.archie.rm.RMObject)5 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)5 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)5 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)4 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)4 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)4 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)4 Entry (com.nedap.archie.rm.composition.Entry)3