fix for 1.4.0 problems

This commit is contained in:
Grahame Grieve 2020-03-17 11:13:50 +11:00
parent c46d4dd779
commit 851d1fc228
4 changed files with 64 additions and 14 deletions

View File

@ -234,6 +234,14 @@ public class ToolingExtensions {
} }
} }
public static void addUriExtension(Element e, String url, String uri) {
Extension ex = getExtension(e, url);
if (ex != null)
ex.setValue(new UriType(uri));
else
e.getExtension().add(Factory.newExtension(url, new UriType(uri), true));
}
public static void addBooleanExtension(Element e, String url, boolean content) { public static void addBooleanExtension(Element e, String url, boolean content) {
Extension ex = getExtension(e, url); Extension ex = getExtension(e, url);
if (ex != null) if (ex != null)

View File

@ -2459,7 +2459,7 @@ public class ProfileUtilities extends TranslatingUtilities {
if (derived.hasIsSummaryElement()) { if (derived.hasIsSummaryElement()) {
if (!Base.compareDeep(derived.getIsSummaryElement(), base.getIsSummaryElement(), false)) { if (!Base.compareDeep(derived.getIsSummaryElement(), base.getIsSummaryElement(), false)) {
if (base.hasIsSummary()) if (base.hasIsSummary() && !context.getVersion().equals("1.4.0")) // work around a known issue with some 1.4.0 cosntraints
throw new Error(context.formatMessage(I18nConstants.ERROR_IN_PROFILE__AT__BASE_ISSUMMARY___DERIVED_ISSUMMARY__, pn, derived.getPath(), base.getIsSummaryElement().asStringValue(), derived.getIsSummaryElement().asStringValue())); throw new Error(context.formatMessage(I18nConstants.ERROR_IN_PROFILE__AT__BASE_ISSUMMARY___DERIVED_ISSUMMARY__, pn, derived.getPath(), base.getIsSummaryElement().asStringValue(), derived.getIsSummaryElement().asStringValue()));
base.setIsSummaryElement(derived.getIsSummaryElement().copy()); base.setIsSummaryElement(derived.getIsSummaryElement().copy());
} else if (trimDifferential) } else if (trimDifferential)

View File

@ -21,6 +21,7 @@ package org.hl7.fhir.r5.context;
*/ */
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -41,6 +42,8 @@ import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory; import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
import org.hl7.fhir.r5.context.TerminologyCache.CacheToken; import org.hl7.fhir.r5.context.TerminologyCache.CacheToken;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.BooleanType; import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CapabilityStatement; import org.hl7.fhir.r5.model.CapabilityStatement;
import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.CodeSystem;
@ -50,6 +53,7 @@ import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.Coding; import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.ConceptMap; import org.hl7.fhir.r5.model.ConceptMap;
import org.hl7.fhir.r5.model.Constants; import org.hl7.fhir.r5.model.Constants;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus; import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.ImplementationGuide; import org.hl7.fhir.r5.model.ImplementationGuide;
@ -67,6 +71,7 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.SearchParameter; import org.hl7.fhir.r5.model.SearchParameter;
import org.hl7.fhir.r5.model.StringType; import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.StructureMap; import org.hl7.fhir.r5.model.StructureMap;
import org.hl7.fhir.r5.model.TerminologyCapabilities; import org.hl7.fhir.r5.model.TerminologyCapabilities;
import org.hl7.fhir.r5.model.TerminologyCapabilities.TerminologyCapabilitiesCodeSystemComponent; import org.hl7.fhir.r5.model.TerminologyCapabilities.TerminologyCapabilitiesCodeSystemComponent;
@ -126,6 +131,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
private Object lock = new Object(); // used as a lock for the data that follows private Object lock = new Object(); // used as a lock for the data that follows
protected String version;
private Map<String, Map<String, Resource>> allResourcesById = new HashMap<String, Map<String, Resource>>(); private Map<String, Map<String, Resource>> allResourcesById = new HashMap<String, Map<String, Resource>>();
// all maps are to the full URI // all maps are to the full URI
@ -236,9 +243,13 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url)); throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
} }
if (r instanceof StructureDefinition) if (r instanceof StructureDefinition) {
structures.see((StructureDefinition) m); StructureDefinition sd = (StructureDefinition) m;
else if (r instanceof ValueSet) if ("1.4.0".equals(version)) {
fixOldSD(sd);
}
structures.see(sd);
} else if (r instanceof ValueSet)
valueSets.see((ValueSet) m); valueSets.see((ValueSet) m);
else if (r instanceof CodeSystem) else if (r instanceof CodeSystem)
codeSystems.see((CodeSystem) m); codeSystems.see((CodeSystem) m);
@ -264,6 +275,21 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
} }
public void fixOldSD(StructureDefinition sd) {
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT && sd.getType().equals("Extension") && sd.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
sd.setSnapshot(null);
}
for (ElementDefinition ed : sd.getDifferential().getElement()) {
if (ed.getPath().equals("Extension.url") || ed.getPath().endsWith(".extension.url") ) {
ed.setMin(1);
ed.getBase().setMin(1);
}
if ("extension".equals(ed.getSliceName())) {
ed.setSliceName(null);
}
}
}
/* /*
* Compare business versions, returning "true" if the candidate newer version is in fact newer than the oldVersion * Compare business versions, returning "true" if the candidate newer version is in fact newer than the oldVersion
* Comparison will work for strictly numeric versions as well as multi-level versions separated by ., -, _, : or space * Comparison will work for strictly numeric versions as well as multi-level versions separated by ., -, _, : or space
@ -1277,4 +1303,29 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
public Map<String, byte[]> getBinaries() { public Map<String, byte[]> getBinaries() {
return binaries; return binaries;
} }
public void finishLoading() {
for (StructureDefinition sd : listStructures()) {
try {
if (sd.getSnapshot().isEmpty()) {
generateSnapshot(sd);
// new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "snapshot", tail(sd.getUrl())+".xml")), sd);
}
} catch (Exception e) {
// System.out.println("Unable to generate snapshot for "+tail(sd.getUrl()) +" from "+tail(sd.getBaseDefinition())+" because "+e.getMessage());
}
}
}
protected String tail(String url) {
if (Utilities.noString(url)) {
return "noname";
}
if (url.contains("/")) {
return url.substring(url.lastIndexOf("/")+1);
}
return url;
}
} }

View File

@ -101,7 +101,6 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
} }
private Questionnaire questionnaire; private Questionnaire questionnaire;
private String version;
private String revision; private String revision;
private String date; private String date;
private IValidatorFactory validatorFactory; private IValidatorFactory validatorFactory;
@ -179,6 +178,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
res.setAllowLoadingDuplicates(true); res.setAllowLoadingDuplicates(true);
res.version = pi.getNpm().get("version").getAsString(); res.version = pi.getNpm().get("version").getAsString();
res.loadFromPackage(pi, loader, filter); res.loadFromPackage(pi, loader, filter);
res.finishLoading();
return res; return res;
} }
@ -540,15 +540,6 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
return result; return result;
} }
private String tail(String url) {
if (Utilities.noString(url)) {
return "noname";
}
if (url.contains("/")) {
return url.substring(url.lastIndexOf("/")+1);
}
return url;
}
public void loadBinariesFromFolder(String folder) throws FileNotFoundException, Exception { public void loadBinariesFromFolder(String folder) throws FileNotFoundException, Exception {
for (String n : new File(folder).list()) { for (String n : new File(folder).list()) {