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