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