reorganise to test cross-version extensions

This commit is contained in:
Grahame Grieve 2020-04-17 22:27:02 +10:00
parent ec517834b0
commit 8a9bcbf6e6
10 changed files with 91 additions and 12 deletions

View File

@ -32,7 +32,7 @@ import org.hl7.fhir.dstu2016may.formats.XmlParser;
import org.hl7.fhir.dstu2016may.model.Resource;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleType;

View File

@ -31,7 +31,7 @@ import org.hl7.fhir.dstu2.formats.JsonParser;
import org.hl7.fhir.dstu2.formats.XmlParser;
import org.hl7.fhir.dstu2.model.Resource;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleType;

View File

@ -31,7 +31,7 @@ import org.hl7.fhir.dstu3.formats.JsonParser;
import org.hl7.fhir.dstu3.formats.XmlParser;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleType;

View File

@ -31,7 +31,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.formats.JsonParser;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleType;

View File

@ -31,7 +31,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.Bundle.BundleType;

View File

@ -91,6 +91,8 @@ import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.utils.NarrativeGenerator;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.TranslatingUtilities;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.r5.utils.XVerExtensionManager.XVerExtensionStatus;
import org.hl7.fhir.r5.utils.formats.CSVWriter;
import org.hl7.fhir.r5.utils.formats.XLSXWriter;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
@ -265,6 +267,7 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean newSlicingProcessing;
private String defWebRoot;
private boolean autoFixSliceNames;
private XVerExtensionManager xver;
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp) {
super();
@ -617,6 +620,11 @@ public class ProfileUtilities extends TranslatingUtilities {
for (TypeRefComponent t : ed.getType()) {
for (UriType u : t.getProfile()) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, u.getValue());
if (sd == null) {
if (xver != null && xver.matchingUrl(u.getValue()) && xver.status(u.getValue()) == XVerExtensionStatus.Valid) {
sd = xver.makeDefinition(u.getValue());
}
}
if (sd == null) {
if (messages != null) {
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url+"#"+ed.getId(), "The type of profile "+u.getValue()+" cannot be checked as the profile is not known", IssueSeverity.WARNING));
@ -876,6 +884,16 @@ public class ProfileUtilities extends TranslatingUtilities {
if (diffMatches.get(0).hasType() && diffMatches.get(0).getType().size() == 1 && diffMatches.get(0).getType().get(0).hasProfile() && !"Reference".equals(diffMatches.get(0).getType().get(0).getWorkingCode())) {
CanonicalType p = diffMatches.get(0).getType().get(0).getProfile().get(0);
StructureDefinition sd = context.fetchResource(StructureDefinition.class, p.getValue());
if (sd == null && xver != null && xver.matchingUrl(p.getValue())) {
switch (xver.status(p.getValue())) {
case BadVersion: throw new FHIRException("Reference to invalid version in extension url "+p.getValue());
case Invalid: throw new FHIRException("Reference to invalid extension "+p.getValue());
case Unknown: throw new FHIRException("Reference to unknown extension "+p.getValue());
case Valid:
sd = xver.makeDefinition(p.getValue());
generateSnapshot(context.fetchTypeDefinition("Extension"), sd, sd.getUrl(), webUrl, sd.getName());
}
}
if (sd != null) {
checkNotGenerating(sd, "an extension definition");
if (!sd.hasSnapshot()) {
@ -5662,6 +5680,15 @@ public class ProfileUtilities extends TranslatingUtilities {
return base;
}
public XVerExtensionManager getXver() {
return xver;
}
public ProfileUtilities setXver(XVerExtensionManager xver) {
this.xver = xver;
return this;
}

View File

@ -1,5 +1,8 @@
package org.hl7.fhir.r5.context;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
/*-
@ -41,6 +44,7 @@ import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.ConceptMap;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.Resource;
@ -53,6 +57,7 @@ import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.utils.INarrativeGenerator;
import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.utilities.TranslationServices;
import org.hl7.fhir.utilities.cache.NpmPackage;
import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
@ -105,6 +110,13 @@ public interface IWorkerContext {
}
}
public interface IContextResourceLoader {
Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException;
String[] getTypes();
}
/**
* Get the versions of the definitions loaded in context
* @return
@ -618,5 +630,9 @@ public interface IWorkerContext {
public String getLinkForUrl(String corePath, String s);
public Map<String, byte[]> getBinaries();
void loadFromPackage(NpmPackage pi, IContextResourceLoader loader, String[] types) throws FileNotFoundException, IOException, FHIRException;
public boolean hasPackage(String id, String ver);
}

View File

@ -90,12 +90,6 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
}
public interface IContextResourceLoader {
Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException;
String[] getTypes();
}
public interface IValidatorFactory {
IResourceValidator makeValidator(IWorkerContext ctxts) throws FHIRException;
}
@ -106,6 +100,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
private IValidatorFactory validatorFactory;
private boolean ignoreProfileErrors;
private boolean progress;
private List<String> loadedPackages = new ArrayList<String>();
public SimpleWorkerContext() throws FileNotFoundException, IOException, FHIRException {
super();
@ -324,6 +319,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
if (progress) {
System.out.println("Load Package "+pi.name()+"#"+pi.version());
}
loadedPackages.add(pi.id()+"#"+pi.version());
for (String s : pi.listResources(loader.getTypes())) {
try {
loadDefinitionItem(s, pi.load("package", s), loader, filter, new PackageVersion(pi.id(), pi.version()));
@ -339,10 +335,12 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
}
}
@Override
public void loadFromPackage(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, IOException, FHIRException {
if (progress) {
System.out.println("Load Package "+pi.name()+"#"+pi.version());
}
loadedPackages.add(pi.id()+"#"+pi.version());
if (types.length == 0)
types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
for (String s : pi.listResources(types)) {
@ -699,6 +697,11 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
this.progress = progress;
}
@Override
public boolean hasPackage(String id, String ver) {
return loadedPackages.contains(id+"#"+ver);
}

View File

@ -5,6 +5,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -22,11 +23,13 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r5.model.ExpressionNode.CollectionStatus;
@ -43,6 +46,7 @@ import org.hl7.fhir.r5.model.TestScript.TestActionComponent;
import org.hl7.fhir.r5.model.TestScript.TestScriptFixtureComponent;
import org.hl7.fhir.r5.model.TestScript.TestScriptTestComponent;
import org.hl7.fhir.r5.test.SnapShotGenerationTests.TestFetchMode;
import org.hl7.fhir.r5.test.SnapShotGenerationTests.TestLoader;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
@ -52,8 +56,12 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.r5.utils.NarrativeGenerator;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.cache.NpmPackage;
import org.hl7.fhir.utilities.cache.PackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.xml.XMLUtil;
@ -70,6 +78,26 @@ import junit.framework.Assert;
@RunWith(Parameterized.class)
public class SnapShotGenerationTests {
public class TestLoader implements IContextResourceLoader {
private String[] types;
public TestLoader(String[] types) {
this.types = types;
}
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
return null;
}
@Override
public String[] getTypes() {
return types;
}
}
public enum TestFetchMode {
INPUT,
OUTPUT,
@ -499,6 +527,11 @@ public class SnapShotGenerationTests {
pu.setThrowException(false);
pu.setDebug(test.isDebug());
pu.setIds(test.getSource(), false);
if (!TestingUtilities.context().hasPackage("hl7.fhir.xver-extensions", "0.0.3")) {
NpmPackage npm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.fhir.xver-extensions", "0.0.3");
TestingUtilities.context().loadFromPackage(npm, new TestLoader(new String[] {"StructureDefinition"}), new String[] {"StructureDefinition"});
}
pu.setXver(new XVerExtensionManager(TestingUtilities.context()));
if (test.isSort()) {
List<String> errors = new ArrayList<String>();
int lastCount = output.getDifferential().getElement().size();

View File

@ -5,9 +5,9 @@ import org.hl7.fhir.convertors.*;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;