fix for additional type choice option when generating snapshots

This commit is contained in:
Grahame Grieve 2019-12-13 09:25:41 +11:00
parent 4287b1ae68
commit 498d3bf505
3 changed files with 28 additions and 10 deletions

View File

@ -910,10 +910,7 @@ public class ProfileUtilities extends TranslatingUtilities {
if (diffMatches.size() > i+1) {
throw new FHIRException("Invalid slicing : there is more than one type slice at "+diffMatches.get(i).getPath()+", but one of them ("+diffMatches.get(i).getSliceName()+") has min = 1, so the other slices cannot exist");
}
if (diffMatches.get(i).getType().size() != 1) {
throw new FHIRException("Unexpected condition in differential: type-slice.type-list.size() != 1 at "+diffMatches.get(i).getPath()+"/"+diffMatches.get(i).getSliceName());
}
fixedType = diffMatches.get(i).getType().get(0).getCode();
fixedType = determineFixedType(diffMatches, fixedType, i);
}
ndc = differential.getElement().indexOf(diffMatches.get(i));
ndl = findEndOfElement(differential, ndc);
@ -1159,10 +1156,7 @@ public class ProfileUtilities extends TranslatingUtilities {
// now process the siblings, which should each be type constrained - and may also have their own children. they may match existing slices
// now we process the base scope repeatedly for each instance of the item in the differential list
for (int i = start; i < diffMatches.size(); i++) {
if (diffMatches.get(i).getType().size() != 1) {
throw new FHIRException("Unexpected condition in differential: type-slice.type-list.size() != 1 at "+diffMatches.get(i).getPath()+"/"+diffMatches.get(i).getSliceName());
}
String type = diffMatches.get(i).getType().get(0).getCode();
String type = determineFixedType(diffMatches, fixedType, i);
// our processing scope for the differential is the item in the list, and all the items before the next one in the list
if (diffMatches.get(i).getMin() > 0) {
if (diffMatches.size() > i+1) {
@ -1381,6 +1375,26 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public String determineFixedType(List<ElementDefinition> diffMatches, String fixedType, int i) {
if (diffMatches.get(i).getType().size() == 0 && diffMatches.get(i).hasSliceName()) {
String n = tail(diffMatches.get(i).getPath()).replace("[x]", "");
String t = diffMatches.get(i).getSliceName().substring(n.length());
if (isDataType(t)) {
fixedType = t;
} else if (isPrimitive(Utilities.uncapitalize(t))) {
fixedType = Utilities.uncapitalize(t);
} else {
throw new FHIRException("Unexpected condition in differential: type-slice.type-list.size() == 10 and implicit slice name does not contain a valid type ('"+t+"'?) at "+diffMatches.get(i).getPath()+"/"+diffMatches.get(i).getSliceName());
}
} else if (diffMatches.get(i).getType().size() == 1) {
fixedType = diffMatches.get(i).getType().get(0).getCode();
} else {
throw new FHIRException("Unexpected condition in differential: type-slice.type-list.size() != 1 at "+diffMatches.get(i).getPath()+"/"+diffMatches.get(i).getSliceName());
}
return fixedType;
}
private BaseTypeSlice chooseMatchingBaseSlice(List<BaseTypeSlice> baseSlices, String type) {
for (BaseTypeSlice bs : baseSlices) {
if (bs.type.equals(type)) {

View File

@ -175,7 +175,11 @@ public class SnapShotGenerationTests {
if (!Utilities.noString(include))
included = (StructureDefinition) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", include+".xml"));
if (!Utilities.noString(register)) {
included = (StructureDefinition) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", register+".xml"));
try {
included = (StructureDefinition) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", register+".xml"));
} catch (Exception e) {
included = (StructureDefinition) new JsonParser().parse(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", register+".json"));
}
}
}
}

View File

@ -17,7 +17,7 @@
<properties>
<hapi_fhir_version>4.1.0</hapi_fhir_version>
<validator_test_case_version>1.0.16-SNAPSHOT</validator_test_case_version>
<validator_test_case_version>1.0.17-SNAPSHOT</validator_test_case_version>
</properties>
<artifactId>org.hl7.fhir.core</artifactId>