Search in sources :

Example 1 with Containment

use of org.ehrbase.client.aql.containment.Containment in project openEHR_SDK by ehrbase.

the class ContainmentBinder method handleContainmentDto.

public void handleContainmentDto(ContainmentDto dto, MutablePair<ContainmentExpression, Map<Integer, Containment>> result) {
    ContainmentExpression containmentExpression;
    Map<Integer, Containment> containmentMap = new HashMap<>();
    ContainmentExpression containmentExpression1;
    Containment containment = new Containment(dto.getArchetypeId());
    containmentExpression1 = containment;
    containmentMap.put(dto.getId(), containment);
    if (dto.getContains() != null) {
        Pair<ContainmentExpression, Map<Integer, Containment>> pair = buildContainment(dto.getContains());
        containment.setContains(pair.getLeft());
        containmentMap.putAll(pair.getRight());
    }
    containmentExpression = containmentExpression1;
    result.setLeft(containmentExpression);
    result.setRight(containmentMap);
}
Also used : HashMap(java.util.HashMap) ContainmentExpression(org.ehrbase.client.aql.containment.ContainmentExpression) Map(java.util.Map) HashMap(java.util.HashMap) Containment(org.ehrbase.client.aql.containment.Containment)

Example 2 with Containment

use of org.ehrbase.client.aql.containment.Containment in project openEHR_SDK by ehrbase.

the class DefaultRestFolderDAO method find.

@Override
public <T> List<T> find(Class<T> clazz) {
    Containment compositionContainment = new Containment("COMPOSITION");
    EntityQuery<Record1<T>> query = Query.buildEntityQuery(compositionContainment, new NativeSelectAqlField<>(compositionContainment, "", clazz));
    query.where(Condition.equal(EhrFields.EHR_ID(), directoryEndpoint.getEhrId()).and(Condition.equal(new NativeSelectAqlField<>(compositionContainment, "/template_id", String.class), extractTemplateId(clazz))).and(Condition.matches(new NativeSelectAqlField<>(compositionContainment, "/uid/value", String.class), getFolder().getItems().stream().map(ObjectRef::getId).map(Object::toString).toArray(String[]::new))));
    List<Record1<T>> execute = directoryEndpoint.getDefaultRestClient().aqlEndpoint().execute(query);
    return execute.stream().map(Record1::value1).collect(Collectors.toList());
}
Also used : NativeSelectAqlField(org.ehrbase.client.aql.field.NativeSelectAqlField) Containment(org.ehrbase.client.aql.containment.Containment) Record1(org.ehrbase.client.aql.record.Record1)

Example 3 with Containment

use of org.ehrbase.client.aql.containment.Containment in project openEHR_SDK by ehrbase.

the class EntityQueryTest method buildAqlWithNativePath.

@Test
public void buildAqlWithNativePath() {
    BefundObservationContainment befundObservationContainment = BefundObservationContainment.getInstance();
    ProVirusClusterContainment proVirusClusterContainment = ProVirusClusterContainment.getInstance();
    ProbeClusterContainment probeClusterContainment = ProbeClusterContainment.getInstance();
    Containment compositionContainment = new Containment("COMPOSITION");
    ContainmentExpression containment = compositionContainment.contains(befundObservationContainment).contains(proVirusClusterContainment.and(probeClusterContainment));
    EntityQuery<Record3<String, TemporalAccessor, UUID>> entityQuery = Query.buildEntityQuery(containment, proVirusClusterContainment.VIRUS_VALUE, probeClusterContainment.ZEITPUNKT_DER_PROBENENTNAHME_VALUE, new NativeSelectAqlField<>(compositionContainment, "/uid/value", "uid", UUID.class));
    entityQuery.where(Condition.equal(new NativeSelectAqlField<>(compositionContainment, "/name/value", String.class), "Mikrobiologischer Befund"));
    assertThat(entityQuery.buildAql()).isEqualTo("Select c0/items[at0024]/value/value as virusValue, c1/items[at0015]/value/value as zeitpunktDerProbenentnahmeValue, c2/uid/value as uid " + "from EHR e " + "contains COMPOSITION c2 " + "contains OBSERVATION o3[openEHR-EHR-OBSERVATION.laboratory_test_result.v1] " + "contains (CLUSTER c0[openEHR-EHR-CLUSTER.laboratory_test_analyte.v1] and CLUSTER c1[openEHR-EHR-CLUSTER.specimen.v1]) " + "where c2/name/value = 'Mikrobiologischer Befund'");
}
Also used : ProbeClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProbeClusterContainment) NativeSelectAqlField(org.ehrbase.client.aql.field.NativeSelectAqlField) ContainmentExpression(org.ehrbase.client.aql.containment.ContainmentExpression) UUID(java.util.UUID) Record3(org.ehrbase.client.aql.record.Record3) BefundObservationContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.BefundObservationContainment) ProVirusClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProVirusClusterContainment) EhrbaseBloodPressureSimpleDeV0CompositionContainment(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0CompositionContainment) ProVirusClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProVirusClusterContainment) ProbeClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProbeClusterContainment) Containment(org.ehrbase.client.aql.containment.Containment) BefundObservationContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.BefundObservationContainment) BloodPressureTrainingSampleObservationContainment(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.definition.BloodPressureTrainingSampleObservationContainment) Test(org.junit.Test)

Example 4 with Containment

use of org.ehrbase.client.aql.containment.Containment in project openEHR_SDK by ehrbase.

the class AqlTestIT method testExecute12.

@Test
public void testExecute12() {
    ehr = openEhrClient.ehrEndpoint().createEhr();
    openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(TestData.buildEhrbaseBloodPressureSimpleDeV0());
    EhrbaseBloodPressureSimpleDeV0Composition pressureSimple1 = TestData.buildEhrbaseBloodPressureSimpleDeV0();
    pressureSimple1.getBloodPressureTrainingSample().get(0).setSystolicMagnitude(1.1);
    openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(pressureSimple1);
    EhrbaseBloodPressureSimpleDeV0Composition pressureSimple2 = TestData.buildEhrbaseBloodPressureSimpleDeV0();
    pressureSimple2.getBloodPressureTrainingSample().get(0).setSystolicMagnitude(1.1);
    openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(pressureSimple2);
    Containment observationContainment = new Containment("OBSERVATION");
    NativeSelectAqlField<Double> magnitudeField = new NativeSelectAqlField<>(observationContainment, "/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/magnitude", Double.class);
    EntityQuery<Record2<UUID, Double>> entityQuery = Query.buildEntityQuery(observationContainment, EhrFields.EHR_ID(), magnitudeField);
    Parameter<UUID> ehrIdParameter = entityQuery.buildParameter();
    entityQuery.where(Condition.equal(EhrFields.EHR_ID(), ehrIdParameter).and(Condition.equal(magnitudeField, 1.1d)));
    List<Record2<UUID, Double>> result = openEhrClient.aqlEndpoint().execute(entityQuery, ehrIdParameter.setValue(ehr));
    assertThat(result).isNotNull().size().isEqualTo(1);
}
Also used : NativeSelectAqlField(org.ehrbase.client.aql.field.NativeSelectAqlField) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) UUID(java.util.UUID) Record2(org.ehrbase.client.aql.record.Record2) Containment(org.ehrbase.client.aql.containment.Containment) Test(org.junit.Test)

Example 5 with Containment

use of org.ehrbase.client.aql.containment.Containment in project openEHR_SDK by ehrbase.

the class CoronaTestIT method testNUMResearchCase_8.

/**
 * see https://wiki.vitagroup.ag/display/NUM/Research+Repository
 *
 * Containment test UC 8:
 *
 * contains COMPOSITION c
 * contains OBSERVATION v[openEHR-EHR-OBSERVATION.laboratory_test_result.v1]
 * contains (
 * CLUSTER h[openEHR-EHR-CLUSTER.laboratory_test_panel.v0] and
 * CLUSTER x[openEHR-EHR-CLUSTER.specimen.v1] and
 * CLUSTER q[openEHR-EHR-CLUSTER.laboratory_test_analyte.v1])
 */
@Test
public void testNUMResearchCase_8() {
    VirologischerBefundComposition virologischerBefundComposition = TestData.buildTestVirologischerBefundComposition();
    assertThat(virologischerBefundComposition.getBefund()).isNotNull();
    ehr = openEhrClient.ehrEndpoint().createEhr();
    openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(virologischerBefundComposition);
    // build AQL expression
    Containment compositionContainment = new Containment("COMPOSITION");
    BefundObservationContainment befundObservationContainment = BefundObservationContainment.getInstance();
    ProbeClusterContainment probeClusterContainment = ProbeClusterContainment.getInstance();
    KulturClusterContainment kulturClusterContainment = KulturClusterContainment.getInstance();
    ProVirusClusterContainment proVirusClusterContainment = ProVirusClusterContainment.getInstance();
    ContainmentExpression containmentExpression = compositionContainment.contains(befundObservationContainment.contains(kulturClusterContainment.and(probeClusterContainment.and(proVirusClusterContainment))));
    EntityQuery<Record2<String, Long>> entityQuery = Query.buildEntityQuery(containmentExpression, proVirusClusterContainment.VIRUS_VALUE, proVirusClusterContainment.ANALYSEERGEBNIS_REIHENFOLGE_MAGNITUDE);
    Parameter<UUID> ehrIdParameter = entityQuery.buildParameter();
    entityQuery.where(Condition.equal(EhrFields.EHR_ID(), ehrIdParameter).and(Condition.equal(new NativeSelectAqlField<>(compositionContainment, "/name/value", String.class), "Virologischer Befund")));
    List<Record2<String, Long>> actual = openEhrClient.aqlEndpoint().execute(entityQuery, ehrIdParameter.setValue(ehr));
    // NB. At the moment, we cannot specify DISTINCT with SDK
    assertThat(actual).extracting(Record2::value1, Record2::value2).containsExactlyInAnyOrder(new Tuple("SARS-Cov-2", 32L), new Tuple("SARS-Cov-2", 34L), new Tuple("SARS-Cov-2", 32L), new Tuple("SARS-Cov-2", 34L));
}
Also used : ContainmentExpression(org.ehrbase.client.aql.containment.ContainmentExpression) VirologischerBefundComposition(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.VirologischerBefundComposition) ProVirusClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProVirusClusterContainment) ProbeClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProbeClusterContainment) KulturClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.KulturClusterContainment) UUID(java.util.UUID) Record2(org.ehrbase.client.aql.record.Record2) Tuple(org.assertj.core.groups.Tuple) FieberOderErhohteKorpertemperaturObservationContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition.FieberOderErhohteKorpertemperaturObservationContainment) Containment(org.ehrbase.client.aql.containment.Containment) BefundObservationContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.BefundObservationContainment) VirologischerBefundCompositionContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.VirologischerBefundCompositionContainment) ReisefallObservationContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition.ReisefallObservationContainment) KulturClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.KulturClusterContainment) ProbeClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProbeClusterContainment) RisikogebietSectionContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition.RisikogebietSectionContainment) SymptomeSectionContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition.SymptomeSectionContainment) AufnahmedatenAdminEntryContainment(org.ehrbase.client.classgenerator.examples.stationarerversorgungsfallcomposition.definition.AufnahmedatenAdminEntryContainment) EntlassungsdatenAdminEntryContainment(org.ehrbase.client.classgenerator.examples.stationarerversorgungsfallcomposition.definition.EntlassungsdatenAdminEntryContainment) HustenObservationContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition.HustenObservationContainment) PatientenaufenthaltCompositionContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.PatientenaufenthaltCompositionContainment) VersorgungsortAdminEntryContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.definition.VersorgungsortAdminEntryContainment) StandortClusterContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.definition.StandortClusterContainment) CoronaAnamneseCompositionContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseCompositionContainment) ProVirusClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProVirusClusterContainment) HeiserkeitObservationContainment(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition.HeiserkeitObservationContainment) StationarerVersorgungsfallCompositionContainment(org.ehrbase.client.classgenerator.examples.stationarerversorgungsfallcomposition.StationarerVersorgungsfallCompositionContainment) AbteilungsfallClusterContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.definition.AbteilungsfallClusterContainment) BefundObservationContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.BefundObservationContainment) Test(org.junit.Test)

Aggregations

Containment (org.ehrbase.client.aql.containment.Containment)9 ContainmentExpression (org.ehrbase.client.aql.containment.ContainmentExpression)5 Map (java.util.Map)4 HashMap (java.util.HashMap)3 List (java.util.List)3 UUID (java.util.UUID)3 SelectAqlField (org.ehrbase.client.aql.field.SelectAqlField)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 StringUtils (org.apache.commons.lang3.StringUtils)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 Pair (org.apache.commons.lang3.tuple.Pair)2 ParameterValue (org.ehrbase.aql.dto.condition.ParameterValue)2 Condition (org.ehrbase.client.aql.condition.Condition)2 NativeSelectAqlField (org.ehrbase.client.aql.field.NativeSelectAqlField)2 Record2 (org.ehrbase.client.aql.record.Record2)2 AnnotationSpec (com.squareup.javapoet.AnnotationSpec)1 ClassName (com.squareup.javapoet.ClassName)1 FieldSpec (com.squareup.javapoet.FieldSpec)1 JavaFile (com.squareup.javapoet.JavaFile)1