diff --git a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClient.java b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClient.java index 6699f664..cf3c7af1 100644 --- a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClient.java +++ b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClient.java @@ -11,7 +11,7 @@ public interface BFDClient { String BFD_HDR_BULK_JOBID = "BULK-JOBID"; IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, String contractNum); - IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, OffsetDateTime sinceTime, String contractNum); + IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, OffsetDateTime sinceTime, OffsetDateTime untilTime, String contractNum); IBaseBundle requestNextBundleFromServer(FhirVersion version, IBaseBundle bundle, String contractNum); /** diff --git a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClientImpl.java b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClientImpl.java index 06642fef..9085b0e6 100644 --- a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClientImpl.java +++ b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDClientImpl.java @@ -79,8 +79,7 @@ public BFDClientImpl(BFDSearch bfdSearch, BfdClientVersions bfdClientVersions) { exclude = { ResourceNotFoundException.class } ) public IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, String contractNum) { - return requestEOBFromServer(version, patientID, null, contractNum); - // return requestEOBFromServer(version, patientID, null, null, contractNum); + return requestEOBFromServer(version, patientID, null, null, contractNum); } /** @@ -92,6 +91,7 @@ public IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, Str * @param version The FHIR version * @param patientID The requested patient's ID * @param sinceTime The start date for the request + * @param untilTime The stop date for the request * @return {@link IBaseBundle} Containing a number (possibly 0) of Resources * objects * @throws ResourceNotFoundException when the requested patient does not exist @@ -104,12 +104,12 @@ public IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, Str backoff = @Backoff(delayExpression = "${bfd.retry.backoffDelay:250}", multiplier = 2), exclude = { ResourceNotFoundException.class } ) - public IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, OffsetDateTime sinceTime, String contractNum) { - final Segment bfdSegment = NewRelic.getAgent().getTransaction().startSegment("BFD Call for patient with patient ID " + patientID + - " using since " + sinceTime); + public IBaseBundle requestEOBFromServer(FhirVersion version, long patientID, OffsetDateTime sinceTime, OffsetDateTime untilTime, String contractNum) { + final Segment bfdSegment = NewRelic.getAgent().getTransaction().startSegment("BFD Call for patient with patient ID " + patientID + + " using since " + sinceTime + " and until " + untilTime); bfdSegment.setMetricName("RequestEOB"); - IBaseBundle result = bfdSearch.searchEOB(patientID, sinceTime, pageSize, getJobId(), version, contractNum); + IBaseBundle result = bfdSearch.searchEOB(patientID, sinceTime, untilTime, pageSize, getJobId(), version, contractNum); bfdSegment.end(); @@ -226,4 +226,4 @@ private String createMonthParameter(int month) { final String zeroPaddedMonth = StringUtils.leftPad("" + month, 2, '0'); return PTDCNTRCT_URL_PREFIX + zeroPaddedMonth; } -} +} \ No newline at end of file diff --git a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearch.java b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearch.java index 637bae19..d5dcfecd 100644 --- a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearch.java +++ b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearch.java @@ -7,5 +7,5 @@ import java.time.OffsetDateTime; public interface BFDSearch { - IBaseBundle searchEOB(long patientId, OffsetDateTime since, int pageSize, String bulkJobId, FhirVersion version, String contractNum) throws IOException; + IBaseBundle searchEOB(long patientId, OffsetDateTime since, OffsetDateTime until, int pageSize, String bulkJobId, FhirVersion version, String contractNum) throws IOException; } diff --git a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearchImpl.java b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearchImpl.java index d6825da0..13a4f780 100644 --- a/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearchImpl.java +++ b/ab2d-bfd/src/main/java/gov/cms/ab2d/bfd/client/BFDSearchImpl.java @@ -39,6 +39,7 @@ public BFDSearchImpl(HttpClient httpClient, Environment environment, BfdClientVe * * @param patientId internal beneficiary id * @param since the minimum lastUpdated date which may be null + * @param until the maximum lastUpdated date which may be null * @param pageSize maximum number of records that can be returned * @param bulkJobId header to uniquely identify what job this is coming from within BFD logs * @param version the version of FHIR that we need from BFD @@ -47,21 +48,17 @@ public BFDSearchImpl(HttpClient httpClient, Environment environment, BfdClientVe */ @Trace @Override - public IBaseBundle searchEOB(long patientId, OffsetDateTime since, int pageSize, String bulkJobId, FhirVersion version, String contractNum) throws IOException { + public IBaseBundle searchEOB(long patientId, OffsetDateTime since, OffsetDateTime until, int pageSize, String bulkJobId, FhirVersion version, String contractNum) throws IOException { + String urlLocation = bfdClientVersions.getUrl(version); StringBuilder url = new StringBuilder(urlLocation + "ExplanationOfBenefit?patient=" + patientId + "&excludeSAMHSA=true"); if (since != null) { url.append("&_lastUpdated=ge").append(since); + } - //AB2D-5892 (Sprint 3)Centene customer support to provide 2 year data - if (contractNum.equals("S4802") || contractNum.equals("Z1001")) { - url.append("&_lastUpdated=le").append(since.plusMonths(1)); - } - //AB2D-6167 Create customized script for Humana - if (contractNum.equals("S5884")) { - url.append("&_lastUpdated=le").append(since.plusMonths(2)); - } + if (until != null) { + url.append("&_lastUpdated=le").append(until); } if (pageSize > 0) { @@ -85,7 +82,7 @@ public IBaseBundle searchEOB(long patientId, OffsetDateTime since, int pageSize, } /** - Method exists to track connection to BFD for New Relic + Method exists to track connection to BFD for New Relic */ @Trace private byte[] getEOBSFromBFD(long patientId, HttpGet request) throws IOException { @@ -111,4 +108,4 @@ private byte[] getEOBSFromBFD(long patientId, HttpGet request) throws IOExceptio private IBaseBundle parseBundle(FhirVersion version, byte[] responseBytes) { return version.getJsonParser().parseResource(version.getBundleClass(), new ByteArrayInputStream(responseBytes)); } -} +} \ No newline at end of file diff --git a/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BFDSearchImplTest.java b/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BFDSearchImplTest.java index 855fd0c5..8596b593 100644 --- a/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BFDSearchImplTest.java +++ b/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BFDSearchImplTest.java @@ -89,7 +89,7 @@ void testSearchEOB100() throws IOException { // Business logic & assertion(s) assertThrows( RuntimeException.class, - () -> bfdSearchImpl.searchEOB(patientId, since, pageSize, bulkJobId, version, contractNum) + () -> bfdSearchImpl.searchEOB(patientId, since, until, pageSize, bulkJobId, version, contractNum) ); } @@ -105,7 +105,7 @@ void testSearchEOB200() throws IOException{ BFDSearchImpl bfdSearchImpl = new BFDSearchImpl(httpClient, environment, bfdClientVersions); // Business logic & assertion(s) - IBaseBundle result = bfdSearchImpl.searchEOB(patientId, since, pageSize, bulkJobId, version, contractNum); + IBaseBundle result = bfdSearchImpl.searchEOB(patientId, since, until, pageSize, bulkJobId, version, contractNum); assertNotNull(result); } @@ -121,7 +121,7 @@ void testSearchEOB200WithFalsyArgs() throws IOException{ BFDSearchImpl bfdSearchImpl = new BFDSearchImpl(httpClient, environment, bfdClientVersions); // Business logic & assertion(s) - IBaseBundle result = bfdSearchImpl.searchEOB(patientId, null, 0, bulkJobId, version, contractNum); + IBaseBundle result = bfdSearchImpl.searchEOB(patientId, null, null, 0, bulkJobId, version, contractNum); assertNotNull(result); } @@ -139,7 +139,7 @@ void testSearchEOB404() throws IOException { // Business logic & assertion(s) assertThrows( ResourceNotFoundException.class, - () -> bfdSearchImpl.searchEOB(patientId, since, pageSize, bulkJobId, version, contractNum) + () -> bfdSearchImpl.searchEOB(patientId, since, until, pageSize, bulkJobId, version, contractNum) ); } @@ -157,7 +157,7 @@ void testSearchEOB500() throws IOException { // Business logic & assertion(s) assertThrows( RuntimeException.class, - () -> bfdSearchImpl.searchEOB(patientId, since, pageSize, bulkJobId, version, contractNum) + () -> bfdSearchImpl.searchEOB(patientId, since, until, pageSize, bulkJobId, version, contractNum) ); } diff --git a/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BlueButtonClientSTU3Test.java b/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BlueButtonClientSTU3Test.java index 4a48a50d..832ce59f 100644 --- a/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BlueButtonClientSTU3Test.java +++ b/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/BlueButtonClientSTU3Test.java @@ -200,14 +200,16 @@ void shouldGetEOBFromPatientID() { @Test void shouldGetEOBFromPatientIDSince() { - org.hl7.fhir.dstu3.model.Bundle response = (org.hl7.fhir.dstu3.model.Bundle) bbc.requestEOBFromServer(STU3, TEST_PATIENT_ID, null, CONTRACT); + org.hl7.fhir.dstu3.model.Bundle response = (org.hl7.fhir.dstu3.model.Bundle) bbc.requestEOBFromServer(STU3, TEST_PATIENT_ID, OffsetDateTime.parse( + "2020-02-13T00:00:00.000-05:00", DateTimeFormatter.ISO_DATE_TIME), null, CONTRACT); validation(response); } @Test void shouldGetEOBFromPatientIDUtil() { - org.hl7.fhir.dstu3.model.Bundle response = (org.hl7.fhir.dstu3.model.Bundle) bbc.requestEOBFromServer(STU3, TEST_PATIENT_ID, null, CONTRACT); + org.hl7.fhir.dstu3.model.Bundle response = (org.hl7.fhir.dstu3.model.Bundle) bbc.requestEOBFromServer(STU3, TEST_PATIENT_ID, null, OffsetDateTime.parse( + "2024-02-13T00:00:00.000-05:00", DateTimeFormatter.ISO_DATE_TIME), CONTRACT); validation(response); } @@ -215,7 +217,8 @@ void shouldGetEOBFromPatientIDUtil() { @Test void shouldGetEOBFromPatientIDSinceAndUtil() { org.hl7.fhir.dstu3.model.Bundle response = (org.hl7.fhir.dstu3.model.Bundle) bbc.requestEOBFromServer(STU3, TEST_PATIENT_ID, OffsetDateTime.parse( - "2020-02-13T00:00:00.000-05:00", DateTimeFormatter.ISO_DATE_TIME), CONTRACT); + "2020-02-13T00:00:00.000-05:00", DateTimeFormatter.ISO_DATE_TIME), OffsetDateTime.parse( + "2024-02-13T00:00:00.000-05:00", DateTimeFormatter.ISO_DATE_TIME), CONTRACT); validation(response); } diff --git a/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/FhirBfdServerTest.java b/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/FhirBfdServerTest.java index 37ecea21..b17bcd70 100644 --- a/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/FhirBfdServerTest.java +++ b/ab2d-bfd/src/test/java/gov/cms/ab2d/bfd/client/FhirBfdServerTest.java @@ -11,7 +11,7 @@ class FhirBfdServerTest { @Test void testGetVersion() { - assertEquals(FhirVersion.R4, new FhirBfdServer(FhirVersion.R4).getVersion());; + assertEquals(FhirVersion.R4, new FhirBfdServer(FhirVersion.R4).getVersion()); } @Test diff --git a/ab2d-events-client/build.gradle b/ab2d-events-client/build.gradle index 68866036..8a0535f8 100644 --- a/ab2d-events-client/build.gradle +++ b/ab2d-events-client/build.gradle @@ -3,7 +3,8 @@ dependencies { implementation(platform(annotationProcessor("com.slack.api:slack-api-client:$slackAPIVersion"))) implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}" implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}" - implementation "org.springframework:spring-web:${springBootVersion}" + implementation "org.springframework:spring-web:${springWebVersion}" + implementation "org.springframework:spring-webmvc:${springWebVersion}" implementation "org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}" implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" implementation "io.awspring.cloud:spring-cloud-starter-aws:${springCloudAwsVersion}" @@ -14,7 +15,7 @@ dependencies { implementation "com.slack.api:slack-api-client:${slackAPIVersion}" annotationProcessor "org.projectlombok:lombok:${lombokVersion}" compileOnly "org.projectlombok:lombok:${lombokVersion}" - runtimeOnly "org.postgresql:postgresql:42.6.0" + runtimeOnly 'org.postgresql:postgresql:42.7.3' testCompileOnly "org.projectlombok:lombok:${lombokVersion}" testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" diff --git a/ab2d-fhir/src/main/java/gov/cms/ab2d/fhir/IdentifierUtils.java b/ab2d-fhir/src/main/java/gov/cms/ab2d/fhir/IdentifierUtils.java index a535209c..8e1d5a18 100644 --- a/ab2d-fhir/src/main/java/gov/cms/ab2d/fhir/IdentifierUtils.java +++ b/ab2d-fhir/src/main/java/gov/cms/ab2d/fhir/IdentifierUtils.java @@ -5,6 +5,7 @@ import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.instance.model.api.ICompositeType; import org.hl7.fhir.instance.model.api.IDomainResource; +import org.hl7.fhir.dstu3.model.Coding; import java.util.ArrayList; import java.util.Date; @@ -206,41 +207,59 @@ private static PatientIdentifier.Currency getCurrencyMbiStandard(ICompositeType return getCurrencyFromTypeCodingExtension(identifier); } - private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICompositeType identifier) { + public static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICompositeType identifier) { Object type = Versions.invokeGetMethod(identifier, "getType"); - if (type == null) { - return PatientIdentifier.Currency.UNKNOWN; - } - List vals = (List) Versions.invokeGetMethod(type, "getCoding"); - if (vals == null || vals.isEmpty()) { + List vals = (List) Versions.invokeGetMethod(type, "getCoding"); + + if (checkTypeAndCodingNotExists(type, vals)) { return PatientIdentifier.Currency.UNKNOWN; } + Object val = vals.get(0); String codeSystem = (String) Versions.invokeGetMethod(val, GET_SYSTEM); String codeValue = (String) Versions.invokeGetMethod(val, GET_CODE); - if (codeSystem != null && codeSystem.equalsIgnoreCase(MBI_ID_R4) && ("MB".equalsIgnoreCase(codeValue) || "MC".equalsIgnoreCase(codeValue))) { - List extensions = (List) Versions.invokeGetMethod(val, "getExtension"); - if (extensions != null && extensions.size() > 0) { - Object extension = extensions.get(0); - String url = (String) Versions.invokeGetMethod(extension, "getUrl"); - if (url != null && url.equalsIgnoreCase(CURRENCY_IDENTIFIER)) { - Object currValue = Versions.invokeGetMethod(extension, GET_VALUE); - String extValueSystem = (String) Versions.invokeGetMethod(currValue, GET_SYSTEM); - if (CURRENCY_IDENTIFIER.equalsIgnoreCase(extValueSystem)) { - String currValueCode = (String) Versions.invokeGetMethod(currValue, GET_CODE); - if (CURRENT_MBI.equalsIgnoreCase(currValueCode)) { - return PatientIdentifier.Currency.CURRENT; - } - if (HISTORIC_MBI.equalsIgnoreCase(currValueCode)) { - return PatientIdentifier.Currency.HISTORIC; - } - } - } + + List extensions = (List) Versions.invokeGetMethod(val, "getExtension"); + if (checkCodingIsNotValid(codeSystem, codeValue) || checkExtensionsNotExists(extensions)) { + return PatientIdentifier.Currency.UNKNOWN; + } + + Object extension = extensions.get(0); + String url = (String) Versions.invokeGetMethod(extension, "getUrl"); + if (checkCurrencyUrlIsNotValid(url)) { + return PatientIdentifier.Currency.UNKNOWN; + } + + Object currValue = Versions.invokeGetMethod(extension, GET_VALUE); + String extValueSystem = (String) Versions.invokeGetMethod(currValue, GET_SYSTEM); + if (CURRENCY_IDENTIFIER.equalsIgnoreCase(extValueSystem)) { + String currValueCode = (String) Versions.invokeGetMethod(currValue, GET_CODE); + if (CURRENT_MBI.equalsIgnoreCase(currValueCode)) { + return PatientIdentifier.Currency.CURRENT; + } + if (HISTORIC_MBI.equalsIgnoreCase(currValueCode)) { + return PatientIdentifier.Currency.HISTORIC; } } return PatientIdentifier.Currency.UNKNOWN; } + public static boolean checkTypeAndCodingNotExists(Object type, List vals) { + return (type == null || vals == null || vals.isEmpty()); + } + + public static boolean checkCodingIsNotValid(String codeSystem, String codeValue) { + return (codeSystem == null || !codeSystem.equalsIgnoreCase(MBI_ID_R4)) || (!codeValue.equalsIgnoreCase("MB") && !codeValue.equalsIgnoreCase("MC")); + } + + public static boolean checkExtensionsNotExists(List extensions) { + return (extensions == null || extensions.isEmpty()); + } + + public static boolean checkCurrencyUrlIsNotValid(String url) { + return (url == null || !url.equalsIgnoreCase(CURRENCY_IDENTIFIER)); + } + /** * If the period has a value for the identifier, return the information from that, otherwise UNKNOWN * diff --git a/ab2d-fhir/src/test/java/gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java b/ab2d-fhir/src/test/java/gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java index af4cdd93..997440f9 100644 --- a/ab2d-fhir/src/test/java/gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java +++ b/ab2d-fhir/src/test/java/gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java @@ -2,9 +2,10 @@ import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Coding; -import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.Identifier; import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Extension; +import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.ICompositeType; import org.junit.jupiter.api.Test; @@ -13,6 +14,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.ArrayList; import java.util.Set; import static gov.cms.ab2d.fhir.PatientIdentifier.CURRENT_MBI; @@ -20,6 +22,7 @@ import static gov.cms.ab2d.fhir.PatientIdentifier.Currency.HISTORIC; import static gov.cms.ab2d.fhir.PatientIdentifier.HISTORIC_MBI; import static gov.cms.ab2d.fhir.PatientIdentifier.MBI_ID; +import static gov.cms.ab2d.fhir.PatientIdentifier.MBI_ID_R4; import static gov.cms.ab2d.fhir.IdentifierUtils.CURRENCY_IDENTIFIER; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; @@ -177,6 +180,161 @@ void testGetCurrentMbiWrongType() { assertNull(IdentifierUtils.getCurrentMbi(List.of(patientIdentifier))); } + @Test + void testGetCurrentMbiTypeNotExists() { + PatientIdentifier patientIdentifier = new PatientIdentifier(); + patientIdentifier.setType(null); + patientIdentifier.setValue("test-1"); + assertNull(IdentifierUtils.getCurrentMbi(List.of(patientIdentifier))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsCurrent() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.CURRENT, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsHistoric() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, HISTORIC_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.HISTORIC, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknown() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, "unknown"); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingEmpty() { + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(null, null); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingSystemInvalid() { + Coding coding = setupCodingForTestingCurrencyTypeCode("invalid_system", "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingCodeInvalid() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "invalid_code"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlNull() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(null, extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlInvalid() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode("invalid_url", extCoding); + + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testReturnsTrueIfCodingNotExist() { + PatientIdentifier patientIdentifier = new PatientIdentifier(); + patientIdentifier.setType(PatientIdentifier.Type.MBI); + patientIdentifier.setValue("test-1"); + + Object type = Versions.invokeGetMethod(patientIdentifier, "getType"); + List vals = (List) Versions.invokeGetMethod(type, "getCode"); + + assertTrue(IdentifierUtils.checkTypeAndCodingNotExists(type, vals)); + } + + @Test + void testReturnsTrueIfCodingNotValid() { + assertTrue(IdentifierUtils.checkCodingIsNotValid("invalid_system", "invalid_value")); + } + + @Test + void testReturnsFalseIfCodingValid() { + assertFalse(IdentifierUtils.checkCodingIsNotValid(MBI_ID_R4, "MB")); + assertFalse(IdentifierUtils.checkCodingIsNotValid(MBI_ID_R4, "MC")); + } + + @Test + void testReturnsTrueIfExtensionsNotExists() { + assertTrue(IdentifierUtils.checkExtensionsNotExists(new ArrayList<>())); + } + + @Test + void testReturnsFalseIfExtensionsExists() { + List extensions = new ArrayList<>(); + Extension extension = new Extension(); + extensions.add(extension); + assertFalse(IdentifierUtils.checkExtensionsNotExists(extensions)); + } + + @Test + void testReturnsFalseIfURLValid() { + assertFalse(IdentifierUtils.checkCurrencyUrlIsNotValid(IdentifierUtils.CURRENCY_IDENTIFIER)); + } + + @Test + void testReturnsTrueIfURLInvalid() { + assertTrue(IdentifierUtils.checkCurrencyUrlIsNotValid("invalid_url")); + } + @Test void testR4ExtractIds() throws IOException { List beneIds = List.of("-19990000001101", "-19990000001102", "-19990000001103"); @@ -212,6 +370,42 @@ void testR4ExtractIds() throws IOException { } } + Extension setupExtensionForTestingCurrencyTypeCode(String url, Coding extCoding) { + Extension extension = new Extension(); + extension.setUrl(url); + + if (extCoding != null) { + extension.setValue(extCoding); + } + return extension; + } + + Coding setupCodingForTestingCurrencyTypeCode(String system, String code) { + Coding coding = new Coding(); + coding.setSystem(system); + coding.setCode(code); + return coding; + } + + Identifier setupIdentifierForTestingCurrencyTypeCode(Coding coding, Extension extension) { + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + identifier.setValue("mbi-1"); + if (coding != null) { + identifier.getType().addCoding(coding); + } + if (extension != null) { + identifier.getType().getCoding().get(0).addExtension(extension); + } + return identifier; + } + + Patient setupPatientForTestingCurrencyTypeCode(Identifier identifier) { + Patient patient = new Patient(); + patient.setIdentifier(List.of(identifier)); + return patient; + } + IBaseResource extractBundle(FhirVersion version, String fileName) throws IOException { return version.getJsonParser().parseResource(getRawJson(fileName)); } diff --git a/build.gradle b/build.gradle index 06110c4f..a6b95fe9 100644 --- a/build.gradle +++ b/build.gradle @@ -22,11 +22,11 @@ ext { : System.getenv()['ARTIFACTORY_PASSWORD'] // AB2D libraries - fhirVersion='1.2.6' - bfdVersion='2.2.2' + fhirVersion='1.2.10' + bfdVersion='2.3.0' aggregatorVersion='1.3.4' - filtersVersion='1.9.4' - eventClientVersion='1.12.8' + filtersVersion='1.9.7' + eventClientVersion='1.12.10' propertiesClientVersion='1.2.5' contractClientVersion='1.2.4' snsClientVersion='0.2.4' @@ -40,6 +40,7 @@ ext { hapiVersion = '6.6.2' springBootVersion='2.7.6' springCloudAwsVersion='2.4.4' + springWebVersion="5.3.26" newRelicVersion='8.4.0' testContainerVersion='1.18.3' mockServerVersion='5.15.0'