use of gov.cms.bfd.server.war.commons.MedicareSegment 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.server.war.commons.MedicareSegment in project beneficiary-fhir-data by CMSgov.
the class CoverageResourceProviderIT method searchByExistingBeneficiaryWithPaging.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
* works as expected for a {@link Beneficiary} that does exist in the DB, with paging.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchByExistingBeneficiaryWithPaging() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtils.buildPatientId(beneficiary))).count(4).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(MedicareSegment.values().length, searchResults.getTotal());
/*
* Verify that only the first and last paging links exist, since there should
* only be one page.
*/
assertNotNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNotNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Verify that each of the expected Coverages (one for every MedicareSegment) is
* present and looks correct.
*/
Coverage partACoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
use of gov.cms.bfd.server.war.commons.MedicareSegment in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProviderIT method searchByExistingBeneficiaryWithPaging.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
* works as expected for a {@link Beneficiary} that does exist in the DB, with paging.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchByExistingBeneficiaryWithPaging() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).count(4).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(MedicareSegment.values().length, searchResults.getTotal());
/*
* Verify that only the first and last paging links exist, since there should
* only be one page.
*/
assertNotNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNotNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Verify that each of the expected Coverages (one for every MedicareSegment) is
* present and looks correct.
*/
Coverage partACoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
use of gov.cms.bfd.server.war.commons.MedicareSegment in project beneficiary-fhir-data by CMSgov.
the class R4CoverageResourceProviderIT method searchByExistingBeneficiary.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.R4CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
* works as expected for a {@link Beneficiary} that does exist in the DB.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchByExistingBeneficiary() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(MedicareSegment.values().length, searchResults.getTotal());
/*
* Verify that no paging links exist within the bundle.
*/
assertNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Verify that each of the expected Coverages (one for every
* MedicareSegment) is present and looks correct.
*/
Coverage partACoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> c.getClass_().stream().filter(cl -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(cl.getValue())).findAny().isPresent()).findFirst().get();
CoverageTransformerV2Test.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
use of gov.cms.bfd.server.war.commons.MedicareSegment in project beneficiary-fhir-data by CMSgov.
the class CoverageResourceProviderIT method searchByExistingBeneficiary.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary(ca.uhn.fhir.rest.param.ReferenceParam)}
* works as expected for a {@link Beneficiary} that does exist in the DB.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchByExistingBeneficiary() throws FHIRException {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(MedicareSegment.values().length, searchResults.getTotal());
/*
* Verify that no paging links exist within the bundle.
*/
assertNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Verify that each of the expected Coverages (one for every
* MedicareSegment) is present and looks correct.
*/
Coverage partACoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_A.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartAMatches(beneficiary, partACoverageFromSearchResult);
Coverage partBCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_B.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartBMatches(beneficiary, partBCoverageFromSearchResult);
Coverage partDCoverageFromSearchResult = searchResults.getEntry().stream().filter(e -> e.getResource() instanceof Coverage).map(e -> (Coverage) e.getResource()).filter(c -> TransformerConstants.COVERAGE_PLAN_PART_D.equals(c.getGrouping().getSubPlan())).findFirst().get();
CoverageTransformerTest.assertPartDMatches(beneficiary, partDCoverageFromSearchResult);
}
Aggregations