001package org.hl7.fhir.r4.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Thu, Sep 13, 2018 09:04-0400 for FHIR v3.5.0
033
034import java.util.*;
035
036import java.math.*;
037import org.hl7.fhir.utilities.Utilities;
038import org.hl7.fhir.r4.model.Enumerations.*;
039import ca.uhn.fhir.model.api.annotation.Child;
040import ca.uhn.fhir.model.api.annotation.ChildOrder;
041import ca.uhn.fhir.model.api.annotation.Description;
042import ca.uhn.fhir.model.api.annotation.DatatypeDef;
043import ca.uhn.fhir.model.api.annotation.Block;
044import org.hl7.fhir.instance.model.api.*;
045import org.hl7.fhir.exceptions.FHIRException;
046/**
047 * An amount of economic utility in some recognized currency.
048 */
049@DatatypeDef(name="Money")
050public class Money extends Type implements ICompositeType {
051
052    /**
053     * Numerical value (with implicit precision).
054     */
055    @Child(name = "value", type = {DecimalType.class}, order=0, min=0, max=1, modifier=false, summary=true)
056    @Description(shortDefinition="Numerical value (with implicit precision)", formalDefinition="Numerical value (with implicit precision)." )
057    protected DecimalType value;
058
059    /**
060     * ISO 4217 Currency Code.
061     */
062    @Child(name = "currency", type = {CodeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
063    @Description(shortDefinition="ISO 4217 Currency Code", formalDefinition="ISO 4217 Currency Code." )
064    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/currencies")
065    protected CodeType currency;
066
067    private static final long serialVersionUID = -484637938L;
068
069  /**
070   * Constructor
071   */
072    public Money() {
073      super();
074    }
075
076    /**
077     * @return {@link #value} (Numerical value (with implicit precision).). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value
078     */
079    public DecimalType getValueElement() { 
080      if (this.value == null)
081        if (Configuration.errorOnAutoCreate())
082          throw new Error("Attempt to auto-create Money.value");
083        else if (Configuration.doAutoCreate())
084          this.value = new DecimalType(); // bb
085      return this.value;
086    }
087
088    public boolean hasValueElement() { 
089      return this.value != null && !this.value.isEmpty();
090    }
091
092    public boolean hasValue() { 
093      return this.value != null && !this.value.isEmpty();
094    }
095
096    /**
097     * @param value {@link #value} (Numerical value (with implicit precision).). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value
098     */
099    public Money setValueElement(DecimalType value) { 
100      this.value = value;
101      return this;
102    }
103
104    /**
105     * @return Numerical value (with implicit precision).
106     */
107    public BigDecimal getValue() { 
108      return this.value == null ? null : this.value.getValue();
109    }
110
111    /**
112     * @param value Numerical value (with implicit precision).
113     */
114    public Money setValue(BigDecimal value) { 
115      if (value == null)
116        this.value = null;
117      else {
118        if (this.value == null)
119          this.value = new DecimalType();
120        this.value.setValue(value);
121      }
122      return this;
123    }
124
125    /**
126     * @param value Numerical value (with implicit precision).
127     */
128    public Money setValue(long value) { 
129          this.value = new DecimalType();
130        this.value.setValue(value);
131      return this;
132    }
133
134    /**
135     * @param value Numerical value (with implicit precision).
136     */
137    public Money setValue(double value) { 
138          this.value = new DecimalType();
139        this.value.setValue(value);
140      return this;
141    }
142
143    /**
144     * @return {@link #currency} (ISO 4217 Currency Code.). This is the underlying object with id, value and extensions. The accessor "getCurrency" gives direct access to the value
145     */
146    public CodeType getCurrencyElement() { 
147      if (this.currency == null)
148        if (Configuration.errorOnAutoCreate())
149          throw new Error("Attempt to auto-create Money.currency");
150        else if (Configuration.doAutoCreate())
151          this.currency = new CodeType(); // bb
152      return this.currency;
153    }
154
155    public boolean hasCurrencyElement() { 
156      return this.currency != null && !this.currency.isEmpty();
157    }
158
159    public boolean hasCurrency() { 
160      return this.currency != null && !this.currency.isEmpty();
161    }
162
163    /**
164     * @param value {@link #currency} (ISO 4217 Currency Code.). This is the underlying object with id, value and extensions. The accessor "getCurrency" gives direct access to the value
165     */
166    public Money setCurrencyElement(CodeType value) { 
167      this.currency = value;
168      return this;
169    }
170
171    /**
172     * @return ISO 4217 Currency Code.
173     */
174    public String getCurrency() { 
175      return this.currency == null ? null : this.currency.getValue();
176    }
177
178    /**
179     * @param value ISO 4217 Currency Code.
180     */
181    public Money setCurrency(String value) { 
182      if (Utilities.noString(value))
183        this.currency = null;
184      else {
185        if (this.currency == null)
186          this.currency = new CodeType();
187        this.currency.setValue(value);
188      }
189      return this;
190    }
191
192      protected void listChildren(List<Property> children) {
193        super.listChildren(children);
194        children.add(new Property("value", "decimal", "Numerical value (with implicit precision).", 0, 1, value));
195        children.add(new Property("currency", "code", "ISO 4217 Currency Code.", 0, 1, currency));
196      }
197
198      @Override
199      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
200        switch (_hash) {
201        case 111972721: /*value*/  return new Property("value", "decimal", "Numerical value (with implicit precision).", 0, 1, value);
202        case 575402001: /*currency*/  return new Property("currency", "code", "ISO 4217 Currency Code.", 0, 1, currency);
203        default: return super.getNamedProperty(_hash, _name, _checkValid);
204        }
205
206      }
207
208      @Override
209      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
210        switch (hash) {
211        case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // DecimalType
212        case 575402001: /*currency*/ return this.currency == null ? new Base[0] : new Base[] {this.currency}; // CodeType
213        default: return super.getProperty(hash, name, checkValid);
214        }
215
216      }
217
218      @Override
219      public Base setProperty(int hash, String name, Base value) throws FHIRException {
220        switch (hash) {
221        case 111972721: // value
222          this.value = castToDecimal(value); // DecimalType
223          return value;
224        case 575402001: // currency
225          this.currency = castToCode(value); // CodeType
226          return value;
227        default: return super.setProperty(hash, name, value);
228        }
229
230      }
231
232      @Override
233      public Base setProperty(String name, Base value) throws FHIRException {
234        if (name.equals("value")) {
235          this.value = castToDecimal(value); // DecimalType
236        } else if (name.equals("currency")) {
237          this.currency = castToCode(value); // CodeType
238        } else
239          return super.setProperty(name, value);
240        return value;
241      }
242
243      @Override
244      public Base makeProperty(int hash, String name) throws FHIRException {
245        switch (hash) {
246        case 111972721:  return getValueElement();
247        case 575402001:  return getCurrencyElement();
248        default: return super.makeProperty(hash, name);
249        }
250
251      }
252
253      @Override
254      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
255        switch (hash) {
256        case 111972721: /*value*/ return new String[] {"decimal"};
257        case 575402001: /*currency*/ return new String[] {"code"};
258        default: return super.getTypesForProperty(hash, name);
259        }
260
261      }
262
263      @Override
264      public Base addChild(String name) throws FHIRException {
265        if (name.equals("value")) {
266          throw new FHIRException("Cannot call addChild on a primitive type Money.value");
267        }
268        else if (name.equals("currency")) {
269          throw new FHIRException("Cannot call addChild on a primitive type Money.currency");
270        }
271        else
272          return super.addChild(name);
273      }
274
275  public String fhirType() {
276    return "Money";
277
278  }
279
280      public Money copy() {
281        Money dst = new Money();
282        copyValues(dst);
283        dst.value = value == null ? null : value.copy();
284        dst.currency = currency == null ? null : currency.copy();
285        return dst;
286      }
287
288      protected Money typedCopy() {
289        return copy();
290      }
291
292      @Override
293      public boolean equalsDeep(Base other_) {
294        if (!super.equalsDeep(other_))
295          return false;
296        if (!(other_ instanceof Money))
297          return false;
298        Money o = (Money) other_;
299        return compareDeep(value, o.value, true) && compareDeep(currency, o.currency, true);
300      }
301
302      @Override
303      public boolean equalsShallow(Base other_) {
304        if (!super.equalsShallow(other_))
305          return false;
306        if (!(other_ instanceof Money))
307          return false;
308        Money o = (Money) other_;
309        return compareValues(value, o.value, true) && compareValues(currency, o.currency, true);
310      }
311
312      public boolean isEmpty() {
313        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(value, currency);
314      }
315
316
317}
318