Search in sources :

Example 36 with BeneficiaryHistory

use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProviderIT method searchForExistingPatientByMbiWithNoHistory.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.PatientResourceProvider#searchByIdentifier(ca.uhn.fhir.rest.param.TokenParam)}
 * works as expected for MBIs associated with {@link Beneficiary}s that have <strong>no</strong>
 * {@link BeneficiaryHistory} records.
 */
@Test
public void searchForExistingPatientByMbiWithNoHistory() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResource.SAMPLE_A_BENES));
    IGenericClient fhirClient = createFhirClient();
    loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) 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());
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) Identifier(org.hl7.fhir.dstu3.model.Identifier) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BeneficiaryMonthly_(gov.cms.bfd.model.rif.BeneficiaryMonthly_) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) Year(java.time.Year) Patient(org.hl7.fhir.dstu3.model.Patient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle) Patient(org.hl7.fhir.dstu3.model.Patient) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 37 with BeneficiaryHistory

use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProviderIT method searchForExistingPatientByMbiHashWithBeneDups.

/**
 * Verifies that the correct bene id or exception is returned when an MBI points to more than one
 * bene id in either the Beneficiaries and/or BeneficiariesHistory table.
 */
@Test
public void searchForExistingPatientByMbiHashWithBeneDups() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    // load additional Beneficiary and Beneficiary History records for
    // testing
    loadedRecords.addAll(ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_HICN_MULT_BENES.getResources())));
    IGenericClient fhirClient = createFhirClient();
    Stream<Beneficiary> beneficiariesStream = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r);
    List<Beneficiary> beneficiariesList = beneficiariesStream.collect(Collectors.toList());
    Stream<BeneficiaryHistory> beneficiariesHistoryStream = loadedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r);
    List<BeneficiaryHistory> beneficiariesHistoryList = beneficiariesHistoryStream.collect(Collectors.toList());
    boolean useMbiFromBeneficiaryTable;
    boolean expectsSingleBeneMatch;
    /*
     * The following scenario tests when the same mbi is in the
     * Beneficiaries table but points to different bene ids.
     */
    useMbiFromBeneficiaryTable = true;
    expectsSingleBeneMatch = false;
    assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "567834", "3456789", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
    /*
     * The following scenario tests when only one mbi is in the
     * Beneficiaries table.
     */
    useMbiFromBeneficiaryTable = true;
    expectsSingleBeneMatch = true;
    assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "123456NULLREFYR", "3456789N", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
    /*
     * The following scenario tests when the same mbi is in the
     * Beneficiaries and also in the BeneficiariesHistory table. The bene id
     * is different between the tables so the bene record from the
     * Beneficiaries table should be used.
     *
     * bene id=BENE1234 mbi=SAMEMBI rfrnc_yr=2019 should be pulled back.
     */
    useMbiFromBeneficiaryTable = true;
    expectsSingleBeneMatch = false;
    assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "BENE1234", "SAMEMBI", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
    /*
     * The following scenario tests when the requested mbi is only in the
     * BeneficiariesHistory table. Use the bene id from the
     * BeneficiariesHistory table to then read the Beneficiaries table.
     */
    useMbiFromBeneficiaryTable = false;
    expectsSingleBeneMatch = true;
    assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "55555", "HISTMBI", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
    /*
     * The following scenario tests when the requested mbi is only in the
     * BeneficiariesHistory table but this mbi points to more than one bene
     * id in history.
     */
    useMbiFromBeneficiaryTable = false;
    expectsSingleBeneMatch = false;
    assertPatientByHashTypeMatch(fhirClient, beneficiariesList, beneficiariesHistoryList, "66666", "DUPHISTMBI", useMbiFromBeneficiaryTable, "mbi", expectsSingleBeneMatch);
    /*
     * The following scenario tests when a mbi is not found in the
     * Beneficiaries and BeneficiariesHistory table.
     *
     */
    Bundle searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, "notfoundmbi")).returnBundle(Bundle.class).execute();
    assertEquals(0, searchResults.getTotal());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) Identifier(org.hl7.fhir.dstu3.model.Identifier) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BeneficiaryMonthly_(gov.cms.bfd.model.rif.BeneficiaryMonthly_) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) Year(java.time.Year) Patient(org.hl7.fhir.dstu3.model.Patient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle) Patient(org.hl7.fhir.dstu3.model.Patient) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 38 with BeneficiaryHistory

use of gov.cms.bfd.model.rif.BeneficiaryHistory in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProviderIT method assertPatientByHashTypeMatch.

/**
 * The following method tests that a ResourceNotFoundException exception is thrown when there are
 * instances of one hash value (hicn or mbi) pointing to more than bene id between the
 * Beneficiaries and BeneficiariesHistory tables.
 *
 * <p>Or that single match is found when the expectsSingleBeneMatch param is = true.
 *
 * <p>The hashType param chooses which type of values/hash to use. This is either "hicn" or "mbi".
 *
 * @param fhirClient
 * @param beneficiariesList
 * @param beneficiariesHistoryList
 * @param beneficiaryId
 * @param unhashedValue
 * @param useFromBeneficiaryTable
 * @param hashType
 * @param expectsSingleBeneMatch
 */
private void assertPatientByHashTypeMatch(IGenericClient fhirClient, List<Beneficiary> beneficiariesList, List<BeneficiaryHistory> beneficiariesHistoryList, String beneficiaryId, String unhashedValue, Boolean useFromBeneficiaryTable, String hashType, Boolean expectsSingleBeneMatch) {
    Bundle searchResults = null;
    String hicnHashed = "";
    String mbiHash = "";
    if (hashType != "hicn" && hashType != "mbi") {
        fail("hashType value must be: hicn or mbi.");
    }
    if (useFromBeneficiaryTable) {
        if (hashType.equals("hicn")) {
            Beneficiary beneficiaryHicnToMatchTo = beneficiariesList.stream().filter(r -> unhashedValue.equals(r.getHicnUnhashed().get())).findFirst().get();
            hicnHashed = beneficiaryHicnToMatchTo.getHicn();
        } else if (hashType.equals("mbi")) {
            Beneficiary beneficiaryMbiToMatchTo = beneficiariesList.stream().filter(r -> unhashedValue.equals(r.getMedicareBeneficiaryId().get())).findFirst().get();
            mbiHash = beneficiaryMbiToMatchTo.getMbiHash().get();
        }
    } else {
        if (hashType.equals("hicn")) {
            BeneficiaryHistory beneficiaryHistoryHicnToMatchTo = beneficiariesHistoryList.stream().filter(r -> unhashedValue.equals(r.getHicnUnhashed().get())).findFirst().get();
            hicnHashed = beneficiaryHistoryHicnToMatchTo.getHicn();
        } else if (hashType.equals("mbi")) {
            BeneficiaryHistory beneficiaryHistoryMbiToMatchTo = beneficiariesHistoryList.stream().filter(r -> unhashedValue.equals(r.getMedicareBeneficiaryId().get())).findFirst().get();
            mbiHash = beneficiaryHistoryMbiToMatchTo.getMbiHash().get();
        }
    }
    try {
        // return bene record based on unhashedValue passed to this method
        if (hashType.equals("hicn")) {
            searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_HICN_HASH, hicnHashed)).returnBundle(Bundle.class).execute();
        } else if (hashType.equals("mbi")) {
            searchResults = fhirClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndIdentifier(TransformerConstants.CODING_BBAPI_BENE_MBI_HASH, mbiHash)).returnBundle(Bundle.class).execute();
        }
        if (!expectsSingleBeneMatch) {
            // Should throw exception before here, so assert a failed test.
            fail("An exception was expected when there are duplicate bene id matches.");
        }
    } catch (ResourceNotFoundException e) {
    // Test passes if an exception was thrown.
    }
    // Validate result if a single match is expected for test.
    if (expectsSingleBeneMatch) {
        assertNotNull(searchResults);
        assertEquals(1, searchResults.getTotal());
        Beneficiary beneficiary = beneficiariesList.stream().filter(r -> beneficiaryId.equals(r.getBeneficiaryId())).findAny().get();
        Patient patientFromSearchResult = (Patient) searchResults.getEntry().get(0).getResource();
        BeneficiaryTransformerTest.assertMatches(beneficiary, patientFromSearchResult, getRHwithIncldAddrFldHdr("false"));
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Date(java.util.Date) Identifier(org.hl7.fhir.dstu3.model.Identifier) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) BeforeAll(org.junit.jupiter.api.BeforeAll) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Iterator(java.util.Iterator) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) BeneficiaryMonthly_(gov.cms.bfd.model.rif.BeneficiaryMonthly_) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Stream(java.util.stream.Stream) Year(java.time.Year) Patient(org.hl7.fhir.dstu3.model.Patient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Bundle(org.hl7.fhir.dstu3.model.Bundle) Patient(org.hl7.fhir.dstu3.model.Patient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Beneficiary(gov.cms.bfd.model.rif.Beneficiary)

Aggregations

BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)38 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)30 Test (org.junit.jupiter.api.Test)29 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)27 MedicareBeneficiaryIdHistory (gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory)27 StaticRifResourceGroup (gov.cms.bfd.model.rif.samples.StaticRifResourceGroup)26 ServerTestUtils (gov.cms.bfd.server.war.ServerTestUtils)26 RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)26 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)26 Instant (java.time.Instant)26 Arrays (java.util.Arrays)26 List (java.util.List)26 Collectors (java.util.stream.Collectors)26 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)26 Date (java.util.Date)25 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)25 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)25 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)25 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)24 Constants (ca.uhn.fhir.rest.api.Constants)24