use of org.hl7.fhir.r4.model.BaseReference in project Gravity-SDOH-Exchange-RI by FHIR.
the class ResourceLoader method getResourcesBySystem.
public Map<Class<? extends Resource>, List<Resource>> getResourcesBySystem(IGenericClient client, String system, List<Reference> references) {
if (references.isEmpty()) {
return Collections.emptyMap();
}
Bundle loadResourcesBundle = new Bundle();
loadResourcesBundle.setType(BundleType.TRANSACTION);
references.stream().map(BaseReference::getReferenceElement).collect(Collectors.groupingBy(IIdType::getResourceType)).forEach((resourceType, referenceElements) -> {
StringBuilder urlBuilder = new StringBuilder(resourceType).append("?").append("identifier").append("=");
String searchParams = referenceElements.stream().map(element -> new StringBuilder(system).append("|").append(element.getIdPart())).map(StringBuilder::toString).collect(Collectors.joining(","));
urlBuilder.append(searchParams);
loadResourcesBundle.addEntry(FhirUtil.createGetEntry(urlBuilder.toString()));
});
return client.transaction().withBundle(loadResourcesBundle).execute().getEntry().stream().map(BundleEntryComponent::getResource).filter(Bundle.class::isInstance).map(Bundle.class::cast).map(Bundle::getEntry).flatMap(List::stream).map(BundleEntryComponent::getResource).collect(Collectors.groupingBy(Resource::getClass));
}
use of org.hl7.fhir.r4.model.BaseReference in project Gravity-SDOH-Exchange-RI by FHIR.
the class ResourceLoader method getResources.
public Map<Class<? extends Resource>, List<Resource>> getResources(IGenericClient client, List<Reference> references) {
if (references.isEmpty()) {
return Collections.emptyMap();
}
Bundle loadResourcesBundle = new Bundle();
loadResourcesBundle.setType(BundleType.TRANSACTION);
references.stream().map(BaseReference::getReferenceElement).map(element -> element.getResourceType() + "/" + element.getIdPart()).map(FhirUtil::createGetEntry).forEach(loadResourcesBundle::addEntry);
return client.transaction().withBundle(loadResourcesBundle).execute().getEntry().stream().map(BundleEntryComponent::getResource).filter(Objects::nonNull).collect(Collectors.groupingBy(Resource::getClass));
}
Aggregations