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.*;
034
035import org.hl7.fhir.exceptions.FHIRException;
036import org.hl7.fhir.instance.model.Enumerations.DocumentReferenceStatus;
037import org.hl7.fhir.instance.model.Enumerations.DocumentReferenceStatusEnumFactory;
038import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
039import org.hl7.fhir.utilities.Utilities;
040
041import ca.uhn.fhir.model.api.annotation.*;
042/**
043 * A reference to a document .
044 */
045@ResourceDef(name="DocumentReference", profile="http://hl7.org/fhir/Profile/DocumentReference")
046public class DocumentReference extends DomainResource {
047
048    public enum DocumentRelationshipType {
049        /**
050         * This document logically replaces or supersedes the target document.
051         */
052        REPLACES, 
053        /**
054         * This document was generated by transforming the target document (e.g. format or language conversion).
055         */
056        TRANSFORMS, 
057        /**
058         * This document is a signature of the target document.
059         */
060        SIGNS, 
061        /**
062         * This document adds additional information to the target document.
063         */
064        APPENDS, 
065        /**
066         * added to help the parsers
067         */
068        NULL;
069        public static DocumentRelationshipType fromCode(String codeString) throws FHIRException {
070            if (codeString == null || "".equals(codeString))
071                return null;
072        if ("replaces".equals(codeString))
073          return REPLACES;
074        if ("transforms".equals(codeString))
075          return TRANSFORMS;
076        if ("signs".equals(codeString))
077          return SIGNS;
078        if ("appends".equals(codeString))
079          return APPENDS;
080        throw new FHIRException("Unknown DocumentRelationshipType code '"+codeString+"'");
081        }
082        public String toCode() {
083          switch (this) {
084            case REPLACES: return "replaces";
085            case TRANSFORMS: return "transforms";
086            case SIGNS: return "signs";
087            case APPENDS: return "appends";
088            default: return "?";
089          }
090        }
091        public String getSystem() {
092          switch (this) {
093            case REPLACES: return "http://hl7.org/fhir/document-relationship-type";
094            case TRANSFORMS: return "http://hl7.org/fhir/document-relationship-type";
095            case SIGNS: return "http://hl7.org/fhir/document-relationship-type";
096            case APPENDS: return "http://hl7.org/fhir/document-relationship-type";
097            default: return "?";
098          }
099        }
100        public String getDefinition() {
101          switch (this) {
102            case REPLACES: return "This document logically replaces or supersedes the target document.";
103            case TRANSFORMS: return "This document was generated by transforming the target document (e.g. format or language conversion).";
104            case SIGNS: return "This document is a signature of the target document.";
105            case APPENDS: return "This document adds additional information to the target document.";
106            default: return "?";
107          }
108        }
109        public String getDisplay() {
110          switch (this) {
111            case REPLACES: return "Replaces";
112            case TRANSFORMS: return "Transforms";
113            case SIGNS: return "Signs";
114            case APPENDS: return "Appends";
115            default: return "?";
116          }
117        }
118    }
119
120  public static class DocumentRelationshipTypeEnumFactory implements EnumFactory<DocumentRelationshipType> {
121    public DocumentRelationshipType fromCode(String codeString) throws IllegalArgumentException {
122      if (codeString == null || "".equals(codeString))
123            if (codeString == null || "".equals(codeString))
124                return null;
125        if ("replaces".equals(codeString))
126          return DocumentRelationshipType.REPLACES;
127        if ("transforms".equals(codeString))
128          return DocumentRelationshipType.TRANSFORMS;
129        if ("signs".equals(codeString))
130          return DocumentRelationshipType.SIGNS;
131        if ("appends".equals(codeString))
132          return DocumentRelationshipType.APPENDS;
133        throw new IllegalArgumentException("Unknown DocumentRelationshipType code '"+codeString+"'");
134        }
135        public Enumeration<DocumentRelationshipType> fromType(Base code) throws FHIRException {
136          if (code == null || code.isEmpty())
137            return null;
138          String codeString = ((PrimitiveType) code).asStringValue();
139          if (codeString == null || "".equals(codeString))
140            return null;
141        if ("replaces".equals(codeString))
142          return new Enumeration<DocumentRelationshipType>(this, DocumentRelationshipType.REPLACES);
143        if ("transforms".equals(codeString))
144          return new Enumeration<DocumentRelationshipType>(this, DocumentRelationshipType.TRANSFORMS);
145        if ("signs".equals(codeString))
146          return new Enumeration<DocumentRelationshipType>(this, DocumentRelationshipType.SIGNS);
147        if ("appends".equals(codeString))
148          return new Enumeration<DocumentRelationshipType>(this, DocumentRelationshipType.APPENDS);
149        throw new FHIRException("Unknown DocumentRelationshipType code '"+codeString+"'");
150        }
151    public String toCode(DocumentRelationshipType code) {
152      if (code == DocumentRelationshipType.REPLACES)
153        return "replaces";
154      if (code == DocumentRelationshipType.TRANSFORMS)
155        return "transforms";
156      if (code == DocumentRelationshipType.SIGNS)
157        return "signs";
158      if (code == DocumentRelationshipType.APPENDS)
159        return "appends";
160      return "?";
161      }
162    }
163
164    @Block()
165    public static class DocumentReferenceRelatesToComponent extends BackboneElement implements IBaseBackboneElement {
166        /**
167         * The type of relationship that this document has with anther document.
168         */
169        @Child(name = "code", type = {CodeType.class}, order=1, min=1, max=1, modifier=false, summary=true)
170        @Description(shortDefinition="replaces | transforms | signs | appends", formalDefinition="The type of relationship that this document has with anther document." )
171        protected Enumeration<DocumentRelationshipType> code;
172
173        /**
174         * The target document of this relationship.
175         */
176        @Child(name = "target", type = {DocumentReference.class}, order=2, min=1, max=1, modifier=false, summary=true)
177        @Description(shortDefinition="Target of the relationship", formalDefinition="The target document of this relationship." )
178        protected Reference target;
179
180        /**
181         * The actual object that is the target of the reference (The target document of this relationship.)
182         */
183        protected DocumentReference targetTarget;
184
185        private static final long serialVersionUID = -347257495L;
186
187    /*
188     * Constructor
189     */
190      public DocumentReferenceRelatesToComponent() {
191        super();
192      }
193
194    /*
195     * Constructor
196     */
197      public DocumentReferenceRelatesToComponent(Enumeration<DocumentRelationshipType> code, Reference target) {
198        super();
199        this.code = code;
200        this.target = target;
201      }
202
203        /**
204         * @return {@link #code} (The type of relationship that this document has with anther document.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value
205         */
206        public Enumeration<DocumentRelationshipType> getCodeElement() { 
207          if (this.code == null)
208            if (Configuration.errorOnAutoCreate())
209              throw new Error("Attempt to auto-create DocumentReferenceRelatesToComponent.code");
210            else if (Configuration.doAutoCreate())
211              this.code = new Enumeration<DocumentRelationshipType>(new DocumentRelationshipTypeEnumFactory()); // bb
212          return this.code;
213        }
214
215        public boolean hasCodeElement() { 
216          return this.code != null && !this.code.isEmpty();
217        }
218
219        public boolean hasCode() { 
220          return this.code != null && !this.code.isEmpty();
221        }
222
223        /**
224         * @param value {@link #code} (The type of relationship that this document has with anther document.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value
225         */
226        public DocumentReferenceRelatesToComponent setCodeElement(Enumeration<DocumentRelationshipType> value) { 
227          this.code = value;
228          return this;
229        }
230
231        /**
232         * @return The type of relationship that this document has with anther document.
233         */
234        public DocumentRelationshipType getCode() { 
235          return this.code == null ? null : this.code.getValue();
236        }
237
238        /**
239         * @param value The type of relationship that this document has with anther document.
240         */
241        public DocumentReferenceRelatesToComponent setCode(DocumentRelationshipType value) { 
242            if (this.code == null)
243              this.code = new Enumeration<DocumentRelationshipType>(new DocumentRelationshipTypeEnumFactory());
244            this.code.setValue(value);
245          return this;
246        }
247
248        /**
249         * @return {@link #target} (The target document of this relationship.)
250         */
251        public Reference getTarget() { 
252          if (this.target == null)
253            if (Configuration.errorOnAutoCreate())
254              throw new Error("Attempt to auto-create DocumentReferenceRelatesToComponent.target");
255            else if (Configuration.doAutoCreate())
256              this.target = new Reference(); // cc
257          return this.target;
258        }
259
260        public boolean hasTarget() { 
261          return this.target != null && !this.target.isEmpty();
262        }
263
264        /**
265         * @param value {@link #target} (The target document of this relationship.)
266         */
267        public DocumentReferenceRelatesToComponent setTarget(Reference value) { 
268          this.target = value;
269          return this;
270        }
271
272        /**
273         * @return {@link #target} 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. (The target document of this relationship.)
274         */
275        public DocumentReference getTargetTarget() { 
276          if (this.targetTarget == null)
277            if (Configuration.errorOnAutoCreate())
278              throw new Error("Attempt to auto-create DocumentReferenceRelatesToComponent.target");
279            else if (Configuration.doAutoCreate())
280              this.targetTarget = new DocumentReference(); // aa
281          return this.targetTarget;
282        }
283
284        /**
285         * @param value {@link #target} 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. (The target document of this relationship.)
286         */
287        public DocumentReferenceRelatesToComponent setTargetTarget(DocumentReference value) { 
288          this.targetTarget = value;
289          return this;
290        }
291
292        protected void listChildren(List<Property> childrenList) {
293          super.listChildren(childrenList);
294          childrenList.add(new Property("code", "code", "The type of relationship that this document has with anther document.", 0, java.lang.Integer.MAX_VALUE, code));
295          childrenList.add(new Property("target", "Reference(DocumentReference)", "The target document of this relationship.", 0, java.lang.Integer.MAX_VALUE, target));
296        }
297
298      @Override
299      public void setProperty(String name, Base value) throws FHIRException {
300        if (name.equals("code"))
301          this.code = new DocumentRelationshipTypeEnumFactory().fromType(value); // Enumeration<DocumentRelationshipType>
302        else if (name.equals("target"))
303          this.target = castToReference(value); // Reference
304        else
305          super.setProperty(name, value);
306      }
307
308      @Override
309      public Base addChild(String name) throws FHIRException {
310        if (name.equals("code")) {
311          throw new FHIRException("Cannot call addChild on a primitive type DocumentReference.code");
312        }
313        else if (name.equals("target")) {
314          this.target = new Reference();
315          return this.target;
316        }
317        else
318          return super.addChild(name);
319      }
320
321      public DocumentReferenceRelatesToComponent copy() {
322        DocumentReferenceRelatesToComponent dst = new DocumentReferenceRelatesToComponent();
323        copyValues(dst);
324        dst.code = code == null ? null : code.copy();
325        dst.target = target == null ? null : target.copy();
326        return dst;
327      }
328
329      @Override
330      public boolean equalsDeep(Base other) {
331        if (!super.equalsDeep(other))
332          return false;
333        if (!(other instanceof DocumentReferenceRelatesToComponent))
334          return false;
335        DocumentReferenceRelatesToComponent o = (DocumentReferenceRelatesToComponent) other;
336        return compareDeep(code, o.code, true) && compareDeep(target, o.target, true);
337      }
338
339      @Override
340      public boolean equalsShallow(Base other) {
341        if (!super.equalsShallow(other))
342          return false;
343        if (!(other instanceof DocumentReferenceRelatesToComponent))
344          return false;
345        DocumentReferenceRelatesToComponent o = (DocumentReferenceRelatesToComponent) other;
346        return compareValues(code, o.code, true);
347      }
348
349      public boolean isEmpty() {
350        return super.isEmpty() && (code == null || code.isEmpty()) && (target == null || target.isEmpty())
351          ;
352      }
353
354  public String fhirType() {
355    return "DocumentReference.relatesTo";
356
357  }
358
359  }
360
361    @Block()
362    public static class DocumentReferenceContentComponent extends BackboneElement implements IBaseBackboneElement {
363        /**
364         * The document or url of the document along with critical metadata to prove content has integrity.
365         */
366        @Child(name = "attachment", type = {Attachment.class}, order=1, min=1, max=1, modifier=false, summary=true)
367        @Description(shortDefinition="Where to access the document", formalDefinition="The document or url of the document along with critical metadata to prove content has integrity." )
368        protected Attachment attachment;
369
370        /**
371         * An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType.
372         */
373        @Child(name = "format", type = {Coding.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
374        @Description(shortDefinition="Format/content rules for the document", formalDefinition="An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType." )
375        protected List<Coding> format;
376
377        private static final long serialVersionUID = -1412643085L;
378
379    /*
380     * Constructor
381     */
382      public DocumentReferenceContentComponent() {
383        super();
384      }
385
386    /*
387     * Constructor
388     */
389      public DocumentReferenceContentComponent(Attachment attachment) {
390        super();
391        this.attachment = attachment;
392      }
393
394        /**
395         * @return {@link #attachment} (The document or url of the document along with critical metadata to prove content has integrity.)
396         */
397        public Attachment getAttachment() { 
398          if (this.attachment == null)
399            if (Configuration.errorOnAutoCreate())
400              throw new Error("Attempt to auto-create DocumentReferenceContentComponent.attachment");
401            else if (Configuration.doAutoCreate())
402              this.attachment = new Attachment(); // cc
403          return this.attachment;
404        }
405
406        public boolean hasAttachment() { 
407          return this.attachment != null && !this.attachment.isEmpty();
408        }
409
410        /**
411         * @param value {@link #attachment} (The document or url of the document along with critical metadata to prove content has integrity.)
412         */
413        public DocumentReferenceContentComponent setAttachment(Attachment value) { 
414          this.attachment = value;
415          return this;
416        }
417
418        /**
419         * @return {@link #format} (An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType.)
420         */
421        public List<Coding> getFormat() { 
422          if (this.format == null)
423            this.format = new ArrayList<Coding>();
424          return this.format;
425        }
426
427        public boolean hasFormat() { 
428          if (this.format == null)
429            return false;
430          for (Coding item : this.format)
431            if (!item.isEmpty())
432              return true;
433          return false;
434        }
435
436        /**
437         * @return {@link #format} (An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType.)
438         */
439    // syntactic sugar
440        public Coding addFormat() { //3
441          Coding t = new Coding();
442          if (this.format == null)
443            this.format = new ArrayList<Coding>();
444          this.format.add(t);
445          return t;
446        }
447
448    // syntactic sugar
449        public DocumentReferenceContentComponent addFormat(Coding t) { //3
450          if (t == null)
451            return this;
452          if (this.format == null)
453            this.format = new ArrayList<Coding>();
454          this.format.add(t);
455          return this;
456        }
457
458        protected void listChildren(List<Property> childrenList) {
459          super.listChildren(childrenList);
460          childrenList.add(new Property("attachment", "Attachment", "The document or url of the document along with critical metadata to prove content has integrity.", 0, java.lang.Integer.MAX_VALUE, attachment));
461          childrenList.add(new Property("format", "Coding", "An identifier of the document encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType.", 0, java.lang.Integer.MAX_VALUE, format));
462        }
463
464      @Override
465      public void setProperty(String name, Base value) throws FHIRException {
466        if (name.equals("attachment"))
467          this.attachment = castToAttachment(value); // Attachment
468        else if (name.equals("format"))
469          this.getFormat().add(castToCoding(value));
470        else
471          super.setProperty(name, value);
472      }
473
474      @Override
475      public Base addChild(String name) throws FHIRException {
476        if (name.equals("attachment")) {
477          this.attachment = new Attachment();
478          return this.attachment;
479        }
480        else if (name.equals("format")) {
481          return addFormat();
482        }
483        else
484          return super.addChild(name);
485      }
486
487      public DocumentReferenceContentComponent copy() {
488        DocumentReferenceContentComponent dst = new DocumentReferenceContentComponent();
489        copyValues(dst);
490        dst.attachment = attachment == null ? null : attachment.copy();
491        if (format != null) {
492          dst.format = new ArrayList<Coding>();
493          for (Coding i : format)
494            dst.format.add(i.copy());
495        };
496        return dst;
497      }
498
499      @Override
500      public boolean equalsDeep(Base other) {
501        if (!super.equalsDeep(other))
502          return false;
503        if (!(other instanceof DocumentReferenceContentComponent))
504          return false;
505        DocumentReferenceContentComponent o = (DocumentReferenceContentComponent) other;
506        return compareDeep(attachment, o.attachment, true) && compareDeep(format, o.format, true);
507      }
508
509      @Override
510      public boolean equalsShallow(Base other) {
511        if (!super.equalsShallow(other))
512          return false;
513        if (!(other instanceof DocumentReferenceContentComponent))
514          return false;
515        DocumentReferenceContentComponent o = (DocumentReferenceContentComponent) other;
516        return true;
517      }
518
519      public boolean isEmpty() {
520        return super.isEmpty() && (attachment == null || attachment.isEmpty()) && (format == null || format.isEmpty())
521          ;
522      }
523
524  public String fhirType() {
525    return "DocumentReference.content";
526
527  }
528
529  }
530
531    @Block()
532    public static class DocumentReferenceContextComponent extends BackboneElement implements IBaseBackboneElement {
533        /**
534         * Describes the clinical encounter or type of care that the document content is associated with.
535         */
536        @Child(name = "encounter", type = {Encounter.class}, order=1, min=0, max=1, modifier=false, summary=true)
537        @Description(shortDefinition="Context of the document  content", formalDefinition="Describes the clinical encounter or type of care that the document content is associated with." )
538        protected Reference encounter;
539
540        /**
541         * The actual object that is the target of the reference (Describes the clinical encounter or type of care that the document content is associated with.)
542         */
543        protected Encounter encounterTarget;
544
545        /**
546         * This list of codes represents the main clinical acts, such as a colonoscopy or an appendectomy, being documented. In some cases, the event is inherent in the typeCode, such as a "History and Physical Report" in which the procedure being documented is necessarily a "History and Physical" act.
547         */
548        @Child(name = "event", type = {CodeableConcept.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
549        @Description(shortDefinition="Main Clinical Acts Documented", formalDefinition="This list of codes represents the main clinical acts, such as a colonoscopy or an appendectomy, being documented. In some cases, the event is inherent in the typeCode, such as a \"History and Physical Report\" in which the procedure being documented is necessarily a \"History and Physical\" act." )
550        protected List<CodeableConcept> event;
551
552        /**
553         * The time period over which the service that is described by the document was provided.
554         */
555        @Child(name = "period", type = {Period.class}, order=3, min=0, max=1, modifier=false, summary=true)
556        @Description(shortDefinition="Time of service that is being documented", formalDefinition="The time period over which the service that is described by the document was provided." )
557        protected Period period;
558
559        /**
560         * The kind of facility where the patient was seen.
561         */
562        @Child(name = "facilityType", type = {CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
563        @Description(shortDefinition="Kind of facility where patient was seen", formalDefinition="The kind of facility where the patient was seen." )
564        protected CodeableConcept facilityType;
565
566        /**
567         * This property may convey specifics about the practice setting where the content was created, often reflecting the clinical specialty.
568         */
569        @Child(name = "practiceSetting", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=true)
570        @Description(shortDefinition="Additional details about where the content was created (e.g. clinical specialty)", formalDefinition="This property may convey specifics about the practice setting where the content was created, often reflecting the clinical specialty." )
571        protected CodeableConcept practiceSetting;
572
573        /**
574         * The Patient Information as known when the document was published. May be a reference to a version specific, or contained.
575         */
576        @Child(name = "sourcePatientInfo", type = {Patient.class}, order=6, min=0, max=1, modifier=false, summary=true)
577        @Description(shortDefinition="Patient demographics from source", formalDefinition="The Patient Information as known when the document was published. May be a reference to a version specific, or contained." )
578        protected Reference sourcePatientInfo;
579
580        /**
581         * The actual object that is the target of the reference (The Patient Information as known when the document was published. May be a reference to a version specific, or contained.)
582         */
583        protected Patient sourcePatientInfoTarget;
584
585        /**
586         * Related identifiers or resources associated with the DocumentReference.
587         */
588        @Child(name = "related", type = {}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
589        @Description(shortDefinition="Related identifiers or resources", formalDefinition="Related identifiers or resources associated with the DocumentReference." )
590        protected List<DocumentReferenceContextRelatedComponent> related;
591
592        private static final long serialVersionUID = 994799273L;
593
594    /*
595     * Constructor
596     */
597      public DocumentReferenceContextComponent() {
598        super();
599      }
600
601        /**
602         * @return {@link #encounter} (Describes the clinical encounter or type of care that the document content is associated with.)
603         */
604        public Reference getEncounter() { 
605          if (this.encounter == null)
606            if (Configuration.errorOnAutoCreate())
607              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.encounter");
608            else if (Configuration.doAutoCreate())
609              this.encounter = new Reference(); // cc
610          return this.encounter;
611        }
612
613        public boolean hasEncounter() { 
614          return this.encounter != null && !this.encounter.isEmpty();
615        }
616
617        /**
618         * @param value {@link #encounter} (Describes the clinical encounter or type of care that the document content is associated with.)
619         */
620        public DocumentReferenceContextComponent setEncounter(Reference value) { 
621          this.encounter = value;
622          return this;
623        }
624
625        /**
626         * @return {@link #encounter} 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. (Describes the clinical encounter or type of care that the document content is associated with.)
627         */
628        public Encounter getEncounterTarget() { 
629          if (this.encounterTarget == null)
630            if (Configuration.errorOnAutoCreate())
631              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.encounter");
632            else if (Configuration.doAutoCreate())
633              this.encounterTarget = new Encounter(); // aa
634          return this.encounterTarget;
635        }
636
637        /**
638         * @param value {@link #encounter} 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. (Describes the clinical encounter or type of care that the document content is associated with.)
639         */
640        public DocumentReferenceContextComponent setEncounterTarget(Encounter value) { 
641          this.encounterTarget = value;
642          return this;
643        }
644
645        /**
646         * @return {@link #event} (This list of codes represents the main clinical acts, such as a colonoscopy or an appendectomy, being documented. In some cases, the event is inherent in the typeCode, such as a "History and Physical Report" in which the procedure being documented is necessarily a "History and Physical" act.)
647         */
648        public List<CodeableConcept> getEvent() { 
649          if (this.event == null)
650            this.event = new ArrayList<CodeableConcept>();
651          return this.event;
652        }
653
654        public boolean hasEvent() { 
655          if (this.event == null)
656            return false;
657          for (CodeableConcept item : this.event)
658            if (!item.isEmpty())
659              return true;
660          return false;
661        }
662
663        /**
664         * @return {@link #event} (This list of codes represents the main clinical acts, such as a colonoscopy or an appendectomy, being documented. In some cases, the event is inherent in the typeCode, such as a "History and Physical Report" in which the procedure being documented is necessarily a "History and Physical" act.)
665         */
666    // syntactic sugar
667        public CodeableConcept addEvent() { //3
668          CodeableConcept t = new CodeableConcept();
669          if (this.event == null)
670            this.event = new ArrayList<CodeableConcept>();
671          this.event.add(t);
672          return t;
673        }
674
675    // syntactic sugar
676        public DocumentReferenceContextComponent addEvent(CodeableConcept t) { //3
677          if (t == null)
678            return this;
679          if (this.event == null)
680            this.event = new ArrayList<CodeableConcept>();
681          this.event.add(t);
682          return this;
683        }
684
685        /**
686         * @return {@link #period} (The time period over which the service that is described by the document was provided.)
687         */
688        public Period getPeriod() { 
689          if (this.period == null)
690            if (Configuration.errorOnAutoCreate())
691              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.period");
692            else if (Configuration.doAutoCreate())
693              this.period = new Period(); // cc
694          return this.period;
695        }
696
697        public boolean hasPeriod() { 
698          return this.period != null && !this.period.isEmpty();
699        }
700
701        /**
702         * @param value {@link #period} (The time period over which the service that is described by the document was provided.)
703         */
704        public DocumentReferenceContextComponent setPeriod(Period value) { 
705          this.period = value;
706          return this;
707        }
708
709        /**
710         * @return {@link #facilityType} (The kind of facility where the patient was seen.)
711         */
712        public CodeableConcept getFacilityType() { 
713          if (this.facilityType == null)
714            if (Configuration.errorOnAutoCreate())
715              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.facilityType");
716            else if (Configuration.doAutoCreate())
717              this.facilityType = new CodeableConcept(); // cc
718          return this.facilityType;
719        }
720
721        public boolean hasFacilityType() { 
722          return this.facilityType != null && !this.facilityType.isEmpty();
723        }
724
725        /**
726         * @param value {@link #facilityType} (The kind of facility where the patient was seen.)
727         */
728        public DocumentReferenceContextComponent setFacilityType(CodeableConcept value) { 
729          this.facilityType = value;
730          return this;
731        }
732
733        /**
734         * @return {@link #practiceSetting} (This property may convey specifics about the practice setting where the content was created, often reflecting the clinical specialty.)
735         */
736        public CodeableConcept getPracticeSetting() { 
737          if (this.practiceSetting == null)
738            if (Configuration.errorOnAutoCreate())
739              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.practiceSetting");
740            else if (Configuration.doAutoCreate())
741              this.practiceSetting = new CodeableConcept(); // cc
742          return this.practiceSetting;
743        }
744
745        public boolean hasPracticeSetting() { 
746          return this.practiceSetting != null && !this.practiceSetting.isEmpty();
747        }
748
749        /**
750         * @param value {@link #practiceSetting} (This property may convey specifics about the practice setting where the content was created, often reflecting the clinical specialty.)
751         */
752        public DocumentReferenceContextComponent setPracticeSetting(CodeableConcept value) { 
753          this.practiceSetting = value;
754          return this;
755        }
756
757        /**
758         * @return {@link #sourcePatientInfo} (The Patient Information as known when the document was published. May be a reference to a version specific, or contained.)
759         */
760        public Reference getSourcePatientInfo() { 
761          if (this.sourcePatientInfo == null)
762            if (Configuration.errorOnAutoCreate())
763              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.sourcePatientInfo");
764            else if (Configuration.doAutoCreate())
765              this.sourcePatientInfo = new Reference(); // cc
766          return this.sourcePatientInfo;
767        }
768
769        public boolean hasSourcePatientInfo() { 
770          return this.sourcePatientInfo != null && !this.sourcePatientInfo.isEmpty();
771        }
772
773        /**
774         * @param value {@link #sourcePatientInfo} (The Patient Information as known when the document was published. May be a reference to a version specific, or contained.)
775         */
776        public DocumentReferenceContextComponent setSourcePatientInfo(Reference value) { 
777          this.sourcePatientInfo = value;
778          return this;
779        }
780
781        /**
782         * @return {@link #sourcePatientInfo} 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. (The Patient Information as known when the document was published. May be a reference to a version specific, or contained.)
783         */
784        public Patient getSourcePatientInfoTarget() { 
785          if (this.sourcePatientInfoTarget == null)
786            if (Configuration.errorOnAutoCreate())
787              throw new Error("Attempt to auto-create DocumentReferenceContextComponent.sourcePatientInfo");
788            else if (Configuration.doAutoCreate())
789              this.sourcePatientInfoTarget = new Patient(); // aa
790          return this.sourcePatientInfoTarget;
791        }
792
793        /**
794         * @param value {@link #sourcePatientInfo} 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. (The Patient Information as known when the document was published. May be a reference to a version specific, or contained.)
795         */
796        public DocumentReferenceContextComponent setSourcePatientInfoTarget(Patient value) { 
797          this.sourcePatientInfoTarget = value;
798          return this;
799        }
800
801        /**
802         * @return {@link #related} (Related identifiers or resources associated with the DocumentReference.)
803         */
804        public List<DocumentReferenceContextRelatedComponent> getRelated() { 
805          if (this.related == null)
806            this.related = new ArrayList<DocumentReferenceContextRelatedComponent>();
807          return this.related;
808        }
809
810        public boolean hasRelated() { 
811          if (this.related == null)
812            return false;
813          for (DocumentReferenceContextRelatedComponent item : this.related)
814            if (!item.isEmpty())
815              return true;
816          return false;
817        }
818
819        /**
820         * @return {@link #related} (Related identifiers or resources associated with the DocumentReference.)
821         */
822    // syntactic sugar
823        public DocumentReferenceContextRelatedComponent addRelated() { //3
824          DocumentReferenceContextRelatedComponent t = new DocumentReferenceContextRelatedComponent();
825          if (this.related == null)
826            this.related = new ArrayList<DocumentReferenceContextRelatedComponent>();
827          this.related.add(t);
828          return t;
829        }
830
831    // syntactic sugar
832        public DocumentReferenceContextComponent addRelated(DocumentReferenceContextRelatedComponent t) { //3
833          if (t == null)
834            return this;
835          if (this.related == null)
836            this.related = new ArrayList<DocumentReferenceContextRelatedComponent>();
837          this.related.add(t);
838          return this;
839        }
840
841        protected void listChildren(List<Property> childrenList) {
842          super.listChildren(childrenList);
843          childrenList.add(new Property("encounter", "Reference(Encounter)", "Describes the clinical encounter or type of care that the document content is associated with.", 0, java.lang.Integer.MAX_VALUE, encounter));
844          childrenList.add(new Property("event", "CodeableConcept", "This list of codes represents the main clinical acts, such as a colonoscopy or an appendectomy, being documented. In some cases, the event is inherent in the typeCode, such as a \"History and Physical Report\" in which the procedure being documented is necessarily a \"History and Physical\" act.", 0, java.lang.Integer.MAX_VALUE, event));
845          childrenList.add(new Property("period", "Period", "The time period over which the service that is described by the document was provided.", 0, java.lang.Integer.MAX_VALUE, period));
846          childrenList.add(new Property("facilityType", "CodeableConcept", "The kind of facility where the patient was seen.", 0, java.lang.Integer.MAX_VALUE, facilityType));
847          childrenList.add(new Property("practiceSetting", "CodeableConcept", "This property may convey specifics about the practice setting where the content was created, often reflecting the clinical specialty.", 0, java.lang.Integer.MAX_VALUE, practiceSetting));
848          childrenList.add(new Property("sourcePatientInfo", "Reference(Patient)", "The Patient Information as known when the document was published. May be a reference to a version specific, or contained.", 0, java.lang.Integer.MAX_VALUE, sourcePatientInfo));
849          childrenList.add(new Property("related", "", "Related identifiers or resources associated with the DocumentReference.", 0, java.lang.Integer.MAX_VALUE, related));
850        }
851
852      @Override
853      public void setProperty(String name, Base value) throws FHIRException {
854        if (name.equals("encounter"))
855          this.encounter = castToReference(value); // Reference
856        else if (name.equals("event"))
857          this.getEvent().add(castToCodeableConcept(value));
858        else if (name.equals("period"))
859          this.period = castToPeriod(value); // Period
860        else if (name.equals("facilityType"))
861          this.facilityType = castToCodeableConcept(value); // CodeableConcept
862        else if (name.equals("practiceSetting"))
863          this.practiceSetting = castToCodeableConcept(value); // CodeableConcept
864        else if (name.equals("sourcePatientInfo"))
865          this.sourcePatientInfo = castToReference(value); // Reference
866        else if (name.equals("related"))
867          this.getRelated().add((DocumentReferenceContextRelatedComponent) value);
868        else
869          super.setProperty(name, value);
870      }
871
872      @Override
873      public Base addChild(String name) throws FHIRException {
874        if (name.equals("encounter")) {
875          this.encounter = new Reference();
876          return this.encounter;
877        }
878        else if (name.equals("event")) {
879          return addEvent();
880        }
881        else if (name.equals("period")) {
882          this.period = new Period();
883          return this.period;
884        }
885        else if (name.equals("facilityType")) {
886          this.facilityType = new CodeableConcept();
887          return this.facilityType;
888        }
889        else if (name.equals("practiceSetting")) {
890          this.practiceSetting = new CodeableConcept();
891          return this.practiceSetting;
892        }
893        else if (name.equals("sourcePatientInfo")) {
894          this.sourcePatientInfo = new Reference();
895          return this.sourcePatientInfo;
896        }
897        else if (name.equals("related")) {
898          return addRelated();
899        }
900        else
901          return super.addChild(name);
902      }
903
904      public DocumentReferenceContextComponent copy() {
905        DocumentReferenceContextComponent dst = new DocumentReferenceContextComponent();
906        copyValues(dst);
907        dst.encounter = encounter == null ? null : encounter.copy();
908        if (event != null) {
909          dst.event = new ArrayList<CodeableConcept>();
910          for (CodeableConcept i : event)
911            dst.event.add(i.copy());
912        };
913        dst.period = period == null ? null : period.copy();
914        dst.facilityType = facilityType == null ? null : facilityType.copy();
915        dst.practiceSetting = practiceSetting == null ? null : practiceSetting.copy();
916        dst.sourcePatientInfo = sourcePatientInfo == null ? null : sourcePatientInfo.copy();
917        if (related != null) {
918          dst.related = new ArrayList<DocumentReferenceContextRelatedComponent>();
919          for (DocumentReferenceContextRelatedComponent i : related)
920            dst.related.add(i.copy());
921        };
922        return dst;
923      }
924
925      @Override
926      public boolean equalsDeep(Base other) {
927        if (!super.equalsDeep(other))
928          return false;
929        if (!(other instanceof DocumentReferenceContextComponent))
930          return false;
931        DocumentReferenceContextComponent o = (DocumentReferenceContextComponent) other;
932        return compareDeep(encounter, o.encounter, true) && compareDeep(event, o.event, true) && compareDeep(period, o.period, true)
933           && compareDeep(facilityType, o.facilityType, true) && compareDeep(practiceSetting, o.practiceSetting, true)
934           && compareDeep(sourcePatientInfo, o.sourcePatientInfo, true) && compareDeep(related, o.related, true)
935          ;
936      }
937
938      @Override
939      public boolean equalsShallow(Base other) {
940        if (!super.equalsShallow(other))
941          return false;
942        if (!(other instanceof DocumentReferenceContextComponent))
943          return false;
944        DocumentReferenceContextComponent o = (DocumentReferenceContextComponent) other;
945        return true;
946      }
947
948      public boolean isEmpty() {
949        return super.isEmpty() && (encounter == null || encounter.isEmpty()) && (event == null || event.isEmpty())
950           && (period == null || period.isEmpty()) && (facilityType == null || facilityType.isEmpty())
951           && (practiceSetting == null || practiceSetting.isEmpty()) && (sourcePatientInfo == null || sourcePatientInfo.isEmpty())
952           && (related == null || related.isEmpty());
953      }
954
955  public String fhirType() {
956    return "DocumentReference.context";
957
958  }
959
960  }
961
962    @Block()
963    public static class DocumentReferenceContextRelatedComponent extends BackboneElement implements IBaseBackboneElement {
964        /**
965         * Related identifier to this DocumentReference. If both id and ref are present they shall refer to the same thing.
966         */
967        @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=1, modifier=false, summary=true)
968        @Description(shortDefinition="Identifier of related objects or events", formalDefinition="Related identifier to this DocumentReference. If both id and ref are present they shall refer to the same thing." )
969        protected Identifier identifier;
970
971        /**
972         * Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.
973         */
974        @Child(name = "ref", type = {}, order=2, min=0, max=1, modifier=false, summary=true)
975        @Description(shortDefinition="Related Resource", formalDefinition="Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing." )
976        protected Reference ref;
977
978        /**
979         * The actual object that is the target of the reference (Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
980         */
981        protected Resource refTarget;
982
983        private static final long serialVersionUID = -1670123330L;
984
985    /*
986     * Constructor
987     */
988      public DocumentReferenceContextRelatedComponent() {
989        super();
990      }
991
992        /**
993         * @return {@link #identifier} (Related identifier to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
994         */
995        public Identifier getIdentifier() { 
996          if (this.identifier == null)
997            if (Configuration.errorOnAutoCreate())
998              throw new Error("Attempt to auto-create DocumentReferenceContextRelatedComponent.identifier");
999            else if (Configuration.doAutoCreate())
1000              this.identifier = new Identifier(); // cc
1001          return this.identifier;
1002        }
1003
1004        public boolean hasIdentifier() { 
1005          return this.identifier != null && !this.identifier.isEmpty();
1006        }
1007
1008        /**
1009         * @param value {@link #identifier} (Related identifier to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
1010         */
1011        public DocumentReferenceContextRelatedComponent setIdentifier(Identifier value) { 
1012          this.identifier = value;
1013          return this;
1014        }
1015
1016        /**
1017         * @return {@link #ref} (Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
1018         */
1019        public Reference getRef() { 
1020          if (this.ref == null)
1021            if (Configuration.errorOnAutoCreate())
1022              throw new Error("Attempt to auto-create DocumentReferenceContextRelatedComponent.ref");
1023            else if (Configuration.doAutoCreate())
1024              this.ref = new Reference(); // cc
1025          return this.ref;
1026        }
1027
1028        public boolean hasRef() { 
1029          return this.ref != null && !this.ref.isEmpty();
1030        }
1031
1032        /**
1033         * @param value {@link #ref} (Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
1034         */
1035        public DocumentReferenceContextRelatedComponent setRef(Reference value) { 
1036          this.ref = value;
1037          return this;
1038        }
1039
1040        /**
1041         * @return {@link #ref} 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. (Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
1042         */
1043        public Resource getRefTarget() { 
1044          return this.refTarget;
1045        }
1046
1047        /**
1048         * @param value {@link #ref} 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. (Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.)
1049         */
1050        public DocumentReferenceContextRelatedComponent setRefTarget(Resource value) { 
1051          this.refTarget = value;
1052          return this;
1053        }
1054
1055        protected void listChildren(List<Property> childrenList) {
1056          super.listChildren(childrenList);
1057          childrenList.add(new Property("identifier", "Identifier", "Related identifier to this DocumentReference. If both id and ref are present they shall refer to the same thing.", 0, java.lang.Integer.MAX_VALUE, identifier));
1058          childrenList.add(new Property("ref", "Reference(Any)", "Related Resource to this DocumentReference. If both id and ref are present they shall refer to the same thing.", 0, java.lang.Integer.MAX_VALUE, ref));
1059        }
1060
1061      @Override
1062      public void setProperty(String name, Base value) throws FHIRException {
1063        if (name.equals("identifier"))
1064          this.identifier = castToIdentifier(value); // Identifier
1065        else if (name.equals("ref"))
1066          this.ref = castToReference(value); // Reference
1067        else
1068          super.setProperty(name, value);
1069      }
1070
1071      @Override
1072      public Base addChild(String name) throws FHIRException {
1073        if (name.equals("identifier")) {
1074          this.identifier = new Identifier();
1075          return this.identifier;
1076        }
1077        else if (name.equals("ref")) {
1078          this.ref = new Reference();
1079          return this.ref;
1080        }
1081        else
1082          return super.addChild(name);
1083      }
1084
1085      public DocumentReferenceContextRelatedComponent copy() {
1086        DocumentReferenceContextRelatedComponent dst = new DocumentReferenceContextRelatedComponent();
1087        copyValues(dst);
1088        dst.identifier = identifier == null ? null : identifier.copy();
1089        dst.ref = ref == null ? null : ref.copy();
1090        return dst;
1091      }
1092
1093      @Override
1094      public boolean equalsDeep(Base other) {
1095        if (!super.equalsDeep(other))
1096          return false;
1097        if (!(other instanceof DocumentReferenceContextRelatedComponent))
1098          return false;
1099        DocumentReferenceContextRelatedComponent o = (DocumentReferenceContextRelatedComponent) other;
1100        return compareDeep(identifier, o.identifier, true) && compareDeep(ref, o.ref, true);
1101      }
1102
1103      @Override
1104      public boolean equalsShallow(Base other) {
1105        if (!super.equalsShallow(other))
1106          return false;
1107        if (!(other instanceof DocumentReferenceContextRelatedComponent))
1108          return false;
1109        DocumentReferenceContextRelatedComponent o = (DocumentReferenceContextRelatedComponent) other;
1110        return true;
1111      }
1112
1113      public boolean isEmpty() {
1114        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (ref == null || ref.isEmpty())
1115          ;
1116      }
1117
1118  public String fhirType() {
1119    return "DocumentReference.context.related";
1120
1121  }
1122
1123  }
1124
1125    /**
1126     * Document identifier as assigned by the source of the document. This identifier is specific to this version of the document. This unique identifier may be used elsewhere to identify this version of the document.
1127     */
1128    @Child(name = "masterIdentifier", type = {Identifier.class}, order=0, min=0, max=1, modifier=false, summary=true)
1129    @Description(shortDefinition="Master Version Specific Identifier", formalDefinition="Document identifier as assigned by the source of the document. This identifier is specific to this version of the document. This unique identifier may be used elsewhere to identify this version of the document." )
1130    protected Identifier masterIdentifier;
1131
1132    /**
1133     * Other identifiers associated with the document, including version independent identifiers.
1134     */
1135    @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1136    @Description(shortDefinition="Other identifiers for the document", formalDefinition="Other identifiers associated with the document, including version independent identifiers." )
1137    protected List<Identifier> identifier;
1138
1139    /**
1140     * Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).
1141     */
1142    @Child(name = "subject", type = {Patient.class, Practitioner.class, Group.class, Device.class}, order=2, min=0, max=1, modifier=false, summary=true)
1143    @Description(shortDefinition="Who/what is the subject of the document", formalDefinition="Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure)." )
1144    protected Reference subject;
1145
1146    /**
1147     * The actual object that is the target of the reference (Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).)
1148     */
1149    protected Resource subjectTarget;
1150
1151    /**
1152     * Specifies the particular kind of document referenced  (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced.
1153     */
1154    @Child(name = "type", type = {CodeableConcept.class}, order=3, min=1, max=1, modifier=false, summary=true)
1155    @Description(shortDefinition="Kind of document (LOINC if possible)", formalDefinition="Specifies the particular kind of document referenced  (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced." )
1156    protected CodeableConcept type;
1157
1158    /**
1159     * A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type.
1160     */
1161    @Child(name = "class", type = {CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
1162    @Description(shortDefinition="Categorization of document", formalDefinition="A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type." )
1163    protected CodeableConcept class_;
1164
1165    /**
1166     * Identifies who is responsible for adding the information to the document.
1167     */
1168    @Child(name = "author", type = {Practitioner.class, Organization.class, Device.class, Patient.class, RelatedPerson.class}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1169    @Description(shortDefinition="Who and/or what authored the document", formalDefinition="Identifies who is responsible for adding the information to the document." )
1170    protected List<Reference> author;
1171    /**
1172     * The actual objects that are the target of the reference (Identifies who is responsible for adding the information to the document.)
1173     */
1174    protected List<Resource> authorTarget;
1175
1176
1177    /**
1178     * Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.
1179     */
1180    @Child(name = "custodian", type = {Organization.class}, order=6, min=0, max=1, modifier=false, summary=true)
1181    @Description(shortDefinition="Organization which maintains the document", formalDefinition="Identifies the organization or group who is responsible for ongoing maintenance of and access to the document." )
1182    protected Reference custodian;
1183
1184    /**
1185     * The actual object that is the target of the reference (Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.)
1186     */
1187    protected Organization custodianTarget;
1188
1189    /**
1190     * Which person or organization authenticates that this document is valid.
1191     */
1192    @Child(name = "authenticator", type = {Practitioner.class, Organization.class}, order=7, min=0, max=1, modifier=false, summary=true)
1193    @Description(shortDefinition="Who/what authenticated the document", formalDefinition="Which person or organization authenticates that this document is valid." )
1194    protected Reference authenticator;
1195
1196    /**
1197     * The actual object that is the target of the reference (Which person or organization authenticates that this document is valid.)
1198     */
1199    protected Resource authenticatorTarget;
1200
1201    /**
1202     * When the document was created.
1203     */
1204    @Child(name = "created", type = {DateTimeType.class}, order=8, min=0, max=1, modifier=false, summary=true)
1205    @Description(shortDefinition="Document creation time", formalDefinition="When the document was created." )
1206    protected DateTimeType created;
1207
1208    /**
1209     * When the document reference was created.
1210     */
1211    @Child(name = "indexed", type = {InstantType.class}, order=9, min=1, max=1, modifier=false, summary=true)
1212    @Description(shortDefinition="When this document reference created", formalDefinition="When the document reference was created." )
1213    protected InstantType indexed;
1214
1215    /**
1216     * The status of this document reference.
1217     */
1218    @Child(name = "status", type = {CodeType.class}, order=10, min=1, max=1, modifier=true, summary=true)
1219    @Description(shortDefinition="current | superseded | entered-in-error", formalDefinition="The status of this document reference." )
1220    protected Enumeration<DocumentReferenceStatus> status;
1221
1222    /**
1223     * The status of the underlying document.
1224     */
1225    @Child(name = "docStatus", type = {CodeableConcept.class}, order=11, min=0, max=1, modifier=false, summary=true)
1226    @Description(shortDefinition="preliminary | final | appended | amended | entered-in-error", formalDefinition="The status of the underlying document." )
1227    protected CodeableConcept docStatus;
1228
1229    /**
1230     * Relationships that this document has with other document references that already exist.
1231     */
1232    @Child(name = "relatesTo", type = {}, order=12, min=0, max=Child.MAX_UNLIMITED, modifier=true, summary=true)
1233    @Description(shortDefinition="Relationships to other documents", formalDefinition="Relationships that this document has with other document references that already exist." )
1234    protected List<DocumentReferenceRelatesToComponent> relatesTo;
1235
1236    /**
1237     * Human-readable description of the source document. This is sometimes known as the "title".
1238     */
1239    @Child(name = "description", type = {StringType.class}, order=13, min=0, max=1, modifier=false, summary=true)
1240    @Description(shortDefinition="Human-readable description (title)", formalDefinition="Human-readable description of the source document. This is sometimes known as the \"title\"." )
1241    protected StringType description;
1242
1243    /**
1244     * A set of Security-Tag codes specifying the level of privacy/security of the Document. Note that DocumentReference.meta.security contains the security labels of the "reference" to the document, while DocumentReference.securityLabel contains a snapshot of the security labels on the document the reference refers to.
1245     */
1246    @Child(name = "securityLabel", type = {CodeableConcept.class}, order=14, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1247    @Description(shortDefinition="Document security-tags", formalDefinition="A set of Security-Tag codes specifying the level of privacy/security of the Document. Note that DocumentReference.meta.security contains the security labels of the \"reference\" to the document, while DocumentReference.securityLabel contains a snapshot of the security labels on the document the reference refers to." )
1248    protected List<CodeableConcept> securityLabel;
1249
1250    /**
1251     * The document and format referenced. There may be multiple content element repetitions, each with a different format.
1252     */
1253    @Child(name = "content", type = {}, order=15, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1254    @Description(shortDefinition="Document referenced", formalDefinition="The document and format referenced. There may be multiple content element repetitions, each with a different format." )
1255    protected List<DocumentReferenceContentComponent> content;
1256
1257    /**
1258     * The clinical context in which the document was prepared.
1259     */
1260    @Child(name = "context", type = {}, order=16, min=0, max=1, modifier=false, summary=true)
1261    @Description(shortDefinition="Clinical context of document", formalDefinition="The clinical context in which the document was prepared." )
1262    protected DocumentReferenceContextComponent context;
1263
1264    private static final long serialVersionUID = -1009325322L;
1265
1266  /*
1267   * Constructor
1268   */
1269    public DocumentReference() {
1270      super();
1271    }
1272
1273  /*
1274   * Constructor
1275   */
1276    public DocumentReference(CodeableConcept type, InstantType indexed, Enumeration<DocumentReferenceStatus> status) {
1277      super();
1278      this.type = type;
1279      this.indexed = indexed;
1280      this.status = status;
1281    }
1282
1283    /**
1284     * @return {@link #masterIdentifier} (Document identifier as assigned by the source of the document. This identifier is specific to this version of the document. This unique identifier may be used elsewhere to identify this version of the document.)
1285     */
1286    public Identifier getMasterIdentifier() { 
1287      if (this.masterIdentifier == null)
1288        if (Configuration.errorOnAutoCreate())
1289          throw new Error("Attempt to auto-create DocumentReference.masterIdentifier");
1290        else if (Configuration.doAutoCreate())
1291          this.masterIdentifier = new Identifier(); // cc
1292      return this.masterIdentifier;
1293    }
1294
1295    public boolean hasMasterIdentifier() { 
1296      return this.masterIdentifier != null && !this.masterIdentifier.isEmpty();
1297    }
1298
1299    /**
1300     * @param value {@link #masterIdentifier} (Document identifier as assigned by the source of the document. This identifier is specific to this version of the document. This unique identifier may be used elsewhere to identify this version of the document.)
1301     */
1302    public DocumentReference setMasterIdentifier(Identifier value) { 
1303      this.masterIdentifier = value;
1304      return this;
1305    }
1306
1307    /**
1308     * @return {@link #identifier} (Other identifiers associated with the document, including version independent identifiers.)
1309     */
1310    public List<Identifier> getIdentifier() { 
1311      if (this.identifier == null)
1312        this.identifier = new ArrayList<Identifier>();
1313      return this.identifier;
1314    }
1315
1316    public boolean hasIdentifier() { 
1317      if (this.identifier == null)
1318        return false;
1319      for (Identifier item : this.identifier)
1320        if (!item.isEmpty())
1321          return true;
1322      return false;
1323    }
1324
1325    /**
1326     * @return {@link #identifier} (Other identifiers associated with the document, including version independent identifiers.)
1327     */
1328    // syntactic sugar
1329    public Identifier addIdentifier() { //3
1330      Identifier t = new Identifier();
1331      if (this.identifier == null)
1332        this.identifier = new ArrayList<Identifier>();
1333      this.identifier.add(t);
1334      return t;
1335    }
1336
1337    // syntactic sugar
1338    public DocumentReference addIdentifier(Identifier t) { //3
1339      if (t == null)
1340        return this;
1341      if (this.identifier == null)
1342        this.identifier = new ArrayList<Identifier>();
1343      this.identifier.add(t);
1344      return this;
1345    }
1346
1347    /**
1348     * @return {@link #subject} (Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).)
1349     */
1350    public Reference getSubject() { 
1351      if (this.subject == null)
1352        if (Configuration.errorOnAutoCreate())
1353          throw new Error("Attempt to auto-create DocumentReference.subject");
1354        else if (Configuration.doAutoCreate())
1355          this.subject = new Reference(); // cc
1356      return this.subject;
1357    }
1358
1359    public boolean hasSubject() { 
1360      return this.subject != null && !this.subject.isEmpty();
1361    }
1362
1363    /**
1364     * @param value {@link #subject} (Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).)
1365     */
1366    public DocumentReference setSubject(Reference value) { 
1367      this.subject = value;
1368      return this;
1369    }
1370
1371    /**
1372     * @return {@link #subject} 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. (Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).)
1373     */
1374    public Resource getSubjectTarget() { 
1375      return this.subjectTarget;
1376    }
1377
1378    /**
1379     * @param value {@link #subject} 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. (Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).)
1380     */
1381    public DocumentReference setSubjectTarget(Resource value) { 
1382      this.subjectTarget = value;
1383      return this;
1384    }
1385
1386    /**
1387     * @return {@link #type} (Specifies the particular kind of document referenced  (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced.)
1388     */
1389    public CodeableConcept getType() { 
1390      if (this.type == null)
1391        if (Configuration.errorOnAutoCreate())
1392          throw new Error("Attempt to auto-create DocumentReference.type");
1393        else if (Configuration.doAutoCreate())
1394          this.type = new CodeableConcept(); // cc
1395      return this.type;
1396    }
1397
1398    public boolean hasType() { 
1399      return this.type != null && !this.type.isEmpty();
1400    }
1401
1402    /**
1403     * @param value {@link #type} (Specifies the particular kind of document referenced  (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced.)
1404     */
1405    public DocumentReference setType(CodeableConcept value) { 
1406      this.type = value;
1407      return this;
1408    }
1409
1410    /**
1411     * @return {@link #class_} (A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type.)
1412     */
1413    public CodeableConcept getClass_() { 
1414      if (this.class_ == null)
1415        if (Configuration.errorOnAutoCreate())
1416          throw new Error("Attempt to auto-create DocumentReference.class_");
1417        else if (Configuration.doAutoCreate())
1418          this.class_ = new CodeableConcept(); // cc
1419      return this.class_;
1420    }
1421
1422    public boolean hasClass_() { 
1423      return this.class_ != null && !this.class_.isEmpty();
1424    }
1425
1426    /**
1427     * @param value {@link #class_} (A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type.)
1428     */
1429    public DocumentReference setClass_(CodeableConcept value) { 
1430      this.class_ = value;
1431      return this;
1432    }
1433
1434    /**
1435     * @return {@link #author} (Identifies who is responsible for adding the information to the document.)
1436     */
1437    public List<Reference> getAuthor() { 
1438      if (this.author == null)
1439        this.author = new ArrayList<Reference>();
1440      return this.author;
1441    }
1442
1443    public boolean hasAuthor() { 
1444      if (this.author == null)
1445        return false;
1446      for (Reference item : this.author)
1447        if (!item.isEmpty())
1448          return true;
1449      return false;
1450    }
1451
1452    /**
1453     * @return {@link #author} (Identifies who is responsible for adding the information to the document.)
1454     */
1455    // syntactic sugar
1456    public Reference addAuthor() { //3
1457      Reference t = new Reference();
1458      if (this.author == null)
1459        this.author = new ArrayList<Reference>();
1460      this.author.add(t);
1461      return t;
1462    }
1463
1464    // syntactic sugar
1465    public DocumentReference addAuthor(Reference t) { //3
1466      if (t == null)
1467        return this;
1468      if (this.author == null)
1469        this.author = new ArrayList<Reference>();
1470      this.author.add(t);
1471      return this;
1472    }
1473
1474    /**
1475     * @return {@link #author} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. Identifies who is responsible for adding the information to the document.)
1476     */
1477    public List<Resource> getAuthorTarget() { 
1478      if (this.authorTarget == null)
1479        this.authorTarget = new ArrayList<Resource>();
1480      return this.authorTarget;
1481    }
1482
1483    /**
1484     * @return {@link #custodian} (Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.)
1485     */
1486    public Reference getCustodian() { 
1487      if (this.custodian == null)
1488        if (Configuration.errorOnAutoCreate())
1489          throw new Error("Attempt to auto-create DocumentReference.custodian");
1490        else if (Configuration.doAutoCreate())
1491          this.custodian = new Reference(); // cc
1492      return this.custodian;
1493    }
1494
1495    public boolean hasCustodian() { 
1496      return this.custodian != null && !this.custodian.isEmpty();
1497    }
1498
1499    /**
1500     * @param value {@link #custodian} (Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.)
1501     */
1502    public DocumentReference setCustodian(Reference value) { 
1503      this.custodian = value;
1504      return this;
1505    }
1506
1507    /**
1508     * @return {@link #custodian} 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. (Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.)
1509     */
1510    public Organization getCustodianTarget() { 
1511      if (this.custodianTarget == null)
1512        if (Configuration.errorOnAutoCreate())
1513          throw new Error("Attempt to auto-create DocumentReference.custodian");
1514        else if (Configuration.doAutoCreate())
1515          this.custodianTarget = new Organization(); // aa
1516      return this.custodianTarget;
1517    }
1518
1519    /**
1520     * @param value {@link #custodian} 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. (Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.)
1521     */
1522    public DocumentReference setCustodianTarget(Organization value) { 
1523      this.custodianTarget = value;
1524      return this;
1525    }
1526
1527    /**
1528     * @return {@link #authenticator} (Which person or organization authenticates that this document is valid.)
1529     */
1530    public Reference getAuthenticator() { 
1531      if (this.authenticator == null)
1532        if (Configuration.errorOnAutoCreate())
1533          throw new Error("Attempt to auto-create DocumentReference.authenticator");
1534        else if (Configuration.doAutoCreate())
1535          this.authenticator = new Reference(); // cc
1536      return this.authenticator;
1537    }
1538
1539    public boolean hasAuthenticator() { 
1540      return this.authenticator != null && !this.authenticator.isEmpty();
1541    }
1542
1543    /**
1544     * @param value {@link #authenticator} (Which person or organization authenticates that this document is valid.)
1545     */
1546    public DocumentReference setAuthenticator(Reference value) { 
1547      this.authenticator = value;
1548      return this;
1549    }
1550
1551    /**
1552     * @return {@link #authenticator} 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. (Which person or organization authenticates that this document is valid.)
1553     */
1554    public Resource getAuthenticatorTarget() { 
1555      return this.authenticatorTarget;
1556    }
1557
1558    /**
1559     * @param value {@link #authenticator} 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. (Which person or organization authenticates that this document is valid.)
1560     */
1561    public DocumentReference setAuthenticatorTarget(Resource value) { 
1562      this.authenticatorTarget = value;
1563      return this;
1564    }
1565
1566    /**
1567     * @return {@link #created} (When the document was created.). This is the underlying object with id, value and extensions. The accessor "getCreated" gives direct access to the value
1568     */
1569    public DateTimeType getCreatedElement() { 
1570      if (this.created == null)
1571        if (Configuration.errorOnAutoCreate())
1572          throw new Error("Attempt to auto-create DocumentReference.created");
1573        else if (Configuration.doAutoCreate())
1574          this.created = new DateTimeType(); // bb
1575      return this.created;
1576    }
1577
1578    public boolean hasCreatedElement() { 
1579      return this.created != null && !this.created.isEmpty();
1580    }
1581
1582    public boolean hasCreated() { 
1583      return this.created != null && !this.created.isEmpty();
1584    }
1585
1586    /**
1587     * @param value {@link #created} (When the document was created.). This is the underlying object with id, value and extensions. The accessor "getCreated" gives direct access to the value
1588     */
1589    public DocumentReference setCreatedElement(DateTimeType value) { 
1590      this.created = value;
1591      return this;
1592    }
1593
1594    /**
1595     * @return When the document was created.
1596     */
1597    public Date getCreated() { 
1598      return this.created == null ? null : this.created.getValue();
1599    }
1600
1601    /**
1602     * @param value When the document was created.
1603     */
1604    public DocumentReference setCreated(Date value) { 
1605      if (value == null)
1606        this.created = null;
1607      else {
1608        if (this.created == null)
1609          this.created = new DateTimeType();
1610        this.created.setValue(value);
1611      }
1612      return this;
1613    }
1614
1615    /**
1616     * @return {@link #indexed} (When the document reference was created.). This is the underlying object with id, value and extensions. The accessor "getIndexed" gives direct access to the value
1617     */
1618    public InstantType getIndexedElement() { 
1619      if (this.indexed == null)
1620        if (Configuration.errorOnAutoCreate())
1621          throw new Error("Attempt to auto-create DocumentReference.indexed");
1622        else if (Configuration.doAutoCreate())
1623          this.indexed = new InstantType(); // bb
1624      return this.indexed;
1625    }
1626
1627    public boolean hasIndexedElement() { 
1628      return this.indexed != null && !this.indexed.isEmpty();
1629    }
1630
1631    public boolean hasIndexed() { 
1632      return this.indexed != null && !this.indexed.isEmpty();
1633    }
1634
1635    /**
1636     * @param value {@link #indexed} (When the document reference was created.). This is the underlying object with id, value and extensions. The accessor "getIndexed" gives direct access to the value
1637     */
1638    public DocumentReference setIndexedElement(InstantType value) { 
1639      this.indexed = value;
1640      return this;
1641    }
1642
1643    /**
1644     * @return When the document reference was created.
1645     */
1646    public Date getIndexed() { 
1647      return this.indexed == null ? null : this.indexed.getValue();
1648    }
1649
1650    /**
1651     * @param value When the document reference was created.
1652     */
1653    public DocumentReference setIndexed(Date value) { 
1654        if (this.indexed == null)
1655          this.indexed = new InstantType();
1656        this.indexed.setValue(value);
1657      return this;
1658    }
1659
1660    /**
1661     * @return {@link #status} (The status of this document reference.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1662     */
1663    public Enumeration<DocumentReferenceStatus> getStatusElement() { 
1664      if (this.status == null)
1665        if (Configuration.errorOnAutoCreate())
1666          throw new Error("Attempt to auto-create DocumentReference.status");
1667        else if (Configuration.doAutoCreate())
1668          this.status = new Enumeration<DocumentReferenceStatus>(new DocumentReferenceStatusEnumFactory()); // bb
1669      return this.status;
1670    }
1671
1672    public boolean hasStatusElement() { 
1673      return this.status != null && !this.status.isEmpty();
1674    }
1675
1676    public boolean hasStatus() { 
1677      return this.status != null && !this.status.isEmpty();
1678    }
1679
1680    /**
1681     * @param value {@link #status} (The status of this document reference.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1682     */
1683    public DocumentReference setStatusElement(Enumeration<DocumentReferenceStatus> value) { 
1684      this.status = value;
1685      return this;
1686    }
1687
1688    /**
1689     * @return The status of this document reference.
1690     */
1691    public DocumentReferenceStatus getStatus() { 
1692      return this.status == null ? null : this.status.getValue();
1693    }
1694
1695    /**
1696     * @param value The status of this document reference.
1697     */
1698    public DocumentReference setStatus(DocumentReferenceStatus value) { 
1699        if (this.status == null)
1700          this.status = new Enumeration<DocumentReferenceStatus>(new DocumentReferenceStatusEnumFactory());
1701        this.status.setValue(value);
1702      return this;
1703    }
1704
1705    /**
1706     * @return {@link #docStatus} (The status of the underlying document.)
1707     */
1708    public CodeableConcept getDocStatus() { 
1709      if (this.docStatus == null)
1710        if (Configuration.errorOnAutoCreate())
1711          throw new Error("Attempt to auto-create DocumentReference.docStatus");
1712        else if (Configuration.doAutoCreate())
1713          this.docStatus = new CodeableConcept(); // cc
1714      return this.docStatus;
1715    }
1716
1717    public boolean hasDocStatus() { 
1718      return this.docStatus != null && !this.docStatus.isEmpty();
1719    }
1720
1721    /**
1722     * @param value {@link #docStatus} (The status of the underlying document.)
1723     */
1724    public DocumentReference setDocStatus(CodeableConcept value) { 
1725      this.docStatus = value;
1726      return this;
1727    }
1728
1729    /**
1730     * @return {@link #relatesTo} (Relationships that this document has with other document references that already exist.)
1731     */
1732    public List<DocumentReferenceRelatesToComponent> getRelatesTo() { 
1733      if (this.relatesTo == null)
1734        this.relatesTo = new ArrayList<DocumentReferenceRelatesToComponent>();
1735      return this.relatesTo;
1736    }
1737
1738    public boolean hasRelatesTo() { 
1739      if (this.relatesTo == null)
1740        return false;
1741      for (DocumentReferenceRelatesToComponent item : this.relatesTo)
1742        if (!item.isEmpty())
1743          return true;
1744      return false;
1745    }
1746
1747    /**
1748     * @return {@link #relatesTo} (Relationships that this document has with other document references that already exist.)
1749     */
1750    // syntactic sugar
1751    public DocumentReferenceRelatesToComponent addRelatesTo() { //3
1752      DocumentReferenceRelatesToComponent t = new DocumentReferenceRelatesToComponent();
1753      if (this.relatesTo == null)
1754        this.relatesTo = new ArrayList<DocumentReferenceRelatesToComponent>();
1755      this.relatesTo.add(t);
1756      return t;
1757    }
1758
1759    // syntactic sugar
1760    public DocumentReference addRelatesTo(DocumentReferenceRelatesToComponent t) { //3
1761      if (t == null)
1762        return this;
1763      if (this.relatesTo == null)
1764        this.relatesTo = new ArrayList<DocumentReferenceRelatesToComponent>();
1765      this.relatesTo.add(t);
1766      return this;
1767    }
1768
1769    /**
1770     * @return {@link #description} (Human-readable description of the source document. This is sometimes known as the "title".). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value
1771     */
1772    public StringType getDescriptionElement() { 
1773      if (this.description == null)
1774        if (Configuration.errorOnAutoCreate())
1775          throw new Error("Attempt to auto-create DocumentReference.description");
1776        else if (Configuration.doAutoCreate())
1777          this.description = new StringType(); // bb
1778      return this.description;
1779    }
1780
1781    public boolean hasDescriptionElement() { 
1782      return this.description != null && !this.description.isEmpty();
1783    }
1784
1785    public boolean hasDescription() { 
1786      return this.description != null && !this.description.isEmpty();
1787    }
1788
1789    /**
1790     * @param value {@link #description} (Human-readable description of the source document. This is sometimes known as the "title".). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value
1791     */
1792    public DocumentReference setDescriptionElement(StringType value) { 
1793      this.description = value;
1794      return this;
1795    }
1796
1797    /**
1798     * @return Human-readable description of the source document. This is sometimes known as the "title".
1799     */
1800    public String getDescription() { 
1801      return this.description == null ? null : this.description.getValue();
1802    }
1803
1804    /**
1805     * @param value Human-readable description of the source document. This is sometimes known as the "title".
1806     */
1807    public DocumentReference setDescription(String value) { 
1808      if (Utilities.noString(value))
1809        this.description = null;
1810      else {
1811        if (this.description == null)
1812          this.description = new StringType();
1813        this.description.setValue(value);
1814      }
1815      return this;
1816    }
1817
1818    /**
1819     * @return {@link #securityLabel} (A set of Security-Tag codes specifying the level of privacy/security of the Document. Note that DocumentReference.meta.security contains the security labels of the "reference" to the document, while DocumentReference.securityLabel contains a snapshot of the security labels on the document the reference refers to.)
1820     */
1821    public List<CodeableConcept> getSecurityLabel() { 
1822      if (this.securityLabel == null)
1823        this.securityLabel = new ArrayList<CodeableConcept>();
1824      return this.securityLabel;
1825    }
1826
1827    public boolean hasSecurityLabel() { 
1828      if (this.securityLabel == null)
1829        return false;
1830      for (CodeableConcept item : this.securityLabel)
1831        if (!item.isEmpty())
1832          return true;
1833      return false;
1834    }
1835
1836    /**
1837     * @return {@link #securityLabel} (A set of Security-Tag codes specifying the level of privacy/security of the Document. Note that DocumentReference.meta.security contains the security labels of the "reference" to the document, while DocumentReference.securityLabel contains a snapshot of the security labels on the document the reference refers to.)
1838     */
1839    // syntactic sugar
1840    public CodeableConcept addSecurityLabel() { //3
1841      CodeableConcept t = new CodeableConcept();
1842      if (this.securityLabel == null)
1843        this.securityLabel = new ArrayList<CodeableConcept>();
1844      this.securityLabel.add(t);
1845      return t;
1846    }
1847
1848    // syntactic sugar
1849    public DocumentReference addSecurityLabel(CodeableConcept t) { //3
1850      if (t == null)
1851        return this;
1852      if (this.securityLabel == null)
1853        this.securityLabel = new ArrayList<CodeableConcept>();
1854      this.securityLabel.add(t);
1855      return this;
1856    }
1857
1858    /**
1859     * @return {@link #content} (The document and format referenced. There may be multiple content element repetitions, each with a different format.)
1860     */
1861    public List<DocumentReferenceContentComponent> getContent() { 
1862      if (this.content == null)
1863        this.content = new ArrayList<DocumentReferenceContentComponent>();
1864      return this.content;
1865    }
1866
1867    public boolean hasContent() { 
1868      if (this.content == null)
1869        return false;
1870      for (DocumentReferenceContentComponent item : this.content)
1871        if (!item.isEmpty())
1872          return true;
1873      return false;
1874    }
1875
1876    /**
1877     * @return {@link #content} (The document and format referenced. There may be multiple content element repetitions, each with a different format.)
1878     */
1879    // syntactic sugar
1880    public DocumentReferenceContentComponent addContent() { //3
1881      DocumentReferenceContentComponent t = new DocumentReferenceContentComponent();
1882      if (this.content == null)
1883        this.content = new ArrayList<DocumentReferenceContentComponent>();
1884      this.content.add(t);
1885      return t;
1886    }
1887
1888    // syntactic sugar
1889    public DocumentReference addContent(DocumentReferenceContentComponent t) { //3
1890      if (t == null)
1891        return this;
1892      if (this.content == null)
1893        this.content = new ArrayList<DocumentReferenceContentComponent>();
1894      this.content.add(t);
1895      return this;
1896    }
1897
1898    /**
1899     * @return {@link #context} (The clinical context in which the document was prepared.)
1900     */
1901    public DocumentReferenceContextComponent getContext() { 
1902      if (this.context == null)
1903        if (Configuration.errorOnAutoCreate())
1904          throw new Error("Attempt to auto-create DocumentReference.context");
1905        else if (Configuration.doAutoCreate())
1906          this.context = new DocumentReferenceContextComponent(); // cc
1907      return this.context;
1908    }
1909
1910    public boolean hasContext() { 
1911      return this.context != null && !this.context.isEmpty();
1912    }
1913
1914    /**
1915     * @param value {@link #context} (The clinical context in which the document was prepared.)
1916     */
1917    public DocumentReference setContext(DocumentReferenceContextComponent value) { 
1918      this.context = value;
1919      return this;
1920    }
1921
1922      protected void listChildren(List<Property> childrenList) {
1923        super.listChildren(childrenList);
1924        childrenList.add(new Property("masterIdentifier", "Identifier", "Document identifier as assigned by the source of the document. This identifier is specific to this version of the document. This unique identifier may be used elsewhere to identify this version of the document.", 0, java.lang.Integer.MAX_VALUE, masterIdentifier));
1925        childrenList.add(new Property("identifier", "Identifier", "Other identifiers associated with the document, including version independent identifiers.", 0, java.lang.Integer.MAX_VALUE, identifier));
1926        childrenList.add(new Property("subject", "Reference(Patient|Practitioner|Group|Device)", "Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).", 0, java.lang.Integer.MAX_VALUE, subject));
1927        childrenList.add(new Property("type", "CodeableConcept", "Specifies the particular kind of document referenced  (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced.", 0, java.lang.Integer.MAX_VALUE, type));
1928        childrenList.add(new Property("class", "CodeableConcept", "A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type.", 0, java.lang.Integer.MAX_VALUE, class_));
1929        childrenList.add(new Property("author", "Reference(Practitioner|Organization|Device|Patient|RelatedPerson)", "Identifies who is responsible for adding the information to the document.", 0, java.lang.Integer.MAX_VALUE, author));
1930        childrenList.add(new Property("custodian", "Reference(Organization)", "Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.", 0, java.lang.Integer.MAX_VALUE, custodian));
1931        childrenList.add(new Property("authenticator", "Reference(Practitioner|Organization)", "Which person or organization authenticates that this document is valid.", 0, java.lang.Integer.MAX_VALUE, authenticator));
1932        childrenList.add(new Property("created", "dateTime", "When the document was created.", 0, java.lang.Integer.MAX_VALUE, created));
1933        childrenList.add(new Property("indexed", "instant", "When the document reference was created.", 0, java.lang.Integer.MAX_VALUE, indexed));
1934        childrenList.add(new Property("status", "code", "The status of this document reference.", 0, java.lang.Integer.MAX_VALUE, status));
1935        childrenList.add(new Property("docStatus", "CodeableConcept", "The status of the underlying document.", 0, java.lang.Integer.MAX_VALUE, docStatus));
1936        childrenList.add(new Property("relatesTo", "", "Relationships that this document has with other document references that already exist.", 0, java.lang.Integer.MAX_VALUE, relatesTo));
1937        childrenList.add(new Property("description", "string", "Human-readable description of the source document. This is sometimes known as the \"title\".", 0, java.lang.Integer.MAX_VALUE, description));
1938        childrenList.add(new Property("securityLabel", "CodeableConcept", "A set of Security-Tag codes specifying the level of privacy/security of the Document. Note that DocumentReference.meta.security contains the security labels of the \"reference\" to the document, while DocumentReference.securityLabel contains a snapshot of the security labels on the document the reference refers to.", 0, java.lang.Integer.MAX_VALUE, securityLabel));
1939        childrenList.add(new Property("content", "", "The document and format referenced. There may be multiple content element repetitions, each with a different format.", 0, java.lang.Integer.MAX_VALUE, content));
1940        childrenList.add(new Property("context", "", "The clinical context in which the document was prepared.", 0, java.lang.Integer.MAX_VALUE, context));
1941      }
1942
1943      @Override
1944      public void setProperty(String name, Base value) throws FHIRException {
1945        if (name.equals("masterIdentifier"))
1946          this.masterIdentifier = castToIdentifier(value); // Identifier
1947        else if (name.equals("identifier"))
1948          this.getIdentifier().add(castToIdentifier(value));
1949        else if (name.equals("subject"))
1950          this.subject = castToReference(value); // Reference
1951        else if (name.equals("type"))
1952          this.type = castToCodeableConcept(value); // CodeableConcept
1953        else if (name.equals("class"))
1954          this.class_ = castToCodeableConcept(value); // CodeableConcept
1955        else if (name.equals("author"))
1956          this.getAuthor().add(castToReference(value));
1957        else if (name.equals("custodian"))
1958          this.custodian = castToReference(value); // Reference
1959        else if (name.equals("authenticator"))
1960          this.authenticator = castToReference(value); // Reference
1961        else if (name.equals("created"))
1962          this.created = castToDateTime(value); // DateTimeType
1963        else if (name.equals("indexed"))
1964          this.indexed = castToInstant(value); // InstantType
1965        else if (name.equals("status"))
1966          this.status = new DocumentReferenceStatusEnumFactory().fromType(value); // Enumeration<DocumentReferenceStatus>
1967        else if (name.equals("docStatus"))
1968          this.docStatus = castToCodeableConcept(value); // CodeableConcept
1969        else if (name.equals("relatesTo"))
1970          this.getRelatesTo().add((DocumentReferenceRelatesToComponent) value);
1971        else if (name.equals("description"))
1972          this.description = castToString(value); // StringType
1973        else if (name.equals("securityLabel"))
1974          this.getSecurityLabel().add(castToCodeableConcept(value));
1975        else if (name.equals("content"))
1976          this.getContent().add((DocumentReferenceContentComponent) value);
1977        else if (name.equals("context"))
1978          this.context = (DocumentReferenceContextComponent) value; // DocumentReferenceContextComponent
1979        else
1980          super.setProperty(name, value);
1981      }
1982
1983      @Override
1984      public Base addChild(String name) throws FHIRException {
1985        if (name.equals("masterIdentifier")) {
1986          this.masterIdentifier = new Identifier();
1987          return this.masterIdentifier;
1988        }
1989        else if (name.equals("identifier")) {
1990          return addIdentifier();
1991        }
1992        else if (name.equals("subject")) {
1993          this.subject = new Reference();
1994          return this.subject;
1995        }
1996        else if (name.equals("type")) {
1997          this.type = new CodeableConcept();
1998          return this.type;
1999        }
2000        else if (name.equals("class")) {
2001          this.class_ = new CodeableConcept();
2002          return this.class_;
2003        }
2004        else if (name.equals("author")) {
2005          return addAuthor();
2006        }
2007        else if (name.equals("custodian")) {
2008          this.custodian = new Reference();
2009          return this.custodian;
2010        }
2011        else if (name.equals("authenticator")) {
2012          this.authenticator = new Reference();
2013          return this.authenticator;
2014        }
2015        else if (name.equals("created")) {
2016          throw new FHIRException("Cannot call addChild on a primitive type DocumentReference.created");
2017        }
2018        else if (name.equals("indexed")) {
2019          throw new FHIRException("Cannot call addChild on a primitive type DocumentReference.indexed");
2020        }
2021        else if (name.equals("status")) {
2022          throw new FHIRException("Cannot call addChild on a primitive type DocumentReference.status");
2023        }
2024        else if (name.equals("docStatus")) {
2025          this.docStatus = new CodeableConcept();
2026          return this.docStatus;
2027        }
2028        else if (name.equals("relatesTo")) {
2029          return addRelatesTo();
2030        }
2031        else if (name.equals("description")) {
2032          throw new FHIRException("Cannot call addChild on a primitive type DocumentReference.description");
2033        }
2034        else if (name.equals("securityLabel")) {
2035          return addSecurityLabel();
2036        }
2037        else if (name.equals("content")) {
2038          return addContent();
2039        }
2040        else if (name.equals("context")) {
2041          this.context = new DocumentReferenceContextComponent();
2042          return this.context;
2043        }
2044        else
2045          return super.addChild(name);
2046      }
2047
2048  public String fhirType() {
2049    return "DocumentReference";
2050
2051  }
2052
2053      public DocumentReference copy() {
2054        DocumentReference dst = new DocumentReference();
2055        copyValues(dst);
2056        dst.masterIdentifier = masterIdentifier == null ? null : masterIdentifier.copy();
2057        if (identifier != null) {
2058          dst.identifier = new ArrayList<Identifier>();
2059          for (Identifier i : identifier)
2060            dst.identifier.add(i.copy());
2061        };
2062        dst.subject = subject == null ? null : subject.copy();
2063        dst.type = type == null ? null : type.copy();
2064        dst.class_ = class_ == null ? null : class_.copy();
2065        if (author != null) {
2066          dst.author = new ArrayList<Reference>();
2067          for (Reference i : author)
2068            dst.author.add(i.copy());
2069        };
2070        dst.custodian = custodian == null ? null : custodian.copy();
2071        dst.authenticator = authenticator == null ? null : authenticator.copy();
2072        dst.created = created == null ? null : created.copy();
2073        dst.indexed = indexed == null ? null : indexed.copy();
2074        dst.status = status == null ? null : status.copy();
2075        dst.docStatus = docStatus == null ? null : docStatus.copy();
2076        if (relatesTo != null) {
2077          dst.relatesTo = new ArrayList<DocumentReferenceRelatesToComponent>();
2078          for (DocumentReferenceRelatesToComponent i : relatesTo)
2079            dst.relatesTo.add(i.copy());
2080        };
2081        dst.description = description == null ? null : description.copy();
2082        if (securityLabel != null) {
2083          dst.securityLabel = new ArrayList<CodeableConcept>();
2084          for (CodeableConcept i : securityLabel)
2085            dst.securityLabel.add(i.copy());
2086        };
2087        if (content != null) {
2088          dst.content = new ArrayList<DocumentReferenceContentComponent>();
2089          for (DocumentReferenceContentComponent i : content)
2090            dst.content.add(i.copy());
2091        };
2092        dst.context = context == null ? null : context.copy();
2093        return dst;
2094      }
2095
2096      protected DocumentReference typedCopy() {
2097        return copy();
2098      }
2099
2100      @Override
2101      public boolean equalsDeep(Base other) {
2102        if (!super.equalsDeep(other))
2103          return false;
2104        if (!(other instanceof DocumentReference))
2105          return false;
2106        DocumentReference o = (DocumentReference) other;
2107        return compareDeep(masterIdentifier, o.masterIdentifier, true) && compareDeep(identifier, o.identifier, true)
2108           && compareDeep(subject, o.subject, true) && compareDeep(type, o.type, true) && compareDeep(class_, o.class_, true)
2109           && compareDeep(author, o.author, true) && compareDeep(custodian, o.custodian, true) && compareDeep(authenticator, o.authenticator, true)
2110           && compareDeep(created, o.created, true) && compareDeep(indexed, o.indexed, true) && compareDeep(status, o.status, true)
2111           && compareDeep(docStatus, o.docStatus, true) && compareDeep(relatesTo, o.relatesTo, true) && compareDeep(description, o.description, true)
2112           && compareDeep(securityLabel, o.securityLabel, true) && compareDeep(content, o.content, true) && compareDeep(context, o.context, true)
2113          ;
2114      }
2115
2116      @Override
2117      public boolean equalsShallow(Base other) {
2118        if (!super.equalsShallow(other))
2119          return false;
2120        if (!(other instanceof DocumentReference))
2121          return false;
2122        DocumentReference o = (DocumentReference) other;
2123        return compareValues(created, o.created, true) && compareValues(indexed, o.indexed, true) && compareValues(status, o.status, true)
2124           && compareValues(description, o.description, true);
2125      }
2126
2127      public boolean isEmpty() {
2128        return super.isEmpty() && (masterIdentifier == null || masterIdentifier.isEmpty()) && (identifier == null || identifier.isEmpty())
2129           && (subject == null || subject.isEmpty()) && (type == null || type.isEmpty()) && (class_ == null || class_.isEmpty())
2130           && (author == null || author.isEmpty()) && (custodian == null || custodian.isEmpty()) && (authenticator == null || authenticator.isEmpty())
2131           && (created == null || created.isEmpty()) && (indexed == null || indexed.isEmpty()) && (status == null || status.isEmpty())
2132           && (docStatus == null || docStatus.isEmpty()) && (relatesTo == null || relatesTo.isEmpty())
2133           && (description == null || description.isEmpty()) && (securityLabel == null || securityLabel.isEmpty())
2134           && (content == null || content.isEmpty()) && (context == null || context.isEmpty());
2135      }
2136
2137  @Override
2138  public ResourceType getResourceType() {
2139    return ResourceType.DocumentReference;
2140   }
2141
2142  @SearchParamDefinition(name="securitylabel", path="DocumentReference.securityLabel", description="Document security-tags", type="token" )
2143  public static final String SP_SECURITYLABEL = "securitylabel";
2144  @SearchParamDefinition(name="subject", path="DocumentReference.subject", description="Who/what is the subject of the document", type="reference" )
2145  public static final String SP_SUBJECT = "subject";
2146  @SearchParamDefinition(name="description", path="DocumentReference.description", description="Human-readable description (title)", type="string" )
2147  public static final String SP_DESCRIPTION = "description";
2148  @SearchParamDefinition(name="language", path="DocumentReference.content.attachment.language", description="Human language of the content (BCP-47)", type="token" )
2149  public static final String SP_LANGUAGE = "language";
2150  @SearchParamDefinition(name="type", path="DocumentReference.type", description="Kind of document (LOINC if possible)", type="token" )
2151  public static final String SP_TYPE = "type";
2152  @SearchParamDefinition(name="relation", path="DocumentReference.relatesTo.code", description="replaces | transforms | signs | appends", type="token" )
2153  public static final String SP_RELATION = "relation";
2154  @SearchParamDefinition(name="setting", path="DocumentReference.context.practiceSetting", description="Additional details about where the content was created (e.g. clinical specialty)", type="token" )
2155  public static final String SP_SETTING = "setting";
2156  @SearchParamDefinition(name="patient", path="DocumentReference.subject", description="Who/what is the subject of the document", type="reference" )
2157  public static final String SP_PATIENT = "patient";
2158  @SearchParamDefinition(name="relationship", path="null", description="Combination of relation and relatesTo", type="composite" )
2159  public static final String SP_RELATIONSHIP = "relationship";
2160  @SearchParamDefinition(name="event", path="DocumentReference.context.event", description="Main Clinical Acts Documented", type="token" )
2161  public static final String SP_EVENT = "event";
2162  @SearchParamDefinition(name="class", path="DocumentReference.class", description="Categorization of document", type="token" )
2163  public static final String SP_CLASS = "class";
2164  @SearchParamDefinition(name="authenticator", path="DocumentReference.authenticator", description="Who/what authenticated the document", type="reference" )
2165  public static final String SP_AUTHENTICATOR = "authenticator";
2166  @SearchParamDefinition(name="identifier", path="DocumentReference.masterIdentifier | DocumentReference.identifier", description="Master Version Specific Identifier", type="token" )
2167  public static final String SP_IDENTIFIER = "identifier";
2168  @SearchParamDefinition(name="period", path="DocumentReference.context.period", description="Time of service that is being documented", type="date" )
2169  public static final String SP_PERIOD = "period";
2170  @SearchParamDefinition(name="related-id", path="DocumentReference.context.related.identifier", description="Identifier of related objects or events", type="token" )
2171  public static final String SP_RELATEDID = "related-id";
2172  @SearchParamDefinition(name="custodian", path="DocumentReference.custodian", description="Organization which maintains the document", type="reference" )
2173  public static final String SP_CUSTODIAN = "custodian";
2174  @SearchParamDefinition(name="indexed", path="DocumentReference.indexed", description="When this document reference created", type="date" )
2175  public static final String SP_INDEXED = "indexed";
2176  @SearchParamDefinition(name="author", path="DocumentReference.author", description="Who and/or what authored the document", type="reference" )
2177  public static final String SP_AUTHOR = "author";
2178  @SearchParamDefinition(name="created", path="DocumentReference.created", description="Document creation time", type="date" )
2179  public static final String SP_CREATED = "created";
2180  @SearchParamDefinition(name="format", path="DocumentReference.content.format", description="Format/content rules for the document", type="token" )
2181  public static final String SP_FORMAT = "format";
2182  @SearchParamDefinition(name="encounter", path="DocumentReference.context.encounter", description="Context of the document  content", type="reference" )
2183  public static final String SP_ENCOUNTER = "encounter";
2184  @SearchParamDefinition(name="related-ref", path="DocumentReference.context.related.ref", description="Related Resource", type="reference" )
2185  public static final String SP_RELATEDREF = "related-ref";
2186  @SearchParamDefinition(name="location", path="DocumentReference.content.attachment.url", description="Uri where the data can be found", type="uri" )
2187  public static final String SP_LOCATION = "location";
2188  @SearchParamDefinition(name="relatesto", path="DocumentReference.relatesTo.target", description="Target of the relationship", type="reference" )
2189  public static final String SP_RELATESTO = "relatesto";
2190  @SearchParamDefinition(name="facility", path="DocumentReference.context.facilityType", description="Kind of facility where patient was seen", type="token" )
2191  public static final String SP_FACILITY = "facility";
2192  @SearchParamDefinition(name="status", path="DocumentReference.status", description="current | superseded | entered-in-error", type="token" )
2193  public static final String SP_STATUS = "status";
2194
2195}
2196