more WIP on rendering rewrite

This commit is contained in:
Grahame Grieve 2024-06-14 17:15:56 +10:00
parent 506dad8752
commit 2f5ef0b216
22 changed files with 557 additions and 2607 deletions

View File

@ -383,7 +383,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
String url = r.getUrl();
if (!allowLoadingDuplicates && hasResourceVersion(r.getType(), url, r.getVersion()) && !packageInfo.isHTO()) {
// spcial workaround for known problems with existing packages
// special workaround for known problems with existing packages
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}

View File

@ -27,6 +27,7 @@ import org.hl7.fhir.r5.model.CapabilityStatement.SystemRestfulInteraction;
import org.hl7.fhir.r5.model.CapabilityStatement.TypeRestfulInteraction;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Element;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.FHIRVersion;
@ -35,11 +36,13 @@ import org.hl7.fhir.r5.model.OperationDefinition;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.StructureDefinitionRenderer.InternalMarkdownProcessor;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.NodeType;
@ -47,7 +50,26 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class CapabilityStatementRenderer extends ResourceRenderer {
public CapabilityStatementRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("CapabilityStatementRenderer only renders native resources directly");
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (CapabilityStatement) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
private static final String EXPECTATION = "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation";
private static final String COMBINED = "http://hl7.org/fhir/StructureDefinition/capabilitystatement-search-parameter-combination";
private static final String SP_BASE = "http://hl7.org/fhir/searchparameter/";
@ -266,20 +288,8 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
}
//Constructors
public CapabilityStatementRenderer(RenderingContext context) {
super(context);
}
public CapabilityStatementRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (CapabilityStatement) dr);
}
public boolean render(XhtmlNode x, CapabilityStatement conf) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, CapabilityStatement conf) throws FHIRFormatError, DefinitionException, IOException {
status.setExtensions(true);
boolean igRenderingMode = (context.getRules() == GenerationRules.IG_PUBLISHER);
FHIRVersion currentVersion = conf.getFhirVersion();
String versionPathComponent = getVersionPathComponent(currentVersion.getDefinition());
@ -298,7 +308,7 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_FHIR_VER, currentVersion.toCode()) + " ");
addSupportedFormats(uList, conf);
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_PUB_ON, displayDateTime(conf.getDateElement()) + " "));
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_PUB_ON, displayDateTime(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), conf.getDateElement())) + " "));
uList.li().addText(context.formatPhrase(RenderingContext.CAPABILITY_PUB_BY, conf.getPublisherElement().asStringValue()) + " ");
@ -355,7 +365,6 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
addWarningPanel(x,"⹋⹋ - this mark indicates that there are more than one expectation extensions present");
}
return true;
}
private String getVersionPathComponent(String definition) {
@ -374,12 +383,6 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
return cs.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((CapabilityStatement) r).present();
}
private boolean hasOp(CapabilityStatementRestResourceComponent r, TypeRestfulInteraction on) {
for (ResourceInteractionComponent op : r.getInteraction()) {
if (op.getCode() == on)
@ -1451,16 +1454,6 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
node.addTag("span").attribute("class", "lead").addText(text);
}
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
if (r.has("name")) {
return r.children("name").get(0).getBase().primitiveValue();
}
return "??";
}
private void addResourceLink(XhtmlNode node, String name, String canonicalUri) {
addResourceLink(node, name, canonicalUri, false, "");
}

View File

@ -1,10 +1,10 @@
package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
@ -13,7 +13,6 @@ import org.hl7.fhir.r5.comparison.VersionComparisonAnnotation;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.Enumerations.CodeSystemContentMode;
import org.hl7.fhir.r5.model.CodeSystem.CodeSystemFilterComponent;
import org.hl7.fhir.r5.model.CodeSystem.CodeSystemHierarchyMeaning;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
@ -21,27 +20,48 @@ import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent;
import org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent;
import org.hl7.fhir.r5.model.CodeSystem.PropertyComponent;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.CodeSystemContentMode;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.PrimitiveType;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.renderers.CodeSystemRenderer.Translateable;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.MultiLanguagePolicy;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.CodeSystemNavigator;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.LoincLinker;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class CodeSystemRenderer extends TerminologyRenderer {
public CodeSystemRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("CodeSystemRenderer only renders native resources directly");
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (CodeSystem) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public class Translateable {
private String lang;
@ -62,25 +82,10 @@ public class CodeSystemRenderer extends TerminologyRenderer {
}
private Boolean doMarkdown = null;
public CodeSystemRenderer(RenderingContext context) {
super(context);
}
public CodeSystemRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
private Boolean doMarkdown = null;
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (CodeSystem) dr);
}
public boolean render(XhtmlNode x, CodeSystem cs) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
public void render(RenderingStatus status, XhtmlNode x, CodeSystem cs) throws FHIRFormatError, DefinitionException, IOException {
if (context.isHeader()) {
XhtmlNode h = x.h2();
h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName());
@ -92,9 +97,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
boolean props = generateProperties(x, cs);
generateFilters(x, cs);
List<UsedConceptMap> maps = new ArrayList<UsedConceptMap>();
hasExtensions = generateCodeSystemContent(x, cs, hasExtensions, maps, props);
return hasExtensions;
generateCodeSystemContent(status, x, cs, maps, props);
}
public void describe(XhtmlNode x, CodeSystem cs) {
@ -200,7 +203,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
}
}
private boolean generateCodeSystemContent(XhtmlNode x, CodeSystem cs, boolean hasExtensions, List<UsedConceptMap> maps, boolean props) throws FHIRFormatError, DefinitionException, IOException {
private void generateCodeSystemContent(RenderingStatus status, XhtmlNode x, CodeSystem cs, List<UsedConceptMap> maps, boolean props) throws FHIRFormatError, DefinitionException, IOException {
if (props) {
x.para().b().tx(formatPhrase(RenderingContext.CODESYSTEM_CONCEPTS));
}
@ -212,7 +215,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
p.paramValue("code-count", CodeSystemUtilities.countCodes(cs));
p.sentenceForParams(sentenceForContent(cs.getContent(), cs));
if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
return false;
return;
}
XhtmlNode t = x.table( "codes");
@ -258,7 +261,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
addCopyColumn(addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, null, false), maps));
}
for (ConceptDefinitionComponent c : csNav.getConcepts(null)) {
hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs.size() < 2 ? langs : null, isSupplement) || hasExtensions;
addDefineRowToTable(status, t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs.size() < 2 ? langs : null, isSupplement);
}
if (langs.size() >= 2) {
Collections.sort(langs);
@ -272,7 +275,6 @@ public class CodeSystemRenderer extends TerminologyRenderer {
addLanguageRow(c, t, langs);
}
}
return hasExtensions;
}
private void makeHierarchyParam(XhtmlNode x, CodeSystem cs, Enumeration<CodeSystemHierarchyMeaning> hm) {
@ -421,7 +423,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int level, boolean hasHierarchy, boolean hasDisplay, boolean hasDefinitions, boolean comment, boolean version, boolean deprecated, List<UsedConceptMap> maps, String system, CodeSystem cs, List<PropertyComponent> properties, CodeSystemNavigator csNav, List<String> langs, boolean isSupplement) throws FHIRFormatError, DefinitionException, IOException {
private void addDefineRowToTable(RenderingStatus status, XhtmlNode t, ConceptDefinitionComponent c, int level, boolean hasHierarchy, boolean hasDisplay, boolean hasDefinitions, boolean comment, boolean version, boolean deprecated, List<UsedConceptMap> maps, String system, CodeSystem cs, List<PropertyComponent> properties, CodeSystemNavigator csNav, List<String> langs, boolean isSupplement) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
XhtmlNode tr = t.tr();
boolean notCurrent = CodeSystemUtilities.isNotCurrent(cs, c);
@ -615,7 +617,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
}
List<ConceptDefinitionComponent> ocl = csNav.getOtherChildren(c);
for (ConceptDefinitionComponent cc : csNav.getConcepts(c)) {
hasExtensions = addDefineRowToTable(t, cc, level+1, hasHierarchy, hasDisplay, hasDefinitions, comment, version, deprecated, maps, system, cs, properties, csNav, langs, isSupplement) || hasExtensions;
addDefineRowToTable(status, t, cc, level+1, hasHierarchy, hasDisplay, hasDefinitions, comment, version, deprecated, maps, system, cs, properties, csNav, langs, isSupplement);
}
for (ConceptDefinitionComponent cc : ocl) {
tr = t.tr();
@ -643,7 +645,6 @@ public class CodeSystemRenderer extends TerminologyRenderer {
td.nbsp();
clipboard(td, "icon_clipboard_j.png", "JSON", "\"system\" : \""+Utilities.escapeXml(cs.getUrl())+"\",\n"+(cs.getVersionNeeded() ? "\"version\" : \""+Utilities.escapeXml(cs.getVersion())+"\",\n" : "")+"\"code\" : \""+Utilities.escapeXml(c.getCode())+"\",\n\"display\" : \""+Utilities.escapeXml(c.getDisplay())+"\"\n");
}
return hasExtensions;
}
private String getDisplay(String lang, ConceptDefinitionComponent c) {

View File

@ -4,33 +4,45 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CompartmentDefinition;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.StructureDefinitionRenderer.InternalMarkdownProcessor;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
public class CompartmentDefinitionRenderer extends ResourceRenderer {
public CompartmentDefinitionRenderer(RenderingContext context) {
super(context);
}
public CompartmentDefinitionRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
public CompartmentDefinitionRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("StructureDefinitionRenderer only renders native resources directly");
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (CompartmentDefinition) dr);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (CompartmentDefinition) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, CompartmentDefinition cpd) throws FHIRFormatError, DefinitionException, IOException {
StringBuilder in = new StringBuilder();
StringBuilder out = new StringBuilder();
for (CompartmentDefinitionResourceComponent cc: cpd.getResource()) {
@ -56,7 +68,6 @@ public class CompartmentDefinitionRenderer extends ResourceRenderer {
out.toString()+
"</ul></div>\r\n");
x.getChildNodes().addAll(xn.getChildNodes());
return true;
}
public void describe(XhtmlNode x, CompartmentDefinition cd) {
@ -67,19 +78,4 @@ public class CompartmentDefinitionRenderer extends ResourceRenderer {
return cd.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((CompartmentDefinition) r).present();
}
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
if (r.has("name")) {
return r.children("name").get(0).getBase().primitiveValue();
}
return "??";
}
}

View File

@ -1,6 +1,7 @@
package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -10,6 +11,7 @@ import java.util.List;
import java.util.Map;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.Coding;
@ -22,11 +24,12 @@ import org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent;
import org.hl7.fhir.r5.model.ContactDetail;
import org.hl7.fhir.r5.model.ContactPoint;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Enumerations.ConceptMapRelationship;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.ConceptMapRenderer.CollateralDefinition;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.Utilities;
@ -35,6 +38,28 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ConceptMapRenderer extends TerminologyRenderer {
public ConceptMapRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("ConceptMapRenderer only renders native resources directly");
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (ConceptMap) r, false);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public static class CollateralDefinition {
private Resource resource;
private String label;
@ -296,19 +321,9 @@ public class ConceptMapRenderer extends TerminologyRenderer {
}
}
public ConceptMapRenderer(RenderingContext context) {
super(context);
}
public ConceptMapRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (ConceptMap) dr, false);
}
public boolean render(XhtmlNode x, ConceptMap cm, boolean header) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, ConceptMap cm, boolean header) throws FHIRFormatError, DefinitionException, IOException {
if (header) {
x.h2().addText(cm.getName()+" ("+cm.getUrl()+")");
}
@ -330,7 +345,7 @@ public class ConceptMapRenderer extends TerminologyRenderer {
p.addText(Utilities.capitalize(cm.getStatus().toString())+" "+ (context.formatPhrase(RenderingContext.CONC_MAP_NO_PROD_USE) + " "));
else
p.addText(Utilities.capitalize(cm.getStatus().toString())+". ");
p.tx(context.formatPhrase(RenderingContext.CONC_MAP_PUB_ON, (cm.hasDate() ? display(cm.getDateElement()) : "?ngen-10?")+" by "+cm.getPublisher()) + " ");
p.tx(context.formatPhrase(RenderingContext.CONC_MAP_PUB_ON, (cm.hasDate() ? displayDataType(cm.getDateElement()) : "?ngen-10?")+" by "+cm.getPublisher()) + " ");
if (!cm.getContact().isEmpty()) {
p.tx(" (");
boolean firsti = true;
@ -403,13 +418,13 @@ public class ConceptMapRenderer extends TerminologyRenderer {
pp.b().tx(context.formatPhrase(RenderingContext.CONC_MAP_GRP, gc) + " ");
pp.tx(context.formatPhrase(RenderingContext.CONC_MAP_FROM) + " ");
if (grp.hasSource()) {
renderCanonical(cm, pp, grp.getSource());
renderCanonical(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), cm), pp, grp.getSource());
} else {
pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC));
}
pp.tx(" to ");
if (grp.hasTarget()) {
renderCanonical(cm, pp, grp.getTarget());
renderCanonical(new ResourceElement(context.getContextUtilities(), context.getProfileUtilities(), cm), pp, grp.getTarget());
} else {
pp.code(context.formatPhrase(RenderingContext.CONC_MAP_CODE_SYS_UNSPEC));
}
@ -630,7 +645,6 @@ public class ConceptMapRenderer extends TerminologyRenderer {
}
}
}
return true;
}
public void describe(XhtmlNode x, ConceptMap cm) {

View File

@ -657,7 +657,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
}
private String displayReference(ResourceElement type) {
protected String displayReference(ResourceElement type) {
if (type.has("display")) {
return type.primitiveValue("display");
} else if (type.has("reference")) {

View File

@ -17,8 +17,9 @@ import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -27,34 +28,31 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
public class ObservationNode {
private String ref;
private ResourceWithReference obs;
private String reference;
private ResourceElement resource;
private List<ObservationNode> contained;
}
public DiagnosticReportRenderer(RenderingContext context) {
super(context);
}
public DiagnosticReportRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws IOException, FHIRException, EOperationOutcome {
return render(x, (DiagnosticReport) dr);
}
public boolean render(XhtmlNode x, ResourceWrapper dr) throws IOException, FHIRException, EOperationOutcome {
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement dr) throws IOException, FHIRException, EOperationOutcome {
renderDiagnosticReport(status, x, dr);
}
public void renderDiagnosticReport(RenderingStatus status, XhtmlNode x, ResourceElement dr) throws IOException, FHIRException, EOperationOutcome {
XhtmlNode h2 = x.h2();
render(h2, getProperty(dr, "code").value());
renderDataType(status, h2, dr.child("code"));
h2.tx(" ");
PropertyWrapper pw = getProperty(dr, "category");
if (valued(pw)) {
List<ResourceElement> cats = dr.children("category");
if (!cats.isEmpty()) {
h2.tx("(");
boolean first = true;
for (BaseWrapper b : pw.getValues()) {
for (ResourceElement b : cats) {
if (first) first = false; else h2.tx(", ");
render(h2, b);
renderDataType(status, h2, b);
}
h2.tx(") ");
}
@ -63,136 +61,97 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
if (dr.has("subject")) {
tr = tbl.tr();
tr.td().tx(context.formatPhrase(RenderingContext.GENERAL_SUBJ));
populateSubjectSummary(tr.td(), getProperty(dr, "subject").value());
populateSubjectSummary(status, tr.td(), dr.child("subject"));
}
DataType eff = null;
DataType iss = null;
ResourceElement eff = null;
ResourceElement iss = null;
if (dr.has("effective[x]")) {
tr = tbl.tr();
tr.td().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_WHEN));
eff = (DataType) getProperty(dr, "effective[x]").value().getBase();
render(tr.td(), eff);
tr.td().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_WHEN));
eff = dr.child("effective[x]");
renderDataType(status, tr.td(), eff);
}
if (dr.has("issued")) {
tr = tbl.tr();
tr.td().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_REP));
eff = (DataType) getProperty(dr, "issued").value().getBase();
render(tr.td(), getProperty(dr, "issued").value());
iss = dr.child("issued");
renderDataType(status, tr.td(), iss);
}
pw = getProperty(dr, "perfomer");
if (valued(pw)) {
tr = tbl.tr();
tr.td().tx(Utilities.pluralize((context.formatPhrase(RenderingContext.DIAG_REP_REND_PER)), pw.getValues().size()));
XhtmlNode tdr = tr.td();
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
render(tdr, v);
}
}
pw = getProperty(dr, "identifier");
if (valued(pw)) {
tr = tbl.tr();
tr.td().tx(Utilities.pluralize((context.formatPhrase(RenderingContext.DIAG_REP_REND_IDENTIFIER)), pw.getValues().size())+":");
XhtmlNode tdr = tr.td();
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
render(tdr, v);
}
}
pw = getProperty(dr, "request");
if (valued(pw)) {
tr = tbl.tr();
tr.td().tx(Utilities.pluralize((context.formatPhrase(RenderingContext.GENERAL_REQUEST)), pw.getValues().size())+":");
XhtmlNode tdr = tr.td();
for (BaseWrapper v : pw.getValues()) {
tdr.tx(" ");
render(tdr, v);
}
tdr.br();
}
addTableRow(status, tbl, dr, RenderingContext.DIAG_REP_REND_PER, "performer");
addTableRow(status, tbl, dr, RenderingContext.DIAG_REP_REND_IDENTIFIER, "identifier");
addTableRow(status, tbl, dr, RenderingContext.GENERAL_REQUEST, "request");
x.para().b().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_REPDET));
pw = getProperty(dr, "result");
if (valued(pw)) {
List<ObservationNode> observations = fetchObservations(pw.getValues(), dr);
buildObservationsTable(x, observations, eff, iss);
List<ResourceElement> items = dr.children("result");
if (!items.isEmpty()) {
List<ObservationNode> observations = fetchObservations(items, dr);
buildObservationsTable(status, x, observations, eff, iss);
}
pw = getProperty(dr, "conclusion");
if (valued(pw)) {
if (pw.fhirType().equals("markdown")) {
render(x, pw.value());
if (dr.has("conclusion")) {
ResourceElement conc = dr.child("conclusion");
if (conc.fhirType().equals("markdown")) {
renderDataType(status, x, conc);
} else {
render(x.para(), pw.value());
renderDataType(status, x.para(), conc);
}
}
pw = getProperty(dr, "conclusionCode");
if (!valued(pw)) {
pw = getProperty(dr, "codedDiagnosis");
}
if (valued(pw)) {
XhtmlNode p = x.para();
p.b().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_CODECON));
XhtmlNode ul = x.ul();
for (BaseWrapper v : pw.getValues()) {
render(ul.li(), v);
}
}
return false;
}
public boolean render(XhtmlNode x, DiagnosticReport dr) throws IOException, FHIRException, EOperationOutcome {
render(x, new DirectWrappers.ResourceWrapperDirect(this.context, dr));
for (Resource resource : dr.getContained()) {
tbl = x.table("grid");
addTableRow(status, tbl, dr, RenderingContext.DIAG_REP_REND_CODECON, "conclusionCode", "codedDiagnosis");
for (ResourceElement cont : dr.children("contained")) {
x.hr();
RendererFactory.factory(resource, context).render(x, resource);
RendererFactory.factory(cont, context).renderResource(status, x, cont);
}
return true;
}
public void describe(XhtmlNode x, DiagnosticReport dr) {
x.tx(display(dr));
private void addTableRow(RenderingStatus status, XhtmlNode tbl, ResourceElement dr, String constName, String... names) throws FHIRFormatError, DefinitionException, IOException {
List<ResourceElement> items = dr.childrenMN(names);
if (!items.isEmpty()) {
XhtmlNode tr = tbl.tr();
tr.td().tx(Utilities.pluralize(context.formatPhrase(constName), items.size()));
XhtmlNode tdr = tr.td();
for (ResourceElement v : items) {
tdr.tx(" ");
renderDataType(status, tdr, v);
}
}
}
public void describeDiagnosticReport(XhtmlNode x, ResourceElement dr) {
x.tx(displayDiagnosticReport(dr));
}
public String display(DiagnosticReport dr) {
return display(dr.getCode());
public String displayDiagnosticReport(ResourceElement dr) {
return displayDataType(dr.child("code"));
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return display((DiagnosticReport) r);
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return displayDiagnosticReport(r);
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return "Not done yet";
}
private void populateSubjectSummary(XhtmlNode container, BaseWrapper subject) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome {
ResourceWrapper r = fetchResource(subject);
private void populateSubjectSummary(RenderingStatus status, XhtmlNode container, ResourceElement subject) throws UnsupportedEncodingException, FHIRException, IOException, EOperationOutcome {
ResourceElement r = fetchResource(subject);
if (r == null)
container.tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_UNABLE));
else if (r.getName().equals("Patient"))
else if (r.fhirType().equals("Patient"))
generatePatientSummary(container, r);
else
container.tx(context.formatPhrase(RenderingContext.GENERAL_TODO));
}
private void generatePatientSummary(XhtmlNode c, ResourceWrapper r) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
private void generatePatientSummary(XhtmlNode c, ResourceElement r) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
new PatientRenderer(context).describe(c, r);
}
private List<ObservationNode> fetchObservations(List<BaseWrapper> list, ResourceWrapper rw) throws UnsupportedEncodingException, FHIRException, IOException {
private List<ObservationNode> fetchObservations(List<ResourceElement> list, ResourceElement rw) throws UnsupportedEncodingException, FHIRException, IOException {
List<ObservationNode> res = new ArrayList<ObservationNode>();
for (BaseWrapper b : list) {
for (ResourceElement b : list) {
if (b.has("reference")) {
ObservationNode obs = new ObservationNode();
obs.ref = b.get("reference").primitiveValue();
@ -209,7 +168,7 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
return res;
}
private void buildObservationsTable(XhtmlNode root, List<ObservationNode> observations, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
private void buildObservationsTable(RenderingStatus status, XhtmlNode root, List<ObservationNode> observations, ResourceElement eff, ResourceElement iss) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tbl = root.table("grid");
boolean refRange = scanObsForRefRange(observations);
boolean flags = scanObsForFlags(observations);
@ -241,17 +200,15 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
tr.td().b().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_REP));
}
for (ObservationNode o : observations) {
addObservationToTable(tbl, o, 0, Integer.toString(cs), refRange, flags, note, effectiveTime, issued, eff, iss);
addObservationToTable(status, tbl, o, 0, Integer.toString(cs), refRange, flags, note, effectiveTime, issued, eff, iss);
}
}
private boolean scanObsForRefRange(List<ObservationNode> observations) {
for (ObservationNode o : observations) {
if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "referenceRange");
if (valued(pw)) {
return true;
}
for (ObservationNode o : observations) {
ResourceElement obs = o.resource;
if (obs != null && obs.has("referenceRange")) {
return true;
}
if (o.contained != null) {
if (scanObsForRefRange(o.contained)) {
@ -264,11 +221,9 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForNote(List<ObservationNode> observations) {
for (ObservationNode o : observations) {
if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "note");
if (valued(pw)) {
return true;
}
ResourceElement obs = o.resource;
if (obs != null && obs.has("note")) {
return true;
}
if (o.contained != null) {
if (scanObsForNote(o.contained)) {
@ -279,15 +234,11 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
return false;
}
private boolean scanObsForIssued(List<ObservationNode> observations, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
private boolean scanObsForIssued(List<ObservationNode> observations, ResourceElement iss) throws UnsupportedEncodingException, FHIRException, IOException {
for (ObservationNode o : observations) {
if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "issued");
if (valued(pw)) {
if (!Base.compareDeep(pw.value().getBase(), iss, true)) {
return true;
}
}
ResourceElement obs = o.resource;
if (obs != null && obs.has("issued") && (iss == null || !iss.matches(obs.child("issued")))) {
return true;
}
if (o.contained != null) {
if (scanObsForIssued(o.contained, iss)) {
@ -298,15 +249,11 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
return false;
}
private boolean scanObsForEffective(List<ObservationNode> observations, DataType eff) throws UnsupportedEncodingException, FHIRException, IOException {
private boolean scanObsForEffective(List<ObservationNode> observations, ResourceElement eff) throws UnsupportedEncodingException, FHIRException, IOException {
for (ObservationNode o : observations) {
if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "effective[x]");
if (valued(pw)) {
if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
return true;
}
}
ResourceElement obs = o.resource;
if (obs != null && obs.has("effective[x]") && (eff == null || !eff.matches(obs.child("effective[x]")))) {
return true;
}
if (o.contained != null) {
if (scanObsForEffective(o.contained, eff)) {
@ -319,18 +266,9 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
private boolean scanObsForFlags(List<ObservationNode> observations) throws UnsupportedEncodingException, FHIRException, IOException {
for (ObservationNode o : observations) {
if (o.obs != null && o.obs.getResource() != null) {
PropertyWrapper pw = getProperty(o.obs.getResource(), "interpretation");
if (valued(pw)) {
return true;
}
pw = getProperty(o.obs.getResource(), "status");
if (valued(pw)) {
if (!pw.value().getBase().primitiveValue().equals("final")) {
return true;
}
}
ResourceElement obs = o.resource;
if (obs != null && (obs.has("interpretation") || obs.has("status"))) {
return true;
}
if (o.contained != null) {
if (scanObsForFlags(o.contained)) {
@ -341,155 +279,124 @@ public class DiagnosticReportRenderer extends ResourceRenderer {
return false;
}
private void addObservationToTable(XhtmlNode tbl, ObservationNode o, int i, String cs, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
private void addObservationToTable(RenderingStatus status, XhtmlNode tbl, ObservationNode o, int i, String cs, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, ResourceElement eff, ResourceElement iss) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = tbl.tr();
if (o.obs != null && o.obs.getReference() == null) {
if (o.reference == null) {
XhtmlNode td = tr.td().colspan(cs);
td.i().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_NOTRES));
} else {
if (o.obs != null && o.obs.getResource() != null) {
addObservationToTable(tr, o.obs.getResource(), i, o.obs.getReference(), refRange, flags, note, effectiveTime, issued, eff, iss);
if (o.resource != null) {
addObservationToTable(status, tr, o.resource, i, o.reference, refRange, flags, note, effectiveTime, issued, eff, iss);
} else {
XhtmlNode td = tr.td().colspan(cs);
td.i().tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_OBS));
}
if (o.contained != null) {
for (ObservationNode c : o.contained) {
addObservationToTable(tbl, c, i+1, cs, refRange, flags, note, effectiveTime, issued, eff, iss);
addObservationToTable(status, tbl, c, i+1, cs, refRange, flags, note, effectiveTime, issued, eff, iss);
}
}
}
}
private void addObservationToTable(XhtmlNode tr, ResourceWrapper obs, int i, String ref, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
private void addObservationToTable(RenderingStatus status, XhtmlNode tr, ResourceElement obs, int i, String ref, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, ResourceElement eff, ResourceElement iss) throws UnsupportedEncodingException, FHIRException, IOException {
// code (+bodysite)
XhtmlNode td = tr.td();
PropertyWrapper pw = getProperty(obs, "code");
if (valued(pw)) {
render(td.ah(ref), pw.value());
if (obs.has("code")) {
renderDataType(status, td.ah(ref), obs.child("code"));
}
pw = getProperty(obs, "bodySite");
if (valued(pw)) {
if (obs.has("bodySite")) {
td.tx(" (");
render(td, pw.value());
renderDataType(status, td, obs.child("bodySite"));
td.tx(")");
}
// value / dataAbsentReason (in red)
td = tr.td();
pw = getProperty(obs, "value[x]");
if (valued(pw)) {
render(td, pw.value());
} else {
pw = getProperty(obs, "dataAbsentReason");
if (valued(pw)) {
XhtmlNode span = td.span("color: maroon", "Error");
span.tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_ERR) + " ");
render(span.b(), pw.value());
}
if (obs.has("value[x]")) {
renderDataType(status, td, obs.child("value[x]"));
} else if (obs.has("dataAbsentReason")) {
XhtmlNode span = td.span("color: maroon", "Error");
span.tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_ERR) + " ");
renderDataType(status, span.b(), obs.child("dataAbsentReason"));
}
if (refRange) {
// reference range
td = tr.td();
pw = getProperty(obs, "referenceRange");
if (valued(pw)) {
List<ResourceElement> items = obs.children("referenceRange");
if (!items.isEmpty()) {
boolean first = true;
for (BaseWrapper v : pw.getValues()) {
for (ResourceElement v : items) {
if (first) first = false; else td.br();
PropertyWrapper pwr = getProperty(v, "type");
if (valued(pwr)) {
render(td, pwr.value());
ResourceElement pwr = v.child("type");
if (pwr != null) {
renderDataType(status, td, pwr);
td.tx(": ");
}
PropertyWrapper pwt = getProperty(v, "text");
if (valued(pwt)) {
render(td, pwt.value());
ResourceElement pwt = v.child("text");
if (pwt != null) {
renderDataType(status, td, pwt);
} else {
PropertyWrapper pwl = getProperty(v, "low");
PropertyWrapper pwh = getProperty(v, "high");
if (valued(pwl) && valued(pwh)) {
render(td, pwl.value());
ResourceElement pwl = v.child("low");
ResourceElement pwh = v.child("high");
if (pwl != null && pwh != null) {
renderDataType(status, td, pwl);
td.tx(" - ");
render(td, pwh.value());
} else if (valued(pwl)) {
renderDataType(status, td, pwh);
} else if (pwl != null) {
td.tx(">");
render(td, pwl.value());
} else if (valued(pwh)) {
renderDataType(status, td, pwl);
} else if (pwh != null) {
td.tx("<");
render(td, pwh.value());
renderDataType(status, td, pwh);
} else {
td.tx("??");
}
}
pwr = getProperty(v, "appliesTo");
PropertyWrapper pwrA = getProperty(v, "age");
if (valued(pwr) || valued(pwrA)) {
List<ResourceElement> pwrF = v.children("appliesTo");
ResourceElement pwrA = v.child("age");
if (!pwrF.isEmpty() || pwrA != null) {
boolean firstA = true;
td.tx(" "+ (context.formatPhrase(RenderingContext.DIAG_REP_REND_FOR)) + " ");
if (valued(pwr)) {
for (BaseWrapper va : pwr.getValues()) {
if (!pwrF.isEmpty()) {
for (ResourceElement va : pwrF) {
if (firstA) firstA = false; else td.tx(", ");
render(td, va);
renderDataType(status, td, va);
}
}
if (valued(pwrA)) {
if (pwrA != null) {
if (firstA) firstA = false; else td.tx(", ");
td.tx(context.formatPhrase(RenderingContext.DIAG_REP_REND_AGE) + " ");
render(td, pwrA.value());
renderDataType(status, td, pwrA);
}
}
}
}
}
if (flags) {
// flags (status other than F, interpretation, )
td = tr.td();
boolean first = true;
pw = getProperty(obs, "status");
if (valued(pw)) {
if (!pw.value().getBase().primitiveValue().equals("final")) {
if (first) first = false; else td.br();
render(td, pw.value());
}
}
pw = getProperty(obs, "interpretation");
if (valued(pw)) {
for (BaseWrapper v : pw.getValues()) {
if (first) first = false; else td.br();
render(td, v);
}
}
}
if (note) {
td = tr.td();
pw = getProperty(obs, "note");
if (valued(pw)) {
for (BaseWrapper b : pw.getValues()) {
render(td, b);
addCellToTable(flags, status, tr, obs, null, "status", "interpretation");
addCellToTable(note, status, tr, obs, null, "note");
addCellToTable(effectiveTime, status, tr, obs, eff, "effective[x]");
addCellToTable(issued, status, tr, obs, iss, "issued");
}
private void addCellToTable(boolean included, RenderingStatus status, XhtmlNode tr, ResourceElement obs, ResourceElement diff, String... names) throws FHIRFormatError, DefinitionException, IOException {
if (included) {
XhtmlNode td = tr.td();
List<ResourceElement> list = obs.childrenMN(names);
if (!list.isEmpty()) {
boolean first = true;
for (ResourceElement b : list) {
if (diff == null || !diff.matches(b)) {
if (first) first = false; else td.tx(", ");
renderDataType(status, td, b);
}
}
}
}
if (effectiveTime) {
// effective if different to DR
td = tr.td();
pw = getProperty(obs, "effective[x]");
if (valued(pw)) {
if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
render(td, pw.value());
}
}
}
if (issued) {
// issued if different to DR
td = tr.td();
pw = getProperty(obs, "issued");
if (valued(pw)) {
if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
render(td, pw.value());
}
}
}
}
}
}

View File

@ -3,31 +3,31 @@ package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class EncounterRenderer extends ResourceRenderer {
public EncounterRenderer(RenderingContext context) {
super(context);
}
public boolean render(XhtmlNode x, Resource dr) throws UnsupportedEncodingException, IOException {
describe(x, dr);
return false;
}
public String display(Resource dr) {
return "Not done yet";
public EncounterRenderer(RenderingContext context) {
super(context);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "todo";
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return "Not done yet";
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("todo");
}
}

View File

@ -4,34 +4,42 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ImplementationGuideRenderer extends ResourceRenderer {
public ImplementationGuideRenderer(RenderingContext context) {
super(context);
}
public ImplementationGuideRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
public ImplementationGuideRenderer(RenderingContext context) {
super(context);
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("ImplementationGuideRenderer only renders native resources directly");
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (ImplementationGuide) dr);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (ImplementationGuide) r);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
public boolean render(XhtmlNode x, ImplementationGuide ig) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, ImplementationGuide ig) throws FHIRFormatError, DefinitionException, IOException {
x.h2().addText(ig.getName());
x.para().tx(context.formatPhrase(RenderingContext.IMP_GUIDE_URL)+" ");
x.pre().tx(ig.getUrl());
addMarkdown(x, ig.getDescription());
return true;
}
public void describe(XhtmlNode x, ImplementationGuide ig) {
@ -42,19 +50,5 @@ public class ImplementationGuideRenderer extends ResourceRenderer {
return ig.present();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((ImplementationGuide) r).present();
}
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
if (r.has("name")) {
return r.children("name").get(0).getBase().primitiveValue();
}
return "??";
}
}

View File

@ -1,21 +1,16 @@
package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Annotation;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.ListResource;
import org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent;
import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.ListResource;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ListRenderer extends ResourceRenderer {
@ -24,57 +19,55 @@ public class ListRenderer extends ResourceRenderer {
super(context);
}
public ListRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (ListResource) dr);
}
public boolean render(XhtmlNode x, ResourceWrapper list) throws FHIRFormatError, DefinitionException, IOException {
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "todo";
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement list) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (list.has("title")) {
x.h2().tx(list.get("title").primitiveValue());
x.h2().tx(list.primitiveValue("title"));
}
XhtmlNode t = x.table("clstu");
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
if (list.has("date")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_DATE, displayDateTime(list.get("date").dateTimeValue()))+" ");
td.tx(context.formatPhrase(RenderingContext.LIST_REND_DATE, displayDateTime(list.child("date")))+" ");
}
if (list.has("mode")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_MODE, list.get("mode").primitiveValue())+" ");
td.tx(context.formatPhrase(RenderingContext.LIST_REND_MODE, list.primitiveValue("mode"))+" ");
}
if (list.has("status")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_STAT, list.get("status").primitiveValue())+" ");
td.tx(context.formatPhrase(RenderingContext.LIST_REND_STAT, list.primitiveValue("status"))+" ");
}
if (list.has("code")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_CODE, displayBase(list.get("code")))+" ");
td.tx(context.formatPhrase(RenderingContext.LIST_REND_CODE, displayDataType(list.child("code")))+" ");
}
tr = t.tr();
td = tr.td();
if (list.has("subject")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_SUB)+" ");
shortForRef(td, list.get("subject"));
shortForRef(td, list.child("subject"));
}
if (list.has("encounter")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_ENC)+" ");
shortForRef(td, list.get("encounter"));
shortForRef(td, list.child("encounter"));
}
if (list.has("source")) {
td.tx(context.formatPhrase(RenderingContext.GENERAL_SRC)+" ");
shortForRef(td, list.get("encounter"));
shortForRef(td, list.child("encounter"));
}
if (list.has("orderedBy")) {
td.tx(context.formatPhrase(RenderingContext.LIST_REND_ORD, displayBase(list.get("orderedBy")))+" ");
td.tx(context.formatPhrase(RenderingContext.LIST_REND_ORD, displayDataType(list.child("orderedBy")))+" ");
}
for (ResourceElement a : list.children("note")) {
renderAnnotation(status, x, a);
}
// for (Annotation a : list.getNote()) {
// renderAnnotation(a, x);
// }
boolean flag = false;
boolean deleted = false;
boolean date = false;
for (BaseWrapper e : list.children("entry")) {
for (ResourceElement e : list.children("entry")) {
flag = flag || e.has("flag");
deleted = deleted || e.has("deleted");
date = date || e.has("date");
@ -91,105 +84,21 @@ public class ListRenderer extends ResourceRenderer {
if (deleted) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DEL));
}
for (BaseWrapper e : list.children("entry")) {
for (ResourceElement e : list.children("entry")) {
tr = t.tr();
shortForRef(tr.td(), e.get("item"));
shortForRef(tr.td(), e.child("item"));
if (date) {
tr.td().tx(e.has("date") ? e.get("date").dateTimeValue().toHumanDisplay() : "");
tr.td().tx(e.has("date") ? displayDateTime(e.child("date")) : "");
}
if (flag) {
tr.td().tx(e.has("flag") ? displayBase(e.get("flag")) : "");
tr.td().tx(e.has("flag") ? displayDataType(e.child("flag")) : "");
}
if (deleted) {
tr.td().tx(e.has("deleted") ? e.get("deleted").primitiveValue() : "");
tr.td().tx(e.has("deleted") ? e.primitiveValue("deleted") : "");
}
}
return false;
}
public boolean render(XhtmlNode x, ListResource list) throws FHIRFormatError, DefinitionException, IOException {
if (list.hasTitle()) {
x.h2().tx(list.getTitle());
}
XhtmlNode t = x.table("clstu");
XhtmlNode tr = t.tr();
if (list.hasDate()) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DATE, displayDateTime(list.getDateElement()))+" ");
}
if (list.hasMode()) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_MODE, list.getMode().getDisplay())+" ");
}
if (list.hasStatus()) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_STAT, list.getStatus().getDisplay())+" ");
}
if (list.hasCode()) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_CODE, display(list.getCode()))+" ");
}
tr = t.tr();
if (list.hasSubject()) {
if (list.getSubject().size() == 1) {
shortForRef(tr.td().txN("Subject: "), list.getSubjectFirstRep());
} else {
XhtmlNode td = tr.td();
td.txN(context.formatPhrase(RenderingContext.LIST_REND_SUB)+" ");
int i = 0;
for (Reference subj : list.getSubject()) {
if (i == list.getSubject().size() - 1) {
td.tx(" and ");
} else if (i > 0) {
td.tx(", ");
}
shortForRef(td, subj);
}
}
}
if (list.hasEncounter()) {
shortForRef(tr.td().txN(context.formatPhrase(RenderingContext.LIST_REND_ENC)+" "), list.getEncounter());
}
if (list.hasSource()) {
shortForRef(tr.td().txN(context.formatPhrase(RenderingContext.GENERAL_SRC)+" "), list.getEncounter());
}
if (list.hasOrderedBy()) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_ORD, display(list.getOrderedBy()))+" ");
}
for (Annotation a : list.getNote()) {
renderAnnotation(x, a);
}
boolean flag = false;
boolean deleted = false;
boolean date = false;
for (ListResourceEntryComponent e : list.getEntry()) {
flag = flag || e.hasFlag();
deleted = deleted || e.hasDeleted();
date = date || e.hasDate();
}
t = x.table("grid");
tr = t.tr().style("backgound-color: #eeeeee");
tr.td().b().tx(context.formatPhrase(RenderingContext.LIST_REND_ITEM));
if (date) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DAT));
}
if (flag) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_FLAG));
}
if (deleted) {
tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DEL));
}
for (ListResourceEntryComponent e : list.getEntry()) {
tr = t.tr();
shortForRef(tr.td(), e.getItem());
if (date) {
tr.td().tx(e.hasDate() ? e.getDate().toLocaleString() : "");
}
if (flag) {
tr.td().tx(e.hasFlag() ? display(e.getFlag()) : "");
}
if (deleted) {
tr.td().tx(e.hasDeleted() ? Boolean.toString(e.getDeleted()) : "");
}
}
return false;
}
public void describe(XhtmlNode x, ListResource list) {
x.tx(display(list));
}
@ -198,56 +107,13 @@ public class ListRenderer extends ResourceRenderer {
return list.getTitle();
}
@Override
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((ListResource) r).getTitle();
}
@Override
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
return "??";
}
private void shortForRef(XhtmlNode x, Reference ref) throws UnsupportedEncodingException, IOException {
ResourceWithReference r = context.getResolver() == null ? null : context.getResolver().resolve(context, ref.getReference());
private void shortForRef(XhtmlNode x, ResourceElement ref) throws UnsupportedEncodingException, IOException {
ResourceWithReference r = context.getResolver() == null ? null : context.getResolver().resolve(context, ref.primitiveValue("reference"));
if (r == null) {
x.tx(display(ref));
} else {
RendererFactory.factory(r.getResource().getName(), context).renderReference(r.getResource(), x, ref);
x.tx(displayReference(ref));
} else {
x.ah(r.getReference()).tx(RendererFactory.factory(r.getResource().fhirType(), context).displayResource(r.getResource()));
}
}
private XhtmlNode shortForRef(XhtmlNode x, Base ref) throws UnsupportedEncodingException, IOException {
if (ref == null) {
x.tx("(null)");
} else {
String disp = ref.getChildByName("display") != null && ref.getChildByName("display").hasValues() ? ref.getChildByName("display").getValues().get(0).primitiveValue() : null;
if (ref.getChildByName("reference").hasValues()) {
String url = ref.getChildByName("reference").getValues().get(0).primitiveValue();
if (url.startsWith("#")) {
x.tx("?ngen-16a?");
} else {
ResourceWithReference r = context.getResolver().resolve(context, url);
if (r == null) {
if (disp == null) {
disp = url;
}
x.tx(disp);
} else if (r.getResource() != null) {
RendererFactory.factory(r.getResource().getName(), context).renderReference(r.getResource(), x, (Reference) ref);
} else {
x.ah(r.getReference()).tx(url);
}
}
} else if (disp != null) {
x.tx(disp);
} else {
x.tx("?ngen-16?");
}
}
return x;
}
}

View File

@ -3,7 +3,8 @@ package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.ExtensionHelper;
@ -12,31 +13,34 @@ import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class OperationOutcomeRenderer extends ResourceRenderer {
public OperationOutcomeRenderer(RenderingContext context) {
super(context);
}
public OperationOutcomeRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (OperationOutcome) dr);
}
public boolean render(XhtmlNode x, OperationOutcome op) throws FHIRFormatError, DefinitionException, IOException {
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return "todo";
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement op) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
boolean hasSource = false;
boolean success = true;
for (OperationOutcomeIssueComponent i : op.getIssue()) {
for (ResourceElement i : op.children("issue")) {
success = success && i.getSeverity() == IssueSeverity.INFORMATION;
hasSource = hasSource || ExtensionHelper.hasExtension(i, ToolingExtensions.EXT_ISSUE_SOURCE);
}

View File

@ -2,7 +2,6 @@ package org.hl7.fhir.r5.renderers;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.utilities.Utilities;
@ -80,10 +79,6 @@ public class RendererFactory {
return new ProfileDrivenRenderer(context);
}
public static ResourceRenderer factory(ResourceWrapper rw, RenderingContext lrc) {
return factory(rw, lrc);
}
public static boolean hasSpecificRenderer(String rt) {
return Utilities.existsInList(rt,

View File

@ -29,11 +29,6 @@ import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
import org.hl7.fhir.r5.model.Reference;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.DirectWrappers.ResourceWrapperDirect;
import org.hl7.fhir.r5.renderers.utils.ElementWrappers.ResourceWrapperMetaElement;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceReferenceKind;
@ -370,7 +365,7 @@ public abstract class ResourceRenderer extends DataRenderer {
pieces.add(gen.new Piece(link,text.toString(), null));
}
private String getNameForResource(ResourceElement resource) {
protected String getNameForResource(ResourceElement resource) {
ResourceElement name = resource.firstChild("name");
if (name != null && !name.isEmpty()) {
if (name.isPrimitive()) {
@ -601,19 +596,6 @@ public abstract class ResourceRenderer extends DataRenderer {
return null;
}
protected PropertyWrapper getProperty(BaseWrapper res, String name) {
for (PropertyWrapper t : res.children()) {
if (t.getName().equals(name))
return t;
}
return null;
}
protected boolean valued(PropertyWrapper pw) {
return pw != null && pw.hasValues();
}
// protected ResourceElement fetchResource(BaseWrapper subject) throws UnsupportedEncodingException, FHIRException, IOException {
// if (context.getResolver() == null)
// return null;
@ -743,14 +725,6 @@ public abstract class ResourceRenderer extends DataRenderer {
return para.style("margin-bottom: 0px");
}
private String getPrimitiveValue(BaseWrapper b, String name) throws UnsupportedEncodingException, FHIRException, IOException {
return b != null && b.has(name) && b.getChildByName(name).hasValues() ? b.getChildByName(name).getValues().get(0).getBase().primitiveValue() : null;
}
private String getPrimitiveValue(ResourceWrapper r, String name) throws UnsupportedEncodingException, FHIRException, IOException {
return r.has(name) && r.getChildByName(name).hasValues() ? r.getChildByName(name).getValues().get(0).getBase().primitiveValue() : null;
}
// public void renderOrError(DomainResource dr) {
// try {
// render(dr);

View File

@ -77,7 +77,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext.FixedValueFormat;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.StructureDefinitionRendererMode;
import org.hl7.fhir.r5.renderers2.Renderer.RenderingStatus;
import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus;
import org.hl7.fhir.r5.terminologies.utilities.ValidationResult;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.PublicationHacker;

View File

@ -8,7 +8,6 @@ import java.util.Map;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
@ -22,9 +21,7 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.terminologies.utilities.ValidationResult;
import org.hl7.fhir.r5.utils.ToolingExtensions;
@ -40,24 +37,10 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
super(context);
}
public TerminologyRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
}
public String display(Resource r) throws UnsupportedEncodingException, IOException {
return ((CanonicalResource) r).present();
}
public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
if (r.has("title")) {
return r.children("title").get(0).getBase().primitiveValue();
}
if (r.has("name")) {
return r.children("name").get(0).getBase().primitiveValue();
}
return "??";
}
protected class TargetElementComponentWrapper {
protected ConceptMapGroupComponent group;
protected TargetElementComponent comp;
@ -280,12 +263,6 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
protected void AddVsRef(String value, XhtmlNode li, Resource source) {
Resource res = null;
if (rcontext != null) {
BundleEntryComponent be = rcontext.resolve(value);
if (be != null) {
res = be.getResource();
}
}
if (res != null && !(res instanceof CanonicalResource)) {
li.addText(value);
return;

View File

@ -1,6 +1,7 @@
package org.hl7.fhir.r5.renderers;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -18,18 +19,17 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.comparison.VersionComparisonAnnotation;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.ConceptMap;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Enumerations.FilterOperator;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.ExtensionHelper;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.PrimitiveType;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StringType;
@ -47,20 +47,16 @@ import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionPropertyComponent;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.terminologies.utilities.CodingValidationRequest;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass;
import org.hl7.fhir.r5.terminologies.utilities.ValidationResult;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache.CacheToken;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.LoincLinker;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.i18n.RenderingI18nContext;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel;
@ -71,12 +67,23 @@ import com.google.common.collect.Multimap;
public class ValueSetRenderer extends TerminologyRenderer {
public ValueSetRenderer(RenderingContext context) {
super(context);
public ValueSetRenderer(RenderingContext context) {
super(context);
}
public ValueSetRenderer(RenderingContext context, ResourceContext rcontext) {
super(context, rcontext);
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, ResourceElement r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new Error("ValueSetRenderer only renders native resources directly");
}
@Override
public void renderResource(RenderingStatus status, XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
render(status, x, (ValueSet) r, false);
}
@Override
public String displayResource(ResourceElement r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
private static final int MAX_DESIGNATIONS_IN_LINE = 5;
@ -84,23 +91,17 @@ public class ValueSetRenderer extends TerminologyRenderer {
private static final int MAX_BATCH_VALIDATION_SIZE = 1000;
private List<ConceptMapRenderInstructions> renderingMaps = new ArrayList<ConceptMapRenderInstructions>();
public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
return render(x, (ValueSet) dr, false);
}
public boolean render(XhtmlNode x, ValueSet vs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
public void render(RenderingStatus status, XhtmlNode x, ValueSet vs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
List<UsedConceptMap> maps = findReleventMaps(vs);
boolean hasExtensions;
if (vs.hasExpansion()) {
// for now, we just accept an expansion if there is one
hasExtensions = generateExpansion(x, vs, header, maps);
generateExpansion(status, x, vs, header, maps);
} else {
hasExtensions = generateComposition(x, vs, header, maps);
generateComposition(status, x, vs, header, maps);
}
return hasExtensions;
}
public void describe(XhtmlNode x, ValueSet vs) {
@ -176,8 +177,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
return vs.hasUrl() && source != null && vs.getUrl().equals(source.primitiveValue());
}
private boolean generateExpansion(XhtmlNode x, ValueSet vs, boolean header, List<UsedConceptMap> maps) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
private void generateExpansion(RenderingStatus status, XhtmlNode x, ValueSet vs, boolean header, List<UsedConceptMap> maps) throws FHIRFormatError, DefinitionException, IOException {
List<String> langs = new ArrayList<String>();
Map<String, String> designations = new HashMap<>(); // map of url = description, where url is the designation code. Designations that are for languages won't make it into this list
Map<String, String> properties = new HashMap<>(); // map of url = description, where url is the designation code. Designations that are for languages won't make it into this list
@ -314,7 +314,6 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
return hasExtensions;
}
@ -935,8 +934,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
// a.addText(code);
}
private boolean generateComposition(XhtmlNode x, ValueSet vs, boolean header, List<UsedConceptMap> maps) throws FHIRException, IOException {
boolean hasExtensions = false;
private void generateComposition(RenderingStatus status, XhtmlNode x, ValueSet vs, boolean header, List<UsedConceptMap> maps) throws FHIRException, IOException {
List<String> langs = new ArrayList<String>();
Map<String, String> designations = new HashMap<>(); // map of url = description, where url is the designation code. Designations that are for languages won't make it into this list
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
@ -956,17 +954,17 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
int index = 0;
if (vs.getCompose().getInclude().size() == 1 && vs.getCompose().getExclude().size() == 0 && !VersionComparisonAnnotation.hasDeleted(vs.getCompose(), "include", "exclude")) {
hasExtensions = genInclude(x.ul(), vs.getCompose().getInclude().get(0), "Include", langs, doDesignations, maps, designations, index, vs) || hasExtensions;
genInclude(status, x.ul(), vs.getCompose().getInclude().get(0), "Include", langs, doDesignations, maps, designations, index, vs);
} else {
XhtmlNode p = x.para();
p.tx(context.formatPhrase(RenderingContext.VALUE_SET_RULES_INC));
XhtmlNode ul = x.ul();
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
hasExtensions = genInclude(ul, inc, context.formatPhrase(RenderingContext.VALUE_SET_INC), langs, doDesignations, maps, designations, index, vs) || hasExtensions;
genInclude(status, ul, inc, context.formatPhrase(RenderingContext.VALUE_SET_INC), langs, doDesignations, maps, designations, index, vs);
index++;
}
for (Base inc : VersionComparisonAnnotation.getDeleted(vs.getCompose(), "include")) {
genInclude(ul, (ConceptSetComponent) inc, context.formatPhrase(RenderingContext.VALUE_SET_INC), langs, doDesignations, maps, designations, index, vs);
genInclude(status, ul, (ConceptSetComponent) inc, context.formatPhrase(RenderingContext.VALUE_SET_INC), langs, doDesignations, maps, designations, index, vs);
index++;
}
if (vs.getCompose().hasExclude() || VersionComparisonAnnotation.hasDeleted(vs.getCompose(), "exclude")) {
@ -974,11 +972,11 @@ public class ValueSetRenderer extends TerminologyRenderer {
p.tx(context.formatPhrase(RenderingContext.VALUE_SET_RULES_EXC));
ul = x.ul();
for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
hasExtensions = genInclude(ul, exc, context.formatPhrase(RenderingContext.VALUE_SET_EXCL), langs, doDesignations, maps, designations, index, vs) || hasExtensions;
genInclude(status, ul, exc, context.formatPhrase(RenderingContext.VALUE_SET_EXCL), langs, doDesignations, maps, designations, index, vs);
index++;
}
for (Base inc : VersionComparisonAnnotation.getDeleted(vs.getCompose(), "exclude")) {
genInclude(ul, (ConceptSetComponent) inc, context.formatPhrase(RenderingContext.VALUE_SET_EXCL), langs, doDesignations, maps, designations, index, vs);
genInclude(status, ul, (ConceptSetComponent) inc, context.formatPhrase(RenderingContext.VALUE_SET_EXCL), langs, doDesignations, maps, designations, index, vs);
index++;
}
}
@ -1010,9 +1008,6 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
}
return hasExtensions;
}
private void renderExpansionRules(XhtmlNode x, ConceptSetComponent inc, int index, Map<String, ConceptDefinitionComponent> definitions) throws FHIRException, IOException {
@ -1166,8 +1161,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index, ValueSet vsRes) throws FHIRException, IOException {
boolean hasExtensions = false;
private void genInclude(RenderingStatus status, XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index, ValueSet vsRes) throws FHIRException, IOException {
XhtmlNode li;
li = ul.li();
li = renderStatus(inc, li);
@ -1200,8 +1194,9 @@ public class ValueSetRenderer extends TerminologyRenderer {
ConceptDefinitionComponent cc = definitions == null ? null : definitions.get(c.getCode());
hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
}
if (hasComments || hasDefinition)
hasExtensions = true;
if (hasComments || hasDefinition) {
status.setExtensions(true);
}
addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, designations, doDesignations), maps);
for (ConceptReferenceComponent c : inc.getConcept()) {
renderConcept(inc, langs, doDesignations, maps, designations, definitions, t, hasComments, hasDefinition, c);
@ -1268,7 +1263,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
if (inc.hasExtension(ToolingExtensions.EXT_EXPAND_RULES) || inc.hasExtension(ToolingExtensions.EXT_EXPAND_GROUP)) {
hasExtensions = true;
status.setExtensions(true);
renderExpansionRules(li, inc, index, definitions);
}
} else {
@ -1296,7 +1291,6 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
return hasExtensions;
}
private void renderConcept(ConceptSetComponent inc, List<String> langs, boolean doDesignations,

View File

@ -1,132 +0,0 @@
package org.hl7.fhir.r5.renderers.utils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.ResourceRenderer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class BaseWrappers {
public interface RendererWrapper {
public RenderingContext getContext();
}
public interface PropertyWrapper extends RendererWrapper {
public String getName();
public boolean hasValues();
public List<BaseWrapper> getValues();
public String getTypeCode();
public String getDefinition();
public int getMinCardinality();
public int getMaxCardinality();
public StructureDefinition getStructure();
public ElementDefinition getElementDefinition();
public BaseWrapper value();
public ResourceWrapper getAsResource();
public String fhirType();
}
public interface WrapperBase extends RendererWrapper {
public boolean has(String name);
public Base get(String name) throws UnsupportedEncodingException, FHIRException, IOException;
public List<BaseWrapper> children(String name) throws UnsupportedEncodingException, FHIRException, IOException;
public List<PropertyWrapper> children();
public String fhirType();
}
public interface ResourceWrapper extends WrapperBase {
public List<ResourceWrapper> getContained();
public String getId();
public XhtmlNode getNarrative() throws FHIRFormatError, IOException, FHIRException;
public Base getBase();
public String getName();
public void describe(XhtmlNode x) throws UnsupportedEncodingException, IOException;
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) throws IOException;
public BaseWrapper root();
public PropertyWrapper getChildByName(String tail);
public StructureDefinition getDefinition();
public boolean hasNarrative();
public String getNameFromResource();
public Resource getResource(); // if there is one
}
public interface BaseWrapper extends WrapperBase {
public Base getBase() throws UnsupportedEncodingException, IOException, FHIRException;
public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException; // for contained, etc
public PropertyWrapper getChildByName(String tail);
public String fhirType();
}
public static abstract class RendererWrapperImpl implements RendererWrapper {
protected RenderingContext context;
public RendererWrapperImpl(RenderingContext context) {
super();
this.context = context;
}
public RenderingContext getContext() {
return context;
}
protected String tail(String path) {
return path.substring(path.lastIndexOf(".")+1);
}
}
public static abstract class WrapperBaseImpl extends RendererWrapperImpl implements WrapperBase {
public WrapperBaseImpl(RenderingContext context) {
super(context);
}
@Override
public boolean has(String name) {
for (PropertyWrapper p : children()) {
if (p.getName().equals(name) || p.getName().equals(name+"[x]") ) {
return p.hasValues();
}
}
return false;
}
@Override
public Base get(String name) throws UnsupportedEncodingException, FHIRException, IOException {
for (PropertyWrapper p : children()) {
if (p.getName().equals(name) || p.getName().equals(name+"[x]")) {
if (p.hasValues()) {
return p.getValues().get(0).getBase();
} else {
return null;
}
}
}
return null;
}
@Override
public List<BaseWrapper> children(String name) throws UnsupportedEncodingException, FHIRException, IOException {
for (PropertyWrapper p : children()) {
if (p.getName().equals(name) || p.getName().equals(name+"[x]")) {
List<BaseWrapper> res = new ArrayList<>();
for (BaseWrapper b : p.getValues()) {
res.add(b);
}
return res;
}
}
return null;
}
}
}

View File

@ -1,447 +0,0 @@
package org.hl7.fhir.r5.renderers.utils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.formats.FormatUtilities;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.renderers.ResourceRenderer;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.RendererWrapperImpl;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.WrapperBaseImpl;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.hl7.fhir.utilities.xml.XmlGenerator;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* This class is only used in kindling, and it's going to be phased out and replaced by
* ElementWrappers. Don't use in any other context
*/
@Deprecated
public class DOMWrappers {
/**
* This class is only used in kindling, and it's going to be phased out and replaced by
* ElementWrappers. Don't use in any other context
*/
@Deprecated
public static class BaseWrapperElement extends WrapperBaseImpl implements BaseWrapper {
private Element element;
private String type;
private StructureDefinition structure;
private ElementDefinition definition;
private List<ElementDefinition> children;
private List<PropertyWrapper> list;
public BaseWrapperElement(RenderingContext context, Element element, String type, StructureDefinition structure, ElementDefinition definition) {
super(context);
this.element = element;
this.type = type;
this.structure = structure;
this.definition = definition;
}
@Override
public Base getBase() throws UnsupportedEncodingException, IOException, FHIRException {
if (Utilities.noString(type) || type.equals("Resource") || type.equals("BackboneElement") || type.equals("Element"))
return null;
String xml;
try {
xml = new XmlGenerator().generate(element);
} catch (org.hl7.fhir.exceptions.FHIRException e) {
throw new FHIRException(e.getMessage(), e);
}
Node n = element.getPreviousSibling();
Base ret = context.getParser().parseType(xml, type);
while (n != null && (n.getNodeType() == Node.COMMENT_NODE || n.getNodeType() == Node.TEXT_NODE)) {
if (n.getNodeType() == Node.COMMENT_NODE) {
ret.getFormatCommentsPre().add(0, n.getTextContent());
}
n = n.getPreviousSibling();
}
return ret;
}
@Override
public List<PropertyWrapper> children() {
if (list == null) {
children = context.getProfileUtilities().getChildList(structure, definition);
if (children.isEmpty() && type != null) {
StructureDefinition sdt = context.getWorker().fetchTypeDefinition(type);
children = context.getProfileUtilities().getChildList(sdt, sdt.getSnapshot().getElementFirstRep());
}
list = new ArrayList<PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
XMLUtil.getNamedChildrenWithWildcard(element, tail(child.getPath()), elements);
list.add(new PropertyWrapperElement(context, structure, child, elements));
}
}
return list;
}
@Override
public PropertyWrapper getChildByName(String name) {
for (PropertyWrapper p : children())
if (p.getName().equals(name))
return p;
return null;
}
@Override
public String fhirType() {
return type;
}
@Override
public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException {
Element r = XMLUtil.getFirstChild(element);
StructureDefinition sd = getContext().getContext().fetchTypeDefinition(r.getLocalName());
if (sd == null) {
throw new FHIRException("Unable to find definition for type "+type+" @ "+definition.getPath());
}
if (sd.getKind() != StructureDefinitionKind.RESOURCE) {
throw new FHIRException("Definition for type "+type+" is not for a resource @ "+definition.getPath());
}
return new ResourceWrapperElement(context, r, sd);
}
}
/**
* This class is only used in kindling, and it's going to be phased out and replaced by
* ElementWrappers. Don't use in any other context
*/
@Deprecated
public static class PropertyWrapperElement extends RendererWrapperImpl implements PropertyWrapper {
private StructureDefinition structure;
private ElementDefinition definition;
private List<Element> values;
private List<BaseWrapper> list;
public PropertyWrapperElement(RenderingContext context, StructureDefinition structure, ElementDefinition definition, List<Element> values) {
super(context);
this.structure = structure;
this.definition = definition;
this.values = values;
}
@Override
public String getName() {
return tail(definition.getPath());
}
@Override
public boolean hasValues() {
return values.size() > 0;
}
@Override
public List<BaseWrapper> getValues() {
if (list == null) {
list = new ArrayList<BaseWrapper>();
for (Element e : values)
list.add(new BaseWrapperElement(context, e, determineType(e), structure, definition));
}
return list;
}
private String determineType(Element e) {
if (definition.getType().isEmpty())
return null;
if (definition.getType().size() == 1) {
if (definition.getType().get(0).getWorkingCode().equals("Element") || definition.getType().get(0).getWorkingCode().equals("BackboneElement"))
return null;
return definition.getType().get(0).getWorkingCode();
}
String t = e.getNodeName().substring(tail(definition.getPath()).length()-3);
if (isPrimitive(Utilities.uncapitalize(t)))
return Utilities.uncapitalize(t);
else
return t;
}
private boolean isPrimitive(String code) {
StructureDefinition sd = context.getWorker().fetchTypeDefinition(code);
return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
}
@Override
public String getTypeCode() {
if (definition == null || definition.getType().size() != 1) {
if (values.size() != 1) {
throw new Error("not handled");
}
String tn = values.get(0).getLocalName().substring(tail(definition.getPath()).replace("[x]", "").length());
if (isPrimitive(Utilities.uncapitalize(tn))) {
return Utilities.uncapitalize(tn);
} else {
return tn;
}
}
return definition.getType().get(0).getWorkingCode();
}
@Override
public String getDefinition() {
if (definition == null)
throw new Error("not handled");
return definition.getDefinition();
}
@Override
public int getMinCardinality() {
if (definition == null)
throw new Error("not handled");
return definition.getMin();
}
@Override
public int getMaxCardinality() {
if (definition == null)
throw new Error("not handled");
return definition.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(definition.getMax());
}
@Override
public StructureDefinition getStructure() {
return structure;
}
@Override
public BaseWrapper value() {
if (getValues().size() != 1)
throw new Error("Access single value, but value count is "+getValues().size());
return getValues().get(0);
}
@Override
public ResourceWrapper getAsResource() {
throw new Error("Not implemented yet");
}
@Override
public String fhirType() {
return getTypeCode();
}
@Override
public ElementDefinition getElementDefinition() {
return definition;
}
}
/**
* This class is only used in kindling, and it's going to be phased out and replaced by
* ElementWrappers. Don't use in any other context
*/
@Deprecated
public static class ResourceWrapperElement extends WrapperBaseImpl implements ResourceWrapper {
private Element wrapped;
private StructureDefinition definition;
private List<ResourceWrapper> list;
private List<PropertyWrapper> list2;
public ResourceWrapperElement(RenderingContext context, Element wrapped, StructureDefinition definition) {
super(context);
this.wrapped = wrapped;
this.definition = definition;
}
@Override
public List<ResourceWrapper> getContained() {
if (list == null) {
List<Element> children = new ArrayList<Element>();
XMLUtil.getNamedChildren(wrapped, "contained", children);
list = new ArrayList<ResourceWrapper>();
for (Element e : children) {
Element c = XMLUtil.getFirstChild(e);
list.add(new ResourceWrapperElement(context, c, context.getWorker().fetchTypeDefinition(c.getNodeName())));
}
}
return list;
}
@Override
public String getId() {
return XMLUtil.getNamedChildValue(wrapped, "id");
}
@Override
public XhtmlNode getNarrative() throws FHIRFormatError, IOException, FHIRException {
Element txt = XMLUtil.getNamedChild(wrapped, "text");
if (txt == null)
return null;
Element div = XMLUtil.getNamedChild(txt, "div");
if (div == null)
return null;
try {
return new XhtmlParser().parse(new XmlGenerator().generate(div), "div");
} catch (org.hl7.fhir.exceptions.FHIRFormatError e) {
throw new FHIRFormatError(e.getMessage(), e);
} catch (org.hl7.fhir.exceptions.FHIRException e) {
throw new FHIRException(e.getMessage(), e);
}
}
@Override
public String getName() {
return wrapped.getNodeName();
}
@Override
public String getNameFromResource() {
Element e = XMLUtil.getNamedChild(wrapped, "name");
if (e != null) {
if (e.hasAttribute("value")) {
return e.getAttribute("value");
}
if (XMLUtil.hasNamedChild(e, "text")) {
return XMLUtil.getNamedChildValue(e, "text");
}
if (XMLUtil.hasNamedChild(e, "family") || XMLUtil.hasNamedChild(e, "given")) {
Element family = XMLUtil.getNamedChild(e, "family");
Element given = XMLUtil.getNamedChild(e, "given");
String s = given != null && given.hasAttribute("value") ? given.getAttribute("value") : "";
if (family != null && family.hasAttribute("value"))
s = s + " " + family.getAttribute("value").toUpperCase();
return s;
}
return null;
}
return null;
}
@Override
public List<PropertyWrapper> children() {
if (list2 == null) {
List<ElementDefinition> children = context.getProfileUtilities().getChildList(definition, definition.getSnapshot().getElement().get(0));
list2 = new ArrayList<PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
XMLUtil.getNamedChildrenWithWildcard(wrapped, tail(child.getPath()), elements);
list2.add(new PropertyWrapperElement(context, definition, child, elements));
}
}
return list2;
}
@Override
public void describe(XhtmlNode x) {
throw new Error("Not done yet");
}
@Override
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) {
if (!x.hasAttribute("xmlns"))
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
Element le = XMLUtil.getNamedChild(wrapped, "language");
String l = le == null ? null : le.getAttribute("value");
if (!Utilities.noString(l)) {
// use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
x.setAttribute("lang", l);
x.setAttribute("xml:lang", l);
}
Element txt = XMLUtil.getNamedChild(wrapped, "text");
if (txt == null) {
txt = wrapped.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "text");
Element n = XMLUtil.getFirstChild(wrapped);
while (n != null && (n.getNodeName().equals("id") || n.getNodeName().equals("meta") || n.getNodeName().equals("implicitRules") || n.getNodeName().equals("language")))
n = XMLUtil.getNextSibling(n);
if (n == null)
wrapped.appendChild(txt);
else
wrapped.insertBefore(txt, n);
}
Element st = XMLUtil.getNamedChild(txt, "status");
if (st == null) {
st = wrapped.getOwnerDocument().createElementNS(FormatUtilities.FHIR_NS, "status");
Element n = XMLUtil.getFirstChild(txt);
if (n == null)
txt.appendChild(st);
else
txt.insertBefore(st, n);
}
st.setAttribute("value", status.toCode());
Element div = XMLUtil.getNamedChild(txt, "div");
if (div == null) {
div = wrapped.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "div");
div.setAttribute("xmlns", FormatUtilities.XHTML_NS);
txt.appendChild(div);
}
if (div.hasChildNodes())
div.appendChild(wrapped.getOwnerDocument().createElementNS(FormatUtilities.XHTML_NS, "hr"));
new XhtmlComposer(XhtmlComposer.XML, context.isPretty()).compose(div, x);
}
@Override
public BaseWrapper root() {
return new BaseWrapperElement(context, wrapped, getName(), definition, definition.getSnapshot().getElementFirstRep());
}
@Override
public StructureDefinition getDefinition() {
return definition;
}
@Override
public Base getBase() {
throw new Error("Not Implemented yet");
}
@Override
public boolean hasNarrative() {
StructureDefinition sd = definition;
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.getWorker().fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
return false;
}
@Override
public String fhirType() {
return wrapped.getNodeName();
}
@Override
public PropertyWrapper getChildByName(String name) {
for (PropertyWrapper p : children())
if (p.getName().equals(name))
return p;
return null;
}
@Override
public Resource getResource() {
return null;
}
}
}

View File

@ -1,336 +0,0 @@
package org.hl7.fhir.r5.renderers.utils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Encounter;
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
import org.hl7.fhir.r5.model.Patient;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.renderers.EncounterRenderer;
import org.hl7.fhir.r5.renderers.PatientRenderer;
import org.hl7.fhir.r5.renderers.ResourceRenderer;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.RendererWrapperImpl;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.WrapperBaseImpl;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class DirectWrappers {
public static class PropertyWrapperDirect extends RendererWrapperImpl implements PropertyWrapper {
private Property wrapped;
private List<BaseWrapper> list;
private ElementDefinition ed;
public PropertyWrapperDirect(RenderingContext context, Property wrapped) {
super(context);
if (wrapped == null)
throw new Error("wrapped == null");
this.wrapped = wrapped;
}
public PropertyWrapperDirect(RenderingContext context, Property wrapped, ElementDefinition ed) {
super(context);
if (wrapped == null)
throw new Error("wrapped == null");
this.wrapped = wrapped;
this.ed = ed;
}
@Override
public String getName() {
return wrapped.getName();
}
public Property getWrapped() {
return wrapped;
}
@Override
public boolean hasValues() {
return wrapped.hasValues();
}
@Override
public List<BaseWrapper> getValues() {
if (list == null) {
list = new ArrayList<BaseWrapper>();
for (Base b : wrapped.getValues())
list.add(b == null ? null : new BaseWrapperDirect(context, b));
}
return list;
}
@Override
public String getTypeCode() {
return wrapped.getTypeCode();
}
@Override
public String getDefinition() {
return wrapped.getDefinition();
}
@Override
public int getMinCardinality() {
return wrapped.getMinCardinality();
}
@Override
public int getMaxCardinality() {
return wrapped.getMinCardinality();
}
@Override
public StructureDefinition getStructure() {
return wrapped.getStructure();
}
@Override
public BaseWrapper value() {
if (getValues().size() != 1)
throw new Error("Access single value, but value count is "+getValues().size());
return getValues().get(0);
}
public String toString() {
return "#."+wrapped.toString();
}
@Override
public ResourceWrapper getAsResource() {
return new ResourceWrapperDirect(context, (Resource) wrapped.getValues().get(0));
}
@Override
public String fhirType() {
return wrapped.getTypeCode();
}
@Override
public ElementDefinition getElementDefinition() {
return ed;
}
}
public static class BaseWrapperDirect extends WrapperBaseImpl implements BaseWrapper {
private Base wrapped;
private List<PropertyWrapper> list;
public BaseWrapperDirect(RenderingContext context, Base wrapped) {
super(context);
if (wrapped == null)
throw new Error("wrapped == null");
this.wrapped = wrapped;
}
@Override
public Base getBase() {
return wrapped;
}
@Override
public List<PropertyWrapper> children() {
if (list == null) {
list = new ArrayList<PropertyWrapper>();
for (Property p : wrapped.children())
list.add(new PropertyWrapperDirect(context, p));
}
return list;
}
@Override
public PropertyWrapper getChildByName(String name) {
Property p = wrapped.getChildByName(name);
if (p == null)
return null;
else
return new PropertyWrapperDirect(context, p);
}
@Override
public String fhirType() {
return wrapped.fhirType();
}
@Override
public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException {
return new DirectWrappers.ResourceWrapperDirect(getContext(), (Resource) wrapped);
}
}
public static class ResourceWrapperDirect extends WrapperBaseImpl implements ResourceWrapper {
private Resource wrapped;
public ResourceWrapperDirect(RenderingContext context, Resource wrapped) {
super(context);
if (wrapped == null)
throw new Error("wrapped == null");
this.wrapped = wrapped;
}
@Override
public List<ResourceWrapper> getContained() {
List<ResourceWrapper> list = new ArrayList<ResourceWrapper>();
if (wrapped instanceof DomainResource) {
DomainResource dr = (DomainResource) wrapped;
for (Resource c : dr.getContained()) {
list.add(new ResourceWrapperDirect(context, c));
}
}
return list;
}
@Override
public String getId() {
return wrapped.getId();
}
@Override
public XhtmlNode getNarrative() {
if (wrapped instanceof DomainResource) {
DomainResource dr = (DomainResource) wrapped;
if (dr.hasText() && dr.getText().hasDiv())
return dr.getText().getDiv();
}
return null;
}
@Override
public String getName() {
return wrapped.getResourceType().toString();
}
@Override
public String getNameFromResource() {
Property name = wrapped.getChildByName("name");
if (name != null && name.hasValues()) {
Base b = name.getValues().get(0);
if (b.isPrimitive()) {
return b.primitiveValue();
} else if (b.fhirType().equals("HumanName")) {
Property family = b.getChildByName("family");
Property given = wrapped.getChildByName("given");
String s = given != null && given.hasValues() ? given.getValues().get(0).primitiveValue() : "";
if (family != null && family.hasValues()) {
String v = family.getValues().get(0).primitiveValue();
if (v == null) {
s = s + " " + "??";
} else {
s = s + " " + v.toUpperCase();
}
}
return s;
} else {
Property p = b.getChildByName("name");
if (p == null || !p.hasValues()) {
p = b.getChildByName("name");
}
if (p == null || !p.hasValues()) {
p = b.getChildByName("text");
}
if (p == null || !p.hasValues()) {
p = b.getChildByName("value");
}
if (p == null || !p.hasValues()) {
p = b.getChildByName("productName"); // MedicinalProductDefinition
}
if (p == null || !p.hasValues()) {
throw new Error("What to render for 'name'? Type is "+b.fhirType());
} else {
return p.getValues().get(0).primitiveValue();
}
}
}
return null;
}
@Override
public List<PropertyWrapper> children() {
List<PropertyWrapper> list = new ArrayList<PropertyWrapper>();
if (wrapped.children() != null) {
for (Property c : wrapped.children())
list.add(new PropertyWrapperDirect(context, c));
}
return list;
}
@Override
public void describe(XhtmlNode x) throws UnsupportedEncodingException, IOException {
if (wrapped instanceof CanonicalResource) {
x.tx(((CanonicalResource) wrapped).present());
} else if (wrapped instanceof Patient) {
new PatientRenderer(getContext()).describe(x, (Patient) wrapped);
} else if (wrapped instanceof Encounter) {
new EncounterRenderer(getContext()).describe(x, (Encounter) wrapped);
}
}
@Override
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) {
renderer.inject((DomainResource) wrapped, x, status);
}
@Override
public BaseWrapper root() {
return new BaseWrapperDirect(context, wrapped);
}
@Override
public StructureDefinition getDefinition() {
return context.getWorker().fetchTypeDefinition(wrapped.fhirType());
}
@Override
public Base getBase() {
return wrapped;
}
@Override
public boolean hasNarrative() {
StructureDefinition sd = context.getWorker().fetchTypeDefinition(wrapped.fhirType());
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.getWorker().fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
return false;
}
@Override
public String fhirType() {
return wrapped.fhirType();
}
@Override
public PropertyWrapper getChildByName(String name) {
Property p = wrapped.getChildByName(name);
if (p == null)
return null;
else
return new PropertyWrapperDirect(context, p);
}
public Resource getResource() {
return wrapped;
}
}
}

View File

@ -1,403 +0,0 @@
package org.hl7.fhir.r5.renderers.utils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.XmlParser;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.renderers.ResourceRenderer;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.RendererWrapperImpl;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.WrapperBaseImpl;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class ElementWrappers {
public static class BaseWrapperMetaElement extends WrapperBaseImpl implements BaseWrapper {
private Element element;
private String type;
private StructureDefinition structure;
private ElementDefinition definition;
private List<ElementDefinition> children;
private List<PropertyWrapper> list;
public BaseWrapperMetaElement(RenderingContext context, Element element, String type, StructureDefinition structure, ElementDefinition definition) {
super(context);
this.element = element;
this.type = type;
this.structure = structure;
this.definition = definition;
}
@Override
public Base getBase() throws UnsupportedEncodingException, IOException, FHIRException {
if (type == null || type.equals("Resource") || type.equals("BackboneElement") || type.equals("Element"))
return null;
if (element.hasElementProperty()) {
return element;
}
ByteArrayOutputStream xml = new ByteArrayOutputStream();
try {
new XmlParser(context.getWorker()).compose(element, xml, OutputStyle.PRETTY, null);
} catch (Exception e) {
throw new FHIRException(e.getMessage(), e);
}
if (context.getParser() == null) {
System.out.println("No version specific parser provided");
}
if (context.getParser() == null) {
throw new Error("No type parser provided to renderer context");
} else {
try {
return context.getParser().parseType(xml.toString(StandardCharsets.UTF_8), type);
} catch (Exception e) {
throw new FHIRException(e.getMessage(), e);
}
}
}
@Override
public List<PropertyWrapper> children() {
if (list == null) {
children = context.getProfileUtilities().getChildList(structure, definition, false, true);
if (children.isEmpty() && !Utilities.noString(type)) {
StructureDefinition sd = context.getWorker().fetchTypeDefinition(type);
children = context.getProfileUtilities().getChildList(sd, sd.getSnapshot().getElementFirstRep());
}
list = new ArrayList<PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
String name = tail(child.getPath());
if (name.endsWith("[x]"))
element.getNamedChildrenWithWildcard(name, elements);
else
element.getNamedChildren(name, elements);
list.add(new PropertyWrapperMetaElement(context, structure, child, elements));
}
}
return list;
}
@Override
public PropertyWrapper getChildByName(String name) {
for (PropertyWrapper p : children())
if (p.getName().equals(name))
return p;
return null;
}
@Override
public String fhirType() {
return element.fhirType();
}
@Override
public ResourceWrapper getResource() throws UnsupportedEncodingException, IOException, FHIRException {
return new ElementWrappers.ResourceWrapperMetaElement(getContext(), element);
}
}
public static class ResourceWrapperMetaElement extends WrapperBaseImpl implements ResourceWrapper {
private Element wrapped;
private List<ResourceWrapper> list;
private List<PropertyWrapper> list2;
private StructureDefinition definition;
public ResourceWrapperMetaElement(RenderingContext context, Element wrapped) {
super(context);
this.wrapped = wrapped;
this.definition = wrapped.getProperty().getStructure();
}
@Override
public List<ResourceWrapper> getContained() {
if (list == null) {
List<Element> children = wrapped.getChildrenByName("contained");
list = new ArrayList<ResourceWrapper>();
for (Element e : children) {
list.add(new ResourceWrapperMetaElement(context, e));
}
}
return list;
}
@Override
public String getId() {
return wrapped.getNamedChildValue("id");
}
@Override
public XhtmlNode getNarrative() throws FHIRFormatError, IOException, FHIRException {
Element txt = wrapped.getNamedChild("text");
if (txt == null)
return null;
Element div = txt.getNamedChild("div");
if (div == null)
return null;
else
return div.getXhtml();
}
@Override
public String getName() {
return wrapped.getName();
}
@Override
public String getNameFromResource() {
Property name = wrapped.getChildByName("name");
if (name != null && name.hasValues()) {
Base b = name.getValues().get(0);
if (b.isPrimitive()) {
return b.primitiveValue();
} else if (b.fhirType().equals("HumanName")) {
Property family = b.getChildByName("family");
Property given = wrapped.getChildByName("given");
String s = given != null && given.hasValues() ? given.getValues().get(0).primitiveValue() : "";
if (family != null && family.hasValues() && family.getValues().get(0).primitiveValue() != null)
s = s + " " + family.getValues().get(0).primitiveValue().toUpperCase();
return s;
} else {
// well, we couldn't get a name from that
return null;
}
}
return null;
}
@Override
public List<PropertyWrapper> children() {
if (list2 == null) {
List<ElementDefinition> children = context.getProfileUtilities().getChildList(definition, definition.getSnapshot().getElement().get(0));
list2 = new ArrayList<PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
if (child.getPath().endsWith("[x]"))
wrapped.getNamedChildrenWithWildcard(tail(child.getPath()), elements);
else
wrapped.getNamedChildren(tail(child.getPath()), elements);
list2.add(new PropertyWrapperMetaElement(context, definition, child, elements));
}
}
return list2;
}
@Override
public void describe(XhtmlNode x) {
if (wrapped.hasChild("title") && wrapped.getChildValue("title") != null) {
x.tx(wrapped.getChildValue("title"));
} else if (wrapped.hasChild("name") && wrapped.getChildValue("name") != null) {
x.tx(wrapped.getChildValue("name"));
} else {
x.tx("?ngen-1?");
}
}
@Override
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) throws IOException {
org.hl7.fhir.r5.elementmodel.Element txt = wrapped.getNamedChild("text");
if (txt == null) {
txt = new org.hl7.fhir.r5.elementmodel.Element("text", wrapped.getProperty().getChild(null, "text"));
int i = 0;
while (i < wrapped.getChildren().size() && (wrapped.getChildren().get(i).getName().equals("id") || wrapped.getChildren().get(i).getName().equals("meta") || wrapped.getChildren().get(i).getName().equals("implicitRules") || wrapped.getChildren().get(i).getName().equals("language"))) {
i++;
}
if (i >= wrapped.getChildren().size())
wrapped.getChildren().add(txt);
else
wrapped.getChildren().add(i, txt);
}
org.hl7.fhir.r5.elementmodel.Element st = txt.getNamedChild("status");
if (st == null) {
st = new org.hl7.fhir.r5.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
txt.getChildren().add(0, st);
}
st.setValue(status.toCode());
org.hl7.fhir.r5.elementmodel.Element div = txt.getNamedChild("div");
if (div == null) {
div = new org.hl7.fhir.r5.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
txt.getChildren().add(div);
}
// now process the xhtml
if (renderer.isMultiLangMode()) {
XhtmlNode xd = div.getXhtml();
if (xd == null) {
xd = new XhtmlNode(NodeType.Element, "div");
xd.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
div.setXhtml(xd);
} else {
xd.getChildNodes().removeIf(c -> !"div".equals(c.getName()) || !c.hasAttribute("xml:lang"));
}
renderer.markLanguage(x);
xd.getChildNodes().add(x);
} else {
if (!x.hasAttribute("xmlns")) {
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
}
String l = wrapped.getChildValue("language");
if (!Utilities.noString(l)) {
// use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
x.setAttribute("lang", l);
x.setAttribute("xml:lang", l);
}
div.setXhtml(x);
}
div.setValue(new XhtmlComposer(XhtmlComposer.XML, context.isPretty()).compose(div.getXhtml()));
}
@Override
public BaseWrapper root() {
return new BaseWrapperMetaElement(context, wrapped, getName(), definition, definition.getSnapshot().getElementFirstRep());
}
@Override
public StructureDefinition getDefinition() {
return definition;
}
@Override
public Base getBase() {
return wrapped;
}
@Override
public boolean hasNarrative() {
StructureDefinition sd = definition;
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.getWorker().fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
return false;
}
@Override
public String fhirType() {
return wrapped.fhirType();
}
@Override
public PropertyWrapper getChildByName(String name) {
for (PropertyWrapper p : children())
if (p.getName().equals(name))
return p;
return null;
}
public Element getElement() {
return wrapped;
}
@Override
public Resource getResource() {
return null;
}
}
public static class PropertyWrapperMetaElement extends RendererWrapperImpl implements PropertyWrapper {
private StructureDefinition structure;
private ElementDefinition definition;
private List<Element> values;
private List<BaseWrapper> list;
public PropertyWrapperMetaElement(RenderingContext context, StructureDefinition structure, ElementDefinition definition, List<Element> values) {
super(context);
this.structure = structure;
this.definition = definition;
this.values = values;
}
@Override
public String getName() {
return tail(definition.getPath());
}
@Override
public boolean hasValues() {
return values.size() > 0;
}
@Override
public List<BaseWrapper> getValues() {
if (list == null) {
list = new ArrayList<BaseWrapper>();
for (Element e : values) {
list.add(new BaseWrapperMetaElement(context, e, e.fhirType(), structure, definition));
}
}
return list;
}
@Override
public String getTypeCode() {
return definition.typeSummary();
}
@Override
public String getDefinition() {
return definition.getDefinition();
}
@Override
public int getMinCardinality() {
return definition.getMin();
}
@Override
public int getMaxCardinality() {
return "*".equals(definition.getMax()) ? Integer.MAX_VALUE : Integer.valueOf(definition.getMax());
}
@Override
public StructureDefinition getStructure() {
return structure;
}
@Override
public BaseWrapper value() {
if (getValues().size() != 1)
throw new Error("Access single value, but value count is "+getValues().size());
return getValues().get(0);
}
@Override
public ResourceWrapper getAsResource() {
return new ElementWrappers.ResourceWrapperMetaElement(context, values.get(0));
}
@Override
public String fhirType() {
return getTypeCode();
}
@Override
public ElementDefinition getElementDefinition() {
return definition;
}
}
}

View File

@ -52,7 +52,9 @@ public class ResourceElement {
public List<ResourceElement> getValues() {
return values;
}
public ElementDefinition getPropertyDefinition() {
return values.isEmpty() ? null : values.get(0).getPropertyDefinition();
}
}
private ContextUtilities contextUtils;
@ -82,8 +84,8 @@ public class ResourceElement {
}
public ResourceElement(ContextUtilities contextUtils, ProfileUtilities profileUtils, DataType type) {
this.contextUtils = contextUtils;
this.profileUtils = profileUtils;
this.contextUtils = parent.contextUtils;
this.profileUtils = parent.profileUtils;
this.parent = null;
this.name = null;
this.index = -1;
@ -93,7 +95,7 @@ public class ResourceElement {
this.propertyDefinition = this.classDefinition.getSnapshot().getElementFirstRep();
}
public ResourceElement(ContextUtilities contextUtils, ProfileUtilities profileUtils, ResourceElement parent, String name, int index, ElementKind kind, Base element, StructureDefinition classDefinition, ElementDefinition propertyDefinition) {
public ResourceElement(ResourceElement parent, String name, int index, ElementKind kind, Base element, StructureDefinition classDefinition, ElementDefinition propertyDefinition) {
this.contextUtils = contextUtils;
this.profileUtils = profileUtils;
this.parent = parent;
@ -115,9 +117,9 @@ public class ResourceElement {
this.model = resource;
}
public ResourceElement(ContextUtilities contextUtils, ProfileUtilities profileUtils, ResourceElement parent, String name, int index, ElementKind kind, Element em) {
this.contextUtils = contextUtils;
this.profileUtils = profileUtils;
public ResourceElement(ResourceElement parent, String name, int index, ElementKind kind, Element em) {
this.contextUtils = parent.contextUtils;
this.profileUtils = parent.profileUtils;
this.parent = parent;
this.name = name;
this.index = index;
@ -237,7 +239,7 @@ public class ResourceElement {
String name = child.getProperty().isChoice() ? child.getProperty().getName() : child.getName();
int index = child.isList() ? child.getIndex() : -1;
ElementKind kind = determineModelKind(child);
children.add(new ResourceElement(contextUtils, profileUtils, this, name, index, kind, child));
children.add(new ResourceElement(this, name, index, kind, child));
}
}
@ -286,11 +288,11 @@ public class ResourceElement {
}
}
if (ed != null) {
children.add(new ResourceElement(contextUtils, profileUtils, this, name, index, kind, v, childDefs.getSource(), ed));
children.add(new ResourceElement(this, name, index, kind, v, childDefs.getSource(), ed));
} else {
StructureDefinition sd = profileUtils.getContext().fetchTypeDefinition(v.fhirType());
ElementDefinition ted = sd.getSnapshot().getElementFirstRep();
children.add(new ResourceElement(contextUtils, profileUtils, this, name, index, kind, v, sd, ted));
children.add(new ResourceElement(this, name, index, kind, v, sd, ted));
}
i++;
}