Search in sources :

Example 1 with ResourceTypeV2

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;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) ClaimDao(gov.cms.bfd.server.war.r4.providers.preadj.common.ClaimDao) Trace(com.newrelic.api.agent.Trace) SpringConfiguration(gov.cms.bfd.server.war.SpringConfiguration) Description(ca.uhn.fhir.model.api.annotation.Description) NoResultException(javax.persistence.NoResultException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) PreAdjMcsClaim(gov.cms.bfd.model.rda.PreAdjMcsClaim) Inject(javax.inject.Inject) TransformerUtilsV2(gov.cms.bfd.server.war.r4.providers.TransformerUtilsV2) Matcher(java.util.regex.Matcher) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Search(ca.uhn.fhir.rest.annotation.Search) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Map(java.util.Map) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Nonnull(javax.annotation.Nonnull) Read(ca.uhn.fhir.rest.annotation.Read) PreAdjFissClaim(gov.cms.bfd.model.rda.PreAdjFissClaim) IdDt(ca.uhn.fhir.model.primitive.IdDt) MetricRegistry(com.codahale.metrics.MetricRegistry) Set(java.util.Set) Resource(org.hl7.fhir.r4.model.Resource) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Collectors(java.util.stream.Collectors) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Objects(java.util.Objects) List(java.util.List) ResourceTypeV2(gov.cms.bfd.server.war.r4.providers.preadj.common.ResourceTypeV2) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Pattern(java.util.regex.Pattern) Claim(org.hl7.fhir.r4.model.Claim) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Bundle(org.hl7.fhir.r4.model.Bundle) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ResourceTypeV2

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);
}
Also used : Matcher(java.util.regex.Matcher) NoResultException(javax.persistence.NoResultException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) ResourceTypeV2(gov.cms.bfd.server.war.r4.providers.preadj.common.ResourceTypeV2) Read(ca.uhn.fhir.rest.annotation.Read) Trace(com.newrelic.api.agent.Trace)

Aggregations

Read (ca.uhn.fhir.rest.annotation.Read)2 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 Trace (com.newrelic.api.agent.Trace)2 ResourceTypeV2 (gov.cms.bfd.server.war.r4.providers.preadj.common.ResourceTypeV2)2 Matcher (java.util.regex.Matcher)2 NoResultException (javax.persistence.NoResultException)2 Description (ca.uhn.fhir.model.api.annotation.Description)1 IdDt (ca.uhn.fhir.model.primitive.IdDt)1 IdParam (ca.uhn.fhir.rest.annotation.IdParam)1 OptionalParam (ca.uhn.fhir.rest.annotation.OptionalParam)1 RequiredParam (ca.uhn.fhir.rest.annotation.RequiredParam)1 Search (ca.uhn.fhir.rest.annotation.Search)1 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)1 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)1 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)1 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)1 TokenParam (ca.uhn.fhir.rest.param.TokenParam)1 IResourceProvider (ca.uhn.fhir.rest.server.IResourceProvider)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1