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