Skip to content

Commit

Permalink
add setup methods in test to reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Rwolfe-Nava committed Jul 18, 2024
1 parent 43e9027 commit 4b91367
Showing 1 changed file with 81 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 4b91367

Please sign in to comment.