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