use of gov.cms.bfd.model.rif.RifRecordEvent in project beneficiary-fhir-data by CMSgov.
the class RifFilesProcessor method buildOutpatientClaimEvent.
/**
* @param fileEvent the {@link RifFileEvent} being processed that is being processed
* @param csvRecords the {@link CSVRecord}s to be mapped, which must be from a {@link
* RifFileType#OUTPATIENT} {@link RifFile}
* @return a {@link RifRecordEvent} built from the specified {@link CSVRecord}s
*/
private static RifRecordEvent<OutpatientClaim> buildOutpatientClaimEvent(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"));
OutpatientClaim claim = OutpatientClaimParser.parseRif(csvRecords);
return new RifRecordEvent<OutpatientClaim>(fileEvent, csvRecords, recordAction, claim.getBeneficiaryId(), claim);
}
use of gov.cms.bfd.model.rif.RifRecordEvent in project beneficiary-fhir-data by CMSgov.
the class RifFilesProcessor method produceRecords.
/**
* @param rifFileEvent the {@link RifFileEvent} that is being processed
* @return a {@link RifFileRecords} with the {@link RifRecordEvent}s produced from the specified
* {@link RifFileEvent}
*/
public RifFileRecords produceRecords(RifFileEvent rifFileEvent) {
RifFile file = rifFileEvent.getFile();
/*
* Approach used here to parse CSV as a Java 8 Stream is courtesy of
* https://rumianom.pl/rumianom/entry/apache-commons-csv-with-java.
*/
CSVParser parser = RifParsingUtils.createCsvParser(file);
boolean isGrouped;
BiFunction<RifFileEvent, List<CSVRecord>, RifRecordEvent<?>> recordParser;
if (file.getFileType() == RifFileType.BENEFICIARY) {
isGrouped = false;
recordParser = RifFilesProcessor::buildBeneficiaryEvent;
} else if (file.getFileType() == RifFileType.BENEFICIARY_HISTORY) {
isGrouped = false;
recordParser = RifFilesProcessor::buildBeneficiaryHistoryEvent;
} else if (file.getFileType() == RifFileType.MEDICARE_BENEFICIARY_ID_HISTORY) {
isGrouped = false;
recordParser = RifFilesProcessor::buildMedicareBeneficiaryIdHistoryEvent;
} else if (file.getFileType() == RifFileType.PDE) {
isGrouped = false;
recordParser = RifFilesProcessor::buildPartDEvent;
} else if (file.getFileType() == RifFileType.CARRIER) {
isGrouped = true;
recordParser = RifFilesProcessor::buildCarrierClaimEvent;
} else if (file.getFileType() == RifFileType.INPATIENT) {
isGrouped = true;
recordParser = RifFilesProcessor::buildInpatientClaimEvent;
} else if (file.getFileType() == RifFileType.OUTPATIENT) {
isGrouped = true;
recordParser = RifFilesProcessor::buildOutpatientClaimEvent;
} else if (file.getFileType() == RifFileType.SNF) {
isGrouped = true;
recordParser = RifFilesProcessor::buildSNFClaimEvent;
} else if (file.getFileType() == RifFileType.HOSPICE) {
isGrouped = true;
recordParser = RifFilesProcessor::buildHospiceClaimEvent;
} else if (file.getFileType() == RifFileType.HHA) {
isGrouped = true;
recordParser = RifFilesProcessor::buildHHAClaimEvent;
} else if (file.getFileType() == RifFileType.DME) {
isGrouped = true;
recordParser = RifFilesProcessor::buildDMEClaimEvent;
} else {
throw new UnsupportedRifFileTypeException("Unsupported file type:" + file.getFileType());
}
/*
* Use the CSVParser to drive a Stream of grouped CSVRecords
* (specifically, group by claim ID/lines).
*/
CsvRecordGrouper grouper = new ColumnValueCsvRecordGrouper(isGrouped ? file.getFileType().getIdColumn() : null);
Iterator<List<CSVRecord>> csvIterator = new CsvRecordGroupingIterator(parser, grouper);
Spliterator<List<CSVRecord>> spliterator = Spliterators.spliteratorUnknownSize(csvIterator, Spliterator.ORDERED | Spliterator.NONNULL);
Stream<List<CSVRecord>> csvRecordStream = StreamSupport.stream(spliterator, false).onClose(() -> {
try {
/*
* This will also close the Reader and InputStream that the
* CSVParser was consuming.
*/
parser.close();
} catch (IOException e) {
LOGGER.warn("Unable to close CSVParser", e);
}
});
/* Map each record group to a single RifRecordEvent. */
Stream<RifRecordEvent<?>> rifRecordStream = csvRecordStream.map(csvRecordGroup -> {
try {
Timer.Context parsingTimer = rifFileEvent.getEventMetrics().timer(MetricRegistry.name(getClass().getSimpleName(), "recordParsing")).time();
RifRecordEvent<?> recordEvent = recordParser.apply(rifFileEvent, csvRecordGroup);
parsingTimer.close();
return recordEvent;
} catch (InvalidRifValueException e) {
LOGGER.warn("Parse error encountered near line number '{}'.", csvRecordGroup.get(0).getRecordNumber());
throw new InvalidRifValueException(e);
}
});
return new RifFileRecords(rifFileEvent, rifRecordStream);
}
use of gov.cms.bfd.model.rif.RifRecordEvent in project beneficiary-fhir-data by CMSgov.
the class RifFilesProcessor method buildPartDEvent.
/**
* @param fileEvent the {@link RifFilesEvent} being processed
* @param csvRecords the {@link CSVRecord}s to be mapped, which must be from a {@link
* RifFileType#PDE} {@link RifFile}
* @return a {@link RifRecordEvent} built from the specified {@link CSVRecord}s
*/
private static RifRecordEvent<PartDEvent> buildPartDEvent(RifFileEvent fileEvent, List<CSVRecord> csvRecords) {
if (csvRecords.size() != 1)
throw new BadCodeMonkeyException();
if (LOGGER.isTraceEnabled())
LOGGER.trace(csvRecords.toString());
CSVRecord csvRecord = csvRecords.get(0);
RecordAction recordAction = RecordAction.match(csvRecord.get("DML_IND"));
PartDEvent partDEvent = PartDEventParser.parseRif(csvRecords);
return new RifRecordEvent<PartDEvent>(fileEvent, csvRecords, recordAction, partDEvent.getBeneficiaryId(), partDEvent);
}
use of gov.cms.bfd.model.rif.RifRecordEvent in project beneficiary-fhir-data by CMSgov.
the class RifFilesProcessor method buildSNFClaimEvent.
/**
* @param fileEvent the {@link RifFileEvent} being processed
* @param csvRecords the {@link CSVRecord}s to be mapped, which must be from a {@link
* RifFileType#SNF} {@link RifFile}
* @return a {@link RifRecordEvent} built from the specified {@link CSVRecord}s
*/
private static RifRecordEvent<SNFClaim> buildSNFClaimEvent(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"));
SNFClaim claim = SNFClaimParser.parseRif(csvRecords);
return new RifRecordEvent<SNFClaim>(fileEvent, csvRecords, recordAction, claim.getBeneficiaryId(), claim);
}
use of gov.cms.bfd.model.rif.RifRecordEvent in project beneficiary-fhir-data by CMSgov.
the class RifFilesProcessor method buildInpatientClaimEvent.
/**
* @param fileEvent the {@link RifFileEvent} being processed that is being processed
* @param csvRecords the {@link CSVRecord}s to be mapped, which must be from a {@link
* RifFileType#INPATIENT} {@link RifFile}
* @return a {@link RifRecordEvent} built from the specified {@link CSVRecord}s
*/
private static RifRecordEvent<InpatientClaim> buildInpatientClaimEvent(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"));
InpatientClaim claim = InpatientClaimParser.parseRif(csvRecords);
return new RifRecordEvent<InpatientClaim>(fileEvent, csvRecords, recordAction, claim.getBeneficiaryId(), claim);
}
Aggregations