Search in sources :

Example 1 with McsClaimTransformer

use of gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer in project beneficiary-fhir-data by CMSgov.

the class McsClaimRdaSinkIT method mcsClaim.

@Test
public void mcsClaim() throws Exception {
    RdaPipelineTestUtils.runTestWithTemporaryDb(McsClaimRdaSinkIT.class, Clock.systemUTC(), (appState, entityManager) -> {
        final LocalDate today = LocalDate.of(2022, 1, 3);
        final Instant now = today.atStartOfDay().toInstant(ZoneOffset.UTC);
        final Clock clock = Clock.fixed(now, ZoneOffset.UTC);
        final PreAdjMcsClaim claim = new PreAdjMcsClaim();
        claim.setSequenceNumber(7L);
        claim.setIdrClmHdIcn("3");
        claim.setIdrContrId("c1");
        claim.setIdrHic("hc");
        claim.setIdrClaimType("c");
        claim.setMbiRecord(new Mbi(1L, "12345678901", "hash-of-12345678901"));
        final PreAdjMcsDetail detail = new PreAdjMcsDetail();
        detail.setIdrClmHdIcn(claim.getIdrClmHdIcn());
        detail.setPriority((short) 0);
        detail.setIdrDtlStatus("P");
        claim.getDetails().add(detail);
        final PreAdjMcsDiagnosisCode diagCode = new PreAdjMcsDiagnosisCode();
        diagCode.setIdrClmHdIcn(claim.getIdrClmHdIcn());
        diagCode.setPriority((short) 0);
        diagCode.setIdrDiagIcdType("T");
        diagCode.setIdrDiagCode("D");
        claim.getDiagCodes().add(diagCode);
        final McsDetail detailMessage = McsDetail.newBuilder().setIdrDtlStatusUnrecognized(detail.getIdrDtlStatus()).build();
        final McsDiagnosisCode diagCodeMessage = McsDiagnosisCode.newBuilder().setIdrDiagIcdTypeUnrecognized(diagCode.getIdrDiagIcdType()).setIdrDiagCode(diagCode.getIdrDiagCode()).build();
        final McsClaim claimMessage = McsClaim.newBuilder().setIdrClmHdIcn(claim.getIdrClmHdIcn()).setIdrContrId(claim.getIdrContrId()).setIdrClaimMbi(claim.getIdrClaimMbi()).setIdrHic(claim.getIdrHic()).setIdrClaimTypeUnrecognized(claim.getIdrClaimType()).addMcsDetails(detailMessage).addMcsDiagnosisCodes(diagCodeMessage).build();
        final McsClaimChange message = McsClaimChange.newBuilder().setSeq(claim.getSequenceNumber()).setIcn(claim.getIdrClmHdIcn()).setClaim(claimMessage).build();
        final IdHasher hasher = new IdHasher(new IdHasher.Config(1, "notarealpepper"));
        final McsClaimTransformer transformer = new McsClaimTransformer(clock, MbiCache.computedCache(hasher.getConfig()));
        final McsClaimRdaSink sink = new McsClaimRdaSink(appState, transformer, true);
        final String expectedMbiHash = hasher.computeIdentifierHash(claim.getIdrClaimMbi());
        assertEquals(Optional.empty(), sink.readMaxExistingSequenceNumber());
        int count = sink.writeMessage("version", message);
        assertEquals(1, count);
        List<PreAdjMcsClaim> resultClaims = entityManager.createQuery("select c from PreAdjMcsClaim c", PreAdjMcsClaim.class).getResultList();
        assertEquals(1, resultClaims.size());
        PreAdjMcsClaim resultClaim = resultClaims.get(0);
        assertEquals(Long.valueOf(7), resultClaim.getSequenceNumber());
        assertEquals(claim.getIdrHic(), resultClaim.getIdrHic());
        assertEquals(claim.getIdrClaimMbi(), resultClaim.getIdrClaimMbi());
        assertEquals(expectedMbiHash, resultClaim.getIdrClaimMbiHash());
        assertEquals(claim.getDetails().size(), resultClaim.getDetails().size());
        assertEquals(claim.getDiagCodes().size(), resultClaim.getDiagCodes().size());
        assertEquals(Optional.of(claim.getSequenceNumber()), sink.readMaxExistingSequenceNumber());
        Mbi databaseMbiEntity = RdaPipelineTestUtils.lookupCachedMbi(entityManager, claimMessage.getIdrClaimMbi());
        assertNotNull(databaseMbiEntity);
        assertEquals(claim.getIdrClaimMbi(), databaseMbiEntity.getMbi());
        assertEquals(expectedMbiHash, databaseMbiEntity.getHash());
    });
}
Also used : McsClaimTransformer(gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer) Instant(java.time.Instant) PreAdjMcsDetail(gov.cms.bfd.model.rda.PreAdjMcsDetail) McsDetail(gov.cms.mpsm.rda.v1.mcs.McsDetail) Clock(java.time.Clock) LocalDate(java.time.LocalDate) PreAdjMcsDiagnosisCode(gov.cms.bfd.model.rda.PreAdjMcsDiagnosisCode) PreAdjMcsDetail(gov.cms.bfd.model.rda.PreAdjMcsDetail) McsDiagnosisCode(gov.cms.mpsm.rda.v1.mcs.McsDiagnosisCode) PreAdjMcsDiagnosisCode(gov.cms.bfd.model.rda.PreAdjMcsDiagnosisCode) Mbi(gov.cms.bfd.model.rda.Mbi) IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) PreAdjMcsClaim(gov.cms.bfd.model.rda.PreAdjMcsClaim) PreAdjMcsClaim(gov.cms.bfd.model.rda.PreAdjMcsClaim) McsClaim(gov.cms.mpsm.rda.v1.mcs.McsClaim) McsClaimChange(gov.cms.mpsm.rda.v1.McsClaimChange) Test(org.junit.jupiter.api.Test)

Example 2 with McsClaimTransformer

use of gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer in project beneficiary-fhir-data by CMSgov.

the class RdaLoadJobIT method mcsClaimsAreValid.

/**
 * All of our test claims should be valid for our IT tests to succeed. This test ensures this is
 * the case and catches any incompatibility issues when a new RDA API version contains breaking
 * changes.
 */
@Test
public void mcsClaimsAreValid() throws Exception {
    final ImmutableList<McsClaimChange> expectedClaims = JsonMessageSource.parseAll(mcsClaimJson, JsonMessageSource::parseMcsClaimChange);
    final McsClaimTransformer transformer = new McsClaimTransformer(clock, MbiCache.computedCache(new IdHasher.Config(1, "testing")));
    for (McsClaimChange claim : expectedClaims) {
        try {
            transformer.transformClaim(claim);
        } catch (DataTransformer.TransformationException ex) {
            fail(String.format("bad sample claim: seq=%d error=%s", claim.getSeq(), ex.getErrors()));
        }
    }
}
Also used : JsonMessageSource(gov.cms.bfd.pipeline.rda.grpc.server.JsonMessageSource) McsClaimTransformer(gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer) DataTransformer(gov.cms.bfd.pipeline.rda.grpc.source.DataTransformer) McsClaimChange(gov.cms.mpsm.rda.v1.McsClaimChange) Test(org.junit.jupiter.api.Test)

Example 3 with McsClaimTransformer

use of gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer 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

McsClaimTransformer (gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer)3 Test (org.junit.jupiter.api.Test)3 IdHasher (gov.cms.bfd.pipeline.sharedutils.IdHasher)2 McsClaimChange (gov.cms.mpsm.rda.v1.McsClaimChange)2 Clock (java.time.Clock)2 MessageOrBuilder (com.google.protobuf.MessageOrBuilder)1 Mbi (gov.cms.bfd.model.rda.Mbi)1 PreAdjMcsClaim (gov.cms.bfd.model.rda.PreAdjMcsClaim)1 PreAdjMcsDetail (gov.cms.bfd.model.rda.PreAdjMcsDetail)1 PreAdjMcsDiagnosisCode (gov.cms.bfd.model.rda.PreAdjMcsDiagnosisCode)1 Sink (gov.cms.bfd.pipeline.bridge.io.Sink)1 BeneficiaryData (gov.cms.bfd.pipeline.bridge.model.BeneficiaryData)1 WrappedCounter (gov.cms.bfd.pipeline.bridge.util.WrappedCounter)1 JsonMessageSource (gov.cms.bfd.pipeline.rda.grpc.server.JsonMessageSource)1 DataTransformer (gov.cms.bfd.pipeline.rda.grpc.source.DataTransformer)1 FissClaimTransformer (gov.cms.bfd.pipeline.rda.grpc.source.FissClaimTransformer)1 FissClaimChange (gov.cms.mpsm.rda.v1.FissClaimChange)1 McsClaim (gov.cms.mpsm.rda.v1.mcs.McsClaim)1 McsDetail (gov.cms.mpsm.rda.v1.mcs.McsDetail)1 McsDiagnosisCode (gov.cms.mpsm.rda.v1.mcs.McsDiagnosisCode)1