Skip to content

Commit 9e8e149

Browse files
committed
adding logging
1 parent 3effdbc commit 9e8e149

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/EhrExtractStatusService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ private void getEhrExtractStatus(
439439
List<EhrExtractStatus.GpcDocument> docs,
440440
Update.AddToSetBuilder updateBuilder,
441441
FindAndModifyOptions returningUpdatedRecordOption) {
442+
443+
LOGGER.debug("Attempting to update EHR extract status. Query: {}, Number of documents: {}", query, docs.size());
444+
442445
Update update = updateBuilder.each(docs);
443446

444447
EhrExtractStatus ehrExtractStatus = mongoTemplate.findAndModify(query,
@@ -447,8 +450,10 @@ private void getEhrExtractStatus(
447450
EhrExtractStatus.class);
448451

449452
if (ehrExtractStatus == null) {
453+
LOGGER.error("Failed to update EHR extract status. No matching record found for query: {}", query);
450454
throw new EhrExtractException("EHR Extract Status was not updated with document URL's");
451455
}
456+
LOGGER.info("Successfully updated EHR extract status with {} documents", docs.size());
452457
}
453458

454459
public void updateEhrExtractStatusAcknowledgement(SendAcknowledgementTaskDefinition taskDefinition, String ackMessageId) {

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/SendEhrExtractCoreTaskExecutor.java

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,31 @@ public void execute(SendEhrExtractCoreTaskDefinition sendEhrExtractCoreTaskDefin
9696
private String compressEhrExtractAndReplacePayloadWithSkeleton(
9797
SendEhrExtractCoreTaskDefinition sendEhrExtractCoreTaskDefinition,
9898
OutboundMessage outboundMessage) throws JsonProcessingException {
99+
100+
LOGGER.info("Starting compression and skeleton replacement for outbound message");
101+
99102
String documentId = randomIdGeneratorService.createNewId();
100103
String messageId = randomIdGeneratorService.createNewId();
101104
String taskId = randomIdGeneratorService.createNewId();
105+
106+
LOGGER.debug("Generated IDs - Document ID: {}, Message ID: {}, Task ID: {}", documentId, messageId, taskId);
107+
102108
String fileName = GpcFilenameUtils.generateLargeExrExtractFilename(documentId);
103-
final var compressedEhrExtract = Base64Utils.toBase64String(Gzip.compress(outboundMessage.getPayload()));
109+
String originalPayload = outboundMessage.getPayload();
110+
final var compressedEhrExtract = Base64Utils.toBase64String(Gzip.compress(originalPayload));
111+
LOGGER.info("Compressed EHR extract: original size = {}, compressed size = {}",
112+
originalPayload.length(), compressedEhrExtract.length());
113+
104114
storeCompressedEhrExtractAsDocument(sendEhrExtractCoreTaskDefinition, documentId, messageId, fileName, taskId);
105115

106116
uploadCompressedEhrExtractToStorageWrapper(
107117
sendEhrExtractCoreTaskDefinition, messageId, documentId, compressedEhrExtract, taskId, fileName);
108118

109-
outboundMessage.setPayload(structuredRecordMappingService.buildSkeletonEhrExtractXml(outboundMessage.getPayload(), documentId));
119+
outboundMessage.setPayload(structuredRecordMappingService.buildSkeletonEhrExtractXml(originalPayload, documentId));
110120
referenceCompressedEhrExtractDocumentAsAttachmentInOutboundMessage(
111121
outboundMessage, documentId, messageId, fileName, compressedEhrExtract.length());
112122

123+
LOGGER.info("Successfully completed compression and skeleton replacement for outbound message with document ID: {}", documentId);
113124
return objectMapper.writeValueAsString(outboundMessage);
114125
}
115126

@@ -146,31 +157,41 @@ private void uploadCompressedEhrExtractToStorageWrapper(
146157
String taskId,
147158
String fileName) throws JsonProcessingException {
148159

149-
String data = objectMapper.writeValueAsString(
150-
OutboundMessage.builder()
151-
.payload(
152-
ehrDocumentMapper.generateMhsPayload(
153-
sendEhrExtractCoreTaskDefinition,
154-
messageId,
155-
documentId,
156-
"application/xml"
157-
)
158-
).attachments(
159-
List.of(
160-
OutboundMessage.Attachment.builder()
161-
.contentType(TEXT_XML_CONTENT_TYPE)
162-
.isBase64(true)
163-
.description(documentId)
164-
.payload(compressedEhrExtract)
165-
.build()
166-
)
167-
).build()
168-
);
160+
LOGGER.info("Preparing to upload compressed EHR extract. File name: {}, Document ID: {}, Task ID: {}, Message ID: {}",
161+
fileName, documentId, taskId, messageId);
162+
163+
String data;
164+
165+
try {
166+
data = objectMapper.writeValueAsString(
167+
OutboundMessage.builder()
168+
.payload(
169+
ehrDocumentMapper.generateMhsPayload(
170+
sendEhrExtractCoreTaskDefinition,
171+
messageId,
172+
documentId,
173+
"application/xml"
174+
)
175+
).attachments(
176+
List.of(
177+
OutboundMessage.Attachment.builder()
178+
.contentType(TEXT_XML_CONTENT_TYPE)
179+
.isBase64(true)
180+
.description(documentId)
181+
.payload(compressedEhrExtract)
182+
.build()
183+
)).build());
184+
} catch (JsonProcessingException exception) {
185+
LOGGER.error("Failed to serialize OutboundMessage for document ID: {}", documentId, exception);
186+
throw exception;
187+
}
169188

170189
storageConnectorService.uploadFile(
171190
StorageDataWrapperProvider.buildStorageDataWrapper(sendEhrExtractCoreTaskDefinition, data, taskId),
172191
fileName
173192
);
193+
194+
LOGGER.info("Upload completed for file: {}", fileName);
174195
}
175196

176197
private void storeCompressedEhrExtractAsDocument(

0 commit comments

Comments
 (0)