use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class CoronaTestIT method testCorona.
@Test
@Ignore("see https://github.com/ehrbase/project_management/issues/376")
public void testCorona() throws IOException {
ehr = openEhrClient.ehrEndpoint().createEhr();
Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.CORONA.getStream(), StandardCharsets.UTF_8), Composition.class);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
CoronaAnamneseComposition coronaAnamneseComposition = flattener.flatten(composition, CoronaAnamneseComposition.class);
openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(coronaAnamneseComposition);
assertThat(openEhrClient.compositionEndpoint(ehr).find(coronaAnamneseComposition.getVersionUid().getUuid(), CoronaAnamneseComposition.class)).isNotNull();
CoronaAnamneseCompositionContainment coronaAnamneseCompositionContainment = CoronaAnamneseCompositionContainment.getInstance();
SymptomeSectionContainment symptomeSectionContainment = SymptomeSectionContainment.getInstance();
HustenObservationContainment hustenObservationContainment = HustenObservationContainment.getInstance();
FieberOderErhohteKorpertemperaturObservationContainment fieberOderErhohteKorpertemperaturObservationContainment = FieberOderErhohteKorpertemperaturObservationContainment.getInstance();
HeiserkeitObservationContainment heiserkeitObservationContainment = HeiserkeitObservationContainment.getInstance();
ContainmentExpression containmentExpression = coronaAnamneseCompositionContainment.contains(symptomeSectionContainment).contains(hustenObservationContainment.and(fieberOderErhohteKorpertemperaturObservationContainment).and(heiserkeitObservationContainment));
EntityQuery<Record4<VorhandenDefiningCode, VorhandenDefiningCode, VorhandenDefiningCode, Language>> entityQuery = Query.buildEntityQuery(containmentExpression, hustenObservationContainment.VORHANDEN_DEFINING_CODE, fieberOderErhohteKorpertemperaturObservationContainment.VORHANDEN_DEFINING_CODE, heiserkeitObservationContainment.VORHANDEN_DEFINING_CODE, coronaAnamneseCompositionContainment.LANGUAGE);
Parameter<UUID> ehrIdParameter = entityQuery.buildParameter();
entityQuery.where(Condition.equal(EhrFields.EHR_ID(), ehrIdParameter));
/*
Select
o0/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0005]/value/defining_Code as F0,
o1/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0005]/value/defining_Code as F1,
o2/data[at0001]/events[at0002]/data[at0003]/items[at0022]/items[at0005]/value/defining_Code as F2,
c3/language as F3
from EHR e
contains ( COMPOSITION c3[openEHR-EHR-COMPOSITION.report.v1] contains
SECTION s4[openEHR-EHR-SECTION.adhoc.v1] contains
(
(OBSERVATION o0[openEHR-EHR-OBSERVATION.symptom_sign_screening.v0]
and
OBSERVATION o1[openEHR-EHR-OBSERVATION.symptom_sign_screening.v0])
and
OBSERVATION o2[openEHR-EHR-OBSERVATION.symptom_sign_screening.v0])
)
where e/ehr_id/value = $parm0
*/
List<Record4<VorhandenDefiningCode, VorhandenDefiningCode, VorhandenDefiningCode, Language>> actual = openEhrClient.aqlEndpoint().execute(entityQuery, ehrIdParameter.setValue(ehr));
assertThat(actual).extracting(Record4::value1, Record4::value2, Record4::value3, Record4::value4).containsExactlyInAnyOrder(new Tuple(VorhandenDefiningCode.VORHANDEN, VorhandenDefiningCode.VORHANDEN, VorhandenDefiningCode.NICHT_VORHANDEN, Language.DE));
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class DefaultRestCompositionEndpointIT method testVirologischerBefund.
@Test
public void testVirologischerBefund() throws IOException {
Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.VIROLOGY_FINDING_WITH_SPECIMEN.getStream(), StandardCharsets.UTF_8), Composition.class);
assertThat(composition.itemsAtPath("/content[openEHR-EHR-OBSERVATION.laboratory_test_result.v1]/data[at0001]/events[at0002]/data[at0003]")).isNotNull();
Flattener flattener = new Flattener(new TestDataTemplateProvider());
VirologischerBefundComposition virologischerBefundComposition = flattener.flatten(composition, VirologischerBefundComposition.class);
assertThat(virologischerBefundComposition.getBefund()).isNotNull();
// with the test data
virologischerBefundComposition = TestData.buildTestVirologischerBefundComposition();
assertThat(virologischerBefundComposition.getBefund()).isNotNull();
ehr = openEhrClient.ehrEndpoint().createEhr();
VirologischerBefundComposition version1 = openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(virologischerBefundComposition);
Optional<VirologischerBefundComposition> actual = openEhrClient.compositionEndpoint(ehr).find(version1.getVersionUid().getUuid(), VirologischerBefundComposition.class);
assertThat(actual).isPresent();
assertThat(actual.get().getBefund()).isNotNull();
assertThat(actual.get().getBefund().getKultur().get(0).getProVirus()).extracting(ProVirusCluster::getVirusValue, ProVirusCluster::getAnalyseergebnisReihenfolgeMagnitude).containsExactlyInAnyOrder(new Tuple("SARS-Cov-2", 32L), new Tuple("SARS-Cov-2", 34L));
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflatten.
@Test
public void testUnflatten() {
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
BloodpressureListDe dto = buildExampleBloodpressureListDe();
Composition rmObject = (Composition) cut.unflatten(dto);
assertThat(rmObject).isNotNull();
assertThat(rmObject.itemAtPath("/context/start_time/value")).isEqualTo(dto.getStartTime());
List<Object> observationList = rmObject.itemsAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]");
assertThat(observationList).size().isEqualTo(2);
List<Double> systolischValues = observationList.stream().map(o -> (Observation) o).map(o -> (Element) o.itemAtPath("/data[at0001]/events[at0002]/data[at0003]/items[at0004]")).map(e -> (DvQuantity) e.getValue()).map(DvQuantity::getMagnitude).collect(Collectors.toList());
assertThat(systolischValues).containsExactlyInAnyOrder(12d, 22d);
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflattenCorona.
@Test
public void testUnflattenCorona() throws IOException {
Composition expected = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.CORONA.getStream(), StandardCharsets.UTF_8), Composition.class);
Flattener flattener = new Flattener(new TestDataTemplateProvider());
CoronaAnamneseComposition coronaAnamneseComposition = flattener.flatten(expected, CoronaAnamneseComposition.class);
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
Composition actual = (Composition) cut.unflatten(coronaAnamneseComposition);
assertThat(actual).isNotNull();
assertThat(actual.getContent()).extracting(Locatable::getNameAsString, Locatable::getArchetypeNodeId).containsExactlyInAnyOrder(actual.getContent().stream().map(c -> new Tuple(c.getNameAsString(), c.getArchetypeNodeId())).toArray(Tuple[]::new));
}
use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflattenEhrbaseMultiOccurrenceDeV1.
@Test
public void testUnflattenEhrbaseMultiOccurrenceDeV1() {
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
EhrbaseMultiOccurrenceDeV1Composition dto = TestData.buildEhrbaseMultiOccurrenceDeV1();
Composition rmObject = (Composition) cut.unflatten(dto);
assertThat(rmObject).isNotNull();
assertThat(rmObject.getArchetypeDetails().getTemplateId().getValue()).isEqualTo("ehrbase_multi_occurrence.de.v1");
List<Object> observationList = rmObject.itemsAtPath("/content[openEHR-EHR-OBSERVATION.body_temperature.v2]");
assertThat(observationList).size().isEqualTo(2);
Observation observation1 = (Observation) observationList.get(0);
List<Object> objects = observation1.itemsAtPath("/data[at0002]/events");
assertThat(objects).extracting(o -> ((PointEvent) o)).extracting(p -> (DvQuantity) p.itemAtPath("/data[at0001]/items[at0004]/value")).extracting(DvQuantity::getMagnitude).containsExactlyInAnyOrder(11d, 22d);
DvCodedText dvCodedText = (DvCodedText) observation1.itemAtPath("/protocol[at0020]/items[at0021]/value");
assertThat(dvCodedText.getValue()).isEqualTo("Forehead");
Observation observation2 = (Observation) observationList.get(1);
DvText dvText = (DvText) observation2.itemAtPath("/protocol[at0020]/items[at0021]/value");
assertFalse(dvText instanceof DvCodedText);
assertThat(dvText.getValue()).isEqualTo("location");
}
Aggregations