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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import uk.nhs.adaptors.gp2gp.ehr.utils.ResourceExtractor;
import uk.nhs.adaptors.gp2gp.mhs.model.Identifier;
import uk.nhs.adaptors.gp2gp.mhs.model.OutboundMessage;
import uk.nhs.adaptors.gp2gp.transformjsontoxmltool.XmlSchemaValidator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class StructuredRecordMappingService {
private final RandomIdGeneratorService randomIdGeneratorService;
private final SupportedContentTypes supportedContentTypes;
private final EhrExtractStatusService ehrExtractStatusService;
private final XmlSchemaValidator xmlSchemaValidator;

private DocumentBuilder documentBuilder;

Expand Down Expand Up @@ -151,6 +153,8 @@ public String mapStructuredRecordToEhrExtractXml(GetGpcStructuredTaskDefinition
.mapBundleToEhrFhirExtractParams(structuredTaskDefinition, bundle);
String ehrExtractContent = ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters);

xmlSchemaValidator.validateOutputToXmlSchema(structuredTaskDefinition.getConversationId(), ehrExtractContent);

ehrExtractStatusService.saveEhrExtractMessageId(structuredTaskDefinition.getConversationId(),
ehrExtractTemplateParameters.getEhrExtractId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@
@Override
public void run(String... args) {
try {
getFiles().forEach(file -> {
String xmlResult = mapJsonToXml(file.getJsonFileInput());
writeToFile(xmlResult, file.getJsonFileName());
xmlSchemaValidator.validateOutputToXmlSchema(file.getJsonFileName(), xmlResult);
});
getFiles().forEach(this::processAndValidateFile);

Check warning on line 68 in service/src/main/java/uk/nhs/adaptors/gp2gp/transformjsontoxmltool/TransformJsonToXml.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 68 without causing a test to fail

removed call to java/util/List::forEach (no tests cover this line VoidMethodCallMutator)
} catch (NHSNumberNotFound | UnreadableJsonFileException | NoJsonFileFound | Hl7TranslatedResponseError e) {
LOGGER.error("error: " + e.getMessage());
}

LOGGER.info("end");
}

private void processAndValidateFile(InputFile file) {
String xmlResult = mapJsonToXml(file.getJsonFileInput());

writeToFile(xmlResult, file.getJsonFileName());

Check warning on line 79 in service/src/main/java/uk/nhs/adaptors/gp2gp/transformjsontoxmltool/TransformJsonToXml.java

View workflow job for this annotation

GitHub Actions / pitest

2 different changes can be made to line 79 without causing a test to fail

swapped parameters 1 and 2 in call to writeToFile (no tests cover this line ParamSwapMutator) removed call to writeToFile (no tests cover this line VoidMethodCallMutator)

xmlSchemaValidator.validateOutputToXmlSchema(file.getJsonFileName(), xmlResult);

Check warning on line 81 in service/src/main/java/uk/nhs/adaptors/gp2gp/transformjsontoxmltool/TransformJsonToXml.java

View workflow job for this annotation

GitHub Actions / pitest

2 different changes can be made to line 81 without causing a test to fail

swapped parameters 1 and 2 in call to validateOutputToXmlSchema (no tests cover this line ParamSwapMutator) removed call to uk/nhs/adaptors/gp2gp/transformjsontoxmltool/XmlSchemaValidator::validateOutputToXmlSchema (no tests cover this line VoidMethodCallMutator)
}

private List<InputFile> getFiles() throws UnreadableJsonFileException, NoJsonFileFound {
File[] files = new File(JSON_FILE_INPUT_PATH).listFiles();
List<String> jsonStringInputs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import uk.nhs.adaptors.gp2gp.ehr.mapper.SupportedContentTypes;
import uk.nhs.adaptors.gp2gp.ehr.mapper.parameters.EhrExtractTemplateParameters;
import uk.nhs.adaptors.gp2gp.mhs.model.OutboundMessage;
import uk.nhs.adaptors.gp2gp.transformjsontoxmltool.XmlSchemaValidator;
import wiremock.org.custommonkey.xmlunit.DetailedDiff;
import wiremock.org.custommonkey.xmlunit.XMLUnit;

Expand Down Expand Up @@ -68,6 +69,8 @@ class StructuredRecordMappingServiceTest {
private SupportedContentTypes supportedContentTypes;
@Mock
private EhrExtractStatusService ehrExtractStatusService;
@Mock
private XmlSchemaValidator xmlSchemaValidator;

@InjectMocks
private StructuredRecordMappingService structuredRecordMappingService;
Expand Down Expand Up @@ -280,6 +283,31 @@ void When_BuildingSkeletonForEhrExtractWithoutChildComponentNodesToReplace_Expec
assertXMLEquals(skeletonEhrExtract, expectedSkeletonEhrExtract);
}

@Test
void When_MapStructuredRecordToEhrExtractXml_Expect_XmlValidatedAndReturned() {
var structuredTaskDefinition = mock(GetGpcStructuredTaskDefinition.class);
var bundle = mock(Bundle.class);
var ehrExtractTemplateParameters = mock(EhrExtractTemplateParameters.class);
var ehrExtractContent = "ehrExtractXmlContent";
var expectedOutput = "wrappedEhrExtractXml";
var conversationId = "conversationId123";

when(ehrExtractMapper.mapBundleToEhrFhirExtractParams(structuredTaskDefinition, bundle))
.thenReturn(ehrExtractTemplateParameters);
when(ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters))
.thenReturn(ehrExtractContent);
when(structuredTaskDefinition.getConversationId())
.thenReturn(conversationId);
when(outputMessageWrapperMapper.map(structuredTaskDefinition, ehrExtractContent))
.thenReturn(expectedOutput);

var actualOutput = structuredRecordMappingService.mapStructuredRecordToEhrExtractXml(structuredTaskDefinition, bundle);

verify(xmlSchemaValidator).validateOutputToXmlSchema("conversationId123", ehrExtractContent);
assertThat(actualOutput).isEqualTo(expectedOutput);
}


public static void assertXMLEquals(String actualXML, String expectedXML) throws Exception {
XMLUnit.setIgnoreWhitespace(true);

Expand Down