This commit is contained in:
Grahame Grieve 2023-11-25 06:43:21 +13:00
commit 639c41ad5e
9 changed files with 170 additions and 42 deletions

View File

@ -12,10 +12,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.naming.Context;
import org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl;
/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
@ -70,7 +66,6 @@ import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.r5.utils.XVerExtensionManager.XVerExtensionStatus;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.r5.utils.validation.ValidationContextCarrier.IValidationContextResourceLoader;
import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
@ -164,7 +159,7 @@ public class BaseValidator implements IValidationContextResourceLoader {
protected BaseValidator parent;
protected Source source;
protected IWorkerContext context;
protected TimeTracker timeTracker = new TimeTracker();
protected ValidationTimeTracker timeTracker = new ValidationTimeTracker();
protected XVerExtensionManager xverManager;
protected List<TrackedLocationRelatedMessage> trackedMessages = new ArrayList<>();
protected List<ValidationMessage> messagesToRemove = new ArrayList<>();

View File

@ -91,6 +91,8 @@ import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.validation.BaseValidator.ValidationControl;
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
import org.hl7.fhir.validation.cli.model.HtmlInMarkdownCheck;
import org.hl7.fhir.validation.cli.model.ValidatedFragments;
import org.hl7.fhir.validation.cli.model.ValidationTime;
import org.hl7.fhir.validation.cli.services.IPackageInstaller;
import org.hl7.fhir.validation.cli.utils.ProfileLoader;
import org.hl7.fhir.validation.cli.utils.QuestionnaireMode;
@ -633,10 +635,11 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
}
public List<ValidatedFragment> validateAsFragments(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
public ValidatedFragments validateAsFragments(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
InstanceValidator validator = getValidator(cntType);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
return validator.validatedContent;
return new ValidatedFragments(validator.validatedContent,
ValidationTime.fromTimeTracker(validator.timeTracker));
}
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {

View File

@ -1,6 +1,6 @@
package org.hl7.fhir.validation;
public class TimeTracker {
public class ValidationTimeTracker {
private long overall = 0;
private long txTime = 0;
private long sdTime = 0;

View File

@ -0,0 +1,26 @@
package org.hl7.fhir.validation.cli.model;
import org.hl7.fhir.r5.elementmodel.ValidatedFragment;
import java.util.List;
public class ValidatedFragments {
public List<ValidatedFragment> getValidatedFragments() {
return validatedFragments;
}
public ValidationTime getValidationTime() {
return validationTime;
}
private List<ValidatedFragment> validatedFragments;
private ValidationTime validationTime;
public ValidatedFragments(List<ValidatedFragment> validatedFragments, ValidationTime validationTime) {
this.validatedFragments = validatedFragments;
this.validationTime = validationTime;
}
}

View File

@ -1,7 +1,9 @@
package org.hl7.fhir.validation.cli.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -13,17 +15,22 @@ public class ValidationResponse {
@JsonProperty("sessionId")
public String sessionId;
@JsonProperty("validationTimes")
public Map<String, ValidationTime> validationTimes;
public ValidationResponse() {}
public ValidationResponse(List<ValidationOutcome> outcomes) {
this(outcomes, null);
this(outcomes, null, new HashMap<>());
}
public ValidationResponse(List<ValidationOutcome> outcomes, String sessionId) {
public ValidationResponse(List<ValidationOutcome> outcomes, String sessionId, Map<String, ValidationTime> validationTimes) {
this.outcomes = outcomes;
this.sessionId = sessionId;
this.validationTimes = validationTimes;
}
@JsonProperty("outcomes")
public List<ValidationOutcome> getOutcomes() {
return outcomes;
@ -54,4 +61,15 @@ public class ValidationResponse {
return this;
}
@JsonProperty("validationTimes")
public Map<String, ValidationTime> getValidationTimes() {
return validationTimes;
}
@JsonProperty("validationTimes")
public ValidationResponse setValidationTimes(Map<String, ValidationTime> validationTimes) {
this.validationTimes = validationTimes;
return this;
}
}

View File

@ -0,0 +1,102 @@
package org.hl7.fhir.validation.cli.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hl7.fhir.validation.ValidationTimeTracker;
public class ValidationTime {
public ValidationTime() {}
@JsonProperty("overall")
private long overall = 0;
@JsonProperty("terminology")
private long terminology = 0;
@JsonProperty("structureDefinition")
private long structureDefinition = 0;
@JsonProperty("resourceParse")
private long resourceParse = 0;
@JsonProperty("fhirPath")
private long fhirPath = 0;
@JsonProperty("checkingSpecials")
private long checkingSpecials = 0;
@JsonProperty("terminology")
public long getTerminology() {
return terminology;
}
@JsonProperty("terminology")
public ValidationTime setTerminology(long terminology) {
this.terminology = terminology;
return this;
}
@JsonProperty("structureDefinition")
public long getStructureDefinition() {
return structureDefinition;
}
@JsonProperty("structureDefinition")
public ValidationTime setStructureDefinition(long structureDefinition) {
this.structureDefinition = structureDefinition;
return this;
}
@JsonProperty("resourceParse")
public long getResourceParse() {
return resourceParse;
}
@JsonProperty("resourceParse")
public ValidationTime setResourceParse(long resourceParse) {
this.resourceParse = resourceParse;
return this;
}
@JsonProperty("fhirPath")
public long getFhirPath() {
return fhirPath;
}
@JsonProperty("fhirPath")
public ValidationTime setFhirPath(long fpeTime) {
this.fhirPath = fpeTime;
return this;
}
@JsonProperty("checkingSpecials")
public long getCheckingSpecials() {
return checkingSpecials;
}
@JsonProperty("checkingSpecials")
public ValidationTime setCheckingSpecials(long checkingSpecials) {
this.checkingSpecials = checkingSpecials;
return this;
}
@JsonProperty("overall")
public long getOverall() {
return overall;
}
@JsonProperty("overall")
public ValidationTime setOverall(long overall) {
this.overall = overall;
return this;
}
public static ValidationTime fromTimeTracker(ValidationTimeTracker timeTracker) {
return new ValidationTime()
.setStructureDefinition(timeTracker.getSdTime())
.setTerminology(timeTracker.getTxTime())
.setCheckingSpecials(timeTracker.getSpecTime())
.setFhirPath(timeTracker.getFpeTime())
.setOverall(timeTracker.getOverall())
.setResourceParse(timeTracker.getLoadTime());
}
}

View File

@ -10,12 +10,7 @@ import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.*;
import javax.annotation.Nonnull;
@ -64,11 +59,7 @@ import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.validation.*;
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
import org.hl7.fhir.validation.cli.model.CliContext;
import org.hl7.fhir.validation.cli.model.FileInfo;
import org.hl7.fhir.validation.cli.model.ValidationOutcome;
import org.hl7.fhir.validation.cli.model.ValidationRequest;
import org.hl7.fhir.validation.cli.model.ValidationResponse;
import org.hl7.fhir.validation.cli.model.*;
import org.hl7.fhir.validation.cli.renderers.CSVRenderer;
import org.hl7.fhir.validation.cli.renderers.CompactRenderer;
import org.hl7.fhir.validation.cli.renderers.DefaultRenderer;
@ -101,7 +92,8 @@ public class ValidationService {
String definitions = VersionUtilities.packageForVersion(request.getCliContext().getSv()) + "#" + VersionUtilities.getCurrentVersion(request.getCliContext().getSv());
String sessionId = initializeValidator(request.getCliContext(), definitions, new TimeTracker(), request.sessionId);
TimeTracker timeTracker = new TimeTracker();
String sessionId = initializeValidator(request.getCliContext(), definitions, timeTracker, request.sessionId);
ValidationEngine validator = sessionCache.fetchSessionValidatorEngine(sessionId);
if (request.getCliContext().getProfiles().size() > 0) {
@ -110,7 +102,7 @@ public class ValidationService {
System.out.println(" .. validate " + request.listSourceFiles());
}
ValidationResponse response = new ValidationResponse().setSessionId(sessionId);
ValidationResponse response = new ValidationResponse().setSessionId(sessionId).setValidationTimes(new HashMap<>());
for (FileInfo fileToValidate : request.getFilesToValidate()) {
if (fileToValidate.getFileType() == null) {
@ -124,13 +116,13 @@ public class ValidationService {
List<ValidationMessage> messages = new ArrayList<>();
List<ValidatedFragment> validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
ValidatedFragments validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
request.getCliContext().getProfiles(), messages);
if (validatedFragments.size() == 1 && !validatedFragments.get(0).isDerivedContent()) {
ValidatedFragment validatedFragment = validatedFragments.get(0);
if (validatedFragments.getValidatedFragments().size() == 1 && !validatedFragments.getValidatedFragments().get(0).isDerivedContent()) {
ValidatedFragment validatedFragment = validatedFragments.getValidatedFragments().get(0);
ValidationOutcome outcome = new ValidationOutcome();
FileInfo fileInfo = new FileInfo(
FileInfo fileInfo = new FileInfo(
fileToValidate.getFileName(),
new String(validatedFragment.getContent()),
validatedFragment.getExtension());
@ -138,7 +130,7 @@ public class ValidationService {
outcome.setFileInfo(fileInfo);
response.addOutcome(outcome);
} else {
for (ValidatedFragment validatedFragment : validatedFragments) {
for (ValidatedFragment validatedFragment : validatedFragments.getValidatedFragments()) {
ValidationOutcome outcome = new ValidationOutcome();
FileInfo fileInfo = new FileInfo(
validatedFragment.getFilename(),
@ -149,7 +141,12 @@ public class ValidationService {
response.addOutcome(outcome);
}
}
if (request.getCliContext().isShowTimes()) {
response.getValidationTimes().put(fileToValidate.getFileName(), validatedFragments.getValidationTime());
}
}
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
return response;
}

View File

@ -3,22 +3,15 @@ package org.hl7.fhir.validation.instance.type;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.terminologies.utilities.ValidationResult;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.hl7.fhir.validation.BaseValidator;
import org.hl7.fhir.validation.TimeTracker;
import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.validation.instance.utils.NodeStack;
public class CodeSystemValidator extends BaseValidator {

View File

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
@ -16,17 +15,12 @@ import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.terminologies.utilities.CodingValidationRequest;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass;
import org.hl7.fhir.r5.terminologies.utilities.ValidationResult;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.hl7.fhir.validation.BaseValidator;
import org.hl7.fhir.validation.TimeTracker;
import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.validation.instance.type.ValueSetValidator.VSCodingValidationRequest;
import org.hl7.fhir.validation.instance.utils.NodeStack;