use of org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.
the class ListRenderer method shortForRef.
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();
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 {
RendererFactory.factory(url, context).renderReference(r.getResource(), x, (Reference) ref);
}
} else if (disp != null) {
x.tx(disp);
} else {
x.tx("?ngen-16?");
}
}
return x;
}
use of org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.
the class ListRenderer method shortForRef.
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();
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 {
RendererFactory.factory(url, context).renderReference(r.getResource(), x, (Reference) ref);
}
} else if (disp != null) {
x.tx(disp);
} else {
x.tx("?ngen-16?");
}
}
return x;
}
use of org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference 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);
}
}
use of org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.
the class ResourceRenderer method fetchResource.
protected ResourceWrapper fetchResource(BaseWrapper subject) throws UnsupportedEncodingException, FHIRException, IOException {
if (context.getResolver() == null)
return null;
PropertyWrapper ref = subject.getChildByName("reference");
if (ref == null || !ref.hasValues()) {
return null;
}
String url = ref.value().getBase().primitiveValue();
ResourceWithReference rr = context.getResolver().resolve(context, url);
return rr == null ? null : rr.getResource();
}
use of org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference in project org.hl7.fhir.core by hapifhir.
the class ResourceRenderer method resolveReference.
protected ResourceWithReference resolveReference(ResourceWrapper res, String url) {
if (url == null)
return null;
if (url.startsWith("#") && res != null) {
for (ResourceWrapper r : res.getContained()) {
if (r.getId().equals(url.substring(1)))
return new ResourceWithReference(null, r);
}
return null;
}
String version = null;
if (url.contains("/_history/")) {
version = url.substring(url.indexOf("/_history/") + 10);
url = url.substring(0, url.indexOf("/_history/"));
}
if (rcontext != null) {
BundleEntryComponent bundleResource = rcontext.resolve(url);
if (bundleResource != null) {
String bundleUrl = "#" + bundleResource.getResource().getResourceType().name() + "_" + bundleResource.getResource().getId();
return new ResourceWithReference(bundleUrl, new ResourceWrapperDirect(this.context, bundleResource.getResource()));
}
org.hl7.fhir.r5.elementmodel.Element bundleElement = rcontext.resolveElement(url, version);
if (bundleElement != null) {
String bundleUrl = null;
Element br = bundleElement.getNamedChild("resource");
if (br.getChildValue("id") != null) {
bundleUrl = "#" + br.fhirType() + "_" + br.getChildValue("id");
} else {
bundleUrl = "#" + fullUrlToAnchor(bundleElement.getChildValue("fullUrl"));
}
return new ResourceWithReference(bundleUrl, new ResourceWrapperMetaElement(this.context, br));
}
}
Resource ae = getContext().getWorker().fetchResource(null, url, version);
if (ae != null)
return new ResourceWithReference(url, new ResourceWrapperDirect(this.context, ae));
else if (context.getResolver() != null) {
return context.getResolver().resolve(context, url);
} else
return null;
}
Aggregations