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