work to improve snapshot generation

This commit is contained in:
Grahame Grieve 2019-07-23 05:44:12 +10:00
parent 5bf00c7aca
commit ecb3a8e1fe
4 changed files with 48 additions and 15 deletions

View File

@ -64,6 +64,7 @@ import org.hl7.fhir.r5.model.ElementDefinition.SlicingRules;
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.BindingStrength;
import org.hl7.fhir.r5.model.Enumerations.FHIRVersion;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.IntegerType;
import org.hl7.fhir.r5.model.PrimitiveType;
@ -234,6 +235,7 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean igmode;
private boolean exception;
private TerminologyServiceOptions terminologyServiceOptions = new TerminologyServiceOptions();
private boolean newSlicingProcessing;
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp) {
super();
@ -422,7 +424,7 @@ public class ProfileUtilities extends TranslatingUtilities {
throw new DefinitionException("Circular snapshot references detected; cannot generate snapshot (stack = "+snapshotStack.toString()+")");
snapshotStack.add(derived.getUrl());
if (webUrl != null && !webUrl.endsWith("/"))
if (!Utilities.noString(webUrl) && !webUrl.endsWith("/"))
webUrl = webUrl + '/';
derived.setSnapshot(new StructureDefinitionSnapshotComponent());
@ -729,17 +731,33 @@ public class ProfileUtilities extends TranslatingUtilities {
// we come here whether they are sliced in the diff, or whether the short cut is used.
if (typeList.get(0).type != null) {
// this is the short cut method, we've just dived in and specified a type slice.
// we insert a cloned element with the right types at the start of the diffMatches
ElementDefinition ed = new ElementDefinition();
ed.setPath(determineTypeSlicePath(diffMatches.get(0).getPath(), cpath));
for (TypeSlice ts : typeList)
ed.addType().setCode(ts.type);
ed.setSlicing(new ElementDefinitionSlicingComponent());
ed.getSlicing().addDiscriminator().setType(DiscriminatorType.TYPE).setPath("$this");
ed.getSlicing().setRules(SlicingRules.CLOSED);
ed.getSlicing().setOrdered(false);
diffMatches.add(0, ed);
differential.getElement().add(ndc, ed);
// in R3 (and unpatched R4, as a workaround right now...
if (!FHIRVersion.isR4Plus(context.getVersion()) || !newSlicingProcessing) { // newSlicingProcessing is a work around for editorial loop dependency
// we insert a cloned element with the right types at the start of the diffMatches
ElementDefinition ed = new ElementDefinition();
ed.setPath(determineTypeSlicePath(diffMatches.get(0).getPath(), cpath));
for (TypeSlice ts : typeList)
ed.addType().setCode(ts.type);
ed.setSlicing(new ElementDefinitionSlicingComponent());
ed.getSlicing().addDiscriminator().setType(DiscriminatorType.TYPE).setPath("$this");
ed.getSlicing().setRules(SlicingRules.CLOSED);
ed.getSlicing().setOrdered(false);
diffMatches.add(0, ed);
differential.getElement().add(ndc, ed);
} else {
// as of R4, this changed; if there's no slice, there's no constraint on the slice types, only one the type.
// so the element we insert specifies no types (= all types) allowed in the base, not just the listed type.
// see also discussion here: https://chat.fhir.org/#narrow/stream/179177-conformance/topic/Slicing.20a.20non-repeating.20element
ElementDefinition ed = new ElementDefinition();
ed.setPath(determineTypeSlicePath(diffMatches.get(0).getPath(), cpath));
ed.setSlicing(new ElementDefinitionSlicingComponent());
ed.getSlicing().addDiscriminator().setType(DiscriminatorType.TYPE).setPath("$this");
ed.getSlicing().setRules(SlicingRules.CLOSED);
ed.getSlicing().setOrdered(false);
diffMatches.add(0, ed);
differential.getElement().add(ndc, ed);
}
}
int ndl = findEndOfElement(differential, ndc);
// the first element is setting up the slicing
@ -4344,6 +4362,18 @@ public class ProfileUtilities extends TranslatingUtilities {
public void setTerminologyServiceOptions(TerminologyServiceOptions terminologyServiceOptions) {
this.terminologyServiceOptions = terminologyServiceOptions;
}
public boolean isNewSlicingProcessing() {
return newSlicingProcessing;
}
public void setNewSlicingProcessing(boolean newSlicingProcessing) {
this.newSlicingProcessing = newSlicingProcessing;
}
}

View File

@ -289,6 +289,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
}
}
}
version = pi.version();
}
public void loadFromFile(String file, IContextResourceLoader loader) throws IOException, FHIRException {

View File

@ -248,7 +248,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
}
}
public class ResourceContext {
public static class ResourceContext {
Bundle bundleResource;
DomainResource resourceResource;

View File

@ -41,7 +41,6 @@ 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.SnapShotGenerationTests2.TestPKP;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.utils.CodingUtilities;
@ -425,6 +424,7 @@ public class SnapShotGenerationTests {
private void testGen() throws DefinitionException, FHIRException, IOException, EOperationOutcome {
if (!Utilities.noString(test.register)) {
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
pu.setNewSlicingProcessing(true);
List<String> errors = new ArrayList<String>();
pu.setIds(test.included, false);
StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, test.included.getBaseDefinition());
@ -434,6 +434,7 @@ public class SnapShotGenerationTests {
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
StructureDefinition output = test.getSource().copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages , new TestPKP());
pu.setNewSlicingProcessing(true);
pu.setIds(test.getSource(), false);
if (test.isSort()) {
List<String> errors = new ArrayList<String>();
@ -462,6 +463,7 @@ public class SnapShotGenerationTests {
if (!sd.hasSnapshot()) {
StructureDefinition base = getSD(sd.getBaseDefinition());
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages , new TestPKP());
pu.setNewSlicingProcessing(true);
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, sd, url, errors);
if (!errors.isEmpty())