001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * A contributor to the content of a knowledge asset, including authors, editors, reviewers, and endorsers.
046 */
047@DatatypeDef(name="Contributor")
048public class Contributor extends Type implements ICompositeType {
049
050    public enum ContributorType {
051        /**
052         * An author of the content of the module
053         */
054        AUTHOR, 
055        /**
056         * An editor of the content of the module
057         */
058        EDITOR, 
059        /**
060         * A reviewer of the content of the module
061         */
062        REVIEWER, 
063        /**
064         * An endorser of the content of the module
065         */
066        ENDORSER, 
067        /**
068         * added to help the parsers with the generic types
069         */
070        NULL;
071        public static ContributorType fromCode(String codeString) throws FHIRException {
072            if (codeString == null || "".equals(codeString))
073                return null;
074        if ("author".equals(codeString))
075          return AUTHOR;
076        if ("editor".equals(codeString))
077          return EDITOR;
078        if ("reviewer".equals(codeString))
079          return REVIEWER;
080        if ("endorser".equals(codeString))
081          return ENDORSER;
082        if (Configuration.isAcceptInvalidEnums())
083          return null;
084        else
085          throw new FHIRException("Unknown ContributorType code '"+codeString+"'");
086        }
087        public String toCode() {
088          switch (this) {
089            case AUTHOR: return "author";
090            case EDITOR: return "editor";
091            case REVIEWER: return "reviewer";
092            case ENDORSER: return "endorser";
093            default: return "?";
094          }
095        }
096        public String getSystem() {
097          switch (this) {
098            case AUTHOR: return "http://hl7.org/fhir/contributor-type";
099            case EDITOR: return "http://hl7.org/fhir/contributor-type";
100            case REVIEWER: return "http://hl7.org/fhir/contributor-type";
101            case ENDORSER: return "http://hl7.org/fhir/contributor-type";
102            default: return "?";
103          }
104        }
105        public String getDefinition() {
106          switch (this) {
107            case AUTHOR: return "An author of the content of the module";
108            case EDITOR: return "An editor of the content of the module";
109            case REVIEWER: return "A reviewer of the content of the module";
110            case ENDORSER: return "An endorser of the content of the module";
111            default: return "?";
112          }
113        }
114        public String getDisplay() {
115          switch (this) {
116            case AUTHOR: return "Author";
117            case EDITOR: return "Editor";
118            case REVIEWER: return "Reviewer";
119            case ENDORSER: return "Endorser";
120            default: return "?";
121          }
122        }
123    }
124
125  public static class ContributorTypeEnumFactory implements EnumFactory<ContributorType> {
126    public ContributorType fromCode(String codeString) throws IllegalArgumentException {
127      if (codeString == null || "".equals(codeString))
128            if (codeString == null || "".equals(codeString))
129                return null;
130        if ("author".equals(codeString))
131          return ContributorType.AUTHOR;
132        if ("editor".equals(codeString))
133          return ContributorType.EDITOR;
134        if ("reviewer".equals(codeString))
135          return ContributorType.REVIEWER;
136        if ("endorser".equals(codeString))
137          return ContributorType.ENDORSER;
138        throw new IllegalArgumentException("Unknown ContributorType code '"+codeString+"'");
139        }
140        public Enumeration<ContributorType> fromType(Base code) throws FHIRException {
141          if (code == null)
142            return null;
143          if (code.isEmpty())
144            return new Enumeration<ContributorType>(this);
145          String codeString = ((PrimitiveType) code).asStringValue();
146          if (codeString == null || "".equals(codeString))
147            return null;
148        if ("author".equals(codeString))
149          return new Enumeration<ContributorType>(this, ContributorType.AUTHOR);
150        if ("editor".equals(codeString))
151          return new Enumeration<ContributorType>(this, ContributorType.EDITOR);
152        if ("reviewer".equals(codeString))
153          return new Enumeration<ContributorType>(this, ContributorType.REVIEWER);
154        if ("endorser".equals(codeString))
155          return new Enumeration<ContributorType>(this, ContributorType.ENDORSER);
156        throw new FHIRException("Unknown ContributorType code '"+codeString+"'");
157        }
158    public String toCode(ContributorType code) {
159      if (code == ContributorType.AUTHOR)
160        return "author";
161      if (code == ContributorType.EDITOR)
162        return "editor";
163      if (code == ContributorType.REVIEWER)
164        return "reviewer";
165      if (code == ContributorType.ENDORSER)
166        return "endorser";
167      return "?";
168      }
169    public String toSystem(ContributorType code) {
170      return code.getSystem();
171      }
172    }
173
174    /**
175     * The type of contributor.
176     */
177    @Child(name = "type", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
178    @Description(shortDefinition="author | editor | reviewer | endorser", formalDefinition="The type of contributor." )
179    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/contributor-type")
180    protected Enumeration<ContributorType> type;
181
182    /**
183     * The name of the individual or organization responsible for the contribution.
184     */
185    @Child(name = "name", type = {StringType.class}, order=1, min=1, max=1, modifier=false, summary=true)
186    @Description(shortDefinition="Who contributed the content", formalDefinition="The name of the individual or organization responsible for the contribution." )
187    protected StringType name;
188
189    /**
190     * Contact details to assist a user in finding and communicating with the contributor.
191     */
192    @Child(name = "contact", type = {ContactDetail.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
193    @Description(shortDefinition="Contact details of the contributor", formalDefinition="Contact details to assist a user in finding and communicating with the contributor." )
194    protected List<ContactDetail> contact;
195
196    private static final long serialVersionUID = -609887113L;
197
198  /**
199   * Constructor
200   */
201    public Contributor() {
202      super();
203    }
204
205  /**
206   * Constructor
207   */
208    public Contributor(Enumeration<ContributorType> type, StringType name) {
209      super();
210      this.type = type;
211      this.name = name;
212    }
213
214    /**
215     * @return {@link #type} (The type of contributor.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
216     */
217    public Enumeration<ContributorType> getTypeElement() { 
218      if (this.type == null)
219        if (Configuration.errorOnAutoCreate())
220          throw new Error("Attempt to auto-create Contributor.type");
221        else if (Configuration.doAutoCreate())
222          this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory()); // bb
223      return this.type;
224    }
225
226    public boolean hasTypeElement() { 
227      return this.type != null && !this.type.isEmpty();
228    }
229
230    public boolean hasType() { 
231      return this.type != null && !this.type.isEmpty();
232    }
233
234    /**
235     * @param value {@link #type} (The type of contributor.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
236     */
237    public Contributor setTypeElement(Enumeration<ContributorType> value) { 
238      this.type = value;
239      return this;
240    }
241
242    /**
243     * @return The type of contributor.
244     */
245    public ContributorType getType() { 
246      return this.type == null ? null : this.type.getValue();
247    }
248
249    /**
250     * @param value The type of contributor.
251     */
252    public Contributor setType(ContributorType value) { 
253        if (this.type == null)
254          this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory());
255        this.type.setValue(value);
256      return this;
257    }
258
259    /**
260     * @return {@link #name} (The name of the individual or organization responsible for the contribution.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value
261     */
262    public StringType getNameElement() { 
263      if (this.name == null)
264        if (Configuration.errorOnAutoCreate())
265          throw new Error("Attempt to auto-create Contributor.name");
266        else if (Configuration.doAutoCreate())
267          this.name = new StringType(); // bb
268      return this.name;
269    }
270
271    public boolean hasNameElement() { 
272      return this.name != null && !this.name.isEmpty();
273    }
274
275    public boolean hasName() { 
276      return this.name != null && !this.name.isEmpty();
277    }
278
279    /**
280     * @param value {@link #name} (The name of the individual or organization responsible for the contribution.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value
281     */
282    public Contributor setNameElement(StringType value) { 
283      this.name = value;
284      return this;
285    }
286
287    /**
288     * @return The name of the individual or organization responsible for the contribution.
289     */
290    public String getName() { 
291      return this.name == null ? null : this.name.getValue();
292    }
293
294    /**
295     * @param value The name of the individual or organization responsible for the contribution.
296     */
297    public Contributor setName(String value) { 
298        if (this.name == null)
299          this.name = new StringType();
300        this.name.setValue(value);
301      return this;
302    }
303
304    /**
305     * @return {@link #contact} (Contact details to assist a user in finding and communicating with the contributor.)
306     */
307    public List<ContactDetail> getContact() { 
308      if (this.contact == null)
309        this.contact = new ArrayList<ContactDetail>();
310      return this.contact;
311    }
312
313    /**
314     * @return Returns a reference to <code>this</code> for easy method chaining
315     */
316    public Contributor setContact(List<ContactDetail> theContact) { 
317      this.contact = theContact;
318      return this;
319    }
320
321    public boolean hasContact() { 
322      if (this.contact == null)
323        return false;
324      for (ContactDetail item : this.contact)
325        if (!item.isEmpty())
326          return true;
327      return false;
328    }
329
330    public ContactDetail addContact() { //3
331      ContactDetail t = new ContactDetail();
332      if (this.contact == null)
333        this.contact = new ArrayList<ContactDetail>();
334      this.contact.add(t);
335      return t;
336    }
337
338    public Contributor addContact(ContactDetail t) { //3
339      if (t == null)
340        return this;
341      if (this.contact == null)
342        this.contact = new ArrayList<ContactDetail>();
343      this.contact.add(t);
344      return this;
345    }
346
347    /**
348     * @return The first repetition of repeating field {@link #contact}, creating it if it does not already exist
349     */
350    public ContactDetail getContactFirstRep() { 
351      if (getContact().isEmpty()) {
352        addContact();
353      }
354      return getContact().get(0);
355    }
356
357      protected void listChildren(List<Property> childrenList) {
358        super.listChildren(childrenList);
359        childrenList.add(new Property("type", "code", "The type of contributor.", 0, java.lang.Integer.MAX_VALUE, type));
360        childrenList.add(new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, java.lang.Integer.MAX_VALUE, name));
361        childrenList.add(new Property("contact", "ContactDetail", "Contact details to assist a user in finding and communicating with the contributor.", 0, java.lang.Integer.MAX_VALUE, contact));
362      }
363
364      @Override
365      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
366        switch (hash) {
367        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<ContributorType>
368        case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType
369        case 951526432: /*contact*/ return this.contact == null ? new Base[0] : this.contact.toArray(new Base[this.contact.size()]); // ContactDetail
370        default: return super.getProperty(hash, name, checkValid);
371        }
372
373      }
374
375      @Override
376      public Base setProperty(int hash, String name, Base value) throws FHIRException {
377        switch (hash) {
378        case 3575610: // type
379          value = new ContributorTypeEnumFactory().fromType(castToCode(value));
380          this.type = (Enumeration) value; // Enumeration<ContributorType>
381          return value;
382        case 3373707: // name
383          this.name = castToString(value); // StringType
384          return value;
385        case 951526432: // contact
386          this.getContact().add(castToContactDetail(value)); // ContactDetail
387          return value;
388        default: return super.setProperty(hash, name, value);
389        }
390
391      }
392
393      @Override
394      public Base setProperty(String name, Base value) throws FHIRException {
395        if (name.equals("type")) {
396          value = new ContributorTypeEnumFactory().fromType(castToCode(value));
397          this.type = (Enumeration) value; // Enumeration<ContributorType>
398        } else if (name.equals("name")) {
399          this.name = castToString(value); // StringType
400        } else if (name.equals("contact")) {
401          this.getContact().add(castToContactDetail(value));
402        } else
403          return super.setProperty(name, value);
404        return value;
405      }
406
407      @Override
408      public Base makeProperty(int hash, String name) throws FHIRException {
409        switch (hash) {
410        case 3575610:  return getTypeElement();
411        case 3373707:  return getNameElement();
412        case 951526432:  return addContact(); 
413        default: return super.makeProperty(hash, name);
414        }
415
416      }
417
418      @Override
419      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
420        switch (hash) {
421        case 3575610: /*type*/ return new String[] {"code"};
422        case 3373707: /*name*/ return new String[] {"string"};
423        case 951526432: /*contact*/ return new String[] {"ContactDetail"};
424        default: return super.getTypesForProperty(hash, name);
425        }
426
427      }
428
429      @Override
430      public Base addChild(String name) throws FHIRException {
431        if (name.equals("type")) {
432          throw new FHIRException("Cannot call addChild on a primitive type Contributor.type");
433        }
434        else if (name.equals("name")) {
435          throw new FHIRException("Cannot call addChild on a primitive type Contributor.name");
436        }
437        else if (name.equals("contact")) {
438          return addContact();
439        }
440        else
441          return super.addChild(name);
442      }
443
444  public String fhirType() {
445    return "Contributor";
446
447  }
448
449      public Contributor copy() {
450        Contributor dst = new Contributor();
451        copyValues(dst);
452        dst.type = type == null ? null : type.copy();
453        dst.name = name == null ? null : name.copy();
454        if (contact != null) {
455          dst.contact = new ArrayList<ContactDetail>();
456          for (ContactDetail i : contact)
457            dst.contact.add(i.copy());
458        };
459        return dst;
460      }
461
462      protected Contributor typedCopy() {
463        return copy();
464      }
465
466      @Override
467      public boolean equalsDeep(Base other) {
468        if (!super.equalsDeep(other))
469          return false;
470        if (!(other instanceof Contributor))
471          return false;
472        Contributor o = (Contributor) other;
473        return compareDeep(type, o.type, true) && compareDeep(name, o.name, true) && compareDeep(contact, o.contact, true)
474          ;
475      }
476
477      @Override
478      public boolean equalsShallow(Base other) {
479        if (!super.equalsShallow(other))
480          return false;
481        if (!(other instanceof Contributor))
482          return false;
483        Contributor o = (Contributor) other;
484        return compareValues(type, o.type, true) && compareValues(name, o.name, true);
485      }
486
487      public boolean isEmpty() {
488        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, name, contact);
489      }
490
491
492}
493