Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package uk.nhs.adaptors.common.util;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.hl7.fhir.dstu3.model.Extension;
import org.junit.jupiter.api.Test;

public class CodeableConceptUtilsTest {

@Test
public void shouldCreateCodeableConceptWithTextAndUrnFormattedSystem() {
var codeableConcept = CodeableConceptUtils.createCodeableConcept("123", "1.2.3", "Display value", "Some text");

assertEquals("Some text", codeableConcept.getText());
assertEquals("123", codeableConcept.getCodingFirstRep().getCode());
assertEquals("urn:oid:1.2.3", codeableConcept.getCodingFirstRep().getSystem());
assertEquals("Display value", codeableConcept.getCodingFirstRep().getDisplay());
}

@Test
public void shouldCreateCodeableConceptWithGp2gpSpecificCoding() {
var codeableConcept = CodeableConceptUtils.createCodeableConceptWithEhrRequestAckOidCode(
"INTERNAL_SERVER_ERROR",
"1.2.3",
"Error display",
"Any text",
"25"
);

assertEquals(2, codeableConcept.getCoding().size());
assertEquals("urn:oid:1.2.3", codeableConcept.getCoding().get(0).getSystem());
assertEquals(CodeableConceptUtils.EHR_REQUEST_ACK_CODE_URN, codeableConcept.getCoding().get(1).getSystem());
assertEquals("25", codeableConcept.getCoding().get(1).getCode());
}

@Test
public void shouldCreateCodeableConceptWithExtension() {
var extension = new Extension("https://example.test/extension");

var codeableConcept = CodeableConceptUtils.createCodeableConcept("CODE", "http://system", "Display", "Text", extension);

assertEquals("http://system", codeableConcept.getCodingFirstRep().getSystem());
assertEquals("CODE", codeableConcept.getCodingFirstRep().getCode());
assertEquals(1, codeableConcept.getCodingFirstRep().getExtension().size());
assertEquals("https://example.test/extension", codeableConcept.getCodingFirstRep().getExtensionFirstRep().getUrl());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package uk.nhs.adaptors.common.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class OidUtilTest {

@Test
public void shouldReturnUrnWhenOidIsValid() {
var parsed = OidUtil.tryParseToUrn("1.2.826.1285.2.107");

assertTrue(parsed.isPresent());
assertEquals("urn:oid:1.2.826.1285.2.107", parsed.get());
}

@Test
public void shouldReturnEmptyOptionalWhenOidIsInvalid() {
var parsed = OidUtil.tryParseToUrn("urn:oid:1.2.3");

assertTrue(parsed.isEmpty());
}

@Test
public void shouldDetectValidAndInvalidOids() {
assertTrue(OidUtil.isOid("2.16.840.1.113883.2.1.3.2.4.17.101"));
assertFalse(OidUtil.isOid(""));
assertFalse(OidUtil.isOid("0.0"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class JmsListenerErrorHandler implements ErrorHandler {
public void handleError(Throwable t) {

LOGGER.error("Handling JMS message error due to [{}] with message [{}]", t.getClass(), t.getMessage());
t.printStackTrace();
LOGGER.error("JMS error detail", t);

Throwable cause = t.getCause();
if (cause == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Bundle mapToBundle(RCMRIN030000UKMessage xmlMessage, String losingPractic

return bundle;
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Bundle mapping failed", e);
throw new BundleMappingException(e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class EhrExtractRequestService {
private final IdGeneratorService idGeneratorService;

public String buildEhrExtractRequest(TransferRequestMessage transferRequestMessage, String messageId) {
LOGGER.debug("Building EHRExtractRequest with nhsNumber=[{}]", transferRequestMessage.getPatientNhsNumber());
LOGGER.debug("Building EHRExtractRequest");

SendEhrExtractRequestParams params = SendEhrExtractRequestParams.builder()
.messageId(messageId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package uk.nhs.adaptors.pss.gpc.util.fhir;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.hl7.fhir.dstu3.model.Extension;
import org.junit.jupiter.api.Test;
Expand All @@ -21,27 +22,28 @@ public void When_CreateCodeableConcept_Expect_CodeableConceptIsCreatedCorrectly(
final var result = CodeableConceptUtils.createCodeableConcept(CODE, ISSUE_SYSTEM, DISPLAY, TEXT);

assertAll(
() -> assertThat(result.getCodingFirstRep().getCode()).isEqualTo(CODE),
() -> assertThat(result.getCodingFirstRep().getSystem()).isEqualTo(ISSUE_SYSTEM),
() -> assertThat(result.getCodingFirstRep().getDisplay()).isEqualTo(DISPLAY),
() -> assertThat(result.getText()).isEqualTo(TEXT)
() -> assertEquals(CODE, result.getCodingFirstRep().getCode()),
() -> assertEquals(ISSUE_SYSTEM, result.getCodingFirstRep().getSystem()),
() -> assertEquals(DISPLAY, result.getCodingFirstRep().getDisplay()),
() -> assertEquals(TEXT, result.getText())
);
}

@Test
public void When_CreateCodeableConceptWithOidAsSystem_Expect_CreatedCodeableConceptContainsOidAsUrn() {
final var system = "1.2.3.4.5";
final var expectedSystem = "urn:oid:1.2.3.4.5";

final var result = CodeableConceptUtils.createCodeableConcept(CODE, system, DISPLAY, TEXT);

assertThat(result.getCodingFirstRep().getSystem()).isEqualTo(expectedSystem);
assertEquals(expectedSystem, result.getCodingFirstRep().getSystem());
}

@Test
public void When_CreateCodeableConceptWithNullText_Expect_CreatedCodeableConceptDoesNotContainText() {
final var result = CodeableConceptUtils.createCodeableConcept(CODE, ISSUE_SYSTEM, DISPLAY, null);

assertThat(result.getText()).isNull();
assertNull(result.getText());
}

@Test
Expand All @@ -56,7 +58,7 @@ public void When_CreateCodeableConceptWithExtension_Expect_CreatedCodeableContai
null,
extension);

assertThat(result.getCoding().getFirst().getExtension().getFirst().getUrlElement().getValue()).isEqualTo(EXTENSION_URL);
assertEquals(EXTENSION_URL, result.getCoding().getFirst().getExtension().getFirst().getUrlElement().getValue());
}

@Test
Expand All @@ -71,12 +73,12 @@ public void When_CreateCodeableConceptWithEhrRequestAckOidCode_Expect_CodeableCo
final var actualEhrRequestAckCoding = result.getCoding().get(1);

assertAll(
() -> assertThat(actualBaseCoding.getSystem()).isEqualTo(ISSUE_SYSTEM),
() -> assertThat(actualBaseCoding.getCode()).isEqualTo(CODE),
() -> assertThat(actualBaseCoding.getDisplay()).isEqualTo(DISPLAY),
() -> assertThat(actualEhrRequestAckCoding.getSystem()).isEqualTo(EHR_REQUEST_ACK_OID_URN),
() -> assertThat(actualEhrRequestAckCoding.getCode()).isEqualTo(GP2GP_SPECIFIC_CODE),
() -> assertThat(actualEhrRequestAckCoding.getDisplay()).isEqualTo(DISPLAY)
() -> assertEquals(ISSUE_SYSTEM, actualBaseCoding.getSystem()),
() -> assertEquals(CODE, actualBaseCoding.getCode()),
() -> assertEquals(DISPLAY, actualBaseCoding.getDisplay()),
() -> assertEquals(EHR_REQUEST_ACK_OID_URN, actualEhrRequestAckCoding.getSystem()),
() -> assertEquals(GP2GP_SPECIFIC_CODE, actualEhrRequestAckCoding.getCode()),
() -> assertEquals(DISPLAY, actualEhrRequestAckCoding.getDisplay())
);
}

Expand All @@ -92,6 +94,6 @@ public void When_CreateCodeableConceptWithEhrRequestAckOidCodeWithSystemOid_Expe
null,
GP2GP_SPECIFIC_CODE);

assertThat(result.getCoding().getFirst().getSystem()).isEqualTo(expectedSystem);
assertEquals(expectedSystem, result.getCoding().getFirst().getSystem());
}
}
Loading