@@ -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