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