From 5e2c42a2b651f3858657e9f1108f129f87879d5b Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Tue, 16 Jul 2024 09:59:29 -0400 Subject: [PATCH 01/13] initial commit - first pass at reducing method complexity --- .../gov/cms/ab2d/fhir/IdentifierUtils.java | 76 ++++++++++++++----- 1 file changed, 55 insertions(+), 21 deletions(-) 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..35055c72 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 @@ -208,37 +208,71 @@ private static PatientIdentifier.Currency getCurrencyMbiStandard(ICompositeType private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICompositeType identifier) { Object type = Versions.invokeGetMethod(identifier, "getType"); - if (type == null) { + List vals = (List) Versions.invokeGetMethod(type, "getCoding"); + + if (checkTypeAndValsExists(type, vals)) { return PatientIdentifier.Currency.UNKNOWN; } - List vals = (List) Versions.invokeGetMethod(type, "getCoding"); - if (vals == null || vals.isEmpty()) { + + if (!checkCodeSystemAndValueIsValid()) { return PatientIdentifier.Currency.UNKNOWN; } + + Object val = vals.get(0); + List extensions = (List) Versions.invokeGetMethod(val, "getExtension"); + + if (!checkExtensionsHasValidUrl()) { + return PatientIdentifier.Currency.UNKNOWN; + } + + Object extension = extensions.get(0); + 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; + } + + private static boolean checkTypeAndValsExists(Object type, List vals) { + if (type == null) { + return true; + } + if (vals == null || vals.isEmpty()) { + return true; + } + return false; + } + + private static boolean checkCodeSystemAndValueIsValid(List vals) { + if (vals == null || vals.isEmpty()) { + return false; + } + 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; - } - } - } + return true; + } + return false; + } + + private static boolean checkExtensionsHasValidUrl(List extensions) { + if (extensions != null && !extensions.isEmpty()) { + Object extension = extensions.get(0); + String url = (String) Versions.invokeGetMethod(extension, "getUrl"); + if (url != null && url.equalsIgnoreCase(CURRENCY_IDENTIFIER)) { + return true; } } - return PatientIdentifier.Currency.UNKNOWN; + return false; } /** From d50c40049e30a0ed09370a3d58a708ab1d5c370c Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 10:51:13 -0400 Subject: [PATCH 02/13] add missing args --- .../src/main/java/gov/cms/ab2d/fhir/IdentifierUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 35055c72..cd34ab05 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 @@ -214,14 +214,14 @@ private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICo return PatientIdentifier.Currency.UNKNOWN; } - if (!checkCodeSystemAndValueIsValid()) { + if (!checkCodeSystemAndValueIsValid(vals)) { return PatientIdentifier.Currency.UNKNOWN; } Object val = vals.get(0); List extensions = (List) Versions.invokeGetMethod(val, "getExtension"); - if (!checkExtensionsHasValidUrl()) { + if (!checkExtensionsHasValidUrl(extensions)) { return PatientIdentifier.Currency.UNKNOWN; } From 1f32956c7a4c5de8098109d10585b837b117f725 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 12:22:29 -0400 Subject: [PATCH 03/13] first pass at tests --- .../gov/cms/ab2d/fhir/IdentifierUtils.java | 16 +++++++------- .../ab2d/fhir/PatientIdentifierUtilsTest.java | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) 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 cd34ab05..e9a5bb8d 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 @@ -210,11 +210,11 @@ private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICo Object type = Versions.invokeGetMethod(identifier, "getType"); List vals = (List) Versions.invokeGetMethod(type, "getCoding"); - if (checkTypeAndValsExists(type, vals)) { + if (!checkTypeAndCodingExists(type, vals)) { return PatientIdentifier.Currency.UNKNOWN; } - if (!checkCodeSystemAndValueIsValid(vals)) { + if (!checkCodingIsValid(vals)) { return PatientIdentifier.Currency.UNKNOWN; } @@ -240,17 +240,17 @@ private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICo return PatientIdentifier.Currency.UNKNOWN; } - private static boolean checkTypeAndValsExists(Object type, List vals) { + public static boolean checkTypeAndCodingExists(Object type, List vals) { if (type == null) { - return true; + return false; } if (vals == null || vals.isEmpty()) { - return true; + return false; } - return false; + return true; } - private static boolean checkCodeSystemAndValueIsValid(List vals) { + public static boolean checkCodingIsValid(List vals) { if (vals == null || vals.isEmpty()) { return false; } @@ -264,7 +264,7 @@ private static boolean checkCodeSystemAndValueIsValid(List vals) { return false; } - private static boolean checkExtensionsHasValidUrl(List extensions) { + public static boolean checkExtensionsHasValidUrl(List extensions) { if (extensions != null && !extensions.isEmpty()) { Object extension = extensions.get(0); String url = (String) Versions.invokeGetMethod(extension, "getUrl"); 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..1b907d3b 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 @@ -177,6 +177,28 @@ 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 testReturnsFalseIfCodingNotExist() { + PatientIdentifier patientIdentifier = new PatientIdentifier(); + patientIdentifier.setType(PatientIdentifier.Type.MBI); + patientIdentifier.setValue("test-1"); + patientIdentifier.setCurrency(PatientIdentifier.Currency.UNKNOWN); + + Object type = Versions.invokeGetMethod(patientIdentifier, "getType"); + List vals = (List) Versions.invokeGetMethod(type, "getCoding"); + System.out.println("TEST-VALS = " + vals); + + assertFalse(IdentifierUtils.checkTypeAndCodingExists(type, vals)); + } + @Test void testR4ExtractIds() throws IOException { List beneIds = List.of("-19990000001101", "-19990000001102", "-19990000001103"); From 4c28adeab282c811eaa23f6cce52978abe2ea806 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 13:49:36 -0400 Subject: [PATCH 04/13] update tests and address codesmells --- .../gov/cms/ab2d/fhir/IdentifierUtils.java | 49 ++++++------------- .../ab2d/fhir/PatientIdentifierUtilsTest.java | 33 +++++++++++-- 2 files changed, 46 insertions(+), 36 deletions(-) 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 e9a5bb8d..d6fc2eb8 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 @@ -214,18 +214,24 @@ private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICo return PatientIdentifier.Currency.UNKNOWN; } - if (!checkCodingIsValid(vals)) { + Object val = vals.get(0); + String codeSystem = (String) Versions.invokeGetMethod(val, GET_SYSTEM); + String codeValue = (String) Versions.invokeGetMethod(val, GET_CODE); + if (!checkCodingIsValid(codeSystem, codeValue)) { return PatientIdentifier.Currency.UNKNOWN; } - Object val = vals.get(0); List extensions = (List) Versions.invokeGetMethod(val, "getExtension"); - - if (!checkExtensionsHasValidUrl(extensions)) { + if (extensions == null || extensions.isEmpty()) { return PatientIdentifier.Currency.UNKNOWN; } - + Object extension = extensions.get(0); + String url = (String) Versions.invokeGetMethod(extension, "getUrl"); + if (!checkCurrencyUrlIsValid(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)) { @@ -241,38 +247,15 @@ private static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICo } public static boolean checkTypeAndCodingExists(Object type, List vals) { - if (type == null) { - return false; - } - if (vals == null || vals.isEmpty()) { - return false; - } - return true; + return (type != null && vals != null && !vals.isEmpty()); } - public static boolean checkCodingIsValid(List vals) { - if (vals == null || vals.isEmpty()) { - return false; - } - - 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))) { - return true; - } - return false; + public static boolean checkCodingIsValid(String codeSystem, String codeValue) { + return ((codeSystem != null && codeSystem.equalsIgnoreCase(MBI_ID_R4)) && ("MB".equalsIgnoreCase(codeValue) || "MC".equalsIgnoreCase(codeValue))); } - public static boolean checkExtensionsHasValidUrl(List extensions) { - if (extensions != null && !extensions.isEmpty()) { - Object extension = extensions.get(0); - String url = (String) Versions.invokeGetMethod(extension, "getUrl"); - if (url != null && url.equalsIgnoreCase(CURRENCY_IDENTIFIER)) { - return true; - } - } - return false; + public static boolean checkCurrencyUrlIsValid(String url) { + return (url != null && url.equalsIgnoreCase(CURRENCY_IDENTIFIER)); } /** 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 1b907d3b..c9a09a7d 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 @@ -20,6 +20,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; @@ -190,15 +191,41 @@ void testReturnsFalseIfCodingNotExist() { PatientIdentifier patientIdentifier = new PatientIdentifier(); patientIdentifier.setType(PatientIdentifier.Type.MBI); patientIdentifier.setValue("test-1"); - patientIdentifier.setCurrency(PatientIdentifier.Currency.UNKNOWN); Object type = Versions.invokeGetMethod(patientIdentifier, "getType"); - List vals = (List) Versions.invokeGetMethod(type, "getCoding"); - System.out.println("TEST-VALS = " + vals); + List vals = (List) Versions.invokeGetMethod(type, "getCode"); assertFalse(IdentifierUtils.checkTypeAndCodingExists(type, vals)); } + @Test + void testReturnsFalseIfCodingInvalid() { + String codeSystem = "INVALID"; + String codeValue = "INVALID"; + assertFalse(IdentifierUtils.checkCodingIsValid(codeSystem, codeValue)); + } + + @Test + void testReturnsTrueIfCodingValid() { + String codeSystem = MBI_ID_R4; + String mbCodeValue = "MB"; + assertTrue(IdentifierUtils.checkCodingIsValid(codeSystem, mbCodeValue)); + String mcCodeValue = "MC"; + assertTrue(IdentifierUtils.checkCodingIsValid(codeSystem, mcCodeValue)); + } + + @Test + void testReturnsTrueIfURLValid() { + String url = IdentifierUtils.CURRENCY_IDENTIFIER; + assertTrue(IdentifierUtils.checkCurrencyUrlIsValid(url)); + } + + @Test + void testReturnsFalseIfURLInvalid() { + String url = "INVALID"; + assertFalse(IdentifierUtils.checkCurrencyUrlIsValid(url)); + } + @Test void testR4ExtractIds() throws IOException { List beneIds = List.of("-19990000001101", "-19990000001102", "-19990000001103"); From 38a9bef661130a56824fb175724c20c83f1687e9 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 17:43:06 -0400 Subject: [PATCH 05/13] update tests --- .../gov/cms/ab2d/fhir/IdentifierUtils.java | 2 +- .../ab2d/fhir/PatientIdentifierUtilsTest.java | 177 +++++++++++++++++- 2 files changed, 175 insertions(+), 4 deletions(-) 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 d6fc2eb8..aaaa4c73 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 @@ -206,7 +206,7 @@ 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"); List vals = (List) Versions.invokeGetMethod(type, "getCoding"); 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 c9a09a7d..9bfe9016 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 @@ -186,6 +186,177 @@ void testGetCurrentMbiTypeNotExists() { assertNull(IdentifierUtils.getCurrentMbi(List.of(patientIdentifier))); } + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsCurrent() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + Coding coding = new Coding(); + coding.setSystem(MBI_ID_R4); + coding.setCode("MB"); + identifier.getType().addCoding(coding); + + identifier.setValue("mbi-1"); + + Extension extension = new Extension(); + extension.setUrl(CURRENCY_IDENTIFIER); + Coding extCoding = new Coding(); + extCoding.setSystem(CURRENCY_IDENTIFIER); + extCoding.setCode(CURRENT_MBI); + extension.setValue(extCoding); + identifier.getType().getCoding().get(0).addExtension(extension); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.CURRENT, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsHistoric() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + Coding coding = new Coding(); + coding.setSystem(MBI_ID_R4); + coding.setCode("MB"); + identifier.getType().addCoding(coding); + + identifier.setValue("mbi-1"); + + Extension extension = new Extension(); + extension.setUrl(CURRENCY_IDENTIFIER); + Coding extCoding = new Coding(); + extCoding.setSystem(CURRENCY_IDENTIFIER); + extCoding.setCode(HISTORIC_MBI); + extension.setValue(extCoding); + identifier.getType().getCoding().get(0).addExtension(extension); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.HISTORIC, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknown() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + Coding coding = new Coding(); + coding.setSystem(MBI_ID_R4); + coding.setCode("MB"); + identifier.getType().addCoding(coding); + + identifier.setValue("mbi-1"); + + Extension extension = new Extension(); + extension.setUrl(CURRENCY_IDENTIFIER); + Coding extCoding = new Coding(); + extCoding.setSystem(CURRENCY_IDENTIFIER); + extCoding.setCode("unknown"); + extension.setValue(extCoding); + identifier.getType().getCoding().get(0).addExtension(extension); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingEmpty() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingInvalid() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + Coding coding = new Coding(); + coding.setSystem("invalid_system"); + coding.setCode("MB"); + identifier.getType().addCoding(coding); + + identifier.setValue("mbi-1"); + + Extension extension = new Extension(); + extension.setUrl(CURRENCY_IDENTIFIER); + Coding extCoding = new Coding(); + extCoding.setSystem(CURRENCY_IDENTIFIER); + extCoding.setCode(CURRENT_MBI); + extension.setValue(extCoding); + identifier.getType().getCoding().get(0).addExtension(extension); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + + coding.setSystem(MBI_ID_R4); + coding.setCode("invalid_code"); + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlNull() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + Coding coding = new Coding(); + coding.setSystem(MBI_ID_R4); + coding.setCode("MB"); + identifier.getType().addCoding(coding); + + identifier.setValue("mbi-1"); + + Extension extension = new Extension(); + extension.setUrl(null); + Coding extCoding = new Coding(); + extCoding.setSystem(CURRENCY_IDENTIFIER); + extCoding.setCode(CURRENT_MBI); + extension.setValue(extCoding); + identifier.getType().getCoding().get(0).addExtension(extension); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlInvalid() { + Patient patient = new Patient(); + Identifier identifier = new Identifier(); + identifier.setSystem(MBI_ID); + + Coding coding = new Coding(); + coding.setSystem(MBI_ID_R4); + coding.setCode("MB"); + identifier.getType().addCoding(coding); + + identifier.setValue("mbi-1"); + + Extension extension = new Extension(); + extension.setUrl("invalid_url"); + Coding extCoding = new Coding(); + extCoding.setSystem(CURRENCY_IDENTIFIER); + extCoding.setCode(CURRENT_MBI); + extension.setValue(extCoding); + identifier.getType().getCoding().get(0).addExtension(extension); + + patient.setIdentifier(List.of(identifier)); + + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + } + @Test void testReturnsFalseIfCodingNotExist() { PatientIdentifier patientIdentifier = new PatientIdentifier(); @@ -200,8 +371,8 @@ void testReturnsFalseIfCodingNotExist() { @Test void testReturnsFalseIfCodingInvalid() { - String codeSystem = "INVALID"; - String codeValue = "INVALID"; + String codeSystem = "invalid_system"; + String codeValue = "invalid_value"; assertFalse(IdentifierUtils.checkCodingIsValid(codeSystem, codeValue)); } @@ -222,7 +393,7 @@ void testReturnsTrueIfURLValid() { @Test void testReturnsFalseIfURLInvalid() { - String url = "INVALID"; + String url = "invalid_url"; assertFalse(IdentifierUtils.checkCurrencyUrlIsValid(url)); } From 2df4c0cbae793c0406bd1b901f43e037430126b0 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 17:58:36 -0400 Subject: [PATCH 06/13] parameterize generic --- .../src/main/java/gov/cms/ab2d/fhir/IdentifierUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 aaaa4c73..8d7024b4 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; @@ -208,7 +209,7 @@ private static PatientIdentifier.Currency getCurrencyMbiStandard(ICompositeType public static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICompositeType identifier) { Object type = Versions.invokeGetMethod(identifier, "getType"); - List vals = (List) Versions.invokeGetMethod(type, "getCoding"); + List vals = (List) Versions.invokeGetMethod(type, "getCoding"); if (!checkTypeAndCodingExists(type, vals)) { return PatientIdentifier.Currency.UNKNOWN; @@ -246,7 +247,7 @@ public static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICom return PatientIdentifier.Currency.UNKNOWN; } - public static boolean checkTypeAndCodingExists(Object type, List vals) { + public static boolean checkTypeAndCodingExists(Object type, List vals) { return (type != null && vals != null && !vals.isEmpty()); } From 98553426501395f9f5aef4e25cdc7233a3e9d6dc Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 18:14:27 -0400 Subject: [PATCH 07/13] bump fhirVersion --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 06110c4f..2f77dcd9 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ ext { : System.getenv()['ARTIFACTORY_PASSWORD'] // AB2D libraries - fhirVersion='1.2.6' + fhirVersion='1.2.7' bfdVersion='2.2.2' aggregatorVersion='1.3.4' filtersVersion='1.9.4' From 63a91c8e7ac4702984c5c84fa9bebb8318081789 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Wed, 17 Jul 2024 22:09:36 -0400 Subject: [PATCH 08/13] update based on review feedback --- .../gov/cms/ab2d/fhir/IdentifierUtils.java | 27 +++++++------ .../ab2d/fhir/PatientIdentifierUtilsTest.java | 40 +++++++++++++------ 2 files changed, 42 insertions(+), 25 deletions(-) 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 8d7024b4..0731307e 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 @@ -211,25 +211,22 @@ public static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICom Object type = Versions.invokeGetMethod(identifier, "getType"); List vals = (List) Versions.invokeGetMethod(type, "getCoding"); - if (!checkTypeAndCodingExists(type, vals)) { + 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 (!checkCodingIsValid(codeSystem, codeValue)) { - return PatientIdentifier.Currency.UNKNOWN; - } - List extensions = (List) Versions.invokeGetMethod(val, "getExtension"); - if (extensions == null || extensions.isEmpty()) { + 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 (!checkCurrencyUrlIsValid(url)) { + if (checkCurrencyUrlIsNotValid(url)) { return PatientIdentifier.Currency.UNKNOWN; } @@ -247,16 +244,20 @@ public static PatientIdentifier.Currency getCurrencyFromTypeCodingExtension(ICom return PatientIdentifier.Currency.UNKNOWN; } - public static boolean checkTypeAndCodingExists(Object type, List vals) { - return (type != null && vals != null && !vals.isEmpty()); + 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 checkCodingIsValid(String codeSystem, String codeValue) { - return ((codeSystem != null && codeSystem.equalsIgnoreCase(MBI_ID_R4)) && ("MB".equalsIgnoreCase(codeValue) || "MC".equalsIgnoreCase(codeValue))); + public static boolean checkExtensionsNotExists(List extensions) { + return (extensions == null || extensions.isEmpty()); } - public static boolean checkCurrencyUrlIsValid(String url) { - return (url != null && url.equalsIgnoreCase(CURRENCY_IDENTIFIER)); + public static boolean checkCurrencyUrlIsNotValid(String url) { + return (url == null || !url.equalsIgnoreCase(CURRENCY_IDENTIFIER)); } /** 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 9bfe9016..71a21ad2 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; @@ -358,43 +360,57 @@ void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlInvalid() { } @Test - void testReturnsFalseIfCodingNotExist() { + 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"); + List vals = (List) Versions.invokeGetMethod(type, "getCode"); - assertFalse(IdentifierUtils.checkTypeAndCodingExists(type, vals)); + assertTrue(IdentifierUtils.checkTypeAndCodingNotExists(type, vals)); } @Test - void testReturnsFalseIfCodingInvalid() { + void testReturnsTrueIfCodingNotValid() { String codeSystem = "invalid_system"; String codeValue = "invalid_value"; - assertFalse(IdentifierUtils.checkCodingIsValid(codeSystem, codeValue)); + assertTrue(IdentifierUtils.checkCodingIsNotValid(codeSystem, codeValue)); } @Test - void testReturnsTrueIfCodingValid() { + void testReturnsFalseIfCodingValid() { String codeSystem = MBI_ID_R4; String mbCodeValue = "MB"; - assertTrue(IdentifierUtils.checkCodingIsValid(codeSystem, mbCodeValue)); + assertFalse(IdentifierUtils.checkCodingIsNotValid(codeSystem, mbCodeValue)); String mcCodeValue = "MC"; - assertTrue(IdentifierUtils.checkCodingIsValid(codeSystem, mcCodeValue)); + assertFalse(IdentifierUtils.checkCodingIsNotValid(codeSystem, mcCodeValue)); + } + + @Test + void testReturnsTrueIfExtensionsNotExists() { + List extensions = new ArrayList<>(); + assertTrue(IdentifierUtils.checkExtensionsNotExists(extensions)); + } + + @Test + void testReturnsFalseIfExtensionsExists() { + List extensions = new ArrayList<>(); + Extension extension = new Extension(); + extensions.add(extension); + assertFalse(IdentifierUtils.checkExtensionsNotExists(extensions)); } @Test - void testReturnsTrueIfURLValid() { + void testReturnsFalseIfURLValid() { String url = IdentifierUtils.CURRENCY_IDENTIFIER; - assertTrue(IdentifierUtils.checkCurrencyUrlIsValid(url)); + assertFalse(IdentifierUtils.checkCurrencyUrlIsNotValid(url)); } @Test void testReturnsFalseIfURLInvalid() { String url = "invalid_url"; - assertFalse(IdentifierUtils.checkCurrencyUrlIsValid(url)); + assertTrue(IdentifierUtils.checkCurrencyUrlIsNotValid(url)); } @Test From 43e9027747c02d20eedb3273f8604779689e29ca Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Thu, 18 Jul 2024 11:23:58 -0400 Subject: [PATCH 09/13] fix test method name --- .../test/java/gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 71a21ad2..de513c5f 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 @@ -408,7 +408,7 @@ void testReturnsFalseIfURLValid() { } @Test - void testReturnsFalseIfURLInvalid() { + void testReturnsTrueIfURLInvalid() { String url = "invalid_url"; assertTrue(IdentifierUtils.checkCurrencyUrlIsNotValid(url)); } From 4b91367e33c89eb0ddb9b018d15881f78cb77f12 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Thu, 18 Jul 2024 12:29:17 -0400 Subject: [PATCH 10/13] add setup methods in test to reduce code duplication --- .../ab2d/fhir/PatientIdentifierUtilsTest.java | 196 ++++++++---------- 1 file changed, 81 insertions(+), 115 deletions(-) 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 de513c5f..6d27fbcc 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 @@ -190,171 +190,101 @@ void testGetCurrentMbiTypeNotExists() { @Test void testGetCurrencyFromTypeCodingExtensionReturnsCurrent() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); - Coding coding = new Coding(); - coding.setSystem(MBI_ID_R4); - coding.setCode("MB"); - identifier.getType().addCoding(coding); + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); - identifier.setValue("mbi-1"); - - Extension extension = new Extension(); - extension.setUrl(CURRENCY_IDENTIFIER); - Coding extCoding = new Coding(); - extCoding.setSystem(CURRENCY_IDENTIFIER); - extCoding.setCode(CURRENT_MBI); - extension.setValue(extCoding); - identifier.getType().getCoding().get(0).addExtension(extension); - - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.CURRENT, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @Test void testGetCurrencyFromTypeCodingExtensionReturnsHistoric() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); - - Coding coding = new Coding(); - coding.setSystem(MBI_ID_R4); - coding.setCode("MB"); - identifier.getType().addCoding(coding); + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); - identifier.setValue("mbi-1"); - - Extension extension = new Extension(); - extension.setUrl(CURRENCY_IDENTIFIER); - Coding extCoding = new Coding(); - extCoding.setSystem(CURRENCY_IDENTIFIER); - extCoding.setCode(HISTORIC_MBI); - extension.setValue(extCoding); - identifier.getType().getCoding().get(0).addExtension(extension); + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, HISTORIC_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.HISTORIC, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @Test void testGetCurrencyFromTypeCodingExtensionReturnsUnknown() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); - Coding coding = new Coding(); - coding.setSystem(MBI_ID_R4); - coding.setCode("MB"); - identifier.getType().addCoding(coding); - - identifier.setValue("mbi-1"); - - Extension extension = new Extension(); - extension.setUrl(CURRENCY_IDENTIFIER); - Coding extCoding = new Coding(); - extCoding.setSystem(CURRENCY_IDENTIFIER); - extCoding.setCode("unknown"); - extension.setValue(extCoding); - identifier.getType().getCoding().get(0).addExtension(extension); + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, "unknown"); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @Test void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingEmpty() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); - - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(null, null); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @Test - void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingInvalid() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingSystemInvalid() { + Coding coding = setupCodingForTestingCurrencyTypeCode("invalid_system", "MB"); + + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); - Coding coding = new Coding(); - coding.setSystem("invalid_system"); - coding.setCode("MB"); - identifier.getType().addCoding(coding); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); - identifier.setValue("mbi-1"); + assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); + + } + + @Test + void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenCodingCodeInvalid() { + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "invalid_code"); - Extension extension = new Extension(); - extension.setUrl(CURRENCY_IDENTIFIER); - Coding extCoding = new Coding(); - extCoding.setSystem(CURRENCY_IDENTIFIER); - extCoding.setCode(CURRENT_MBI); - extension.setValue(extCoding); - identifier.getType().getCoding().get(0).addExtension(extension); + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, extCoding); - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); - coding.setSystem(MBI_ID_R4); - coding.setCode("invalid_code"); - assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @Test void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlNull() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); - - Coding coding = new Coding(); - coding.setSystem(MBI_ID_R4); - coding.setCode("MB"); - identifier.getType().addCoding(coding); - - identifier.setValue("mbi-1"); + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); - Extension extension = new Extension(); - extension.setUrl(null); - Coding extCoding = new Coding(); - extCoding.setSystem(CURRENCY_IDENTIFIER); - extCoding.setCode(CURRENT_MBI); - extension.setValue(extCoding); - identifier.getType().getCoding().get(0).addExtension(extension); + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode(null, extCoding); - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @Test void testGetCurrencyFromTypeCodingExtensionReturnsUnknownWhenUrlInvalid() { - Patient patient = new Patient(); - Identifier identifier = new Identifier(); - identifier.setSystem(MBI_ID); - - Coding coding = new Coding(); - coding.setSystem(MBI_ID_R4); - coding.setCode("MB"); - identifier.getType().addCoding(coding); - - identifier.setValue("mbi-1"); + Coding coding = setupCodingForTestingCurrencyTypeCode(MBI_ID_R4, "MB"); - Extension extension = new Extension(); - extension.setUrl("invalid_url"); - Coding extCoding = new Coding(); - extCoding.setSystem(CURRENCY_IDENTIFIER); - extCoding.setCode(CURRENT_MBI); - extension.setValue(extCoding); - identifier.getType().getCoding().get(0).addExtension(extension); + Coding extCoding = setupCodingForTestingCurrencyTypeCode(CURRENCY_IDENTIFIER, CURRENT_MBI); + Extension extension = setupExtensionForTestingCurrencyTypeCode("invalid_url", extCoding); - patient.setIdentifier(List.of(identifier)); + Identifier identifier = setupIdentifierForTestingCurrencyTypeCode(coding, extension); + Patient patient = setupPatientForTestingCurrencyTypeCode(identifier); assertEquals(PatientIdentifier.Currency.UNKNOWN, IdentifierUtils.getCurrencyFromTypeCodingExtension(patient.getIdentifier().get(0))); } @@ -448,6 +378,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)); } From dadf0a5c9f7d807e17a6792d2fdd619134b28c2a Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Thu, 18 Jul 2024 12:35:45 -0400 Subject: [PATCH 11/13] remove redundant variables --- .../gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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 6d27fbcc..ae2fe7e5 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 @@ -303,9 +303,7 @@ void testReturnsTrueIfCodingNotExist() { @Test void testReturnsTrueIfCodingNotValid() { - String codeSystem = "invalid_system"; - String codeValue = "invalid_value"; - assertTrue(IdentifierUtils.checkCodingIsNotValid(codeSystem, codeValue)); + assertTrue(IdentifierUtils.checkCodingIsNotValid("invalid_system", "invalid_value")); } @Test @@ -333,14 +331,12 @@ void testReturnsFalseIfExtensionsExists() { @Test void testReturnsFalseIfURLValid() { - String url = IdentifierUtils.CURRENCY_IDENTIFIER; - assertFalse(IdentifierUtils.checkCurrencyUrlIsNotValid(url)); + assertFalse(IdentifierUtils.checkCurrencyUrlIsNotValid(IdentifierUtils.CURRENCY_IDENTIFIER)); } @Test void testReturnsTrueIfURLInvalid() { - String url = "invalid_url"; - assertTrue(IdentifierUtils.checkCurrencyUrlIsNotValid(url)); + assertTrue(IdentifierUtils.checkCurrencyUrlIsNotValid("invalid_url")); } @Test From 64c8d14e0b0d4047fa54f2eb214a1ff1d79ac06a Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Thu, 18 Jul 2024 12:38:02 -0400 Subject: [PATCH 12/13] remove more redundant variables --- .../gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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 ae2fe7e5..fd4e2be2 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 @@ -308,17 +308,13 @@ void testReturnsTrueIfCodingNotValid() { @Test void testReturnsFalseIfCodingValid() { - String codeSystem = MBI_ID_R4; - String mbCodeValue = "MB"; - assertFalse(IdentifierUtils.checkCodingIsNotValid(codeSystem, mbCodeValue)); - String mcCodeValue = "MC"; - assertFalse(IdentifierUtils.checkCodingIsNotValid(codeSystem, mcCodeValue)); + assertFalse(IdentifierUtils.checkCodingIsNotValid(MBI_ID_R4, "MB")); + assertFalse(IdentifierUtils.checkCodingIsNotValid(MBI_ID_R4, "MC")); } @Test void testReturnsTrueIfExtensionsNotExists() { - List extensions = new ArrayList<>(); - assertTrue(IdentifierUtils.checkExtensionsNotExists(extensions)); + assertTrue(IdentifierUtils.checkExtensionsNotExists(new ArrayList()<>)); } @Test From 4e5e0c50bdd4061019bbd66a6d3d61fa429ae569 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Thu, 18 Jul 2024 12:44:19 -0400 Subject: [PATCH 13/13] fix generic so sonar is happy --- .../test/java/gov/cms/ab2d/fhir/PatientIdentifierUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fd4e2be2..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 @@ -314,7 +314,7 @@ void testReturnsFalseIfCodingValid() { @Test void testReturnsTrueIfExtensionsNotExists() { - assertTrue(IdentifierUtils.checkExtensionsNotExists(new ArrayList()<>)); + assertTrue(IdentifierUtils.checkExtensionsNotExists(new ArrayList<>())); } @Test