Fix cardinality generation in Element Table

This commit is contained in:
Grahame Grieve 2025-01-05 12:08:17 +11:00
parent ea2dd37fa1
commit 8663068d28
3 changed files with 20 additions and 4 deletions

View File

@ -4985,7 +4985,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context, imageFolder, inlineGraphics, true, defFile, rc.getUniqueLocalPrefix());
gen.setTreelines(false);
TableModel model = initElementTable(gen, corePath, true, profile.getId()+"e", true, TableGenerationMode.XHTML);
new ElementTable(context, groups, this).build(gen, model);
new ElementTable(context, groups, this, ToolingExtensions.hasExtensionValue(profile, ToolingExtensions.EXT_PROFILE_VIEW_HINT, "element-view-replace-cardinality")).build(gen, model);
try {
return gen.generate(model, imagePath, 0, outputTracker);

View File

@ -468,11 +468,13 @@ public class ElementTable {
private RenderingContext context;
private List<TableGroup> groups;
private DataRenderer dr;
private boolean replaceCardinality;
public ElementTable(RenderingContext context, List<TableGroup> groups, DataRenderer dr) {
public ElementTable(RenderingContext context, List<TableGroup> groups, DataRenderer dr, boolean replaceCardinality) {
this.context = context;
this.groups = groups;
this.dr = dr;
this.replaceCardinality = replaceCardinality;
}
public void build(HierarchicalTableGenerator gen, TableModel table) throws FHIRFormatError, DefinitionException, IOException {
@ -542,7 +544,9 @@ public class ElementTable {
cell.setInnerTable(true);
cell.addText(e.getName()).addStyle("font-weight: bold");
cell.addPiece(gen.new Piece("br"));
if ("1".equals(e.min) && "1".equals(e.max)) {
if (!replaceCardinality) {
cell.addText("Cardinality: "+e.min+".."+e.max);
} else if ("1".equals(e.min) && "1".equals(e.max)) {
cell.addText("Required");
} else if ("0".equals(e.min) && "*".equals(e.max)) {
cell.addText("Optional, Repeating");
@ -790,7 +794,9 @@ public class ElementTable {
x.code().tx(name);
String min = c.value.primitiveValue();
String max = c.value2.primitiveValue();
if ("1".equals(min) && "1".equals(max)) {
if (!replaceCardinality) {
x.tx("has cardinality: "+min+".."+max);
} else if ("1".equals(min) && "1".equals(max)) {
x.tx("is required");
} else if ("0".equals(min) && "*".equals(max)) {
x.tx("is Optional and repeats");

View File

@ -99,6 +99,7 @@ import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent;
import org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.model.UrlType;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
@ -1236,4 +1237,13 @@ public class ToolingExtensions {
return res;
}
public static boolean hasExtensionValue(StructureDefinition src, String url, String value) {
for (Extension ext : src.getExtension()) {
if (url.equals(ext.getUrl()) && ext.hasValue() && value.equals(ext.getValue().primitiveValue())) {
return true;
}
}
return false;
}
}