mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-02 17:39:11 +00:00
Improve complex extension rendering when rendering by profile
This commit is contained in:
parent
636dbf14d4
commit
af75c51fea
@ -5625,6 +5625,11 @@ public boolean hasTarget() {
|
|||||||
|
|
||||||
@Block()
|
@Block()
|
||||||
public static class ElementDefinitionMappingComponent extends Element implements IBaseDatatypeElement {
|
public static class ElementDefinitionMappingComponent extends Element implements IBaseDatatypeElement {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return identity+"=" + map;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An internal reference to the definition of a mapping.
|
* An internal reference to the definition of a mapping.
|
||||||
*/
|
*/
|
||||||
|
@ -397,6 +397,11 @@ public class StructureDefinition extends CanonicalResource {
|
|||||||
|
|
||||||
@Block()
|
@Block()
|
||||||
public static class StructureDefinitionMappingComponent extends BackboneElement implements IBaseBackboneElement {
|
public static class StructureDefinitionMappingComponent extends BackboneElement implements IBaseBackboneElement {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return identity + "=" + uri + " (\""+name+"\")";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Internal id that is used to identify this mapping set when specific mappings are made.
|
* An Internal id that is used to identify this mapping set when specific mappings are made.
|
||||||
*/
|
*/
|
||||||
|
@ -27,6 +27,7 @@ import org.hl7.fhir.r5.utils.ToolingExtensions;
|
|||||||
import org.hl7.fhir.r5.utils.XVerExtensionManager;
|
import org.hl7.fhir.r5.utils.XVerExtensionManager;
|
||||||
import org.hl7.fhir.r5.utils.XVerExtensionManager.XVerExtensionStatus;
|
import org.hl7.fhir.r5.utils.XVerExtensionManager.XVerExtensionStatus;
|
||||||
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
||||||
|
import org.hl7.fhir.utilities.DebugUtilities;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
import org.hl7.fhir.utilities.xhtml.NodeType;
|
import org.hl7.fhir.utilities.xhtml.NodeType;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
@ -41,6 +42,9 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildNarrative(RenderingStatus status, XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
|
public void buildNarrative(RenderingStatus status, XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
|
||||||
|
if ("medicationrequest-coded-oral-axid".equals(r.getId())) {
|
||||||
|
DebugUtilities.breakpoint();
|
||||||
|
}
|
||||||
renderResourceTechDetails(r, x);
|
renderResourceTechDetails(r, x);
|
||||||
try {
|
try {
|
||||||
StructureDefinition sd = context.getContext().fetchTypeDefinition(r.fhirType());
|
StructureDefinition sd = context.getContext().fetchTypeDefinition(r.fhirType());
|
||||||
@ -332,13 +336,14 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!round2 && !exemptFromRendering(child)) {
|
} else if (!round2 && !exemptFromRendering(child)) {
|
||||||
if (isExtension(p)) {
|
boolean isExt = isExtension(p);
|
||||||
|
if (isExt) {
|
||||||
status.setExtensions(true);
|
status.setExtensions(true);
|
||||||
}
|
}
|
||||||
List<ElementDefinition> grandChildren = getChildrenForPath(profile, allElements, path+"."+p.getName());
|
List<ElementDefinition> grandChildren = getChildrenForPath(profile, allElements, path+"."+p.getName());
|
||||||
filterGrandChildren(grandChildren, path+"."+p.getName(), p);
|
filterGrandChildren(grandChildren, path+"."+p.getName(), p);
|
||||||
if (p.getValues().size() > 0) {
|
if (p.getValues().size() > 0) {
|
||||||
if (isSimple(child)) {
|
if (isSimple(child) && !isExt) {
|
||||||
XhtmlNode para = x.isPara() ? para = x : x.para();
|
XhtmlNode para = x.isPara() ? para = x : x.para();
|
||||||
String name = p.getName();
|
String name = p.getName();
|
||||||
if (name.endsWith("[x]"))
|
if (name.endsWith("[x]"))
|
||||||
@ -383,22 +388,40 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||||||
x.add(tbl);
|
x.add(tbl);
|
||||||
}
|
}
|
||||||
} else if (isExtension(p)) {
|
} else if (isExtension(p)) {
|
||||||
|
StructureDefinition sd = context.getContext().fetchResource(StructureDefinition.class, p.getUrl());
|
||||||
for (ResourceWrapper v : p.getValues()) {
|
for (ResourceWrapper v : p.getValues()) {
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
ResourceWrapper vp = v.child("value");
|
ResourceWrapper vp = v.child("value");
|
||||||
List<ResourceWrapper> ev = v.children("extension");
|
List<ResourceWrapper> ev = v.children("extension");
|
||||||
if (vp != null) {
|
if (vp != null) {
|
||||||
XhtmlNode para = x.para();
|
XhtmlNode para = x.para();
|
||||||
para.b().addText(labelforExtension(p.getName()));
|
para.b().addText(labelforExtension(sd, p.getUrl()));
|
||||||
para.tx(": ");
|
para.tx(": ");
|
||||||
renderLeaf(status, res, vp, profile, child, x, para, false, showCodeDetails, displayHints, path, indent);
|
renderLeaf(status, res, vp, profile, child, x, para, false, showCodeDetails, displayHints, path, indent);
|
||||||
} else if (!ev.isEmpty()) {
|
} else if (!ev.isEmpty()) {
|
||||||
XhtmlNode bq = x.addTag("blockquote");
|
XhtmlNode bq = x.addTag("blockquote");
|
||||||
bq.para().b().addText(labelforExtension(p.getName()));
|
bq.para().b().addText(labelforExtension(sd, p.getUrl()));
|
||||||
|
// what happens now depends. If all the children are simple extensions, they'll be rendered as properties
|
||||||
|
boolean allSimple = true;
|
||||||
for (ResourceWrapper vv : ev) {
|
for (ResourceWrapper vv : ev) {
|
||||||
StructureDefinition ex = context.getWorker().fetchTypeDefinition("Extension");
|
if (!vv.has("value")) {
|
||||||
List<ElementDefinition> children = getChildrenForPath(profile, ex.getSnapshot().getElement(), "Extension");
|
allSimple = false;
|
||||||
generateByProfile(status, res, ex, vv, allElements, child, children, bq, "Extension", showCodeDetails, indent+1);
|
}
|
||||||
|
}
|
||||||
|
if (allSimple) {
|
||||||
|
XhtmlNode ul = bq.ul();
|
||||||
|
for (ResourceWrapper vv : ev) {
|
||||||
|
XhtmlNode li = ul.li();
|
||||||
|
li.tx(labelForSubExtension(vv.primitiveValue("url"), sd));
|
||||||
|
li.tx(": ");
|
||||||
|
renderLeaf(status, res, vv.child("value"), sd, child, x, li, isExt, showCodeDetails, displayHints, path, indent);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (ResourceWrapper vv : ev) {
|
||||||
|
StructureDefinition ex = context.getWorker().fetchTypeDefinition("Extension");
|
||||||
|
List<ElementDefinition> children = getChildrenForPath(profile, ex.getSnapshot().getElement(), "Extension");
|
||||||
|
generateByProfile(status, res, ex, vv, allElements, child, children, bq, "Extension", showCodeDetails, indent+1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -417,8 +440,11 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String labelforExtension(String url) {
|
private String labelForSubExtension(String url, StructureDefinition sd) {
|
||||||
StructureDefinition sd = context.getContext().fetchResource(StructureDefinition.class, url);
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String labelforExtension(StructureDefinition sd, String url) {
|
||||||
if (sd == null) {
|
if (sd == null) {
|
||||||
return tail(url);
|
return tail(url);
|
||||||
} else {
|
} else {
|
||||||
@ -467,7 +493,7 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExtension(NamedResourceWrapperList p) {
|
public boolean isExtension(NamedResourceWrapperList p) {
|
||||||
return p.getName().contains("extension[");
|
return p.getUrl() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -571,12 +597,12 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||||||
// 2. Park it
|
// 2. Park it
|
||||||
NamedResourceWrapperList nl = null;
|
NamedResourceWrapperList nl = null;
|
||||||
for (NamedResourceWrapperList t : results) {
|
for (NamedResourceWrapperList t : results) {
|
||||||
if (t.getName().equals(url)) {
|
if (t.getUrl() != null && t.getUrl().equals(url)) {
|
||||||
nl = t;
|
nl = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nl == null) {
|
if (nl == null) {
|
||||||
nl = new NamedResourceWrapperList(url);
|
nl = new NamedResourceWrapperList(p.getName(), url);
|
||||||
results.add(nl);
|
results.add(nl);
|
||||||
}
|
}
|
||||||
nl.getValues().add(v);
|
nl.getValues().add(v);
|
||||||
|
@ -31,16 +31,28 @@ public abstract class ResourceWrapper {
|
|||||||
|
|
||||||
public static class NamedResourceWrapperList {
|
public static class NamedResourceWrapperList {
|
||||||
private String name;
|
private String name;
|
||||||
|
private String url; // for extension definitions
|
||||||
private List<ResourceWrapper> values = new ArrayList<ResourceWrapper>();
|
private List<ResourceWrapper> values = new ArrayList<ResourceWrapper>();
|
||||||
|
|
||||||
public NamedResourceWrapperList(String name) {
|
public NamedResourceWrapperList(String name) {
|
||||||
super();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NamedResourceWrapperList(String name, String url) {
|
||||||
|
super();
|
||||||
|
this.name = name;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ResourceWrapper> getValues() {
|
public List<ResourceWrapper> getValues() {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -275,6 +275,7 @@ public class ToolingExtensions {
|
|||||||
public static final String EXT_VS_CS_SUPPL_NEEDED = "http://hl7.org/fhir/StructureDefinition/valueset-supplement";
|
public static final String EXT_VS_CS_SUPPL_NEEDED = "http://hl7.org/fhir/StructureDefinition/valueset-supplement";
|
||||||
public static final String EXT_TYPE_PARAMETER = "http://hl7.org/fhir/tools/StructureDefinition/type-parameter";
|
public static final String EXT_TYPE_PARAMETER = "http://hl7.org/fhir/tools/StructureDefinition/type-parameter";
|
||||||
public static final String EXT_ALTERNATE_CANONICAL = "http://hl7.org/fhir/StructureDefinition/alternate-canonical";
|
public static final String EXT_ALTERNATE_CANONICAL = "http://hl7.org/fhir/StructureDefinition/alternate-canonical";
|
||||||
|
public static final String EXT_SUPPRESSED = "http://hl7.org/fhir/StructureDefinition/elementdefinition-suppress";
|
||||||
|
|
||||||
// specific extension helpers
|
// specific extension helpers
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user