From a7440c9c70ace99bbe395416f2fa4d9939fe0d35 Mon Sep 17 00:00:00 2001 From: Paul Bastide Date: Fri, 5 Nov 2021 16:28:48 -0400 Subject: [PATCH] Audit record for PUTs should not always use "Update" #2471 Signed-off-by: Paul Bastide --- .../ibm/fhir/server/util/RestAuditLogger.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fhir-server/src/main/java/com/ibm/fhir/server/util/RestAuditLogger.java b/fhir-server/src/main/java/com/ibm/fhir/server/util/RestAuditLogger.java index b57e0523b43..adfc0459509 100644 --- a/fhir-server/src/main/java/com/ibm/fhir/server/util/RestAuditLogger.java +++ b/fhir-server/src/main/java/com/ibm/fhir/server/util/RestAuditLogger.java @@ -119,13 +119,17 @@ public static void logUpdate(HttpServletRequest request, Resource oldResource, R AuditLogService auditLogSvc = AuditLogServiceFactory.getService(); if (auditLogSvc.isEnabled()) { - AuditLogEntry entry = initLogEntry(AuditLogEventType.FHIR_UPDATE); - populateAuditLogEntry(entry, request, updatedResource, startTime, endTime, responseStatus); - - entry.getContext().setAction("U"); - entry.setDescription("FHIR Update request"); - - auditLogSvc.logEntry(entry); + if (oldResource == null) { + // #2471 - Audit record for PUTs should not always use "Update" + // If the oldResource is null, it doesn't exist and is actually treated as a CREATE. + RestAuditLogger.logCreate(request, updatedResource, startTime, endTime, responseStatus); + } else { + AuditLogEntry entry = initLogEntry(AuditLogEventType.FHIR_UPDATE); + populateAuditLogEntry(entry, request, updatedResource, startTime, endTime, responseStatus); + entry.getContext().setAction("U"); + entry.setDescription("FHIR Update request"); + auditLogSvc.logEntry(entry); + } } log.exiting(CLASSNAME, METHODNAME); }