Search in sources :

Example 1 with WebTemplate

use of org.ehrbase.webtemplate.model.WebTemplate in project ehrbase by ehrbase.

the class KnowledgeCacheService method resolveForTemplate.

@Override
public JsonPathQueryResult resolveForTemplate(String templateId, Collection<NodeId> nodeIds) {
    TemplateIdQueryTuple key = new TemplateIdQueryTuple(templateId, nodeIds);
    JsonPathQueryResult jsonPathQueryResult = jsonPathQueryResultCache.get(key, JsonPathQueryResult.class);
    if (jsonPathQueryResult == null) {
        WebTemplate webTemplate = getQueryOptMetaData(templateId);
        List<WebTemplateNode> webTemplateNodeList = new ArrayList<>();
        webTemplateNodeList.add(webTemplate.getTree());
        for (NodeId nodeId : nodeIds) {
            webTemplateNodeList = webTemplateNodeList.stream().map(n -> n.findMatching(f -> {
                if (f.getNodeId() == null) {
                    return false;
                } else // compere only classname
                if (nodeId.getNodeId() == null) {
                    return nodeId.getClassName().equals(new NodeId(f.getNodeId()).getClassName());
                } else {
                    return nodeId.equals(new NodeId(f.getNodeId()));
                }
            })).flatMap(List::stream).collect(Collectors.toList());
        }
        Set<String> uniquePaths = new TreeSet<>();
        webTemplateNodeList.stream().map(n -> n.getAqlPath(false)).forEach(uniquePaths::add);
        if (!uniquePaths.isEmpty()) {
            jsonPathQueryResult = new JsonPathQueryResult(templateId, uniquePaths);
        } else {
            // dummy result since null can not be path of a cache
            jsonPathQueryResult = new JsonPathQueryResult(null, Collections.emptyMap());
        }
        jsonPathQueryResultCache.put(key, jsonPathQueryResult);
    }
    if (jsonPathQueryResult.getTemplateId() != null) {
        return jsonPathQueryResult;
    } else // Is dummy result
    {
        return null;
    }
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) JsonPathQueryResult(org.ehrbase.aql.containment.JsonPathQueryResult) Cache(org.springframework.cache.Cache) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TemplateMetaData(org.ehrbase.ehr.knowledge.TemplateMetaData) LoggerFactory(org.slf4j.LoggerFactory) TreeSet(java.util.TreeSet) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CacheOptions(org.ehrbase.cache.CacheOptions) NodeId(org.ehrbase.webtemplate.parser.NodeId) Value(org.springframework.beans.factory.annotation.Value) ByteArrayInputStream(java.io.ByteArrayInputStream) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) StateConflictException(org.ehrbase.api.exception.StateConflictException) TemplateIdAqlTuple(org.ehrbase.aql.containment.TemplateIdAqlTuple) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) Logger(org.slf4j.Logger) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) ItemInfo(org.ehrbase.aql.sql.queryimpl.ItemInfo) List(java.util.List) XmlException(org.apache.xmlbeans.XmlException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) Optional(java.util.Optional) I_KnowledgeCache(org.ehrbase.ehr.knowledge.I_KnowledgeCache) TemplateIdQueryTuple(org.ehrbase.aql.containment.TemplateIdQueryTuple) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) Collections(java.util.Collections) TemplateUtils(org.ehrbase.util.TemplateUtils) Transactional(org.springframework.transaction.annotation.Transactional) JsonPathQueryResult(org.ehrbase.aql.containment.JsonPathQueryResult) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) ArrayList(java.util.ArrayList) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) TreeSet(java.util.TreeSet) NodeId(org.ehrbase.webtemplate.parser.NodeId) ArrayList(java.util.ArrayList) List(java.util.List) TemplateIdQueryTuple(org.ehrbase.aql.containment.TemplateIdQueryTuple)

Example 2 with WebTemplate

use of org.ehrbase.webtemplate.model.WebTemplate in project openEHR_SDK by ehrbase.

the class DefaultValuesTest method unmarshal.

@Test
public void unmarshal() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
    WebTemplate webTemplate = new OPTParser(template).parse();
    FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
    String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA_WITH_CONTEXT.getStream(), StandardCharsets.UTF_8);
    Composition actual = cut.unmarshal(flat, webTemplate);
    assertThat(actual).isNotNull();
    assertThat(actual.getCategory()).isNotNull();
    assertThat(actual.getCategory().getValue()).isEqualTo("event");
    assertThat(actual.getLanguage()).isNotNull();
    assertThat(actual.getLanguage().getCodeString()).isEqualTo(Language.DE.getCode());
    assertThat(actual.getComposer()).isNotNull();
    assertThat(actual.getComposer()).getClass().isAssignableFrom(PartyIdentified.class);
    assertThat(((PartyIdentified) actual.getComposer()).getName()).isEqualTo("Silvia Blake");
    assertThat(actual.getComposer().getExternalRef().getNamespace()).isEqualTo("HOSPITAL-NS");
    assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getScheme()).isEqualTo("HOSPITAL-NS");
    assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getValue()).isEqualTo("123");
    assertThat(actual.getContext().getHealthCareFacility().getName()).isEqualTo("Hospital");
    assertThat(actual.getContext().getStartTime()).isNotNull();
    assertThat(actual.getContext().getStartTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
    assertThat(actual.getContext().getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
    Observation observation = actual.getContent().stream().filter(c -> Observation.class.isAssignableFrom(c.getClass())).map(Observation.class::cast).findAny().orElse(null);
    assertThat(observation).isNotNull();
    assertThat(observation.getData()).isNotNull();
    assertThat(observation.getData().getOrigin().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
    assertThat(observation.getData().getEvents().get(0).getTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
    assertThat(observation.getOtherParticipations()).extracting(p -> p.getFunction().getValue(), p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getPerformer().getExternalRef().getNamespace()).containsExactlyInAnyOrder(new Tuple("requester", "Dr. Marcus Johnson", "HOSPITAL-NS"), new Tuple("performer", "Lara Markham", "HOSPITAL-NS"));
    assertThat(observation.getOtherParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
    assertThat(observation.getWorkflowId()).isNotNull();
    assertThat(observation.getWorkflowId().getNamespace()).isEqualTo("HOSPITAL-NS");
    assertThat(observation.getWorkflowId().getId().getValue()).isEqualTo("567");
    assertThat(observation.getWorkflowId().getType()).isEqualTo("ORGANISATION");
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Language(org.ehrbase.client.classgenerator.shareddefinition.Language) Composition(com.nedap.archie.rm.composition.Composition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) GenericId(com.nedap.archie.rm.support.identification.GenericId) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ZoneOffset(java.time.ZoneOffset) FlatJsonUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.FlatJsonUnmarshaller) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) Tuple(org.assertj.core.groups.Tuple) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) Iterator(java.util.Iterator) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) StandardCharsets(java.nio.charset.StandardCharsets) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) IOUtils(org.apache.commons.io.IOUtils) Observation(com.nedap.archie.rm.composition.Observation) XmlException(org.apache.xmlbeans.XmlException) OffsetDateTime(java.time.OffsetDateTime) OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) GenericId(com.nedap.archie.rm.support.identification.GenericId) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Observation(com.nedap.archie.rm.composition.Observation) FlatJsonUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.FlatJsonUnmarshaller) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 3 with WebTemplate

use of org.ehrbase.webtemplate.model.WebTemplate in project openEHR_SDK by ehrbase.

the class FlatJsonUnmarshallerTest method unmarshal.

@Test
public void unmarshal() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
    WebTemplate webTemplate = new OPTParser(template).parse();
    FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
    String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
    Composition actual = cut.unmarshal(flat, webTemplate);
    assertThat(actual).isNotNull();
    Observation observation = (Observation) actual.itemAtPath("/content[openEHR-EHR-OBSERVATION.story.v1]");
    assertThat(observation.getData().getOrigin().getValue()).hasToString("2020-05-11T22:53:12.039139+02:00");
    assertThat(observation.getSubject()).isNotNull();
    assertThat(observation.getSubject().getClass()).isEqualTo(PartySelf.class);
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Observation(com.nedap.archie.rm.composition.Observation) Test(org.junit.Test)

Example 4 with WebTemplate

use of org.ehrbase.webtemplate.model.WebTemplate in project openEHR_SDK by ehrbase.

the class FlatJsonUnmarshallerTest method unmarshalAlt.

@Test
public void unmarshalAlt() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALT_EVENTS.getStream()).getTemplate();
    WebTemplate webTemplate = new OPTParser(template).parse();
    FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
    String flat = IOUtils.toString(CompositionTestDataSimSDTJson.ALTERNATIVE_EVENTS.getStream(), StandardCharsets.UTF_8);
    Composition actual = cut.unmarshal(flat, webTemplate);
    assertThat(actual).isNotNull();
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Test(org.junit.Test)

Example 5 with WebTemplate

use of org.ehrbase.webtemplate.model.WebTemplate in project openEHR_SDK by ehrbase.

the class FlatJsonUnmarshallerTest method unmarshalDeterioriationAssessment.

@Test
public void unmarshalDeterioriationAssessment() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.DETERIORIATION_ASSESSMENT.getStream()).getTemplate();
    WebTemplate webTemplate = new OPTParser(template).parse();
    FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
    String flat = IOUtils.toString(CompositionTestDataSimSDTJson.DETERIORIATION_ASSESSMENT.getStream(), StandardCharsets.UTF_8);
    Composition actual = cut.unmarshal(flat, webTemplate);
    assertThat(actual).isNotNull();
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Test(org.junit.Test)

Aggregations

WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)31 OPERATIONALTEMPLATE (org.openehr.schemas.v1.OPERATIONALTEMPLATE)26 Test (org.junit.Test)22 OPTParser (org.ehrbase.webtemplate.parser.OPTParser)15 Filter (org.ehrbase.webtemplate.filter.Filter)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Composition (com.nedap.archie.rm.composition.Composition)10 IOException (java.io.IOException)10 XmlException (org.apache.xmlbeans.XmlException)10 Collectors (java.util.stream.Collectors)8 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)6 TemplateDocument (org.openehr.schemas.v1.TemplateDocument)6 java.util (java.util)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Tuple (org.assertj.core.groups.Tuple)5 OperationalTemplateTestData (org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData)5 Observation (com.nedap.archie.rm.composition.Observation)4 Map (java.util.Map)4 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)4 StandardCharsets (java.nio.charset.StandardCharsets)3