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;
}
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"));
}
Aggregations