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