Skip to content

Commit

Permalink
FI-2410: a little extra logging (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall authored Jan 12, 2024
1 parent cf9dbcc commit 9af43f2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/org/mitre/inferno/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, NpmPackage> loadedPackages;
private static final Logger LOGGER = LoggerFactory.getLogger(Validator.class);

/**
* Creates the HL7 Validator to which can then be used for validation.
Expand Down Expand Up @@ -151,6 +154,20 @@ public List<String> getStructures() {
public OperationOutcome validate(byte[] resource, List<String> 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);
Expand Down Expand Up @@ -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());
}
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 9af43f2

Please sign in to comment.