use of com.nedap.archie.rm.generic.PartyIdentified 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.PartyIdentified 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.PartyIdentified in project openEHR_SDK by ehrbase.
the class FlattenerTest method testFlattenEhrbaseBloodPressureSimpleDeV0.
@Test
public void testFlattenEhrbaseBloodPressureSimpleDeV0() {
Flattener cut = new Flattener(new TestDataTemplateProvider());
EhrbaseBloodPressureSimpleDeV0Composition bloodPressureSimpleDeV0 = TestData.buildEhrbaseBloodPressureSimpleDeV0();
RMObject rmObject = new Unflattener(new TestDataTemplateProvider()).unflatten(bloodPressureSimpleDeV0);
EhrbaseBloodPressureSimpleDeV0Composition actual = cut.flatten((Locatable) rmObject, EhrbaseBloodPressureSimpleDeV0Composition.class);
assertThat(actual).isNotNull();
assertThat(actual.getComposer()).isNotNull().extracting(Object::getClass).isEqualTo(PartyIdentified.class);
PartyIdentified composer = (PartyIdentified) actual.getComposer();
assertThat(composer.getName()).isEqualTo("Test");
assertThat(actual.getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getFunction().getValue()).containsExactlyInAnyOrder(new Tuple("Test", "Pos1"), new Tuple("Test2", "Pos2"));
assertThat(actual.getBloodPressureTrainingSample()).size().isEqualTo(1);
assertThat(actual.getBloodPressureTrainingSample().get(0).getSubject()).isNotNull().extracting(Object::getClass).isEqualTo(PartySelf.class);
assertThat(actual.getBloodPressureTrainingSample().get(0).getSystolicMagnitude()).isEqualTo(22d);
assertThat(actual.getBloodPressureTrainingSample().get(0).getSystolicUnits()).isEqualTo("mm[Hg]");
assertThat(actual.getBloodPressureTrainingSample().get(0).getKorotkoffSoundsDefiningCode()).isEqualTo(KorotkoffSoundsDefiningCode.FIFTH_SOUND);
assertThat(actual.getBloodPressureTrainingSample().get(0).getMeanArterialPressureNullFlavourDefiningCode()).isNull();
}
use of com.nedap.archie.rm.generic.PartyIdentified in project openEHR_SDK by ehrbase.
the class EventContextUnmarshalPostprocessor method process.
/**
* {@inheritDoc}
*/
@Override
public void process(String term, EventContext rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
setValue(term + PATH_DIVIDER + "_location", null, values, rmObject::setLocation, String.class, consumedPaths);
setValue(term + PATH_DIVIDER + "_end_time", null, values, s -> {
if (s != null) {
rmObject.setEndTime(new DvDateTime(s));
}
}, String.class, consumedPaths);
Map<FlatPathDto, String> health_care_facilityValues = FlatHelper.filter(values, term + "/_health_care_facility", false);
if (!health_care_facilityValues.isEmpty()) {
rmObject.setHealthCareFacility(new PartyIdentified());
handleRmAttribute(term, rmObject.getHealthCareFacility(), health_care_facilityValues, consumedPaths, context, "health_care_facility");
}
Map<Integer, Map<String, String>> other = extractMultiValued(term, "_participation", values);
other.values().stream().map(Map::entrySet).map(s -> s.stream().collect(Collectors.toMap(e -> "ctx/" + DefaultValuePath.PARTICIPATION.getPath() + "_" + e.getKey().replace("identifiers_", "identifiers|"), e -> StringUtils.wrap(e.getValue(), '"'))).entrySet()).map(DefaultValues::buildParticipation).forEach(rmObject::addParticipation);
consumeAllMatching(term + PATH_DIVIDER + "_participation", values, consumedPaths, false);
// Strange Path with value true if setting = other care (238)
consumedPaths.add(term + "/" + "setting|238");
// Strange Path with value true if setting != other care (238)
consumedPaths.add(term + "/" + "setting|");
if (rmObject.getSetting() != null && (rmObject.getSetting().getDefiningCode().getTerminologyId() == null || rmObject.getSetting().getDefiningCode().getTerminologyId().getValue() == null)) {
rmObject.getSetting().getDefiningCode().setTerminologyId(new TerminologyId("openehr"));
}
}
use of com.nedap.archie.rm.generic.PartyIdentified 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;
}
Aggregations