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);
}
}
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);
}
}
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"));
}
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;
}
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);
}
Aggregations