Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminating possible NPE + adding safer try--with-resources version + small code cleanup #364

Merged
merged 2 commits into from
Nov 7, 2023
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
Expand Up @@ -63,7 +63,7 @@ public List<? extends DomainResource> mapAgentDirectory(RCMRMT030101UK04AgentDir
return agentResources;
}

return null;
return List.of();
}

private void mapAgent(RCCTMT120101UK01Agent agent, List<DomainResource> agentResourceList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@ private Integer getAttachmentSize(List<PatientAttachmentLog> patientAttachmentLo
// stubbed method for abstract class
public List<DocumentReference> mapResources(RCMRMT030101UK04EhrExtract ehrExtract, Patient patient,
List<Encounter> encounterList, String practiseCode) {
return null;
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Reference> 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<Reference> entryReferences, RCMRMT030101UK04CompoundStatement compoundStatement) {
if (observationStatement != null && isNotIgnoredResource(compoundStatement, entryReferences)) {
Expand Down