Skip to content
Open
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 @@ -7,7 +7,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -31,6 +30,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
import uk.nhs.adaptors.gp2gp.ehr.exception.EhrValidationException;
import uk.nhs.adaptors.gp2gp.ehr.mapper.EhrExtractMapper;
import uk.nhs.adaptors.gp2gp.ehr.mapper.MessageContext;
import uk.nhs.adaptors.gp2gp.ehr.mapper.OutputMessageWrapperMapper;
Expand All @@ -44,8 +44,7 @@
@ConditionalOnProperty(
prefix = "command.line.runner",
value = "enabled",
havingValue = "true",
matchIfMissing = false)
havingValue = "true")
@Component
public class TransformJsonToXml implements CommandLineRunner {
private static final String JSON_FILE_INPUT_PATH =
Expand All @@ -56,7 +55,6 @@
private final MessageContext messageContext;
private final OutputMessageWrapperMapper outputMessageWrapperMapper;
private final EhrExtractMapper ehrExtractMapper;
private final XmlSchemaValidator xmlSchemaValidator;

public static void main(String[] args) {
SpringApplication.run(TransformJsonToXml.class, args).close();
Expand All @@ -68,38 +66,23 @@
getFiles().forEach(file -> {
String xmlResult = mapJsonToXml(file.getJsonFileInput());
writeToFile(xmlResult, file.getJsonFileName());
xmlSchemaValidator.validateOutputToXmlSchema(file.getJsonFileName(), xmlResult);
});
} catch (NHSNumberNotFound | UnreadableJsonFileException | NoJsonFileFound | Hl7TranslatedResponseError e) {
LOGGER.error("error: " + e.getMessage());
LOGGER.error("Failed to parse the provided JSON: {}", e.getMessage());
} catch (EhrValidationException e) {
LOGGER.error("Failed to validate the produced XML");
}
LOGGER.info("end");
}

private List<InputFile> getFiles() throws UnreadableJsonFileException, NoJsonFileFound {
File[] files = new File(JSON_FILE_INPUT_PATH).listFiles();
List<String> jsonStringInputs = new ArrayList<>();
List<String> fileNames = new ArrayList<>();

if (files == null || files.length == 0) {
throw new NoJsonFileFound("No json files found");
}

LOGGER.info("Processing " + files.length + " files from location: " + JSON_FILE_INPUT_PATH);
LOGGER.info("Processing {} files from location: {}", files.length, JSON_FILE_INPUT_PATH);

Arrays.stream(files)
.peek(file -> LOGGER.info("Parsing file: {}", file.getName()))
.filter(file -> FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("json"))
.forEach(file -> {
String jsonAsString;
try {
jsonAsString = readJsonFileAsString(JSON_FILE_INPUT_PATH + file.getName());
} catch (Exception e) {
throw new UnreadableJsonFileException("Cant read file " + file.getName());
}
jsonStringInputs.add(jsonAsString);
fileNames.add(file.getName());
});
return Arrays.stream(files)
.filter(file -> FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("json"))
.map(file -> {
Expand All @@ -109,7 +92,6 @@
} catch (IOException e) {
throw new UnreadableJsonFileException("Cannot read Json File as String: " + file.getName());
}

}).collect(Collectors.toList());

}
Expand Down Expand Up @@ -171,15 +153,16 @@
.filter(resource -> ResourceType.Patient.equals(resource.getResourceType()))
.map(Patient.class::cast)
.map(resource -> getNhsNumberIdentifier(nhsNumberSystem, resource))
.map(Identifier.class::cast)
.findFirst()
.orElseThrow(() -> new NHSNumberNotFound("No Patient identifier was found"))
.getValue();
}

private Identifier getNhsNumberIdentifier(String nhsNumberSystem, Patient resource) {
return resource.getIdentifier()
.stream().filter(identifier -> identifier.getSystem().equals(nhsNumberSystem)).findFirst().get();
return resource.getIdentifier().stream()

Check warning on line 162 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 162 without causing a test to fail

replaced return value with null for getNhsNumberIdentifier (no tests cover this line NullReturnValsMutator)
.filter(identifier -> identifier.getSystem().equals(nhsNumberSystem))

Check warning on line 163 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 163 without causing a test to fail

removed call to filter (no tests cover this line RemoveFilterMutator)

Check warning on line 163 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 a lambda on line 163 without causing a test to fail

replaced boolean return with false for 1st lambda in getNhsNumberIdentifier (no tests cover this line BooleanFalseReturnValsMutator)
.findFirst()
.orElseThrow(() -> new NHSNumberNotFound("No Patient identifier was found"));

Check warning on line 165 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 a lambda on line 165 without causing a test to fail

replaced return value with null for 2nd lambda in getNhsNumberIdentifier (no tests cover this line NullReturnValsMutator)
}

@Data
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion service/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<configuration>
<appender name="TEXT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${GP2GP_LOGGING_FORMAT:-%d{yyyy-MM-dd HH:mm:ss.SSS} Level=%-5level Logger=%logger{36} ConversationId=%X{ConversationId} TaskId=%X{TaskId} Thread="%thread" Message="%msg"%n}
<pattern>${GP2GP_LOGGING_FORMAT:-%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) Level=%-5level Logger=%logger{36} ConversationId=%X{ConversationId} TaskId=%X{TaskId} Thread="%thread" Message="%msg"%n}
</pattern>
</encoder>
</appender>
Expand Down