001package org.hl7.fhir.dstu2.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.List;
034
035import ca.uhn.fhir.model.api.annotation.Child;
036import ca.uhn.fhir.model.api.annotation.DatatypeDef;
037import ca.uhn.fhir.model.api.annotation.Description;
038import org.hl7.fhir.instance.model.api.ICompositeType;
039import org.hl7.fhir.exceptions.FHIRException;
040import org.hl7.fhir.utilities.Utilities;
041
042/**
043 * A technical identifier - identifies some entity uniquely and unambiguously.
044 */
045@DatatypeDef(name = "Identifier")
046public class Identifier extends Type implements ICompositeType {
047
048  public enum IdentifierUse {
049    /**
050     * The identifier recommended for display and use in real-world interactions.
051     */
052    USUAL,
053    /**
054     * The identifier considered to be most trusted for the identification of this
055     * item.
056     */
057    OFFICIAL,
058    /**
059     * A temporary identifier.
060     */
061    TEMP,
062    /**
063     * An identifier that was assigned in secondary use - it serves to identify the
064     * object in a relative context, but cannot be consistently assigned to the same
065     * object again in a different context.
066     */
067    SECONDARY,
068    /**
069     * added to help the parsers
070     */
071    NULL;
072
073    public static IdentifierUse fromCode(String codeString) throws FHIRException {
074      if (codeString == null || "".equals(codeString))
075        return null;
076      if ("usual".equals(codeString))
077        return USUAL;
078      if ("official".equals(codeString))
079        return OFFICIAL;
080      if ("temp".equals(codeString))
081        return TEMP;
082      if ("secondary".equals(codeString))
083        return SECONDARY;
084      throw new FHIRException("Unknown IdentifierUse code '" + codeString + "'");
085    }
086
087    public String toCode() {
088      switch (this) {
089      case USUAL:
090        return "usual";
091      case OFFICIAL:
092        return "official";
093      case TEMP:
094        return "temp";
095      case SECONDARY:
096        return "secondary";
097      case NULL:
098        return null;
099      default:
100        return "?";
101      }
102    }
103
104    public String getSystem() {
105      switch (this) {
106      case USUAL:
107        return "http://hl7.org/fhir/identifier-use";
108      case OFFICIAL:
109        return "http://hl7.org/fhir/identifier-use";
110      case TEMP:
111        return "http://hl7.org/fhir/identifier-use";
112      case SECONDARY:
113        return "http://hl7.org/fhir/identifier-use";
114      case NULL:
115        return null;
116      default:
117        return "?";
118      }
119    }
120
121    public String getDefinition() {
122      switch (this) {
123      case USUAL:
124        return "The identifier recommended for display and use in real-world interactions.";
125      case OFFICIAL:
126        return "The identifier considered to be most trusted for the identification of this item.";
127      case TEMP:
128        return "A temporary identifier.";
129      case SECONDARY:
130        return "An identifier that was assigned in secondary use - it serves to identify the object in a relative context, but cannot be consistently assigned to the same object again in a different context.";
131      case NULL:
132        return null;
133      default:
134        return "?";
135      }
136    }
137
138    public String getDisplay() {
139      switch (this) {
140      case USUAL:
141        return "Usual";
142      case OFFICIAL:
143        return "Official";
144      case TEMP:
145        return "Temp";
146      case SECONDARY:
147        return "Secondary";
148      case NULL:
149        return null;
150      default:
151        return "?";
152      }
153    }
154  }
155
156  public static class IdentifierUseEnumFactory implements EnumFactory<IdentifierUse> {
157    public IdentifierUse fromCode(String codeString) throws IllegalArgumentException {
158      if (codeString == null || "".equals(codeString))
159        if (codeString == null || "".equals(codeString))
160          return null;
161      if ("usual".equals(codeString))
162        return IdentifierUse.USUAL;
163      if ("official".equals(codeString))
164        return IdentifierUse.OFFICIAL;
165      if ("temp".equals(codeString))
166        return IdentifierUse.TEMP;
167      if ("secondary".equals(codeString))
168        return IdentifierUse.SECONDARY;
169      throw new IllegalArgumentException("Unknown IdentifierUse code '" + codeString + "'");
170    }
171
172    public Enumeration<IdentifierUse> fromType(Base code) throws FHIRException {
173      if (code == null || code.isEmpty())
174        return null;
175      String codeString = ((PrimitiveType) code).asStringValue();
176      if (codeString == null || "".equals(codeString))
177        return null;
178      if ("usual".equals(codeString))
179        return new Enumeration<IdentifierUse>(this, IdentifierUse.USUAL);
180      if ("official".equals(codeString))
181        return new Enumeration<IdentifierUse>(this, IdentifierUse.OFFICIAL);
182      if ("temp".equals(codeString))
183        return new Enumeration<IdentifierUse>(this, IdentifierUse.TEMP);
184      if ("secondary".equals(codeString))
185        return new Enumeration<IdentifierUse>(this, IdentifierUse.SECONDARY);
186      throw new FHIRException("Unknown IdentifierUse code '" + codeString + "'");
187    }
188
189    public String toCode(IdentifierUse code) {
190      if (code == IdentifierUse.USUAL)
191        return "usual";
192      if (code == IdentifierUse.OFFICIAL)
193        return "official";
194      if (code == IdentifierUse.TEMP)
195        return "temp";
196      if (code == IdentifierUse.SECONDARY)
197        return "secondary";
198      return "?";
199    }
200  }
201
202  /**
203   * The purpose of this identifier.
204   */
205  @Child(name = "use", type = { CodeType.class }, order = 0, min = 0, max = 1, modifier = true, summary = true)
206  @Description(shortDefinition = "usual | official | temp | secondary (If known)", formalDefinition = "The purpose of this identifier.")
207  protected Enumeration<IdentifierUse> use;
208
209  /**
210   * A coded type for the identifier that can be used to determine which
211   * identifier to use for a specific purpose.
212   */
213  @Child(name = "type", type = { CodeableConcept.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
214  @Description(shortDefinition = "Description of identifier", formalDefinition = "A coded type for the identifier that can be used to determine which identifier to use for a specific purpose.")
215  protected CodeableConcept type;
216
217  /**
218   * Establishes the namespace in which set of possible id values is unique.
219   */
220  @Child(name = "system", type = { UriType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
221  @Description(shortDefinition = "The namespace for the identifier", formalDefinition = "Establishes the namespace in which set of possible id values is unique.")
222  protected UriType system;
223
224  /**
225   * The portion of the identifier typically displayed to the user and which is
226   * unique within the context of the system.
227   */
228  @Child(name = "value", type = { StringType.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
229  @Description(shortDefinition = "The value that is unique", formalDefinition = "The portion of the identifier typically displayed to the user and which is unique within the context of the system.")
230  protected StringType value;
231
232  /**
233   * Time period during which identifier is/was valid for use.
234   */
235  @Child(name = "period", type = { Period.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
236  @Description(shortDefinition = "Time period when id is/was valid for use", formalDefinition = "Time period during which identifier is/was valid for use.")
237  protected Period period;
238
239  /**
240   * Organization that issued/manages the identifier.
241   */
242  @Child(name = "assigner", type = {
243      Organization.class }, order = 5, min = 0, max = 1, modifier = false, summary = true)
244  @Description(shortDefinition = "Organization that issued id (may be just text)", formalDefinition = "Organization that issued/manages the identifier.")
245  protected Reference assigner;
246
247  /**
248   * The actual object that is the target of the reference (Organization that
249   * issued/manages the identifier.)
250   */
251  protected Organization assignerTarget;
252
253  private static final long serialVersionUID = -478840981L;
254
255  /*
256   * Constructor
257   */
258  public Identifier() {
259    super();
260  }
261
262  /**
263   * @return {@link #use} (The purpose of this identifier.). This is the
264   *         underlying object with id, value and extensions. The accessor
265   *         "getUse" gives direct access to the value
266   */
267  public Enumeration<IdentifierUse> getUseElement() {
268    if (this.use == null)
269      if (Configuration.errorOnAutoCreate())
270        throw new Error("Attempt to auto-create Identifier.use");
271      else if (Configuration.doAutoCreate())
272        this.use = new Enumeration<IdentifierUse>(new IdentifierUseEnumFactory()); // bb
273    return this.use;
274  }
275
276  public boolean hasUseElement() {
277    return this.use != null && !this.use.isEmpty();
278  }
279
280  public boolean hasUse() {
281    return this.use != null && !this.use.isEmpty();
282  }
283
284  /**
285   * @param value {@link #use} (The purpose of this identifier.). This is the
286   *              underlying object with id, value and extensions. The accessor
287   *              "getUse" gives direct access to the value
288   */
289  public Identifier setUseElement(Enumeration<IdentifierUse> value) {
290    this.use = value;
291    return this;
292  }
293
294  /**
295   * @return The purpose of this identifier.
296   */
297  public IdentifierUse getUse() {
298    return this.use == null ? null : this.use.getValue();
299  }
300
301  /**
302   * @param value The purpose of this identifier.
303   */
304  public Identifier setUse(IdentifierUse value) {
305    if (value == null)
306      this.use = null;
307    else {
308      if (this.use == null)
309        this.use = new Enumeration<IdentifierUse>(new IdentifierUseEnumFactory());
310      this.use.setValue(value);
311    }
312    return this;
313  }
314
315  /**
316   * @return {@link #type} (A coded type for the identifier that can be used to
317   *         determine which identifier to use for a specific purpose.)
318   */
319  public CodeableConcept getType() {
320    if (this.type == null)
321      if (Configuration.errorOnAutoCreate())
322        throw new Error("Attempt to auto-create Identifier.type");
323      else if (Configuration.doAutoCreate())
324        this.type = new CodeableConcept(); // cc
325    return this.type;
326  }
327
328  public boolean hasType() {
329    return this.type != null && !this.type.isEmpty();
330  }
331
332  /**
333   * @param value {@link #type} (A coded type for the identifier that can be used
334   *              to determine which identifier to use for a specific purpose.)
335   */
336  public Identifier setType(CodeableConcept value) {
337    this.type = value;
338    return this;
339  }
340
341  /**
342   * @return {@link #system} (Establishes the namespace in which set of possible
343   *         id values is unique.). This is the underlying object with id, value
344   *         and extensions. The accessor "getSystem" gives direct access to the
345   *         value
346   */
347  public UriType getSystemElement() {
348    if (this.system == null)
349      if (Configuration.errorOnAutoCreate())
350        throw new Error("Attempt to auto-create Identifier.system");
351      else if (Configuration.doAutoCreate())
352        this.system = new UriType(); // bb
353    return this.system;
354  }
355
356  public boolean hasSystemElement() {
357    return this.system != null && !this.system.isEmpty();
358  }
359
360  public boolean hasSystem() {
361    return this.system != null && !this.system.isEmpty();
362  }
363
364  /**
365   * @param value {@link #system} (Establishes the namespace in which set of
366   *              possible id values is unique.). This is the underlying object
367   *              with id, value and extensions. The accessor "getSystem" gives
368   *              direct access to the value
369   */
370  public Identifier setSystemElement(UriType value) {
371    this.system = value;
372    return this;
373  }
374
375  /**
376   * @return Establishes the namespace in which set of possible id values is
377   *         unique.
378   */
379  public String getSystem() {
380    return this.system == null ? null : this.system.getValue();
381  }
382
383  /**
384   * @param value Establishes the namespace in which set of possible id values is
385   *              unique.
386   */
387  public Identifier setSystem(String value) {
388    if (Utilities.noString(value))
389      this.system = null;
390    else {
391      if (this.system == null)
392        this.system = new UriType();
393      this.system.setValue(value);
394    }
395    return this;
396  }
397
398  /**
399   * @return {@link #value} (The portion of the identifier typically displayed to
400   *         the user and which is unique within the context of the system.). This
401   *         is the underlying object with id, value and extensions. The accessor
402   *         "getValue" gives direct access to the value
403   */
404  public StringType getValueElement() {
405    if (this.value == null)
406      if (Configuration.errorOnAutoCreate())
407        throw new Error("Attempt to auto-create Identifier.value");
408      else if (Configuration.doAutoCreate())
409        this.value = new StringType(); // bb
410    return this.value;
411  }
412
413  public boolean hasValueElement() {
414    return this.value != null && !this.value.isEmpty();
415  }
416
417  public boolean hasValue() {
418    return this.value != null && !this.value.isEmpty();
419  }
420
421  /**
422   * @param value {@link #value} (The portion of the identifier typically
423   *              displayed to the user and which is unique within the context of
424   *              the system.). This is the underlying object with id, value and
425   *              extensions. The accessor "getValue" gives direct access to the
426   *              value
427   */
428  public Identifier setValueElement(StringType value) {
429    this.value = value;
430    return this;
431  }
432
433  /**
434   * @return The portion of the identifier typically displayed to the user and
435   *         which is unique within the context of the system.
436   */
437  public String getValue() {
438    return this.value == null ? null : this.value.getValue();
439  }
440
441  /**
442   * @param value The portion of the identifier typically displayed to the user
443   *              and which is unique within the context of the system.
444   */
445  public Identifier setValue(String value) {
446    if (Utilities.noString(value))
447      this.value = null;
448    else {
449      if (this.value == null)
450        this.value = new StringType();
451      this.value.setValue(value);
452    }
453    return this;
454  }
455
456  /**
457   * @return {@link #period} (Time period during which identifier is/was valid for
458   *         use.)
459   */
460  public Period getPeriod() {
461    if (this.period == null)
462      if (Configuration.errorOnAutoCreate())
463        throw new Error("Attempt to auto-create Identifier.period");
464      else if (Configuration.doAutoCreate())
465        this.period = new Period(); // cc
466    return this.period;
467  }
468
469  public boolean hasPeriod() {
470    return this.period != null && !this.period.isEmpty();
471  }
472
473  /**
474   * @param value {@link #period} (Time period during which identifier is/was
475   *              valid for use.)
476   */
477  public Identifier setPeriod(Period value) {
478    this.period = value;
479    return this;
480  }
481
482  /**
483   * @return {@link #assigner} (Organization that issued/manages the identifier.)
484   */
485  public Reference getAssigner() {
486    if (this.assigner == null)
487      if (Configuration.errorOnAutoCreate())
488        throw new Error("Attempt to auto-create Identifier.assigner");
489      else if (Configuration.doAutoCreate())
490        this.assigner = new Reference(); // cc
491    return this.assigner;
492  }
493
494  public boolean hasAssigner() {
495    return this.assigner != null && !this.assigner.isEmpty();
496  }
497
498  /**
499   * @param value {@link #assigner} (Organization that issued/manages the
500   *              identifier.)
501   */
502  public Identifier setAssigner(Reference value) {
503    this.assigner = value;
504    return this;
505  }
506
507  /**
508   * @return {@link #assigner} The actual object that is the target of the
509   *         reference. The reference library doesn't populate this, but you can
510   *         use it to hold the resource if you resolve it. (Organization that
511   *         issued/manages the identifier.)
512   */
513  public Organization getAssignerTarget() {
514    if (this.assignerTarget == null)
515      if (Configuration.errorOnAutoCreate())
516        throw new Error("Attempt to auto-create Identifier.assigner");
517      else if (Configuration.doAutoCreate())
518        this.assignerTarget = new Organization(); // aa
519    return this.assignerTarget;
520  }
521
522  /**
523   * @param value {@link #assigner} The actual object that is the target of the
524   *              reference. The reference library doesn't use these, but you can
525   *              use it to hold the resource if you resolve it. (Organization
526   *              that issued/manages the identifier.)
527   */
528  public Identifier setAssignerTarget(Organization value) {
529    this.assignerTarget = value;
530    return this;
531  }
532
533  protected void listChildren(List<Property> childrenList) {
534    super.listChildren(childrenList);
535    childrenList
536        .add(new Property("use", "code", "The purpose of this identifier.", 0, java.lang.Integer.MAX_VALUE, use));
537    childrenList.add(new Property("type", "CodeableConcept",
538        "A coded type for the identifier that can be used to determine which identifier to use for a specific purpose.",
539        0, java.lang.Integer.MAX_VALUE, type));
540    childrenList
541        .add(new Property("system", "uri", "Establishes the namespace in which set of possible id values is unique.", 0,
542            java.lang.Integer.MAX_VALUE, system));
543    childrenList.add(new Property("value", "string",
544        "The portion of the identifier typically displayed to the user and which is unique within the context of the system.",
545        0, java.lang.Integer.MAX_VALUE, value));
546    childrenList.add(new Property("period", "Period", "Time period during which identifier is/was valid for use.", 0,
547        java.lang.Integer.MAX_VALUE, period));
548    childrenList.add(new Property("assigner", "Reference(Organization)",
549        "Organization that issued/manages the identifier.", 0, java.lang.Integer.MAX_VALUE, assigner));
550  }
551
552  @Override
553  public void setProperty(String name, Base value) throws FHIRException {
554    if (name.equals("use"))
555      this.use = new IdentifierUseEnumFactory().fromType(value); // Enumeration<IdentifierUse>
556    else if (name.equals("type"))
557      this.type = castToCodeableConcept(value); // CodeableConcept
558    else if (name.equals("system"))
559      this.system = castToUri(value); // UriType
560    else if (name.equals("value"))
561      this.value = castToString(value); // StringType
562    else if (name.equals("period"))
563      this.period = castToPeriod(value); // Period
564    else if (name.equals("assigner"))
565      this.assigner = castToReference(value); // Reference
566    else
567      super.setProperty(name, value);
568  }
569
570  @Override
571  public Base addChild(String name) throws FHIRException {
572    if (name.equals("use")) {
573      throw new FHIRException("Cannot call addChild on a singleton property Identifier.use");
574    } else if (name.equals("type")) {
575      this.type = new CodeableConcept();
576      return this.type;
577    } else if (name.equals("system")) {
578      throw new FHIRException("Cannot call addChild on a singleton property Identifier.system");
579    } else if (name.equals("value")) {
580      throw new FHIRException("Cannot call addChild on a singleton property Identifier.value");
581    } else if (name.equals("period")) {
582      this.period = new Period();
583      return this.period;
584    } else if (name.equals("assigner")) {
585      this.assigner = new Reference();
586      return this.assigner;
587    } else
588      return super.addChild(name);
589  }
590
591  public String fhirType() {
592    return "Identifier";
593
594  }
595
596  public Identifier copy() {
597    Identifier dst = new Identifier();
598    copyValues(dst);
599    dst.use = use == null ? null : use.copy();
600    dst.type = type == null ? null : type.copy();
601    dst.system = system == null ? null : system.copy();
602    dst.value = value == null ? null : value.copy();
603    dst.period = period == null ? null : period.copy();
604    dst.assigner = assigner == null ? null : assigner.copy();
605    return dst;
606  }
607
608  protected Identifier typedCopy() {
609    return copy();
610  }
611
612  @Override
613  public boolean equalsDeep(Base other) {
614    if (!super.equalsDeep(other))
615      return false;
616    if (!(other instanceof Identifier))
617      return false;
618    Identifier o = (Identifier) other;
619    return compareDeep(use, o.use, true) && compareDeep(type, o.type, true) && compareDeep(system, o.system, true)
620        && compareDeep(value, o.value, true) && compareDeep(period, o.period, true)
621        && compareDeep(assigner, o.assigner, true);
622  }
623
624  @Override
625  public boolean equalsShallow(Base other) {
626    if (!super.equalsShallow(other))
627      return false;
628    if (!(other instanceof Identifier))
629      return false;
630    Identifier o = (Identifier) other;
631    return compareValues(use, o.use, true) && compareValues(system, o.system, true)
632        && compareValues(value, o.value, true);
633  }
634
635  public boolean isEmpty() {
636    return super.isEmpty() && (use == null || use.isEmpty()) && (type == null || type.isEmpty())
637        && (system == null || system.isEmpty()) && (value == null || value.isEmpty())
638        && (period == null || period.isEmpty()) && (assigner == null || assigner.isEmpty());
639  }
640
641}