001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import org.hl7.fhir.utilities.Utilities;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.ChildOrder;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Block;
045import org.hl7.fhir.instance.model.api.*;
046import org.hl7.fhir.exceptions.FHIRException;
047/**
048 * A contributor to the content of a knowledge asset, including authors, editors, reviewers, and endorsers.
049 */
050@DatatypeDef(name="Contributor")
051public class Contributor extends Type implements ICompositeType {
052
053    public enum ContributorType {
054        /**
055         * An author of the content of the module.
056         */
057        AUTHOR, 
058        /**
059         * An editor of the content of the module.
060         */
061        EDITOR, 
062        /**
063         * A reviewer of the content of the module.
064         */
065        REVIEWER, 
066        /**
067         * An endorser of the content of the module.
068         */
069        ENDORSER, 
070        /**
071         * added to help the parsers with the generic types
072         */
073        NULL;
074        public static ContributorType fromCode(String codeString) throws FHIRException {
075            if (codeString == null || "".equals(codeString))
076                return null;
077        if ("author".equals(codeString))
078          return AUTHOR;
079        if ("editor".equals(codeString))
080          return EDITOR;
081        if ("reviewer".equals(codeString))
082          return REVIEWER;
083        if ("endorser".equals(codeString))
084          return ENDORSER;
085        if (Configuration.isAcceptInvalidEnums())
086          return null;
087        else
088          throw new FHIRException("Unknown ContributorType code '"+codeString+"'");
089        }
090        public String toCode() {
091          switch (this) {
092            case AUTHOR: return "author";
093            case EDITOR: return "editor";
094            case REVIEWER: return "reviewer";
095            case ENDORSER: return "endorser";
096            case NULL: return null;
097            default: return "?";
098          }
099        }
100        public String getSystem() {
101          switch (this) {
102            case AUTHOR: return "http://hl7.org/fhir/contributor-type";
103            case EDITOR: return "http://hl7.org/fhir/contributor-type";
104            case REVIEWER: return "http://hl7.org/fhir/contributor-type";
105            case ENDORSER: return "http://hl7.org/fhir/contributor-type";
106            case NULL: return null;
107            default: return "?";
108          }
109        }
110        public String getDefinition() {
111          switch (this) {
112            case AUTHOR: return "An author of the content of the module.";
113            case EDITOR: return "An editor of the content of the module.";
114            case REVIEWER: return "A reviewer of the content of the module.";
115            case ENDORSER: return "An endorser of the content of the module.";
116            case NULL: return null;
117            default: return "?";
118          }
119        }
120        public String getDisplay() {
121          switch (this) {
122            case AUTHOR: return "Author";
123            case EDITOR: return "Editor";
124            case REVIEWER: return "Reviewer";
125            case ENDORSER: return "Endorser";
126            case NULL: return null;
127            default: return "?";
128          }
129        }
130    }
131
132  public static class ContributorTypeEnumFactory implements EnumFactory<ContributorType> {
133    public ContributorType fromCode(String codeString) throws IllegalArgumentException {
134      if (codeString == null || "".equals(codeString))
135            if (codeString == null || "".equals(codeString))
136                return null;
137        if ("author".equals(codeString))
138          return ContributorType.AUTHOR;
139        if ("editor".equals(codeString))
140          return ContributorType.EDITOR;
141        if ("reviewer".equals(codeString))
142          return ContributorType.REVIEWER;
143        if ("endorser".equals(codeString))
144          return ContributorType.ENDORSER;
145        throw new IllegalArgumentException("Unknown ContributorType code '"+codeString+"'");
146        }
147        public Enumeration<ContributorType> fromType(Base code) throws FHIRException {
148          if (code == null)
149            return null;
150          if (code.isEmpty())
151            return new Enumeration<ContributorType>(this);
152          String codeString = ((PrimitiveType) code).asStringValue();
153          if (codeString == null || "".equals(codeString))
154            return null;
155        if ("author".equals(codeString))
156          return new Enumeration<ContributorType>(this, ContributorType.AUTHOR);
157        if ("editor".equals(codeString))
158          return new Enumeration<ContributorType>(this, ContributorType.EDITOR);
159        if ("reviewer".equals(codeString))
160          return new Enumeration<ContributorType>(this, ContributorType.REVIEWER);
161        if ("endorser".equals(codeString))
162          return new Enumeration<ContributorType>(this, ContributorType.ENDORSER);
163        throw new FHIRException("Unknown ContributorType code '"+codeString+"'");
164        }
165    public String toCode(ContributorType code) {
166      if (code == ContributorType.AUTHOR)
167        return "author";
168      if (code == ContributorType.EDITOR)
169        return "editor";
170      if (code == ContributorType.REVIEWER)
171        return "reviewer";
172      if (code == ContributorType.ENDORSER)
173        return "endorser";
174      return "?";
175      }
176    public String toSystem(ContributorType code) {
177      return code.getSystem();
178      }
179    }
180
181    /**
182     * The type of contributor.
183     */
184    @Child(name = "type", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
185    @Description(shortDefinition="author | editor | reviewer | endorser", formalDefinition="The type of contributor." )
186    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/contributor-type")
187    protected Enumeration<ContributorType> type;
188
189    /**
190     * The name of the individual or organization responsible for the contribution.
191     */
192    @Child(name = "name", type = {StringType.class}, order=1, min=1, max=1, modifier=false, summary=true)
193    @Description(shortDefinition="Who contributed the content", formalDefinition="The name of the individual or organization responsible for the contribution." )
194    protected StringType name;
195
196    /**
197     * Contact details to assist a user in finding and communicating with the contributor.
198     */
199    @Child(name = "contact", type = {ContactDetail.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
200    @Description(shortDefinition="Contact details of the contributor", formalDefinition="Contact details to assist a user in finding and communicating with the contributor." )
201    protected List<ContactDetail> contact;
202
203    private static final long serialVersionUID = -609887113L;
204
205  /**
206   * Constructor
207   */
208    public Contributor() {
209      super();
210    }
211
212  /**
213   * Constructor
214   */
215    public Contributor(Enumeration<ContributorType> type, StringType name) {
216      super();
217      this.type = type;
218      this.name = name;
219    }
220
221    /**
222     * @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
223     */
224    public Enumeration<ContributorType> getTypeElement() { 
225      if (this.type == null)
226        if (Configuration.errorOnAutoCreate())
227          throw new Error("Attempt to auto-create Contributor.type");
228        else if (Configuration.doAutoCreate())
229          this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory()); // bb
230      return this.type;
231    }
232
233    public boolean hasTypeElement() { 
234      return this.type != null && !this.type.isEmpty();
235    }
236
237    public boolean hasType() { 
238      return this.type != null && !this.type.isEmpty();
239    }
240
241    /**
242     * @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
243     */
244    public Contributor setTypeElement(Enumeration<ContributorType> value) { 
245      this.type = value;
246      return this;
247    }
248
249    /**
250     * @return The type of contributor.
251     */
252    public ContributorType getType() { 
253      return this.type == null ? null : this.type.getValue();
254    }
255
256    /**
257     * @param value The type of contributor.
258     */
259    public Contributor setType(ContributorType value) { 
260        if (this.type == null)
261          this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory());
262        this.type.setValue(value);
263      return this;
264    }
265
266    /**
267     * @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
268     */
269    public StringType getNameElement() { 
270      if (this.name == null)
271        if (Configuration.errorOnAutoCreate())
272          throw new Error("Attempt to auto-create Contributor.name");
273        else if (Configuration.doAutoCreate())
274          this.name = new StringType(); // bb
275      return this.name;
276    }
277
278    public boolean hasNameElement() { 
279      return this.name != null && !this.name.isEmpty();
280    }
281
282    public boolean hasName() { 
283      return this.name != null && !this.name.isEmpty();
284    }
285
286    /**
287     * @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
288     */
289    public Contributor setNameElement(StringType value) { 
290      this.name = value;
291      return this;
292    }
293
294    /**
295     * @return The name of the individual or organization responsible for the contribution.
296     */
297    public String getName() { 
298      return this.name == null ? null : this.name.getValue();
299    }
300
301    /**
302     * @param value The name of the individual or organization responsible for the contribution.
303     */
304    public Contributor setName(String value) { 
305        if (this.name == null)
306          this.name = new StringType();
307        this.name.setValue(value);
308      return this;
309    }
310
311    /**
312     * @return {@link #contact} (Contact details to assist a user in finding and communicating with the contributor.)
313     */
314    public List<ContactDetail> getContact() { 
315      if (this.contact == null)
316        this.contact = new ArrayList<ContactDetail>();
317      return this.contact;
318    }
319
320    /**
321     * @return Returns a reference to <code>this</code> for easy method chaining
322     */
323    public Contributor setContact(List<ContactDetail> theContact) { 
324      this.contact = theContact;
325      return this;
326    }
327
328    public boolean hasContact() { 
329      if (this.contact == null)
330        return false;
331      for (ContactDetail item : this.contact)
332        if (!item.isEmpty())
333          return true;
334      return false;
335    }
336
337    public ContactDetail addContact() { //3
338      ContactDetail t = new ContactDetail();
339      if (this.contact == null)
340        this.contact = new ArrayList<ContactDetail>();
341      this.contact.add(t);
342      return t;
343    }
344
345    public Contributor addContact(ContactDetail t) { //3
346      if (t == null)
347        return this;
348      if (this.contact == null)
349        this.contact = new ArrayList<ContactDetail>();
350      this.contact.add(t);
351      return this;
352    }
353
354    /**
355     * @return The first repetition of repeating field {@link #contact}, creating it if it does not already exist
356     */
357    public ContactDetail getContactFirstRep() { 
358      if (getContact().isEmpty()) {
359        addContact();
360      }
361      return getContact().get(0);
362    }
363
364      protected void listChildren(List<Property> children) {
365        super.listChildren(children);
366        children.add(new Property("type", "code", "The type of contributor.", 0, 1, type));
367        children.add(new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, 1, name));
368        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));
369      }
370
371      @Override
372      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
373        switch (_hash) {
374        case 3575610: /*type*/  return new Property("type", "code", "The type of contributor.", 0, 1, type);
375        case 3373707: /*name*/  return new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, 1, name);
376        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);
377        default: return super.getNamedProperty(_hash, _name, _checkValid);
378        }
379
380      }
381
382      @Override
383      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
384        switch (hash) {
385        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<ContributorType>
386        case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType
387        case 951526432: /*contact*/ return this.contact == null ? new Base[0] : this.contact.toArray(new Base[this.contact.size()]); // ContactDetail
388        default: return super.getProperty(hash, name, checkValid);
389        }
390
391      }
392
393      @Override
394      public Base setProperty(int hash, String name, Base value) throws FHIRException {
395        switch (hash) {
396        case 3575610: // type
397          value = new ContributorTypeEnumFactory().fromType(castToCode(value));
398          this.type = (Enumeration) value; // Enumeration<ContributorType>
399          return value;
400        case 3373707: // name
401          this.name = castToString(value); // StringType
402          return value;
403        case 951526432: // contact
404          this.getContact().add(castToContactDetail(value)); // ContactDetail
405          return value;
406        default: return super.setProperty(hash, name, value);
407        }
408
409      }
410
411      @Override
412      public Base setProperty(String name, Base value) throws FHIRException {
413        if (name.equals("type")) {
414          value = new ContributorTypeEnumFactory().fromType(castToCode(value));
415          this.type = (Enumeration) value; // Enumeration<ContributorType>
416        } else if (name.equals("name")) {
417          this.name = castToString(value); // StringType
418        } else if (name.equals("contact")) {
419          this.getContact().add(castToContactDetail(value));
420        } else
421          return super.setProperty(name, value);
422        return value;
423      }
424
425      @Override
426      public Base makeProperty(int hash, String name) throws FHIRException {
427        switch (hash) {
428        case 3575610:  return getTypeElement();
429        case 3373707:  return getNameElement();
430        case 951526432:  return addContact(); 
431        default: return super.makeProperty(hash, name);
432        }
433
434      }
435
436      @Override
437      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
438        switch (hash) {
439        case 3575610: /*type*/ return new String[] {"code"};
440        case 3373707: /*name*/ return new String[] {"string"};
441        case 951526432: /*contact*/ return new String[] {"ContactDetail"};
442        default: return super.getTypesForProperty(hash, name);
443        }
444
445      }
446
447      @Override
448      public Base addChild(String name) throws FHIRException {
449        if (name.equals("type")) {
450          throw new FHIRException("Cannot call addChild on a primitive type Contributor.type");
451        }
452        else if (name.equals("name")) {
453          throw new FHIRException("Cannot call addChild on a primitive type Contributor.name");
454        }
455        else if (name.equals("contact")) {
456          return addContact();
457        }
458        else
459          return super.addChild(name);
460      }
461
462  public String fhirType() {
463    return "Contributor";
464
465  }
466
467      public Contributor copy() {
468        Contributor dst = new Contributor();
469        copyValues(dst);
470        return dst;
471      }
472
473      public void copyValues(Contributor dst) {
474        super.copyValues(dst);
475        dst.type = type == null ? null : type.copy();
476        dst.name = name == null ? null : name.copy();
477        if (contact != null) {
478          dst.contact = new ArrayList<ContactDetail>();
479          for (ContactDetail i : contact)
480            dst.contact.add(i.copy());
481        };
482      }
483
484      protected Contributor typedCopy() {
485        return copy();
486      }
487
488      @Override
489      public boolean equalsDeep(Base other_) {
490        if (!super.equalsDeep(other_))
491          return false;
492        if (!(other_ instanceof Contributor))
493          return false;
494        Contributor o = (Contributor) other_;
495        return compareDeep(type, o.type, true) && compareDeep(name, o.name, true) && compareDeep(contact, o.contact, true)
496          ;
497      }
498
499      @Override
500      public boolean equalsShallow(Base other_) {
501        if (!super.equalsShallow(other_))
502          return false;
503        if (!(other_ instanceof Contributor))
504          return false;
505        Contributor o = (Contributor) other_;
506        return compareValues(type, o.type, true) && compareValues(name, o.name, true);
507      }
508
509      public boolean isEmpty() {
510        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, name, contact);
511      }
512
513
514}