Search in sources :

Example 1 with BeneficiaryData

use of gov.cms.bfd.pipeline.bridge.model.BeneficiaryData in project beneficiary-fhir-data by CMSgov.

the class RDABridge method run.

/**
 * Reads all relevant source files, executing task logic for each claim found.
 *
 * @param config The configurations to use when generating the RDA data.
 * @throws IOException If there was an issue accessing any of the files.
 */
public void run(ConfigLoader config) throws IOException {
    WrappedCounter fissSequence = new WrappedCounter(config.intValue(AppConfig.Fields.fissSeqStart));
    WrappedCounter mcsSequence = new WrappedCounter(config.intValue(AppConfig.Fields.mcsSeqStart));
    if (fissSequence.get() < 1 || mcsSequence.get() < 1) {
        throw new IllegalArgumentException("Sequences must start at 1 or higher.");
    }
    Path inputDirectory = Paths.get(config.stringValue(AppConfig.Fields.inputDirPath));
    Map<String, BeneficiaryData> mbiMap = parseMbiNumbers(inputDirectory.resolve(config.stringValue(AppConfig.Fields.mbiSource)));
    Path outputDirectory = Paths.get(config.stringOption(AppConfig.Fields.outputDirPath).orElse("output"));
    // ResultOfMethodCallIgnored - Don't need to know if it had to be created.
    // noinspection ResultOfMethodCallIgnored
    outputDirectory.toFile().mkdir();
    String fissOutputFile = config.stringOption(AppConfig.Fields.fissOutputFile).orElse("FISS.ndjson");
    String mcsOutputFile = config.stringOption(AppConfig.Fields.mcsOutputFile).orElse("MCS.ndjson");
    Path fissOutputPath = outputDirectory.resolve(fissOutputFile);
    Path mcsOutputPath = outputDirectory.resolve(mcsOutputFile);
    String fissOutputType = FilenameUtils.getExtension(fissOutputPath.getFileName().toString());
    String mcsOutputType = FilenameUtils.getExtension(mcsOutputPath.getFileName().toString());
    if (!sinkMap.containsKey(fissOutputType)) {
        throw new IllegalArgumentException("Unsupported fiss output file type '" + fissOutputType + "'");
    } else if (!sinkMap.containsKey(mcsOutputType)) {
        throw new IllegalArgumentException("Unsupported mcs output file type '" + mcsOutputType + "'");
    } else {
        final int FISS_ID = 0;
        final int MCS_ID = 1;
        // Grab given ratios for fiss/mcs attribution output
        float fissRatio = config.floatOption(AppConfig.Fields.attributionFissRatio).orElse(1.0f);
        // Convert ratio to proportion
        float fissProportion = 1.0f - (1.0f / (1.0f + fissRatio));
        float mcsProportion = 1.0f - fissProportion;
        DataSampler<String> mbiSampler = DataSampler.<String>builder().maxValues(config.intOption(AppConfig.Fields.attributionSetSize).orElse(10_000)).registerSampleSet(FISS_ID, fissProportion).registerSampleSet(MCS_ID, mcsProportion).build();
        try (Sink<MessageOrBuilder> fissSink = sinkMap.get(fissOutputType).apply(new SinkArguments(fissOutputPath, fissSequence));
            Sink<MessageOrBuilder> mcsSink = sinkMap.get(mcsOutputType).apply(new SinkArguments(mcsOutputPath, mcsSequence))) {
            // Sorting the files so tests are more deterministic
            List<String> fissSources = config.stringValues(AppConfig.Fields.fissSources);
            Collections.sort(fissSources);
            for (String fissSource : fissSources) {
                executeTransformation(SourceType.FISS, inputDirectory, fissSource, fissSequence, mbiMap, fissSink, mbiSampler, FISS_ID);
            }
            // Sorting the files so tests are more deterministic
            List<String> mcsSources = config.stringValues(AppConfig.Fields.mcsSources);
            Collections.sort(mcsSources);
            for (String mcsSource : mcsSources) {
                executeTransformation(SourceType.MCS, inputDirectory, mcsSource, mcsSequence, mbiMap, mcsSink, mbiSampler, MCS_ID);
            }
        }
        if (config.booleanValue(AppConfig.Fields.buildAttributionSet, false)) {
            String templateFileName = config.stringOption(AppConfig.Fields.attributionTemplateFile).orElse(DEFAULT_INPUT_FILE);
            String outputFileName = config.stringOption(AppConfig.Fields.attributionScriptFile).orElse(DEFAULT_OUTPUT_FILE);
            AttributionBuilder builder = new AttributionBuilder(templateFileName, outputFileName);
            builder.run(mbiSampler);
        }
    }
}
Also used : Path(java.nio.file.Path) Sink(gov.cms.bfd.pipeline.bridge.io.Sink) NdJsonSink(gov.cms.bfd.pipeline.bridge.io.NdJsonSink) AttributionBuilder(gov.cms.bfd.pipeline.bridge.util.AttributionBuilder) DataSampler(gov.cms.bfd.pipeline.bridge.util.DataSampler) WrappedCounter(gov.cms.bfd.pipeline.bridge.util.WrappedCounter) List(java.util.List) BeneficiaryData(gov.cms.bfd.pipeline.bridge.model.BeneficiaryData) SinkArguments(gov.cms.bfd.pipeline.bridge.io.SinkArguments)

Example 2 with BeneficiaryData

use of gov.cms.bfd.pipeline.bridge.model.BeneficiaryData in project beneficiary-fhir-data by CMSgov.

the class RDABridgeIT method shouldProduceValidClaimStructures.

/**
 * Ensures that no exceptions are thrown while transforming Fiss and MCS claims.
 *
 * @throws IOException if there is a setup issue loading the test data
 */
@Test
void shouldProduceValidClaimStructures() throws IOException {
    RDABridge bridge = new RDABridge();
    Path resourcesDir = getResourcePath();
    String inpatientData = "inpatient.csv";
    String carrierData = "carrier.csv";
    Map<String, BeneficiaryData> mbiMap = bridge.parseMbiNumbers(resourcesDir.resolve("beneficiary_history.csv"));
    List<MessageOrBuilder> results = new ArrayList<>();
    Sink<MessageOrBuilder> testSink = new Sink<>() {

        @Override
        public void write(MessageOrBuilder value) {
            results.add(value);
        }

        @Override
        public void close() throws IOException {
        }
    };
    final int FISS_ID = 0;
    final int MCS_ID = 1;
    DataSampler<String> dataSampler = DataSampler.<String>builder().maxValues(10_000).registerSampleSet(FISS_ID, 0.5f).registerSampleSet(MCS_ID, 0.5f).build();
    assertDoesNotThrow(() -> {
        bridge.executeTransformation(RDABridge.SourceType.FISS, resourcesDir, inpatientData, new WrappedCounter(0), mbiMap, testSink, dataSampler, FISS_ID);
        bridge.executeTransformation(RDABridge.SourceType.MCS, resourcesDir, carrierData, new WrappedCounter(0), mbiMap, testSink, dataSampler, MCS_ID);
        Clock clock = Clock.fixed(Instant.ofEpochMilli(1622743357000L), ZoneOffset.UTC);
        IdHasher.Config hasherConfig = new IdHasher.Config(10, "justsomestring");
        FissClaimTransformer fissTransformer = new FissClaimTransformer(clock, MbiCache.computedCache(hasherConfig));
        McsClaimTransformer mcsTransformer = new McsClaimTransformer(clock, MbiCache.computedCache(hasherConfig));
        for (MessageOrBuilder message : results) {
            if (message instanceof FissClaimChange) {
                fissTransformer.transformClaim((FissClaimChange) message);
            } else {
                mcsTransformer.transformClaim((McsClaimChange) message);
            }
        }
    });
}
Also used : Path(java.nio.file.Path) McsClaimTransformer(gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer) ArrayList(java.util.ArrayList) WrappedCounter(gov.cms.bfd.pipeline.bridge.util.WrappedCounter) FissClaimChange(gov.cms.mpsm.rda.v1.FissClaimChange) Clock(java.time.Clock) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) Sink(gov.cms.bfd.pipeline.bridge.io.Sink) IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) BeneficiaryData(gov.cms.bfd.pipeline.bridge.model.BeneficiaryData) FissClaimTransformer(gov.cms.bfd.pipeline.rda.grpc.source.FissClaimTransformer) Test(org.junit.jupiter.api.Test)

Aggregations

Sink (gov.cms.bfd.pipeline.bridge.io.Sink)2 BeneficiaryData (gov.cms.bfd.pipeline.bridge.model.BeneficiaryData)2 WrappedCounter (gov.cms.bfd.pipeline.bridge.util.WrappedCounter)2 Path (java.nio.file.Path)2 MessageOrBuilder (com.google.protobuf.MessageOrBuilder)1 NdJsonSink (gov.cms.bfd.pipeline.bridge.io.NdJsonSink)1 SinkArguments (gov.cms.bfd.pipeline.bridge.io.SinkArguments)1 AttributionBuilder (gov.cms.bfd.pipeline.bridge.util.AttributionBuilder)1 DataSampler (gov.cms.bfd.pipeline.bridge.util.DataSampler)1 FissClaimTransformer (gov.cms.bfd.pipeline.rda.grpc.source.FissClaimTransformer)1 McsClaimTransformer (gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer)1 IdHasher (gov.cms.bfd.pipeline.sharedutils.IdHasher)1 FissClaimChange (gov.cms.mpsm.rda.v1.FissClaimChange)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1