org.hl7.fhir.r5.renderers.CompartmentDefinitionRenderer Maven / Gradle / Ivy
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.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CompartmentDefinition;
import org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceWrapper;
import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.MarkedToMoveToAdjunctPackage;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
@MarkedToMoveToAdjunctPackage
public class CompartmentDefinitionRenderer extends ResourceRenderer {
public CompartmentDefinitionRenderer(RenderingContext context) {
super(context);
}
@Override
public void buildNarrative(RenderingStatus status, XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (r.isDirect()) {
renderResourceTechDetails(r, x);
genSummaryTable(status, x, (CompartmentDefinition) r.getBase());
render(status, x, (CompartmentDefinition) r.getBase());
} else {
// it seems very inlikely this will change
x.para().tx("CompartmentDefinitionRenderer only renders native resources directly");
}
}
@Override
public String buildSummary(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
return canonicalTitle(r);
}
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()) {
CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
if (!cc.hasParam()) {
out.append(" ").append(cc.getCode()).append(" \r\n");
} else if (!rules.equals("{def}")) {
for (StringType p : cc.getParam())
rules.append(p.asStringValue());
in.append(" ").append(cc.getCode()).append(" ").append(rules.toString()).append(" \r\n");
}
}
XhtmlNode xn;
xn = new XhtmlParser().parseFragment("\r\nThe following resources may be in this compartment:\r\n
\r\n" +
"\r\n"+
" Resource Inclusion Criteria \r\n"+
in.toString()+
"
\r\n"+
"\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n
\r\n" +
"\r\n\r\n
\r\n" +
"\r\nThe following resources are never in this compartment:\r\n
\r\n" +
"\r\n"+
out.toString()+
"
\r\n");
x.addChildNodes(xn.getChildNodes());
}
public void describe(XhtmlNode x, CompartmentDefinition cd) {
x.tx(display(cd));
}
public String display(CompartmentDefinition cd) {
return cd.present();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy