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