Search in sources :

Example 1 with OPERATIONALTEMPLATE

use of org.openehr.schemas.v1.OPERATIONALTEMPLATE in project fhir-bridge by ehrbase.

the class EhrbaseTemplateInitializer method updateTemplate.

private void updateTemplate(String templateId) {
    LOG.info("Update template '{}'", templateId);
    OPERATIONALTEMPLATE fhirBridgeTemplate = templateProvider.find(templateId).orElseThrow(() -> new IllegalStateException("Failed to load template with id " + templateId));
    var options = new XmlOptions();
    options.setSaveSyntheticDocumentElement(new QName("http://schemas.openehr.org/v1", "template"));
    var uri = UriComponentsBuilder.fromHttpUrl(properties.getBaseUrl()).path("rest/admin/template/{templateId}").build(templateId);
    try {
        webClient.put().uri(uri).contentType(MediaType.APPLICATION_XML).bodyValue(fhirBridgeTemplate.xmlText(options)).retrieve().bodyToMono(String.class).block();
    } catch (WebClientException e) {
        throw new IllegalStateException("An error occurred while updating the template with id " + templateId + " in EHRbase", e);
    }
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) WebClientException(org.springframework.web.reactive.function.client.WebClientException)

Example 2 with OPERATIONALTEMPLATE

use of org.openehr.schemas.v1.OPERATIONALTEMPLATE in project fhir-bridge by ehrbase.

the class ResourceTemplateProvider method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    try {
        Arrays.stream(resourceLoader.getResources(prefix + "*.opt")).forEach(resource -> {
            OPERATIONALTEMPLATE template = parse(resource);
            templates.put(template.getTemplateId().getValue(), resource.getFilename());
        });
    } catch (IOException e) {
        throw new FhirBridgeException("An I/O exception occurred during initialization", e);
    }
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) FhirBridgeException(org.ehrbase.fhirbridge.FhirBridgeException) IOException(java.io.IOException)

Example 3 with OPERATIONALTEMPLATE

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

the class TemplateServiceImp method findOperationalTemplate.

@Override
public String findOperationalTemplate(String templateId, OperationalTemplateFormat format) throws ObjectNotFoundException, InvalidApiParameterException, InternalServerException {
    Optional<OPERATIONALTEMPLATE> operationaltemplate;
    if (format.equals(OperationalTemplateFormat.XML)) {
        try {
            operationaltemplate = this.knowledgeCacheService.retrieveOperationalTemplate(templateId);
            if (!operationaltemplate.isPresent()) {
                throw new ObjectNotFoundException("template", "Template with the specified id does not exist");
            }
        } catch (NullPointerException e) {
            // TODO: is this NPE really thrown in case of not found template anymore?
            throw new ObjectNotFoundException("template", "Template with the specified id does not exist", e);
        }
    } else {
        // TODO only XML at the moment
        throw new InvalidApiParameterException("Requested operational template type not supported");
    }
    XmlOptions opts = new XmlOptions();
    opts.setSaveSyntheticDocumentElement(new QName("http://schemas.openehr.org/v1", "template"));
    return operationaltemplate.map(o -> o.xmlText(opts)).orElseThrow(() -> new InternalServerException("Failure while retrieving operational template"));
}
Also used : InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) TemplateService(org.ehrbase.api.service.TemplateService) TemplateMetaDataDto(org.ehrbase.response.ehrscape.TemplateMetaDataDto) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) TemplateMetaData(org.ehrbase.ehr.knowledge.TemplateMetaData) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CARCHETYPEROOT(org.openehr.schemas.v1.CARCHETYPEROOT) Service(org.springframework.stereotype.Service) DSLContext(org.jooq.DSLContext) OperationalTemplateFormat(org.ehrbase.api.definitions.OperationalTemplateFormat) Logger(org.slf4j.Logger) StructuredStringFormat(org.ehrbase.response.ehrscape.StructuredStringFormat) Collectors(java.util.stream.Collectors) StructuredString(org.ehrbase.response.ehrscape.StructuredString) StandardCharsets(java.nio.charset.StandardCharsets) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) Objects(java.util.Objects) List(java.util.List) CompositionService(org.ehrbase.api.service.CompositionService) XmlOptions(org.apache.xmlbeans.XmlOptions) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) ServerConfig(org.ehrbase.api.definitions.ServerConfig) Optional(java.util.Optional) QName(javax.xml.namespace.QName) OBJECTID(org.openehr.schemas.v1.OBJECTID) CompositionFormat(org.ehrbase.response.ehrscape.CompositionFormat) Transactional(org.springframework.transaction.annotation.Transactional) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) QName(javax.xml.namespace.QName) InternalServerException(org.ehrbase.api.exception.InternalServerException) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) XmlOptions(org.apache.xmlbeans.XmlOptions)

Example 4 with OPERATIONALTEMPLATE

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

the class TemplateServiceImp method mapToDto.

private TemplateMetaDataDto mapToDto(TemplateMetaData data) {
    TemplateMetaDataDto dto = new TemplateMetaDataDto();
    dto.setCreatedOn(data.getCreatedOn());
    Optional<OPERATIONALTEMPLATE> operationaltemplate = Optional.ofNullable(data.getOperationaltemplate());
    dto.setTemplateId(operationaltemplate.map(OPERATIONALTEMPLATE::getTemplateId).map(OBJECTID::getValue).orElse(null));
    dto.setArchetypeId(operationaltemplate.map(OPERATIONALTEMPLATE::getDefinition).map(CARCHETYPEROOT::getArchetypeId).map(OBJECTID::getValue).orElse(null));
    dto.setConcept(operationaltemplate.map(OPERATIONALTEMPLATE::getConcept).orElse(null));
    return dto;
}
Also used : OBJECTID(org.openehr.schemas.v1.OBJECTID) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) TemplateMetaDataDto(org.ehrbase.response.ehrscape.TemplateMetaDataDto)

Example 5 with OPERATIONALTEMPLATE

use of org.openehr.schemas.v1.OPERATIONALTEMPLATE 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)

Aggregations

OPERATIONALTEMPLATE (org.openehr.schemas.v1.OPERATIONALTEMPLATE)72 Test (org.junit.Test)59 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)43 OPTParser (org.ehrbase.webtemplate.parser.OPTParser)42 IOException (java.io.IOException)30 XmlException (org.apache.xmlbeans.XmlException)29 TemplateDocument (org.openehr.schemas.v1.TemplateDocument)27 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)26 OperationalTemplateTestData (org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData)26 Tuple (org.assertj.core.groups.Tuple)24 Collectors (java.util.stream.Collectors)23 Path (java.nio.file.Path)22 java.util (java.util)22 JavaFile (com.squareup.javapoet.JavaFile)21 StringUtils (org.apache.commons.lang3.StringUtils)21 FieldSpec (com.squareup.javapoet.FieldSpec)20 TypeSpec (com.squareup.javapoet.TypeSpec)20 Paths (java.nio.file.Paths)20 FileUtils (org.apache.commons.io.FileUtils)20 Composition (com.nedap.archie.rm.composition.Composition)18