use of org.hl7.fhir.r4.elementmodel.ObjectConverter in project kindling by HL7.
the class ExampleInspector method fetch.
@Override
public Element fetch(IResourceValidator validator, Object appContext, String url) throws IOException, FHIRException {
String[] parts = url.split("\\/");
if (parts.length == 2 && definitions.hasResource(parts[0])) {
ResourceDefn r = definitions.getResourceByName(parts[0]);
for (Example e : r.getExamples()) {
if (e.getElement() == null && e.hasXml()) {
e.setElement(new org.hl7.fhir.r5.elementmodel.XmlParser(context).parse(e.getXml()));
if (e.getElement().getProperty().getStructure().getBaseDefinition().contains("MetadataResource")) {
String urle = e.getElement().getChildValue("url");
String v = e.getElement().getChildValue("url");
if (urle != null && urle.startsWith("http://hl7.org/fhir") && !version.toCode().equals(v)) {
e.getElement().setChildValue("version", version.toCode());
}
}
}
if (e.getElement() != null) {
if (e.getElement().fhirType().equals("Bundle")) {
for (Base b : e.getElement().listChildrenByName("entry")) {
if (b.getChildByName("resource").hasValues()) {
Element res = (Element) b.getChildByName("resource").getValues().get(0);
if (res.fhirType().equals(parts[0]) && parts[1].equals(res.getChildValue("id"))) {
return res;
}
}
}
} else if (e.getElement().fhirType().equals(parts[0]) && e.getId().equals(parts[1])) {
return e.getElement();
}
}
}
try {
if (parts[0].equals("StructureDefinition"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(StructureDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("OperationDefinition"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(OperationDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("SearchParameter"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(SearchParameter.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("ValueSet"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(ValueSet.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
if (parts[0].equals("CodeSystem"))
return new ObjectConverter(context).convert(context.fetchResourceWithException(CodeSystem.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
} catch (Exception e) {
return null;
}
return null;
} else
return null;
}
use of org.hl7.fhir.r4.elementmodel.ObjectConverter in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method createExampleElement.
private org.hl7.fhir.r4.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
Type v = accessor.getExampleValue(ed);
if (v != null) {
return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
} else {
org.hl7.fhir.r4.elementmodel.Element res = new org.hl7.fhir.r4.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
boolean hasValue = false;
List<ElementDefinition> children = getChildMap(profile, ed);
for (ElementDefinition child : children) {
if (!child.hasContentReference()) {
org.hl7.fhir.r4.elementmodel.Element e = createExampleElement(profile, child, accessor);
if (e != null) {
hasValue = true;
res.getChildren().add(e);
}
}
}
if (hasValue)
return res;
else
return null;
}
}
use of org.hl7.fhir.r4.elementmodel.ObjectConverter in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method validate.
@Override
public org.hl7.fhir.r5.elementmodel.Element validate(Object appContext, List<ValidationMessage> errors, Resource resource, List<StructureDefinition> profiles) throws FHIRException {
long t = System.nanoTime();
Element e;
try {
e = new ObjectConverter(context).convert(resource);
} catch (IOException e1) {
throw new FHIRException(e1);
}
timeTracker.load(t);
validate(appContext, errors, null, e, profiles);
return e;
}
use of org.hl7.fhir.r4.elementmodel.ObjectConverter in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method createExampleElement.
private org.hl7.fhir.r4b.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
DataType v = accessor.getExampleValue(ed);
if (v != null) {
return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
} else {
org.hl7.fhir.r4b.elementmodel.Element res = new org.hl7.fhir.r4b.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
boolean hasValue = false;
List<ElementDefinition> children = getChildMap(profile, ed);
for (ElementDefinition child : children) {
if (!child.hasContentReference()) {
org.hl7.fhir.r4b.elementmodel.Element e = createExampleElement(profile, child, accessor);
if (e != null) {
hasValue = true;
res.getChildren().add(e);
}
}
}
if (hasValue)
return res;
else
return null;
}
}
use of org.hl7.fhir.r4.elementmodel.ObjectConverter in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method createExampleElement.
private org.hl7.fhir.dstu3.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
Type v = accessor.getExampleValue(ed);
if (v != null) {
return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
} else {
org.hl7.fhir.dstu3.elementmodel.Element res = new org.hl7.fhir.dstu3.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
boolean hasValue = false;
List<ElementDefinition> children = getChildMap(profile, ed);
for (ElementDefinition child : children) {
if (!child.hasContentReference()) {
org.hl7.fhir.dstu3.elementmodel.Element e = createExampleElement(profile, child, accessor);
if (e != null) {
hasValue = true;
res.getChildren().add(e);
}
}
}
if (hasValue)
return res;
else
return null;
}
}
Aggregations