Merge pull request #427 from DBCG/master

Memory and Performance enhancements
This commit is contained in:
Grahame Grieve 2021-02-03 15:27:31 +11:00 committed by GitHub
commit 7ee25f33b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 20 deletions

View File

@ -330,6 +330,18 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean autoFixSliceNames;
private XVerExtensionManager xver;
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) {
super();
this.context = context;
this.messages = messages;
this.pkp = pkp;
this.fpe = fpe;
if (context != null && this.fpe == null) {
this.fpe = new FHIRPathEngine(context, this);
}
}
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp) {
super();
this.context = context;

View File

@ -53,6 +53,7 @@ import org.hl7.fhir.r5.formats.JsonCreator;
import org.hl7.fhir.r5.formats.JsonCreatorCanonical;
import org.hl7.fhir.r5.formats.JsonCreatorGson;
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
@ -75,8 +76,14 @@ public class JsonParser extends ParserBase {
private Map<JsonElement, LocationData> map;
private boolean allowComments;
private FHIRPathEngine fpe;
private ProfileUtilities profileUtilities;
public JsonParser(IWorkerContext context) {
super(context);
this.fpe = new FHIRPathEngine(this.context);
this.profileUtilities = new ProfileUtilities(this.context, null, null, this.fpe);
}
public Element parse(String source, String type) throws Exception {
@ -86,7 +93,7 @@ public class JsonParser extends ParserBase {
if (sd == null)
return null;
Element result = new Element(type, new Property(context, sd.getSnapshot().getElement().get(0), sd));
Element result = new Element(type, new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities));
checkObject(obj, path);
result.setType(type);
parseChildren(path, obj, result, true);
@ -135,7 +142,7 @@ public class JsonParser extends ParserBase {
if (sd == null)
return null;
Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities));
checkObject(object, path);
result.markLocation(line(object), col(object));
result.setType(name);
@ -357,7 +364,7 @@ public class JsonParser extends ParserBase {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, context.getOverrideVersionNs()));
if (sd == null)
throw new FHIRFormatError(context.formatMessage(I18nConstants.CONTAINED_RESOURCE_DOES_NOT_APPEAR_TO_BE_A_FHIR_RESOURCE_UNKNOWN_NAME_, name));
parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(parent.getProperty()), elementProperty);
parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd, this.profileUtilities), SpecialElement.fromProperty(parent.getProperty()), elementProperty);
parent.setType(name);
parseChildren(npath, res, parent, true);
}

View File

@ -57,11 +57,16 @@ public class Property {
private Boolean canBePrimitive;
private ProfileUtilities profileUtilities;
public Property(IWorkerContext context, ElementDefinition definition, StructureDefinition structure) {
public Property(IWorkerContext context, ElementDefinition definition, StructureDefinition structure, ProfileUtilities profileUtilities) {
this.context = context;
this.definition = definition;
this.structure = structure;
profileUtilities = new ProfileUtilities(context, null, null);
this.profileUtilities = profileUtilities;
}
public Property(IWorkerContext context, ElementDefinition definition, StructureDefinition structure) {
this(context, definition, structure, new ProfileUtilities(context, null, null));
}
public String getName() {
@ -354,7 +359,7 @@ public class Property {
}
List<Property> properties = new ArrayList<Property>();
for (ElementDefinition child : children) {
properties.add(new Property(context, child, sd));
properties.add(new Property(context, child, sd, this.profileUtilities));
}
return properties;
}
@ -393,7 +398,7 @@ public class Property {
}
List<Property> properties = new ArrayList<Property>();
for (ElementDefinition child : children) {
properties.add(new Property(context, child, sd));
properties.add(new Property(context, child, sd, this.profileUtilities));
}
return properties;
}

View File

@ -309,17 +309,7 @@ public class FHIRPathEngine {
* @param worker - used when validating paths (@check), and used doing value set membership when executing tests (once that's defined)
*/
public FHIRPathEngine(IWorkerContext worker) {
super();
this.worker = worker;
profileUtilities = new ProfileUtilities(worker, null, null);
for (StructureDefinition sd : worker.getStructures()) {
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() != StructureDefinitionKind.LOGICAL) {
allTypes.put(sd.getName(), sd);
}
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
primitiveTypes.add(sd.getName());
}
}
this(worker, new ProfileUtilities(worker, null, null));
}
public FHIRPathEngine(IWorkerContext worker, ProfileUtilities utilities) {

View File

@ -207,6 +207,8 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
private Map<String, ValidationControl> validationControl = new HashMap<>();
private QuestionnaireMode questionnaireMode;
private FHIRPathEngine fpe;
public ValidationEngine() throws IOException {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
context = SimpleWorkerContext.fromNothing();
@ -269,6 +271,8 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
}
NpmPackage npmX = pcm.loadPackage("hl7.fhir.xver-extensions", "0.0.4");
context.loadFromPackage(npmX, null);
this.fpe = new FHIRPathEngine(context);
}
private IContextResourceLoader loaderForVersion() {
@ -1310,7 +1314,6 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
private OperationOutcome messagesToOutcome(List<ValidationMessage> messages) throws IOException, FHIRException, EOperationOutcome {
OperationOutcome op = new OperationOutcome();
for (ValidationMessage vm : filterMessages(messages)) {
FHIRPathEngine fpe = new FHIRPathEngine(context);
try {
fpe.parse(vm.getLocation());
} catch (Exception e) {
@ -1387,7 +1390,6 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
public String evaluateFhirPath(String source, String expression) throws FHIRException, IOException {
Content cnt = loadContent(source, "validate", false);
FHIRPathEngine fpe = new FHIRPathEngine(context);
Element e = Manager.parse(context, new ByteArrayInputStream(cnt.focus), cnt.cntType);
return fpe.evaluateToString(e, expression);
}