don't load type definitions from example package
This commit is contained in:
parent
a6f43420d5
commit
483477c9c4
|
@ -6,6 +6,7 @@ import org.hl7.fhir.exceptions.FHIRException;
|
|||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.PackageInformation;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
|
||||
|
@ -126,7 +127,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
|||
}
|
||||
}
|
||||
|
||||
private class CachedCanonicalResource<T1 extends CanonicalResource> {
|
||||
public class CachedCanonicalResource<T1 extends CanonicalResource> {
|
||||
private T1 resource;
|
||||
private CanonicalResourceProxy proxy;
|
||||
private PackageInformation packageInfo;
|
||||
|
@ -186,6 +187,14 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
|||
} else {
|
||||
return resource instanceof CodeSystem ? ((CodeSystem) resource).getSupplements() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getDerivation() {
|
||||
if (resource == null) {
|
||||
return proxy.getDerivation();
|
||||
} else {
|
||||
return resource instanceof StructureDefinition ? ((StructureDefinition) resource).getDerivationElement().primitiveValue() : null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -621,6 +630,10 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
|||
|
||||
}
|
||||
|
||||
public List<CachedCanonicalResource<T>> getCachedList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
List<T> res = new ArrayList<>();
|
||||
for (CachedCanonicalResource<T> t : list) {
|
||||
|
|
|
@ -97,11 +97,13 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
|
||||
private final String filename;
|
||||
private final IContextResourceLoader loader;
|
||||
private PackageInformation pi;
|
||||
|
||||
public PackageResourceLoader(PackageResourceInformation pri, IContextResourceLoader loader) {
|
||||
public PackageResourceLoader(PackageResourceInformation pri, IContextResourceLoader loader, PackageInformation pi) {
|
||||
super(pri.getResourceType(), pri.getId(), loader == null ? pri.getUrl() :loader.patchUrl(pri.getUrl(), pri.getResourceType()), pri.getVersion(), pri.getSupplements(), pri.getDerivation());
|
||||
this.filename = pri.getFilename();
|
||||
this.loader = loader;
|
||||
this.pi = pi;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,9 +112,9 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
FileInputStream f = new FileInputStream(filename);
|
||||
try {
|
||||
if (loader != null) {
|
||||
return R5Hacker.fixR5BrokenResource((CanonicalResource) loader.loadResource(f, true));
|
||||
return setPi(R5Hacker.fixR5BrokenResource((CanonicalResource) loader.loadResource(f, true)));
|
||||
} else {
|
||||
return R5Hacker.fixR5BrokenResource((CanonicalResource) new JsonParser().parse(f));
|
||||
return setPi(R5Hacker.fixR5BrokenResource((CanonicalResource) new JsonParser().parse(f)));
|
||||
}
|
||||
} finally {
|
||||
f.close();
|
||||
|
@ -121,6 +123,11 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
throw new FHIRException("Error loading "+filename+": "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private CanonicalResource setPi(CanonicalResource cr) {
|
||||
cr.setSourcePackage(pi);
|
||||
return cr;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ILoadFilter {
|
||||
|
@ -478,6 +485,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
if ((types == null || types.size() == 0) && loader != null) {
|
||||
types = loader.getTypes();
|
||||
}
|
||||
PackageInformation pii = new PackageInformation(pi);
|
||||
if (VersionUtilities.isR2Ver(pi.fhirVersion()) || !pi.canLazyLoad() || !allowLazyLoading) {
|
||||
// can't lazy load R2 because of valueset/codesystem implementation
|
||||
if (types == null || types.size() == 0) {
|
||||
|
@ -485,7 +493,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
}
|
||||
for (String s : pi.listResources(types)) {
|
||||
try {
|
||||
loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageInformation(pi));
|
||||
loadDefinitionItem(s, pi.load("package", s), loader, null, pii);
|
||||
t++;
|
||||
} catch (Exception e) {
|
||||
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
|
||||
|
@ -499,9 +507,9 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
if (!pri.getFilename().contains("ig-r4") && (loader == null || loader.wantLoad(pi, pri))) {
|
||||
try {
|
||||
if (!pri.hasId()) {
|
||||
loadDefinitionItem(pri.getFilename(), new FileInputStream(pri.getFilename()), loader, null, new PackageInformation(pi));
|
||||
loadDefinitionItem(pri.getFilename(), new FileInputStream(pri.getFilename()), loader, null, pii);
|
||||
} else {
|
||||
registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageInformation(pi));
|
||||
registerResourceFromPackage(new PackageResourceLoader(pri, loader, pii), pii);
|
||||
}
|
||||
t++;
|
||||
} catch (FHIRException e) {
|
||||
|
|
|
@ -33,8 +33,10 @@ public class TypeManager {
|
|||
typeDefinitions.clear();
|
||||
primitiveNames.clear();
|
||||
dataTypeNames.clear();
|
||||
for (StructureDefinition sd : structures.getList()) {
|
||||
see(sd);
|
||||
for (CanonicalResourceManager<StructureDefinition>.CachedCanonicalResource<StructureDefinition> cr : structures.getCachedList()) {
|
||||
if (!"constraint".equals(cr.getDerivation())) {
|
||||
see(cr.getResource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +47,7 @@ public class TypeManager {
|
|||
}
|
||||
|
||||
public void see(StructureDefinition sd) {
|
||||
if (sd.getDerivation() != TypeDerivationRule.CONSTRAINT) {
|
||||
if (sd.getDerivation() != TypeDerivationRule.CONSTRAINT && (sd.getSourcePackage() == null || !sd.getSourcePackage().isExamplesPackage())) {
|
||||
String type = sd.getType();
|
||||
Set<StructureDefinition> types = typeDefinitions.get(type);
|
||||
if (types == null) {
|
||||
|
|
|
@ -827,7 +827,7 @@ public class Element extends Base {
|
|||
public boolean equalsDeep(Base other) {
|
||||
if (!super.equalsDeep(other))
|
||||
return false;
|
||||
if (isPrimitive() && other.isPrimitive())
|
||||
if (isPrimitive() && primitiveValue() != null && other.isPrimitive())
|
||||
return primitiveValue().equals(other.primitiveValue());
|
||||
if (isPrimitive() || other.isPrimitive())
|
||||
return false;
|
||||
|
|
|
@ -102,6 +102,9 @@ public interface IResourceValidator {
|
|||
boolean isForPublication();
|
||||
IResourceValidator setForPublication(boolean forPublication);
|
||||
|
||||
boolean isExample();
|
||||
IResourceValidator setExample(boolean example);
|
||||
|
||||
public boolean isWarnOnDraftOrExperimental();
|
||||
|
||||
public IResourceValidator setWarnOnDraftOrExperimental(boolean warnOnDraftOrExperimental);
|
||||
|
|
Loading…
Reference in New Issue