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