Skip to content

Commit 440d86d

Browse files
committed
refactor samhsa tests for prior authorization
1 parent b1721d5 commit 440d86d

8 files changed

Lines changed: 217 additions & 174 deletions

File tree

apps/bfd-pipeline-idr/model/idr_claim_item_institutional_nch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ class IdrClaimItemInstitutionalNch(IdrBaseModel):
179179
clm_line_instnl_rdcd_amt: Annotated[float | None, {ALIAS: ALIAS_LINE_INSTNL}]
180180
clm_line_instnl_msp1_pd_amt: Annotated[float | None, {ALIAS: ALIAS_LINE_INSTNL}]
181181
clm_line_instnl_msp2_pd_amt: Annotated[float | None, {ALIAS: ALIAS_LINE_INSTNL}]
182-
clm_line_instnl_rev_ctr_dt: Annotated[date | None, {ALIAS: ALIAS_LINE_INSTNL}]
182+
clm_line_instnl_rev_ctr_dt: Annotated[
183+
date | None, {ALIAS: ALIAS_LINE_INSTNL}, BeforeValidator(transform_default_date_to_null)
184+
]
183185
clm_rev_cntr_tdapa_amt: Annotated[float | None, {ALIAS: ALIAS_LINE_INSTNL}]
184186
clm_line_add_on_pymt_amt: Annotated[float | None, {ALIAS: ALIAS_LINE_INSTNL}]
185187
idr_insrt_ts_line_instnl: Annotated[

apps/bfd-pipeline-idr/test_samples2/samhsa/SYNTHETIC_CLM_LINE.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CLM_UNIQ_ID,GEO_BENE_SK,CLM_DT_SGNTR_SK,CLM_TYPE_CD,CLM_NUM_SK,CLM_LINE_NUM,CLM_FROM_DT,CLM_LINE_FROM_DT,CLM_LINE_THRU_DT,CLM_LINE_HCPCS_CD,HCPCS_1_MDFR_CD,HCPCS_2_MDFR_CD,HCPCS_3_MDFR_CD,HCPCS_4_MDFR_CD,HCPCS_5_MDFR_CD,CLM_LINE_ANSTHSA_UNIT_CNT,CLM_LINE_SRVC_UNIT_QTY,CLM_LINE_REV_CTR_CD,CLM_LINE_BENE_PMT_AMT,CLM_LINE_BENE_PD_AMT,CLM_LINE_ALOWD_CHRG_AMT,CLM_LINE_SBMT_CHRG_AMT,CLM_LINE_CVRD_PD_AMT,CLM_LINE_BLOOD_DDCTBL_AMT,CLM_LINE_MDCR_DDCTBL_AMT,CLM_LINE_PRVDR_PMT_AMT,CLM_LINE_NCVRD_CHRG_AMT,CLM_LINE_FINL_ACTN_IND,CLM_LINE_LTST_CLM_IND,CLM_LINE_OTAF_AMT,CLM_LINE_NDC_CD,CLM_LINE_NDC_QTY,CLM_LINE_NDC_QTY_QLFYR_CD,CLM_RNDRG_PRVDR_TYPE_CD,CLM_LINE_MDCR_COINSRNC_AMT,CLM_LINE_DGNS_CD,CLM_POS_CD,CLM_RNDRG_PRVDR_PRTCPTG_CD,CLM_RNDRG_PRVDR_TAX_NUM,CLM_RNDRG_PRVDR_PIN_NUM,PRVDR_RNDRNG_PRVDR_NPI_NUM,CLM_RNDRG_PRVDR_NPI_NUM,CLM_LINE_PMD_UNIQ_TRKNG_NUM,CLM_LINE_NCVRD_PD_AMT,CLM_LINE_RX_NUM,CLM_LINE_GRS_CVRD_CST_TOT_AMT,CLM_LINE_OTHR_TP_PD_AMT,IDR_INSRT_TS,IDR_UPDT_TS,GEO_RNDRG_SSA_STATE_CD
2-
4146709784142,86450,070472586648,60,1,1,2018-06-23,2018-06-23,2018-07-20,J2270,,,,,,,7.0,,3.41,772968.46,,1.99,36129.5,10.46,2.13,887996.87,326.24,N,N,650.61,00338011704,5.0,ML,,,,,,,,,,,,,,,2025-07-04 01:15:55.616196,,03
2+
4146709784142,86450,070472586648,60,1,1,2018-06-23,2018-06-23,1000-01-01,J2270,,,,,,,7.0,,3.41,772968.46,,1.99,36129.5,10.46,2.13,887996.87,326.24,N,N,650.61,00338011704,5.0,ML,,,,,,,,,,,,,,,2025-07-04 01:15:55.616196,,03
33
6647624169509,08639,098209822727,81,1,1,2018-07-06,2018-07-06,2018-07-30,99213,23,US,US,,,,1.61,0832,4.56,3.37,0.72,1.72,2.06,3.33,2.82,267.51,1137.33,N,Y,885.79,,,,64,1.13,,27,,,,1730548868,,,,,,,2023-10-09 06:51:33.259884,,03
44
6647624169509,08639,098209822727,81,1,2,2018-07-06,2018-07-06,2018-07-30,99453,U6,32,,,,,1.37,0262,4.05,3.73,2.86,0.96,1.99,13.5,3.36,1214.37,471.04,Y,Y,694.01,,,,39,3.18,,19,,,,1972944437,,,,,,,2025-08-12 19:02:16.986163,,03
55
5312173004042,22274,933588465810,71,1,1,2020-06-26,2020-06-26,2020-06-30,99213,,,,,,,2.48,0819,2.51,1.98,0.03,0.36,1.56,0.57,1.97,86.03,1390.02,N,N,967.0,00264180032,320.94,ML,29,3.54,W213,39,2,1928347912,19238747,1437702123,1437702123,,,,,,2025-08-27 10:19:11.169444,,03

apps/bfd-pipeline-idr/test_samples2/samhsa/SYNTHETIC_CLM_LINE_INSTNL.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GEO_BENE_SK,CLM_DT_SGNTR_SK,CLM_TYPE_CD,CLM_NUM_SK,CLM_LINE_NUM,CLM_LINE_INSTNL_ADJSTD_AMT,CLM_LINE_INSTNL_RDCD_AMT,CLM_DDCTBL_COINSRNC_CD,CLM_LINE_INSTNL_RATE_AMT,CLM_LINE_INSTNL_MSP1_PD_AMT,CLM_LINE_INSTNL_MSP2_PD_AMT,CLM_LINE_INSTNL_REV_CTR_DT,CLM_REV_DSCNT_IND_CD,CLM_OTAF_ONE_IND_CD,CLM_REV_PACKG_IND_CD,CLM_REV_PMT_MTHD_CD,CLM_REV_CNTR_STUS_CD,CLM_ANSI_SGNTR_SK,CLM_LINE_ADD_ON_PYMT_AMT,CLM_LINE_NON_EHR_RDCTN_AMT,CLM_REV_CNTR_TDAPA_AMT,IDR_INSRT_TS,IDR_UPDT_TS
2-
86450,070472586648,60,1,1,375.9,886.52,1,13.41,16.44,58.54,2019-09-23,7,N,2,~,M,1,2126.25,396.35,7900.67,2026-01-10 10:14:30.076275,
2+
86450,070472586648,60,1,1,375.9,886.52,1,13.41,16.44,58.54,1000-01-01,7,N,2,~,M,1,2126.25,396.35,7900.67,2026-01-10 10:14:30.076275,
33
76752,793325305297,10,1,1,1218.45,111.98,N,12.58,14.94,1.37,2022-06-29,6,N,2,4,R,-6857,8335.8,261.69,5173.22,2024-07-09 12:35:45.553447,
44
86619,888606719576,10,1,1,499.82,1013.04,0,14.64,7.0,0.63,2023-10-03,3,~,3,12,K,-1,8619.32,360.17,9946.79,2024-11-28 05:56:41.404822,
55
55109,969624759354,60,1,1,375.9,886.52,1,13.41,16.44,58.54,2019-09-23,3,~,2,2,R,1,5136.25,346.18,3057.58,2025-12-24 06:32:24.122762,

apps/bfd-server-ng/src/main/java/gov/cms/bfd/server/ng/converter/OptionalDateConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public LocalDate convertToDatabaseColumn(Optional<LocalDate> maybeDate) {
1818

1919
@Override
2020
public Optional<LocalDate> convertToEntityAttribute(LocalDate value) {
21-
if (value == null || value.equals(IdrConstants.DEFAULT_DATE)) {
21+
if (value == null
22+
|| value.equals(IdrConstants.DEFAULT_DATE)
23+
|| value.isBefore(IdrConstants.ALTERNATE_DEFAULT_DATE)) {
2224
return Optional.empty();
2325
} else {
2426
return Optional.of(value);

apps/bfd-server-ng/src/main/java/gov/cms/bfd/server/ng/util/IdrConstants.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ private IdrConstants() {
1919
/** The string value IDR uses to represent "UNKNOWN". */
2020
public static final String UNKNOWN = "U";
2121

22-
/** The value used by IDR to indicate a missing or non-applicable value in a date column. */
22+
/** The date used by IDR to indicate a missing or non-applicable value in a date column. */
2323
public static final LocalDate DEFAULT_DATE = LocalDate.of(9999, 12, 31);
2424

25+
/**
26+
* If there's any date with the year before 1582, Java will switch to the Julian calendar and
27+
* misinterpret and convert the date. IDR has the alternate date 1000-01-01 to indicate a missing
28+
* or non-applicable value in a date column so we use this check to convert those dates to
29+
* optionals.
30+
*/
31+
public static final LocalDate ALTERNATE_DEFAULT_DATE = LocalDate.of(1900, 1, 1);
32+
2533
/** The code for non-final action claims. */
2634
public static final String NOT_FINAL_ACTION = "NotFinalAction";
2735

apps/bfd-server-ng/src/test/java/gov/cms/bfd/server/ng/EobPriorAuthorizationIT.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727

2828
class EobPriorAuthorizationIT extends IntegrationTestBase {
2929

30-
private static final PriorAuthIdentifier NO_SAMHSA_PRIOR_AUTH =
31-
new PriorAuthIdentifier("794471559", "-0Y2K7HP0Y71BO");
32-
private static final PriorAuthIdentifier SAMHSA_PRIOR_AUTH =
33-
new PriorAuthIdentifier("794471559", "-Z7E63N3ROZJC9");
34-
35-
private record PriorAuthIdentifier(String beneSk, String utn) {}
36-
3730
private IQuery<Bundle> searchBundle(SamhsaCertType samhsaCertType) {
3831
final var fhirClient = getFhirClient();
3932

@@ -242,35 +235,6 @@ void eobSearchBySources(
242235
}
243236
}
244237

245-
private static Stream<Arguments> shouldFilterSamhsaPriorAuth() {
246-
return Stream.of(
247-
Arguments.of(SamhsaCertType.NO_CERT, 1, false),
248-
Arguments.of(SamhsaCertType.SAMHSA_NOT_ALLOWED_CERT, 1, false),
249-
Arguments.of(SamhsaCertType.SAMHSA_ALLOWED_CERT, 3, true));
250-
}
251-
252-
@MethodSource({"shouldFilterSamhsaPriorAuth"})
253-
@ParameterizedTest
254-
void shouldFilterSamhsaPriorAuth(
255-
SamhsaCertType certType, int expectedBundleSize, boolean expectedSamhsaPriorAuth) {
256-
var bundle =
257-
searchBundle(certType)
258-
.where(
259-
new TokenClientParam(ExplanationOfBenefit.SP_PATIENT)
260-
.exactly()
261-
.identifier(BENE_WITH_PRIOR_AUTH))
262-
.execute();
263-
264-
assertEquals(expectedBundleSize, bundle.getEntry().size());
265-
266-
var priorAuths = getPriorAuths(bundle);
267-
268-
assertTrue(priorAuths.stream().anyMatch(eob -> matchesPriorAuth(eob, NO_SAMHSA_PRIOR_AUTH)));
269-
assertEquals(
270-
expectedSamhsaPriorAuth,
271-
priorAuths.stream().anyMatch(eob -> matchesPriorAuth(eob, SAMHSA_PRIOR_AUTH)));
272-
}
273-
274238
static Stream<Arguments> provideTagScenarios() {
275239
return Stream.of(SearchStyleEnum.values())
276240
.flatMap(
@@ -366,15 +330,6 @@ void shouldQueryPriorAuthForTagScenarios(
366330
assertEquals(expectedPriorAuth, hasPriorAuth);
367331
}
368332

369-
private boolean matchesPriorAuth(ExplanationOfBenefit eob, PriorAuthIdentifier identifier) {
370-
assertEquals(ExplanationOfBenefit.Use.PREAUTHORIZATION, eob.getUse());
371-
372-
var hasMatchingUtn =
373-
eob.getIdentifier().stream().anyMatch(id -> identifier.utn().equals(id.getValue()));
374-
var hasMatchingMbi = eob.getPatient().getReference().contains(identifier.beneSk());
375-
return hasMatchingUtn && hasMatchingMbi;
376-
}
377-
378333
private List<ExplanationOfBenefit> getPriorAuths(Bundle bundle) {
379334
return getEobFromBundle(bundle).stream()
380335
.filter(eob -> eob.hasUse() && eob.getUse() == ExplanationOfBenefit.Use.PREAUTHORIZATION)

0 commit comments

Comments
 (0)