Search in sources :

Example 1 with StaticRifResourceGroup

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

the class BeneficiaryTransformerTest method loadSampleABeneficiary.

/**
 * @return the {@link StaticRifResourceGroup#SAMPLE_A} {@link Beneficiary} record, with the {@link
 *     Beneficiary#getBeneficiaryHistories()} and {@link
 *     Beneficiary#getMedicareBeneficiaryIdHistories()} fields populated.
 */
private static Beneficiary loadSampleABeneficiary() {
    List<Object> parsedRecords = ServerTestUtils.parseData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    // Pull out the base Beneficiary record and fix its HICN and MBI-HASH fields.
    Beneficiary beneficiary = parsedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    beneficiary.setHicn("someHICNhash");
    beneficiary.setMbiHash(Optional.of("someMBIhash"));
    // Add the HICN history records to the Beneficiary, and fix their HICN fields.
    Set<BeneficiaryHistory> beneficiaryHistories = parsedRecords.stream().filter(r -> r instanceof BeneficiaryHistory).map(r -> (BeneficiaryHistory) r).filter(r -> beneficiary.getBeneficiaryId().equals(r.getBeneficiaryId())).collect(Collectors.toSet());
    beneficiary.getBeneficiaryHistories().addAll(beneficiaryHistories);
    for (BeneficiaryHistory beneficiaryHistory : beneficiary.getBeneficiaryHistories()) {
        beneficiaryHistory.setHicnUnhashed(Optional.of(beneficiaryHistory.getHicn()));
        beneficiaryHistory.setHicn("someHICNhash");
    }
    // Add the MBI history records to the Beneficiary.
    Set<MedicareBeneficiaryIdHistory> beneficiaryMbis = parsedRecords.stream().filter(r -> r instanceof MedicareBeneficiaryIdHistory).map(r -> (MedicareBeneficiaryIdHistory) r).filter(r -> beneficiary.getBeneficiaryId().equals(r.getBeneficiaryId().orElse(null))).collect(Collectors.toSet());
    beneficiary.getMedicareBeneficiaryIdHistories().addAll(beneficiaryMbis);
    return beneficiary;
}
Also used : SkippedRifRecord(gov.cms.bfd.model.rif.SkippedRifRecord) Arrays(java.util.Arrays) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) Identifier(org.hl7.fhir.dstu3.model.Identifier) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) Sex(gov.cms.bfd.server.war.commons.Sex) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) MetricRegistry(com.codahale.metrics.MetricRegistry) Set(java.util.Set) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Patient(org.hl7.fhir.dstu3.model.Patient) Optional(java.util.Optional) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) Beneficiary(gov.cms.bfd.model.rif.Beneficiary)

Example 2 with StaticRifResourceGroup

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

the class RifLoaderIT method failOnUpdateBeneficiaryBeforeInsert.

/**
 * Runs {@link RifLoader} against the {@link StaticRifResourceGroup#SAMPLE_A} data for an <code>
 * UPDATE</code> {@link Beneficiary} record that there hasn't been a previous <code>INSERT</code>
 * on, to verify that this fails as expected.
 */
@Test
public void failOnUpdateBeneficiaryBeforeInsert() {
    // Tweak the SAMPLE_A beneficiary to be an UPDATE.
    Stream<RifFile> samplesStream = filterSamples(r -> r.getFileType() == RifFileType.BENEFICIARY, StaticRifResourceGroup.SAMPLE_A.getResources());
    Function<RifRecordEvent<?>, List<List<String>>> recordEditor = rifRecordEvent -> {
        CSVRecord beneCsvRow = rifRecordEvent.getRawCsvRecords().get(0);
        List<String> beneCsvValues = StreamSupport.stream(beneCsvRow.spliterator(), false).collect(Collectors.toList());
        beneCsvValues.set(0, "UPDATE");
        return List.of(beneCsvValues);
    };
    Function<RifFile, RifFile> fileEditor = sample -> editSampleRecords(sample, recordEditor);
    Stream<RifFile> editedSample = editSamples(samplesStream, fileEditor);
    // Load the edited sample to verify that it fails, as expected.
    AssertionFailedError thrown = assertThrows(AssertionFailedError.class, () -> {
        loadSample("SAMPLE_A, bene only, UPDATE", CcwRifLoadTestUtils.getLoadOptions(), editedSample);
    });
    assertTrue(thrown.getMessage().contains("Load errors encountered"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) RifFileType(gov.cms.bfd.model.rif.RifFileType) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) CSVRecord(org.apache.commons.csv.CSVRecord) LoggerFactory(org.slf4j.LoggerFactory) IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) Disabled(org.junit.jupiter.api.Disabled) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CSVFormat(org.apache.commons.csv.CSVFormat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertionFailedError(org.opentest4j.AssertionFailedError) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) Path(java.nio.file.Path) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Predicate(java.util.function.Predicate) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFile(gov.cms.bfd.model.rif.RifFile) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BeneficiaryMonthly(gov.cms.bfd.model.rif.BeneficiaryMonthly) TestInfo(org.junit.jupiter.api.TestInfo) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) LoadedBatch(gov.cms.bfd.model.rif.LoadedBatch) List(java.util.List) BeneficiaryHistory_(gov.cms.bfd.model.rif.BeneficiaryHistory_) Stream(java.util.stream.Stream) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) LocalDate(java.time.LocalDate) Slf4jReporter(com.codahale.metrics.Slf4jReporter) LoadedFile(gov.cms.bfd.model.rif.LoadedFile) Optional(java.util.Optional) RifParsingUtils(gov.cms.bfd.model.rif.parse.RifParsingUtils) BeneficiaryColumn(gov.cms.bfd.model.rif.BeneficiaryColumn) RifRecordEvent(gov.cms.bfd.model.rif.RifRecordEvent) CSVPrinter(org.apache.commons.csv.CSVPrinter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) SkippedRifRecord(gov.cms.bfd.model.rif.SkippedRifRecord) LocalRifFile(gov.cms.bfd.pipeline.ccw.rif.extract.LocalRifFile) Function(java.util.function.Function) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) StreamSupport(java.util.stream.StreamSupport) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) Root(javax.persistence.criteria.Root) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Month(java.time.Month) FileWriter(java.io.FileWriter) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) EntityTransaction(javax.persistence.EntityTransaction) RifFile(gov.cms.bfd.model.rif.RifFile) LocalRifFile(gov.cms.bfd.pipeline.ccw.rif.extract.LocalRifFile) RifRecordEvent(gov.cms.bfd.model.rif.RifRecordEvent) List(java.util.List) CSVRecord(org.apache.commons.csv.CSVRecord) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Aggregations

Beneficiary (gov.cms.bfd.model.rif.Beneficiary)2 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)2 SkippedRifRecord (gov.cms.bfd.model.rif.SkippedRifRecord)2 StaticRifResource (gov.cms.bfd.model.rif.samples.StaticRifResource)2 StaticRifResourceGroup (gov.cms.bfd.model.rif.samples.StaticRifResourceGroup)2 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Test (org.junit.jupiter.api.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Slf4jReporter (com.codahale.metrics.Slf4jReporter)1 CcwCodebookVariable (gov.cms.bfd.model.codebook.data.CcwCodebookVariable)1 BeneficiaryColumn (gov.cms.bfd.model.rif.BeneficiaryColumn)1 BeneficiaryHistory_ (gov.cms.bfd.model.rif.BeneficiaryHistory_)1 BeneficiaryMonthly (gov.cms.bfd.model.rif.BeneficiaryMonthly)1 CarrierClaim (gov.cms.bfd.model.rif.CarrierClaim)1 CarrierClaimLine (gov.cms.bfd.model.rif.CarrierClaimLine)1