use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PATIENT in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientWithOddPaging.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with paging. This test uses a count of 3 to verify
* our code will not run into an IndexOutOfBoundsException on even bundle sizes.
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsByExistingPatientWithOddPaging() 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(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).count(3).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(3, searchResults.getEntry().size());
/*
* Verify that accessing all next links, eventually leading to the last page,
* will not encounter an IndexOutOfBoundsException.
*/
while (searchResults.getLink(Constants.LINK_NEXT) != null) {
searchResults = fhirClient.loadPage().next(searchResults).execute();
assertNotNull(searchResults);
assertTrue(searchResults.hasEntry());
}
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PATIENT in project beneficiary-fhir-data by CMSgov.
the class ExplanationOfBenefitResourceProviderIT method searchForEobsByExistingPatientWithPageSizeNotProvided.
/**
* Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient} works as expected for
* a {@link Patient} that does exist in the DB, with paging, providing the startIndex but not the
* pageSize (count).
*
* @throws FHIRException (indicates test failure)
*/
@Test
public void searchForEobsByExistingPatientWithPageSizeNotProvided() 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(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
/*
* Verify that no paging links exist in the bundle.
*/
assertNull(searchResults.getLink(Constants.LINK_NEXT));
assertNull(searchResults.getLink(Constants.LINK_PREVIOUS));
assertNull(searchResults.getLink(Constants.LINK_FIRST));
assertNull(searchResults.getLink(Constants.LINK_LAST));
/*
* Access a created link of this bundle, providing the startIndex but not the
* pageSize (count).
*/
Bundle pagedResults = fhirClient.loadPage().byUrl(searchResults.getLink(Bundle.LINK_SELF).getUrl() + "&startIndex=4").andReturnBundle(Bundle.class).execute();
assertNotNull(pagedResults);
/*
* Verify that paging links exist in this paged bundle.
*/
assertNull(pagedResults.getLink(Constants.LINK_NEXT));
assertNotNull(pagedResults.getLink(Constants.LINK_PREVIOUS));
assertNotNull(pagedResults.getLink(Constants.LINK_FIRST));
assertNotNull(pagedResults.getLink(Constants.LINK_LAST));
/*
* Add the entries in the paged results to a list and verify that only the last
* 4 entries in the original searchResults were returned in the pagedResults.
*/
List<IBaseResource> pagedEntries = new ArrayList<>();
pagedResults.getEntry().forEach(e -> pagedEntries.add(e.getResource()));
assertEquals(4, pagedEntries.size());
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PATIENT in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProviderIT method searchForExistingPatientByPartDContractNumIncludeIdentifiersFalse.
@Test
public void searchForExistingPatientByPartDContractNumIncludeIdentifiersFalse() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES));
IGenericClient fhirClient = createFhirClient("mbi, false", "true");
// Should return a single match
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(new TokenClientParam("_has:Coverage.extension").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.PTDCNTRCT01), "S4607")).where(new TokenClientParam("_has:Coverage.rfrncyr").exactly().systemAndIdentifier(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.RFRNC_YR), "2018")).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(1, searchResults.getEntry().size());
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
Beneficiary expectedBene = (Beneficiary) loadedRecords.get(0);
assertEquals(expectedBene.getBeneficiaryId(), patientFromSearchResult.getIdElement().getIdPart());
/*
* Ensure the unhashed values for MBI is present.
*/
Boolean mbiUnhashedPresent = false;
Iterator<Identifier> identifiers = patientFromSearchResult.getIdentifier().iterator();
while (identifiers.hasNext()) {
Identifier identifier = identifiers.next();
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED)) {
mbiUnhashedPresent = true;
}
}
assertTrue(mbiUnhashedPresent);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PATIENT in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProviderIT method searchForExistingPatientByHistoricalMbiHash.
/**
* Verifies that {@link
* gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
* works as expected for MBIs that should be present as a {@link BeneficiaryHistory} record.
*/
@Test
public void searchForExistingPatientByHistoricalMbiHash() {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
loadedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r).forEach(h -> {
Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, h.getMbiHash().get())).returnBundle(Bundle.class).execute();
assertNotNull(searchResults);
assertEquals(1, searchResults.getTotal());
Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
assertEquals(h.getBeneficiaryId(), patientFromSearchResult.getIdElement().getIdPart());
});
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PATIENT in project beneficiary-fhir-data by CMSgov.
the class R4PatientResourceProviderIT method assertExistingPatientIncludeIdentifiersExpected.
/**
* Asserts that {@link
* gov.cms.bfd.server.war.r4.providers.R4PatientResourceProvider#read(org.hl7.fhir.r4.model.IdType)}
* contains expected/present identifiers for a {@link Patient}.
*
* @param includeIdentifiersValue header value
* @param expectingMbi true if expecting a MBI
* @param includeAddressValues header value
*/
public void assertExistingPatientIncludeIdentifiersExpected(boolean expectingMbi, RequestHeaders requestHeader) {
List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
Patient expected = BeneficiaryTransformerV2.transform(PipelineTestUtils.get().getPipelineApplicationState().getMetrics(), beneficiary, requestHeader);
IGenericClient fhirClient = createFhirClient(requestHeader);
Patient patient = fhirClient.read().resource(Patient.class).withId(beneficiary.getBeneficiaryId()).execute();
// Because of how transform doesn't go through R4PatientResourceProvider, `expected` won't have
// the historical MBI data.
// Also, SAMPLE_A does not have mbi history (it used to); however, what used to be denoted as
// historical
// is not provided as the 'current' MBI identifier (no historical).
comparePatient(expected, patient);
/*
* Ensure the unhashed values for MBI are present.
*/
Boolean mbiUnhashedPresent = false;
Iterator<Identifier> identifiers = patient.getIdentifier().iterator();
while (identifiers.hasNext()) {
Identifier identifier = identifiers.next();
if (identifier.getSystem().equals(TransformerConstants.CODING_BBAPI_BENE_ID)) {
mbiUnhashedPresent = true;
}
}
// Unhashed MBI should always be present in V2
assertTrue(mbiUnhashedPresent);
}
Aggregations