From 9af43f20fb004c7ab925b6255d11472f673562bc Mon Sep 17 00:00:00 2001 From: Dylan Hall Date: Fri, 12 Jan 2024 10:48:11 -0500 Subject: [PATCH] FI-2410: a little extra logging (#72) --- .../java/org/mitre/inferno/Validator.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/org/mitre/inferno/Validator.java b/src/main/java/org/mitre/inferno/Validator.java index 326f3a8..b75258f 100644 --- a/src/main/java/org/mitre/inferno/Validator.java +++ b/src/main/java/org/mitre/inferno/Validator.java @@ -33,11 +33,14 @@ import org.hl7.fhir.validation.ValidationEngine; import org.hl7.fhir.validation.ValidationEngine.ValidationEngineBuilder; import org.mitre.inferno.rest.IgResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Validator { private final ValidationEngine hl7Validator; private final FilesystemPackageCacheManager packageManager; private final Map loadedPackages; + private static final Logger LOGGER = LoggerFactory.getLogger(Validator.class); /** * Creates the HL7 Validator to which can then be used for validation. @@ -151,6 +154,20 @@ public List getStructures() { public OperationOutcome validate(byte[] resource, List profiles) { Manager.FhirFormat fmt = FormatUtilities.determineFormat(resource); ByteArrayInputStream resourceStream = new ByteArrayInputStream(resource); + + try { + Resource resourceObj = FormatUtilities.makeParser(fmt).parse(resource); + String metaProfiles = "[]"; + if (resourceObj.hasMeta() && resourceObj.getMeta().hasProfile()) { + metaProfiles = resourceObj.getMeta().getProfile().toString(); + } + LOGGER.info("Validating resource with type: " + resourceObj.fhirType() + + ", selected profile: " + profiles.toString() + + " and meta.profile: " + metaProfiles); + } catch (Exception e) { + LOGGER.warn("Error occurred in parsing resource for logging", e); + } + OperationOutcome oo; try { oo = hl7Validator.validate(fmt, resourceStream, profiles); @@ -207,6 +224,13 @@ public void loadProfile(byte[] profile) throws IOException { Manager.FhirFormat fmt = FormatUtilities.determineFormat(profile); Resource resource = FormatUtilities.makeParser(fmt).parse(profile); hl7Validator.getContext().cacheResource(resource); + if (resource instanceof StructureDefinition) { + StructureDefinition sd = (StructureDefinition)resource; + LOGGER.info("Loaded profile from file, url: " + sd.getUrl() + " version: " + sd.getVersion()); + } else if (resource != null) { + LOGGER.info("Loaded resource from file but it wasn't a StructureDefinition, it was a " + + resource.fhirType()); + } } /** @@ -255,6 +279,9 @@ public IgResponse loadIg(String id, String version) throws Exception { true ); npm = packageManager.loadPackage(id, version); + if (npm != null) { + LOGGER.info("Loaded IG by identifier: " + npm.id() + "#" + npm.version()); + } } return IgResponse.fromPackage(npm); } @@ -283,6 +310,7 @@ public IgResponse loadPackage(byte[] content) throws Exception { } NpmPackage npm = NpmPackage.fromPackage(new ByteArrayInputStream(content)); loadedPackages.put(npm.id() + "#" + npm.version(), npm); + LOGGER.info("Loaded IG from tgz upload: " + npm.id() + "#" + npm.version()); return IgResponse.fromPackage(npm); }