use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.
the class CoverageResourceProvider method findBeneficiaryById.
/**
* @param beneficiaryId the {@link Beneficiary#getBeneficiaryId()} value to find a matching {@link
* Beneficiary} for
* @return the {@link Beneficiary} that matches the specified {@link
* Beneficiary#getBeneficiaryId()} value
* @throws NoResultException A {@link NoResultException} will be thrown if no matching {@link
* Beneficiary} can be found in the database.
*/
@Trace
private Beneficiary findBeneficiaryById(String beneficiaryId, DateRangeParam lastUpdatedRange) throws NoResultException {
// Optimize when the lastUpdated parameter is specified and result set is empty
if (loadedFilterManager.isResultSetEmpty(beneficiaryId, lastUpdatedRange)) {
throw new NoResultException();
}
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Beneficiary> criteria = builder.createQuery(Beneficiary.class);
Root<Beneficiary> root = criteria.from(Beneficiary.class);
root.fetch(Beneficiary_.beneficiaryMonthlys, JoinType.LEFT);
criteria.select(root);
Predicate wherePredicate = builder.equal(root.get(Beneficiary_.beneficiaryId), beneficiaryId);
if (lastUpdatedRange != null) {
Predicate predicate = QueryUtils.createLastUpdatedPredicate(builder, root, lastUpdatedRange);
wherePredicate = builder.and(wherePredicate, predicate);
}
criteria.where(wherePredicate);
Beneficiary beneficiary = null;
Long beneByIdQueryNanoSeconds = null;
Timer.Context timerBeneQuery = metricRegistry.timer(MetricRegistry.name(getClass().getSimpleName(), "query", "bene_by_id")).time();
try {
beneficiary = entityManager.createQuery(criteria).getSingleResult();
} finally {
beneByIdQueryNanoSeconds = timerBeneQuery.stop();
TransformerUtils.recordQueryInMdc("bene_by_id.include_", beneByIdQueryNanoSeconds, beneficiary == null ? 0 : 1);
}
return beneficiary;
}
use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformerV2Test method setup.
@BeforeEach
public void setup() {
List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
// Pull out the base Beneficiary record and fix its HICN and MBI-HASH fields.
beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
beneficiary.getSkippedRifRecords().add(new SkippedRifRecord());
beneficiary.setLastUpdated(Instant.now());
beneficiary.setMbiHash(Optional.of("someMBIhash"));
// Add the history records to the Beneficiary, but nill out the HICN fields.
Set<BeneficiaryHistory> beneficiaryHistories = parsedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r).filter(r -> beneficiary.getBeneficiaryId().equals(r.getBeneficiaryId())).collect(Collectors.toSet());
beneficiary.getBeneficiaryHistories().addAll(beneficiaryHistories);
// Add the MBI history records to the Beneficiary.
Set<MedicareBeneficiaryIdHistory> beneficiaryMbis = parsedRecords.stream().filter(r -> r instanceof MedicareBeneficiaryIdHistory).map(r -> (MedicareBeneficiaryIdHistory) r).filter(r -> beneficiary.getBeneficiaryId().equals(r.getBeneficiaryId().orElse(null))).collect(Collectors.toSet());
beneficiary.getMedicareBeneficiaryIdHistories().addAll(beneficiaryMbis);
assertThat(beneficiary, is(notNullValue()));
createPatient(RequestHeaders.getHeaderWrapper());
}
use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.
the class CoverageTransformerV2Test method setup.
@BeforeEach
public void setup() {
List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
// Pull out the base Beneficiary record and fix its HICN and MBI-HASH fields.
beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Calendar calen = Calendar.getInstance();
calen.set(2021, 3, 17);
beneficiary.setLastUpdated(calen.getTime().toInstant());
}
use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProvider method read.
/**
* Adds support for the FHIR "read" operation, for {@link Coverage}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 coverageId The read operation takes one parameter, which must be of type {@link IdType}
* and must be annotated with the {@link IdParam} annotation.
* @return Returns a resource matching the specified {@link IdDt}, or <code>null</code> if none
* exists.
*/
@Read(version = false)
@Trace
public Coverage read(@IdParam IdType coverageId) {
if (coverageId == null)
throw new IllegalArgumentException();
if (coverageId.getVersionIdPartAsLong() != null)
throw new IllegalArgumentException();
String coverageIdText = coverageId.getIdPart();
if (coverageIdText == null || coverageIdText.trim().isEmpty())
throw new IllegalArgumentException();
Operation operation = new Operation(Operation.Endpoint.V2_COVERAGE);
operation.setOption("by", "id");
operation.publishOperationName();
Matcher coverageIdMatcher = COVERAGE_ID_PATTERN.matcher(coverageIdText);
if (!coverageIdMatcher.matches())
throw new IllegalArgumentException("Unsupported ID pattern: " + coverageIdText);
String coverageIdSegmentText = coverageIdMatcher.group(1);
Optional<MedicareSegment> coverageIdSegment = MedicareSegment.selectByUrlPrefix(coverageIdSegmentText);
if (!coverageIdSegment.isPresent())
throw new ResourceNotFoundException(coverageId);
String coverageIdBeneficiaryIdText = coverageIdMatcher.group(2);
Beneficiary beneficiaryEntity;
try {
beneficiaryEntity = findBeneficiaryById(coverageIdBeneficiaryIdText, null);
if (!beneficiaryEntity.getBeneEnrollmentReferenceYear().isPresent()) {
throw new ResourceNotFoundException("Cannot find coverage for non present enrollment year");
}
} catch (NoResultException e) {
throw new ResourceNotFoundException(new IdDt(Beneficiary.class.getSimpleName(), coverageIdBeneficiaryIdText));
}
Coverage coverage = CoverageTransformerV2.transform(metricRegistry, coverageIdSegment.get(), beneficiaryEntity);
return coverage;
}
use of gov.cms.bfd.model.rif.Beneficiary in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProvider method searchByBeneficiary.
/**
* Adds support for the FHIR "search" operation for {@link Coverage}s, allowing users to search by
* {@link Coverage#getBeneficiary()}.
*
* <p>The {@link Search} annotation indicates that this method supports the search operation.
* There may be many different methods annotated with this {@link Search} annotation, to support
* many different search criteria.
*
* @param beneficiary a {@link ReferenceParam} for the {@link Coverage#getBeneficiary()} to try
* and find matches for
* @param startIndex an {@link OptionalParam} for the startIndex (or offset) used to determine
* pagination
* @param lastUpdated an {@link OptionalParam} to filter the results based on the passed date
* range
* @param requestDetails a {@link RequestDetails} containing the details of the request URL, used
* to parse out pagination values
* @return Returns a {@link List} of {@link Coverage}s, which may contain multiple matching
* resources, or may also be empty.
*/
@Search
@Trace
public Bundle searchByBeneficiary(@RequiredParam(name = Coverage.SP_BENEFICIARY) @Description(shortDefinition = "The patient identifier to search for") ReferenceParam beneficiary, @OptionalParam(name = "startIndex") @Description(shortDefinition = "The offset used for result pagination") String startIndex, @OptionalParam(name = "_lastUpdated") @Description(shortDefinition = "Include resources last updated in the given range") DateRangeParam lastUpdated, RequestDetails requestDetails) {
List<IBaseResource> coverages;
try {
Beneficiary beneficiaryEntity = findBeneficiaryById(beneficiary.getIdPart(), lastUpdated);
if (!beneficiaryEntity.getBeneEnrollmentReferenceYear().isPresent()) {
throw new ResourceNotFoundException("Cannot find coverage for non present enrollment year");
}
coverages = CoverageTransformerV2.transform(metricRegistry, beneficiaryEntity);
} catch (NoResultException e) {
coverages = new LinkedList<IBaseResource>();
}
OffsetLinkBuilder paging = new OffsetLinkBuilder(requestDetails, "/Coverage?");
Operation operation = new Operation(Operation.Endpoint.V2_COVERAGE);
operation.setOption("by", "beneficiary");
operation.setOption("pageSize", paging.isPagingRequested() ? "" + paging.getPageSize() : "*");
operation.setOption("_lastUpdated", Boolean.toString(lastUpdated != null && !lastUpdated.isEmpty()));
operation.publishOperationName();
// Add bene_id to MDC logs
TransformerUtilsV2.logBeneIdToMdc(Arrays.asList(beneficiary.getIdPart()));
return TransformerUtilsV2.createBundle(paging, coverages, loadedFilterManager.getTransactionTime());
}
Aggregations