use of gov.cms.bfd.server.war.r4.providers.preadj.common.ResourceTypeV2 in project beneficiary-fhir-data by CMSgov.
the class AbstractR4ResourceProvider method createBundleFor.
/**
* Creates a Bundle of resources for the given data using the given {@link ResourceTypeV2}.
*
* @param resourceTypes The {@link ResourceTypeV2} data to retrieve.
* @param mbi The mbi to look up associated data for.
* @param isHashed Denotes if the given mbi is hashed.
* @param lastUpdated Date range of desired lastUpdate values to retrieve data for.
* @param serviceDate Date range of the desired service date to retrieve data for.
* @return A Bundle with data found using the provided parameters.
*/
@VisibleForTesting
Bundle createBundleFor(Set<ResourceTypeV2<T>> resourceTypes, String mbi, boolean isHashed, boolean excludeSamhsa, DateRangeParam lastUpdated, DateRangeParam serviceDate) {
List<T> resources = new ArrayList<>();
for (ResourceTypeV2<T> type : resourceTypes) {
List<?> entities;
entities = claimDao.findAllByMbiAttribute(type.getEntityClass(), type.getEntityMbiRecordAttribute(), mbi, isHashed, lastUpdated, serviceDate, type.getEntityEndDateAttribute());
resources.addAll(entities.stream().filter(e -> !excludeSamhsa || hasNoSamhsaData(metricRegistry, e)).map(e -> type.getTransformer().transform(metricRegistry, e)).collect(Collectors.toList()));
}
Bundle bundle = new Bundle();
resources.forEach(c -> {
Bundle.BundleEntryComponent entry = bundle.addEntry();
entry.setResource((Resource) c);
});
return bundle;
}
use of gov.cms.bfd.server.war.r4.providers.preadj.common.ResourceTypeV2 in project beneficiary-fhir-data by CMSgov.
the class AbstractR4ResourceProvider method read.
/**
* Adds support for the FHIR "read" operation, for {@link ClaimResponse}s. The {@link Read}
* annotation indicates that this method supports the read operation.
*
* <p>Read operations take a single parameter annotated with {@link IdParam}, and should return a
* single resource instance.
*
* @param claimId The read operation takes one parameter, which must be of type {@link IdType} and
* must be annotated with the {@link IdParam} annotation.
* @param requestDetails the request details for the read
* @return Returns a resource matching the specified {@link IdDt}, or <code>null</code> if none
* exists.
*/
@Read
@Trace
public T read(@IdParam IdType claimId, RequestDetails requestDetails) {
if (claimId == null)
throw new IllegalArgumentException("Resource ID can not be null");
if (claimId.getVersionIdPartAsLong() != null)
throw new IllegalArgumentException("Resource ID must not define a version.");
String claimIdText = claimId.getIdPart();
if (claimIdText == null || claimIdText.trim().isEmpty())
throw new IllegalArgumentException("Resource ID can not be null/blank");
Matcher claimIdMatcher = CLAIM_ID_PATTERN.matcher(claimIdText);
if (!claimIdMatcher.matches())
throw new IllegalArgumentException("Unsupported ID pattern: " + claimIdText);
String claimIdTypeText = claimIdMatcher.group(1);
Optional<ResourceTypeV2<T>> optional = parseClaimType(claimIdTypeText);
if (optional.isEmpty())
throw new ResourceNotFoundException(claimId);
ResourceTypeV2<T> claimIdType = optional.get();
String claimIdString = claimIdMatcher.group(2);
Object claimEntity;
try {
claimEntity = claimDao.getEntityById(claimIdType, claimIdString);
} catch (NoResultException e) {
throw new ResourceNotFoundException(claimId);
}
return claimIdType.getTransformer().transform(metricRegistry, claimEntity);
}
Aggregations