Skip to content
Closed
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
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
}

dependencies {
api 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:8.0.0'
api 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:8.4.0'
api 'org.springframework.boot:spring-boot-starter-jdbc'
api 'org.springframework.boot:spring-boot-starter-actuator'
api 'org.springframework:spring-web'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ private String normalizeSkeletonXml(String skeletonFileAsString) {
}

private boolean isEntireRcmrSkeleton(String normalizedSkeleton) {
return normalizedSkeleton != null && normalizedSkeleton.startsWith("<RCMR_IN030000UK06");
if (normalizedSkeleton == null || normalizedSkeleton.isBlank()) {
return false;
}

try {
var skeletonDocument = xPathService.parseDocumentFromXml(normalizedSkeleton);
if (skeletonDocument == null) {
return false;
}
var root = skeletonDocument.getDocumentElement();
return root != null && "RCMR_IN030000UK06".equals(root.getLocalName());
} catch (SAXException e) {
return false;
}
}

private InboundMessage insertSkeletonIntoInboundMessagePayload(PatientAttachmentLog skeletonLog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -158,6 +159,11 @@ void When_SkeletonAsWholeRCMRMessageHasLeadingWhitespace_Expect_InboundMessagePa

when(attachmentHandlerService.getAttachment(any(), any())).thenReturn(skeletonMessage.getBytes(StandardCharsets.UTF_8));
when(xmlParseUtilService.getStringFromDocument(any())).thenReturn(readInboundMessagePayloadFromFile());
var document = org.mockito.Mockito.mock(Document.class);
var rootElement = org.mockito.Mockito.mock(Element.class);
when(xPathService.parseDocumentFromXml(any())).thenReturn(document);
when(document.getDocumentElement()).thenReturn(rootElement);
when(rootElement.getLocalName()).thenReturn("RCMR_IN030000UK06");

var newInboundMessage =
skeletonProcessingService.updateInboundMessageWithSkeleton(attachmentLog, inboundMessage, CONVERSATION_ID);
Expand Down Expand Up @@ -187,6 +193,12 @@ void When_IsEntireRcmrSkeletonCalledWithNonRcmrPayload_Expect_ReturnsFalse() thr
var method = SkeletonProcessingService.class.getDeclaredMethod("isEntireRcmrSkeleton", String.class);
method.setAccessible(true);

var document = org.mockito.Mockito.mock(Document.class);
var rootElement = org.mockito.Mockito.mock(Element.class);
when(xPathService.parseDocumentFromXml(any())).thenReturn(document);
when(document.getDocumentElement()).thenReturn(rootElement);
when(rootElement.getLocalName()).thenReturn("MCCI_IN010000UK13");

assertFalse((Boolean) method.invoke(skeletonProcessingService, "<MCCI_IN010000UK13>"));
}

Expand All @@ -197,7 +209,14 @@ void When_NormalizeSkeletonXmlCalledWithXmlDeclaration_Expect_StripsDeclarationB
var isRcmrMethod = SkeletonProcessingService.class.getDeclaredMethod("isEntireRcmrSkeleton", String.class);
isRcmrMethod.setAccessible(true);

var document = org.mockito.Mockito.mock(Document.class);
var rootElement = org.mockito.Mockito.mock(Element.class);
var xmlWithDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<RCMR_IN030000UK06>";

when(xPathService.parseDocumentFromXml(any())).thenReturn(document);
when(document.getDocumentElement()).thenReturn(rootElement);
when(rootElement.getLocalName()).thenReturn("RCMR_IN030000UK06");

var normalized = (String) normalizeMethod.invoke(skeletonProcessingService, xmlWithDeclaration);

assertTrue(normalized.startsWith("<RCMR_IN030000UK06"));
Expand All @@ -216,6 +235,11 @@ void When_SkeletonAsWholeRCMRMessageHasBomPrefix_Expect_InboundMessagePayloadIsN

when(attachmentHandlerService.getAttachment(any(), any())).thenReturn(skeletonMessage.getBytes(StandardCharsets.UTF_8));
when(xmlParseUtilService.getStringFromDocument(any())).thenReturn(readInboundMessagePayloadFromFile());
var document = org.mockito.Mockito.mock(Document.class);
var rootElement = org.mockito.Mockito.mock(Element.class);
when(xPathService.parseDocumentFromXml(any())).thenReturn(document);
when(document.getDocumentElement()).thenReturn(rootElement);
when(rootElement.getLocalName()).thenReturn("RCMR_IN030000UK06");

var newInboundMessage =
skeletonProcessingService.updateInboundMessageWithSkeleton(attachmentLog, inboundMessage, CONVERSATION_ID);
Expand Down
Loading