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