001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.List;
038
039import ca.uhn.fhir.model.api.annotation.Block;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.Description;
042import ca.uhn.fhir.model.api.annotation.ResourceDef;
043import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
044import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
045import org.hl7.fhir.exceptions.FHIRException;
046/**
047 * An interaction between a patient and healthcare provider(s) for the purpose of providing healthcare service(s) or assessing the health status of a patient.
048 */
049@ResourceDef(name="Encounter", profile="http://hl7.org/fhir/Profile/Encounter")
050public class Encounter extends DomainResource {
051
052    public enum EncounterState {
053        /**
054         * The Encounter has not yet started.
055         */
056        PLANNED, 
057        /**
058         * The Patient is present for the encounter, however is not currently meeting with a practitioner.
059         */
060        ARRIVED, 
061        /**
062         * The Encounter has begun and the patient is present / the practitioner and the patient are meeting.
063         */
064        INPROGRESS, 
065        /**
066         * The Encounter has begun, but the patient is temporarily on leave.
067         */
068        ONLEAVE, 
069        /**
070         * The Encounter has ended.
071         */
072        FINISHED, 
073        /**
074         * The Encounter has ended before it has begun.
075         */
076        CANCELLED, 
077        /**
078         * added to help the parsers
079         */
080        NULL;
081        public static EncounterState fromCode(String codeString) throws FHIRException {
082            if (codeString == null || "".equals(codeString))
083                return null;
084        if ("planned".equals(codeString))
085          return PLANNED;
086        if ("arrived".equals(codeString))
087          return ARRIVED;
088        if ("in-progress".equals(codeString))
089          return INPROGRESS;
090        if ("onleave".equals(codeString))
091          return ONLEAVE;
092        if ("finished".equals(codeString))
093          return FINISHED;
094        if ("cancelled".equals(codeString))
095          return CANCELLED;
096        throw new FHIRException("Unknown EncounterState code '"+codeString+"'");
097        }
098        public String toCode() {
099          switch (this) {
100            case PLANNED: return "planned";
101            case ARRIVED: return "arrived";
102            case INPROGRESS: return "in-progress";
103            case ONLEAVE: return "onleave";
104            case FINISHED: return "finished";
105            case CANCELLED: return "cancelled";
106            case NULL: return null;
107            default: return "?";
108          }
109        }
110        public String getSystem() {
111          switch (this) {
112            case PLANNED: return "http://hl7.org/fhir/encounter-state";
113            case ARRIVED: return "http://hl7.org/fhir/encounter-state";
114            case INPROGRESS: return "http://hl7.org/fhir/encounter-state";
115            case ONLEAVE: return "http://hl7.org/fhir/encounter-state";
116            case FINISHED: return "http://hl7.org/fhir/encounter-state";
117            case CANCELLED: return "http://hl7.org/fhir/encounter-state";
118            case NULL: return null;
119            default: return "?";
120          }
121        }
122        public String getDefinition() {
123          switch (this) {
124            case PLANNED: return "The Encounter has not yet started.";
125            case ARRIVED: return "The Patient is present for the encounter, however is not currently meeting with a practitioner.";
126            case INPROGRESS: return "The Encounter has begun and the patient is present / the practitioner and the patient are meeting.";
127            case ONLEAVE: return "The Encounter has begun, but the patient is temporarily on leave.";
128            case FINISHED: return "The Encounter has ended.";
129            case CANCELLED: return "The Encounter has ended before it has begun.";
130            case NULL: return null;
131            default: return "?";
132          }
133        }
134        public String getDisplay() {
135          switch (this) {
136            case PLANNED: return "Planned";
137            case ARRIVED: return "Arrived";
138            case INPROGRESS: return "in Progress";
139            case ONLEAVE: return "On Leave";
140            case FINISHED: return "Finished";
141            case CANCELLED: return "Cancelled";
142            case NULL: return null;
143            default: return "?";
144          }
145        }
146    }
147
148  public static class EncounterStateEnumFactory implements EnumFactory<EncounterState> {
149    public EncounterState fromCode(String codeString) throws IllegalArgumentException {
150      if (codeString == null || "".equals(codeString))
151            if (codeString == null || "".equals(codeString))
152                return null;
153        if ("planned".equals(codeString))
154          return EncounterState.PLANNED;
155        if ("arrived".equals(codeString))
156          return EncounterState.ARRIVED;
157        if ("in-progress".equals(codeString))
158          return EncounterState.INPROGRESS;
159        if ("onleave".equals(codeString))
160          return EncounterState.ONLEAVE;
161        if ("finished".equals(codeString))
162          return EncounterState.FINISHED;
163        if ("cancelled".equals(codeString))
164          return EncounterState.CANCELLED;
165        throw new IllegalArgumentException("Unknown EncounterState code '"+codeString+"'");
166        }
167        public Enumeration<EncounterState> fromType(Base code) throws FHIRException {
168          if (code == null || code.isEmpty())
169            return null;
170          String codeString = ((PrimitiveType) code).asStringValue();
171          if (codeString == null || "".equals(codeString))
172            return null;
173        if ("planned".equals(codeString))
174          return new Enumeration<EncounterState>(this, EncounterState.PLANNED);
175        if ("arrived".equals(codeString))
176          return new Enumeration<EncounterState>(this, EncounterState.ARRIVED);
177        if ("in-progress".equals(codeString))
178          return new Enumeration<EncounterState>(this, EncounterState.INPROGRESS);
179        if ("onleave".equals(codeString))
180          return new Enumeration<EncounterState>(this, EncounterState.ONLEAVE);
181        if ("finished".equals(codeString))
182          return new Enumeration<EncounterState>(this, EncounterState.FINISHED);
183        if ("cancelled".equals(codeString))
184          return new Enumeration<EncounterState>(this, EncounterState.CANCELLED);
185        throw new FHIRException("Unknown EncounterState code '"+codeString+"'");
186        }
187    public String toCode(EncounterState code) {
188      if (code == EncounterState.PLANNED)
189        return "planned";
190      if (code == EncounterState.ARRIVED)
191        return "arrived";
192      if (code == EncounterState.INPROGRESS)
193        return "in-progress";
194      if (code == EncounterState.ONLEAVE)
195        return "onleave";
196      if (code == EncounterState.FINISHED)
197        return "finished";
198      if (code == EncounterState.CANCELLED)
199        return "cancelled";
200      return "?";
201      }
202    }
203
204    public enum EncounterClass {
205        /**
206         * An encounter during which the patient is hospitalized and stays overnight.
207         */
208        INPATIENT, 
209        /**
210         * An encounter during which the patient is not hospitalized overnight.
211         */
212        OUTPATIENT, 
213        /**
214         * An encounter where the patient visits the practitioner in his/her office, e.g. a G.P. visit.
215         */
216        AMBULATORY, 
217        /**
218         * An encounter in the Emergency Care Department.
219         */
220        EMERGENCY, 
221        /**
222         * An encounter where the practitioner visits the patient at his/her home.
223         */
224        HOME, 
225        /**
226         * An encounter taking place outside the regular environment for giving care.
227         */
228        FIELD, 
229        /**
230         * An encounter where the patient needs more prolonged treatment or investigations than outpatients, but who do not need to stay in the hospital overnight.
231         */
232        DAYTIME, 
233        /**
234         * An encounter that takes place where the patient and practitioner do not physically meet but use electronic means for contact.
235         */
236        VIRTUAL, 
237        /**
238         * Any other encounter type that is not described by one of the other values. Where this is used it is expected that an implementer will include an extension value to define what the actual other type is.
239         */
240        OTHER, 
241        /**
242         * added to help the parsers
243         */
244        NULL;
245        public static EncounterClass fromCode(String codeString) throws FHIRException {
246            if (codeString == null || "".equals(codeString))
247                return null;
248        if ("inpatient".equals(codeString))
249          return INPATIENT;
250        if ("outpatient".equals(codeString))
251          return OUTPATIENT;
252        if ("ambulatory".equals(codeString))
253          return AMBULATORY;
254        if ("emergency".equals(codeString))
255          return EMERGENCY;
256        if ("home".equals(codeString))
257          return HOME;
258        if ("field".equals(codeString))
259          return FIELD;
260        if ("daytime".equals(codeString))
261          return DAYTIME;
262        if ("virtual".equals(codeString))
263          return VIRTUAL;
264        if ("other".equals(codeString))
265          return OTHER;
266        throw new FHIRException("Unknown EncounterClass code '"+codeString+"'");
267        }
268        public String toCode() {
269          switch (this) {
270            case INPATIENT: return "inpatient";
271            case OUTPATIENT: return "outpatient";
272            case AMBULATORY: return "ambulatory";
273            case EMERGENCY: return "emergency";
274            case HOME: return "home";
275            case FIELD: return "field";
276            case DAYTIME: return "daytime";
277            case VIRTUAL: return "virtual";
278            case OTHER: return "other";
279            case NULL: return null;
280            default: return "?";
281          }
282        }
283        public String getSystem() {
284          switch (this) {
285            case INPATIENT: return "http://hl7.org/fhir/encounter-class";
286            case OUTPATIENT: return "http://hl7.org/fhir/encounter-class";
287            case AMBULATORY: return "http://hl7.org/fhir/encounter-class";
288            case EMERGENCY: return "http://hl7.org/fhir/encounter-class";
289            case HOME: return "http://hl7.org/fhir/encounter-class";
290            case FIELD: return "http://hl7.org/fhir/encounter-class";
291            case DAYTIME: return "http://hl7.org/fhir/encounter-class";
292            case VIRTUAL: return "http://hl7.org/fhir/encounter-class";
293            case OTHER: return "http://hl7.org/fhir/encounter-class";
294            case NULL: return null;
295            default: return "?";
296          }
297        }
298        public String getDefinition() {
299          switch (this) {
300            case INPATIENT: return "An encounter during which the patient is hospitalized and stays overnight.";
301            case OUTPATIENT: return "An encounter during which the patient is not hospitalized overnight.";
302            case AMBULATORY: return "An encounter where the patient visits the practitioner in his/her office, e.g. a G.P. visit.";
303            case EMERGENCY: return "An encounter in the Emergency Care Department.";
304            case HOME: return "An encounter where the practitioner visits the patient at his/her home.";
305            case FIELD: return "An encounter taking place outside the regular environment for giving care.";
306            case DAYTIME: return "An encounter where the patient needs more prolonged treatment or investigations than outpatients, but who do not need to stay in the hospital overnight.";
307            case VIRTUAL: return "An encounter that takes place where the patient and practitioner do not physically meet but use electronic means for contact.";
308            case OTHER: return "Any other encounter type that is not described by one of the other values. Where this is used it is expected that an implementer will include an extension value to define what the actual other type is.";
309            case NULL: return null;
310            default: return "?";
311          }
312        }
313        public String getDisplay() {
314          switch (this) {
315            case INPATIENT: return "Inpatient";
316            case OUTPATIENT: return "Outpatient";
317            case AMBULATORY: return "Ambulatory";
318            case EMERGENCY: return "Emergency";
319            case HOME: return "Home";
320            case FIELD: return "Field";
321            case DAYTIME: return "Daytime";
322            case VIRTUAL: return "Virtual";
323            case OTHER: return "Other";
324            case NULL: return null;
325            default: return "?";
326          }
327        }
328    }
329
330  public static class EncounterClassEnumFactory implements EnumFactory<EncounterClass> {
331    public EncounterClass fromCode(String codeString) throws IllegalArgumentException {
332      if (codeString == null || "".equals(codeString))
333            if (codeString == null || "".equals(codeString))
334                return null;
335        if ("inpatient".equals(codeString))
336          return EncounterClass.INPATIENT;
337        if ("outpatient".equals(codeString))
338          return EncounterClass.OUTPATIENT;
339        if ("ambulatory".equals(codeString))
340          return EncounterClass.AMBULATORY;
341        if ("emergency".equals(codeString))
342          return EncounterClass.EMERGENCY;
343        if ("home".equals(codeString))
344          return EncounterClass.HOME;
345        if ("field".equals(codeString))
346          return EncounterClass.FIELD;
347        if ("daytime".equals(codeString))
348          return EncounterClass.DAYTIME;
349        if ("virtual".equals(codeString))
350          return EncounterClass.VIRTUAL;
351        if ("other".equals(codeString))
352          return EncounterClass.OTHER;
353        throw new IllegalArgumentException("Unknown EncounterClass code '"+codeString+"'");
354        }
355        public Enumeration<EncounterClass> fromType(Base code) throws FHIRException {
356          if (code == null || code.isEmpty())
357            return null;
358          String codeString = ((PrimitiveType) code).asStringValue();
359          if (codeString == null || "".equals(codeString))
360            return null;
361        if ("inpatient".equals(codeString))
362          return new Enumeration<EncounterClass>(this, EncounterClass.INPATIENT);
363        if ("outpatient".equals(codeString))
364          return new Enumeration<EncounterClass>(this, EncounterClass.OUTPATIENT);
365        if ("ambulatory".equals(codeString))
366          return new Enumeration<EncounterClass>(this, EncounterClass.AMBULATORY);
367        if ("emergency".equals(codeString))
368          return new Enumeration<EncounterClass>(this, EncounterClass.EMERGENCY);
369        if ("home".equals(codeString))
370          return new Enumeration<EncounterClass>(this, EncounterClass.HOME);
371        if ("field".equals(codeString))
372          return new Enumeration<EncounterClass>(this, EncounterClass.FIELD);
373        if ("daytime".equals(codeString))
374          return new Enumeration<EncounterClass>(this, EncounterClass.DAYTIME);
375        if ("virtual".equals(codeString))
376          return new Enumeration<EncounterClass>(this, EncounterClass.VIRTUAL);
377        if ("other".equals(codeString))
378          return new Enumeration<EncounterClass>(this, EncounterClass.OTHER);
379        throw new FHIRException("Unknown EncounterClass code '"+codeString+"'");
380        }
381    public String toCode(EncounterClass code) {
382      if (code == EncounterClass.INPATIENT)
383        return "inpatient";
384      if (code == EncounterClass.OUTPATIENT)
385        return "outpatient";
386      if (code == EncounterClass.AMBULATORY)
387        return "ambulatory";
388      if (code == EncounterClass.EMERGENCY)
389        return "emergency";
390      if (code == EncounterClass.HOME)
391        return "home";
392      if (code == EncounterClass.FIELD)
393        return "field";
394      if (code == EncounterClass.DAYTIME)
395        return "daytime";
396      if (code == EncounterClass.VIRTUAL)
397        return "virtual";
398      if (code == EncounterClass.OTHER)
399        return "other";
400      return "?";
401      }
402    }
403
404    public enum EncounterLocationStatus {
405        /**
406         * The patient is planned to be moved to this location at some point in the future.
407         */
408        PLANNED, 
409        /**
410         * The patient is currently at this location, or was between the period specified.
411
412A system may update these records when the patient leaves the location to either reserved, or completed
413         */
414        ACTIVE, 
415        /**
416         * This location is held empty for this patient.
417         */
418        RESERVED, 
419        /**
420         * The patient was at this location during the period specified.
421
422Not to be used when the patient is currently at the location
423         */
424        COMPLETED, 
425        /**
426         * added to help the parsers
427         */
428        NULL;
429        public static EncounterLocationStatus fromCode(String codeString) throws FHIRException {
430            if (codeString == null || "".equals(codeString))
431                return null;
432        if ("planned".equals(codeString))
433          return PLANNED;
434        if ("active".equals(codeString))
435          return ACTIVE;
436        if ("reserved".equals(codeString))
437          return RESERVED;
438        if ("completed".equals(codeString))
439          return COMPLETED;
440        throw new FHIRException("Unknown EncounterLocationStatus code '"+codeString+"'");
441        }
442        public String toCode() {
443          switch (this) {
444            case PLANNED: return "planned";
445            case ACTIVE: return "active";
446            case RESERVED: return "reserved";
447            case COMPLETED: return "completed";
448            case NULL: return null;
449            default: return "?";
450          }
451        }
452        public String getSystem() {
453          switch (this) {
454            case PLANNED: return "http://hl7.org/fhir/encounter-location-status";
455            case ACTIVE: return "http://hl7.org/fhir/encounter-location-status";
456            case RESERVED: return "http://hl7.org/fhir/encounter-location-status";
457            case COMPLETED: return "http://hl7.org/fhir/encounter-location-status";
458            case NULL: return null;
459            default: return "?";
460          }
461        }
462        public String getDefinition() {
463          switch (this) {
464            case PLANNED: return "The patient is planned to be moved to this location at some point in the future.";
465            case ACTIVE: return "The patient is currently at this location, or was between the period specified.\n\nA system may update these records when the patient leaves the location to either reserved, or completed";
466            case RESERVED: return "This location is held empty for this patient.";
467            case COMPLETED: return "The patient was at this location during the period specified.\n\nNot to be used when the patient is currently at the location";
468            case NULL: return null;
469            default: return "?";
470          }
471        }
472        public String getDisplay() {
473          switch (this) {
474            case PLANNED: return "Planned";
475            case ACTIVE: return "Active";
476            case RESERVED: return "Reserved";
477            case COMPLETED: return "Completed";
478            case NULL: return null;
479            default: return "?";
480          }
481        }
482    }
483
484  public static class EncounterLocationStatusEnumFactory implements EnumFactory<EncounterLocationStatus> {
485    public EncounterLocationStatus fromCode(String codeString) throws IllegalArgumentException {
486      if (codeString == null || "".equals(codeString))
487            if (codeString == null || "".equals(codeString))
488                return null;
489        if ("planned".equals(codeString))
490          return EncounterLocationStatus.PLANNED;
491        if ("active".equals(codeString))
492          return EncounterLocationStatus.ACTIVE;
493        if ("reserved".equals(codeString))
494          return EncounterLocationStatus.RESERVED;
495        if ("completed".equals(codeString))
496          return EncounterLocationStatus.COMPLETED;
497        throw new IllegalArgumentException("Unknown EncounterLocationStatus code '"+codeString+"'");
498        }
499        public Enumeration<EncounterLocationStatus> fromType(Base code) throws FHIRException {
500          if (code == null || code.isEmpty())
501            return null;
502          String codeString = ((PrimitiveType) code).asStringValue();
503          if (codeString == null || "".equals(codeString))
504            return null;
505        if ("planned".equals(codeString))
506          return new Enumeration<EncounterLocationStatus>(this, EncounterLocationStatus.PLANNED);
507        if ("active".equals(codeString))
508          return new Enumeration<EncounterLocationStatus>(this, EncounterLocationStatus.ACTIVE);
509        if ("reserved".equals(codeString))
510          return new Enumeration<EncounterLocationStatus>(this, EncounterLocationStatus.RESERVED);
511        if ("completed".equals(codeString))
512          return new Enumeration<EncounterLocationStatus>(this, EncounterLocationStatus.COMPLETED);
513        throw new FHIRException("Unknown EncounterLocationStatus code '"+codeString+"'");
514        }
515    public String toCode(EncounterLocationStatus code) {
516      if (code == EncounterLocationStatus.PLANNED)
517        return "planned";
518      if (code == EncounterLocationStatus.ACTIVE)
519        return "active";
520      if (code == EncounterLocationStatus.RESERVED)
521        return "reserved";
522      if (code == EncounterLocationStatus.COMPLETED)
523        return "completed";
524      return "?";
525      }
526    }
527
528    @Block()
529    public static class EncounterStatusHistoryComponent extends BackboneElement implements IBaseBackboneElement {
530        /**
531         * planned | arrived | in-progress | onleave | finished | cancelled.
532         */
533        @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=false, summary=false)
534        @Description(shortDefinition="planned | arrived | in-progress | onleave | finished | cancelled", formalDefinition="planned | arrived | in-progress | onleave | finished | cancelled." )
535        protected Enumeration<EncounterState> status;
536
537        /**
538         * The time that the episode was in the specified status.
539         */
540        @Child(name = "period", type = {Period.class}, order=2, min=1, max=1, modifier=false, summary=false)
541        @Description(shortDefinition="The time that the episode was in the specified status", formalDefinition="The time that the episode was in the specified status." )
542        protected Period period;
543
544        private static final long serialVersionUID = 919229161L;
545
546    /*
547     * Constructor
548     */
549      public EncounterStatusHistoryComponent() {
550        super();
551      }
552
553    /*
554     * Constructor
555     */
556      public EncounterStatusHistoryComponent(Enumeration<EncounterState> status, Period period) {
557        super();
558        this.status = status;
559        this.period = period;
560      }
561
562        /**
563         * @return {@link #status} (planned | arrived | in-progress | onleave | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
564         */
565        public Enumeration<EncounterState> getStatusElement() { 
566          if (this.status == null)
567            if (Configuration.errorOnAutoCreate())
568              throw new Error("Attempt to auto-create EncounterStatusHistoryComponent.status");
569            else if (Configuration.doAutoCreate())
570              this.status = new Enumeration<EncounterState>(new EncounterStateEnumFactory()); // bb
571          return this.status;
572        }
573
574        public boolean hasStatusElement() { 
575          return this.status != null && !this.status.isEmpty();
576        }
577
578        public boolean hasStatus() { 
579          return this.status != null && !this.status.isEmpty();
580        }
581
582        /**
583         * @param value {@link #status} (planned | arrived | in-progress | onleave | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
584         */
585        public EncounterStatusHistoryComponent setStatusElement(Enumeration<EncounterState> value) { 
586          this.status = value;
587          return this;
588        }
589
590        /**
591         * @return planned | arrived | in-progress | onleave | finished | cancelled.
592         */
593        public EncounterState getStatus() { 
594          return this.status == null ? null : this.status.getValue();
595        }
596
597        /**
598         * @param value planned | arrived | in-progress | onleave | finished | cancelled.
599         */
600        public EncounterStatusHistoryComponent setStatus(EncounterState value) { 
601            if (this.status == null)
602              this.status = new Enumeration<EncounterState>(new EncounterStateEnumFactory());
603            this.status.setValue(value);
604          return this;
605        }
606
607        /**
608         * @return {@link #period} (The time that the episode was in the specified status.)
609         */
610        public Period getPeriod() { 
611          if (this.period == null)
612            if (Configuration.errorOnAutoCreate())
613              throw new Error("Attempt to auto-create EncounterStatusHistoryComponent.period");
614            else if (Configuration.doAutoCreate())
615              this.period = new Period(); // cc
616          return this.period;
617        }
618
619        public boolean hasPeriod() { 
620          return this.period != null && !this.period.isEmpty();
621        }
622
623        /**
624         * @param value {@link #period} (The time that the episode was in the specified status.)
625         */
626        public EncounterStatusHistoryComponent setPeriod(Period value) { 
627          this.period = value;
628          return this;
629        }
630
631        protected void listChildren(List<Property> childrenList) {
632          super.listChildren(childrenList);
633          childrenList.add(new Property("status", "code", "planned | arrived | in-progress | onleave | finished | cancelled.", 0, java.lang.Integer.MAX_VALUE, status));
634          childrenList.add(new Property("period", "Period", "The time that the episode was in the specified status.", 0, java.lang.Integer.MAX_VALUE, period));
635        }
636
637      @Override
638      public void setProperty(String name, Base value) throws FHIRException {
639        if (name.equals("status"))
640          this.status = new EncounterStateEnumFactory().fromType(value); // Enumeration<EncounterState>
641        else if (name.equals("period"))
642          this.period = castToPeriod(value); // Period
643        else
644          super.setProperty(name, value);
645      }
646
647      @Override
648      public Base addChild(String name) throws FHIRException {
649        if (name.equals("status")) {
650          throw new FHIRException("Cannot call addChild on a primitive type Encounter.status");
651        }
652        else if (name.equals("period")) {
653          this.period = new Period();
654          return this.period;
655        }
656        else
657          return super.addChild(name);
658      }
659
660      public EncounterStatusHistoryComponent copy() {
661        EncounterStatusHistoryComponent dst = new EncounterStatusHistoryComponent();
662        copyValues(dst);
663        dst.status = status == null ? null : status.copy();
664        dst.period = period == null ? null : period.copy();
665        return dst;
666      }
667
668      @Override
669      public boolean equalsDeep(Base other) {
670        if (!super.equalsDeep(other))
671          return false;
672        if (!(other instanceof EncounterStatusHistoryComponent))
673          return false;
674        EncounterStatusHistoryComponent o = (EncounterStatusHistoryComponent) other;
675        return compareDeep(status, o.status, true) && compareDeep(period, o.period, true);
676      }
677
678      @Override
679      public boolean equalsShallow(Base other) {
680        if (!super.equalsShallow(other))
681          return false;
682        if (!(other instanceof EncounterStatusHistoryComponent))
683          return false;
684        EncounterStatusHistoryComponent o = (EncounterStatusHistoryComponent) other;
685        return compareValues(status, o.status, true);
686      }
687
688      public boolean isEmpty() {
689        return super.isEmpty() && (status == null || status.isEmpty()) && (period == null || period.isEmpty())
690          ;
691      }
692
693  public String fhirType() {
694    return "Encounter.statusHistory";
695
696  }
697
698  }
699
700    @Block()
701    public static class EncounterParticipantComponent extends BackboneElement implements IBaseBackboneElement {
702        /**
703         * Role of participant in encounter.
704         */
705        @Child(name = "type", type = {CodeableConcept.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
706        @Description(shortDefinition="Role of participant in encounter", formalDefinition="Role of participant in encounter." )
707        protected List<CodeableConcept> type;
708
709        /**
710         * The period of time that the specified participant was present during the encounter. These can overlap or be sub-sets of the overall encounters period.
711         */
712        @Child(name = "period", type = {Period.class}, order=2, min=0, max=1, modifier=false, summary=false)
713        @Description(shortDefinition="Period of time during the encounter participant was present", formalDefinition="The period of time that the specified participant was present during the encounter. These can overlap or be sub-sets of the overall encounters period." )
714        protected Period period;
715
716        /**
717         * Persons involved in the encounter other than the patient.
718         */
719        @Child(name = "individual", type = {Practitioner.class, RelatedPerson.class}, order=3, min=0, max=1, modifier=false, summary=true)
720        @Description(shortDefinition="Persons involved in the encounter other than the patient", formalDefinition="Persons involved in the encounter other than the patient." )
721        protected Reference individual;
722
723        /**
724         * The actual object that is the target of the reference (Persons involved in the encounter other than the patient.)
725         */
726        protected Resource individualTarget;
727
728        private static final long serialVersionUID = 317095765L;
729
730    /*
731     * Constructor
732     */
733      public EncounterParticipantComponent() {
734        super();
735      }
736
737        /**
738         * @return {@link #type} (Role of participant in encounter.)
739         */
740        public List<CodeableConcept> getType() { 
741          if (this.type == null)
742            this.type = new ArrayList<CodeableConcept>();
743          return this.type;
744        }
745
746        public boolean hasType() { 
747          if (this.type == null)
748            return false;
749          for (CodeableConcept item : this.type)
750            if (!item.isEmpty())
751              return true;
752          return false;
753        }
754
755        /**
756         * @return {@link #type} (Role of participant in encounter.)
757         */
758    // syntactic sugar
759        public CodeableConcept addType() { //3
760          CodeableConcept t = new CodeableConcept();
761          if (this.type == null)
762            this.type = new ArrayList<CodeableConcept>();
763          this.type.add(t);
764          return t;
765        }
766
767    // syntactic sugar
768        public EncounterParticipantComponent addType(CodeableConcept t) { //3
769          if (t == null)
770            return this;
771          if (this.type == null)
772            this.type = new ArrayList<CodeableConcept>();
773          this.type.add(t);
774          return this;
775        }
776
777        /**
778         * @return {@link #period} (The period of time that the specified participant was present during the encounter. These can overlap or be sub-sets of the overall encounters period.)
779         */
780        public Period getPeriod() { 
781          if (this.period == null)
782            if (Configuration.errorOnAutoCreate())
783              throw new Error("Attempt to auto-create EncounterParticipantComponent.period");
784            else if (Configuration.doAutoCreate())
785              this.period = new Period(); // cc
786          return this.period;
787        }
788
789        public boolean hasPeriod() { 
790          return this.period != null && !this.period.isEmpty();
791        }
792
793        /**
794         * @param value {@link #period} (The period of time that the specified participant was present during the encounter. These can overlap or be sub-sets of the overall encounters period.)
795         */
796        public EncounterParticipantComponent setPeriod(Period value) { 
797          this.period = value;
798          return this;
799        }
800
801        /**
802         * @return {@link #individual} (Persons involved in the encounter other than the patient.)
803         */
804        public Reference getIndividual() { 
805          if (this.individual == null)
806            if (Configuration.errorOnAutoCreate())
807              throw new Error("Attempt to auto-create EncounterParticipantComponent.individual");
808            else if (Configuration.doAutoCreate())
809              this.individual = new Reference(); // cc
810          return this.individual;
811        }
812
813        public boolean hasIndividual() { 
814          return this.individual != null && !this.individual.isEmpty();
815        }
816
817        /**
818         * @param value {@link #individual} (Persons involved in the encounter other than the patient.)
819         */
820        public EncounterParticipantComponent setIndividual(Reference value) { 
821          this.individual = value;
822          return this;
823        }
824
825        /**
826         * @return {@link #individual} 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. (Persons involved in the encounter other than the patient.)
827         */
828        public Resource getIndividualTarget() { 
829          return this.individualTarget;
830        }
831
832        /**
833         * @param value {@link #individual} 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. (Persons involved in the encounter other than the patient.)
834         */
835        public EncounterParticipantComponent setIndividualTarget(Resource value) { 
836          this.individualTarget = value;
837          return this;
838        }
839
840        protected void listChildren(List<Property> childrenList) {
841          super.listChildren(childrenList);
842          childrenList.add(new Property("type", "CodeableConcept", "Role of participant in encounter.", 0, java.lang.Integer.MAX_VALUE, type));
843          childrenList.add(new Property("period", "Period", "The period of time that the specified participant was present during the encounter. These can overlap or be sub-sets of the overall encounters period.", 0, java.lang.Integer.MAX_VALUE, period));
844          childrenList.add(new Property("individual", "Reference(Practitioner|RelatedPerson)", "Persons involved in the encounter other than the patient.", 0, java.lang.Integer.MAX_VALUE, individual));
845        }
846
847      @Override
848      public void setProperty(String name, Base value) throws FHIRException {
849        if (name.equals("type"))
850          this.getType().add(castToCodeableConcept(value));
851        else if (name.equals("period"))
852          this.period = castToPeriod(value); // Period
853        else if (name.equals("individual"))
854          this.individual = castToReference(value); // Reference
855        else
856          super.setProperty(name, value);
857      }
858
859      @Override
860      public Base addChild(String name) throws FHIRException {
861        if (name.equals("type")) {
862          return addType();
863        }
864        else if (name.equals("period")) {
865          this.period = new Period();
866          return this.period;
867        }
868        else if (name.equals("individual")) {
869          this.individual = new Reference();
870          return this.individual;
871        }
872        else
873          return super.addChild(name);
874      }
875
876      public EncounterParticipantComponent copy() {
877        EncounterParticipantComponent dst = new EncounterParticipantComponent();
878        copyValues(dst);
879        if (type != null) {
880          dst.type = new ArrayList<CodeableConcept>();
881          for (CodeableConcept i : type)
882            dst.type.add(i.copy());
883        };
884        dst.period = period == null ? null : period.copy();
885        dst.individual = individual == null ? null : individual.copy();
886        return dst;
887      }
888
889      @Override
890      public boolean equalsDeep(Base other) {
891        if (!super.equalsDeep(other))
892          return false;
893        if (!(other instanceof EncounterParticipantComponent))
894          return false;
895        EncounterParticipantComponent o = (EncounterParticipantComponent) other;
896        return compareDeep(type, o.type, true) && compareDeep(period, o.period, true) && compareDeep(individual, o.individual, true)
897          ;
898      }
899
900      @Override
901      public boolean equalsShallow(Base other) {
902        if (!super.equalsShallow(other))
903          return false;
904        if (!(other instanceof EncounterParticipantComponent))
905          return false;
906        EncounterParticipantComponent o = (EncounterParticipantComponent) other;
907        return true;
908      }
909
910      public boolean isEmpty() {
911        return super.isEmpty() && (type == null || type.isEmpty()) && (period == null || period.isEmpty())
912           && (individual == null || individual.isEmpty());
913      }
914
915  public String fhirType() {
916    return "Encounter.participant";
917
918  }
919
920  }
921
922    @Block()
923    public static class EncounterHospitalizationComponent extends BackboneElement implements IBaseBackboneElement {
924        /**
925         * Pre-admission identifier.
926         */
927        @Child(name = "preAdmissionIdentifier", type = {Identifier.class}, order=1, min=0, max=1, modifier=false, summary=false)
928        @Description(shortDefinition="Pre-admission identifier", formalDefinition="Pre-admission identifier." )
929        protected Identifier preAdmissionIdentifier;
930
931        /**
932         * The location from which the patient came before admission.
933         */
934        @Child(name = "origin", type = {Location.class}, order=2, min=0, max=1, modifier=false, summary=false)
935        @Description(shortDefinition="The location from which the patient came before admission", formalDefinition="The location from which the patient came before admission." )
936        protected Reference origin;
937
938        /**
939         * The actual object that is the target of the reference (The location from which the patient came before admission.)
940         */
941        protected Location originTarget;
942
943        /**
944         * From where patient was admitted (physician referral, transfer).
945         */
946        @Child(name = "admitSource", type = {CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=false)
947        @Description(shortDefinition="From where patient was admitted (physician referral, transfer)", formalDefinition="From where patient was admitted (physician referral, transfer)." )
948        protected CodeableConcept admitSource;
949
950        /**
951         * The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.
952         */
953        @Child(name = "admittingDiagnosis", type = {Condition.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
954        @Description(shortDefinition="The admitting diagnosis as reported by admitting practitioner", formalDefinition="The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter." )
955        protected List<Reference> admittingDiagnosis;
956        /**
957         * The actual objects that are the target of the reference (The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.)
958         */
959        protected List<Condition> admittingDiagnosisTarget;
960
961
962        /**
963         * Whether this hospitalization is a readmission and why if known.
964         */
965        @Child(name = "reAdmission", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=false)
966        @Description(shortDefinition="The type of hospital re-admission that has occurred (if any). If the value is absent, then this is not identified as a readmission", formalDefinition="Whether this hospitalization is a readmission and why if known." )
967        protected CodeableConcept reAdmission;
968
969        /**
970         * Diet preferences reported by the patient.
971         */
972        @Child(name = "dietPreference", type = {CodeableConcept.class}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
973        @Description(shortDefinition="Diet preferences reported by the patient", formalDefinition="Diet preferences reported by the patient." )
974        protected List<CodeableConcept> dietPreference;
975
976        /**
977         * Special courtesies (VIP, board member).
978         */
979        @Child(name = "specialCourtesy", type = {CodeableConcept.class}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
980        @Description(shortDefinition="Special courtesies (VIP, board member)", formalDefinition="Special courtesies (VIP, board member)." )
981        protected List<CodeableConcept> specialCourtesy;
982
983        /**
984         * Wheelchair, translator, stretcher, etc.
985         */
986        @Child(name = "specialArrangement", type = {CodeableConcept.class}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
987        @Description(shortDefinition="Wheelchair, translator, stretcher, etc.", formalDefinition="Wheelchair, translator, stretcher, etc." )
988        protected List<CodeableConcept> specialArrangement;
989
990        /**
991         * Location to which the patient is discharged.
992         */
993        @Child(name = "destination", type = {Location.class}, order=9, min=0, max=1, modifier=false, summary=false)
994        @Description(shortDefinition="Location to which the patient is discharged", formalDefinition="Location to which the patient is discharged." )
995        protected Reference destination;
996
997        /**
998         * The actual object that is the target of the reference (Location to which the patient is discharged.)
999         */
1000        protected Location destinationTarget;
1001
1002        /**
1003         * Category or kind of location after discharge.
1004         */
1005        @Child(name = "dischargeDisposition", type = {CodeableConcept.class}, order=10, min=0, max=1, modifier=false, summary=false)
1006        @Description(shortDefinition="Category or kind of location after discharge", formalDefinition="Category or kind of location after discharge." )
1007        protected CodeableConcept dischargeDisposition;
1008
1009        /**
1010         * The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.
1011         */
1012        @Child(name = "dischargeDiagnosis", type = {Condition.class}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1013        @Description(shortDefinition="The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete", formalDefinition="The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete." )
1014        protected List<Reference> dischargeDiagnosis;
1015        /**
1016         * The actual objects that are the target of the reference (The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.)
1017         */
1018        protected List<Condition> dischargeDiagnosisTarget;
1019
1020
1021        private static final long serialVersionUID = 164618034L;
1022
1023    /*
1024     * Constructor
1025     */
1026      public EncounterHospitalizationComponent() {
1027        super();
1028      }
1029
1030        /**
1031         * @return {@link #preAdmissionIdentifier} (Pre-admission identifier.)
1032         */
1033        public Identifier getPreAdmissionIdentifier() { 
1034          if (this.preAdmissionIdentifier == null)
1035            if (Configuration.errorOnAutoCreate())
1036              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.preAdmissionIdentifier");
1037            else if (Configuration.doAutoCreate())
1038              this.preAdmissionIdentifier = new Identifier(); // cc
1039          return this.preAdmissionIdentifier;
1040        }
1041
1042        public boolean hasPreAdmissionIdentifier() { 
1043          return this.preAdmissionIdentifier != null && !this.preAdmissionIdentifier.isEmpty();
1044        }
1045
1046        /**
1047         * @param value {@link #preAdmissionIdentifier} (Pre-admission identifier.)
1048         */
1049        public EncounterHospitalizationComponent setPreAdmissionIdentifier(Identifier value) { 
1050          this.preAdmissionIdentifier = value;
1051          return this;
1052        }
1053
1054        /**
1055         * @return {@link #origin} (The location from which the patient came before admission.)
1056         */
1057        public Reference getOrigin() { 
1058          if (this.origin == null)
1059            if (Configuration.errorOnAutoCreate())
1060              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.origin");
1061            else if (Configuration.doAutoCreate())
1062              this.origin = new Reference(); // cc
1063          return this.origin;
1064        }
1065
1066        public boolean hasOrigin() { 
1067          return this.origin != null && !this.origin.isEmpty();
1068        }
1069
1070        /**
1071         * @param value {@link #origin} (The location from which the patient came before admission.)
1072         */
1073        public EncounterHospitalizationComponent setOrigin(Reference value) { 
1074          this.origin = value;
1075          return this;
1076        }
1077
1078        /**
1079         * @return {@link #origin} 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 location from which the patient came before admission.)
1080         */
1081        public Location getOriginTarget() { 
1082          if (this.originTarget == null)
1083            if (Configuration.errorOnAutoCreate())
1084              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.origin");
1085            else if (Configuration.doAutoCreate())
1086              this.originTarget = new Location(); // aa
1087          return this.originTarget;
1088        }
1089
1090        /**
1091         * @param value {@link #origin} 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 location from which the patient came before admission.)
1092         */
1093        public EncounterHospitalizationComponent setOriginTarget(Location value) { 
1094          this.originTarget = value;
1095          return this;
1096        }
1097
1098        /**
1099         * @return {@link #admitSource} (From where patient was admitted (physician referral, transfer).)
1100         */
1101        public CodeableConcept getAdmitSource() { 
1102          if (this.admitSource == null)
1103            if (Configuration.errorOnAutoCreate())
1104              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.admitSource");
1105            else if (Configuration.doAutoCreate())
1106              this.admitSource = new CodeableConcept(); // cc
1107          return this.admitSource;
1108        }
1109
1110        public boolean hasAdmitSource() { 
1111          return this.admitSource != null && !this.admitSource.isEmpty();
1112        }
1113
1114        /**
1115         * @param value {@link #admitSource} (From where patient was admitted (physician referral, transfer).)
1116         */
1117        public EncounterHospitalizationComponent setAdmitSource(CodeableConcept value) { 
1118          this.admitSource = value;
1119          return this;
1120        }
1121
1122        /**
1123         * @return {@link #admittingDiagnosis} (The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.)
1124         */
1125        public List<Reference> getAdmittingDiagnosis() { 
1126          if (this.admittingDiagnosis == null)
1127            this.admittingDiagnosis = new ArrayList<Reference>();
1128          return this.admittingDiagnosis;
1129        }
1130
1131        public boolean hasAdmittingDiagnosis() { 
1132          if (this.admittingDiagnosis == null)
1133            return false;
1134          for (Reference item : this.admittingDiagnosis)
1135            if (!item.isEmpty())
1136              return true;
1137          return false;
1138        }
1139
1140        /**
1141         * @return {@link #admittingDiagnosis} (The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.)
1142         */
1143    // syntactic sugar
1144        public Reference addAdmittingDiagnosis() { //3
1145          Reference t = new Reference();
1146          if (this.admittingDiagnosis == null)
1147            this.admittingDiagnosis = new ArrayList<Reference>();
1148          this.admittingDiagnosis.add(t);
1149          return t;
1150        }
1151
1152    // syntactic sugar
1153        public EncounterHospitalizationComponent addAdmittingDiagnosis(Reference t) { //3
1154          if (t == null)
1155            return this;
1156          if (this.admittingDiagnosis == null)
1157            this.admittingDiagnosis = new ArrayList<Reference>();
1158          this.admittingDiagnosis.add(t);
1159          return this;
1160        }
1161
1162        /**
1163         * @return {@link #admittingDiagnosis} (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. The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.)
1164         */
1165        public List<Condition> getAdmittingDiagnosisTarget() { 
1166          if (this.admittingDiagnosisTarget == null)
1167            this.admittingDiagnosisTarget = new ArrayList<Condition>();
1168          return this.admittingDiagnosisTarget;
1169        }
1170
1171    // syntactic sugar
1172        /**
1173         * @return {@link #admittingDiagnosis} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.)
1174         */
1175        public Condition addAdmittingDiagnosisTarget() { 
1176          Condition r = new Condition();
1177          if (this.admittingDiagnosisTarget == null)
1178            this.admittingDiagnosisTarget = new ArrayList<Condition>();
1179          this.admittingDiagnosisTarget.add(r);
1180          return r;
1181        }
1182
1183        /**
1184         * @return {@link #reAdmission} (Whether this hospitalization is a readmission and why if known.)
1185         */
1186        public CodeableConcept getReAdmission() { 
1187          if (this.reAdmission == null)
1188            if (Configuration.errorOnAutoCreate())
1189              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.reAdmission");
1190            else if (Configuration.doAutoCreate())
1191              this.reAdmission = new CodeableConcept(); // cc
1192          return this.reAdmission;
1193        }
1194
1195        public boolean hasReAdmission() { 
1196          return this.reAdmission != null && !this.reAdmission.isEmpty();
1197        }
1198
1199        /**
1200         * @param value {@link #reAdmission} (Whether this hospitalization is a readmission and why if known.)
1201         */
1202        public EncounterHospitalizationComponent setReAdmission(CodeableConcept value) { 
1203          this.reAdmission = value;
1204          return this;
1205        }
1206
1207        /**
1208         * @return {@link #dietPreference} (Diet preferences reported by the patient.)
1209         */
1210        public List<CodeableConcept> getDietPreference() { 
1211          if (this.dietPreference == null)
1212            this.dietPreference = new ArrayList<CodeableConcept>();
1213          return this.dietPreference;
1214        }
1215
1216        public boolean hasDietPreference() { 
1217          if (this.dietPreference == null)
1218            return false;
1219          for (CodeableConcept item : this.dietPreference)
1220            if (!item.isEmpty())
1221              return true;
1222          return false;
1223        }
1224
1225        /**
1226         * @return {@link #dietPreference} (Diet preferences reported by the patient.)
1227         */
1228    // syntactic sugar
1229        public CodeableConcept addDietPreference() { //3
1230          CodeableConcept t = new CodeableConcept();
1231          if (this.dietPreference == null)
1232            this.dietPreference = new ArrayList<CodeableConcept>();
1233          this.dietPreference.add(t);
1234          return t;
1235        }
1236
1237    // syntactic sugar
1238        public EncounterHospitalizationComponent addDietPreference(CodeableConcept t) { //3
1239          if (t == null)
1240            return this;
1241          if (this.dietPreference == null)
1242            this.dietPreference = new ArrayList<CodeableConcept>();
1243          this.dietPreference.add(t);
1244          return this;
1245        }
1246
1247        /**
1248         * @return {@link #specialCourtesy} (Special courtesies (VIP, board member).)
1249         */
1250        public List<CodeableConcept> getSpecialCourtesy() { 
1251          if (this.specialCourtesy == null)
1252            this.specialCourtesy = new ArrayList<CodeableConcept>();
1253          return this.specialCourtesy;
1254        }
1255
1256        public boolean hasSpecialCourtesy() { 
1257          if (this.specialCourtesy == null)
1258            return false;
1259          for (CodeableConcept item : this.specialCourtesy)
1260            if (!item.isEmpty())
1261              return true;
1262          return false;
1263        }
1264
1265        /**
1266         * @return {@link #specialCourtesy} (Special courtesies (VIP, board member).)
1267         */
1268    // syntactic sugar
1269        public CodeableConcept addSpecialCourtesy() { //3
1270          CodeableConcept t = new CodeableConcept();
1271          if (this.specialCourtesy == null)
1272            this.specialCourtesy = new ArrayList<CodeableConcept>();
1273          this.specialCourtesy.add(t);
1274          return t;
1275        }
1276
1277    // syntactic sugar
1278        public EncounterHospitalizationComponent addSpecialCourtesy(CodeableConcept t) { //3
1279          if (t == null)
1280            return this;
1281          if (this.specialCourtesy == null)
1282            this.specialCourtesy = new ArrayList<CodeableConcept>();
1283          this.specialCourtesy.add(t);
1284          return this;
1285        }
1286
1287        /**
1288         * @return {@link #specialArrangement} (Wheelchair, translator, stretcher, etc.)
1289         */
1290        public List<CodeableConcept> getSpecialArrangement() { 
1291          if (this.specialArrangement == null)
1292            this.specialArrangement = new ArrayList<CodeableConcept>();
1293          return this.specialArrangement;
1294        }
1295
1296        public boolean hasSpecialArrangement() { 
1297          if (this.specialArrangement == null)
1298            return false;
1299          for (CodeableConcept item : this.specialArrangement)
1300            if (!item.isEmpty())
1301              return true;
1302          return false;
1303        }
1304
1305        /**
1306         * @return {@link #specialArrangement} (Wheelchair, translator, stretcher, etc.)
1307         */
1308    // syntactic sugar
1309        public CodeableConcept addSpecialArrangement() { //3
1310          CodeableConcept t = new CodeableConcept();
1311          if (this.specialArrangement == null)
1312            this.specialArrangement = new ArrayList<CodeableConcept>();
1313          this.specialArrangement.add(t);
1314          return t;
1315        }
1316
1317    // syntactic sugar
1318        public EncounterHospitalizationComponent addSpecialArrangement(CodeableConcept t) { //3
1319          if (t == null)
1320            return this;
1321          if (this.specialArrangement == null)
1322            this.specialArrangement = new ArrayList<CodeableConcept>();
1323          this.specialArrangement.add(t);
1324          return this;
1325        }
1326
1327        /**
1328         * @return {@link #destination} (Location to which the patient is discharged.)
1329         */
1330        public Reference getDestination() { 
1331          if (this.destination == null)
1332            if (Configuration.errorOnAutoCreate())
1333              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.destination");
1334            else if (Configuration.doAutoCreate())
1335              this.destination = new Reference(); // cc
1336          return this.destination;
1337        }
1338
1339        public boolean hasDestination() { 
1340          return this.destination != null && !this.destination.isEmpty();
1341        }
1342
1343        /**
1344         * @param value {@link #destination} (Location to which the patient is discharged.)
1345         */
1346        public EncounterHospitalizationComponent setDestination(Reference value) { 
1347          this.destination = value;
1348          return this;
1349        }
1350
1351        /**
1352         * @return {@link #destination} 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. (Location to which the patient is discharged.)
1353         */
1354        public Location getDestinationTarget() { 
1355          if (this.destinationTarget == null)
1356            if (Configuration.errorOnAutoCreate())
1357              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.destination");
1358            else if (Configuration.doAutoCreate())
1359              this.destinationTarget = new Location(); // aa
1360          return this.destinationTarget;
1361        }
1362
1363        /**
1364         * @param value {@link #destination} 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. (Location to which the patient is discharged.)
1365         */
1366        public EncounterHospitalizationComponent setDestinationTarget(Location value) { 
1367          this.destinationTarget = value;
1368          return this;
1369        }
1370
1371        /**
1372         * @return {@link #dischargeDisposition} (Category or kind of location after discharge.)
1373         */
1374        public CodeableConcept getDischargeDisposition() { 
1375          if (this.dischargeDisposition == null)
1376            if (Configuration.errorOnAutoCreate())
1377              throw new Error("Attempt to auto-create EncounterHospitalizationComponent.dischargeDisposition");
1378            else if (Configuration.doAutoCreate())
1379              this.dischargeDisposition = new CodeableConcept(); // cc
1380          return this.dischargeDisposition;
1381        }
1382
1383        public boolean hasDischargeDisposition() { 
1384          return this.dischargeDisposition != null && !this.dischargeDisposition.isEmpty();
1385        }
1386
1387        /**
1388         * @param value {@link #dischargeDisposition} (Category or kind of location after discharge.)
1389         */
1390        public EncounterHospitalizationComponent setDischargeDisposition(CodeableConcept value) { 
1391          this.dischargeDisposition = value;
1392          return this;
1393        }
1394
1395        /**
1396         * @return {@link #dischargeDiagnosis} (The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.)
1397         */
1398        public List<Reference> getDischargeDiagnosis() { 
1399          if (this.dischargeDiagnosis == null)
1400            this.dischargeDiagnosis = new ArrayList<Reference>();
1401          return this.dischargeDiagnosis;
1402        }
1403
1404        public boolean hasDischargeDiagnosis() { 
1405          if (this.dischargeDiagnosis == null)
1406            return false;
1407          for (Reference item : this.dischargeDiagnosis)
1408            if (!item.isEmpty())
1409              return true;
1410          return false;
1411        }
1412
1413        /**
1414         * @return {@link #dischargeDiagnosis} (The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.)
1415         */
1416    // syntactic sugar
1417        public Reference addDischargeDiagnosis() { //3
1418          Reference t = new Reference();
1419          if (this.dischargeDiagnosis == null)
1420            this.dischargeDiagnosis = new ArrayList<Reference>();
1421          this.dischargeDiagnosis.add(t);
1422          return t;
1423        }
1424
1425    // syntactic sugar
1426        public EncounterHospitalizationComponent addDischargeDiagnosis(Reference t) { //3
1427          if (t == null)
1428            return this;
1429          if (this.dischargeDiagnosis == null)
1430            this.dischargeDiagnosis = new ArrayList<Reference>();
1431          this.dischargeDiagnosis.add(t);
1432          return this;
1433        }
1434
1435        /**
1436         * @return {@link #dischargeDiagnosis} (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. The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.)
1437         */
1438        public List<Condition> getDischargeDiagnosisTarget() { 
1439          if (this.dischargeDiagnosisTarget == null)
1440            this.dischargeDiagnosisTarget = new ArrayList<Condition>();
1441          return this.dischargeDiagnosisTarget;
1442        }
1443
1444    // syntactic sugar
1445        /**
1446         * @return {@link #dischargeDiagnosis} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.)
1447         */
1448        public Condition addDischargeDiagnosisTarget() { 
1449          Condition r = new Condition();
1450          if (this.dischargeDiagnosisTarget == null)
1451            this.dischargeDiagnosisTarget = new ArrayList<Condition>();
1452          this.dischargeDiagnosisTarget.add(r);
1453          return r;
1454        }
1455
1456        protected void listChildren(List<Property> childrenList) {
1457          super.listChildren(childrenList);
1458          childrenList.add(new Property("preAdmissionIdentifier", "Identifier", "Pre-admission identifier.", 0, java.lang.Integer.MAX_VALUE, preAdmissionIdentifier));
1459          childrenList.add(new Property("origin", "Reference(Location)", "The location from which the patient came before admission.", 0, java.lang.Integer.MAX_VALUE, origin));
1460          childrenList.add(new Property("admitSource", "CodeableConcept", "From where patient was admitted (physician referral, transfer).", 0, java.lang.Integer.MAX_VALUE, admitSource));
1461          childrenList.add(new Property("admittingDiagnosis", "Reference(Condition)", "The admitting diagnosis field is used to record the diagnosis codes as reported by admitting practitioner. This could be different or in addition to the conditions reported as reason-condition(s) for the encounter.", 0, java.lang.Integer.MAX_VALUE, admittingDiagnosis));
1462          childrenList.add(new Property("reAdmission", "CodeableConcept", "Whether this hospitalization is a readmission and why if known.", 0, java.lang.Integer.MAX_VALUE, reAdmission));
1463          childrenList.add(new Property("dietPreference", "CodeableConcept", "Diet preferences reported by the patient.", 0, java.lang.Integer.MAX_VALUE, dietPreference));
1464          childrenList.add(new Property("specialCourtesy", "CodeableConcept", "Special courtesies (VIP, board member).", 0, java.lang.Integer.MAX_VALUE, specialCourtesy));
1465          childrenList.add(new Property("specialArrangement", "CodeableConcept", "Wheelchair, translator, stretcher, etc.", 0, java.lang.Integer.MAX_VALUE, specialArrangement));
1466          childrenList.add(new Property("destination", "Reference(Location)", "Location to which the patient is discharged.", 0, java.lang.Integer.MAX_VALUE, destination));
1467          childrenList.add(new Property("dischargeDisposition", "CodeableConcept", "Category or kind of location after discharge.", 0, java.lang.Integer.MAX_VALUE, dischargeDisposition));
1468          childrenList.add(new Property("dischargeDiagnosis", "Reference(Condition)", "The final diagnosis given a patient before release from the hospital after all testing, surgery, and workup are complete.", 0, java.lang.Integer.MAX_VALUE, dischargeDiagnosis));
1469        }
1470
1471      @Override
1472      public void setProperty(String name, Base value) throws FHIRException {
1473        if (name.equals("preAdmissionIdentifier"))
1474          this.preAdmissionIdentifier = castToIdentifier(value); // Identifier
1475        else if (name.equals("origin"))
1476          this.origin = castToReference(value); // Reference
1477        else if (name.equals("admitSource"))
1478          this.admitSource = castToCodeableConcept(value); // CodeableConcept
1479        else if (name.equals("admittingDiagnosis"))
1480          this.getAdmittingDiagnosis().add(castToReference(value));
1481        else if (name.equals("reAdmission"))
1482          this.reAdmission = castToCodeableConcept(value); // CodeableConcept
1483        else if (name.equals("dietPreference"))
1484          this.getDietPreference().add(castToCodeableConcept(value));
1485        else if (name.equals("specialCourtesy"))
1486          this.getSpecialCourtesy().add(castToCodeableConcept(value));
1487        else if (name.equals("specialArrangement"))
1488          this.getSpecialArrangement().add(castToCodeableConcept(value));
1489        else if (name.equals("destination"))
1490          this.destination = castToReference(value); // Reference
1491        else if (name.equals("dischargeDisposition"))
1492          this.dischargeDisposition = castToCodeableConcept(value); // CodeableConcept
1493        else if (name.equals("dischargeDiagnosis"))
1494          this.getDischargeDiagnosis().add(castToReference(value));
1495        else
1496          super.setProperty(name, value);
1497      }
1498
1499      @Override
1500      public Base addChild(String name) throws FHIRException {
1501        if (name.equals("preAdmissionIdentifier")) {
1502          this.preAdmissionIdentifier = new Identifier();
1503          return this.preAdmissionIdentifier;
1504        }
1505        else if (name.equals("origin")) {
1506          this.origin = new Reference();
1507          return this.origin;
1508        }
1509        else if (name.equals("admitSource")) {
1510          this.admitSource = new CodeableConcept();
1511          return this.admitSource;
1512        }
1513        else if (name.equals("admittingDiagnosis")) {
1514          return addAdmittingDiagnosis();
1515        }
1516        else if (name.equals("reAdmission")) {
1517          this.reAdmission = new CodeableConcept();
1518          return this.reAdmission;
1519        }
1520        else if (name.equals("dietPreference")) {
1521          return addDietPreference();
1522        }
1523        else if (name.equals("specialCourtesy")) {
1524          return addSpecialCourtesy();
1525        }
1526        else if (name.equals("specialArrangement")) {
1527          return addSpecialArrangement();
1528        }
1529        else if (name.equals("destination")) {
1530          this.destination = new Reference();
1531          return this.destination;
1532        }
1533        else if (name.equals("dischargeDisposition")) {
1534          this.dischargeDisposition = new CodeableConcept();
1535          return this.dischargeDisposition;
1536        }
1537        else if (name.equals("dischargeDiagnosis")) {
1538          return addDischargeDiagnosis();
1539        }
1540        else
1541          return super.addChild(name);
1542      }
1543
1544      public EncounterHospitalizationComponent copy() {
1545        EncounterHospitalizationComponent dst = new EncounterHospitalizationComponent();
1546        copyValues(dst);
1547        dst.preAdmissionIdentifier = preAdmissionIdentifier == null ? null : preAdmissionIdentifier.copy();
1548        dst.origin = origin == null ? null : origin.copy();
1549        dst.admitSource = admitSource == null ? null : admitSource.copy();
1550        if (admittingDiagnosis != null) {
1551          dst.admittingDiagnosis = new ArrayList<Reference>();
1552          for (Reference i : admittingDiagnosis)
1553            dst.admittingDiagnosis.add(i.copy());
1554        };
1555        dst.reAdmission = reAdmission == null ? null : reAdmission.copy();
1556        if (dietPreference != null) {
1557          dst.dietPreference = new ArrayList<CodeableConcept>();
1558          for (CodeableConcept i : dietPreference)
1559            dst.dietPreference.add(i.copy());
1560        };
1561        if (specialCourtesy != null) {
1562          dst.specialCourtesy = new ArrayList<CodeableConcept>();
1563          for (CodeableConcept i : specialCourtesy)
1564            dst.specialCourtesy.add(i.copy());
1565        };
1566        if (specialArrangement != null) {
1567          dst.specialArrangement = new ArrayList<CodeableConcept>();
1568          for (CodeableConcept i : specialArrangement)
1569            dst.specialArrangement.add(i.copy());
1570        };
1571        dst.destination = destination == null ? null : destination.copy();
1572        dst.dischargeDisposition = dischargeDisposition == null ? null : dischargeDisposition.copy();
1573        if (dischargeDiagnosis != null) {
1574          dst.dischargeDiagnosis = new ArrayList<Reference>();
1575          for (Reference i : dischargeDiagnosis)
1576            dst.dischargeDiagnosis.add(i.copy());
1577        };
1578        return dst;
1579      }
1580
1581      @Override
1582      public boolean equalsDeep(Base other) {
1583        if (!super.equalsDeep(other))
1584          return false;
1585        if (!(other instanceof EncounterHospitalizationComponent))
1586          return false;
1587        EncounterHospitalizationComponent o = (EncounterHospitalizationComponent) other;
1588        return compareDeep(preAdmissionIdentifier, o.preAdmissionIdentifier, true) && compareDeep(origin, o.origin, true)
1589           && compareDeep(admitSource, o.admitSource, true) && compareDeep(admittingDiagnosis, o.admittingDiagnosis, true)
1590           && compareDeep(reAdmission, o.reAdmission, true) && compareDeep(dietPreference, o.dietPreference, true)
1591           && compareDeep(specialCourtesy, o.specialCourtesy, true) && compareDeep(specialArrangement, o.specialArrangement, true)
1592           && compareDeep(destination, o.destination, true) && compareDeep(dischargeDisposition, o.dischargeDisposition, true)
1593           && compareDeep(dischargeDiagnosis, o.dischargeDiagnosis, true);
1594      }
1595
1596      @Override
1597      public boolean equalsShallow(Base other) {
1598        if (!super.equalsShallow(other))
1599          return false;
1600        if (!(other instanceof EncounterHospitalizationComponent))
1601          return false;
1602        EncounterHospitalizationComponent o = (EncounterHospitalizationComponent) other;
1603        return true;
1604      }
1605
1606      public boolean isEmpty() {
1607        return super.isEmpty() && (preAdmissionIdentifier == null || preAdmissionIdentifier.isEmpty())
1608           && (origin == null || origin.isEmpty()) && (admitSource == null || admitSource.isEmpty())
1609           && (admittingDiagnosis == null || admittingDiagnosis.isEmpty()) && (reAdmission == null || reAdmission.isEmpty())
1610           && (dietPreference == null || dietPreference.isEmpty()) && (specialCourtesy == null || specialCourtesy.isEmpty())
1611           && (specialArrangement == null || specialArrangement.isEmpty()) && (destination == null || destination.isEmpty())
1612           && (dischargeDisposition == null || dischargeDisposition.isEmpty()) && (dischargeDiagnosis == null || dischargeDiagnosis.isEmpty())
1613          ;
1614      }
1615
1616  public String fhirType() {
1617    return "Encounter.hospitalization";
1618
1619  }
1620
1621  }
1622
1623    @Block()
1624    public static class EncounterLocationComponent extends BackboneElement implements IBaseBackboneElement {
1625        /**
1626         * The location where the encounter takes place.
1627         */
1628        @Child(name = "location", type = {Location.class}, order=1, min=1, max=1, modifier=false, summary=false)
1629        @Description(shortDefinition="Location the encounter takes place", formalDefinition="The location where the encounter takes place." )
1630        protected Reference location;
1631
1632        /**
1633         * The actual object that is the target of the reference (The location where the encounter takes place.)
1634         */
1635        protected Location locationTarget;
1636
1637        /**
1638         * The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time.
1639         */
1640        @Child(name = "status", type = {CodeType.class}, order=2, min=0, max=1, modifier=false, summary=false)
1641        @Description(shortDefinition="planned | active | reserved | completed", formalDefinition="The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time." )
1642        protected Enumeration<EncounterLocationStatus> status;
1643
1644        /**
1645         * Time period during which the patient was present at the location.
1646         */
1647        @Child(name = "period", type = {Period.class}, order=3, min=0, max=1, modifier=false, summary=false)
1648        @Description(shortDefinition="Time period during which the patient was present at the location", formalDefinition="Time period during which the patient was present at the location." )
1649        protected Period period;
1650
1651        private static final long serialVersionUID = -322984880L;
1652
1653    /*
1654     * Constructor
1655     */
1656      public EncounterLocationComponent() {
1657        super();
1658      }
1659
1660    /*
1661     * Constructor
1662     */
1663      public EncounterLocationComponent(Reference location) {
1664        super();
1665        this.location = location;
1666      }
1667
1668        /**
1669         * @return {@link #location} (The location where the encounter takes place.)
1670         */
1671        public Reference getLocation() { 
1672          if (this.location == null)
1673            if (Configuration.errorOnAutoCreate())
1674              throw new Error("Attempt to auto-create EncounterLocationComponent.location");
1675            else if (Configuration.doAutoCreate())
1676              this.location = new Reference(); // cc
1677          return this.location;
1678        }
1679
1680        public boolean hasLocation() { 
1681          return this.location != null && !this.location.isEmpty();
1682        }
1683
1684        /**
1685         * @param value {@link #location} (The location where the encounter takes place.)
1686         */
1687        public EncounterLocationComponent setLocation(Reference value) { 
1688          this.location = value;
1689          return this;
1690        }
1691
1692        /**
1693         * @return {@link #location} 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 location where the encounter takes place.)
1694         */
1695        public Location getLocationTarget() { 
1696          if (this.locationTarget == null)
1697            if (Configuration.errorOnAutoCreate())
1698              throw new Error("Attempt to auto-create EncounterLocationComponent.location");
1699            else if (Configuration.doAutoCreate())
1700              this.locationTarget = new Location(); // aa
1701          return this.locationTarget;
1702        }
1703
1704        /**
1705         * @param value {@link #location} 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 location where the encounter takes place.)
1706         */
1707        public EncounterLocationComponent setLocationTarget(Location value) { 
1708          this.locationTarget = value;
1709          return this;
1710        }
1711
1712        /**
1713         * @return {@link #status} (The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1714         */
1715        public Enumeration<EncounterLocationStatus> getStatusElement() { 
1716          if (this.status == null)
1717            if (Configuration.errorOnAutoCreate())
1718              throw new Error("Attempt to auto-create EncounterLocationComponent.status");
1719            else if (Configuration.doAutoCreate())
1720              this.status = new Enumeration<EncounterLocationStatus>(new EncounterLocationStatusEnumFactory()); // bb
1721          return this.status;
1722        }
1723
1724        public boolean hasStatusElement() { 
1725          return this.status != null && !this.status.isEmpty();
1726        }
1727
1728        public boolean hasStatus() { 
1729          return this.status != null && !this.status.isEmpty();
1730        }
1731
1732        /**
1733         * @param value {@link #status} (The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1734         */
1735        public EncounterLocationComponent setStatusElement(Enumeration<EncounterLocationStatus> value) { 
1736          this.status = value;
1737          return this;
1738        }
1739
1740        /**
1741         * @return The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time.
1742         */
1743        public EncounterLocationStatus getStatus() { 
1744          return this.status == null ? null : this.status.getValue();
1745        }
1746
1747        /**
1748         * @param value The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time.
1749         */
1750        public EncounterLocationComponent setStatus(EncounterLocationStatus value) { 
1751          if (value == null)
1752            this.status = null;
1753          else {
1754            if (this.status == null)
1755              this.status = new Enumeration<EncounterLocationStatus>(new EncounterLocationStatusEnumFactory());
1756            this.status.setValue(value);
1757          }
1758          return this;
1759        }
1760
1761        /**
1762         * @return {@link #period} (Time period during which the patient was present at the location.)
1763         */
1764        public Period getPeriod() { 
1765          if (this.period == null)
1766            if (Configuration.errorOnAutoCreate())
1767              throw new Error("Attempt to auto-create EncounterLocationComponent.period");
1768            else if (Configuration.doAutoCreate())
1769              this.period = new Period(); // cc
1770          return this.period;
1771        }
1772
1773        public boolean hasPeriod() { 
1774          return this.period != null && !this.period.isEmpty();
1775        }
1776
1777        /**
1778         * @param value {@link #period} (Time period during which the patient was present at the location.)
1779         */
1780        public EncounterLocationComponent setPeriod(Period value) { 
1781          this.period = value;
1782          return this;
1783        }
1784
1785        protected void listChildren(List<Property> childrenList) {
1786          super.listChildren(childrenList);
1787          childrenList.add(new Property("location", "Reference(Location)", "The location where the encounter takes place.", 0, java.lang.Integer.MAX_VALUE, location));
1788          childrenList.add(new Property("status", "code", "The status of the participants' presence at the specified location during the period specified. If the participant is is no longer at the location, then the period will have an end date/time.", 0, java.lang.Integer.MAX_VALUE, status));
1789          childrenList.add(new Property("period", "Period", "Time period during which the patient was present at the location.", 0, java.lang.Integer.MAX_VALUE, period));
1790        }
1791
1792      @Override
1793      public void setProperty(String name, Base value) throws FHIRException {
1794        if (name.equals("location"))
1795          this.location = castToReference(value); // Reference
1796        else if (name.equals("status"))
1797          this.status = new EncounterLocationStatusEnumFactory().fromType(value); // Enumeration<EncounterLocationStatus>
1798        else if (name.equals("period"))
1799          this.period = castToPeriod(value); // Period
1800        else
1801          super.setProperty(name, value);
1802      }
1803
1804      @Override
1805      public Base addChild(String name) throws FHIRException {
1806        if (name.equals("location")) {
1807          this.location = new Reference();
1808          return this.location;
1809        }
1810        else if (name.equals("status")) {
1811          throw new FHIRException("Cannot call addChild on a primitive type Encounter.status");
1812        }
1813        else if (name.equals("period")) {
1814          this.period = new Period();
1815          return this.period;
1816        }
1817        else
1818          return super.addChild(name);
1819      }
1820
1821      public EncounterLocationComponent copy() {
1822        EncounterLocationComponent dst = new EncounterLocationComponent();
1823        copyValues(dst);
1824        dst.location = location == null ? null : location.copy();
1825        dst.status = status == null ? null : status.copy();
1826        dst.period = period == null ? null : period.copy();
1827        return dst;
1828      }
1829
1830      @Override
1831      public boolean equalsDeep(Base other) {
1832        if (!super.equalsDeep(other))
1833          return false;
1834        if (!(other instanceof EncounterLocationComponent))
1835          return false;
1836        EncounterLocationComponent o = (EncounterLocationComponent) other;
1837        return compareDeep(location, o.location, true) && compareDeep(status, o.status, true) && compareDeep(period, o.period, true)
1838          ;
1839      }
1840
1841      @Override
1842      public boolean equalsShallow(Base other) {
1843        if (!super.equalsShallow(other))
1844          return false;
1845        if (!(other instanceof EncounterLocationComponent))
1846          return false;
1847        EncounterLocationComponent o = (EncounterLocationComponent) other;
1848        return compareValues(status, o.status, true);
1849      }
1850
1851      public boolean isEmpty() {
1852        return super.isEmpty() && (location == null || location.isEmpty()) && (status == null || status.isEmpty())
1853           && (period == null || period.isEmpty());
1854      }
1855
1856  public String fhirType() {
1857    return "Encounter.location";
1858
1859  }
1860
1861  }
1862
1863    /**
1864     * Identifier(s) by which this encounter is known.
1865     */
1866    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1867    @Description(shortDefinition="Identifier(s) by which this encounter is known", formalDefinition="Identifier(s) by which this encounter is known." )
1868    protected List<Identifier> identifier;
1869
1870    /**
1871     * planned | arrived | in-progress | onleave | finished | cancelled.
1872     */
1873    @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=true, summary=true)
1874    @Description(shortDefinition="planned | arrived | in-progress | onleave | finished | cancelled", formalDefinition="planned | arrived | in-progress | onleave | finished | cancelled." )
1875    protected Enumeration<EncounterState> status;
1876
1877    /**
1878     * The status history permits the encounter resource to contain the status history without needing to read through the historical versions of the resource, or even have the server store them.
1879     */
1880    @Child(name = "statusHistory", type = {}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1881    @Description(shortDefinition="List of past encounter statuses", formalDefinition="The status history permits the encounter resource to contain the status history without needing to read through the historical versions of the resource, or even have the server store them." )
1882    protected List<EncounterStatusHistoryComponent> statusHistory;
1883
1884    /**
1885     * inpatient | outpatient | ambulatory | emergency +.
1886     */
1887    @Child(name = "class", type = {CodeType.class}, order=3, min=0, max=1, modifier=false, summary=true)
1888    @Description(shortDefinition="inpatient | outpatient | ambulatory | emergency +", formalDefinition="inpatient | outpatient | ambulatory | emergency +." )
1889    protected Enumeration<EncounterClass> class_;
1890
1891    /**
1892     * Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation).
1893     */
1894    @Child(name = "type", type = {CodeableConcept.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1895    @Description(shortDefinition="Specific type of encounter", formalDefinition="Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation)." )
1896    protected List<CodeableConcept> type;
1897
1898    /**
1899     * Indicates the urgency of the encounter.
1900     */
1901    @Child(name = "priority", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=false)
1902    @Description(shortDefinition="Indicates the urgency of the encounter", formalDefinition="Indicates the urgency of the encounter." )
1903    protected CodeableConcept priority;
1904
1905    /**
1906     * The patient present at the encounter.
1907     */
1908    @Child(name = "patient", type = {Patient.class}, order=6, min=0, max=1, modifier=false, summary=true)
1909    @Description(shortDefinition="The patient present at the encounter", formalDefinition="The patient present at the encounter." )
1910    protected Reference patient;
1911
1912    /**
1913     * The actual object that is the target of the reference (The patient present at the encounter.)
1914     */
1915    protected Patient patientTarget;
1916
1917    /**
1918     * Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).
1919     */
1920    @Child(name = "episodeOfCare", type = {EpisodeOfCare.class}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1921    @Description(shortDefinition="Episode(s) of care that this encounter should be recorded against", formalDefinition="Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years)." )
1922    protected List<Reference> episodeOfCare;
1923    /**
1924     * The actual objects that are the target of the reference (Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).)
1925     */
1926    protected List<EpisodeOfCare> episodeOfCareTarget;
1927
1928
1929    /**
1930     * The referral request this encounter satisfies (incoming referral).
1931     */
1932    @Child(name = "incomingReferral", type = {ReferralRequest.class}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1933    @Description(shortDefinition="The ReferralRequest that initiated this encounter", formalDefinition="The referral request this encounter satisfies (incoming referral)." )
1934    protected List<Reference> incomingReferral;
1935    /**
1936     * The actual objects that are the target of the reference (The referral request this encounter satisfies (incoming referral).)
1937     */
1938    protected List<ReferralRequest> incomingReferralTarget;
1939
1940
1941    /**
1942     * The list of people responsible for providing the service.
1943     */
1944    @Child(name = "participant", type = {}, order=9, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1945    @Description(shortDefinition="List of participants involved in the encounter", formalDefinition="The list of people responsible for providing the service." )
1946    protected List<EncounterParticipantComponent> participant;
1947
1948    /**
1949     * The appointment that scheduled this encounter.
1950     */
1951    @Child(name = "appointment", type = {Appointment.class}, order=10, min=0, max=1, modifier=false, summary=true)
1952    @Description(shortDefinition="The appointment that scheduled this encounter", formalDefinition="The appointment that scheduled this encounter." )
1953    protected Reference appointment;
1954
1955    /**
1956     * The actual object that is the target of the reference (The appointment that scheduled this encounter.)
1957     */
1958    protected Appointment appointmentTarget;
1959
1960    /**
1961     * The start and end time of the encounter.
1962     */
1963    @Child(name = "period", type = {Period.class}, order=11, min=0, max=1, modifier=false, summary=false)
1964    @Description(shortDefinition="The start and end time of the encounter", formalDefinition="The start and end time of the encounter." )
1965    protected Period period;
1966
1967    /**
1968     * Quantity of time the encounter lasted. This excludes the time during leaves of absence.
1969     */
1970    @Child(name = "length", type = {Duration.class}, order=12, min=0, max=1, modifier=false, summary=false)
1971    @Description(shortDefinition="Quantity of time the encounter lasted (less time absent)", formalDefinition="Quantity of time the encounter lasted. This excludes the time during leaves of absence." )
1972    protected Duration length;
1973
1974    /**
1975     * Reason the encounter takes place, expressed as a code. For admissions, this can be used for a coded admission diagnosis.
1976     */
1977    @Child(name = "reason", type = {CodeableConcept.class}, order=13, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1978    @Description(shortDefinition="Reason the encounter takes place (code)", formalDefinition="Reason the encounter takes place, expressed as a code. For admissions, this can be used for a coded admission diagnosis." )
1979    protected List<CodeableConcept> reason;
1980
1981    /**
1982     * Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure.
1983     */
1984    @Child(name = "indication", type = {Condition.class, Procedure.class}, order=14, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1985    @Description(shortDefinition="Reason the encounter takes place (resource)", formalDefinition="Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure." )
1986    protected List<Reference> indication;
1987    /**
1988     * The actual objects that are the target of the reference (Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure.)
1989     */
1990    protected List<Resource> indicationTarget;
1991
1992
1993    /**
1994     * Details about the admission to a healthcare service.
1995     */
1996    @Child(name = "hospitalization", type = {}, order=15, min=0, max=1, modifier=false, summary=false)
1997    @Description(shortDefinition="Details about the admission to a healthcare service", formalDefinition="Details about the admission to a healthcare service." )
1998    protected EncounterHospitalizationComponent hospitalization;
1999
2000    /**
2001     * List of locations where  the patient has been during this encounter.
2002     */
2003    @Child(name = "location", type = {}, order=16, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
2004    @Description(shortDefinition="List of locations where the patient has been", formalDefinition="List of locations where  the patient has been during this encounter." )
2005    protected List<EncounterLocationComponent> location;
2006
2007    /**
2008     * An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.
2009     */
2010    @Child(name = "serviceProvider", type = {Organization.class}, order=17, min=0, max=1, modifier=false, summary=false)
2011    @Description(shortDefinition="The custodian organization of this Encounter record", formalDefinition="An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization." )
2012    protected Reference serviceProvider;
2013
2014    /**
2015     * The actual object that is the target of the reference (An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.)
2016     */
2017    protected Organization serviceProviderTarget;
2018
2019    /**
2020     * Another Encounter of which this encounter is a part of (administratively or in time).
2021     */
2022    @Child(name = "partOf", type = {Encounter.class}, order=18, min=0, max=1, modifier=false, summary=false)
2023    @Description(shortDefinition="Another Encounter this encounter is part of", formalDefinition="Another Encounter of which this encounter is a part of (administratively or in time)." )
2024    protected Reference partOf;
2025
2026    /**
2027     * The actual object that is the target of the reference (Another Encounter of which this encounter is a part of (administratively or in time).)
2028     */
2029    protected Encounter partOfTarget;
2030
2031    private static final long serialVersionUID = 929562300L;
2032
2033  /*
2034   * Constructor
2035   */
2036    public Encounter() {
2037      super();
2038    }
2039
2040  /*
2041   * Constructor
2042   */
2043    public Encounter(Enumeration<EncounterState> status) {
2044      super();
2045      this.status = status;
2046    }
2047
2048    /**
2049     * @return {@link #identifier} (Identifier(s) by which this encounter is known.)
2050     */
2051    public List<Identifier> getIdentifier() { 
2052      if (this.identifier == null)
2053        this.identifier = new ArrayList<Identifier>();
2054      return this.identifier;
2055    }
2056
2057    public boolean hasIdentifier() { 
2058      if (this.identifier == null)
2059        return false;
2060      for (Identifier item : this.identifier)
2061        if (!item.isEmpty())
2062          return true;
2063      return false;
2064    }
2065
2066    /**
2067     * @return {@link #identifier} (Identifier(s) by which this encounter is known.)
2068     */
2069    // syntactic sugar
2070    public Identifier addIdentifier() { //3
2071      Identifier t = new Identifier();
2072      if (this.identifier == null)
2073        this.identifier = new ArrayList<Identifier>();
2074      this.identifier.add(t);
2075      return t;
2076    }
2077
2078    // syntactic sugar
2079    public Encounter addIdentifier(Identifier t) { //3
2080      if (t == null)
2081        return this;
2082      if (this.identifier == null)
2083        this.identifier = new ArrayList<Identifier>();
2084      this.identifier.add(t);
2085      return this;
2086    }
2087
2088    /**
2089     * @return {@link #status} (planned | arrived | in-progress | onleave | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
2090     */
2091    public Enumeration<EncounterState> getStatusElement() { 
2092      if (this.status == null)
2093        if (Configuration.errorOnAutoCreate())
2094          throw new Error("Attempt to auto-create Encounter.status");
2095        else if (Configuration.doAutoCreate())
2096          this.status = new Enumeration<EncounterState>(new EncounterStateEnumFactory()); // bb
2097      return this.status;
2098    }
2099
2100    public boolean hasStatusElement() { 
2101      return this.status != null && !this.status.isEmpty();
2102    }
2103
2104    public boolean hasStatus() { 
2105      return this.status != null && !this.status.isEmpty();
2106    }
2107
2108    /**
2109     * @param value {@link #status} (planned | arrived | in-progress | onleave | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
2110     */
2111    public Encounter setStatusElement(Enumeration<EncounterState> value) { 
2112      this.status = value;
2113      return this;
2114    }
2115
2116    /**
2117     * @return planned | arrived | in-progress | onleave | finished | cancelled.
2118     */
2119    public EncounterState getStatus() { 
2120      return this.status == null ? null : this.status.getValue();
2121    }
2122
2123    /**
2124     * @param value planned | arrived | in-progress | onleave | finished | cancelled.
2125     */
2126    public Encounter setStatus(EncounterState value) { 
2127        if (this.status == null)
2128          this.status = new Enumeration<EncounterState>(new EncounterStateEnumFactory());
2129        this.status.setValue(value);
2130      return this;
2131    }
2132
2133    /**
2134     * @return {@link #statusHistory} (The status history permits the encounter resource to contain the status history without needing to read through the historical versions of the resource, or even have the server store them.)
2135     */
2136    public List<EncounterStatusHistoryComponent> getStatusHistory() { 
2137      if (this.statusHistory == null)
2138        this.statusHistory = new ArrayList<EncounterStatusHistoryComponent>();
2139      return this.statusHistory;
2140    }
2141
2142    public boolean hasStatusHistory() { 
2143      if (this.statusHistory == null)
2144        return false;
2145      for (EncounterStatusHistoryComponent item : this.statusHistory)
2146        if (!item.isEmpty())
2147          return true;
2148      return false;
2149    }
2150
2151    /**
2152     * @return {@link #statusHistory} (The status history permits the encounter resource to contain the status history without needing to read through the historical versions of the resource, or even have the server store them.)
2153     */
2154    // syntactic sugar
2155    public EncounterStatusHistoryComponent addStatusHistory() { //3
2156      EncounterStatusHistoryComponent t = new EncounterStatusHistoryComponent();
2157      if (this.statusHistory == null)
2158        this.statusHistory = new ArrayList<EncounterStatusHistoryComponent>();
2159      this.statusHistory.add(t);
2160      return t;
2161    }
2162
2163    // syntactic sugar
2164    public Encounter addStatusHistory(EncounterStatusHistoryComponent t) { //3
2165      if (t == null)
2166        return this;
2167      if (this.statusHistory == null)
2168        this.statusHistory = new ArrayList<EncounterStatusHistoryComponent>();
2169      this.statusHistory.add(t);
2170      return this;
2171    }
2172
2173    /**
2174     * @return {@link #class_} (inpatient | outpatient | ambulatory | emergency +.). This is the underlying object with id, value and extensions. The accessor "getClass_" gives direct access to the value
2175     */
2176    public Enumeration<EncounterClass> getClass_Element() { 
2177      if (this.class_ == null)
2178        if (Configuration.errorOnAutoCreate())
2179          throw new Error("Attempt to auto-create Encounter.class_");
2180        else if (Configuration.doAutoCreate())
2181          this.class_ = new Enumeration<EncounterClass>(new EncounterClassEnumFactory()); // bb
2182      return this.class_;
2183    }
2184
2185    public boolean hasClass_Element() { 
2186      return this.class_ != null && !this.class_.isEmpty();
2187    }
2188
2189    public boolean hasClass_() { 
2190      return this.class_ != null && !this.class_.isEmpty();
2191    }
2192
2193    /**
2194     * @param value {@link #class_} (inpatient | outpatient | ambulatory | emergency +.). This is the underlying object with id, value and extensions. The accessor "getClass_" gives direct access to the value
2195     */
2196    public Encounter setClass_Element(Enumeration<EncounterClass> value) { 
2197      this.class_ = value;
2198      return this;
2199    }
2200
2201    /**
2202     * @return inpatient | outpatient | ambulatory | emergency +.
2203     */
2204    public EncounterClass getClass_() { 
2205      return this.class_ == null ? null : this.class_.getValue();
2206    }
2207
2208    /**
2209     * @param value inpatient | outpatient | ambulatory | emergency +.
2210     */
2211    public Encounter setClass_(EncounterClass value) { 
2212      if (value == null)
2213        this.class_ = null;
2214      else {
2215        if (this.class_ == null)
2216          this.class_ = new Enumeration<EncounterClass>(new EncounterClassEnumFactory());
2217        this.class_.setValue(value);
2218      }
2219      return this;
2220    }
2221
2222    /**
2223     * @return {@link #type} (Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation).)
2224     */
2225    public List<CodeableConcept> getType() { 
2226      if (this.type == null)
2227        this.type = new ArrayList<CodeableConcept>();
2228      return this.type;
2229    }
2230
2231    public boolean hasType() { 
2232      if (this.type == null)
2233        return false;
2234      for (CodeableConcept item : this.type)
2235        if (!item.isEmpty())
2236          return true;
2237      return false;
2238    }
2239
2240    /**
2241     * @return {@link #type} (Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation).)
2242     */
2243    // syntactic sugar
2244    public CodeableConcept addType() { //3
2245      CodeableConcept t = new CodeableConcept();
2246      if (this.type == null)
2247        this.type = new ArrayList<CodeableConcept>();
2248      this.type.add(t);
2249      return t;
2250    }
2251
2252    // syntactic sugar
2253    public Encounter addType(CodeableConcept t) { //3
2254      if (t == null)
2255        return this;
2256      if (this.type == null)
2257        this.type = new ArrayList<CodeableConcept>();
2258      this.type.add(t);
2259      return this;
2260    }
2261
2262    /**
2263     * @return {@link #priority} (Indicates the urgency of the encounter.)
2264     */
2265    public CodeableConcept getPriority() { 
2266      if (this.priority == null)
2267        if (Configuration.errorOnAutoCreate())
2268          throw new Error("Attempt to auto-create Encounter.priority");
2269        else if (Configuration.doAutoCreate())
2270          this.priority = new CodeableConcept(); // cc
2271      return this.priority;
2272    }
2273
2274    public boolean hasPriority() { 
2275      return this.priority != null && !this.priority.isEmpty();
2276    }
2277
2278    /**
2279     * @param value {@link #priority} (Indicates the urgency of the encounter.)
2280     */
2281    public Encounter setPriority(CodeableConcept value) { 
2282      this.priority = value;
2283      return this;
2284    }
2285
2286    /**
2287     * @return {@link #patient} (The patient present at the encounter.)
2288     */
2289    public Reference getPatient() { 
2290      if (this.patient == null)
2291        if (Configuration.errorOnAutoCreate())
2292          throw new Error("Attempt to auto-create Encounter.patient");
2293        else if (Configuration.doAutoCreate())
2294          this.patient = new Reference(); // cc
2295      return this.patient;
2296    }
2297
2298    public boolean hasPatient() { 
2299      return this.patient != null && !this.patient.isEmpty();
2300    }
2301
2302    /**
2303     * @param value {@link #patient} (The patient present at the encounter.)
2304     */
2305    public Encounter setPatient(Reference value) { 
2306      this.patient = value;
2307      return this;
2308    }
2309
2310    /**
2311     * @return {@link #patient} 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 present at the encounter.)
2312     */
2313    public Patient getPatientTarget() { 
2314      if (this.patientTarget == null)
2315        if (Configuration.errorOnAutoCreate())
2316          throw new Error("Attempt to auto-create Encounter.patient");
2317        else if (Configuration.doAutoCreate())
2318          this.patientTarget = new Patient(); // aa
2319      return this.patientTarget;
2320    }
2321
2322    /**
2323     * @param value {@link #patient} 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 present at the encounter.)
2324     */
2325    public Encounter setPatientTarget(Patient value) { 
2326      this.patientTarget = value;
2327      return this;
2328    }
2329
2330    /**
2331     * @return {@link #episodeOfCare} (Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).)
2332     */
2333    public List<Reference> getEpisodeOfCare() { 
2334      if (this.episodeOfCare == null)
2335        this.episodeOfCare = new ArrayList<Reference>();
2336      return this.episodeOfCare;
2337    }
2338
2339    public boolean hasEpisodeOfCare() { 
2340      if (this.episodeOfCare == null)
2341        return false;
2342      for (Reference item : this.episodeOfCare)
2343        if (!item.isEmpty())
2344          return true;
2345      return false;
2346    }
2347
2348    /**
2349     * @return {@link #episodeOfCare} (Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).)
2350     */
2351    // syntactic sugar
2352    public Reference addEpisodeOfCare() { //3
2353      Reference t = new Reference();
2354      if (this.episodeOfCare == null)
2355        this.episodeOfCare = new ArrayList<Reference>();
2356      this.episodeOfCare.add(t);
2357      return t;
2358    }
2359
2360    // syntactic sugar
2361    public Encounter addEpisodeOfCare(Reference t) { //3
2362      if (t == null)
2363        return this;
2364      if (this.episodeOfCare == null)
2365        this.episodeOfCare = new ArrayList<Reference>();
2366      this.episodeOfCare.add(t);
2367      return this;
2368    }
2369
2370    /**
2371     * @return {@link #episodeOfCare} (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. Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).)
2372     */
2373    public List<EpisodeOfCare> getEpisodeOfCareTarget() { 
2374      if (this.episodeOfCareTarget == null)
2375        this.episodeOfCareTarget = new ArrayList<EpisodeOfCare>();
2376      return this.episodeOfCareTarget;
2377    }
2378
2379    // syntactic sugar
2380    /**
2381     * @return {@link #episodeOfCare} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).)
2382     */
2383    public EpisodeOfCare addEpisodeOfCareTarget() { 
2384      EpisodeOfCare r = new EpisodeOfCare();
2385      if (this.episodeOfCareTarget == null)
2386        this.episodeOfCareTarget = new ArrayList<EpisodeOfCare>();
2387      this.episodeOfCareTarget.add(r);
2388      return r;
2389    }
2390
2391    /**
2392     * @return {@link #incomingReferral} (The referral request this encounter satisfies (incoming referral).)
2393     */
2394    public List<Reference> getIncomingReferral() { 
2395      if (this.incomingReferral == null)
2396        this.incomingReferral = new ArrayList<Reference>();
2397      return this.incomingReferral;
2398    }
2399
2400    public boolean hasIncomingReferral() { 
2401      if (this.incomingReferral == null)
2402        return false;
2403      for (Reference item : this.incomingReferral)
2404        if (!item.isEmpty())
2405          return true;
2406      return false;
2407    }
2408
2409    /**
2410     * @return {@link #incomingReferral} (The referral request this encounter satisfies (incoming referral).)
2411     */
2412    // syntactic sugar
2413    public Reference addIncomingReferral() { //3
2414      Reference t = new Reference();
2415      if (this.incomingReferral == null)
2416        this.incomingReferral = new ArrayList<Reference>();
2417      this.incomingReferral.add(t);
2418      return t;
2419    }
2420
2421    // syntactic sugar
2422    public Encounter addIncomingReferral(Reference t) { //3
2423      if (t == null)
2424        return this;
2425      if (this.incomingReferral == null)
2426        this.incomingReferral = new ArrayList<Reference>();
2427      this.incomingReferral.add(t);
2428      return this;
2429    }
2430
2431    /**
2432     * @return {@link #incomingReferral} (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. The referral request this encounter satisfies (incoming referral).)
2433     */
2434    public List<ReferralRequest> getIncomingReferralTarget() { 
2435      if (this.incomingReferralTarget == null)
2436        this.incomingReferralTarget = new ArrayList<ReferralRequest>();
2437      return this.incomingReferralTarget;
2438    }
2439
2440    // syntactic sugar
2441    /**
2442     * @return {@link #incomingReferral} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. The referral request this encounter satisfies (incoming referral).)
2443     */
2444    public ReferralRequest addIncomingReferralTarget() { 
2445      ReferralRequest r = new ReferralRequest();
2446      if (this.incomingReferralTarget == null)
2447        this.incomingReferralTarget = new ArrayList<ReferralRequest>();
2448      this.incomingReferralTarget.add(r);
2449      return r;
2450    }
2451
2452    /**
2453     * @return {@link #participant} (The list of people responsible for providing the service.)
2454     */
2455    public List<EncounterParticipantComponent> getParticipant() { 
2456      if (this.participant == null)
2457        this.participant = new ArrayList<EncounterParticipantComponent>();
2458      return this.participant;
2459    }
2460
2461    public boolean hasParticipant() { 
2462      if (this.participant == null)
2463        return false;
2464      for (EncounterParticipantComponent item : this.participant)
2465        if (!item.isEmpty())
2466          return true;
2467      return false;
2468    }
2469
2470    /**
2471     * @return {@link #participant} (The list of people responsible for providing the service.)
2472     */
2473    // syntactic sugar
2474    public EncounterParticipantComponent addParticipant() { //3
2475      EncounterParticipantComponent t = new EncounterParticipantComponent();
2476      if (this.participant == null)
2477        this.participant = new ArrayList<EncounterParticipantComponent>();
2478      this.participant.add(t);
2479      return t;
2480    }
2481
2482    // syntactic sugar
2483    public Encounter addParticipant(EncounterParticipantComponent t) { //3
2484      if (t == null)
2485        return this;
2486      if (this.participant == null)
2487        this.participant = new ArrayList<EncounterParticipantComponent>();
2488      this.participant.add(t);
2489      return this;
2490    }
2491
2492    /**
2493     * @return {@link #appointment} (The appointment that scheduled this encounter.)
2494     */
2495    public Reference getAppointment() { 
2496      if (this.appointment == null)
2497        if (Configuration.errorOnAutoCreate())
2498          throw new Error("Attempt to auto-create Encounter.appointment");
2499        else if (Configuration.doAutoCreate())
2500          this.appointment = new Reference(); // cc
2501      return this.appointment;
2502    }
2503
2504    public boolean hasAppointment() { 
2505      return this.appointment != null && !this.appointment.isEmpty();
2506    }
2507
2508    /**
2509     * @param value {@link #appointment} (The appointment that scheduled this encounter.)
2510     */
2511    public Encounter setAppointment(Reference value) { 
2512      this.appointment = value;
2513      return this;
2514    }
2515
2516    /**
2517     * @return {@link #appointment} 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 appointment that scheduled this encounter.)
2518     */
2519    public Appointment getAppointmentTarget() { 
2520      if (this.appointmentTarget == null)
2521        if (Configuration.errorOnAutoCreate())
2522          throw new Error("Attempt to auto-create Encounter.appointment");
2523        else if (Configuration.doAutoCreate())
2524          this.appointmentTarget = new Appointment(); // aa
2525      return this.appointmentTarget;
2526    }
2527
2528    /**
2529     * @param value {@link #appointment} 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 appointment that scheduled this encounter.)
2530     */
2531    public Encounter setAppointmentTarget(Appointment value) { 
2532      this.appointmentTarget = value;
2533      return this;
2534    }
2535
2536    /**
2537     * @return {@link #period} (The start and end time of the encounter.)
2538     */
2539    public Period getPeriod() { 
2540      if (this.period == null)
2541        if (Configuration.errorOnAutoCreate())
2542          throw new Error("Attempt to auto-create Encounter.period");
2543        else if (Configuration.doAutoCreate())
2544          this.period = new Period(); // cc
2545      return this.period;
2546    }
2547
2548    public boolean hasPeriod() { 
2549      return this.period != null && !this.period.isEmpty();
2550    }
2551
2552    /**
2553     * @param value {@link #period} (The start and end time of the encounter.)
2554     */
2555    public Encounter setPeriod(Period value) { 
2556      this.period = value;
2557      return this;
2558    }
2559
2560    /**
2561     * @return {@link #length} (Quantity of time the encounter lasted. This excludes the time during leaves of absence.)
2562     */
2563    public Duration getLength() { 
2564      if (this.length == null)
2565        if (Configuration.errorOnAutoCreate())
2566          throw new Error("Attempt to auto-create Encounter.length");
2567        else if (Configuration.doAutoCreate())
2568          this.length = new Duration(); // cc
2569      return this.length;
2570    }
2571
2572    public boolean hasLength() { 
2573      return this.length != null && !this.length.isEmpty();
2574    }
2575
2576    /**
2577     * @param value {@link #length} (Quantity of time the encounter lasted. This excludes the time during leaves of absence.)
2578     */
2579    public Encounter setLength(Duration value) { 
2580      this.length = value;
2581      return this;
2582    }
2583
2584    /**
2585     * @return {@link #reason} (Reason the encounter takes place, expressed as a code. For admissions, this can be used for a coded admission diagnosis.)
2586     */
2587    public List<CodeableConcept> getReason() { 
2588      if (this.reason == null)
2589        this.reason = new ArrayList<CodeableConcept>();
2590      return this.reason;
2591    }
2592
2593    public boolean hasReason() { 
2594      if (this.reason == null)
2595        return false;
2596      for (CodeableConcept item : this.reason)
2597        if (!item.isEmpty())
2598          return true;
2599      return false;
2600    }
2601
2602    /**
2603     * @return {@link #reason} (Reason the encounter takes place, expressed as a code. For admissions, this can be used for a coded admission diagnosis.)
2604     */
2605    // syntactic sugar
2606    public CodeableConcept addReason() { //3
2607      CodeableConcept t = new CodeableConcept();
2608      if (this.reason == null)
2609        this.reason = new ArrayList<CodeableConcept>();
2610      this.reason.add(t);
2611      return t;
2612    }
2613
2614    // syntactic sugar
2615    public Encounter addReason(CodeableConcept t) { //3
2616      if (t == null)
2617        return this;
2618      if (this.reason == null)
2619        this.reason = new ArrayList<CodeableConcept>();
2620      this.reason.add(t);
2621      return this;
2622    }
2623
2624    /**
2625     * @return {@link #indication} (Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure.)
2626     */
2627    public List<Reference> getIndication() { 
2628      if (this.indication == null)
2629        this.indication = new ArrayList<Reference>();
2630      return this.indication;
2631    }
2632
2633    public boolean hasIndication() { 
2634      if (this.indication == null)
2635        return false;
2636      for (Reference item : this.indication)
2637        if (!item.isEmpty())
2638          return true;
2639      return false;
2640    }
2641
2642    /**
2643     * @return {@link #indication} (Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure.)
2644     */
2645    // syntactic sugar
2646    public Reference addIndication() { //3
2647      Reference t = new Reference();
2648      if (this.indication == null)
2649        this.indication = new ArrayList<Reference>();
2650      this.indication.add(t);
2651      return t;
2652    }
2653
2654    // syntactic sugar
2655    public Encounter addIndication(Reference t) { //3
2656      if (t == null)
2657        return this;
2658      if (this.indication == null)
2659        this.indication = new ArrayList<Reference>();
2660      this.indication.add(t);
2661      return this;
2662    }
2663
2664    /**
2665     * @return {@link #indication} (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. Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure.)
2666     */
2667    public List<Resource> getIndicationTarget() { 
2668      if (this.indicationTarget == null)
2669        this.indicationTarget = new ArrayList<Resource>();
2670      return this.indicationTarget;
2671    }
2672
2673    /**
2674     * @return {@link #hospitalization} (Details about the admission to a healthcare service.)
2675     */
2676    public EncounterHospitalizationComponent getHospitalization() { 
2677      if (this.hospitalization == null)
2678        if (Configuration.errorOnAutoCreate())
2679          throw new Error("Attempt to auto-create Encounter.hospitalization");
2680        else if (Configuration.doAutoCreate())
2681          this.hospitalization = new EncounterHospitalizationComponent(); // cc
2682      return this.hospitalization;
2683    }
2684
2685    public boolean hasHospitalization() { 
2686      return this.hospitalization != null && !this.hospitalization.isEmpty();
2687    }
2688
2689    /**
2690     * @param value {@link #hospitalization} (Details about the admission to a healthcare service.)
2691     */
2692    public Encounter setHospitalization(EncounterHospitalizationComponent value) { 
2693      this.hospitalization = value;
2694      return this;
2695    }
2696
2697    /**
2698     * @return {@link #location} (List of locations where  the patient has been during this encounter.)
2699     */
2700    public List<EncounterLocationComponent> getLocation() { 
2701      if (this.location == null)
2702        this.location = new ArrayList<EncounterLocationComponent>();
2703      return this.location;
2704    }
2705
2706    public boolean hasLocation() { 
2707      if (this.location == null)
2708        return false;
2709      for (EncounterLocationComponent item : this.location)
2710        if (!item.isEmpty())
2711          return true;
2712      return false;
2713    }
2714
2715    /**
2716     * @return {@link #location} (List of locations where  the patient has been during this encounter.)
2717     */
2718    // syntactic sugar
2719    public EncounterLocationComponent addLocation() { //3
2720      EncounterLocationComponent t = new EncounterLocationComponent();
2721      if (this.location == null)
2722        this.location = new ArrayList<EncounterLocationComponent>();
2723      this.location.add(t);
2724      return t;
2725    }
2726
2727    // syntactic sugar
2728    public Encounter addLocation(EncounterLocationComponent t) { //3
2729      if (t == null)
2730        return this;
2731      if (this.location == null)
2732        this.location = new ArrayList<EncounterLocationComponent>();
2733      this.location.add(t);
2734      return this;
2735    }
2736
2737    /**
2738     * @return {@link #serviceProvider} (An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.)
2739     */
2740    public Reference getServiceProvider() { 
2741      if (this.serviceProvider == null)
2742        if (Configuration.errorOnAutoCreate())
2743          throw new Error("Attempt to auto-create Encounter.serviceProvider");
2744        else if (Configuration.doAutoCreate())
2745          this.serviceProvider = new Reference(); // cc
2746      return this.serviceProvider;
2747    }
2748
2749    public boolean hasServiceProvider() { 
2750      return this.serviceProvider != null && !this.serviceProvider.isEmpty();
2751    }
2752
2753    /**
2754     * @param value {@link #serviceProvider} (An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.)
2755     */
2756    public Encounter setServiceProvider(Reference value) { 
2757      this.serviceProvider = value;
2758      return this;
2759    }
2760
2761    /**
2762     * @return {@link #serviceProvider} 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. (An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.)
2763     */
2764    public Organization getServiceProviderTarget() { 
2765      if (this.serviceProviderTarget == null)
2766        if (Configuration.errorOnAutoCreate())
2767          throw new Error("Attempt to auto-create Encounter.serviceProvider");
2768        else if (Configuration.doAutoCreate())
2769          this.serviceProviderTarget = new Organization(); // aa
2770      return this.serviceProviderTarget;
2771    }
2772
2773    /**
2774     * @param value {@link #serviceProvider} 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. (An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.)
2775     */
2776    public Encounter setServiceProviderTarget(Organization value) { 
2777      this.serviceProviderTarget = value;
2778      return this;
2779    }
2780
2781    /**
2782     * @return {@link #partOf} (Another Encounter of which this encounter is a part of (administratively or in time).)
2783     */
2784    public Reference getPartOf() { 
2785      if (this.partOf == null)
2786        if (Configuration.errorOnAutoCreate())
2787          throw new Error("Attempt to auto-create Encounter.partOf");
2788        else if (Configuration.doAutoCreate())
2789          this.partOf = new Reference(); // cc
2790      return this.partOf;
2791    }
2792
2793    public boolean hasPartOf() { 
2794      return this.partOf != null && !this.partOf.isEmpty();
2795    }
2796
2797    /**
2798     * @param value {@link #partOf} (Another Encounter of which this encounter is a part of (administratively or in time).)
2799     */
2800    public Encounter setPartOf(Reference value) { 
2801      this.partOf = value;
2802      return this;
2803    }
2804
2805    /**
2806     * @return {@link #partOf} 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. (Another Encounter of which this encounter is a part of (administratively or in time).)
2807     */
2808    public Encounter getPartOfTarget() { 
2809      if (this.partOfTarget == null)
2810        if (Configuration.errorOnAutoCreate())
2811          throw new Error("Attempt to auto-create Encounter.partOf");
2812        else if (Configuration.doAutoCreate())
2813          this.partOfTarget = new Encounter(); // aa
2814      return this.partOfTarget;
2815    }
2816
2817    /**
2818     * @param value {@link #partOf} 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. (Another Encounter of which this encounter is a part of (administratively or in time).)
2819     */
2820    public Encounter setPartOfTarget(Encounter value) { 
2821      this.partOfTarget = value;
2822      return this;
2823    }
2824
2825      protected void listChildren(List<Property> childrenList) {
2826        super.listChildren(childrenList);
2827        childrenList.add(new Property("identifier", "Identifier", "Identifier(s) by which this encounter is known.", 0, java.lang.Integer.MAX_VALUE, identifier));
2828        childrenList.add(new Property("status", "code", "planned | arrived | in-progress | onleave | finished | cancelled.", 0, java.lang.Integer.MAX_VALUE, status));
2829        childrenList.add(new Property("statusHistory", "", "The status history permits the encounter resource to contain the status history without needing to read through the historical versions of the resource, or even have the server store them.", 0, java.lang.Integer.MAX_VALUE, statusHistory));
2830        childrenList.add(new Property("class", "code", "inpatient | outpatient | ambulatory | emergency +.", 0, java.lang.Integer.MAX_VALUE, class_));
2831        childrenList.add(new Property("type", "CodeableConcept", "Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation).", 0, java.lang.Integer.MAX_VALUE, type));
2832        childrenList.add(new Property("priority", "CodeableConcept", "Indicates the urgency of the encounter.", 0, java.lang.Integer.MAX_VALUE, priority));
2833        childrenList.add(new Property("patient", "Reference(Patient)", "The patient present at the encounter.", 0, java.lang.Integer.MAX_VALUE, patient));
2834        childrenList.add(new Property("episodeOfCare", "Reference(EpisodeOfCare)", "Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem.  The association is recorded on the encounter as these are typically created after the episode of care, and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).", 0, java.lang.Integer.MAX_VALUE, episodeOfCare));
2835        childrenList.add(new Property("incomingReferral", "Reference(ReferralRequest)", "The referral request this encounter satisfies (incoming referral).", 0, java.lang.Integer.MAX_VALUE, incomingReferral));
2836        childrenList.add(new Property("participant", "", "The list of people responsible for providing the service.", 0, java.lang.Integer.MAX_VALUE, participant));
2837        childrenList.add(new Property("appointment", "Reference(Appointment)", "The appointment that scheduled this encounter.", 0, java.lang.Integer.MAX_VALUE, appointment));
2838        childrenList.add(new Property("period", "Period", "The start and end time of the encounter.", 0, java.lang.Integer.MAX_VALUE, period));
2839        childrenList.add(new Property("length", "Duration", "Quantity of time the encounter lasted. This excludes the time during leaves of absence.", 0, java.lang.Integer.MAX_VALUE, length));
2840        childrenList.add(new Property("reason", "CodeableConcept", "Reason the encounter takes place, expressed as a code. For admissions, this can be used for a coded admission diagnosis.", 0, java.lang.Integer.MAX_VALUE, reason));
2841        childrenList.add(new Property("indication", "Reference(Condition|Procedure)", "Reason the encounter takes place, as specified using information from another resource. For admissions, this is the admission diagnosis. The indication will typically be a Condition (with other resources referenced in the evidence.detail), or a Procedure.", 0, java.lang.Integer.MAX_VALUE, indication));
2842        childrenList.add(new Property("hospitalization", "", "Details about the admission to a healthcare service.", 0, java.lang.Integer.MAX_VALUE, hospitalization));
2843        childrenList.add(new Property("location", "", "List of locations where  the patient has been during this encounter.", 0, java.lang.Integer.MAX_VALUE, location));
2844        childrenList.add(new Property("serviceProvider", "Reference(Organization)", "An organization that is in charge of maintaining the information of this Encounter (e.g. who maintains the report or the master service catalog item, etc.). This MAY be the same as the organization on the Patient record, however it could be different. This MAY not be not the Service Delivery Location's Organization.", 0, java.lang.Integer.MAX_VALUE, serviceProvider));
2845        childrenList.add(new Property("partOf", "Reference(Encounter)", "Another Encounter of which this encounter is a part of (administratively or in time).", 0, java.lang.Integer.MAX_VALUE, partOf));
2846      }
2847
2848      @Override
2849      public void setProperty(String name, Base value) throws FHIRException {
2850        if (name.equals("identifier"))
2851          this.getIdentifier().add(castToIdentifier(value));
2852        else if (name.equals("status"))
2853          this.status = new EncounterStateEnumFactory().fromType(value); // Enumeration<EncounterState>
2854        else if (name.equals("statusHistory"))
2855          this.getStatusHistory().add((EncounterStatusHistoryComponent) value);
2856        else if (name.equals("class"))
2857          this.class_ = new EncounterClassEnumFactory().fromType(value); // Enumeration<EncounterClass>
2858        else if (name.equals("type"))
2859          this.getType().add(castToCodeableConcept(value));
2860        else if (name.equals("priority"))
2861          this.priority = castToCodeableConcept(value); // CodeableConcept
2862        else if (name.equals("patient"))
2863          this.patient = castToReference(value); // Reference
2864        else if (name.equals("episodeOfCare"))
2865          this.getEpisodeOfCare().add(castToReference(value));
2866        else if (name.equals("incomingReferral"))
2867          this.getIncomingReferral().add(castToReference(value));
2868        else if (name.equals("participant"))
2869          this.getParticipant().add((EncounterParticipantComponent) value);
2870        else if (name.equals("appointment"))
2871          this.appointment = castToReference(value); // Reference
2872        else if (name.equals("period"))
2873          this.period = castToPeriod(value); // Period
2874        else if (name.equals("length"))
2875          this.length = castToDuration(value); // Duration
2876        else if (name.equals("reason"))
2877          this.getReason().add(castToCodeableConcept(value));
2878        else if (name.equals("indication"))
2879          this.getIndication().add(castToReference(value));
2880        else if (name.equals("hospitalization"))
2881          this.hospitalization = (EncounterHospitalizationComponent) value; // EncounterHospitalizationComponent
2882        else if (name.equals("location"))
2883          this.getLocation().add((EncounterLocationComponent) value);
2884        else if (name.equals("serviceProvider"))
2885          this.serviceProvider = castToReference(value); // Reference
2886        else if (name.equals("partOf"))
2887          this.partOf = castToReference(value); // Reference
2888        else
2889          super.setProperty(name, value);
2890      }
2891
2892      @Override
2893      public Base addChild(String name) throws FHIRException {
2894        if (name.equals("identifier")) {
2895          return addIdentifier();
2896        }
2897        else if (name.equals("status")) {
2898          throw new FHIRException("Cannot call addChild on a primitive type Encounter.status");
2899        }
2900        else if (name.equals("statusHistory")) {
2901          return addStatusHistory();
2902        }
2903        else if (name.equals("class")) {
2904          throw new FHIRException("Cannot call addChild on a primitive type Encounter.class");
2905        }
2906        else if (name.equals("type")) {
2907          return addType();
2908        }
2909        else if (name.equals("priority")) {
2910          this.priority = new CodeableConcept();
2911          return this.priority;
2912        }
2913        else if (name.equals("patient")) {
2914          this.patient = new Reference();
2915          return this.patient;
2916        }
2917        else if (name.equals("episodeOfCare")) {
2918          return addEpisodeOfCare();
2919        }
2920        else if (name.equals("incomingReferral")) {
2921          return addIncomingReferral();
2922        }
2923        else if (name.equals("participant")) {
2924          return addParticipant();
2925        }
2926        else if (name.equals("appointment")) {
2927          this.appointment = new Reference();
2928          return this.appointment;
2929        }
2930        else if (name.equals("period")) {
2931          this.period = new Period();
2932          return this.period;
2933        }
2934        else if (name.equals("length")) {
2935          this.length = new Duration();
2936          return this.length;
2937        }
2938        else if (name.equals("reason")) {
2939          return addReason();
2940        }
2941        else if (name.equals("indication")) {
2942          return addIndication();
2943        }
2944        else if (name.equals("hospitalization")) {
2945          this.hospitalization = new EncounterHospitalizationComponent();
2946          return this.hospitalization;
2947        }
2948        else if (name.equals("location")) {
2949          return addLocation();
2950        }
2951        else if (name.equals("serviceProvider")) {
2952          this.serviceProvider = new Reference();
2953          return this.serviceProvider;
2954        }
2955        else if (name.equals("partOf")) {
2956          this.partOf = new Reference();
2957          return this.partOf;
2958        }
2959        else
2960          return super.addChild(name);
2961      }
2962
2963  public String fhirType() {
2964    return "Encounter";
2965
2966  }
2967
2968      public Encounter copy() {
2969        Encounter dst = new Encounter();
2970        copyValues(dst);
2971        if (identifier != null) {
2972          dst.identifier = new ArrayList<Identifier>();
2973          for (Identifier i : identifier)
2974            dst.identifier.add(i.copy());
2975        };
2976        dst.status = status == null ? null : status.copy();
2977        if (statusHistory != null) {
2978          dst.statusHistory = new ArrayList<EncounterStatusHistoryComponent>();
2979          for (EncounterStatusHistoryComponent i : statusHistory)
2980            dst.statusHistory.add(i.copy());
2981        };
2982        dst.class_ = class_ == null ? null : class_.copy();
2983        if (type != null) {
2984          dst.type = new ArrayList<CodeableConcept>();
2985          for (CodeableConcept i : type)
2986            dst.type.add(i.copy());
2987        };
2988        dst.priority = priority == null ? null : priority.copy();
2989        dst.patient = patient == null ? null : patient.copy();
2990        if (episodeOfCare != null) {
2991          dst.episodeOfCare = new ArrayList<Reference>();
2992          for (Reference i : episodeOfCare)
2993            dst.episodeOfCare.add(i.copy());
2994        };
2995        if (incomingReferral != null) {
2996          dst.incomingReferral = new ArrayList<Reference>();
2997          for (Reference i : incomingReferral)
2998            dst.incomingReferral.add(i.copy());
2999        };
3000        if (participant != null) {
3001          dst.participant = new ArrayList<EncounterParticipantComponent>();
3002          for (EncounterParticipantComponent i : participant)
3003            dst.participant.add(i.copy());
3004        };
3005        dst.appointment = appointment == null ? null : appointment.copy();
3006        dst.period = period == null ? null : period.copy();
3007        dst.length = length == null ? null : length.copy();
3008        if (reason != null) {
3009          dst.reason = new ArrayList<CodeableConcept>();
3010          for (CodeableConcept i : reason)
3011            dst.reason.add(i.copy());
3012        };
3013        if (indication != null) {
3014          dst.indication = new ArrayList<Reference>();
3015          for (Reference i : indication)
3016            dst.indication.add(i.copy());
3017        };
3018        dst.hospitalization = hospitalization == null ? null : hospitalization.copy();
3019        if (location != null) {
3020          dst.location = new ArrayList<EncounterLocationComponent>();
3021          for (EncounterLocationComponent i : location)
3022            dst.location.add(i.copy());
3023        };
3024        dst.serviceProvider = serviceProvider == null ? null : serviceProvider.copy();
3025        dst.partOf = partOf == null ? null : partOf.copy();
3026        return dst;
3027      }
3028
3029      protected Encounter typedCopy() {
3030        return copy();
3031      }
3032
3033      @Override
3034      public boolean equalsDeep(Base other) {
3035        if (!super.equalsDeep(other))
3036          return false;
3037        if (!(other instanceof Encounter))
3038          return false;
3039        Encounter o = (Encounter) other;
3040        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(statusHistory, o.statusHistory, true)
3041           && compareDeep(class_, o.class_, true) && compareDeep(type, o.type, true) && compareDeep(priority, o.priority, true)
3042           && compareDeep(patient, o.patient, true) && compareDeep(episodeOfCare, o.episodeOfCare, true) && compareDeep(incomingReferral, o.incomingReferral, true)
3043           && compareDeep(participant, o.participant, true) && compareDeep(appointment, o.appointment, true)
3044           && compareDeep(period, o.period, true) && compareDeep(length, o.length, true) && compareDeep(reason, o.reason, true)
3045           && compareDeep(indication, o.indication, true) && compareDeep(hospitalization, o.hospitalization, true)
3046           && compareDeep(location, o.location, true) && compareDeep(serviceProvider, o.serviceProvider, true)
3047           && compareDeep(partOf, o.partOf, true);
3048      }
3049
3050      @Override
3051      public boolean equalsShallow(Base other) {
3052        if (!super.equalsShallow(other))
3053          return false;
3054        if (!(other instanceof Encounter))
3055          return false;
3056        Encounter o = (Encounter) other;
3057        return compareValues(status, o.status, true) && compareValues(class_, o.class_, true);
3058      }
3059
3060      public boolean isEmpty() {
3061        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
3062           && (statusHistory == null || statusHistory.isEmpty()) && (class_ == null || class_.isEmpty())
3063           && (type == null || type.isEmpty()) && (priority == null || priority.isEmpty()) && (patient == null || patient.isEmpty())
3064           && (episodeOfCare == null || episodeOfCare.isEmpty()) && (incomingReferral == null || incomingReferral.isEmpty())
3065           && (participant == null || participant.isEmpty()) && (appointment == null || appointment.isEmpty())
3066           && (period == null || period.isEmpty()) && (length == null || length.isEmpty()) && (reason == null || reason.isEmpty())
3067           && (indication == null || indication.isEmpty()) && (hospitalization == null || hospitalization.isEmpty())
3068           && (location == null || location.isEmpty()) && (serviceProvider == null || serviceProvider.isEmpty())
3069           && (partOf == null || partOf.isEmpty());
3070      }
3071
3072  @Override
3073  public ResourceType getResourceType() {
3074    return ResourceType.Encounter;
3075   }
3076
3077  @SearchParamDefinition(name="date", path="Encounter.period", description="A date within the period the Encounter lasted", type="date" )
3078  public static final String SP_DATE = "date";
3079  @SearchParamDefinition(name="identifier", path="Encounter.identifier", description="Identifier(s) by which this encounter is known", type="token" )
3080  public static final String SP_IDENTIFIER = "identifier";
3081  @SearchParamDefinition(name="reason", path="Encounter.reason", description="Reason the encounter takes place (code)", type="token" )
3082  public static final String SP_REASON = "reason";
3083  @SearchParamDefinition(name="episodeofcare", path="Encounter.episodeOfCare", description="Episode(s) of care that this encounter should be recorded against", type="reference" )
3084  public static final String SP_EPISODEOFCARE = "episodeofcare";
3085  @SearchParamDefinition(name="participant-type", path="Encounter.participant.type", description="Role of participant in encounter", type="token" )
3086  public static final String SP_PARTICIPANTTYPE = "participant-type";
3087  @SearchParamDefinition(name="incomingreferral", path="Encounter.incomingReferral", description="The ReferralRequest that initiated this encounter", type="reference" )
3088  public static final String SP_INCOMINGREFERRAL = "incomingreferral";
3089  @SearchParamDefinition(name="practitioner", path="Encounter.participant.individual", description="Persons involved in the encounter other than the patient", type="reference" )
3090  public static final String SP_PRACTITIONER = "practitioner";
3091  @SearchParamDefinition(name="length", path="Encounter.length", description="Length of encounter in days", type="number" )
3092  public static final String SP_LENGTH = "length";
3093  @SearchParamDefinition(name="appointment", path="Encounter.appointment", description="The appointment that scheduled this encounter", type="reference" )
3094  public static final String SP_APPOINTMENT = "appointment";
3095  @SearchParamDefinition(name="part-of", path="Encounter.partOf", description="Another Encounter this encounter is part of", type="reference" )
3096  public static final String SP_PARTOF = "part-of";
3097  @SearchParamDefinition(name="procedure", path="Encounter.indication", description="Reason the encounter takes place (resource)", type="reference" )
3098  public static final String SP_PROCEDURE = "procedure";
3099  @SearchParamDefinition(name="type", path="Encounter.type", description="Specific type of encounter", type="token" )
3100  public static final String SP_TYPE = "type";
3101  @SearchParamDefinition(name="participant", path="Encounter.participant.individual", description="Persons involved in the encounter other than the patient", type="reference" )
3102  public static final String SP_PARTICIPANT = "participant";
3103  @SearchParamDefinition(name="condition", path="Encounter.indication", description="Reason the encounter takes place (resource)", type="reference" )
3104  public static final String SP_CONDITION = "condition";
3105  @SearchParamDefinition(name="patient", path="Encounter.patient", description="The patient present at the encounter", type="reference" )
3106  public static final String SP_PATIENT = "patient";
3107  @SearchParamDefinition(name="location-period", path="Encounter.location.period", description="Time period during which the patient was present at the location", type="date" )
3108  public static final String SP_LOCATIONPERIOD = "location-period";
3109  @SearchParamDefinition(name="location", path="Encounter.location.location", description="Location the encounter takes place", type="reference" )
3110  public static final String SP_LOCATION = "location";
3111  @SearchParamDefinition(name="indication", path="Encounter.indication", description="Reason the encounter takes place (resource)", type="reference" )
3112  public static final String SP_INDICATION = "indication";
3113  @SearchParamDefinition(name="special-arrangement", path="Encounter.hospitalization.specialArrangement", description="Wheelchair, translator, stretcher, etc.", type="token" )
3114  public static final String SP_SPECIALARRANGEMENT = "special-arrangement";
3115  @SearchParamDefinition(name="status", path="Encounter.status", description="planned | arrived | in-progress | onleave | finished | cancelled", type="token" )
3116  public static final String SP_STATUS = "status";
3117
3118}