Search in sources :

Example 1 with IdHasher

use of gov.cms.bfd.pipeline.sharedutils.IdHasher in project beneficiary-fhir-data by CMSgov.

the class RifLoaderTest method computeHicnHash.

/**
 * Runs a couple of fake HICNs through {@link RifLoader#computeHicnHash(LoadAppOptions,
 * SecretKeyFactory, String)} to verify that the expected result is produced.
 */
@Test
public void computeHicnHash() {
    LoadAppOptions options = CcwRifLoadTestUtils.getLoadOptions();
    options = new LoadAppOptions(new IdHasher.Config(1000, "nottherealpepper".getBytes(StandardCharsets.UTF_8)), options.getLoaderThreads(), options.isIdempotencyRequired(), false);
    LOGGER.info("salt/pepper: {}", Arrays.toString(options.getIdHasherConfig().getHashPepper()));
    LOGGER.info("hash iterations: {}", options.getIdHasherConfig().getHashIterations());
    IdHasher hasher = new IdHasher(options.getIdHasherConfig());
    /*
     * These are the two samples from `dev/design-decisions-readme.md` that
     * the frontend and backend both have tests to verify the result of.
     */
    assertEquals("d95a418b0942c7910fb1d0e84f900fe12e5a7fd74f312fa10730cc0fda230e9a", RifLoader.computeHicnHash(hasher, "123456789A"));
    assertEquals("6357f16ebd305103cf9f2864c56435ad0de5e50f73631159772f4a4fcdfe39a5", RifLoader.computeHicnHash(hasher, "987654321E"));
}
Also used : IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) Test(org.junit.jupiter.api.Test)

Example 2 with IdHasher

use of gov.cms.bfd.pipeline.sharedutils.IdHasher 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 3 with IdHasher

use of gov.cms.bfd.pipeline.sharedutils.IdHasher in project beneficiary-fhir-data by CMSgov.

the class RifLoaderIT method assertAreInDatabase.

/**
 * Verifies that the specified RIF records are actually in the database.
 *
 * @param options the {@link LoadAppOptions} to use
 * @param entityManagerFactory the {@link EntityManagerFactory} to use
 * @param records the RIF records to verify
 */
private static void assertAreInDatabase(LoadAppOptions options, EntityManagerFactory entityManagerFactory, Stream<Object> records) {
    EntityManager entityManager = null;
    try {
        entityManager = entityManagerFactory.createEntityManager();
        for (Object record : records.collect(Collectors.toList())) {
            /*
         * We need to handle BeneficiaryHistory separately, as it has a generated ID.
         */
            if (record instanceof BeneficiaryHistory) {
                BeneficiaryHistory beneficiaryHistoryToFind = (BeneficiaryHistory) record;
                beneficiaryHistoryToFind.setHicn(RifLoader.computeHicnHash(new IdHasher(options.getIdHasherConfig()), beneficiaryHistoryToFind.getHicn()));
                beneficiaryHistoryToFind.setMbiHash(beneficiaryHistoryToFind.getMedicareBeneficiaryId().isPresent() ? Optional.of(RifLoader.computeMbiHash(new IdHasher(options.getIdHasherConfig()), beneficiaryHistoryToFind.getMedicareBeneficiaryId().get())) : Optional.empty());
                CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
                CriteriaQuery<BeneficiaryHistory> query = criteriaBuilder.createQuery(BeneficiaryHistory.class);
                Root<BeneficiaryHistory> from = query.from(BeneficiaryHistory.class);
                query.select(from).where(criteriaBuilder.equal(from.get(BeneficiaryHistory_.beneficiaryId), beneficiaryHistoryToFind.getBeneficiaryId()), criteriaBuilder.equal(from.get(BeneficiaryHistory_.birthDate), beneficiaryHistoryToFind.getBirthDate()), criteriaBuilder.equal(from.get(BeneficiaryHistory_.sex), beneficiaryHistoryToFind.getSex()), criteriaBuilder.equal(from.get(BeneficiaryHistory_.hicn), beneficiaryHistoryToFind.getHicn()), criteriaBuilder.equal(from.get(BeneficiaryHistory_.mbiHash), beneficiaryHistoryToFind.getMbiHash().orElse(null)));
                List<BeneficiaryHistory> beneficiaryHistoryFound = entityManager.createQuery(query).getResultList();
                assertNotNull(beneficiaryHistoryFound);
                assertFalse(beneficiaryHistoryFound.isEmpty());
            } else {
                Object recordId = entityManagerFactory.getPersistenceUnitUtil().getIdentifier(record);
                Object recordFromDb = entityManager.find(record.getClass(), recordId);
                assertNotNull(recordFromDb);
            }
        }
    } finally {
        if (entityManager != null)
            entityManager.close();
    }
}
Also used : BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher)

Example 4 with IdHasher

use of gov.cms.bfd.pipeline.sharedutils.IdHasher in project beneficiary-fhir-data by CMSgov.

the class RifLoaderTest method computeMbiHash.

/**
 * Runs a couple of fake MBIs through {@link RifLoader#computeMbiHash(LoadAppOptions,
 * SecretKeyFactory, String)} to verify that the expected result is produced.
 */
@Test
public void computeMbiHash() {
    LoadAppOptions options = CcwRifLoadTestUtils.getLoadOptions();
    options = new LoadAppOptions(new IdHasher.Config(1000, "nottherealpepper".getBytes(StandardCharsets.UTF_8)), options.getLoaderThreads(), options.isIdempotencyRequired(), false);
    LOGGER.info("salt/pepper: {}", Arrays.toString(options.getIdHasherConfig().getHashPepper()));
    LOGGER.info("hash iterations: {}", options.getIdHasherConfig().getHashIterations());
    IdHasher hasher = new IdHasher(options.getIdHasherConfig());
    /*
     * These are the two samples from `dev/design-decisions-readme.md` that
     * the frontend and backend both have tests to verify the result of.
     */
    assertEquals("ec49dc08f8dd8b4e189f623ab666cfc8b81f201cc94fe6aef860a4c3bd57f278", RifLoader.computeMbiHash(hasher, "3456789"));
    assertEquals("742086db6bf338dedda6175ea3af8ca5e85b81fda9cc7078004a4d3e4792494b", RifLoader.computeMbiHash(hasher, "2456689"));
}
Also used : IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) Test(org.junit.jupiter.api.Test)

Example 5 with IdHasher

use of gov.cms.bfd.pipeline.sharedutils.IdHasher in project beneficiary-fhir-data by CMSgov.

the class FissClaimRdaSinkIT method fissClaim.

@Test
public void fissClaim() throws Exception {
    RdaPipelineTestUtils.runTestWithTemporaryDb(FissClaimRdaSinkIT.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 PreAdjFissClaim claim = new PreAdjFissClaim();
        claim.setSequenceNumber(3L);
        claim.setDcn("1");
        claim.setHicNo("h1");
        claim.setCurrStatus('T');
        claim.setCurrLoc1('A');
        claim.setCurrLoc2("1A");
        claim.setPracLocCity("city name can be very long indeed");
        claim.setMbiRecord(new Mbi(1L, "12345678901", "hash-of-12345678901"));
        final PreAdjFissProcCode procCode0 = new PreAdjFissProcCode();
        procCode0.setDcn(claim.getDcn());
        procCode0.setPriority((short) 0);
        procCode0.setProcCode("P");
        procCode0.setProcFlag("F");
        procCode0.setProcDate(today);
        claim.getProcCodes().add(procCode0);
        final PreAdjFissDiagnosisCode diagCode0 = new PreAdjFissDiagnosisCode();
        diagCode0.setDcn(claim.getDcn());
        diagCode0.setPriority((short) 0);
        diagCode0.setDiagCd2("cd2");
        diagCode0.setDiagPoaInd("Q");
        claim.getDiagCodes().add(diagCode0);
        final FissProcedureCode procCodeMessage = FissProcedureCode.newBuilder().setProcCd("P").setProcFlag("F").setProcDt("2022-01-03").build();
        final FissDiagnosisCode diagCodeMessage = FissDiagnosisCode.newBuilder().setDiagCd2("cd2").setDiagPoaIndUnrecognized("Q").build();
        final FissClaim claimMessage = FissClaim.newBuilder().setDcn(claim.getDcn()).setHicNo(claim.getHicNo()).setCurrStatusEnum(FissClaimStatus.CLAIM_STATUS_RTP).setCurrLoc1Unrecognized(String.valueOf(claim.getCurrLoc1())).setCurrLoc2Unrecognized(claim.getCurrLoc2()).setPracLocCity("city name can be very long indeed").addFissProcCodes(0, procCodeMessage).addFissDiagCodes(0, diagCodeMessage).setMbi(claim.getMbi()).build();
        final FissClaimChange message = FissClaimChange.newBuilder().setSeq(claim.getSequenceNumber()).setDcn(claim.getDcn()).setClaim(claimMessage).build();
        final IdHasher defaultIdHasher = new IdHasher(new IdHasher.Config(1, "notarealpepper"));
        final FissClaimTransformer transformer = new FissClaimTransformer(clock, MbiCache.computedCache(defaultIdHasher.getConfig()));
        final FissClaimRdaSink sink = new FissClaimRdaSink(appState, transformer, true);
        final String expectedMbiHash = defaultIdHasher.computeIdentifierHash(claim.getMbi());
        assertEquals(Optional.empty(), sink.readMaxExistingSequenceNumber());
        int count = sink.writeMessage("version", message);
        assertEquals(1, count);
        List<PreAdjFissClaim> claims = entityManager.createQuery("select c from PreAdjFissClaim c", PreAdjFissClaim.class).getResultList();
        assertEquals(1, claims.size());
        PreAdjFissClaim resultClaim = claims.get(0);
        assertEquals(Long.valueOf(3), resultClaim.getSequenceNumber());
        assertEquals(claim.getHicNo(), resultClaim.getHicNo());
        assertEquals(claim.getPracLocCity(), resultClaim.getPracLocCity());
        assertEquals(claim.getMbi(), resultClaim.getMbi());
        assertEquals(expectedMbiHash, resultClaim.getMbiHash());
        assertEquals(claim.getProcCodes().size(), resultClaim.getProcCodes().size());
        assertEquals(claim.getDiagCodes().size(), resultClaim.getDiagCodes().size());
        assertEquals(Optional.of(claim.getSequenceNumber()), sink.readMaxExistingSequenceNumber());
        Mbi databaseMbiEntity = RdaPipelineTestUtils.lookupCachedMbi(entityManager, claimMessage.getMbi());
        assertNotNull(databaseMbiEntity);
        assertEquals(claim.getMbi(), databaseMbiEntity.getMbi());
        assertEquals(expectedMbiHash, databaseMbiEntity.getHash());
    });
}
Also used : FissProcedureCode(gov.cms.mpsm.rda.v1.fiss.FissProcedureCode) Instant(java.time.Instant) PreAdjFissClaim(gov.cms.bfd.model.rda.PreAdjFissClaim) FissClaim(gov.cms.mpsm.rda.v1.fiss.FissClaim) FissClaimChange(gov.cms.mpsm.rda.v1.FissClaimChange) PreAdjFissClaim(gov.cms.bfd.model.rda.PreAdjFissClaim) FissDiagnosisCode(gov.cms.mpsm.rda.v1.fiss.FissDiagnosisCode) PreAdjFissDiagnosisCode(gov.cms.bfd.model.rda.PreAdjFissDiagnosisCode) Clock(java.time.Clock) LocalDate(java.time.LocalDate) PreAdjFissDiagnosisCode(gov.cms.bfd.model.rda.PreAdjFissDiagnosisCode) Mbi(gov.cms.bfd.model.rda.Mbi) PreAdjFissProcCode(gov.cms.bfd.model.rda.PreAdjFissProcCode) IdHasher(gov.cms.bfd.pipeline.sharedutils.IdHasher) FissClaimTransformer(gov.cms.bfd.pipeline.rda.grpc.source.FissClaimTransformer) Test(org.junit.jupiter.api.Test)

Aggregations

IdHasher (gov.cms.bfd.pipeline.sharedutils.IdHasher)5 Test (org.junit.jupiter.api.Test)4 Mbi (gov.cms.bfd.model.rda.Mbi)2 Clock (java.time.Clock)2 Instant (java.time.Instant)2 LocalDate (java.time.LocalDate)2 PreAdjFissClaim (gov.cms.bfd.model.rda.PreAdjFissClaim)1 PreAdjFissDiagnosisCode (gov.cms.bfd.model.rda.PreAdjFissDiagnosisCode)1 PreAdjFissProcCode (gov.cms.bfd.model.rda.PreAdjFissProcCode)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 BeneficiaryHistory (gov.cms.bfd.model.rif.BeneficiaryHistory)1 FissClaimTransformer (gov.cms.bfd.pipeline.rda.grpc.source.FissClaimTransformer)1 McsClaimTransformer (gov.cms.bfd.pipeline.rda.grpc.source.McsClaimTransformer)1 FissClaimChange (gov.cms.mpsm.rda.v1.FissClaimChange)1 McsClaimChange (gov.cms.mpsm.rda.v1.McsClaimChange)1 FissClaim (gov.cms.mpsm.rda.v1.fiss.FissClaim)1 FissDiagnosisCode (gov.cms.mpsm.rda.v1.fiss.FissDiagnosisCode)1 FissProcedureCode (gov.cms.mpsm.rda.v1.fiss.FissProcedureCode)1