use of org.hl7.fhir.r4b.model.ContactPoint in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType) {
renderDateTime(x, e);
} else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.r4b.model.DateType) {
org.hl7.fhir.r4b.model.DateType dt = ((org.hl7.fhir.r4b.model.DateType) e);
if (((org.hl7.fhir.r4b.model.DateType) e).hasValue()) {
x.addText(((org.hl7.fhir.r4b.model.DateType) e).toHumanDisplay());
}
} else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType) {
x.addText(((BooleanType) e).getValue().toString());
} else if (e instanceof CodeableConcept) {
renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding(x, (Coding) e, showCodeDetails);
} else if (e instanceof CodeableReference) {
renderCodeableReference(x, (CodeableReference) e, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation(x, (Annotation) e);
} else if (e instanceof Identifier) {
renderIdentifier(x, (Identifier) e);
} else if (e instanceof org.hl7.fhir.r4b.model.IntegerType) {
if (((org.hl7.fhir.r4b.model.IntegerType) e).hasValue()) {
x.addText(Integer.toString(((org.hl7.fhir.r4b.model.IntegerType) e).getValue()));
} else {
x.addText("??");
}
} else if (e instanceof org.hl7.fhir.r4b.model.Integer64Type) {
if (((org.hl7.fhir.r4b.model.Integer64Type) e).hasValue()) {
x.addText(Long.toString(((org.hl7.fhir.r4b.model.Integer64Type) e).getValue()));
} else {
x.addText("??");
}
} else if (e instanceof org.hl7.fhir.r4b.model.DecimalType) {
x.addText(((org.hl7.fhir.r4b.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName(x, (HumanName) e);
} else if (e instanceof SampledData) {
renderSampledData(x, (SampledData) e);
} else if (e instanceof Address) {
renderAddress(x, (Address) e);
} else if (e instanceof ContactPoint) {
renderContactPoint(x, (ContactPoint) e);
} else if (e instanceof Expression) {
renderExpression(x, (Expression) e);
} else if (e instanceof Money) {
renderMoney(x, (Money) e);
} else if (e instanceof ContactDetail) {
ContactDetail cd = (ContactDetail) e;
if (cd.hasName()) {
x.tx(cd.getName() + ": ");
}
boolean first = true;
for (ContactPoint c : cd.getTelecom()) {
if (first)
first = false;
else
x.tx(",");
renderContactPoint(x, c);
}
} else if (e instanceof UriType) {
renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
} else if (e instanceof Timing) {
renderTiming(x, (Timing) e);
} else if (e instanceof Range) {
renderRange(x, (Range) e);
} else if (e instanceof Quantity) {
renderQuantity(x, (Quantity) e, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
x.tx("/");
renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
renderPeriod(x, p);
} else if (e instanceof Reference) {
Reference r = (Reference) e;
if (r.getReference() != null && r.getReference().contains("#")) {
if (containedIds.contains(r.getReference().substring(1))) {
x.ah(r.getReference()).tx("See " + r.getReference());
} else {
// in this case, we render the resource in line
ResourceWrapper rw = null;
for (ResourceWrapper t : res.getContained()) {
if (r.getReference().substring(1).equals(t.getId())) {
rw = t;
}
}
if (rw == null) {
renderReference(res, x, r);
} else {
x.an(rw.getId());
ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
rr.render(parent.blockquote(), rw);
}
}
} else {
renderReference(res, x, r);
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof DataRequirement) {
DataRequirement p = (DataRequirement) e;
renderDataRequirement(x, p);
} else if (e instanceof PrimitiveType) {
x.tx(((PrimitiveType) e).primitiveValue());
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
}
}
use of org.hl7.fhir.r4b.model.ContactPoint in project org.hl7.fhir.core by hapifhir.
the class ConceptMapRenderer method render.
public boolean render(XhtmlNode x, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
XhtmlNode p = x.para();
p.tx("Mapping from ");
if (cm.hasSource())
AddVsRef(cm.getSource().primitiveValue(), p);
else
p.tx("(not specified)");
p.tx(" to ");
if (cm.hasTarget())
AddVsRef(cm.getTarget().primitiveValue(), p);
else
p.tx("(not specified)");
p = x.para();
if (cm.getExperimental())
p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
else
p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
p.tx("Published on " + (cm.hasDate() ? cm.getDateElement().toHumanDisplay() : "?ngen-10?") + " by " + cm.getPublisher());
if (!cm.getContact().isEmpty()) {
p.tx(" (");
boolean firsti = true;
for (ContactDetail ci : cm.getContact()) {
if (firsti)
firsti = false;
else
p.tx(", ");
if (ci.hasName())
p.addText(ci.getName() + ": ");
boolean first = true;
for (ContactPoint c : ci.getTelecom()) {
if (first)
first = false;
else
p.tx(", ");
addTelecom(p, c);
}
}
p.tx(")");
}
p.tx(". ");
p.addText(cm.getCopyright());
if (!Utilities.noString(cm.getDescription()))
addMarkdown(x, cm.getDescription());
x.br();
CodeSystem cs = getContext().getWorker().fetchCodeSystem("http://hl7.org/fhir/concept-map-relationship");
if (cs == null)
cs = getContext().getWorker().fetchCodeSystem("http://hl7.org/fhir/concept-map-equivalence");
String eqpath = cs == null ? null : cs.getUserString("path");
for (ConceptMapGroupComponent grp : cm.getGroup()) {
String src = grp.getSource();
boolean comment = false;
boolean ok = true;
Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
sources.put("code", new HashSet<String>());
targets.put("code", new HashSet<String>());
SourceElementComponent cc = grp.getElement().get(0);
String dst = grp.getTarget();
sources.get("code").add(grp.getSource());
targets.get("code").add(grp.getTarget());
for (SourceElementComponent ccl : grp.getElement()) {
ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
for (TargetElementComponent ccm : ccl.getTarget()) {
comment = comment || !Utilities.noString(ccm.getComment());
for (OtherElementComponent d : ccm.getDependsOn()) {
if (!sources.containsKey(d.getProperty()))
sources.put(d.getProperty(), new HashSet<String>());
sources.get(d.getProperty()).add(d.getSystem());
}
for (OtherElementComponent d : ccm.getProduct()) {
if (!targets.containsKey(d.getProperty()))
targets.put(d.getProperty(), new HashSet<String>());
targets.get(d.getProperty()).add(d.getSystem());
}
}
}
String display;
if (ok) {
// simple
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Source Code");
tr.td().b().tx("Relationship");
tr.td().b().tx("Destination Code");
if (comment)
tr.td().b().tx("Comment");
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
XhtmlNode td = tr.td();
td.addText(ccl.getCode());
display = getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
if (display != null && !isSameCodeAndDisplay(ccl.getCode(), display))
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
if (!ccm.hasEquivalence())
tr.td().tx(":" + "(" + ConceptMapEquivalence.NULL.toCode() + ")");
else {
String code = ccm.getEquivalenceElement().primitiveValue();
tr.td().ah(eqpath + "#" + code).tx(presentEquivalenceCode(code));
}
td = tr.td();
td.addText(ccm.getCode());
display = getDisplayForConcept(systemFromCanonical(grp.getTarget()), versionFromCanonical(grp.getTarget()), ccm.getCode());
if (display != null && !isSameCodeAndDisplay(ccm.getCode(), display))
td.tx(" (" + display + ")");
if (comment)
tr.td().addText(ccm.getComment());
addUnmapped(tbl, grp);
}
} else {
boolean hasRelationships = false;
for (int si = 0; si < grp.getElement().size(); si++) {
SourceElementComponent ccl = grp.getElement().get(si);
for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
TargetElementComponent ccm = ccl.getTarget().get(ti);
if (ccm.hasEquivalence()) {
hasRelationships = true;
}
}
}
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode td;
tr.td().colspan(Integer.toString(1 + sources.size())).b().tx("Source Concept Details");
if (hasRelationships) {
tr.td().b().tx("Relationship");
}
tr.td().colspan(Integer.toString(1 + targets.size())).b().tx("Destination Concept Details");
if (comment) {
tr.td().b().tx("Comment");
}
tr = tbl.tr();
if (sources.get("code").size() == 1) {
String url = sources.get("code").iterator().next();
renderCSDetailsLink(tr, url, true);
} else
tr.td().b().tx("Code");
for (String s : sources.keySet()) {
if (!s.equals("code")) {
if (sources.get(s).size() == 1) {
String url = sources.get(s).iterator().next();
renderCSDetailsLink(tr, url, false);
} else
tr.td().b().addText(getDescForConcept(s));
}
}
if (hasRelationships) {
tr.td();
}
if (targets.get("code").size() == 1) {
String url = targets.get("code").iterator().next();
renderCSDetailsLink(tr, url, true);
} else
tr.td().b().tx("Code");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
if (targets.get(s).size() == 1) {
String url = targets.get(s).iterator().next();
renderCSDetailsLink(tr, url, false);
} else
tr.td().b().addText(getDescForConcept(s));
}
}
if (comment)
tr.td();
for (int si = 0; si < grp.getElement().size(); si++) {
SourceElementComponent ccl = grp.getElement().get(si);
boolean slast = si == grp.getElement().size() - 1;
boolean first = true;
if (false) {
tr = tbl.tr();
td = tr.td().style("border-right-width: 0px");
if (!first)
td.style("border-top-style: none");
else
td.style("border-bottom-style: none");
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
tr.td().style("border-left-width: 0px").tx(display == null ? "" : display);
tr.td().colspan("4").style("background-color: #efefef").tx("(not mapped)");
} else {
for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
TargetElementComponent ccm = ccl.getTarget().get(ti);
boolean last = ti == ccl.getTarget().size() - 1;
tr = tbl.tr();
td = tr.td().style("border-right-width: 0px");
if (!first && !last)
td.style("border-top-style: none; border-bottom-style: none");
else if (!first)
td.style("border-top-style: none");
else if (!last)
td.style("border-bottom-style: none");
if (first) {
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = ccl.hasDisplay() ? ccl.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
td = tr.td();
if (!last)
td.style("border-left-width: 0px; border-bottom-style: none");
else
td.style("border-left-width: 0px");
td.tx(display == null ? "" : display);
} else {
// for display
td = tr.td();
if (!last)
td.style("border-left-width: 0px; border-top-style: none; border-bottom-style: none");
else
td.style("border-top-style: none; border-left-width: 0px");
}
for (String s : sources.keySet()) {
if (!s.equals("code")) {
td = tr.td();
if (first) {
td.addText(getValue(ccm.getDependsOn(), s, sources.get(s).size() != 1));
display = getDisplay(ccm.getDependsOn(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
}
first = false;
if (hasRelationships) {
if (!ccm.hasEquivalence())
tr.td();
else {
String code = ccm.getEquivalenceElement().toString();
tr.td().ah(eqpath + "#" + code).tx(presentEquivalenceCode(code));
}
}
td = tr.td().style("border-right-width: 0px");
if (targets.get("code").size() == 1)
td.addText(ccm.getCode());
else
td.addText(grp.getTarget() + " / " + ccm.getCode());
display = ccm.hasDisplay() ? ccm.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getTarget()), versionFromCanonical(grp.getTarget()), ccm.getCode());
tr.td().style("border-left-width: 0px").tx(display == null ? "" : display);
for (String s : targets.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getValue(ccm.getProduct(), s, targets.get(s).size() != 1));
display = getDisplay(ccm.getProduct(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (comment)
tr.td().addText(ccm.getComment());
}
}
addUnmapped(tbl, grp);
}
}
}
return true;
}
use of org.hl7.fhir.r4b.model.ContactPoint in project org.hl7.fhir.core by hapifhir.
the class ConceptMapRenderer method render.
public boolean render(XhtmlNode x, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
XhtmlNode p = x.para();
p.tx("Mapping from ");
if (cm.hasSource())
AddVsRef(cm.getSource().primitiveValue(), p);
else
p.tx("(not specified)");
p.tx(" to ");
if (cm.hasTarget())
AddVsRef(cm.getTarget().primitiveValue(), p);
else
p.tx("(not specified)");
p = x.para();
if (cm.getExperimental())
p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
else
p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
p.tx("Published on " + (cm.hasDate() ? display(cm.getDateElement()) : "?ngen-10?") + " by " + cm.getPublisher());
if (!cm.getContact().isEmpty()) {
p.tx(" (");
boolean firsti = true;
for (ContactDetail ci : cm.getContact()) {
if (firsti)
firsti = false;
else
p.tx(", ");
if (ci.hasName())
p.addText(ci.getName() + ": ");
boolean first = true;
for (ContactPoint c : ci.getTelecom()) {
if (first)
first = false;
else
p.tx(", ");
addTelecom(p, c);
}
}
p.tx(")");
}
p.tx(". ");
p.addText(cm.getCopyright());
if (!Utilities.noString(cm.getDescription()))
addMarkdown(x, cm.getDescription());
x.br();
CodeSystem cs = getContext().getWorker().fetchCodeSystem("http://hl7.org/fhir/concept-map-relationship");
if (cs == null)
cs = getContext().getWorker().fetchCodeSystem("http://hl7.org/fhir/concept-map-equivalence");
String eqpath = cs == null ? null : cs.getUserString("path");
for (ConceptMapGroupComponent grp : cm.getGroup()) {
String src = grp.getSource();
boolean comment = false;
boolean ok = true;
Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
sources.put("code", new HashSet<String>());
targets.put("code", new HashSet<String>());
SourceElementComponent cc = grp.getElement().get(0);
String dst = grp.getTarget();
sources.get("code").add(grp.getSource());
targets.get("code").add(grp.getTarget());
for (SourceElementComponent ccl : grp.getElement()) {
ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
for (TargetElementComponent ccm : ccl.getTarget()) {
comment = comment || !Utilities.noString(ccm.getComment());
for (OtherElementComponent d : ccm.getDependsOn()) {
if (!sources.containsKey(d.getProperty()))
sources.put(d.getProperty(), new HashSet<String>());
sources.get(d.getProperty()).add(d.getSystem());
}
for (OtherElementComponent d : ccm.getProduct()) {
if (!targets.containsKey(d.getProperty()))
targets.put(d.getProperty(), new HashSet<String>());
targets.get(d.getProperty()).add(d.getSystem());
}
}
}
String display;
if (ok) {
// simple
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Source Code");
tr.td().b().tx("Relationship");
tr.td().b().tx("Destination Code");
if (comment)
tr.td().b().tx("Comment");
tr = tbl.tr();
XhtmlNode td = tr.td().colspan(comment ? "4" : "3");
td.tx("Mapping from ");
if (grp.hasSource()) {
renderCanonical(cm, td, grp.getSource());
} else {
td.code("unspecified code system");
}
td.tx(" to ");
if (grp.hasTarget()) {
renderCanonical(cm, td, grp.getTarget());
} else {
td.code("unspecified code system");
}
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
td = tr.td();
td.addText(ccl.getCode());
display = ccl.hasDisplay() ? ccl.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
if (display != null && !isSameCodeAndDisplay(ccl.getCode(), display))
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
if (!ccm.hasRelationship())
tr.td().tx(":" + "(" + ConceptMapRelationship.EQUIVALENT.toCode() + ")");
else {
if (ccm.getRelationshipElement().hasExtension(ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE)) {
String code = ToolingExtensions.readStringExtension(ccm.getRelationshipElement(), ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE);
tr.td().ah(eqpath + "#" + code).tx(presentEquivalenceCode(code));
} else {
tr.td().ah(eqpath + "#" + ccm.getRelationship().toCode()).tx(presentRelationshipCode(ccm.getRelationship().toCode()));
}
}
td = tr.td();
td.addText(ccm.getCode());
display = ccm.hasDisplay() ? ccm.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getTarget()), versionFromCanonical(grp.getTarget()), ccm.getCode());
if (display != null && !isSameCodeAndDisplay(ccm.getCode(), display))
td.tx(" (" + display + ")");
if (comment)
tr.td().addText(ccm.getComment());
addUnmapped(tbl, grp);
}
} else {
boolean hasRelationships = false;
for (int si = 0; si < grp.getElement().size(); si++) {
SourceElementComponent ccl = grp.getElement().get(si);
for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
TargetElementComponent ccm = ccl.getTarget().get(ti);
if (ccm.hasRelationship()) {
hasRelationships = true;
}
}
}
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode td;
tr.td().colspan(Integer.toString(1 + sources.size())).b().tx("Source Concept Details");
if (hasRelationships) {
tr.td().b().tx("Relationship");
}
tr.td().colspan(Integer.toString(1 + targets.size())).b().tx("Destination Concept Details");
if (comment) {
tr.td().b().tx("Comment");
}
tr = tbl.tr();
if (sources.get("code").size() == 1) {
String url = sources.get("code").iterator().next();
renderCSDetailsLink(tr, url, true);
} else
tr.td().b().tx("Code");
for (String s : sources.keySet()) {
if (!s.equals("code")) {
if (sources.get(s).size() == 1) {
String url = sources.get(s).iterator().next();
renderCSDetailsLink(tr, url, false);
} else
tr.td().b().addText(getDescForConcept(s));
}
}
if (hasRelationships) {
tr.td();
}
if (targets.get("code").size() == 1) {
String url = targets.get("code").iterator().next();
renderCSDetailsLink(tr, url, true);
} else
tr.td().b().tx("Code");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
if (targets.get(s).size() == 1) {
String url = targets.get(s).iterator().next();
renderCSDetailsLink(tr, url, false);
} else
tr.td().b().addText(getDescForConcept(s));
}
}
if (comment)
tr.td();
for (int si = 0; si < grp.getElement().size(); si++) {
SourceElementComponent ccl = grp.getElement().get(si);
boolean slast = si == grp.getElement().size() - 1;
boolean first = true;
if (ccl.hasNoMap() && ccl.getNoMap()) {
tr = tbl.tr();
td = tr.td().style("border-right-width: 0px");
if (!first)
td.style("border-top-style: none");
else
td.style("border-bottom-style: none");
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
tr.td().style("border-left-width: 0px").tx(display == null ? "" : display);
tr.td().colspan("4").style("background-color: #efefef").tx("(not mapped)");
} else {
for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
TargetElementComponent ccm = ccl.getTarget().get(ti);
boolean last = ti == ccl.getTarget().size() - 1;
tr = tbl.tr();
td = tr.td().style("border-right-width: 0px");
if (!first && !last)
td.style("border-top-style: none; border-bottom-style: none");
else if (!first)
td.style("border-top-style: none");
else if (!last)
td.style("border-bottom-style: none");
if (first) {
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = ccl.hasDisplay() ? ccl.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
td = tr.td();
if (!last)
td.style("border-left-width: 0px; border-bottom-style: none");
else
td.style("border-left-width: 0px");
td.tx(display == null ? "" : display);
} else {
// for display
td = tr.td();
if (!last)
td.style("border-left-width: 0px; border-top-style: none; border-bottom-style: none");
else
td.style("border-top-style: none; border-left-width: 0px");
}
for (String s : sources.keySet()) {
if (!s.equals("code")) {
td = tr.td();
if (first) {
td.addText(getValue(ccm.getDependsOn(), s, sources.get(s).size() != 1));
display = getDisplay(ccm.getDependsOn(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
}
first = false;
if (hasRelationships) {
if (!ccm.hasRelationship())
tr.td();
else {
if (ccm.getRelationshipElement().hasExtension(ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE)) {
String code = ToolingExtensions.readStringExtension(ccm.getRelationshipElement(), ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE);
tr.td().ah(eqpath + "#" + code).tx(presentEquivalenceCode(code));
} else {
tr.td().ah(eqpath + "#" + ccm.getRelationship().toCode()).tx(presentRelationshipCode(ccm.getRelationship().toCode()));
}
}
}
td = tr.td().style("border-right-width: 0px");
if (targets.get("code").size() == 1)
td.addText(ccm.getCode());
else
td.addText(grp.getTarget() + " / " + ccm.getCode());
display = ccm.hasDisplay() ? ccm.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getTarget()), versionFromCanonical(grp.getTarget()), ccm.getCode());
tr.td().style("border-left-width: 0px").tx(display == null ? "" : display);
for (String s : targets.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getValue(ccm.getProduct(), s, targets.get(s).size() != 1));
display = getDisplay(ccm.getProduct(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (comment)
tr.td().addText(ccm.getComment());
}
}
addUnmapped(tbl, grp);
}
}
}
return true;
}
use of org.hl7.fhir.r4b.model.ContactPoint in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generate.
public boolean generate(ResourceContext rcontext, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
XhtmlNode p = x.para();
if (cm.hasSource() || cm.hasTarget())
p.tx("Mapping from ");
if (!cm.hasSource())
p.tx("(unspecified)");
else
AddVsRef(rcontext, cm.getSource() instanceof Reference ? ((Reference) cm.getSource()).getReference() : ((UriType) cm.getSource()).asStringValue(), p);
p.tx(" to ");
if (!cm.hasTarget())
p.tx("(unspecified)");
else
AddVsRef(rcontext, cm.getTarget() instanceof Reference ? ((Reference) cm.getTarget()).getReference() : ((UriType) cm.getTarget()).asStringValue(), p);
p = x.para();
if (cm.getExperimental())
p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
else
p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
p.tx("Published on " + (cm.hasDate() ? cm.getDateElement().toHumanDisplay() : "??") + " by " + cm.getPublisher());
if (!cm.getContact().isEmpty()) {
p.tx(" (");
boolean firsti = true;
for (ContactDetail ci : cm.getContact()) {
if (firsti)
firsti = false;
else
p.tx(", ");
if (ci.hasName())
p.addText(ci.getName() + ": ");
boolean first = true;
for (ContactPoint c : ci.getTelecom()) {
if (first)
first = false;
else
p.tx(", ");
addTelecom(p, c);
}
}
p.tx(")");
}
p.tx(". ");
p.addText(cm.getCopyright());
if (!Utilities.noString(cm.getDescription()))
addMarkdown(x, cm.getDescription());
x.br();
for (ConceptMapGroupComponent grp : cm.getGroup()) {
String src = grp.getSource();
boolean comment = false;
boolean ok = true;
Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
sources.put("code", new HashSet<String>());
targets.put("code", new HashSet<String>());
SourceElementComponent cc = grp.getElement().get(0);
String dst = grp.getTarget();
sources.get("code").add(grp.getSource());
targets.get("code").add(grp.getTarget());
for (SourceElementComponent ccl : grp.getElement()) {
ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
for (TargetElementComponent ccm : ccl.getTarget()) {
comment = comment || !Utilities.noString(ccm.getComment());
for (OtherElementComponent d : ccm.getDependsOn()) {
if (!sources.containsKey(d.getProperty()))
sources.put(d.getProperty(), new HashSet<String>());
sources.get(d.getProperty()).add(d.getSystem());
}
for (OtherElementComponent d : ccm.getProduct()) {
if (!targets.containsKey(d.getProperty()))
targets.put(d.getProperty(), new HashSet<String>());
targets.get(d.getProperty()).add(d.getSystem());
}
}
}
String display;
if (ok) {
// simple
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Source Code");
tr.td().b().tx("Equivalence");
tr.td().b().tx("Destination Code");
if (comment)
tr.td().b().tx("Comment");
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
XhtmlNode td = tr.td();
td.addText(ccl.getCode());
display = getDisplayForConcept(grp.getSource(), ccl.getCode());
if (display != null)
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
tr.td().addText(!ccm.hasEquivalence() ? "" : ccm.getEquivalence().toCode());
td = tr.td();
td.addText(ccm.getCode());
display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
if (display != null)
td.tx(" (" + display + ")");
if (comment)
tr.td().addText(ccm.getComment());
}
} else {
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode td;
tr.td().colspan(Integer.toString(sources.size())).b().tx("Source Concept");
tr.td().b().tx("Equivalence");
tr.td().colspan(Integer.toString(targets.size())).b().tx("Destination Concept");
if (comment)
tr.td().b().tx("Comment");
tr = tbl.tr();
if (sources.get("code").size() == 1)
tr.td().b().tx("Code " + sources.get("code").toString() + "");
else
tr.td().b().tx("Code");
for (String s : sources.keySet()) {
if (!s.equals("code")) {
if (sources.get(s).size() == 1)
tr.td().b().addText(getDescForConcept(s) + " " + sources.get(s).toString());
else
tr.td().b().addText(getDescForConcept(s));
}
}
tr.td();
if (targets.get("code").size() == 1)
tr.td().b().tx("Code " + targets.get("code").toString());
else
tr.td().b().tx("Code");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
if (targets.get(s).size() == 1)
tr.td().b().addText(getDescForConcept(s) + " " + targets.get(s).toString() + "");
else
tr.td().b().addText(getDescForConcept(s));
}
}
if (comment)
tr.td();
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
td = tr.td();
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = getDisplayForConcept(grp.getSource(), ccl.getCode());
if (display != null)
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
for (String s : sources.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getCode(ccm.getDependsOn(), s, sources.get(s).size() != 1));
display = getDisplay(ccm.getDependsOn(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (!ccm.hasEquivalence())
tr.td().tx(":" + "(" + ConceptMapEquivalence.EQUIVALENT.toCode() + ")");
else
tr.td().tx(":" + ccm.getEquivalence().toCode());
td = tr.td();
if (targets.get("code").size() == 1)
td.addText(ccm.getCode());
else
td.addText(grp.getTarget() + " / " + ccm.getCode());
display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
if (display != null)
td.tx(" (" + display + ")");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getCode(ccm.getProduct(), s, targets.get(s).size() != 1));
display = getDisplay(ccm.getProduct(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (comment)
tr.td().addText(ccm.getComment());
}
}
}
inject(cm, x, NarrativeStatus.GENERATED);
return true;
}
use of org.hl7.fhir.r4b.model.ContactPoint in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType)
x.addText(((DateTimeType) e).toHumanDisplay());
else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.dstu3.model.DateType)
x.addText(((org.hl7.fhir.dstu3.model.DateType) e).toHumanDisplay());
else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType)
x.addText(((BooleanType) e).getValue().toString());
else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x);
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
} else if (e instanceof org.hl7.fhir.dstu3.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
x.addText(((org.hl7.fhir.dstu3.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
} else if (e instanceof Address) {
renderAddress((Address) e, x);
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
} else if (e instanceof UriType) {
renderUri((UriType) e, x);
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
} else if (e instanceof Range) {
renderRange((Range) e, x);
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.tx("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.tx(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
} else if (e instanceof Reference) {
Reference r = (Reference) e;
XhtmlNode c = x;
ResourceWithReference tr = null;
if (r.hasReferenceElement()) {
tr = resolveReference(res, r.getReference());
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null)
c = x.ah(tr.getReference());
else
c = x.ah(r.getReference());
}
}
// what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
if (r.hasDisplayElement()) {
c.addText(r.getDisplay());
if (tr != null && tr.getResource() != null) {
c.tx(". Generated Summary: ");
generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
}
} else if (tr != null && tr.getResource() != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
} else {
c.addText(r.getReference());
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
if (sd == null)
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
else
generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails);
}
}
Aggregations