use of org.hl7.fhir.r4.model.Coverage in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method createBundle.
/**
* Create a bundle from the entire search result
*
* @param resources a list of {@link ExplanationOfBenefit}s, {@link Coverage}s, or {@link
* Patient}s, all of which will be added to the bundle
* @param paging contains the {@link LinkBuilder} information to add to the bundle
* @param transactionTime date for the bundle
* @return Returns a {@link Bundle} of either {@link ExplanationOfBenefit}s, {@link Coverage}s, or
* {@link Patient}s, which may contain multiple matching resources, or may also be empty.
*/
public static Bundle createBundle(List<IBaseResource> resources, LinkBuilder paging, Instant transactionTime) {
Bundle bundle = new Bundle();
TransformerUtils.addResourcesToBundle(bundle, resources);
paging.addLinks(bundle);
bundle.setTotalElement(paging.isPagingRequested() ? new UnsignedIntType() : new UnsignedIntType(resources.size()));
/*
* Dev Note: the Bundle's lastUpdated timestamp is the known last update time for the whole
* database. Because the filterManager's tracking of this timestamp is lazily updated for
* performance reason, the resources of the bundle may be after the filter manager's version of
* the timestamp.
*/
Instant maxBundleDate = resources.stream().map(r -> r.getMeta().getLastUpdated().toInstant()).filter(Objects::nonNull).max(Instant::compareTo).orElse(transactionTime);
bundle.getMeta().setLastUpdated(transactionTime.isAfter(maxBundleDate) ? Date.from(transactionTime) : Date.from(maxBundleDate));
return bundle;
}
use of org.hl7.fhir.r4.model.Coverage in project beneficiary-fhir-data by CMSgov.
the class HHAClaimTransformerV2Test method shouldReferenceCoverageInInsurance.
/**
* Insurance
*/
@Test
public void shouldReferenceCoverageInInsurance() {
// Only one insurance object
assertEquals(1, eob.getInsurance().size());
InsuranceComponent insurance = eob.getInsuranceFirstRep();
InsuranceComponent compare = new InsuranceComponent().setCoverage(new Reference().setReference("Coverage/part-b-567834"));
assertTrue(compare.equalsDeep(insurance));
}
use of org.hl7.fhir.r4.model.Coverage in project beneficiary-fhir-data by CMSgov.
the class CoverageTransformerV2Test method verifyCoverageContract.
private static void verifyCoverageContract(String partId) {
assertEquals(2, coverage.getContract().size());
Coverage compare = new Coverage();
compare.addContract().setId("contract1");
compare.addContract().setReference("Coverage/" + partId + "-contract1");
assertTrue(compare.getContract().get(0).equalsDeep(coverage.getContract().get(0)));
assertTrue(compare.getContract().get(1).equalsDeep(coverage.getContract().get(1)));
}
use of org.hl7.fhir.r4.model.Coverage 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);
}
use of org.hl7.fhir.r4.model.Coverage in project beneficiary-fhir-data by CMSgov.
the class CoverageTransformerTest method transformSampleARecord.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.stu3.providers.CoverageTransformer#transform(MedicareSegment,
* Beneficiary)} works as expected when run against the {@link StaticRifResource#SAMPLE_A_CARRIER}
* {@link Beneficiary}.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void transformSampleARecord() throws FHIRException {
List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
Beneficiary beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
beneficiary.setLastUpdated(Instant.now());
Coverage partACoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_A, beneficiary);
assertPartAMatches(beneficiary, partACoverage);
Coverage partBCoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_B, beneficiary);
assertPartBMatches(beneficiary, partBCoverage);
Coverage partCCoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_C, beneficiary);
assertPartCMatches(beneficiary, partCCoverage);
Coverage partDCoverage = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_D, beneficiary);
assertPartDMatches(beneficiary, partDCoverage);
// Test with null lastUpdated
beneficiary.setLastUpdated(Optional.empty());
Coverage partACoverageNullLastUpdated = CoverageTransformer.transform(new MetricRegistry(), MedicareSegment.PART_A, beneficiary);
assertPartAMatches(beneficiary, partACoverageNullLastUpdated);
}
Aggregations