Search in sources :

Example 6 with Participation

use of com.nedap.archie.rm.generic.Participation in project openEHR_SDK by ehrbase.

the class DefaultRestCompositionEndpointIT method testSaveCompositionEntityProxy.

@Test
public void testSaveCompositionEntityProxy() {
    ehr = openEhrClient.ehrEndpoint().createEhr();
    EhrbaseBloodPressureSimpleDeV0Composition bloodPressureSimpleDeV0 = TestData.buildEhrbaseBloodPressureSimpleDeV0();
    ProxyEhrbaseBloodPressureSimpleDeV0Composition proxy = new ProxyEhrbaseBloodPressureSimpleDeV0Composition();
    proxy.dummy = "dummy";
    proxy.setStartTimeValue(OffsetDateTime.of(2019, 04, 03, 22, 00, 00, 00, ZoneOffset.UTC));
    proxy.setEndTimeValue(OffsetDateTime.now());
    proxy.setBloodPressureTrainingSample(new ArrayList<>());
    proxy.setLanguage(Language.DE);
    proxy.setTerritory(Territory.DE);
    proxy.setCategoryDefiningCode(org.ehrbase.client.classgenerator.shareddefinition.Category.EVENT);
    proxy.setSettingDefiningCode(Setting.NURSING_HOME_CARE);
    proxy.setComposer(new PartyIdentified(null, "Test", null));
    proxy.setParticipations(new ArrayList<>());
    proxy.getParticipations().add(new Participation(new PartyIdentified(null, "Test", null), new DvText("Pos1"), null, null));
    proxy.getParticipations().add(new Participation(new PartyIdentified(null, "Test2", null), new DvText("Pos2"), null, null));
    proxy.setBloodPressureTrainingSample(bloodPressureSimpleDeV0.getBloodPressureTrainingSample());
    openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(proxy);
    assertThat(proxy.getVersionUid()).isNotNull();
    assertThat(proxy.getVersionUid().getVersion()).isEqualTo(1L);
    proxy.setSettingDefiningCode(Setting.EMERGENCY_CARE);
    openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(proxy);
    assertThat(proxy.getVersionUid()).isNotNull();
    assertThat(proxy.getVersionUid().getVersion()).isEqualTo(2L);
    proxy.setVersionUid(new VersionUid(proxy.getVersionUid().getUuid(), proxy.getVersionUid().getSystem(), 1L));
    try {
        openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(proxy);
        fail();
    } catch (RuntimeException e) {
        assertThat(e.getClass()).isEqualTo(OptimisticLockException.class);
    }
}
Also used : Participation(com.nedap.archie.rm.generic.Participation) VersionUid(org.ehrbase.client.openehrclient.VersionUid) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) OptimisticLockException(org.ehrbase.client.exception.OptimisticLockException) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) DvText(com.nedap.archie.rm.datavalues.DvText) Test(org.junit.Test)

Example 7 with Participation

use of com.nedap.archie.rm.generic.Participation in project openEHR_SDK by ehrbase.

the class ParticipationTestIT method testParticipation.

@Test
@Ignore("see https://github.com/ehrbase/ehrbase/issues/710")
public void testParticipation() throws IOException {
    ehr = openEhrClient.ehrEndpoint().createEhr();
    Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.PARTICIPATION_NO_CONTENT.getStream(), StandardCharsets.UTF_8), Composition.class);
    VersionUid versionUid = openEhrClient.compositionEndpoint(ehr).mergeRaw(composition);
    Optional<Composition> postedComposition = openEhrClient.compositionEndpoint(ehr).findRaw(versionUid.getUuid());
    assertThat(postedComposition.get()).isNotNull();
    // check the actual participation IDs and Names
    List<Participation> participations = postedComposition.get().getContext().getParticipations();
    List<String> names = participations.stream().map(p -> p.getPerformer()).map(p -> ((PartyIdentified) p).getName()).collect(Collectors.toList());
    assertThat(names).containsExactlyInAnyOrder("Dr. Marcus Johnson", "Zaza Markham");
    List<String> ids = participations.stream().map(p -> p.getPerformer()).map(p -> p.getExternalRef().getId().getValue()).collect(Collectors.toList());
    assertThat(ids).containsExactlyInAnyOrder("000", "123");
    // use the sames IDs, but change one name. This raises an exception for conflicting identity!
    ((PartyIdentified) composition.getContext().getParticipations().get(0).getPerformer()).setName("Dummy");
    try {
        openEhrClient.compositionEndpoint(ehr).mergeRaw(composition);
        fail("Didn't detect conflicting identity!");
    } catch (WrongStatusCodeException e) {
    // continue
    }
    // Now, keep the same names, but change an externalRef id
    composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.PARTICIPATION_NO_CONTENT.getStream(), StandardCharsets.UTF_8), Composition.class);
    composition.getContext().getParticipations().get(0).getPerformer().getExternalRef().setId(new GenericId("ABC", "HOSPITAL-NS"));
    versionUid = openEhrClient.compositionEndpoint(ehr).mergeRaw(composition);
    postedComposition = openEhrClient.compositionEndpoint(ehr).findRaw(versionUid.getUuid());
    assertThat(postedComposition.get()).isNotNull();
    // check the actual participation IDs and Names
    participations = postedComposition.get().getContext().getParticipations();
    names = participations.stream().map(p -> p.getPerformer()).map(p -> ((PartyIdentified) p).getName()).collect(Collectors.toList());
    assertThat(names).containsExactlyInAnyOrder("Dr. Marcus Johnson", "Zaza Markham");
    ids = participations.stream().map(p -> p.getPerformer()).map(p -> p.getExternalRef().getId().getValue()).collect(Collectors.toList());
    assertThat(ids).containsExactlyInAnyOrder("ABC", "123");
    // use the same name and id, but in another namespace
    composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.PARTICIPATION_NO_CONTENT.getStream(), StandardCharsets.UTF_8), Composition.class);
    composition.getContext().getParticipations().get(0).getPerformer().getExternalRef().setNamespace("ANOTHER_NAMESPACE");
    versionUid = openEhrClient.compositionEndpoint(ehr).mergeRaw(composition);
    postedComposition = openEhrClient.compositionEndpoint(ehr).findRaw(versionUid.getUuid());
    assertThat(postedComposition.get()).isNotNull();
    // check the actual participation IDs and Names
    participations = postedComposition.get().getContext().getParticipations();
    List<String> namespaces = participations.stream().map(p -> p.getPerformer()).map(p -> p.getExternalRef().getNamespace()).collect(Collectors.toList());
    assertThat(namespaces).containsExactlyInAnyOrder("ANOTHER_NAMESPACE", "ANOTHER-HOSPITAL-NS");
}
Also used : Language(org.ehrbase.client.classgenerator.shareddefinition.Language) org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.definition) Composition(com.nedap.archie.rm.composition.Composition) VersionUid(org.ehrbase.client.openehrclient.VersionUid) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Containment(org.ehrbase.client.aql.containment.Containment) BefundObservationContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.BefundObservationContainment) VirologischerBefundCompositionContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.VirologischerBefundCompositionContainment) Record2(org.ehrbase.client.aql.record.Record2) Record4(org.ehrbase.client.aql.record.Record4) Record3(org.ehrbase.client.aql.record.Record3) GenericId(com.nedap.archie.rm.support.identification.GenericId) After(org.junit.After) KulturClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.KulturClusterContainment) EhrFields(org.ehrbase.client.aql.field.EhrFields) StandortschlusselDefiningCode(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.definition.StandortschlusselDefiningCode) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) ProbeClusterContainment(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.definition.ProbeClusterContainment) OpenEhrClient(org.ehrbase.client.openehrclient.OpenEhrClient) UUID(java.util.UUID) AufnahmedatenAdminEntryContainment(org.ehrbase.client.classgenerator.examples.stationarerversorgungsfallcomposition.definition.AufnahmedatenAdminEntryContainment) Category(org.junit.experimental.categories.Category) EntlassungsdatenAdminEntryContainment(org.ehrbase.client.classgenerator.examples.stationarerversorgungsfallcomposition.definition.EntlassungsdatenAdminEntryContainment) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Query(org.ehrbase.client.aql.query.Query) PatientenaufenthaltCompositionContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.PatientenaufenthaltCompositionContainment) Optional(java.util.Optional) TestData(org.ehrbase.client.TestData) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) NativeSelectAqlField(org.ehrbase.client.aql.field.NativeSelectAqlField) VersorgungsortAdminEntryContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.definition.VersorgungsortAdminEntryContainment) BeforeClass(org.junit.BeforeClass) 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) Condition(org.ehrbase.client.aql.condition.Condition) ContainmentExpression(org.ehrbase.client.aql.containment.ContainmentExpression) Parameter(org.ehrbase.client.aql.parameter.Parameter) TemporalAccessor(java.time.temporal.TemporalAccessor) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Flattener(org.ehrbase.client.flattener.Flattener) EntityQuery(org.ehrbase.client.aql.query.EntityQuery) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) Integration(org.ehrbase.client.Integration) Tuple(org.assertj.core.groups.Tuple) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) Test(org.junit.Test) IOException(java.io.IOException) Participation(com.nedap.archie.rm.generic.Participation) VirologischerBefundComposition(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.VirologischerBefundComposition) Ignore(org.junit.Ignore) StationarerVersorgungsfallCompositionContainment(org.ehrbase.client.classgenerator.examples.stationarerversorgungsfallcomposition.StationarerVersorgungsfallCompositionContainment) AbteilungsfallClusterContainment(org.ehrbase.client.classgenerator.examples.patientenaufenthaltcomposition.definition.AbteilungsfallClusterContainment) Participation(com.nedap.archie.rm.generic.Participation) Composition(com.nedap.archie.rm.composition.Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) VirologischerBefundComposition(org.ehrbase.client.classgenerator.examples.virologischerbefundcomposition.VirologischerBefundComposition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) VersionUid(org.ehrbase.client.openehrclient.VersionUid) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Participation

use of com.nedap.archie.rm.generic.Participation in project openEHR_SDK by ehrbase.

the class ParticipationConfig method buildChildValues.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Object> buildChildValues(String currentTerm, Participation rmObject, Context<Map<String, Object>> context) {
    Map<String, Object> result = new HashMap<>();
    addValue(result, currentTerm, "id", Optional.of(rmObject).map(Participation::getPerformer).map(PartyProxy::getExternalRef).map(ObjectRef::getId).map(ObjectId::getValue).orElse(null));
    addValue(result, currentTerm, "id_namespace", Optional.of(rmObject).map(Participation::getPerformer).map(PartyProxy::getExternalRef).map(ObjectRef::getNamespace).orElse(null));
    addValue(result, currentTerm, "id_scheme", Optional.of(rmObject).map(Participation::getPerformer).map(PartyProxy::getExternalRef).map(PartyRef::getId).filter(cls -> GenericId.class.isAssignableFrom(cls.getClass())).map(GenericId.class::cast).map(GenericId::getScheme).orElse(null));
    addValue(result, currentTerm, "name", Optional.of(rmObject).map(Participation::getPerformer).filter(p -> PartyIdentified.class.isAssignableFrom(p.getClass())).map(PartyIdentified.class::cast).map(PartyIdentified::getName).orElse(null));
    addValue(result, currentTerm, "mode", Optional.of(rmObject).map(Participation::getMode).map(DvText::getValue).orElse(null));
    addValue(result, currentTerm, "function", Optional.of(rmObject).map(Participation::getFunction).map(DvText::getValue).orElse(null));
    List<DvIdentifier> dvIdentifiers = Optional.of(rmObject).map(Participation::getPerformer).filter(p -> PartyIdentified.class.isAssignableFrom(p.getClass())).map(PartyIdentified.class::cast).map(PartyIdentified::getIdentifiers).orElse(Collections.emptyList());
    IntStream.range(0, dvIdentifiers.size()).forEach(i -> {
        DvIdentifier identifier = dvIdentifiers.get(i);
        addValue(result, currentTerm, "identifiers_id:" + i, identifier.getId());
        addValue(result, currentTerm, "identifiers_issuer:" + i, identifier.getIssuer());
        addValue(result, currentTerm, "identifiers_assigner:" + i, identifier.getAssigner());
        addValue(result, currentTerm, "identifiers_type:" + i, identifier.getType());
    });
    return result;
}
Also used : DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) IntStream(java.util.stream.IntStream) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Context(org.ehrbase.serialisation.walker.Context) java.util(java.util) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) PartyRef(com.nedap.archie.rm.support.identification.PartyRef) DvText(com.nedap.archie.rm.datavalues.DvText) GenericId(com.nedap.archie.rm.support.identification.GenericId) Participation(com.nedap.archie.rm.generic.Participation) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) Participation(com.nedap.archie.rm.generic.Participation) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) DvText(com.nedap.archie.rm.datavalues.DvText) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef)

Example 9 with Participation

use of com.nedap.archie.rm.generic.Participation in project openEHR_SDK by ehrbase.

the class EventContextValueInserter method insert.

@Override
public void insert(EventContext rmObject, DefaultValues defaultValues) {
    if (RMHelper.isEmpty(rmObject.getStartTime()) && defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
        rmObject.setStartTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getEndTime()) && defaultValues.containsDefaultValue(DefaultValuePath.END_TIME)) {
        rmObject.setEndTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.END_TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getHealthCareFacility()) && (defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_NAME) || defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_ID))) {
        rmObject.setHealthCareFacility(buildPartyIdentified(defaultValues, DefaultValuePath.HEALTHCARE_FACILITY_NAME, DefaultValuePath.HEALTHCARE_FACILITY_ID, rmObject.getHealthCareFacility()));
    }
    if (RMHelper.isEmpty(rmObject.getLocation()) && defaultValues.containsDefaultValue(DefaultValuePath.LOCATION)) {
        rmObject.setLocation(defaultValues.getDefaultValue(DefaultValuePath.LOCATION));
    }
    if (RMHelper.isEmpty(rmObject.getSetting()) && defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
        Setting defaultValue = defaultValues.getDefaultValue(DefaultValuePath.SETTING);
        rmObject.setSetting(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
    }
    if (RMHelper.isEmpty(rmObject.getParticipations()) && defaultValues.containsDefaultValue(DefaultValuePath.PARTICIPATION)) {
        rmObject.setParticipations(defaultValues.getDefaultValue(DefaultValuePath.PARTICIPATION));
    }
    if (rmObject.getParticipations() != null) {
        rmObject.getParticipations().stream().map(Participation::getPerformer).filter(Objects::nonNull).map(PartyProxy::getExternalRef).filter(Objects::nonNull).filter(ref -> ref.getId() != null).forEach(ref -> {
            if (ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_NAMESPACE)) {
                ref.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
            }
            if (ref.getId() instanceof GenericId && ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_SCHEME)) {
                ((GenericId) ref.getId()).setScheme(defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME));
            }
        });
    }
}
Also used : PartyProxy(com.nedap.archie.rm.generic.PartyProxy) Objects(java.util.Objects) EventContext(com.nedap.archie.rm.composition.EventContext) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RMHelper(org.ehrbase.serialisation.walker.RMHelper) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Participation(com.nedap.archie.rm.generic.Participation) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) Objects(java.util.Objects) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 10 with Participation

use of com.nedap.archie.rm.generic.Participation in project openEHR_SDK by ehrbase.

the class OtherParticipationAttributes method toMap.

public List<Map<String, Object>> toMap() {
    List<Map<String, Object>> participations = new ArrayList<>();
    for (Participation participation : participationList) {
        Map<String, Object> valuemap = PathMap.getInstance();
        valuemap.put(TAG_CLASS, new SimpleClassName(participation).toString());
        valuemap.put("function", participation.getFunction());
        valuemap.put("mode", participation.getMode());
        valuemap.put("time", participation.getTime());
        valuemap.put("performer", new SubjectAttributes(participation.getPerformer(), compositionSerializer).toMap());
        participations.add(valuemap);
    }
    return participations;
}
Also used : Participation(com.nedap.archie.rm.generic.Participation) ArrayList(java.util.ArrayList) SimpleClassName(org.ehrbase.serialisation.dbencoding.SimpleClassName) Map(java.util.Map) PathMap(org.ehrbase.serialisation.dbencoding.PathMap)

Aggregations

Participation (com.nedap.archie.rm.generic.Participation)12 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)10 DvText (com.nedap.archie.rm.datavalues.DvText)6 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)6 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)5 ArrayList (java.util.ArrayList)5 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)4 GenericId (com.nedap.archie.rm.support.identification.GenericId)4 UUID (java.util.UUID)4 EhrbaseBloodPressureSimpleDeV0Composition (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition)4 Composition (com.nedap.archie.rm.composition.Composition)3 EventContext (com.nedap.archie.rm.composition.EventContext)3 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Optional (java.util.Optional)3 IOUtils (org.apache.commons.io.IOUtils)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Tuple (org.assertj.core.groups.Tuple)3