Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-2410: a little extra logging #72

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading