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