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 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> children) {
358        super.listChildren(children);
359        children.add(new Property("type", "code", "The type of contributor.", 0, 1, type));
360        children.add(new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, 1, name));
361        children.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 Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
366        switch (_hash) {
367        case 3575610: /*type*/  return new Property("type", "code", "The type of contributor.", 0, 1, type);
368        case 3373707: /*name*/  return new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, 1, name);
369        case 951526432: /*contact*/  return new Property("contact", "ContactDetail", "Contact details to assist a user in finding and communicating with the contributor.", 0, java.lang.Integer.MAX_VALUE, contact);
370        default: return super.getNamedProperty(_hash, _name, _checkValid);
371        }
372
373      }
374
375      @Override
376      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
377        switch (hash) {
378        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<ContributorType>
379        case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType
380        case 951526432: /*contact*/ return this.contact == null ? new Base[0] : this.contact.toArray(new Base[this.contact.size()]); // ContactDetail
381        default: return super.getProperty(hash, name, checkValid);
382        }
383
384      }
385
386      @Override
387      public Base setProperty(int hash, String name, Base value) throws FHIRException {
388        switch (hash) {
389        case 3575610: // type
390          value = new ContributorTypeEnumFactory().fromType(castToCode(value));
391          this.type = (Enumeration) value; // Enumeration<ContributorType>
392          return value;
393        case 3373707: // name
394          this.name = castToString(value); // StringType
395          return value;
396        case 951526432: // contact
397          this.getContact().add(castToContactDetail(value)); // ContactDetail
398          return value;
399        default: return super.setProperty(hash, name, value);
400        }
401
402      }
403
404      @Override
405      public Base setProperty(String name, Base value) throws FHIRException {
406        if (name.equals("type")) {
407          value = new ContributorTypeEnumFactory().fromType(castToCode(value));
408          this.type = (Enumeration) value; // Enumeration<ContributorType>
409        } else if (name.equals("name")) {
410          this.name = castToString(value); // StringType
411        } else if (name.equals("contact")) {
412          this.getContact().add(castToContactDetail(value));
413        } else
414          return super.setProperty(name, value);
415        return value;
416      }
417
418      @Override
419      public Base makeProperty(int hash, String name) throws FHIRException {
420        switch (hash) {
421        case 3575610:  return getTypeElement();
422        case 3373707:  return getNameElement();
423        case 951526432:  return addContact(); 
424        default: return super.makeProperty(hash, name);
425        }
426
427      }
428
429      @Override
430      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
431        switch (hash) {
432        case 3575610: /*type*/ return new String[] {"code"};
433        case 3373707: /*name*/ return new String[] {"string"};
434        case 951526432: /*contact*/ return new String[] {"ContactDetail"};
435        default: return super.getTypesForProperty(hash, name);
436        }
437
438      }
439
440      @Override
441      public Base addChild(String name) throws FHIRException {
442        if (name.equals("type")) {
443          throw new FHIRException("Cannot call addChild on a primitive type Contributor.type");
444        }
445        else if (name.equals("name")) {
446          throw new FHIRException("Cannot call addChild on a primitive type Contributor.name");
447        }
448        else if (name.equals("contact")) {
449          return addContact();
450        }
451        else
452          return super.addChild(name);
453      }
454
455  public String fhirType() {
456    return "Contributor";
457
458  }
459
460      public Contributor copy() {
461        Contributor dst = new Contributor();
462        copyValues(dst);
463        dst.type = type == null ? null : type.copy();
464        dst.name = name == null ? null : name.copy();
465        if (contact != null) {
466          dst.contact = new ArrayList<ContactDetail>();
467          for (ContactDetail i : contact)
468            dst.contact.add(i.copy());
469        };
470        return dst;
471      }
472
473      protected Contributor typedCopy() {
474        return copy();
475      }
476
477      @Override
478      public boolean equalsDeep(Base other_) {
479        if (!super.equalsDeep(other_))
480          return false;
481        if (!(other_ instanceof Contributor))
482          return false;
483        Contributor o = (Contributor) other_;
484        return compareDeep(type, o.type, true) && compareDeep(name, o.name, true) && compareDeep(contact, o.contact, true)
485          ;
486      }
487
488      @Override
489      public boolean equalsShallow(Base other_) {
490        if (!super.equalsShallow(other_))
491          return false;
492        if (!(other_ instanceof Contributor))
493          return false;
494        Contributor o = (Contributor) other_;
495        return compareValues(type, o.type, true) && compareValues(name, o.name, true);
496      }
497
498      public boolean isEmpty() {
499        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, name, contact);
500      }
501
502
503}
504