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