
001package org.hl7.fhir.r5.model; 002 003 004import java.util.List; 005 006import org.hl7.fhir.exceptions.FHIRException; 007/** 008 * Used for extensions of type 'named-elements' 009 */ 010 011public class NamedElementExtension extends Element { 012 013 private static final long serialVersionUID = -3624826962424387196L; 014 final private String elementName; 015 private StructureDefinition definition; // if known 016 private Base value; 017 018 019 /** 020 * Constructor 021 */ 022 public NamedElementExtension(String elementName) { 023 super(); 024 this.elementName =elementName; 025 } 026 027 /** 028 * Constructor 029 */ 030 public NamedElementExtension(String elementName, Base value) { 031 this.elementName = elementName; 032 setValue(value); 033 } 034 035 036 /** 037 * @return Element name 038 */ 039 public String getElementName() { 040 return this.elementName; 041 } 042 043 public boolean hasValue() { 044 return this.value != null && !this.value.isEmpty(); 045 } 046 047 /** 048 * @return {@link #value} (Value of extension) 049 */ 050 public Base getValue() { 051 return this.value; 052 } 053 054 public NamedElementExtension setValue(Base value) { 055 this.value = value; 056 return this; 057 } 058 059 protected void listChildren(List<Property> children) { 060 super.listChildren(children); 061 children.add(new Property("value[x]", "Base", "Value of extension", 0, 1, value)); 062 } 063 064 @Override 065 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 066 switch (_hash) { 067 case 111972721: /*value*/ return new Property("value", "Base", "Value of extension", 0, 1, value); 068 default: return super.getNamedProperty(_hash, _name, _checkValid); 069 } 070 } 071 072 @Override 073 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 074 switch (hash) { 075 case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // DataType 076 default: return super.getProperty(hash, name, checkValid); 077 } 078 } 079 080 @Override 081 public Base setProperty(int hash, String name, Base value) throws FHIRException { 082 switch (hash) { 083 case 111972721: // value 084 this.value = value; // DataType 085 return value; 086 default: return super.setProperty(hash, name, value); 087 } 088 089 } 090 091 @Override 092 public Base setProperty(String name, Base value) throws FHIRException { 093 if (name.equals("value[x]")) { 094 this.value = TypeConvertor.castToType(value); // DataType 095 } else 096 return super.setProperty(name, value); 097 return value; 098 } 099 100 @Override 101 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 102 switch (hash) { 103 case 111972721: /*value*/ return new String[] {"Base"}; 104 default: return super.getTypesForProperty(hash, name); 105 } 106 107 } 108 109 public String fhirType() { 110 return "NamedElementExtension"; 111 112 } 113 114 public NamedElementExtension copy() { 115 NamedElementExtension dst = new NamedElementExtension(elementName); 116 copyValues(dst); 117 return dst; 118 } 119 120 public void copyValues(NamedElementExtension dst) { 121 super.copyValues(dst); 122 dst.value = value == null ? null : value.copy(); 123 } 124 125 protected NamedElementExtension typedCopy() { 126 return copy(); 127 } 128 129 @Override 130 public boolean equalsDeep(Base other_) { 131 if (!super.equalsDeep(other_)) 132 return false; 133 if (!(other_ instanceof NamedElementExtension)) 134 return false; 135 NamedElementExtension o = (NamedElementExtension) other_; 136 return compareDeep(elementName, o.elementName, true) && compareDeep(value, o.value, true); 137 } 138 139 @Override 140 public boolean equalsShallow(Base other_) { 141 if (!super.equalsShallow(other_)) 142 return false; 143 if (!(other_ instanceof NamedElementExtension)) 144 return false; 145 NamedElementExtension o = (NamedElementExtension) other_; 146 return compareDeep(elementName, o.elementName, true); 147 } 148 149 public boolean isEmpty() { 150 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(value); 151 } 152 153 154} 155