use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.
the class CareEntryPostprocessor method process.
/**
* {@inheritDoc}
*/
@Override
public void process(String term, CareEntry rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
Map<FlatPathDto, String> guidelineValues = FlatHelper.filter(values, term + "/_guideline_id", false);
if (!guidelineValues.isEmpty()) {
ObjectRef<GenericId> guidelineId = new ObjectRef<>();
guidelineId.setId(new GenericId());
setValue(term + "/_guideline_id", "type", guidelineValues, guidelineId::setType, String.class, consumedPaths);
setValue(term + "/_guideline_id", "namespace", guidelineValues, guidelineId::setNamespace, String.class, consumedPaths);
setValue(term + "/_guideline_id", "id", guidelineValues, s -> guidelineId.getId().setValue(s), String.class, consumedPaths);
setValue(term + "/_guideline_id", "id_scheme", guidelineValues, s -> guidelineId.getId().setScheme(s), String.class, consumedPaths);
rmObject.setGuidelineId(guidelineId);
}
}
use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.
the class DefaultValues method buildParticipation.
public static Participation buildParticipation(Collection<Map.Entry<String, String>> subValues) {
Participation participation = new Participation();
participation.setPerformer(new PartyIdentified());
extractExact(subValues, "id", s -> {
participation.getPerformer().setExternalRef(new PartyRef());
participation.getPerformer().getExternalRef().setType("PARTY");
GenericId id = new GenericId();
id.setValue(s);
participation.getPerformer().getExternalRef().setId(id);
});
extract(subValues, "name", ((PartyIdentified) participation.getPerformer())::setName);
if (participation.getPerformer().getExternalRef() != null) {
extract(subValues, "id_namespace", n -> participation.getPerformer().getExternalRef().setNamespace(n));
extract(subValues, "id_scheme", ((GenericId) participation.getPerformer().getExternalRef().getId())::setScheme);
}
extract(subValues, "function", s -> participation.setFunction(new DvText(s)));
extract(subValues, "mode", s -> {
ParticipationMode participationMode = findEnumValueOrThrow(s, ParticipationMode.class);
participation.setMode(new DvCodedText());
participation.getMode().setValue(participationMode.getValue());
participation.getMode().setDefiningCode(participationMode.toCodePhrase());
});
((PartyIdentified) participation.getPerformer()).setIdentifiers(splitByIndex(filter(subValues.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), DefaultValuePath.PARTICIPATION.getPath() + "_" + "identifiers")).values().stream().map(DefaultValues::toDvIdentifier).collect(Collectors.toList()));
return participation;
}
use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.
the class AbstractValueInserter method buildPartyIdentified.
protected PartyIdentified buildPartyIdentified(DefaultValues defaultValues, DefaultValuePath<String> name, DefaultValuePath<String> id, PartyProxy partyProxy) {
if (partyProxy == null || !PartyIdentified.class.isAssignableFrom(partyProxy.getClass())) {
partyProxy = new PartyIdentified();
}
if (defaultValues.containsDefaultValue(name)) {
((PartyIdentified) partyProxy).setName(defaultValues.getDefaultValue(name));
}
if (defaultValues.containsDefaultValue(id)) {
PartyRef partyRef = new PartyRef();
partyRef.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
partyRef.setType("PARTY");
partyRef.setId(new GenericId(defaultValues.getDefaultValue(id), defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME)));
partyProxy.setExternalRef(partyRef);
}
addSchemeNamespace(partyProxy.getExternalRef(), defaultValues);
return (PartyIdentified) partyProxy;
}
use of com.nedap.archie.rm.support.identification.GenericId in project openEHR_SDK by ehrbase.
the class PartyIdentifiedRMUnmarshaller method handle.
@Override
public void handle(String currentTerm, PartyIdentified rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, "name", currentValues, rmObject::setName, String.class, consumedPaths);
if (rmObject.getName() == null) {
// betters implementation uses /name or /_name instead of |name for subject
setValue(currentTerm + "/name", null, currentValues, rmObject::setName, String.class, consumedPaths);
if (rmObject.getName() == null) {
setValue(currentTerm + "/_name", null, currentValues, rmObject::setName, String.class, consumedPaths);
}
}
rmObject.setExternalRef(new PartyRef());
rmObject.getExternalRef().setType("PARTY");
rmObject.getExternalRef().setId(new GenericId());
setValue(currentTerm, "id", currentValues, rmObject.getExternalRef().getId()::setValue, String.class, consumedPaths);
setValue(currentTerm, "id_scheme", currentValues, ((GenericId) rmObject.getExternalRef().getId())::setScheme, String.class, consumedPaths);
setValue(currentTerm, "id_namespace", currentValues, rmObject.getExternalRef()::setNamespace, String.class, consumedPaths);
// remove if not set
if (rmObject.getExternalRef().getId() == null || StringUtils.isBlank(rmObject.getExternalRef().getId().getValue())) {
rmObject.setExternalRef(null);
}
Map<Integer, Map<String, String>> identifiers = extractMultiValued(currentTerm, "_identifier", currentValues);
rmObject.setIdentifiers(identifiers.values().stream().map(DefaultValues::toDvIdentifier).collect(Collectors.toList()));
consumeAllMatching(currentTerm + PATH_DIVIDER + "_identifier", currentValues, consumedPaths, false);
}
use of com.nedap.archie.rm.support.identification.GenericId 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");
}
Aggregations