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