fix problem with bad maps from core spec

This commit is contained in:
Grahame Grieve 2020-03-06 12:28:45 +11:00
parent d8262c056c
commit 2050052c95
1 changed files with 46 additions and 20 deletions

View File

@ -585,6 +585,13 @@ public class ProfileUtilities extends TranslatingUtilities {
else
messages.add(new ValidationMessage(Source.ProfileValidator, ValidationMessage.IssueType.VALUE, url, msg, ValidationMessage.IssueSeverity.ERROR));
}
// hack around a problem in R4 definitions (somewhere?)
for (ElementDefinition ed : derived.getSnapshot().getElement()) {
for (ElementDefinitionMappingComponent mm : ed.getMapping()) {
mm.setMap(mm.getMap().trim());
}
}
if (derived.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
for (ElementDefinition ed : derived.getSnapshot().getElement()) {
if (!ed.hasBase()) {
@ -2490,16 +2497,19 @@ public class ProfileUtilities extends TranslatingUtilities {
for (ElementDefinitionMappingComponent d : base.getMapping()) {
found = found || (d.getIdentity().equals(s.getIdentity()) && d.getMap().equals(s.getMap()));
}
if (!found)
if (!found) {
base.getMapping().add(s);
}
}
else if (trimDifferential)
}
else if (trimDifferential) {
derived.getMapping().clear();
else
for (ElementDefinitionMappingComponent t : derived.getMapping())
} else {
for (ElementDefinitionMappingComponent t : derived.getMapping()) {
t.setUserData(DERIVATION_EQUALS, true);
}
}
}
for (ElementDefinitionMappingComponent m : base.getMapping()) {
if (m.hasMap()) {
m.setMap(m.getMap().trim());
@ -2509,9 +2519,10 @@ public class ProfileUtilities extends TranslatingUtilities {
// todo: constraints are cumulative. there is no replacing
for (ElementDefinitionConstraintComponent s : base.getConstraint()) {
s.setUserData(IS_DERIVED, true);
if (!s.hasSource())
if (!s.hasSource()) {
s.setSource(srcSD.getUrl());
}
}
if (derived.hasConstraint()) {
for (ElementDefinitionConstraintComponent s : derived.getConstraint()) {
if (!base.hasConstraint(s.getKey())) {
@ -2521,19 +2532,22 @@ public class ProfileUtilities extends TranslatingUtilities {
}
}
for (IdType id : derived.getCondition()) {
if (!base.hasCondition(id))
if (!base.hasCondition(id)) {
base.getCondition().add(id);
}
}
// now, check that we still have a bindable type; if not, delete the binding - see task 8477
if (dest.hasBinding() && !hasBindableType(dest))
if (dest.hasBinding() && !hasBindableType(dest)) {
dest.setBinding(null);
}
// finally, we copy any extensions from source to dest
for (Extension ex : derived.getExtension()) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, ex.getUrl());
if (sd == null || sd.getSnapshot() == null || sd.getSnapshot().getElementFirstRep().getMax().equals("1"))
if (sd == null || sd.getSnapshot() == null || sd.getSnapshot().getElementFirstRep().getMax().equals("1")) {
ToolingExtensions.removeExtension(dest, ex.getUrl());
}
dest.addExtension(ex.copy());
}
}
@ -2622,18 +2636,21 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean hasBindableType(ElementDefinition ed) {
for (TypeRefComponent tr : ed.getType()) {
if (Utilities.existsInList(tr.getWorkingCode(), "Coding", "CodeableConcept", "Quantity", "uri", "string", "code"))
if (Utilities.existsInList(tr.getWorkingCode(), "Coding", "CodeableConcept", "Quantity", "uri", "string", "code")) {
return true;
}
}
return false;
}
private boolean isLargerMax(String derived, String base) {
if ("*".equals(base))
if ("*".equals(base)) {
return false;
if ("*".equals(derived))
}
if ("*".equals(derived)) {
return true;
}
return Integer.parseInt(derived) > Integer.parseInt(base);
}
@ -2645,22 +2662,26 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean codesInExpansion(List<ValueSetExpansionContainsComponent> contains, ValueSetExpansionComponent expansion) {
for (ValueSetExpansionContainsComponent cc : contains) {
if (!inExpansion(cc, expansion.getContains()))
if (!inExpansion(cc, expansion.getContains())) {
return false;
if (!codesInExpansion(cc.getContains(), expansion))
}
if (!codesInExpansion(cc.getContains(), expansion)) {
return false;
}
}
return true;
}
private boolean inExpansion(ValueSetExpansionContainsComponent cc, List<ValueSetExpansionContainsComponent> contains) {
for (ValueSetExpansionContainsComponent cc1 : contains) {
if (cc.getSystem().equals(cc1.getSystem()) && cc.getCode().equals(cc1.getCode()))
if (cc.getSystem().equals(cc1.getSystem()) && cc.getCode().equals(cc1.getCode())) {
return true;
if (inExpansion(cc, cc1.getContains()))
}
if (inExpansion(cc, cc1.getContains())) {
return true;
}
}
return false;
}
@ -2707,33 +2728,38 @@ public class ProfileUtilities extends TranslatingUtilities {
private int findEnd(List<ElementDefinition> list, ElementDefinition ed, int cursor) {
String path = ed.getPath()+".";
while (cursor < list.size() && list.get(cursor).getPath().startsWith(path))
while (cursor < list.size() && list.get(cursor).getPath().startsWith(path)) {
cursor++;
}
return cursor;
}
private ElementDefinition getMatchInDerived(ElementDefinition ed, List<ElementDefinition> list) {
for (ElementDefinition t : list)
if (t.getPath().equals(ed.getPath()))
for (ElementDefinition t : list) {
if (t.getPath().equals(ed.getPath())) {
return t;
}
}
return null;
}
private ElementDefinition getMatchInDerived(ElementDefinition ed, List<ElementDefinition> list, int start, int end) {
for (int i = start; i < end; i++) {
ElementDefinition t = list.get(i);
if (t.getPath().equals(ed.getPath()))
if (t.getPath().equals(ed.getPath())) {
return t;
}
}
return null;
}
private boolean isImmediateChild(ElementDefinition ed) {
String p = ed.getPath();
if (!p.contains("."))
if (!p.contains(".")) {
return false;
}
p = p.substring(p.indexOf(".")+1);
return !p.contains(".");
}