Search in sources :

Example 1 with RifFilesProcessor

use of gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor in project beneficiary-fhir-data by CMSgov.

the class RifLoaderIT method loadSample.

/**
 * Runs {@link RifLoader} against the specified {@link StaticRifResourceGroup}.
 *
 * @param sampleName a human-friendly name that will be logged to identify the data load being
 *     kicked off here
 * @param options the {@link LoadAppOptions} to use
 * @param rifFilesEvent the {@link RifFilesEvent} to load
 * @return the number of RIF records that were loaded (as reported by the {@link RifLoader})
 */
private int loadSample(String sampleName, LoadAppOptions options, RifFilesEvent rifFilesEvent) {
    LOGGER.info("Loading RIF files: '{}'...", sampleName);
    // Create the processors that will handle each stage of the pipeline.
    RifFilesProcessor processor = new RifFilesProcessor();
    RifLoader loader = new RifLoader(options, PipelineTestUtils.get().getPipelineApplicationState());
    // Link up the pipeline and run it.
    LOGGER.info("Loading RIF records...");
    AtomicInteger failureCount = new AtomicInteger(0);
    AtomicInteger loadCount = new AtomicInteger(0);
    for (RifFileEvent rifFileEvent : rifFilesEvent.getFileEvents()) {
        RifFileRecords rifFileRecords = processor.produceRecords(rifFileEvent);
        loader.process(rifFileRecords, error -> {
            failureCount.incrementAndGet();
            LOGGER.warn("Record(s) failed to load.", error);
        }, result -> {
            loadCount.incrementAndGet();
        });
        Slf4jReporter.forRegistry(rifFileEvent.getEventMetrics()).outputTo(LOGGER).build().report();
    }
    LOGGER.info("Loaded RIF files: '{}', record count: '{}'.", sampleName, loadCount.get());
    Slf4jReporter.forRegistry(PipelineTestUtils.get().getPipelineApplicationState().getMetrics()).outputTo(LOGGER).build().report();
    // Verify that the expected number of records were run successfully.
    assertEquals(0, failureCount.get(), "Load errors encountered.");
    return loadCount.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor)

Example 2 with RifFilesProcessor

use of gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor in project beneficiary-fhir-data by CMSgov.

the class PipelineApplication method createCcwRifLoadJob.

/**
 * @param loadOptions the {@link CcwRifLoadOptions} to use
 * @param appState the {@link PipelineApplicationState} to use
 * @return a {@link CcwRifLoadJob} instance for the application to use
 */
private static PipelineJob<?> createCcwRifLoadJob(CcwRifLoadOptions loadOptions, PipelineApplicationState appState) {
    /*
     * Create the services that will be used to handle each stage in the extract, transform, and
     * load process.
     */
    S3TaskManager s3TaskManager = new S3TaskManager(appState.getMetrics(), loadOptions.getExtractionOptions());
    RifFilesProcessor rifProcessor = new RifFilesProcessor();
    RifLoader rifLoader = new RifLoader(loadOptions.getLoadOptions(), appState);
    /*
     * Create the DataSetMonitorListener that will glue those stages together and run them all for
     * each data set that is found.
     */
    DataSetMonitorListener dataSetMonitorListener = new DefaultDataSetMonitorListener(appState.getMetrics(), PipelineApplication::handleUncaughtException, rifProcessor, rifLoader);
    CcwRifLoadJob ccwRifLoadJob = new CcwRifLoadJob(appState.getMetrics(), loadOptions.getExtractionOptions(), s3TaskManager, dataSetMonitorListener);
    return ccwRifLoadJob;
}
Also used : S3TaskManager(gov.cms.bfd.pipeline.ccw.rif.extract.s3.task.S3TaskManager) DataSetMonitorListener(gov.cms.bfd.pipeline.ccw.rif.extract.s3.DataSetMonitorListener) CcwRifLoadJob(gov.cms.bfd.pipeline.ccw.rif.CcwRifLoadJob) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor) RifLoader(gov.cms.bfd.pipeline.ccw.rif.load.RifLoader)

Example 3 with RifFilesProcessor

use of gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor in project beneficiary-fhir-data by CMSgov.

the class LoadedFilterManagerIT method loadData.

/**
 * @param sampleResources the sample RIF resources to load
 */
private static void loadData(DataSource dataSource, List<StaticRifResource> sampleResources) {
    LoadAppOptions loadOptions = CcwRifLoadTestUtils.getLoadOptions();
    RifFilesEvent rifFilesEvent = new RifFilesEvent(Instant.now(), sampleResources.stream().map(StaticRifResource::toRifFile).collect(Collectors.toList()));
    // Create the processors that will handle each stage of the pipeline.
    RifFilesProcessor processor = new RifFilesProcessor();
    RifLoader loader = new RifLoader(loadOptions, PipelineTestUtils.get().getPipelineApplicationState());
    // Link up the pipeline and run it.
    for (RifFileEvent rifFileEvent : rifFilesEvent.getFileEvents()) {
        RifFileRecords rifFileRecords = processor.produceRecords(rifFileEvent);
        loader.process(rifFileRecords, error -> {
        }, result -> {
        });
    }
}
Also used : LoadAppOptions(gov.cms.bfd.pipeline.ccw.rif.load.LoadAppOptions) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor) RifLoader(gov.cms.bfd.pipeline.ccw.rif.load.RifLoader)

Example 4 with RifFilesProcessor

use of gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor in project beneficiary-fhir-data by CMSgov.

the class ServerTestUtils method loadData.

/**
 * @param sampleResources the sample RIF resources to load
 * @return the {@link List} of RIF records that were loaded (e.g. {@link Beneficiary}s, etc.)
 */
public List<Object> loadData(List<StaticRifResource> sampleResources) {
    LoadAppOptions loadOptions = CcwRifLoadTestUtils.getLoadOptions();
    RifFilesEvent rifFilesEvent = new RifFilesEvent(Instant.now(), sampleResources.stream().map(r -> r.toRifFile()).collect(Collectors.toList()));
    // Create the processors that will handle each stage of the pipeline.
    RifFilesProcessor processor = new RifFilesProcessor();
    // Link up the pipeline and run it.
    RifLoader loader = new RifLoader(loadOptions, PipelineTestUtils.get().getPipelineApplicationState());
    LOGGER.info("Loading RIF records...");
    List<Object> recordsLoaded = new ArrayList<>();
    for (RifFileEvent rifFileEvent : rifFilesEvent.getFileEvents()) {
        RifFileRecords rifFileRecords = processor.produceRecords(rifFileEvent);
        loader.process(rifFileRecords, error -> {
            LOGGER.warn("Record(s) failed to load.", error);
        }, result -> {
            recordsLoaded.add(result.getRifRecordEvent().getRecord());
        });
    }
    LOGGER.info("Loaded RIF records: '{}'.", recordsLoaded.size());
    return recordsLoaded;
}
Also used : LoadAppOptions(gov.cms.bfd.pipeline.ccw.rif.load.LoadAppOptions) ArrayList(java.util.ArrayList) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor) RifLoader(gov.cms.bfd.pipeline.ccw.rif.load.RifLoader)

Example 5 with RifFilesProcessor

use of gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor in project beneficiary-fhir-data by CMSgov.

the class ServerTestUtils method parseData.

/**
 * @param sampleResources the sample RIF resources to parse
 * @return the {@link List} of RIF records that were parsed (e.g. {@link Beneficiary}s, etc.)
 */
public static List<Object> parseData(List<StaticRifResource> sampleResources) {
    RifFilesEvent rifFilesEvent = new RifFilesEvent(Instant.now(), sampleResources.stream().map(r -> r.toRifFile()).collect(Collectors.toList()));
    RifFilesProcessor processor = new RifFilesProcessor();
    List<Object> recordsParsed = new ArrayList<>();
    for (RifFileEvent rifFileEvent : rifFilesEvent.getFileEvents()) {
        RifFileRecords rifFileRecords = processor.produceRecords(rifFileEvent);
        rifFileRecords.getRecords().map(r -> r.getRecord()).forEach(r -> recordsParsed.add(r));
    }
    return recordsParsed;
}
Also used : SSLContext(javax.net.ssl.SSLContext) StaticRifResource(gov.cms.bfd.model.rif.samples.StaticRifResource) LoggerFactory(org.slf4j.LoggerFactory) KeyStoreException(java.security.KeyStoreException) RequestConfig(org.apache.http.client.config.RequestConfig) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor) FhirContext(ca.uhn.fhir.context.FhirContext) Duration(java.time.Duration) SSLContexts(org.apache.http.ssl.SSLContexts) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) CcwRifLoadTestUtils(gov.cms.bfd.pipeline.ccw.rif.load.CcwRifLoadTestUtils) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Path(java.nio.file.Path) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) KeyManagementException(java.security.KeyManagementException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) UncheckedIOException(java.io.UncheckedIOException) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) Optional(java.util.Optional) HttpClients(org.apache.http.impl.client.HttpClients) RegistryBuilder(org.apache.http.config.RegistryBuilder) LoadAppOptions(gov.cms.bfd.pipeline.ccw.rif.load.LoadAppOptions) ExtraParamsInterceptor(gov.cms.bfd.server.war.stu3.providers.ExtraParamsInterceptor) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) ArrayList(java.util.ArrayList) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) HttpClient(org.apache.http.client.HttpClient) UnrecoverableKeyException(java.security.UnrecoverableKeyException) MBeanServer(javax.management.MBeanServer) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ManagementFactory(java.lang.management.ManagementFactory) RifLoader(gov.cms.bfd.pipeline.ccw.rif.load.RifLoader) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) Properties(java.util.Properties) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) EntityManager(javax.persistence.EntityManager) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LoggingInterceptor(ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) EntityTransaction(javax.persistence.EntityTransaction) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) RifFileEvent(gov.cms.bfd.model.rif.RifFileEvent) RifFileRecords(gov.cms.bfd.model.rif.RifFileRecords) RifFilesEvent(gov.cms.bfd.model.rif.RifFilesEvent) RifFilesProcessor(gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor)

Aggregations

RifFilesProcessor (gov.cms.bfd.pipeline.ccw.rif.extract.RifFilesProcessor)7 RifFileEvent (gov.cms.bfd.model.rif.RifFileEvent)6 RifFileRecords (gov.cms.bfd.model.rif.RifFileRecords)6 RifFilesEvent (gov.cms.bfd.model.rif.RifFilesEvent)5 RifLoader (gov.cms.bfd.pipeline.ccw.rif.load.RifLoader)4 StaticRifResource (gov.cms.bfd.model.rif.samples.StaticRifResource)3 LoadAppOptions (gov.cms.bfd.pipeline.ccw.rif.load.LoadAppOptions)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 Path (java.nio.file.Path)3 List (java.util.List)3 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)2 LocalRifFile (gov.cms.bfd.pipeline.ccw.rif.extract.LocalRifFile)2 PipelineTestUtils (gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils)2 FileWriter (java.io.FileWriter)2 Files (java.nio.file.Files)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2