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