Skip to content

Commit 71fec72

Browse files
Merge pull request #1315 from vadi2/fix-show-inherited-invariants
fix show-inherited-invariants:false hiding a profile's own invariants
2 parents 9fac1c9 + 08065d6 commit 71fec72

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ public void addVariation(ElementDefinitionConstraintComponent c, String id) {
11251125
// 'primary' indicates if this is the initial definition of the constraint or if it's a subsequently profiled
11261126
// version of the constraint. The logic here could probably use some work, but all it does is make sure the
11271127
// 'official' one comes first, so it's not critical that there are issues.
1128-
if (!c.hasSource() || c.getSource().equals(sd.getUrl()) || (c.getSource().startsWith("http://hl7.org/fhir/StructureDefinition/") && !c.getSource().substring(41).contains("/"))) {
1128+
if (isOwnInvariant(c) || (c.getSource().startsWith("http://hl7.org/fhir/StructureDefinition/") && !c.getSource().substring(41).contains("/"))) {
11291129
if (primary == null) {
11301130
primary = variations.get(constraintHash(c));
11311131
if (primary==null)
@@ -1190,6 +1190,28 @@ else if (constraint.hasSource() && constraint.getSource().equals("http://hl7.org
11901190
}
11911191
}
11921192

1193+
/**
1194+
* True when a constraint belongs to this profile itself (i.e. it is not inherited from a base
1195+
* definition), so it must still be shown when inherited invariants are suppressed
1196+
* (show-inherited-invariants:false). A constraint with no source, or whose source matches this
1197+
* profile's canonical url - ignoring any |version suffix that pin-canonicals may append - is "own".
1198+
*/
1199+
private boolean isOwnInvariant(ElementDefinitionConstraintComponent c) {
1200+
return !c.hasSource() || sameCanonical(c.getSource(), sd.getUrl());
1201+
}
1202+
1203+
private static boolean sameCanonical(String a, String b) {
1204+
return unversionedUrl(a).equals(unversionedUrl(b));
1205+
}
1206+
1207+
private static String unversionedUrl(String u) {
1208+
if (u == null) {
1209+
return "";
1210+
}
1211+
int i = u.indexOf('|');
1212+
return i >= 0 ? u.substring(0, i) : u;
1213+
}
1214+
11931215
public List<ElementDefinition> elementsForMode(int genMode) {
11941216
switch (genMode) {
11951217
case GEN_MODE_DIFF:
@@ -1241,7 +1263,7 @@ public String invOldMode(boolean withHeadings, int genMode) throws IOException {
12411263
ConstraintInfo ci = constraintMap.get(key);
12421264
for (ConstraintVariation cv : ci.getVariations()) {
12431265
ElementDefinitionConstraintComponent inv = cv.getConstraint();
1244-
if (!inv.hasSource() || inv.getSource().equals(sd.getUrl()) || allInvariants || genMode!=GEN_MODE_DIFF ) {
1266+
if (isOwnInvariant(inv) || allInvariants) {
12451267
tr = tbl.tr();
12461268
tr.td().tx(inv.getKey());
12471269
tr.td().tx(grade(inv));

0 commit comments

Comments
 (0)