Search in sources :

Example 26 with RifRecordEvent

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

the class RifFilesProcessor method buildCarrierClaimEvent.

/**
 * @param fileEvent the {@link RifFileEvent} being processed
 * @param csvRecords the {@link CSVRecord}s to be mapped, which must be from a {@link
 *     RifFileType#CARRIER} {@link RifFile}
 * @return a {@link RifRecordEvent} built from the specified {@link CSVRecord}s
 */
private static RifRecordEvent<CarrierClaim> buildCarrierClaimEvent(RifFileEvent fileEvent, List<CSVRecord> csvRecords) {
    if (LOGGER.isTraceEnabled())
        LOGGER.trace(csvRecords.toString());
    CSVRecord firstCsvRecord = csvRecords.get(0);
    RecordAction recordAction = RecordAction.match(firstCsvRecord.get("DML_IND"));
    CarrierClaim claim = CarrierClaimParser.parseRif(csvRecords);
    return new RifRecordEvent<CarrierClaim>(fileEvent, csvRecords, recordAction, claim.getBeneficiaryId(), claim);
}
Also used : RifRecordEvent(gov.cms.bfd.model.rif.RifRecordEvent) CSVRecord(org.apache.commons.csv.CSVRecord) RecordAction(gov.cms.bfd.model.rif.RecordAction) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim)

Example 27 with RifRecordEvent

use of gov.cms.bfd.model.rif.RifRecordEvent 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

RifRecordEvent (gov.cms.bfd.model.rif.RifRecordEvent)27 RifFileRecords (gov.cms.bfd.model.rif.RifFileRecords)16 RifFilesEvent (gov.cms.bfd.model.rif.RifFilesEvent)15 CSVRecord (org.apache.commons.csv.CSVRecord)14 RecordAction (gov.cms.bfd.model.rif.RecordAction)13 Test (org.junit.jupiter.api.Test)13 BigDecimal (java.math.BigDecimal)11 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)6 BadCodeMonkeyException (gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException)6 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)5 CarrierClaim (gov.cms.bfd.model.rif.CarrierClaim)5 CarrierClaimLine (gov.cms.bfd.model.rif.CarrierClaimLine)4 RifFileEvent (gov.cms.bfd.model.rif.RifFileEvent)4 IOException (java.io.IOException)4 List (java.util.List)4 BeneficiaryMonthly (gov.cms.bfd.model.rif.BeneficiaryMonthly)3 LoadedBatch (gov.cms.bfd.model.rif.LoadedBatch)3 LoadedFile (gov.cms.bfd.model.rif.LoadedFile)3 RifFileType (gov.cms.bfd.model.rif.RifFileType)3 SkippedRifRecord (gov.cms.bfd.model.rif.SkippedRifRecord)3