use of org.hl7.fhir.r4b.model.Property in project org.hl7.fhir.core by hapifhir.
the class ObjectConverter method convertElement.
private Element convertElement(Property property, Base base) throws FHIRException {
if (base == null)
return null;
String tn = base.fhirType();
StructureDefinition sd = context.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(tn, context.getOverrideVersionNs()));
if (sd == null)
throw new FHIRException("Unable to find definition for type " + tn);
Element res = new Element(property.getName(), property);
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
res.setValue(((PrimitiveType) base).asStringValue());
List<ElementDefinition> children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
for (ElementDefinition child : children) {
String n = tail(child.getPath());
if (sd.getKind() != StructureDefinitionKind.PRIMITIVETYPE || !"value".equals(n)) {
Base[] values = base.getProperty(n.hashCode(), n, false);
if (values != null)
for (Base value : values) {
res.getChildren().add(convertElement(new Property(context, child, sd), value));
}
}
}
return res;
}
use of org.hl7.fhir.r4b.model.Property in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateExample.
private org.hl7.fhir.r4b.elementmodel.Element generateExample(StructureDefinition profile, ExampleValueAccessor accessor) throws FHIRException {
ElementDefinition ed = profile.getSnapshot().getElementFirstRep();
org.hl7.fhir.r4b.elementmodel.Element r = new org.hl7.fhir.r4b.elementmodel.Element(ed.getPath(), new Property(context, ed, profile));
List<ElementDefinition> children = getChildMap(profile, ed);
for (ElementDefinition child : children) {
if (child.getPath().endsWith(".id")) {
org.hl7.fhir.r4b.elementmodel.Element id = new org.hl7.fhir.r4b.elementmodel.Element("id", new Property(context, child, profile));
id.setValue(profile.getId() + accessor.getId());
r.getChildren().add(id);
} else {
org.hl7.fhir.r4b.elementmodel.Element e = createExampleElement(profile, child, accessor);
if (e != null)
r.getChildren().add(e);
}
}
return r;
}
use of org.hl7.fhir.r4b.model.Property in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseSource.
private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws FHIRException {
VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
if (var == null)
throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
PropertyWithType prop = var.getProperty();
boolean optional = false;
boolean repeating = false;
if (src.hasCondition()) {
optional = true;
}
if (src.hasElement()) {
Property element = prop.getBaseProperty().getChild(prop.getTypes().getType(), src.getElement());
if (element == null)
throw new FHIRException("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
if (element.getDefinition().getMin() == 0)
optional = true;
if (element.getDefinition().getMax().equals("*"))
repeating = true;
VariablesForProfiling result = vars.copy(optional, repeating);
TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
for (TypeRefComponent tr : element.getDefinition().getType()) {
if (!tr.hasCode())
throw new Error("Rule \"" + ruleId + "\": Element has no type");
ProfiledType pt = new ProfiledType(tr.getWorkingCode());
if (tr.hasProfile())
pt.addProfiles(tr.getProfile());
if (element.getDefinition().hasBinding())
pt.addBinding(element.getDefinition().getBinding());
type.addType(pt);
}
td.addText(prop.getPath() + "." + src.getElement());
if (src.hasVariable())
result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
return result;
} else {
// ditto!
td.addText(prop.getPath());
return vars.copy(optional, repeating);
}
}
use of org.hl7.fhir.r4b.model.Property in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateExample.
private org.hl7.fhir.r5.elementmodel.Element generateExample(StructureDefinition profile, ExampleValueAccessor accessor) throws FHIRException {
ElementDefinition ed = profile.getSnapshot().getElementFirstRep();
org.hl7.fhir.r5.elementmodel.Element r = new org.hl7.fhir.r5.elementmodel.Element(ed.getPath(), new Property(context, ed, profile));
List<ElementDefinition> children = getChildMap(profile, ed);
for (ElementDefinition child : children) {
if (child.getPath().endsWith(".id")) {
org.hl7.fhir.r5.elementmodel.Element id = new org.hl7.fhir.r5.elementmodel.Element("id", new Property(context, child, profile));
id.setValue(profile.getId() + accessor.getId());
r.getChildren().add(id);
} else {
org.hl7.fhir.r5.elementmodel.Element e = createExampleElement(profile, child, accessor);
if (e != null)
r.getChildren().add(e);
}
}
return r;
}
use of org.hl7.fhir.r4b.model.Property in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method initSpanningTable.
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical, String id) {
TableModel model = gen.new TableModel(id, true);
model.setDocoImg(prefix + "help16.png");
// todo: change to graph definition
model.setDocoRef(Utilities.pathURL(prefix, "formats.html#table"));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Property", "A profiled resource", null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Card.", "Minimum and Maximum # of times the the element can appear in the instance", null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Content", "What goes here", null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Description", "Description of the profile", null, 0));
return model;
}
Aggregations