use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProvider method fetchBeneficiaries.
/**
* Fetch beneficiaries for the PartD coverage parameter. If includeIdentiers are present then the
* entity mappings are fetched as well
*
* @param coverageId coverage type
* @param requestHeader {@link RequestHeaders} the holder that contains all supported resource
* request headers
* @param paging specified
* @return the beneficiaries
*/
private List<Beneficiary> fetchBeneficiaries(TokenParam coverageId, RequestHeaders requestHeader, PatientLinkBuilder paging) {
String contractMonth = coverageId.getSystem().substring(coverageId.getSystem().lastIndexOf('/') + 1);
CcwCodebookVariable partDContractMonth = partDCwVariableFor(contractMonth);
String contractMonthField = partDFieldFor(partDContractMonth);
String contractCode = coverageId.getValueNotNull();
// Fetching with joins is not compatible with setMaxResults as explained in this post:
// https://stackoverflow.com/questions/53569908/jpa-eager-fetching-and-pagination-best-practices
// So, in cases where there are joins and paging, we query in two steps: first fetch bene-ids
// with paging and then fetch full benes with joins.
boolean useTwoSteps = (requestHeader.isMBIinIncludeIdentifiers() && paging.isPagingRequested());
if (useTwoSteps) {
// Fetch ids
List<String> ids = queryBeneficiaryIds(contractMonthField, contractCode, paging).setMaxResults(paging.getQueryMaxSize()).getResultList();
// Fetch the benes using the ids
return queryBeneficiariesByIds(ids, requestHeader).getResultList();
} else {
// Fetch benes and their histories in one query
return queryBeneficiariesBy(contractMonthField, contractCode, paging, requestHeader).setMaxResults(paging.getQueryMaxSize()).getResultList();
}
}
use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.
the class TransformerTestUtils method assertInformationPeriodEquals.
/**
* @param expectedCategorySystem the expected value for {@link
* SupportingInformationComponent#getCategory()}'s {@link Coding#getSystem()}
* @param expectedCategoryCodeVariable the expected {@link CcwCodebookVariable} for {@link
* SupportingInformationComponent#getCategory()}'s {@link Coding#getCode()}
* @param expectedFromDate the expected {@link
* SupportingInformationComponent#getTimingPeriod().getStartElement()}
* @param expectedThruDate the expected {@link
* SupportingInformationComponent#getTimingPeriod().getEndElement()}
* @param actuals the actual {@link SupportingInformationComponent}s to verify
*/
static void assertInformationPeriodEquals(String expectedCategorySystem, CcwCodebookVariable expectedCategoryCodeVariable, LocalDate expectedFromDate, LocalDate expectedThruDate, List<SupportingInformationComponent> actuals) {
String expectedCategoryCode = CCWUtils.calculateVariableReferenceUrl(expectedCategoryCodeVariable);
Optional<SupportingInformationComponent> supportingInformationComponent = actuals.stream().filter(a -> isCodeInConcept(a.getCategory(), expectedCategorySystem, expectedCategoryCode)).findAny();
assertTrue(supportingInformationComponent.isPresent());
try {
assertDateEquals(expectedFromDate, supportingInformationComponent.get().getTimingPeriod().getStartElement());
assertDateEquals(expectedThruDate, supportingInformationComponent.get().getTimingPeriod().getEndElement());
} catch (FHIRException e) {
throw new BadCodeMonkeyException(e);
}
}
use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.
the class TransformerTestUtils method assertBenefitBalanceUsedIntEquals.
/**
* @param expectedBenefitCategory the {@link BenefitCategory} for the expected {@link
* BenefitBalanceComponent#getCategory()}
* @param expectedFinancialType the {@link CcwCodebookVariable} for the expected {@link
* BenefitComponent#getType()}
* @param expectedUsedInt the expected {@link BenefitComponent#getUsedUnsignedIntType()} value
* @param eob the {@link ExplanationOfBenefit} to verify the actual {@link BenefitComponent}
* within
*/
static void assertBenefitBalanceUsedIntEquals(BenefitCategory expectedBenefitCategory, CcwCodebookVariable expectedFinancialType, Integer expectedUsedInt, ExplanationOfBenefit eob) {
Optional<BenefitBalanceComponent> benefitBalanceComponent = eob.getBenefitBalance().stream().filter(bb -> isCodeInConcept(bb.getCategory(), expectedBenefitCategory.getSystem(), expectedBenefitCategory.toCode())).findAny();
assertTrue(benefitBalanceComponent.isPresent());
Optional<BenefitComponent> benefitBalanceFinancialEntry = benefitBalanceComponent.get().getFinancial().stream().filter(f -> isCodeInConcept(f.getType(), TransformerConstants.CODING_BBAPI_BENEFIT_BALANCE_TYPE, CCWUtils.calculateVariableReferenceUrl(expectedFinancialType))).findAny();
assertTrue(benefitBalanceFinancialEntry.isPresent());
try {
assertEquals(expectedUsedInt, benefitBalanceFinancialEntry.get().getUsedUnsignedIntType().getValue());
} catch (FHIRException e) {
throw new BadCodeMonkeyException(e);
}
}
use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.
the class PatientResourceProvider method searchByCoverageContract.
@Search
@Trace
public Bundle searchByCoverageContract(// of relational search is more common.
@RequiredParam(name = "_has:Coverage.extension") @Description(shortDefinition = "Part D coverage type") TokenParam coverageId, @OptionalParam(name = "_has:Coverage.rfrncyr") @Description(shortDefinition = "Part D reference year") TokenParam referenceYear, @OptionalParam(name = "cursor") @Description(shortDefinition = "The cursor used for result pagination") String cursor, RequestDetails requestDetails) {
// Figure out what month they're searching for.
String contractMonth = coverageId.getSystem().substring(coverageId.getSystem().lastIndexOf('/') + 1);
CcwCodebookVariable partDContractMonth = partDCwVariableFor(contractMonth);
String contractMonthValue = partDFieldByMonth(partDContractMonth);
// Figure out which year they're searching for.
int year = Year.now().getValue();
if (referenceYear != null && !StringUtils.isEmpty(referenceYear.getValueNotNull())) {
/*
* TODO Once AB2D has switched to always specifying the year, the implicit `else` on this
* needs to become an invalid request.
*/
try {
year = Integer.parseInt(referenceYear.getValueNotNull());
} catch (NumberFormatException e) {
throw new InvalidRequestException("Invalid contract year specified", e);
}
}
YearMonth ym = YearMonth.of(year, Integer.valueOf(contractMonthValue));
return searchByCoverageContractAndYearMonth(coverageId, ym.atDay(1), requestDetails);
}
use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProvider method searchByCoverageContract.
@Search
@Trace
public Bundle searchByCoverageContract(// of relational search is more common.
@RequiredParam(name = "_has:Coverage.extension") @Description(shortDefinition = "Part D coverage type") TokenParam coverageId, @OptionalParam(name = "_has:Coverage.rfrncyr") @Description(shortDefinition = "Part D reference year") TokenParam referenceYear, @OptionalParam(name = "cursor") @Description(shortDefinition = "The cursor used for result pagination") String cursor, RequestDetails requestDetails) {
String contractMonth = coverageId.getSystem().substring(coverageId.getSystem().lastIndexOf('/') + 1);
CcwCodebookVariable partDContractMonth = partDCwVariableFor(contractMonth);
String contractMonthValue = partDFieldByMonth(partDContractMonth);
// Figure out which year they're searching for.
int year = Year.now().getValue();
if (referenceYear != null && !StringUtils.isEmpty(referenceYear.getValueNotNull())) {
/*
* TODO Once AB2D has switched to always specifying the year, the implicit `else` on this
* needs to become an invalid request.
*/
try {
year = Integer.parseInt(referenceYear.getValueNotNull());
} catch (NumberFormatException e) {
throw new InvalidRequestException("Invalid contract year specified", e);
}
}
YearMonth ym = YearMonth.of(year, Integer.valueOf(contractMonthValue));
return searchByCoverageContractAndYearMonth(coverageId, ym.atDay(1), requestDetails);
}
Aggregations