From 1a59a829f87d3bdd608c173beba8b948f1c6f1da Mon Sep 17 00:00:00 2001 From: hospel Date: Tue, 7 Nov 2023 14:29:41 +0000 Subject: [PATCH 1/2] eliminating possible NPE + small code cleanup --- .../mapper/AgentDirectoryMapper.java | 2 +- .../mapper/DocumentReferenceMapper.java | 2 +- .../pss/translator/util/ObservationUtil.java | 6 ++---- .../translator/util/ResourceReferenceUtil.java | 18 ------------------ 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapper.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapper.java index af01b1b02..06dafaeeb 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapper.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/AgentDirectoryMapper.java @@ -63,7 +63,7 @@ public List mapAgentDirectory(RCMRMT030101UK04AgentDir return agentResources; } - return null; + return List.of(); } private void mapAgent(RCCTMT120101UK01Agent agent, List agentResourceList) { diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java index f69c40f96..e1276595c 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java @@ -238,6 +238,6 @@ private Integer getAttachmentSize(List patientAttachmentLo // stubbed method for abstract class public List mapResources(RCMRMT030101UK04EhrExtract ehrExtract, Patient patient, List encounterList, String practiseCode) { - return null; + return List.of(); } } diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ObservationUtil.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ObservationUtil.java index 500e9f007..513f4cf65 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ObservationUtil.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ObservationUtil.java @@ -138,10 +138,8 @@ public static Object getEffective(IVLTS effectiveTime, TS availabilityTime) { effectivePeriod.setEndElement(DateFormatUtil.parseToDateTimeType(effectiveTime.getHigh().getValue())); } - if (availabilityTimeHasValue(availabilityTime) && effectivePeriod.getStart() == null) { - if (effectivePeriod.getEnd() != null) { - effectivePeriod.setStartElement(DateFormatUtil.parseToDateTimeType(availabilityTime.getValue())); - } + if (availabilityTimeHasValue(availabilityTime) && effectivePeriod.getStart() == null && effectivePeriod.getEnd() != null) { + effectivePeriod.setStartElement(DateFormatUtil.parseToDateTimeType(availabilityTime.getValue())); } if (effectivePeriod.hasStart() || effectivePeriod.hasEnd()) { diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ResourceReferenceUtil.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ResourceReferenceUtil.java index 0afabe033..40ceb26c0 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ResourceReferenceUtil.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/util/ResourceReferenceUtil.java @@ -4,8 +4,6 @@ import static uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil.isBloodPressure; import static uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil.isDiagnosticReport; import static uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil.isDocumentReference; -import static uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil.isTemplate; - import java.util.List; import org.hl7.fhir.dstu3.model.IdType; @@ -57,14 +55,6 @@ public void extractChildReferencesFromCompoundStatement(RCMRMT030101UK04Compound addDiagnosticReportEntry(compoundStatement, entryReferences); } else { - // NIAD_2190 the section below appears to be for Questionnaire Response links and the observation - // created that goes with it. Since Questionnaires have been removed, the contents of the addTemplateEntry function has - // been commented out while it is tested more in depth. It can be removed following the effect investigation - // - Scott Alexander 21072022 - if (isTemplate(compoundStatement)) { - addTemplateEntry(compoundStatement, entryReferences); - } - compoundStatement.getComponent().forEach(component -> { addObservationStatementEntry( component.getObservationStatement(), entryReferences, compoundStatement); @@ -108,14 +98,6 @@ private static boolean isNotIgnoredResource(RCMRMT030101UK04CompoundStatement co || !references.contains(OBSERVATION_REFERENCE.formatted(compoundStatement.getId().get(0).getRoot())); } - private static void addTemplateEntry(RCMRMT030101UK04CompoundStatement compoundStatement, - List entryReferences) { -// entryReferences.add(createResourceReference(ResourceType.QuestionnaireResponse.name(), -// QUESTIONNAIRE_ID.formatted(compoundStatement.getId().get(0).getRoot()))); -// entryReferences.add(createResourceReference(ResourceType.Observation.name(), -// compoundStatement.getId().get(0).getRoot())); - } - private void addObservationStatementEntry(RCMRMT030101UK04ObservationStatement observationStatement, List entryReferences, RCMRMT030101UK04CompoundStatement compoundStatement) { if (observationStatement != null && isNotIgnoredResource(compoundStatement, entryReferences)) { From 7fb7d5dbe6d300178cd80dee231bc8619aaf82e1 Mon Sep 17 00:00:00 2001 From: hospel Date: Tue, 7 Nov 2023 15:01:26 +0000 Subject: [PATCH 2/2] applying a safer and more concise version of try-catch -> try-with-resources --- .../translator/storage/AzureStorageService.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/storage/AzureStorageService.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/storage/AzureStorageService.java index baa09e000..81e19f2fb 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/storage/AzureStorageService.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/storage/AzureStorageService.java @@ -82,23 +82,21 @@ private BlockBlobClient createBlobBlockClient(String filename) { } private void addFileStringToMainContainer(String filename, byte[] fileAsString) throws StorageException, IOException { - try { + try (InputStream dataStream = new ByteArrayInputStream(fileAsString)) { BlockBlobClient blobClient = createBlobBlockClient(filename); - InputStream dataStream = new ByteArrayInputStream(fileAsString); blobClient.upload(dataStream, fileAsString.length); - dataStream.close(); } catch (IOException e) { throw new StorageException("Failed to upload blob to Azure Blob storage", e); } } private ByteArrayOutputStream downloadFileToStream(String filename) throws StorageException { - try { - BlockBlobClient blobClient = createBlobBlockClient(filename); - int dataSize = (int) blobClient.getProperties().getBlobSize(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(dataSize); + + BlockBlobClient blobClient = createBlobBlockClient(filename); + int dataSize = (int) blobClient.getProperties().getBlobSize(); + + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(dataSize)) { blobClient.downloadStream(outputStream); - outputStream.close(); return outputStream; } catch (IOException e) { throw new StorageException("Failed to download blob from Azure Blob storage", e);