work around bad r4 extension definitions

This commit is contained in:
Grahame Grieve 2024-06-13 12:13:32 +10:00
parent 2f2c7be2ed
commit a9f0b70e30
4 changed files with 15 additions and 854 deletions

View File

@ -800,21 +800,6 @@ public class RenderingContext extends RenderingI18nContext {
return t.asStringValue();
}
public String getTranslated(ResourceElement t) {
if (locale != null) {
for (ResourceElement e : t.extensions(ToolingExtensions.EXT_TRANSLATION)) {
String l = e.extensionString("lang");
if (l != null && l.equals(locale.toString())) {
String v = e.extensionString("content");
if (v != null) {
return v;
}
}
}
}
return t.primitiveValue();
}
public StringType getTranslatedElement(PrimitiveType<?> t) {
if (locale != null) {
StringType v = ToolingExtensions.getLanguageTranslationElement(t, locale.toString());

View File

@ -1,605 +0,0 @@
package org.hl7.fhir.r5.renderers.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.function.BooleanSupplier;
import org.hl7.fhir.r5.context.ContextUtilities;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Narrative;
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.utils.client.network.FhirRequestBuilder;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
/**
* This class is used to walk through the resources when rendering, whether
* the resource is a native resource or loaded by the element model
*/
public class ResourceElement {
public enum ElementKind {
PrimitiveType,
DataType,
BackboneElement,
ContainedResource,
InlineResource,
BundleEntry,
IndependentResource
}
private ContextUtilities context;
private ResourceElement parent;
private String name; // null at root
private int index; // -1 if not repeating
private ElementKind kind;
private Base element;
private Element model;
private List<ResourceElement> children;
public ResourceElement(ContextUtilities context, Resource resource) {
this.context = context;
this.parent = null;
this.name = null;
this.index = -1;
this.kind = ElementKind.IndependentResource;
this.element = resource;
}
public ResourceElement(ContextUtilities context, DataType type) {
this.context = context;
this.parent = null;
this.name = null;
this.index = -1;
this.kind = null;
this.element = type;
}
public ResourceElement(ContextUtilities context, ResourceElement parent, String name, int index, ElementKind kind, Base element) {
this.context = context;
this.parent = parent;
this.name = name;
this.index = index;
this.kind = kind;
this.element = element;
}
public ResourceElement(ContextUtilities context, Element resource) {
this.context = context;
this.parent = null;
this.name = null;
this.index = -1;
this.kind = ElementKind.IndependentResource;
this.model = resource;
}
public ResourceElement(ContextUtilities context, ResourceElement parent, String name, int index, ElementKind kind, Element em) {
this.context = context;
this.parent = parent;
this.name = name;
this.index = index;
this.kind = kind;
this.model = em;
}
public String fhirVersion() {
if (element != null) {
return element.getFHIRPublicationVersion().toCode();
} else {
return model.getFHIRPublicationVersion().toCode();
}
}
public String path() {
if (parent == null) {
return fhirType();
} else {
return parent.path()+"." + (index == -1 ? name : name+"["+index+"]");
}
}
public ElementKind kind() {
return kind;
}
public String name() {
return name;
}
public int index() {
return index;
}
public String fhirType() {
if (kind == ElementKind.BackboneElement) {
return basePath();
} else if (element != null) {
return element.fhirType();
} else {
return model.fhirType();
}
}
private String basePath() {
if (parent == null || this.isResource()) {
return this.fhirType();
} else {
return parent.basePath()+"."+name;
}
}
public boolean isPrimitive() {
if (element != null) {
return element.isPrimitive();
} else {
return model.isPrimitive();
}
}
public boolean hasPrimitiveValue() {
if (element != null) {
return element.hasPrimitiveValue();
} else {
return model.hasPrimitiveValue();
}
}
public String primitiveValue() {
if (element != null) {
return element.primitiveValue();
} else {
return model.primitiveValue();
}
}
public boolean isPrimitive(String name) {
ResourceElement child = child(name);
return child != null && child.isPrimitive();
}
public boolean hasPrimitiveValue(String name) {
ResourceElement child = child(name);
return child != null && child.hasPrimitiveValue();
}
public String primitiveValue(String name) {
ResourceElement child = child(name);
return child == null ? null : child.primitiveValue();
}
public String primitiveValueMN(String... names) {
ResourceElement child = childMN(names);
return child == null ? null : child.primitiveValue();
}
public String firstPrimitiveValue(String name) {
ResourceElement child = firstChild(name);
return child == null ? null : child.primitiveValue();
}
private void loadChildren() {
if (children == null) {
children = new ArrayList<>();
if (element != null) {
loadElementChildren();
} else {
loadModelChildren();
}
}
}
private void loadModelChildren() {
for (Element child : model.getChildren()) {
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(context, this, name, index, kind, child));
}
}
private ElementKind determineModelKind(Element child) {
if (child.isPrimitive()) {
return ElementKind.PrimitiveType;
} else if (child.fhirType().contains("Backbone")) {
return ElementKind.BackboneElement;
} else if (child.getProperty().getContextUtils().isDatatype(child.fhirType())) {
return ElementKind.DataType;
} else if (!child.isResource()) {
return ElementKind.BackboneElement;
} else if (parent == null) {
return ElementKind.IndependentResource;
} else switch (child.getSpecial()) {
case BUNDLE_ENTRY:
return ElementKind.BundleEntry;
case BUNDLE_ISSUES:
return ElementKind.InlineResource;
case BUNDLE_OUTCOME:
return ElementKind.InlineResource;
case CONTAINED:
return ElementKind.ContainedResource;
case PARAMETER:
return ElementKind.InlineResource;
default:
return ElementKind.IndependentResource;
}
}
private void loadElementChildren() {
for (Property p : element.children()) {
String name = p.getName();
int i = 0;
for (Base v : p.getValues()) {
ElementKind kind = determineModelKind(p, v);
int index = p.isList() ? i : -1;
children.add(new ResourceElement(context, this, name, index, kind, v));
i++;
}
}
}
private ElementKind determineModelKind(Property p, Base v) {
if (v.isPrimitive()) {
return ElementKind.PrimitiveType;
} else if (context.isDatatype(v.fhirType())) {
return ElementKind.DataType;
} else if (!v.isResource()) {
return ElementKind.BackboneElement;
} else if (parent == null) {
return ElementKind.IndependentResource;
} else if ("Bundle.entry".equals(fhirType()) && "resource".equals(p.getName())) {
return ElementKind.BundleEntry;
} else if ("Bundle".equals(fhirType()) && "outcome".equals(p.getName())) {
return ElementKind.InlineResource;
} else if ("Bundle".equals(fhirType()) && "issues".equals(p.getName())) {
return ElementKind.InlineResource;
} else if (isResource() && "contained".equals(p.getName())) {
return ElementKind.ContainedResource;
} else {
return ElementKind.InlineResource;
}
}
public List<ResourceElement> children() {
loadChildren();
return children;
}
public List<ResourceElement> children(String name) {
loadChildren();
List<ResourceElement> list = new ArrayList<ResourceElement>();
for (ResourceElement e : children) {
if (name.equals(e.name())) {
list.add(e);
}
}
return list;
}
/**
* For when an item has been renamed - find by any of the names
* @param name
* @return
*/
public List<ResourceElement> childrenMN(String... names) {
loadChildren();
List<ResourceElement> list = new ArrayList<ResourceElement>();
for (ResourceElement e : children) {
for (String name : names) {
if (name.equals(e.name())) {
list.add(e);
}
}
}
return list;
}
public ResourceElement child(String name) {
loadChildren();
ResourceElement res = null;
for (ResourceElement e : children) {
if (name.equals(e.name()) || (name+"[x]").equals(e.name())) {
if (res == null) {
res = e;
} else {
throw new Error("Duplicated element '"+name+"' @ '"+path()+"'");
}
}
}
return res;
}
/**
* For when an item has been renamed - find by any of the names
* @param names
* @return
*/
public ResourceElement childMN(String... names) {
loadChildren();
ResourceElement res = null;
for (ResourceElement e : children) {
for (String name : names) {
if (name.equals(e.name()) || (name+"[x]").equals(e.name())) {
if (res == null) {
res = e;
} else {
throw new Error("Duplicated element '"+name+"' @ '"+path()+"'");
}
}
}
}
return res;
}
public boolean has(String name) {
for (ResourceElement e : children) {
if (name.equals(e.name())) {
return true;
}
}
return false;
}
public ResourceElement resource() {
ResourceElement e = this.parent;
while (e != null && !e.isResource()) {
e = e.parent;
}
return e;
}
public boolean isResource() {
if (element != null) {
return element.isResource();
} else {
return model.isResource();
}
}
public boolean hasChildren() {
loadChildren();
return !children.isEmpty();
}
public boolean hasExtension(String url) {
loadChildren();
for (ResourceElement e : children) {
if ("Extension".equals(e.fhirType()) && url.equals(e.primitiveValue("url"))) {
return true;
}
}
return false;
}
public ResourceElement extension(String url) {
ResourceElement res = null;
loadChildren();
for (ResourceElement e : children) {
if ("Extension".equals(e.fhirType()) && url.equals(e.primitiveValue("url"))) {
if (res == null) {
res = e;
} else {
throw new Error("Duplicated extension '"+url+"' @ '"+path()+"'");
}
}
}
return res;
}
public ResourceElement extensionValue(String url) {
ResourceElement res = null;
loadChildren();
for (ResourceElement e : children) {
if ("Extension".equals(e.fhirType()) && url.equals(e.primitiveValue("url"))) {
if (res == null) {
res = e.child("value");
} else {
throw new Error("Duplicated extension '"+url+"' @ '"+path()+"'");
}
}
}
return res;
}
public List<ResourceElement> extensions(String url) {
List<ResourceElement> res = new ArrayList<ResourceElement>();
loadChildren();
for (ResourceElement e : children) {
if ("Extension".equals(e.fhirType()) && url.equals(e.primitiveValue("url"))) {
res.add(e);
}
}
return res;
}
public List<ResourceElement> extensions() {
List<ResourceElement> res = new ArrayList<ResourceElement>();
loadChildren();
for (ResourceElement e : children) {
if ("Extension".equals(e.fhirType())) {
res.add(e);
}
}
return res;
}
public List<ResourceElement> extensionValues(String url) {
List<ResourceElement> res = new ArrayList<ResourceElement>();
loadChildren();
for (ResourceElement e : children) {
if ("Extension".equals(e.fhirType()) && url.equals(e.primitiveValue("url"))) {
if (e.has("value")) {
res.add(e.child("value"));
}
}
}
return res;
}
public boolean canHaveNarrative() {
if (!isResource()) {
return false;
}
if (element != null) {
return element instanceof DomainResource;
} else {
return context.isDomainResource(fhirType());
}
}
public XhtmlNode getNarrative() {
if (!canHaveNarrative()) {
return null;
}
ResourceElement text = child("text");
if (text == null) {
return null;
}
ResourceElement div = text.child("div");
if (div == null) {
return null;
}
if (div.element != null) {
return div.element.getXhtml();
} else {
return div.model.getXhtml();
}
}
public boolean hasNarrative() {
if (!canHaveNarrative()) {
return false;
}
ResourceElement text = child("text");
if (text == null) {
return false;
}
ResourceElement div = text.child("div");
if (div == null) {
return false;
}
if (div.element != null) {
return div.element.getXhtml() != null;
} else {
return div.model.getXhtml() != null;
}
}
public void setNarrative(XhtmlNode x, String status, boolean multiLangMode, Locale locale) {
if (element != null) {
if (element instanceof DomainResource) {
DomainResource r = (DomainResource) element;
r.getText().setUserData("renderer.generated", true);
if (!r.hasText() || !r.getText().hasDiv()) {
r.setText(new Narrative());
r.getText().setStatusAsString(status);
}
if (multiLangMode) {
if (!r.getText().hasDiv()) {
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
div.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
r.getText().setDiv(div);
} else {
r.getText().getDiv().getChildNodes().removeIf(c -> !"div".equals(c.getName()) || !c.hasAttribute("xml:lang"));
}
markLanguage(x, locale);
r.getText().getDiv().getChildNodes().add(x);
} else {
if (!x.hasAttribute("xmlns"))
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
if (r.hasLanguage()) {
// use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
x.setAttribute("lang", r.getLanguage());
x.setAttribute("xml:lang", r.getLanguage());
}
r.getText().setDiv(x);
}
} else {
throw new Error("Cannot call setNarrative on a "+element.fhirType());
}
}
}
public void markLanguage(XhtmlNode x, Locale locale) {
x.setAttribute("lang", locale.toString());
x.setAttribute("xml:lang", locale.toString());
x.addTag(0, "hr");
x.addTag(0, "p").b().tx(locale.getDisplayName());
x.addTag(0, "hr");
}
public String getId() {
if (element != null) {
return element.getIdBase();
} else {
return model.getIdBase();
}
}
@Override
public String toString() {
return name + (index == -1 ? "" : "["+index+"]")+": "+fhirType()+" ("+kind+")";
}
public boolean matches(ResourceElement b) {
}
public String extensionString(String url) {
ResourceElement re = extensionValue(url);
return re == null ? null : re.primitiveValue();
}
public boolean isEmpty() {
if (hasChildren()) {
for (ResourceElement c : children) {
if (!c.isEmpty()) {
return false;
}
}
}
return !isPrimitive() || !hasPrimitiveValue();
}
public Resource getResource() {
return element == null ? null : (Resource) element;
}
public ResourceElement firstChild(String name) {
List<ResourceElement> list = children(name);
return list.size() == 0 ? null : list.get(0);
}
public ContextUtilities getContextUtilities() {
return context;
}
public boolean hasFormatComment() {
if (element != null) {
return element.hasFormatComment();
} else {
return model.hasFormatComment();
}
}
public Collection<String> getFormatCommentsPre() {
if (element != null) {
return element.getFormatCommentsPre();
} else {
return model.getFormatCommentsPre();
}
}
}

View File

@ -3,6 +3,7 @@ package org.hl7.fhir.r5.utils;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Enumerations.BindingStrength;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.r5.model.PackageInformation;
import org.hl7.fhir.r5.model.StructureDefinition;
@ -77,6 +78,20 @@ public class PackageHackerR5 {
}
}
}
// work around a r4 version of extension pack issue
if (packageInfo.getId().equals("hl7.fhir.uv.extensions.r4") && r.getType().equals("StructureDefinition")) {
StructureDefinition sd = (StructureDefinition) r.getResource();
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
if (ed.getType().removeIf(tr -> Utilities.existsInList(tr.getCode(), "integer64", "CodeableReference", "RatioRange", "Availability", "ExtendedContactDetail"))) {
sd.setUserData("fixed-by-loader", true);
}
}
for (ElementDefinition ed : sd.getDifferential().getElement()) {
if (ed.getType().removeIf(tr -> Utilities.existsInList(tr.getCode(), "integer64", "CodeableReference", "RatioRange", "Availability", "ExtendedContactDetail"))) {
sd.setUserData("fixed-by-loader", true);
}
}
}
if (r.hasUrl() && r.getUrl().contains("|")) {
assert false;
}

View File

@ -1,234 +0,0 @@
package org.hl7.fhir.r5.test.rendering;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.context.ContextUtilities;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.elementmodel.ValidatedFragment;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.ResourceElement;
import org.hl7.fhir.r5.renderers.utils.ResourceElement.ElementKind;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ResourceElementTests {
@Test
public void testDirect() throws FHIRFormatError, IOException {
IWorkerContext worker = TestingUtilities.getSharedWorkerContext();
Resource res = new XmlParser().parse(TestingUtilities.loadTestResource("r5", "bundle-resource-element-test.xml"));
ResourceElement re = new ResourceElement(new ContextUtilities(worker), res);
checkTree(re);
}
@Test
public void testIndirect() throws FHIRFormatError, IOException {
IWorkerContext worker = TestingUtilities.getSharedWorkerContext();
List<ValidatedFragment> res = Manager.parse(worker, TestingUtilities.loadTestResourceStream("r5", "bundle-resource-element-test.xml"), FhirFormat.XML);
ResourceElement re = new ResourceElement(new ContextUtilities(worker), res.get(0).getElement());
checkTree(re);
}
private void checkTree(ResourceElement bnd) {
Assertions.assertTrue(bnd.fhirType().equals("Bundle"));
Assertions.assertNull(bnd.name());
Assertions.assertNull(bnd.getId());
Assertions.assertEquals("Bundle", bnd.path());
Assertions.assertEquals("5.0.0", bnd.fhirVersion());
Assertions.assertFalse(bnd.canHaveNarrative());
Assertions.assertFalse(bnd.hasNarrative());
Assertions.assertEquals(ElementKind.IndependentResource, bnd.kind());
ResourceElement type = bnd.child("type");
Assertions.assertTrue(type.fhirType().equals("code"));
Assertions.assertEquals("type", type.name());
Assertions.assertEquals("Bundle.type", type.path());
Assertions.assertTrue(type.isPrimitive());
Assertions.assertTrue(type.hasPrimitiveValue());
Assertions.assertEquals("collection", type.primitiveValue());
Assertions.assertFalse(type.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, type.kind());
ResourceElement id = bnd.child("identifier");
Assertions.assertEquals("Identifier", id.fhirType());
Assertions.assertEquals("identifier", id.name());
Assertions.assertEquals("Bundle.identifier", id.path());
Assertions.assertFalse(id.isPrimitive());
Assertions.assertFalse(id.hasPrimitiveValue());
Assertions.assertTrue(id.hasChildren());
Assertions.assertEquals(ElementKind.DataType, id.kind());
ResourceElement system = id.child("system");
Assertions.assertEquals("uri", system.fhirType());
Assertions.assertEquals("system", system.name());
Assertions.assertEquals("Bundle.identifier.system", system.path());
Assertions.assertTrue(system.isPrimitive());
Assertions.assertTrue(system.hasPrimitiveValue());
Assertions.assertEquals("http://something1", system.primitiveValue());
Assertions.assertFalse(system.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, system.kind());
ResourceElement value = id.child("value");
Assertions.assertEquals("string", value.fhirType());
Assertions.assertEquals("value", value.name());
Assertions.assertEquals("Bundle.identifier.value", value.path());
Assertions.assertTrue(value.isPrimitive());
Assertions.assertTrue(value.hasPrimitiveValue());
Assertions.assertEquals("something2", value.primitiveValue());
Assertions.assertFalse(value.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, value.kind());
int i = 0;
for (ResourceElement link : bnd.children("link")) {
checkLink(i, link);
i++;
}
ResourceElement entry = bnd.child("entry");
Assertions.assertEquals("Bundle.entry", entry.fhirType());
Assertions.assertEquals("entry", entry.name());
Assertions.assertEquals("Bundle.entry[0]", entry.path());
Assertions.assertFalse(entry.isPrimitive());
Assertions.assertFalse(entry.hasPrimitiveValue());
Assertions.assertTrue(entry.hasChildren());
Assertions.assertEquals(ElementKind.BackboneElement, entry.kind());
ResourceElement fu = entry.child("fullUrl");
Assertions.assertEquals("uri", fu.fhirType());
Assertions.assertEquals("fullUrl", fu.name());
Assertions.assertEquals("Bundle.entry[0].fullUrl", fu.path());
Assertions.assertTrue(fu.isPrimitive());
Assertions.assertTrue(fu.hasPrimitiveValue());
Assertions.assertEquals("http://something5", fu.primitiveValue());
Assertions.assertFalse(fu.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, fu.kind());
ResourceElement obs = entry.child("resource");
checkObservation(obs);
}
private void checkObservation(ResourceElement obs) {
Assertions.assertTrue(obs.fhirType().equals("Observation"));
Assertions.assertEquals("resource", obs.name());
Assertions.assertEquals("obs1", obs.getId());
Assertions.assertEquals("Bundle.entry[0].resource", obs.path());
Assertions.assertEquals(ElementKind.BundleEntry, obs.kind());
Assertions.assertTrue(obs.canHaveNarrative());
Assertions.assertTrue(obs.hasNarrative());
Assertions.assertNotNull(obs.getNarrative());
List<ResourceElement> children = obs.children();
assertEquals(5, children.size());
checkObsCode(children.get(3));
assertEquals(children.get(4), obs.child("value"));
assertEquals(children.get(4), obs.child("value[x]"));
checkObsValue(children.get(4));
assertEquals(children.get(2), obs.child("contained"));
checkContained(children.get(2));
}
private void checkContained(ResourceElement cont) {
Assertions.assertEquals("Provenance", cont.fhirType());
Assertions.assertEquals("contained", cont.name());
Assertions.assertEquals("Bundle.entry[0].resource.contained[0]", cont.path());
Assertions.assertFalse(cont.isPrimitive());
Assertions.assertFalse(cont.hasPrimitiveValue());
Assertions.assertTrue(cont.hasChildren());
Assertions.assertEquals(ElementKind.ContainedResource, cont.kind());
}
private void checkObsValue(ResourceElement obsValue) {
Assertions.assertEquals("Quantity", obsValue.fhirType());
Assertions.assertEquals("value[x]", obsValue.name());
Assertions.assertEquals("Bundle.entry[0].resource.value[x]", obsValue.path());
Assertions.assertFalse(obsValue.isPrimitive());
Assertions.assertFalse(obsValue.hasPrimitiveValue());
Assertions.assertTrue(obsValue.hasChildren());
Assertions.assertEquals(ElementKind.DataType, obsValue.kind());
}
private void checkObsCode(ResourceElement obsCode) {
Assertions.assertEquals("CodeableConcept", obsCode.fhirType());
Assertions.assertEquals("code", obsCode.name());
Assertions.assertEquals("Bundle.entry[0].resource.code", obsCode.path());
Assertions.assertFalse(obsCode.isPrimitive());
Assertions.assertFalse(obsCode.hasPrimitiveValue());
Assertions.assertTrue(obsCode.hasChildren());
Assertions.assertEquals(ElementKind.DataType, obsCode.kind());
ResourceElement txt = obsCode.children().get(1);
Assertions.assertEquals("string", txt.fhirType());
Assertions.assertEquals("text", txt.name());
Assertions.assertEquals("Bundle.entry[0].resource.code.text", txt.path());
Assertions.assertTrue(txt.isPrimitive());
Assertions.assertFalse(txt.hasPrimitiveValue());
Assertions.assertTrue(txt.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, txt.kind());
ResourceElement e1 = txt.extension("http://something11");
Assertions.assertEquals("Extension", e1.fhirType());
Assertions.assertEquals("extension", e1.name());
Assertions.assertEquals("Bundle.entry[0].resource.code.text.extension[0]", e1.path());
Assertions.assertFalse(e1.isPrimitive());
Assertions.assertFalse(e1.hasPrimitiveValue());
Assertions.assertTrue(e1.hasChildren());
Assertions.assertEquals(ElementKind.DataType, e1.kind());
Assertions.assertEquals("http://something11", e1.primitiveValue("url"));
ResourceElement ev = txt.extensionValue("http://something11");
Assertions.assertEquals(ev, e1.child("value"));
Assertions.assertEquals(ev, e1.child("value[x]"));
Assertions.assertEquals("string", ev.fhirType());
Assertions.assertEquals("value[x]", ev.name());
Assertions.assertEquals("Bundle.entry[0].resource.code.text.extension[0].value[x]", ev.path());
Assertions.assertTrue(ev.isPrimitive());
Assertions.assertTrue(ev.hasPrimitiveValue());
Assertions.assertFalse(ev.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, ev.kind());
Assertions.assertEquals("something12", ev.primitiveValue());
}
private void checkLink(int i, ResourceElement link) {
Assertions.assertEquals("Bundle.link", link.fhirType());
Assertions.assertEquals("link", link.name());
Assertions.assertEquals("Bundle.link["+i+"]", link.path());
Assertions.assertFalse(link.isPrimitive());
Assertions.assertFalse(link.hasPrimitiveValue());
Assertions.assertTrue(link.hasChildren());
Assertions.assertEquals(ElementKind.BackboneElement, link.kind());
ResourceElement rel = link.child("relation");
Assertions.assertEquals("code", rel.fhirType());
Assertions.assertEquals("relation", rel.name());
Assertions.assertEquals("Bundle.link["+i+"].relation", rel.path());
Assertions.assertTrue(rel.isPrimitive());
Assertions.assertTrue(rel.hasPrimitiveValue());
Assertions.assertEquals(i == 0 ? "self" : "next", rel.primitiveValue());
Assertions.assertFalse(rel.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, rel.kind());
ResourceElement url = link.child("url");
Assertions.assertEquals("uri", url.fhirType());
Assertions.assertEquals("url", url.name());
Assertions.assertEquals("Bundle.link["+i+"].url", url.path());
Assertions.assertTrue(url.isPrimitive());
Assertions.assertTrue(url.hasPrimitiveValue());
Assertions.assertEquals(i == 0 ? "http://something3" : "http://something4", url.primitiveValue());
Assertions.assertFalse(url.hasChildren());
Assertions.assertEquals(ElementKind.PrimitiveType, url.kind());
}
}