Search in sources :

Example 1 with BaseReference

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));
}
Also used : BaseReference(org.hl7.fhir.r4.model.BaseReference) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) List(java.util.List) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 2 with BaseReference

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));
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle)

Aggregations

Bundle (org.hl7.fhir.r4.model.Bundle)2 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 List (java.util.List)1 IIdType (org.hl7.fhir.instance.model.api.IIdType)1 BaseReference (org.hl7.fhir.r4.model.BaseReference)1