use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class XmlParser method parse.
public Element parse(org.w3c.dom.Element base, String type) throws Exception {
StructureDefinition sd = getDefinition(0, 0, FormatUtilities.FHIR_NS, type);
Element result = new Element(base.getLocalName(), new Property(context, sd.getSnapshot().getElement().get(0), sd));
String path = "/" + pathPrefix(base.getNamespaceURI()) + base.getLocalName();
checkElement(base, path, result.getProperty());
result.setType(base.getLocalName());
parseChildren(path, base, result);
result.numberChildren();
return result;
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeCodeSystemConceptPropertyComponent.
protected void composeCodeSystemConceptPropertyComponent(Complex parent, String parentType, String name, CodeSystem.ConceptPropertyComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "property", name, element, index);
if (element.hasCodeElement())
composeCode(t, "CodeSystem", "code", element.getCodeElement(), -1);
if (element.hasValue())
composeType(t, "CodeSystem", "value", element.getValue(), -1);
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class JavaResourceGenerator method generateUnimplementedAccessors.
private void generateUnimplementedAccessors(Analysis analysis, TypeInfo ti, ElementDefinition e, String indent) throws Exception {
System.out.println(" .. unimplemented: " + e.getPath());
String tn = e.getUserString("java.type");
String className = ti.getName();
if (Utilities.noString(tn)) {
tn = e.getUserString("type");
if (Utilities.noString(tn)) {
throw new Error("??");
}
}
boolean isReferenceRefField = (analysis.getName().equals("Reference") && e.getName().equals("reference"));
jdoc(indent, "not supported on this implementation");
write(indent + "@Override\r\n");
write(indent + "public int get" + getTitle(getElementName(e.getName(), false)) + "Max() { \r\n");
write(indent + " return 0;\r\n");
write(indent + "}\r\n");
String simpleType = getSimpleType(tn);
if (e.unbounded()) {
/*
* getXXX()for repeatable type
*/
jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
String listGenericType;
if (tn == null && e.hasContentReference()) {
listGenericType = analysis.getName();
} else {
listGenericType = tn;
}
write(indent + "public List<" + listGenericType + "> get" + getTitle(getElementName(e.getName(), false)) + "() { \r\n");
write(indent + " return new ArrayList<>();\r\n");
write(indent + "}\r\n");
/*
* setXXX(List<foo>) for repeating type
*/
jdoc(indent, "@return Returns a reference to <code>this</code> for easy method chaining");
write(indent + "public " + className + " set" + getTitle(getElementName(e.getName(), false)) + "(" + "List<" + listGenericType + "> the" + getTitle(getElementName(e.getName(), false)) + ") { \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
/*
* hasXXX() for repeatable type
*/
write(indent + "public boolean has" + getTitle(getElementName(e.getName(), false)) + "() { \r\n");
write(indent + " return false;\r\n");
write(indent + "}\r\n");
write("\r\n");
if (e.getType().size() == 1 && (definitions.hasPrimitiveType(e.typeSummary()) || e.typeSummary().equals("xml:lang") || e.typeSummary().startsWith("canonical("))) {
/*
* addXXXElement() for repeatable primitive
*/
jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
write(indent + "public " + tn + " add" + getTitle(getElementName(e.getName(), false)) + "Element(){//2 \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
/*
* addXXX(foo) for repeatable primitive
*/
jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
write(indent + "public " + className + " add" + getTitle(getElementName(e.getName(), false)) + "(" + simpleType + " value) { //1\r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
/*
* hasXXX(foo) for repeatable primitive
*/
jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
write(indent + "public boolean has" + getTitle(getElementName(e.getName(), false)) + "(" + simpleType + " value); \r\n");
write(indent + " return false;\r\n");
write(indent + "}\r\n");
} else {
if (!definitions.hasResource(tn)) {
/*
* addXXX() for repeatable composite
*/
write(indent + "public " + tn + " add" + getTitle(getElementName(e.getName(), false)) + "() { //3\r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
/*
* addXXX(foo) for repeatable composite
*/
write(indent + "public " + className + " add" + getTitle(getElementName(e.getName(), false)) + "(" + tn + " t) { //3\r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
} else {
/*
* addXXX(foo) for repeatable composite
*/
write(indent + "public " + className + " add" + getTitle(getElementName(e.getName(), false)) + "(" + tn + " t) { //3\r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
}
/*
* getXXXFirstRep() for repeatable element
*/
if (!"DomainResource".equals(className)) {
jdoc(indent, "@return The first repetition of repeating field {@link #" + getElementName(e.getName(), true) + "}, creating it if it does not already exist {2}");
write(indent + "public " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "FirstRep() { \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
}
}
} else {
if (!"xhtml".equals(e.typeSummary()) && isJavaPrimitive(e) || (e.getType().size() == 1 && e.typeSummary().startsWith("canonical("))) {
jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + "). This is the underlying object with id, value and extensions. The accessor \"get" + getTitle(getElementName(e.getName(), false)) + "\" gives direct access to the value");
if (isReferenceRefField) {
/*
* Reference#getReferenceElement is defined differently in BaseReference.java?
*/
write(indent + "public " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "Element_() { \r\n");
} else {
write(indent + "public " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "Element() { \r\n");
}
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
write("\r\n");
write(indent + "public boolean has" + getTitle(getElementName(e.getName(), false)) + "Element() { \r\n");
write(indent + " return false;\r\n");
write(indent + "}\r\n");
write(indent + "public boolean has" + getTitle(getElementName(e.getName(), false)) + "() {\r\n");
write(indent + " return false;\r\n");
write(indent + "}\r\n");
write("\r\n");
jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + "). This is the underlying object with id, value and extensions. The accessor \"get" + getTitle(getElementName(e.getName(), false)) + "\" gives direct access to the value");
write(indent + "public " + className + " set" + getTitle(getElementName(e.getName(), false)) + "Element(" + tn + " value) { \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
write(indent + "public " + simpleType + " get" + getTitle(getElementName(e.getName(), false)) + "() { \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
generateUnimplementedSetter(analysis, e, indent, className, tn, simpleType, analysis.getName());
// BigDecimal sugar methods
if (simpleType.equals("BigDecimal")) {
generateUnimplementedSetter(analysis, e, indent, className, tn, "long", analysis.getName());
generateUnimplementedSetter(analysis, e, indent, className, tn, "double", analysis.getName());
}
} else {
jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
write(indent + "public " + tn + " get" + getTitle(getElementName(e.getName(), false)) + "() { \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
if (e.getType().size() > 1 && (tn.equals("DataType") || !tn.endsWith(".DataType"))) {
for (TypeRefComponent t : e.getType()) {
jdoc(indent, "@return {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
String ttn = getTypename(t);
write(indent + "public " + ttn + " get" + getTitle(getElementName(e.getName(), false)) + ttn + "() { throws FHIRException; \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
write(indent + "public boolean has" + getTitle(getElementName(e.getName(), false)) + ttn + "() { \r\n");
}
}
write(indent + "public boolean has" + getTitle(getElementName(e.getName(), false)) + "() { \r\n");
write(indent + " return false;\r\n");
write(indent + "}\r\n");
jdoc(indent, "@param value {@link #" + getElementName(e.getName(), true) + "} (" + replaceTitle(analysis.getName(), e.getDefinition()) + ")");
write(indent + "public " + className + " set" + getTitle(getElementName(e.getName(), false)) + "(" + tn + " value) { \r\n");
write(indent + " throw new Error(\"The resource type \\\"" + analysis.getName() + "\\\" does not implement the property \\\"" + e.getName() + "\\\"\");\r\n");
write(indent + "}\r\n");
write("\r\n");
}
}
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class ExtensionHelper method setExtension.
/**
* set the value of an extension on the element. if value == null, make sure it doesn't exist
*
* @param element - the element to act on. Can also be a backbone element
* @param modifier - whether this is a modifier. Note that this is a definitional property of the extension; don't alternate
* @param uri - the identifier for the extension
* @param value - the value of the extension. Delete if this is null
* @- if the modifier logic is incorrect
*/
public static void setExtension(Element element, boolean modifier, String uri, Type value) throws FHIRException {
if (value == null) {
// deleting the extension
if (element instanceof BackboneElement)
for (Extension e : ((BackboneElement) element).getModifierExtension()) {
if (uri.equals(e.getUrl()))
((BackboneElement) element).getModifierExtension().remove(e);
}
for (Extension e : element.getExtension()) {
if (uri.equals(e.getUrl()))
element.getExtension().remove(e);
}
} else {
// it would probably be easier to delete and then create, but this would re-order the extensions
// not that order matters, but we'll preserve it anyway
boolean found = false;
if (element instanceof BackboneElement)
for (Extension e : ((BackboneElement) element).getModifierExtension()) {
if (uri.equals(e.getUrl())) {
if (!modifier)
throw new FHIRException("Error adding extension \"" + uri + "\": found an existing modifier extension, and the extension is not marked as a modifier");
e.setValue(value);
found = true;
}
}
for (Extension e : element.getExtension()) {
if (uri.equals(e.getUrl())) {
if (modifier)
throw new FHIRException("Error adding extension \"" + uri + "\": found an existing extension, and the extension is marked as a modifier");
e.setValue(value);
found = true;
}
}
if (!found) {
Extension ex = new Extension().setUrl(uri).setValue(value);
if (modifier) {
if (!(element instanceof BackboneElement))
throw new FHIRException("Error adding extension \"" + uri + "\": extension is marked as a modifier, but element is not a backbone element");
((BackboneElement) element).getModifierExtension().add(ex);
} else {
element.getExtension().add(ex);
}
}
}
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method compareElements.
/**
* left and right refer to the same element. Are they compatible?
* @param outcome
* @param outcome
* @param path
* @param left
* @param right
* @- if there's a problem that needs fixing in this code
* @throws DefinitionException
* @throws IOException
*/
private boolean compareElements(ProfileComparison outcome, String path, DefinitionNavigator left, DefinitionNavigator right) throws DefinitionException, IOException {
// preconditions:
assert (path != null);
assert (left != null);
assert (right != null);
assert (left.path().equals(right.path()));
// we ignore slicing right now - we're going to clone the root one anyway, and then think about clones
// simple stuff
ElementDefinition subset = new ElementDefinition();
subset.setPath(left.path());
// not allowed to be different:
// can't be bothered even testing this one
subset.getRepresentation().addAll(left.current().getRepresentation());
if (!outcome.ruleCompares(subset, left.current().getDefaultValue(), right.current().getDefaultValue(), path + ".defaultValue[x]", BOTH_NULL))
return false;
subset.setDefaultValue(left.current().getDefaultValue());
if (!outcome.ruleEqual(path, subset, left.current().getMeaningWhenMissing(), right.current().getMeaningWhenMissing(), "meaningWhenMissing Must be the same", true))
return false;
subset.setMeaningWhenMissing(left.current().getMeaningWhenMissing());
if (!outcome.ruleEqual(subset, left.current().getIsModifier(), right.current().getIsModifier(), path, "isModifier"))
return false;
subset.setIsModifier(left.current().getIsModifier());
if (!outcome.ruleEqual(subset, left.current().getIsSummary(), right.current().getIsSummary(), path, "isSummary"))
return false;
subset.setIsSummary(left.current().getIsSummary());
// descriptive properties from ElementDefinition - merge them:
subset.setLabel(mergeText(subset, outcome, path, "label", left.current().getLabel(), right.current().getLabel()));
subset.setShort(mergeText(subset, outcome, path, "short", left.current().getShort(), right.current().getShort()));
subset.setDefinition(mergeText(subset, outcome, path, "definition", left.current().getDefinition(), right.current().getDefinition()));
subset.setComments(mergeText(subset, outcome, path, "comments", left.current().getComments(), right.current().getComments()));
subset.setRequirements(mergeText(subset, outcome, path, "requirements", left.current().getRequirements(), right.current().getRequirements()));
subset.getCode().addAll(mergeCodings(left.current().getCode(), right.current().getCode()));
subset.getAlias().addAll(mergeStrings(left.current().getAlias(), right.current().getAlias()));
subset.getMapping().addAll(mergeMappings(left.current().getMapping(), right.current().getMapping()));
// left will win for example
subset.setExample(left.current().hasExample() ? left.current().getExample() : right.current().getExample());
subset.setMustSupport(left.current().getMustSupport() || right.current().getMustSupport());
ElementDefinition superset = subset.copy();
// compare and intersect
superset.setMin(unionMin(left.current().getMin(), right.current().getMin()));
superset.setMax(unionMax(left.current().getMax(), right.current().getMax()));
subset.setMin(intersectMin(left.current().getMin(), right.current().getMin()));
subset.setMax(intersectMax(left.current().getMax(), right.current().getMax()));
outcome.rule(subset, subset.getMax().equals("*") || Integer.parseInt(subset.getMax()) >= subset.getMin(), path, "Cardinality Mismatch: " + card(left) + "/" + card(right));
superset.getType().addAll(unionTypes(path, left.current().getType(), right.current().getType()));
subset.getType().addAll(intersectTypes(subset, outcome, path, left.current().getType(), right.current().getType()));
outcome.rule(subset, !subset.getType().isEmpty() || (!left.current().hasType() && !right.current().hasType()), path, "Type Mismatch:\r\n " + typeCode(left) + "\r\n " + typeCode(right));
// <fixed[x]><!-- ?? 0..1 * Value must be exactly this --></fixed[x]>
// <pattern[x]><!-- ?? 0..1 * Value must have at least these property values --></pattern[x]>
superset.setMaxLengthElement(unionMaxLength(left.current().getMaxLength(), right.current().getMaxLength()));
subset.setMaxLengthElement(intersectMaxLength(left.current().getMaxLength(), right.current().getMaxLength()));
if (left.current().hasBinding() || right.current().hasBinding()) {
compareBindings(outcome, subset, superset, path, left.current(), right.current());
}
// note these are backwards
superset.getConstraint().addAll(intersectConstraints(path, left.current().getConstraint(), right.current().getConstraint()));
subset.getConstraint().addAll(unionConstraints(subset, outcome, path, left.current().getConstraint(), right.current().getConstraint()));
// now process the slices
if (left.current().hasSlicing() || right.current().hasSlicing()) {
if (isExtension(left.path()))
return compareExtensions(outcome, path, superset, subset, left, right);
else
throw new DefinitionException("Slicing is not handled yet");
// todo: name
}
// add the children
outcome.subset.getSnapshot().getElement().add(subset);
outcome.superset.getSnapshot().getElement().add(superset);
return compareChildren(subset, outcome, path, left, right);
}
Aggregations