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 de513c5..6d27fbc 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)); }