Search in sources :

Example 1 with TemplateDocument

use of org.openehr.schemas.v1.TemplateDocument in project ehrbase by ehrbase.

the class TemplateFileStorageService method readOperationaltemplate.

@Override
public Optional<OPERATIONALTEMPLATE> readOperationaltemplate(String templateId) {
    OPERATIONALTEMPLATE operationaltemplate = null;
    File file = optFileMap.get(templateId);
    try (InputStream in = file != null ? new BOMInputStream(new FileInputStream(file), true) : null) {
        // manual reading of OPT file and following parsing into object
        org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(in);
        operationaltemplate = document.getTemplate();
    // use the template id instead of the file name as key
    } catch (Exception e) {
        errorMap.put(templateId, e.getMessage());
    // log.error("Could not parse operational template:" + filename + " error:" + e);
    // throw new ServiceManagerException(global, SysErrorCode.INTERNAL_ILLEGALARGUMENT, "Could not parse operational template:"+key+" error:"+e);
    }
    return Optional.ofNullable(operationaltemplate);
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) BOMInputStream(org.apache.commons.io.input.BOMInputStream) BOMInputStream(org.apache.commons.io.input.BOMInputStream) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) InternalServerException(org.ehrbase.api.exception.InternalServerException)

Example 2 with TemplateDocument

use of org.openehr.schemas.v1.TemplateDocument in project ehrbase by ehrbase.

the class KnowledgeCacheService method addOperationalTemplateIntern.

public String addOperationalTemplateIntern(byte[] content, boolean overwrite) {
    TemplateDocument document;
    try {
        document = TemplateDocument.Factory.parse(new ByteArrayInputStream(content));
    } catch (XmlException | IOException e) {
        throw new InvalidApiParameterException(e.getMessage());
    }
    OPERATIONALTEMPLATE template = document.getTemplate();
    if (template == null) {
        throw new InvalidApiParameterException("Could not parse input template");
    }
    if (template.getConcept() == null || template.getConcept().isEmpty()) {
        throw new IllegalArgumentException("Supplied template has nil or empty concept");
    }
    if (template.getDefinition() == null || template.getDefinition().isNil()) {
        throw new IllegalArgumentException("Supplied template has nil or empty definition");
    }
    if (template.getDescription() == null || !template.getDescription().validate()) {
        throw new IllegalArgumentException("Supplied template has nil or empty description");
    }
    if (!TemplateUtils.isSupported(template)) {
        throw new IllegalArgumentException(MessageFormat.format("The supplied template is not supported (unsupported types: {0})", String.join(",", TemplateUtils.UNSUPPORTED_RM_TYPES)));
    }
    String templateId;
    try {
        templateId = TemplateUtils.getTemplateId(template);
    } catch (IllegalArgumentException a) {
        throw new InvalidApiParameterException("Invalid template input content");
    }
    // pre-check: if already existing throw proper exception
    if (!allowTemplateOverwrite && !overwrite && retrieveOperationalTemplate(templateId).isPresent()) {
        throw new StateConflictException("Operational template with this template ID already exists: " + templateId);
    } else {
        invalidateCache(template);
    }
    templateStorage.storeTemplate(template);
    putIntoCache(template);
    if (cacheOptions.isPreBuildQueries()) {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
        executor.submit(() -> {
            try {
                precalculateQueries(templateId);
            } catch (RuntimeException e) {
                log.error("An error occurred while processing template: {}", templateId);
            }
        });
    }
    // retrieve the template Id for this new entry
    return templateId;
}
Also used : InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException) StateConflictException(org.ehrbase.api.exception.StateConflictException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 3 with TemplateDocument

use of org.openehr.schemas.v1.TemplateDocument in project openEHR_SDK by ehrbase.

the class OptSkeletonBuilderTest method testGenerateCorona.

@Test
public void testGenerateCorona() throws Exception {
    org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream());
    OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
    OptSkeletonBuilder cut = new OptSkeletonBuilder();
    Composition generate = (Composition) cut.generate(operationaltemplate);
    assertThat(generate.getContent()).extracting(Locatable::getName).extracting(DvText::getValue).containsExactlyInAnyOrder("Geschichte/Historie", "Symptome", "Kontakt", "Risikogebiet", "Allgemeine Angaben");
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) Locatable(com.nedap.archie.rm.archetyped.Locatable) Test(org.junit.Test)

Example 4 with TemplateDocument

use of org.openehr.schemas.v1.TemplateDocument in project openEHR_SDK by ehrbase.

the class OptSkeletonBuilderTest method testGenerateEpisodeOfCare.

@Test
public void testGenerateEpisodeOfCare() throws Exception {
    org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.EPISODE_OF_CARE.getStream());
    OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
    OptSkeletonBuilder cut = new OptSkeletonBuilder();
    Composition generate = (Composition) cut.generate(operationaltemplate);
    assertThat(generate).isNotNull();
    assertThat(generate.itemAtPath("/composer")).isNotNull();
    assertThat(generate.itemAtPath("/context/end_time")).isNotNull();
    assertThat(generate.itemAtPath("/name")).extracting(d -> ((DvText) d).getValue()).isEqualTo("EpisodeOfCare");
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) DvText(com.nedap.archie.rm.datavalues.DvText) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Locatable(com.nedap.archie.rm.archetyped.Locatable) Test(org.junit.Test) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) DvText(com.nedap.archie.rm.datavalues.DvText) Test(org.junit.Test)

Example 5 with TemplateDocument

use of org.openehr.schemas.v1.TemplateDocument in project openEHR_SDK by ehrbase.

the class OptSkeletonBuilderTest method testGenerate.

@Test
public void testGenerate() throws Exception {
    org.openehr.schemas.v1.TemplateDocument document = org.openehr.schemas.v1.TemplateDocument.Factory.parse(OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE.getStream());
    OPERATIONALTEMPLATE operationaltemplate = document.getTemplate();
    OptSkeletonBuilder cut = new OptSkeletonBuilder();
    Composition generate = (Composition) cut.generate(operationaltemplate);
    assertThat(generate).isNotNull();
    assertThat(generate.itemAtPath("/composer")).isNotNull();
    assertThat(generate.itemAtPath("/context/end_time")).isNotNull();
    assertThat(generate.itemAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]/data[at0001]/events[at0002]/state[at0007]/items[at1005]/value")).isNotNull();
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) Test(org.junit.Test)

Aggregations

OPERATIONALTEMPLATE (org.openehr.schemas.v1.OPERATIONALTEMPLATE)6 Composition (com.nedap.archie.rm.composition.Composition)5 IOException (java.io.IOException)4 XmlException (org.apache.xmlbeans.XmlException)4 Test (org.junit.Test)4 TemplateDocument (org.openehr.schemas.v1.TemplateDocument)4 OptSkeletonBuilder (org.ehrbase.building.OptSkeletonBuilder)3 Locatable (com.nedap.archie.rm.archetyped.Locatable)2 StandardCharsets (java.nio.charset.StandardCharsets)2 IOUtils (org.apache.commons.io.IOUtils)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 OperationalTemplateTestData (org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData)2 CompositionValidator (care.better.platform.web.template.validator.CompositionValidator)1 ValidationErrorDto (care.better.platform.web.template.validator.ValidationErrorDto)1 Observation (com.nedap.archie.rm.composition.Observation)1 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)1 DvText (com.nedap.archie.rm.datavalues.DvText)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1