Skip to content

Commit 08065d6

Browse files
committed
fix show-inherited-invariants:false hiding a profile's own invariants (#321)
The Constraints-table filter compared constraint.source to the profile url with exact string equality, but pin-canonicals appends |version to source in the render model, so own invariants were misread as inherited and dropped. Compare version-insensitively, and drop the genMode!=DIFF escape so the snapshot/key tables also honour the flag. Default behaviour is unchanged.
1 parent ff30021 commit 08065d6

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
@@ -1122,7 +1122,7 @@ public void addVariation(ElementDefinitionConstraintComponent c, String id) {
11221122
// 'primary' indicates if this is the initial definition of the constraint or if it's a subsequently profiled
11231123
// version of the constraint. The logic here could probably use some work, but all it does is make sure the
11241124
// 'official' one comes first, so it's not critical that there are issues.
1125-
if (!c.hasSource() || c.getSource().equals(sd.getUrl()) || (c.getSource().startsWith("http://hl7.org/fhir/StructureDefinition/") && !c.getSource().substring(41).contains("/"))) {
1125+
if (isOwnInvariant(c) || (c.getSource().startsWith("http://hl7.org/fhir/StructureDefinition/") && !c.getSource().substring(41).contains("/"))) {
11261126
if (primary == null) {
11271127
primary = variations.get(constraintHash(c));
11281128
if (primary==null)
@@ -1187,6 +1187,28 @@ else if (constraint.hasSource() && constraint.getSource().equals("http://hl7.org
11871187
}
11881188
}
11891189

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

0 commit comments

Comments
 (0)