001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import org.hl7.fhir.utilities.Utilities;
040import org.hl7.fhir.r4.model.Enumerations.*;
041import ca.uhn.fhir.model.api.annotation.ResourceDef;
042import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.ChildOrder;
045import ca.uhn.fhir.model.api.annotation.Description;
046import ca.uhn.fhir.model.api.annotation.Block;
047import org.hl7.fhir.instance.model.api.*;
048import org.hl7.fhir.exceptions.FHIRException;
049/**
050 * An association between a patient and an organization / healthcare provider(s) during which time encounters may occur. The managing organization assumes a level of responsibility for the patient during this time.
051 */
052@ResourceDef(name="EpisodeOfCare", profile="http://hl7.org/fhir/StructureDefinition/EpisodeOfCare")
053public class EpisodeOfCare extends DomainResource {
054
055    public enum EpisodeOfCareStatus {
056        /**
057         * This episode of care is planned to start at the date specified in the period.start. During this status, an organization may perform assessments to determine if the patient is eligible to receive services, or be organizing to make resources available to provide care services.
058         */
059        PLANNED, 
060        /**
061         * This episode has been placed on a waitlist, pending the episode being made active (or cancelled).
062         */
063        WAITLIST, 
064        /**
065         * This episode of care is current.
066         */
067        ACTIVE, 
068        /**
069         * This episode of care is on hold; the organization has limited responsibility for the patient (such as while on respite).
070         */
071        ONHOLD, 
072        /**
073         * This episode of care is finished and the organization is not expecting to be providing further care to the patient. Can also be known as "closed", "completed" or other similar terms.
074         */
075        FINISHED, 
076        /**
077         * The episode of care was cancelled, or withdrawn from service, often selected during the planned stage as the patient may have gone elsewhere, or the circumstances have changed and the organization is unable to provide the care. It indicates that services terminated outside the planned/expected workflow.
078         */
079        CANCELLED, 
080        /**
081         * This instance should not have been part of this patient's medical record.
082         */
083        ENTEREDINERROR, 
084        /**
085         * added to help the parsers with the generic types
086         */
087        NULL;
088        public static EpisodeOfCareStatus fromCode(String codeString) throws FHIRException {
089            if (codeString == null || "".equals(codeString))
090                return null;
091        if ("planned".equals(codeString))
092          return PLANNED;
093        if ("waitlist".equals(codeString))
094          return WAITLIST;
095        if ("active".equals(codeString))
096          return ACTIVE;
097        if ("onhold".equals(codeString))
098          return ONHOLD;
099        if ("finished".equals(codeString))
100          return FINISHED;
101        if ("cancelled".equals(codeString))
102          return CANCELLED;
103        if ("entered-in-error".equals(codeString))
104          return ENTEREDINERROR;
105        if (Configuration.isAcceptInvalidEnums())
106          return null;
107        else
108          throw new FHIRException("Unknown EpisodeOfCareStatus code '"+codeString+"'");
109        }
110        public String toCode() {
111          switch (this) {
112            case PLANNED: return "planned";
113            case WAITLIST: return "waitlist";
114            case ACTIVE: return "active";
115            case ONHOLD: return "onhold";
116            case FINISHED: return "finished";
117            case CANCELLED: return "cancelled";
118            case ENTEREDINERROR: return "entered-in-error";
119            default: return "?";
120          }
121        }
122        public String getSystem() {
123          switch (this) {
124            case PLANNED: return "http://hl7.org/fhir/episode-of-care-status";
125            case WAITLIST: return "http://hl7.org/fhir/episode-of-care-status";
126            case ACTIVE: return "http://hl7.org/fhir/episode-of-care-status";
127            case ONHOLD: return "http://hl7.org/fhir/episode-of-care-status";
128            case FINISHED: return "http://hl7.org/fhir/episode-of-care-status";
129            case CANCELLED: return "http://hl7.org/fhir/episode-of-care-status";
130            case ENTEREDINERROR: return "http://hl7.org/fhir/episode-of-care-status";
131            default: return "?";
132          }
133        }
134        public String getDefinition() {
135          switch (this) {
136            case PLANNED: return "This episode of care is planned to start at the date specified in the period.start. During this status, an organization may perform assessments to determine if the patient is eligible to receive services, or be organizing to make resources available to provide care services.";
137            case WAITLIST: return "This episode has been placed on a waitlist, pending the episode being made active (or cancelled).";
138            case ACTIVE: return "This episode of care is current.";
139            case ONHOLD: return "This episode of care is on hold; the organization has limited responsibility for the patient (such as while on respite).";
140            case FINISHED: return "This episode of care is finished and the organization is not expecting to be providing further care to the patient. Can also be known as \"closed\", \"completed\" or other similar terms.";
141            case CANCELLED: return "The episode of care was cancelled, or withdrawn from service, often selected during the planned stage as the patient may have gone elsewhere, or the circumstances have changed and the organization is unable to provide the care. It indicates that services terminated outside the planned/expected workflow.";
142            case ENTEREDINERROR: return "This instance should not have been part of this patient's medical record.";
143            default: return "?";
144          }
145        }
146        public String getDisplay() {
147          switch (this) {
148            case PLANNED: return "Planned";
149            case WAITLIST: return "Waitlist";
150            case ACTIVE: return "Active";
151            case ONHOLD: return "On Hold";
152            case FINISHED: return "Finished";
153            case CANCELLED: return "Cancelled";
154            case ENTEREDINERROR: return "Entered in Error";
155            default: return "?";
156          }
157        }
158    }
159
160  public static class EpisodeOfCareStatusEnumFactory implements EnumFactory<EpisodeOfCareStatus> {
161    public EpisodeOfCareStatus fromCode(String codeString) throws IllegalArgumentException {
162      if (codeString == null || "".equals(codeString))
163            if (codeString == null || "".equals(codeString))
164                return null;
165        if ("planned".equals(codeString))
166          return EpisodeOfCareStatus.PLANNED;
167        if ("waitlist".equals(codeString))
168          return EpisodeOfCareStatus.WAITLIST;
169        if ("active".equals(codeString))
170          return EpisodeOfCareStatus.ACTIVE;
171        if ("onhold".equals(codeString))
172          return EpisodeOfCareStatus.ONHOLD;
173        if ("finished".equals(codeString))
174          return EpisodeOfCareStatus.FINISHED;
175        if ("cancelled".equals(codeString))
176          return EpisodeOfCareStatus.CANCELLED;
177        if ("entered-in-error".equals(codeString))
178          return EpisodeOfCareStatus.ENTEREDINERROR;
179        throw new IllegalArgumentException("Unknown EpisodeOfCareStatus code '"+codeString+"'");
180        }
181        public Enumeration<EpisodeOfCareStatus> fromType(Base code) throws FHIRException {
182          if (code == null)
183            return null;
184          if (code.isEmpty())
185            return new Enumeration<EpisodeOfCareStatus>(this);
186          String codeString = ((PrimitiveType) code).asStringValue();
187          if (codeString == null || "".equals(codeString))
188            return null;
189        if ("planned".equals(codeString))
190          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.PLANNED);
191        if ("waitlist".equals(codeString))
192          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.WAITLIST);
193        if ("active".equals(codeString))
194          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.ACTIVE);
195        if ("onhold".equals(codeString))
196          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.ONHOLD);
197        if ("finished".equals(codeString))
198          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.FINISHED);
199        if ("cancelled".equals(codeString))
200          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.CANCELLED);
201        if ("entered-in-error".equals(codeString))
202          return new Enumeration<EpisodeOfCareStatus>(this, EpisodeOfCareStatus.ENTEREDINERROR);
203        throw new FHIRException("Unknown EpisodeOfCareStatus code '"+codeString+"'");
204        }
205    public String toCode(EpisodeOfCareStatus code) {
206      if (code == EpisodeOfCareStatus.PLANNED)
207        return "planned";
208      if (code == EpisodeOfCareStatus.WAITLIST)
209        return "waitlist";
210      if (code == EpisodeOfCareStatus.ACTIVE)
211        return "active";
212      if (code == EpisodeOfCareStatus.ONHOLD)
213        return "onhold";
214      if (code == EpisodeOfCareStatus.FINISHED)
215        return "finished";
216      if (code == EpisodeOfCareStatus.CANCELLED)
217        return "cancelled";
218      if (code == EpisodeOfCareStatus.ENTEREDINERROR)
219        return "entered-in-error";
220      return "?";
221      }
222    public String toSystem(EpisodeOfCareStatus code) {
223      return code.getSystem();
224      }
225    }
226
227    @Block()
228    public static class EpisodeOfCareStatusHistoryComponent extends BackboneElement implements IBaseBackboneElement {
229        /**
230         * planned | waitlist | active | onhold | finished | cancelled.
231         */
232        @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=false, summary=false)
233        @Description(shortDefinition="planned | waitlist | active | onhold | finished | cancelled | entered-in-error", formalDefinition="planned | waitlist | active | onhold | finished | cancelled." )
234        @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/episode-of-care-status")
235        protected Enumeration<EpisodeOfCareStatus> status;
236
237        /**
238         * The period during this EpisodeOfCare that the specific status applied.
239         */
240        @Child(name = "period", type = {Period.class}, order=2, min=1, max=1, modifier=false, summary=false)
241        @Description(shortDefinition="Duration the EpisodeOfCare was in the specified status", formalDefinition="The period during this EpisodeOfCare that the specific status applied." )
242        protected Period period;
243
244        private static final long serialVersionUID = -1192432864L;
245
246    /**
247     * Constructor
248     */
249      public EpisodeOfCareStatusHistoryComponent() {
250        super();
251      }
252
253    /**
254     * Constructor
255     */
256      public EpisodeOfCareStatusHistoryComponent(Enumeration<EpisodeOfCareStatus> status, Period period) {
257        super();
258        this.status = status;
259        this.period = period;
260      }
261
262        /**
263         * @return {@link #status} (planned | waitlist | active | onhold | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
264         */
265        public Enumeration<EpisodeOfCareStatus> getStatusElement() { 
266          if (this.status == null)
267            if (Configuration.errorOnAutoCreate())
268              throw new Error("Attempt to auto-create EpisodeOfCareStatusHistoryComponent.status");
269            else if (Configuration.doAutoCreate())
270              this.status = new Enumeration<EpisodeOfCareStatus>(new EpisodeOfCareStatusEnumFactory()); // bb
271          return this.status;
272        }
273
274        public boolean hasStatusElement() { 
275          return this.status != null && !this.status.isEmpty();
276        }
277
278        public boolean hasStatus() { 
279          return this.status != null && !this.status.isEmpty();
280        }
281
282        /**
283         * @param value {@link #status} (planned | waitlist | active | onhold | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
284         */
285        public EpisodeOfCareStatusHistoryComponent setStatusElement(Enumeration<EpisodeOfCareStatus> value) { 
286          this.status = value;
287          return this;
288        }
289
290        /**
291         * @return planned | waitlist | active | onhold | finished | cancelled.
292         */
293        public EpisodeOfCareStatus getStatus() { 
294          return this.status == null ? null : this.status.getValue();
295        }
296
297        /**
298         * @param value planned | waitlist | active | onhold | finished | cancelled.
299         */
300        public EpisodeOfCareStatusHistoryComponent setStatus(EpisodeOfCareStatus value) { 
301            if (this.status == null)
302              this.status = new Enumeration<EpisodeOfCareStatus>(new EpisodeOfCareStatusEnumFactory());
303            this.status.setValue(value);
304          return this;
305        }
306
307        /**
308         * @return {@link #period} (The period during this EpisodeOfCare that the specific status applied.)
309         */
310        public Period getPeriod() { 
311          if (this.period == null)
312            if (Configuration.errorOnAutoCreate())
313              throw new Error("Attempt to auto-create EpisodeOfCareStatusHistoryComponent.period");
314            else if (Configuration.doAutoCreate())
315              this.period = new Period(); // cc
316          return this.period;
317        }
318
319        public boolean hasPeriod() { 
320          return this.period != null && !this.period.isEmpty();
321        }
322
323        /**
324         * @param value {@link #period} (The period during this EpisodeOfCare that the specific status applied.)
325         */
326        public EpisodeOfCareStatusHistoryComponent setPeriod(Period value) { 
327          this.period = value;
328          return this;
329        }
330
331        protected void listChildren(List<Property> children) {
332          super.listChildren(children);
333          children.add(new Property("status", "code", "planned | waitlist | active | onhold | finished | cancelled.", 0, 1, status));
334          children.add(new Property("period", "Period", "The period during this EpisodeOfCare that the specific status applied.", 0, 1, period));
335        }
336
337        @Override
338        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
339          switch (_hash) {
340          case -892481550: /*status*/  return new Property("status", "code", "planned | waitlist | active | onhold | finished | cancelled.", 0, 1, status);
341          case -991726143: /*period*/  return new Property("period", "Period", "The period during this EpisodeOfCare that the specific status applied.", 0, 1, period);
342          default: return super.getNamedProperty(_hash, _name, _checkValid);
343          }
344
345        }
346
347      @Override
348      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
349        switch (hash) {
350        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<EpisodeOfCareStatus>
351        case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // Period
352        default: return super.getProperty(hash, name, checkValid);
353        }
354
355      }
356
357      @Override
358      public Base setProperty(int hash, String name, Base value) throws FHIRException {
359        switch (hash) {
360        case -892481550: // status
361          value = new EpisodeOfCareStatusEnumFactory().fromType(castToCode(value));
362          this.status = (Enumeration) value; // Enumeration<EpisodeOfCareStatus>
363          return value;
364        case -991726143: // period
365          this.period = castToPeriod(value); // Period
366          return value;
367        default: return super.setProperty(hash, name, value);
368        }
369
370      }
371
372      @Override
373      public Base setProperty(String name, Base value) throws FHIRException {
374        if (name.equals("status")) {
375          value = new EpisodeOfCareStatusEnumFactory().fromType(castToCode(value));
376          this.status = (Enumeration) value; // Enumeration<EpisodeOfCareStatus>
377        } else if (name.equals("period")) {
378          this.period = castToPeriod(value); // Period
379        } else
380          return super.setProperty(name, value);
381        return value;
382      }
383
384      @Override
385      public Base makeProperty(int hash, String name) throws FHIRException {
386        switch (hash) {
387        case -892481550:  return getStatusElement();
388        case -991726143:  return getPeriod(); 
389        default: return super.makeProperty(hash, name);
390        }
391
392      }
393
394      @Override
395      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
396        switch (hash) {
397        case -892481550: /*status*/ return new String[] {"code"};
398        case -991726143: /*period*/ return new String[] {"Period"};
399        default: return super.getTypesForProperty(hash, name);
400        }
401
402      }
403
404      @Override
405      public Base addChild(String name) throws FHIRException {
406        if (name.equals("status")) {
407          throw new FHIRException("Cannot call addChild on a primitive type EpisodeOfCare.status");
408        }
409        else if (name.equals("period")) {
410          this.period = new Period();
411          return this.period;
412        }
413        else
414          return super.addChild(name);
415      }
416
417      public EpisodeOfCareStatusHistoryComponent copy() {
418        EpisodeOfCareStatusHistoryComponent dst = new EpisodeOfCareStatusHistoryComponent();
419        copyValues(dst);
420        return dst;
421      }
422
423      public void copyValues(EpisodeOfCareStatusHistoryComponent dst) {
424        super.copyValues(dst);
425        dst.status = status == null ? null : status.copy();
426        dst.period = period == null ? null : period.copy();
427      }
428
429      @Override
430      public boolean equalsDeep(Base other_) {
431        if (!super.equalsDeep(other_))
432          return false;
433        if (!(other_ instanceof EpisodeOfCareStatusHistoryComponent))
434          return false;
435        EpisodeOfCareStatusHistoryComponent o = (EpisodeOfCareStatusHistoryComponent) other_;
436        return compareDeep(status, o.status, true) && compareDeep(period, o.period, true);
437      }
438
439      @Override
440      public boolean equalsShallow(Base other_) {
441        if (!super.equalsShallow(other_))
442          return false;
443        if (!(other_ instanceof EpisodeOfCareStatusHistoryComponent))
444          return false;
445        EpisodeOfCareStatusHistoryComponent o = (EpisodeOfCareStatusHistoryComponent) other_;
446        return compareValues(status, o.status, true);
447      }
448
449      public boolean isEmpty() {
450        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(status, period);
451      }
452
453  public String fhirType() {
454    return "EpisodeOfCare.statusHistory";
455
456  }
457
458  }
459
460    @Block()
461    public static class DiagnosisComponent extends BackboneElement implements IBaseBackboneElement {
462        /**
463         * A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.
464         */
465        @Child(name = "condition", type = {Condition.class}, order=1, min=1, max=1, modifier=false, summary=true)
466        @Description(shortDefinition="Conditions/problems/diagnoses this episode of care is for", formalDefinition="A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for." )
467        protected Reference condition;
468
469        /**
470         * The actual object that is the target of the reference (A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.)
471         */
472        protected Condition conditionTarget;
473
474        /**
475         * Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …).
476         */
477        @Child(name = "role", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=true)
478        @Description(shortDefinition="Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …)", formalDefinition="Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …)." )
479        @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/diagnosis-role")
480        protected CodeableConcept role;
481
482        /**
483         * Ranking of the diagnosis (for each role type).
484         */
485        @Child(name = "rank", type = {PositiveIntType.class}, order=3, min=0, max=1, modifier=false, summary=true)
486        @Description(shortDefinition="Ranking of the diagnosis (for each role type)", formalDefinition="Ranking of the diagnosis (for each role type)." )
487        protected PositiveIntType rank;
488
489        private static final long serialVersionUID = 249445632L;
490
491    /**
492     * Constructor
493     */
494      public DiagnosisComponent() {
495        super();
496      }
497
498    /**
499     * Constructor
500     */
501      public DiagnosisComponent(Reference condition) {
502        super();
503        this.condition = condition;
504      }
505
506        /**
507         * @return {@link #condition} (A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.)
508         */
509        public Reference getCondition() { 
510          if (this.condition == null)
511            if (Configuration.errorOnAutoCreate())
512              throw new Error("Attempt to auto-create DiagnosisComponent.condition");
513            else if (Configuration.doAutoCreate())
514              this.condition = new Reference(); // cc
515          return this.condition;
516        }
517
518        public boolean hasCondition() { 
519          return this.condition != null && !this.condition.isEmpty();
520        }
521
522        /**
523         * @param value {@link #condition} (A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.)
524         */
525        public DiagnosisComponent setCondition(Reference value) { 
526          this.condition = value;
527          return this;
528        }
529
530        /**
531         * @return {@link #condition} 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. (A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.)
532         */
533        public Condition getConditionTarget() { 
534          if (this.conditionTarget == null)
535            if (Configuration.errorOnAutoCreate())
536              throw new Error("Attempt to auto-create DiagnosisComponent.condition");
537            else if (Configuration.doAutoCreate())
538              this.conditionTarget = new Condition(); // aa
539          return this.conditionTarget;
540        }
541
542        /**
543         * @param value {@link #condition} 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. (A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.)
544         */
545        public DiagnosisComponent setConditionTarget(Condition value) { 
546          this.conditionTarget = value;
547          return this;
548        }
549
550        /**
551         * @return {@link #role} (Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …).)
552         */
553        public CodeableConcept getRole() { 
554          if (this.role == null)
555            if (Configuration.errorOnAutoCreate())
556              throw new Error("Attempt to auto-create DiagnosisComponent.role");
557            else if (Configuration.doAutoCreate())
558              this.role = new CodeableConcept(); // cc
559          return this.role;
560        }
561
562        public boolean hasRole() { 
563          return this.role != null && !this.role.isEmpty();
564        }
565
566        /**
567         * @param value {@link #role} (Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …).)
568         */
569        public DiagnosisComponent setRole(CodeableConcept value) { 
570          this.role = value;
571          return this;
572        }
573
574        /**
575         * @return {@link #rank} (Ranking of the diagnosis (for each role type).). This is the underlying object with id, value and extensions. The accessor "getRank" gives direct access to the value
576         */
577        public PositiveIntType getRankElement() { 
578          if (this.rank == null)
579            if (Configuration.errorOnAutoCreate())
580              throw new Error("Attempt to auto-create DiagnosisComponent.rank");
581            else if (Configuration.doAutoCreate())
582              this.rank = new PositiveIntType(); // bb
583          return this.rank;
584        }
585
586        public boolean hasRankElement() { 
587          return this.rank != null && !this.rank.isEmpty();
588        }
589
590        public boolean hasRank() { 
591          return this.rank != null && !this.rank.isEmpty();
592        }
593
594        /**
595         * @param value {@link #rank} (Ranking of the diagnosis (for each role type).). This is the underlying object with id, value and extensions. The accessor "getRank" gives direct access to the value
596         */
597        public DiagnosisComponent setRankElement(PositiveIntType value) { 
598          this.rank = value;
599          return this;
600        }
601
602        /**
603         * @return Ranking of the diagnosis (for each role type).
604         */
605        public int getRank() { 
606          return this.rank == null || this.rank.isEmpty() ? 0 : this.rank.getValue();
607        }
608
609        /**
610         * @param value Ranking of the diagnosis (for each role type).
611         */
612        public DiagnosisComponent setRank(int value) { 
613            if (this.rank == null)
614              this.rank = new PositiveIntType();
615            this.rank.setValue(value);
616          return this;
617        }
618
619        protected void listChildren(List<Property> children) {
620          super.listChildren(children);
621          children.add(new Property("condition", "Reference(Condition)", "A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.", 0, 1, condition));
622          children.add(new Property("role", "CodeableConcept", "Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …).", 0, 1, role));
623          children.add(new Property("rank", "positiveInt", "Ranking of the diagnosis (for each role type).", 0, 1, rank));
624        }
625
626        @Override
627        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
628          switch (_hash) {
629          case -861311717: /*condition*/  return new Property("condition", "Reference(Condition)", "A list of conditions/problems/diagnoses that this episode of care is intended to be providing care for.", 0, 1, condition);
630          case 3506294: /*role*/  return new Property("role", "CodeableConcept", "Role that this diagnosis has within the episode of care (e.g. admission, billing, discharge …).", 0, 1, role);
631          case 3492908: /*rank*/  return new Property("rank", "positiveInt", "Ranking of the diagnosis (for each role type).", 0, 1, rank);
632          default: return super.getNamedProperty(_hash, _name, _checkValid);
633          }
634
635        }
636
637      @Override
638      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
639        switch (hash) {
640        case -861311717: /*condition*/ return this.condition == null ? new Base[0] : new Base[] {this.condition}; // Reference
641        case 3506294: /*role*/ return this.role == null ? new Base[0] : new Base[] {this.role}; // CodeableConcept
642        case 3492908: /*rank*/ return this.rank == null ? new Base[0] : new Base[] {this.rank}; // PositiveIntType
643        default: return super.getProperty(hash, name, checkValid);
644        }
645
646      }
647
648      @Override
649      public Base setProperty(int hash, String name, Base value) throws FHIRException {
650        switch (hash) {
651        case -861311717: // condition
652          this.condition = castToReference(value); // Reference
653          return value;
654        case 3506294: // role
655          this.role = castToCodeableConcept(value); // CodeableConcept
656          return value;
657        case 3492908: // rank
658          this.rank = castToPositiveInt(value); // PositiveIntType
659          return value;
660        default: return super.setProperty(hash, name, value);
661        }
662
663      }
664
665      @Override
666      public Base setProperty(String name, Base value) throws FHIRException {
667        if (name.equals("condition")) {
668          this.condition = castToReference(value); // Reference
669        } else if (name.equals("role")) {
670          this.role = castToCodeableConcept(value); // CodeableConcept
671        } else if (name.equals("rank")) {
672          this.rank = castToPositiveInt(value); // PositiveIntType
673        } else
674          return super.setProperty(name, value);
675        return value;
676      }
677
678      @Override
679      public Base makeProperty(int hash, String name) throws FHIRException {
680        switch (hash) {
681        case -861311717:  return getCondition(); 
682        case 3506294:  return getRole(); 
683        case 3492908:  return getRankElement();
684        default: return super.makeProperty(hash, name);
685        }
686
687      }
688
689      @Override
690      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
691        switch (hash) {
692        case -861311717: /*condition*/ return new String[] {"Reference"};
693        case 3506294: /*role*/ return new String[] {"CodeableConcept"};
694        case 3492908: /*rank*/ return new String[] {"positiveInt"};
695        default: return super.getTypesForProperty(hash, name);
696        }
697
698      }
699
700      @Override
701      public Base addChild(String name) throws FHIRException {
702        if (name.equals("condition")) {
703          this.condition = new Reference();
704          return this.condition;
705        }
706        else if (name.equals("role")) {
707          this.role = new CodeableConcept();
708          return this.role;
709        }
710        else if (name.equals("rank")) {
711          throw new FHIRException("Cannot call addChild on a primitive type EpisodeOfCare.rank");
712        }
713        else
714          return super.addChild(name);
715      }
716
717      public DiagnosisComponent copy() {
718        DiagnosisComponent dst = new DiagnosisComponent();
719        copyValues(dst);
720        return dst;
721      }
722
723      public void copyValues(DiagnosisComponent dst) {
724        super.copyValues(dst);
725        dst.condition = condition == null ? null : condition.copy();
726        dst.role = role == null ? null : role.copy();
727        dst.rank = rank == null ? null : rank.copy();
728      }
729
730      @Override
731      public boolean equalsDeep(Base other_) {
732        if (!super.equalsDeep(other_))
733          return false;
734        if (!(other_ instanceof DiagnosisComponent))
735          return false;
736        DiagnosisComponent o = (DiagnosisComponent) other_;
737        return compareDeep(condition, o.condition, true) && compareDeep(role, o.role, true) && compareDeep(rank, o.rank, true)
738          ;
739      }
740
741      @Override
742      public boolean equalsShallow(Base other_) {
743        if (!super.equalsShallow(other_))
744          return false;
745        if (!(other_ instanceof DiagnosisComponent))
746          return false;
747        DiagnosisComponent o = (DiagnosisComponent) other_;
748        return compareValues(rank, o.rank, true);
749      }
750
751      public boolean isEmpty() {
752        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(condition, role, rank);
753      }
754
755  public String fhirType() {
756    return "EpisodeOfCare.diagnosis";
757
758  }
759
760  }
761
762    /**
763     * The EpisodeOfCare may be known by different identifiers for different contexts of use, such as when an external agency is tracking the Episode for funding purposes.
764     */
765    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
766    @Description(shortDefinition="Business Identifier(s) relevant for this EpisodeOfCare", formalDefinition="The EpisodeOfCare may be known by different identifiers for different contexts of use, such as when an external agency is tracking the Episode for funding purposes." )
767    protected List<Identifier> identifier;
768
769    /**
770     * planned | waitlist | active | onhold | finished | cancelled.
771     */
772    @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=true, summary=true)
773    @Description(shortDefinition="planned | waitlist | active | onhold | finished | cancelled | entered-in-error", formalDefinition="planned | waitlist | active | onhold | finished | cancelled." )
774    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/episode-of-care-status")
775    protected Enumeration<EpisodeOfCareStatus> status;
776
777    /**
778     * The history of statuses that the EpisodeOfCare has been through (without requiring processing the history of the resource).
779     */
780    @Child(name = "statusHistory", type = {}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
781    @Description(shortDefinition="Past list of status codes (the current status may be included to cover the start date of the status)", formalDefinition="The history of statuses that the EpisodeOfCare has been through (without requiring processing the history of the resource)." )
782    protected List<EpisodeOfCareStatusHistoryComponent> statusHistory;
783
784    /**
785     * A classification of the type of episode of care; e.g. specialist referral, disease management, type of funded care.
786     */
787    @Child(name = "type", type = {CodeableConcept.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
788    @Description(shortDefinition="Type/class  - e.g. specialist referral, disease management", formalDefinition="A classification of the type of episode of care; e.g. specialist referral, disease management, type of funded care." )
789    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/episodeofcare-type")
790    protected List<CodeableConcept> type;
791
792    /**
793     * The list of diagnosis relevant to this episode of care.
794     */
795    @Child(name = "diagnosis", type = {}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
796    @Description(shortDefinition="The list of diagnosis relevant to this episode of care", formalDefinition="The list of diagnosis relevant to this episode of care." )
797    protected List<DiagnosisComponent> diagnosis;
798
799    /**
800     * The patient who is the focus of this episode of care.
801     */
802    @Child(name = "patient", type = {Patient.class}, order=5, min=1, max=1, modifier=false, summary=true)
803    @Description(shortDefinition="The patient who is the focus of this episode of care", formalDefinition="The patient who is the focus of this episode of care." )
804    protected Reference patient;
805
806    /**
807     * The actual object that is the target of the reference (The patient who is the focus of this episode of care.)
808     */
809    protected Patient patientTarget;
810
811    /**
812     * The organization that has assumed the specific responsibilities for the specified duration.
813     */
814    @Child(name = "managingOrganization", type = {Organization.class}, order=6, min=0, max=1, modifier=false, summary=true)
815    @Description(shortDefinition="Organization that assumes care", formalDefinition="The organization that has assumed the specific responsibilities for the specified duration." )
816    protected Reference managingOrganization;
817
818    /**
819     * The actual object that is the target of the reference (The organization that has assumed the specific responsibilities for the specified duration.)
820     */
821    protected Organization managingOrganizationTarget;
822
823    /**
824     * The interval during which the managing organization assumes the defined responsibility.
825     */
826    @Child(name = "period", type = {Period.class}, order=7, min=0, max=1, modifier=false, summary=true)
827    @Description(shortDefinition="Interval during responsibility is assumed", formalDefinition="The interval during which the managing organization assumes the defined responsibility." )
828    protected Period period;
829
830    /**
831     * Referral Request(s) that are fulfilled by this EpisodeOfCare, incoming referrals.
832     */
833    @Child(name = "referralRequest", type = {ServiceRequest.class}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
834    @Description(shortDefinition="Originating Referral Request(s)", formalDefinition="Referral Request(s) that are fulfilled by this EpisodeOfCare, incoming referrals." )
835    protected List<Reference> referralRequest;
836    /**
837     * The actual objects that are the target of the reference (Referral Request(s) that are fulfilled by this EpisodeOfCare, incoming referrals.)
838     */
839    protected List<ServiceRequest> referralRequestTarget;
840
841
842    /**
843     * The practitioner that is the care manager/care coordinator for this patient.
844     */
845    @Child(name = "careManager", type = {Practitioner.class, PractitionerRole.class}, order=9, min=0, max=1, modifier=false, summary=false)
846    @Description(shortDefinition="Care manager/care coordinator for the patient", formalDefinition="The practitioner that is the care manager/care coordinator for this patient." )
847    protected Reference careManager;
848
849    /**
850     * The actual object that is the target of the reference (The practitioner that is the care manager/care coordinator for this patient.)
851     */
852    protected Resource careManagerTarget;
853
854    /**
855     * The list of practitioners that may be facilitating this episode of care for specific purposes.
856     */
857    @Child(name = "team", type = {CareTeam.class}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
858    @Description(shortDefinition="Other practitioners facilitating this episode of care", formalDefinition="The list of practitioners that may be facilitating this episode of care for specific purposes." )
859    protected List<Reference> team;
860    /**
861     * The actual objects that are the target of the reference (The list of practitioners that may be facilitating this episode of care for specific purposes.)
862     */
863    protected List<CareTeam> teamTarget;
864
865
866    /**
867     * The set of accounts that may be used for billing for this EpisodeOfCare.
868     */
869    @Child(name = "account", type = {Account.class}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
870    @Description(shortDefinition="The set of accounts that may be used for billing for this EpisodeOfCare", formalDefinition="The set of accounts that may be used for billing for this EpisodeOfCare." )
871    protected List<Reference> account;
872    /**
873     * The actual objects that are the target of the reference (The set of accounts that may be used for billing for this EpisodeOfCare.)
874     */
875    protected List<Account> accountTarget;
876
877
878    private static final long serialVersionUID = 548033949L;
879
880  /**
881   * Constructor
882   */
883    public EpisodeOfCare() {
884      super();
885    }
886
887  /**
888   * Constructor
889   */
890    public EpisodeOfCare(Enumeration<EpisodeOfCareStatus> status, Reference patient) {
891      super();
892      this.status = status;
893      this.patient = patient;
894    }
895
896    /**
897     * @return {@link #identifier} (The EpisodeOfCare may be known by different identifiers for different contexts of use, such as when an external agency is tracking the Episode for funding purposes.)
898     */
899    public List<Identifier> getIdentifier() { 
900      if (this.identifier == null)
901        this.identifier = new ArrayList<Identifier>();
902      return this.identifier;
903    }
904
905    /**
906     * @return Returns a reference to <code>this</code> for easy method chaining
907     */
908    public EpisodeOfCare setIdentifier(List<Identifier> theIdentifier) { 
909      this.identifier = theIdentifier;
910      return this;
911    }
912
913    public boolean hasIdentifier() { 
914      if (this.identifier == null)
915        return false;
916      for (Identifier item : this.identifier)
917        if (!item.isEmpty())
918          return true;
919      return false;
920    }
921
922    public Identifier addIdentifier() { //3
923      Identifier t = new Identifier();
924      if (this.identifier == null)
925        this.identifier = new ArrayList<Identifier>();
926      this.identifier.add(t);
927      return t;
928    }
929
930    public EpisodeOfCare addIdentifier(Identifier t) { //3
931      if (t == null)
932        return this;
933      if (this.identifier == null)
934        this.identifier = new ArrayList<Identifier>();
935      this.identifier.add(t);
936      return this;
937    }
938
939    /**
940     * @return The first repetition of repeating field {@link #identifier}, creating it if it does not already exist
941     */
942    public Identifier getIdentifierFirstRep() { 
943      if (getIdentifier().isEmpty()) {
944        addIdentifier();
945      }
946      return getIdentifier().get(0);
947    }
948
949    /**
950     * @return {@link #status} (planned | waitlist | active | onhold | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
951     */
952    public Enumeration<EpisodeOfCareStatus> getStatusElement() { 
953      if (this.status == null)
954        if (Configuration.errorOnAutoCreate())
955          throw new Error("Attempt to auto-create EpisodeOfCare.status");
956        else if (Configuration.doAutoCreate())
957          this.status = new Enumeration<EpisodeOfCareStatus>(new EpisodeOfCareStatusEnumFactory()); // bb
958      return this.status;
959    }
960
961    public boolean hasStatusElement() { 
962      return this.status != null && !this.status.isEmpty();
963    }
964
965    public boolean hasStatus() { 
966      return this.status != null && !this.status.isEmpty();
967    }
968
969    /**
970     * @param value {@link #status} (planned | waitlist | active | onhold | finished | cancelled.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
971     */
972    public EpisodeOfCare setStatusElement(Enumeration<EpisodeOfCareStatus> value) { 
973      this.status = value;
974      return this;
975    }
976
977    /**
978     * @return planned | waitlist | active | onhold | finished | cancelled.
979     */
980    public EpisodeOfCareStatus getStatus() { 
981      return this.status == null ? null : this.status.getValue();
982    }
983
984    /**
985     * @param value planned | waitlist | active | onhold | finished | cancelled.
986     */
987    public EpisodeOfCare setStatus(EpisodeOfCareStatus value) { 
988        if (this.status == null)
989          this.status = new Enumeration<EpisodeOfCareStatus>(new EpisodeOfCareStatusEnumFactory());
990        this.status.setValue(value);
991      return this;
992    }
993
994    /**
995     * @return {@link #statusHistory} (The history of statuses that the EpisodeOfCare has been through (without requiring processing the history of the resource).)
996     */
997    public List<EpisodeOfCareStatusHistoryComponent> getStatusHistory() { 
998      if (this.statusHistory == null)
999        this.statusHistory = new ArrayList<EpisodeOfCareStatusHistoryComponent>();
1000      return this.statusHistory;
1001    }
1002
1003    /**
1004     * @return Returns a reference to <code>this</code> for easy method chaining
1005     */
1006    public EpisodeOfCare setStatusHistory(List<EpisodeOfCareStatusHistoryComponent> theStatusHistory) { 
1007      this.statusHistory = theStatusHistory;
1008      return this;
1009    }
1010
1011    public boolean hasStatusHistory() { 
1012      if (this.statusHistory == null)
1013        return false;
1014      for (EpisodeOfCareStatusHistoryComponent item : this.statusHistory)
1015        if (!item.isEmpty())
1016          return true;
1017      return false;
1018    }
1019
1020    public EpisodeOfCareStatusHistoryComponent addStatusHistory() { //3
1021      EpisodeOfCareStatusHistoryComponent t = new EpisodeOfCareStatusHistoryComponent();
1022      if (this.statusHistory == null)
1023        this.statusHistory = new ArrayList<EpisodeOfCareStatusHistoryComponent>();
1024      this.statusHistory.add(t);
1025      return t;
1026    }
1027
1028    public EpisodeOfCare addStatusHistory(EpisodeOfCareStatusHistoryComponent t) { //3
1029      if (t == null)
1030        return this;
1031      if (this.statusHistory == null)
1032        this.statusHistory = new ArrayList<EpisodeOfCareStatusHistoryComponent>();
1033      this.statusHistory.add(t);
1034      return this;
1035    }
1036
1037    /**
1038     * @return The first repetition of repeating field {@link #statusHistory}, creating it if it does not already exist
1039     */
1040    public EpisodeOfCareStatusHistoryComponent getStatusHistoryFirstRep() { 
1041      if (getStatusHistory().isEmpty()) {
1042        addStatusHistory();
1043      }
1044      return getStatusHistory().get(0);
1045    }
1046
1047    /**
1048     * @return {@link #type} (A classification of the type of episode of care; e.g. specialist referral, disease management, type of funded care.)
1049     */
1050    public List<CodeableConcept> getType() { 
1051      if (this.type == null)
1052        this.type = new ArrayList<CodeableConcept>();
1053      return this.type;
1054    }
1055
1056    /**
1057     * @return Returns a reference to <code>this</code> for easy method chaining
1058     */
1059    public EpisodeOfCare setType(List<CodeableConcept> theType) { 
1060      this.type = theType;
1061      return this;
1062    }
1063
1064    public boolean hasType() { 
1065      if (this.type == null)
1066        return false;
1067      for (CodeableConcept item : this.type)
1068        if (!item.isEmpty())
1069          return true;
1070      return false;
1071    }
1072
1073    public CodeableConcept addType() { //3
1074      CodeableConcept t = new CodeableConcept();
1075      if (this.type == null)
1076        this.type = new ArrayList<CodeableConcept>();
1077      this.type.add(t);
1078      return t;
1079    }
1080
1081    public EpisodeOfCare addType(CodeableConcept t) { //3
1082      if (t == null)
1083        return this;
1084      if (this.type == null)
1085        this.type = new ArrayList<CodeableConcept>();
1086      this.type.add(t);
1087      return this;
1088    }
1089
1090    /**
1091     * @return The first repetition of repeating field {@link #type}, creating it if it does not already exist
1092     */
1093    public CodeableConcept getTypeFirstRep() { 
1094      if (getType().isEmpty()) {
1095        addType();
1096      }
1097      return getType().get(0);
1098    }
1099
1100    /**
1101     * @return {@link #diagnosis} (The list of diagnosis relevant to this episode of care.)
1102     */
1103    public List<DiagnosisComponent> getDiagnosis() { 
1104      if (this.diagnosis == null)
1105        this.diagnosis = new ArrayList<DiagnosisComponent>();
1106      return this.diagnosis;
1107    }
1108
1109    /**
1110     * @return Returns a reference to <code>this</code> for easy method chaining
1111     */
1112    public EpisodeOfCare setDiagnosis(List<DiagnosisComponent> theDiagnosis) { 
1113      this.diagnosis = theDiagnosis;
1114      return this;
1115    }
1116
1117    public boolean hasDiagnosis() { 
1118      if (this.diagnosis == null)
1119        return false;
1120      for (DiagnosisComponent item : this.diagnosis)
1121        if (!item.isEmpty())
1122          return true;
1123      return false;
1124    }
1125
1126    public DiagnosisComponent addDiagnosis() { //3
1127      DiagnosisComponent t = new DiagnosisComponent();
1128      if (this.diagnosis == null)
1129        this.diagnosis = new ArrayList<DiagnosisComponent>();
1130      this.diagnosis.add(t);
1131      return t;
1132    }
1133
1134    public EpisodeOfCare addDiagnosis(DiagnosisComponent t) { //3
1135      if (t == null)
1136        return this;
1137      if (this.diagnosis == null)
1138        this.diagnosis = new ArrayList<DiagnosisComponent>();
1139      this.diagnosis.add(t);
1140      return this;
1141    }
1142
1143    /**
1144     * @return The first repetition of repeating field {@link #diagnosis}, creating it if it does not already exist
1145     */
1146    public DiagnosisComponent getDiagnosisFirstRep() { 
1147      if (getDiagnosis().isEmpty()) {
1148        addDiagnosis();
1149      }
1150      return getDiagnosis().get(0);
1151    }
1152
1153    /**
1154     * @return {@link #patient} (The patient who is the focus of this episode of care.)
1155     */
1156    public Reference getPatient() { 
1157      if (this.patient == null)
1158        if (Configuration.errorOnAutoCreate())
1159          throw new Error("Attempt to auto-create EpisodeOfCare.patient");
1160        else if (Configuration.doAutoCreate())
1161          this.patient = new Reference(); // cc
1162      return this.patient;
1163    }
1164
1165    public boolean hasPatient() { 
1166      return this.patient != null && !this.patient.isEmpty();
1167    }
1168
1169    /**
1170     * @param value {@link #patient} (The patient who is the focus of this episode of care.)
1171     */
1172    public EpisodeOfCare setPatient(Reference value) { 
1173      this.patient = value;
1174      return this;
1175    }
1176
1177    /**
1178     * @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 who is the focus of this episode of care.)
1179     */
1180    public Patient getPatientTarget() { 
1181      if (this.patientTarget == null)
1182        if (Configuration.errorOnAutoCreate())
1183          throw new Error("Attempt to auto-create EpisodeOfCare.patient");
1184        else if (Configuration.doAutoCreate())
1185          this.patientTarget = new Patient(); // aa
1186      return this.patientTarget;
1187    }
1188
1189    /**
1190     * @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 who is the focus of this episode of care.)
1191     */
1192    public EpisodeOfCare setPatientTarget(Patient value) { 
1193      this.patientTarget = value;
1194      return this;
1195    }
1196
1197    /**
1198     * @return {@link #managingOrganization} (The organization that has assumed the specific responsibilities for the specified duration.)
1199     */
1200    public Reference getManagingOrganization() { 
1201      if (this.managingOrganization == null)
1202        if (Configuration.errorOnAutoCreate())
1203          throw new Error("Attempt to auto-create EpisodeOfCare.managingOrganization");
1204        else if (Configuration.doAutoCreate())
1205          this.managingOrganization = new Reference(); // cc
1206      return this.managingOrganization;
1207    }
1208
1209    public boolean hasManagingOrganization() { 
1210      return this.managingOrganization != null && !this.managingOrganization.isEmpty();
1211    }
1212
1213    /**
1214     * @param value {@link #managingOrganization} (The organization that has assumed the specific responsibilities for the specified duration.)
1215     */
1216    public EpisodeOfCare setManagingOrganization(Reference value) { 
1217      this.managingOrganization = value;
1218      return this;
1219    }
1220
1221    /**
1222     * @return {@link #managingOrganization} 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 organization that has assumed the specific responsibilities for the specified duration.)
1223     */
1224    public Organization getManagingOrganizationTarget() { 
1225      if (this.managingOrganizationTarget == null)
1226        if (Configuration.errorOnAutoCreate())
1227          throw new Error("Attempt to auto-create EpisodeOfCare.managingOrganization");
1228        else if (Configuration.doAutoCreate())
1229          this.managingOrganizationTarget = new Organization(); // aa
1230      return this.managingOrganizationTarget;
1231    }
1232
1233    /**
1234     * @param value {@link #managingOrganization} 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 organization that has assumed the specific responsibilities for the specified duration.)
1235     */
1236    public EpisodeOfCare setManagingOrganizationTarget(Organization value) { 
1237      this.managingOrganizationTarget = value;
1238      return this;
1239    }
1240
1241    /**
1242     * @return {@link #period} (The interval during which the managing organization assumes the defined responsibility.)
1243     */
1244    public Period getPeriod() { 
1245      if (this.period == null)
1246        if (Configuration.errorOnAutoCreate())
1247          throw new Error("Attempt to auto-create EpisodeOfCare.period");
1248        else if (Configuration.doAutoCreate())
1249          this.period = new Period(); // cc
1250      return this.period;
1251    }
1252
1253    public boolean hasPeriod() { 
1254      return this.period != null && !this.period.isEmpty();
1255    }
1256
1257    /**
1258     * @param value {@link #period} (The interval during which the managing organization assumes the defined responsibility.)
1259     */
1260    public EpisodeOfCare setPeriod(Period value) { 
1261      this.period = value;
1262      return this;
1263    }
1264
1265    /**
1266     * @return {@link #referralRequest} (Referral Request(s) that are fulfilled by this EpisodeOfCare, incoming referrals.)
1267     */
1268    public List<Reference> getReferralRequest() { 
1269      if (this.referralRequest == null)
1270        this.referralRequest = new ArrayList<Reference>();
1271      return this.referralRequest;
1272    }
1273
1274    /**
1275     * @return Returns a reference to <code>this</code> for easy method chaining
1276     */
1277    public EpisodeOfCare setReferralRequest(List<Reference> theReferralRequest) { 
1278      this.referralRequest = theReferralRequest;
1279      return this;
1280    }
1281
1282    public boolean hasReferralRequest() { 
1283      if (this.referralRequest == null)
1284        return false;
1285      for (Reference item : this.referralRequest)
1286        if (!item.isEmpty())
1287          return true;
1288      return false;
1289    }
1290
1291    public Reference addReferralRequest() { //3
1292      Reference t = new Reference();
1293      if (this.referralRequest == null)
1294        this.referralRequest = new ArrayList<Reference>();
1295      this.referralRequest.add(t);
1296      return t;
1297    }
1298
1299    public EpisodeOfCare addReferralRequest(Reference t) { //3
1300      if (t == null)
1301        return this;
1302      if (this.referralRequest == null)
1303        this.referralRequest = new ArrayList<Reference>();
1304      this.referralRequest.add(t);
1305      return this;
1306    }
1307
1308    /**
1309     * @return The first repetition of repeating field {@link #referralRequest}, creating it if it does not already exist
1310     */
1311    public Reference getReferralRequestFirstRep() { 
1312      if (getReferralRequest().isEmpty()) {
1313        addReferralRequest();
1314      }
1315      return getReferralRequest().get(0);
1316    }
1317
1318    /**
1319     * @deprecated Use Reference#setResource(IBaseResource) instead
1320     */
1321    @Deprecated
1322    public List<ServiceRequest> getReferralRequestTarget() { 
1323      if (this.referralRequestTarget == null)
1324        this.referralRequestTarget = new ArrayList<ServiceRequest>();
1325      return this.referralRequestTarget;
1326    }
1327
1328    /**
1329     * @deprecated Use Reference#setResource(IBaseResource) instead
1330     */
1331    @Deprecated
1332    public ServiceRequest addReferralRequestTarget() { 
1333      ServiceRequest r = new ServiceRequest();
1334      if (this.referralRequestTarget == null)
1335        this.referralRequestTarget = new ArrayList<ServiceRequest>();
1336      this.referralRequestTarget.add(r);
1337      return r;
1338    }
1339
1340    /**
1341     * @return {@link #careManager} (The practitioner that is the care manager/care coordinator for this patient.)
1342     */
1343    public Reference getCareManager() { 
1344      if (this.careManager == null)
1345        if (Configuration.errorOnAutoCreate())
1346          throw new Error("Attempt to auto-create EpisodeOfCare.careManager");
1347        else if (Configuration.doAutoCreate())
1348          this.careManager = new Reference(); // cc
1349      return this.careManager;
1350    }
1351
1352    public boolean hasCareManager() { 
1353      return this.careManager != null && !this.careManager.isEmpty();
1354    }
1355
1356    /**
1357     * @param value {@link #careManager} (The practitioner that is the care manager/care coordinator for this patient.)
1358     */
1359    public EpisodeOfCare setCareManager(Reference value) { 
1360      this.careManager = value;
1361      return this;
1362    }
1363
1364    /**
1365     * @return {@link #careManager} 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 practitioner that is the care manager/care coordinator for this patient.)
1366     */
1367    public Resource getCareManagerTarget() { 
1368      return this.careManagerTarget;
1369    }
1370
1371    /**
1372     * @param value {@link #careManager} 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 practitioner that is the care manager/care coordinator for this patient.)
1373     */
1374    public EpisodeOfCare setCareManagerTarget(Resource value) { 
1375      this.careManagerTarget = value;
1376      return this;
1377    }
1378
1379    /**
1380     * @return {@link #team} (The list of practitioners that may be facilitating this episode of care for specific purposes.)
1381     */
1382    public List<Reference> getTeam() { 
1383      if (this.team == null)
1384        this.team = new ArrayList<Reference>();
1385      return this.team;
1386    }
1387
1388    /**
1389     * @return Returns a reference to <code>this</code> for easy method chaining
1390     */
1391    public EpisodeOfCare setTeam(List<Reference> theTeam) { 
1392      this.team = theTeam;
1393      return this;
1394    }
1395
1396    public boolean hasTeam() { 
1397      if (this.team == null)
1398        return false;
1399      for (Reference item : this.team)
1400        if (!item.isEmpty())
1401          return true;
1402      return false;
1403    }
1404
1405    public Reference addTeam() { //3
1406      Reference t = new Reference();
1407      if (this.team == null)
1408        this.team = new ArrayList<Reference>();
1409      this.team.add(t);
1410      return t;
1411    }
1412
1413    public EpisodeOfCare addTeam(Reference t) { //3
1414      if (t == null)
1415        return this;
1416      if (this.team == null)
1417        this.team = new ArrayList<Reference>();
1418      this.team.add(t);
1419      return this;
1420    }
1421
1422    /**
1423     * @return The first repetition of repeating field {@link #team}, creating it if it does not already exist
1424     */
1425    public Reference getTeamFirstRep() { 
1426      if (getTeam().isEmpty()) {
1427        addTeam();
1428      }
1429      return getTeam().get(0);
1430    }
1431
1432    /**
1433     * @deprecated Use Reference#setResource(IBaseResource) instead
1434     */
1435    @Deprecated
1436    public List<CareTeam> getTeamTarget() { 
1437      if (this.teamTarget == null)
1438        this.teamTarget = new ArrayList<CareTeam>();
1439      return this.teamTarget;
1440    }
1441
1442    /**
1443     * @deprecated Use Reference#setResource(IBaseResource) instead
1444     */
1445    @Deprecated
1446    public CareTeam addTeamTarget() { 
1447      CareTeam r = new CareTeam();
1448      if (this.teamTarget == null)
1449        this.teamTarget = new ArrayList<CareTeam>();
1450      this.teamTarget.add(r);
1451      return r;
1452    }
1453
1454    /**
1455     * @return {@link #account} (The set of accounts that may be used for billing for this EpisodeOfCare.)
1456     */
1457    public List<Reference> getAccount() { 
1458      if (this.account == null)
1459        this.account = new ArrayList<Reference>();
1460      return this.account;
1461    }
1462
1463    /**
1464     * @return Returns a reference to <code>this</code> for easy method chaining
1465     */
1466    public EpisodeOfCare setAccount(List<Reference> theAccount) { 
1467      this.account = theAccount;
1468      return this;
1469    }
1470
1471    public boolean hasAccount() { 
1472      if (this.account == null)
1473        return false;
1474      for (Reference item : this.account)
1475        if (!item.isEmpty())
1476          return true;
1477      return false;
1478    }
1479
1480    public Reference addAccount() { //3
1481      Reference t = new Reference();
1482      if (this.account == null)
1483        this.account = new ArrayList<Reference>();
1484      this.account.add(t);
1485      return t;
1486    }
1487
1488    public EpisodeOfCare addAccount(Reference t) { //3
1489      if (t == null)
1490        return this;
1491      if (this.account == null)
1492        this.account = new ArrayList<Reference>();
1493      this.account.add(t);
1494      return this;
1495    }
1496
1497    /**
1498     * @return The first repetition of repeating field {@link #account}, creating it if it does not already exist
1499     */
1500    public Reference getAccountFirstRep() { 
1501      if (getAccount().isEmpty()) {
1502        addAccount();
1503      }
1504      return getAccount().get(0);
1505    }
1506
1507    /**
1508     * @deprecated Use Reference#setResource(IBaseResource) instead
1509     */
1510    @Deprecated
1511    public List<Account> getAccountTarget() { 
1512      if (this.accountTarget == null)
1513        this.accountTarget = new ArrayList<Account>();
1514      return this.accountTarget;
1515    }
1516
1517    /**
1518     * @deprecated Use Reference#setResource(IBaseResource) instead
1519     */
1520    @Deprecated
1521    public Account addAccountTarget() { 
1522      Account r = new Account();
1523      if (this.accountTarget == null)
1524        this.accountTarget = new ArrayList<Account>();
1525      this.accountTarget.add(r);
1526      return r;
1527    }
1528
1529      protected void listChildren(List<Property> children) {
1530        super.listChildren(children);
1531        children.add(new Property("identifier", "Identifier", "The EpisodeOfCare may be known by different identifiers for different contexts of use, such as when an external agency is tracking the Episode for funding purposes.", 0, java.lang.Integer.MAX_VALUE, identifier));
1532        children.add(new Property("status", "code", "planned | waitlist | active | onhold | finished | cancelled.", 0, 1, status));
1533        children.add(new Property("statusHistory", "", "The history of statuses that the EpisodeOfCare has been through (without requiring processing the history of the resource).", 0, java.lang.Integer.MAX_VALUE, statusHistory));
1534        children.add(new Property("type", "CodeableConcept", "A classification of the type of episode of care; e.g. specialist referral, disease management, type of funded care.", 0, java.lang.Integer.MAX_VALUE, type));
1535        children.add(new Property("diagnosis", "", "The list of diagnosis relevant to this episode of care.", 0, java.lang.Integer.MAX_VALUE, diagnosis));
1536        children.add(new Property("patient", "Reference(Patient)", "The patient who is the focus of this episode of care.", 0, 1, patient));
1537        children.add(new Property("managingOrganization", "Reference(Organization)", "The organization that has assumed the specific responsibilities for the specified duration.", 0, 1, managingOrganization));
1538        children.add(new Property("period", "Period", "The interval during which the managing organization assumes the defined responsibility.", 0, 1, period));
1539        children.add(new Property("referralRequest", "Reference(ServiceRequest)", "Referral Request(s) that are fulfilled by this EpisodeOfCare, incoming referrals.", 0, java.lang.Integer.MAX_VALUE, referralRequest));
1540        children.add(new Property("careManager", "Reference(Practitioner|PractitionerRole)", "The practitioner that is the care manager/care coordinator for this patient.", 0, 1, careManager));
1541        children.add(new Property("team", "Reference(CareTeam)", "The list of practitioners that may be facilitating this episode of care for specific purposes.", 0, java.lang.Integer.MAX_VALUE, team));
1542        children.add(new Property("account", "Reference(Account)", "The set of accounts that may be used for billing for this EpisodeOfCare.", 0, java.lang.Integer.MAX_VALUE, account));
1543      }
1544
1545      @Override
1546      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1547        switch (_hash) {
1548        case -1618432855: /*identifier*/  return new Property("identifier", "Identifier", "The EpisodeOfCare may be known by different identifiers for different contexts of use, such as when an external agency is tracking the Episode for funding purposes.", 0, java.lang.Integer.MAX_VALUE, identifier);
1549        case -892481550: /*status*/  return new Property("status", "code", "planned | waitlist | active | onhold | finished | cancelled.", 0, 1, status);
1550        case -986695614: /*statusHistory*/  return new Property("statusHistory", "", "The history of statuses that the EpisodeOfCare has been through (without requiring processing the history of the resource).", 0, java.lang.Integer.MAX_VALUE, statusHistory);
1551        case 3575610: /*type*/  return new Property("type", "CodeableConcept", "A classification of the type of episode of care; e.g. specialist referral, disease management, type of funded care.", 0, java.lang.Integer.MAX_VALUE, type);
1552        case 1196993265: /*diagnosis*/  return new Property("diagnosis", "", "The list of diagnosis relevant to this episode of care.", 0, java.lang.Integer.MAX_VALUE, diagnosis);
1553        case -791418107: /*patient*/  return new Property("patient", "Reference(Patient)", "The patient who is the focus of this episode of care.", 0, 1, patient);
1554        case -2058947787: /*managingOrganization*/  return new Property("managingOrganization", "Reference(Organization)", "The organization that has assumed the specific responsibilities for the specified duration.", 0, 1, managingOrganization);
1555        case -991726143: /*period*/  return new Property("period", "Period", "The interval during which the managing organization assumes the defined responsibility.", 0, 1, period);
1556        case -310299598: /*referralRequest*/  return new Property("referralRequest", "Reference(ServiceRequest)", "Referral Request(s) that are fulfilled by this EpisodeOfCare, incoming referrals.", 0, java.lang.Integer.MAX_VALUE, referralRequest);
1557        case -1147746468: /*careManager*/  return new Property("careManager", "Reference(Practitioner|PractitionerRole)", "The practitioner that is the care manager/care coordinator for this patient.", 0, 1, careManager);
1558        case 3555933: /*team*/  return new Property("team", "Reference(CareTeam)", "The list of practitioners that may be facilitating this episode of care for specific purposes.", 0, java.lang.Integer.MAX_VALUE, team);
1559        case -1177318867: /*account*/  return new Property("account", "Reference(Account)", "The set of accounts that may be used for billing for this EpisodeOfCare.", 0, java.lang.Integer.MAX_VALUE, account);
1560        default: return super.getNamedProperty(_hash, _name, _checkValid);
1561        }
1562
1563      }
1564
1565      @Override
1566      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1567        switch (hash) {
1568        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
1569        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<EpisodeOfCareStatus>
1570        case -986695614: /*statusHistory*/ return this.statusHistory == null ? new Base[0] : this.statusHistory.toArray(new Base[this.statusHistory.size()]); // EpisodeOfCareStatusHistoryComponent
1571        case 3575610: /*type*/ return this.type == null ? new Base[0] : this.type.toArray(new Base[this.type.size()]); // CodeableConcept
1572        case 1196993265: /*diagnosis*/ return this.diagnosis == null ? new Base[0] : this.diagnosis.toArray(new Base[this.diagnosis.size()]); // DiagnosisComponent
1573        case -791418107: /*patient*/ return this.patient == null ? new Base[0] : new Base[] {this.patient}; // Reference
1574        case -2058947787: /*managingOrganization*/ return this.managingOrganization == null ? new Base[0] : new Base[] {this.managingOrganization}; // Reference
1575        case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // Period
1576        case -310299598: /*referralRequest*/ return this.referralRequest == null ? new Base[0] : this.referralRequest.toArray(new Base[this.referralRequest.size()]); // Reference
1577        case -1147746468: /*careManager*/ return this.careManager == null ? new Base[0] : new Base[] {this.careManager}; // Reference
1578        case 3555933: /*team*/ return this.team == null ? new Base[0] : this.team.toArray(new Base[this.team.size()]); // Reference
1579        case -1177318867: /*account*/ return this.account == null ? new Base[0] : this.account.toArray(new Base[this.account.size()]); // Reference
1580        default: return super.getProperty(hash, name, checkValid);
1581        }
1582
1583      }
1584
1585      @Override
1586      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1587        switch (hash) {
1588        case -1618432855: // identifier
1589          this.getIdentifier().add(castToIdentifier(value)); // Identifier
1590          return value;
1591        case -892481550: // status
1592          value = new EpisodeOfCareStatusEnumFactory().fromType(castToCode(value));
1593          this.status = (Enumeration) value; // Enumeration<EpisodeOfCareStatus>
1594          return value;
1595        case -986695614: // statusHistory
1596          this.getStatusHistory().add((EpisodeOfCareStatusHistoryComponent) value); // EpisodeOfCareStatusHistoryComponent
1597          return value;
1598        case 3575610: // type
1599          this.getType().add(castToCodeableConcept(value)); // CodeableConcept
1600          return value;
1601        case 1196993265: // diagnosis
1602          this.getDiagnosis().add((DiagnosisComponent) value); // DiagnosisComponent
1603          return value;
1604        case -791418107: // patient
1605          this.patient = castToReference(value); // Reference
1606          return value;
1607        case -2058947787: // managingOrganization
1608          this.managingOrganization = castToReference(value); // Reference
1609          return value;
1610        case -991726143: // period
1611          this.period = castToPeriod(value); // Period
1612          return value;
1613        case -310299598: // referralRequest
1614          this.getReferralRequest().add(castToReference(value)); // Reference
1615          return value;
1616        case -1147746468: // careManager
1617          this.careManager = castToReference(value); // Reference
1618          return value;
1619        case 3555933: // team
1620          this.getTeam().add(castToReference(value)); // Reference
1621          return value;
1622        case -1177318867: // account
1623          this.getAccount().add(castToReference(value)); // Reference
1624          return value;
1625        default: return super.setProperty(hash, name, value);
1626        }
1627
1628      }
1629
1630      @Override
1631      public Base setProperty(String name, Base value) throws FHIRException {
1632        if (name.equals("identifier")) {
1633          this.getIdentifier().add(castToIdentifier(value));
1634        } else if (name.equals("status")) {
1635          value = new EpisodeOfCareStatusEnumFactory().fromType(castToCode(value));
1636          this.status = (Enumeration) value; // Enumeration<EpisodeOfCareStatus>
1637        } else if (name.equals("statusHistory")) {
1638          this.getStatusHistory().add((EpisodeOfCareStatusHistoryComponent) value);
1639        } else if (name.equals("type")) {
1640          this.getType().add(castToCodeableConcept(value));
1641        } else if (name.equals("diagnosis")) {
1642          this.getDiagnosis().add((DiagnosisComponent) value);
1643        } else if (name.equals("patient")) {
1644          this.patient = castToReference(value); // Reference
1645        } else if (name.equals("managingOrganization")) {
1646          this.managingOrganization = castToReference(value); // Reference
1647        } else if (name.equals("period")) {
1648          this.period = castToPeriod(value); // Period
1649        } else if (name.equals("referralRequest")) {
1650          this.getReferralRequest().add(castToReference(value));
1651        } else if (name.equals("careManager")) {
1652          this.careManager = castToReference(value); // Reference
1653        } else if (name.equals("team")) {
1654          this.getTeam().add(castToReference(value));
1655        } else if (name.equals("account")) {
1656          this.getAccount().add(castToReference(value));
1657        } else
1658          return super.setProperty(name, value);
1659        return value;
1660      }
1661
1662      @Override
1663      public Base makeProperty(int hash, String name) throws FHIRException {
1664        switch (hash) {
1665        case -1618432855:  return addIdentifier(); 
1666        case -892481550:  return getStatusElement();
1667        case -986695614:  return addStatusHistory(); 
1668        case 3575610:  return addType(); 
1669        case 1196993265:  return addDiagnosis(); 
1670        case -791418107:  return getPatient(); 
1671        case -2058947787:  return getManagingOrganization(); 
1672        case -991726143:  return getPeriod(); 
1673        case -310299598:  return addReferralRequest(); 
1674        case -1147746468:  return getCareManager(); 
1675        case 3555933:  return addTeam(); 
1676        case -1177318867:  return addAccount(); 
1677        default: return super.makeProperty(hash, name);
1678        }
1679
1680      }
1681
1682      @Override
1683      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1684        switch (hash) {
1685        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
1686        case -892481550: /*status*/ return new String[] {"code"};
1687        case -986695614: /*statusHistory*/ return new String[] {};
1688        case 3575610: /*type*/ return new String[] {"CodeableConcept"};
1689        case 1196993265: /*diagnosis*/ return new String[] {};
1690        case -791418107: /*patient*/ return new String[] {"Reference"};
1691        case -2058947787: /*managingOrganization*/ return new String[] {"Reference"};
1692        case -991726143: /*period*/ return new String[] {"Period"};
1693        case -310299598: /*referralRequest*/ return new String[] {"Reference"};
1694        case -1147746468: /*careManager*/ return new String[] {"Reference"};
1695        case 3555933: /*team*/ return new String[] {"Reference"};
1696        case -1177318867: /*account*/ return new String[] {"Reference"};
1697        default: return super.getTypesForProperty(hash, name);
1698        }
1699
1700      }
1701
1702      @Override
1703      public Base addChild(String name) throws FHIRException {
1704        if (name.equals("identifier")) {
1705          return addIdentifier();
1706        }
1707        else if (name.equals("status")) {
1708          throw new FHIRException("Cannot call addChild on a primitive type EpisodeOfCare.status");
1709        }
1710        else if (name.equals("statusHistory")) {
1711          return addStatusHistory();
1712        }
1713        else if (name.equals("type")) {
1714          return addType();
1715        }
1716        else if (name.equals("diagnosis")) {
1717          return addDiagnosis();
1718        }
1719        else if (name.equals("patient")) {
1720          this.patient = new Reference();
1721          return this.patient;
1722        }
1723        else if (name.equals("managingOrganization")) {
1724          this.managingOrganization = new Reference();
1725          return this.managingOrganization;
1726        }
1727        else if (name.equals("period")) {
1728          this.period = new Period();
1729          return this.period;
1730        }
1731        else if (name.equals("referralRequest")) {
1732          return addReferralRequest();
1733        }
1734        else if (name.equals("careManager")) {
1735          this.careManager = new Reference();
1736          return this.careManager;
1737        }
1738        else if (name.equals("team")) {
1739          return addTeam();
1740        }
1741        else if (name.equals("account")) {
1742          return addAccount();
1743        }
1744        else
1745          return super.addChild(name);
1746      }
1747
1748  public String fhirType() {
1749    return "EpisodeOfCare";
1750
1751  }
1752
1753      public EpisodeOfCare copy() {
1754        EpisodeOfCare dst = new EpisodeOfCare();
1755        copyValues(dst);
1756        return dst;
1757      }
1758
1759      public void copyValues(EpisodeOfCare dst) {
1760        super.copyValues(dst);
1761        if (identifier != null) {
1762          dst.identifier = new ArrayList<Identifier>();
1763          for (Identifier i : identifier)
1764            dst.identifier.add(i.copy());
1765        };
1766        dst.status = status == null ? null : status.copy();
1767        if (statusHistory != null) {
1768          dst.statusHistory = new ArrayList<EpisodeOfCareStatusHistoryComponent>();
1769          for (EpisodeOfCareStatusHistoryComponent i : statusHistory)
1770            dst.statusHistory.add(i.copy());
1771        };
1772        if (type != null) {
1773          dst.type = new ArrayList<CodeableConcept>();
1774          for (CodeableConcept i : type)
1775            dst.type.add(i.copy());
1776        };
1777        if (diagnosis != null) {
1778          dst.diagnosis = new ArrayList<DiagnosisComponent>();
1779          for (DiagnosisComponent i : diagnosis)
1780            dst.diagnosis.add(i.copy());
1781        };
1782        dst.patient = patient == null ? null : patient.copy();
1783        dst.managingOrganization = managingOrganization == null ? null : managingOrganization.copy();
1784        dst.period = period == null ? null : period.copy();
1785        if (referralRequest != null) {
1786          dst.referralRequest = new ArrayList<Reference>();
1787          for (Reference i : referralRequest)
1788            dst.referralRequest.add(i.copy());
1789        };
1790        dst.careManager = careManager == null ? null : careManager.copy();
1791        if (team != null) {
1792          dst.team = new ArrayList<Reference>();
1793          for (Reference i : team)
1794            dst.team.add(i.copy());
1795        };
1796        if (account != null) {
1797          dst.account = new ArrayList<Reference>();
1798          for (Reference i : account)
1799            dst.account.add(i.copy());
1800        };
1801      }
1802
1803      protected EpisodeOfCare typedCopy() {
1804        return copy();
1805      }
1806
1807      @Override
1808      public boolean equalsDeep(Base other_) {
1809        if (!super.equalsDeep(other_))
1810          return false;
1811        if (!(other_ instanceof EpisodeOfCare))
1812          return false;
1813        EpisodeOfCare o = (EpisodeOfCare) other_;
1814        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(statusHistory, o.statusHistory, true)
1815           && compareDeep(type, o.type, true) && compareDeep(diagnosis, o.diagnosis, true) && compareDeep(patient, o.patient, true)
1816           && compareDeep(managingOrganization, o.managingOrganization, true) && compareDeep(period, o.period, true)
1817           && compareDeep(referralRequest, o.referralRequest, true) && compareDeep(careManager, o.careManager, true)
1818           && compareDeep(team, o.team, true) && compareDeep(account, o.account, true);
1819      }
1820
1821      @Override
1822      public boolean equalsShallow(Base other_) {
1823        if (!super.equalsShallow(other_))
1824          return false;
1825        if (!(other_ instanceof EpisodeOfCare))
1826          return false;
1827        EpisodeOfCare o = (EpisodeOfCare) other_;
1828        return compareValues(status, o.status, true);
1829      }
1830
1831      public boolean isEmpty() {
1832        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, status, statusHistory
1833          , type, diagnosis, patient, managingOrganization, period, referralRequest, careManager
1834          , team, account);
1835      }
1836
1837  @Override
1838  public ResourceType getResourceType() {
1839    return ResourceType.EpisodeOfCare;
1840   }
1841
1842 /**
1843   * Search parameter: <b>date</b>
1844   * <p>
1845   * Description: <b>The provided date search value falls within the episode of care's period</b><br>
1846   * Type: <b>date</b><br>
1847   * Path: <b>EpisodeOfCare.period</b><br>
1848   * </p>
1849   */
1850  @SearchParamDefinition(name="date", path="EpisodeOfCare.period", description="The provided date search value falls within the episode of care's period", type="date" )
1851  public static final String SP_DATE = "date";
1852 /**
1853   * <b>Fluent Client</b> search parameter constant for <b>date</b>
1854   * <p>
1855   * Description: <b>The provided date search value falls within the episode of care's period</b><br>
1856   * Type: <b>date</b><br>
1857   * Path: <b>EpisodeOfCare.period</b><br>
1858   * </p>
1859   */
1860  public static final ca.uhn.fhir.rest.gclient.DateClientParam DATE = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_DATE);
1861
1862 /**
1863   * Search parameter: <b>identifier</b>
1864   * <p>
1865   * Description: <b>Business Identifier(s) relevant for this EpisodeOfCare</b><br>
1866   * Type: <b>token</b><br>
1867   * Path: <b>EpisodeOfCare.identifier</b><br>
1868   * </p>
1869   */
1870  @SearchParamDefinition(name="identifier", path="EpisodeOfCare.identifier", description="Business Identifier(s) relevant for this EpisodeOfCare", type="token" )
1871  public static final String SP_IDENTIFIER = "identifier";
1872 /**
1873   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1874   * <p>
1875   * Description: <b>Business Identifier(s) relevant for this EpisodeOfCare</b><br>
1876   * Type: <b>token</b><br>
1877   * Path: <b>EpisodeOfCare.identifier</b><br>
1878   * </p>
1879   */
1880  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
1881
1882 /**
1883   * Search parameter: <b>condition</b>
1884   * <p>
1885   * Description: <b>Conditions/problems/diagnoses this episode of care is for</b><br>
1886   * Type: <b>reference</b><br>
1887   * Path: <b>EpisodeOfCare.diagnosis.condition</b><br>
1888   * </p>
1889   */
1890  @SearchParamDefinition(name="condition", path="EpisodeOfCare.diagnosis.condition", description="Conditions/problems/diagnoses this episode of care is for", type="reference", target={Condition.class } )
1891  public static final String SP_CONDITION = "condition";
1892 /**
1893   * <b>Fluent Client</b> search parameter constant for <b>condition</b>
1894   * <p>
1895   * Description: <b>Conditions/problems/diagnoses this episode of care is for</b><br>
1896   * Type: <b>reference</b><br>
1897   * Path: <b>EpisodeOfCare.diagnosis.condition</b><br>
1898   * </p>
1899   */
1900  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CONDITION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_CONDITION);
1901
1902/**
1903   * Constant for fluent queries to be used to add include statements. Specifies
1904   * the path value of "<b>EpisodeOfCare:condition</b>".
1905   */
1906  public static final ca.uhn.fhir.model.api.Include INCLUDE_CONDITION = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:condition").toLocked();
1907
1908 /**
1909   * Search parameter: <b>patient</b>
1910   * <p>
1911   * Description: <b>The patient who is the focus of this episode of care</b><br>
1912   * Type: <b>reference</b><br>
1913   * Path: <b>EpisodeOfCare.patient</b><br>
1914   * </p>
1915   */
1916  @SearchParamDefinition(name="patient", path="EpisodeOfCare.patient", description="The patient who is the focus of this episode of care", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Patient") }, target={Patient.class } )
1917  public static final String SP_PATIENT = "patient";
1918 /**
1919   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
1920   * <p>
1921   * Description: <b>The patient who is the focus of this episode of care</b><br>
1922   * Type: <b>reference</b><br>
1923   * Path: <b>EpisodeOfCare.patient</b><br>
1924   * </p>
1925   */
1926  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
1927
1928/**
1929   * Constant for fluent queries to be used to add include statements. Specifies
1930   * the path value of "<b>EpisodeOfCare:patient</b>".
1931   */
1932  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:patient").toLocked();
1933
1934 /**
1935   * Search parameter: <b>organization</b>
1936   * <p>
1937   * Description: <b>The organization that has assumed the specific responsibilities of this EpisodeOfCare</b><br>
1938   * Type: <b>reference</b><br>
1939   * Path: <b>EpisodeOfCare.managingOrganization</b><br>
1940   * </p>
1941   */
1942  @SearchParamDefinition(name="organization", path="EpisodeOfCare.managingOrganization", description="The organization that has assumed the specific responsibilities of this EpisodeOfCare", type="reference", target={Organization.class } )
1943  public static final String SP_ORGANIZATION = "organization";
1944 /**
1945   * <b>Fluent Client</b> search parameter constant for <b>organization</b>
1946   * <p>
1947   * Description: <b>The organization that has assumed the specific responsibilities of this EpisodeOfCare</b><br>
1948   * Type: <b>reference</b><br>
1949   * Path: <b>EpisodeOfCare.managingOrganization</b><br>
1950   * </p>
1951   */
1952  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam ORGANIZATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_ORGANIZATION);
1953
1954/**
1955   * Constant for fluent queries to be used to add include statements. Specifies
1956   * the path value of "<b>EpisodeOfCare:organization</b>".
1957   */
1958  public static final ca.uhn.fhir.model.api.Include INCLUDE_ORGANIZATION = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:organization").toLocked();
1959
1960 /**
1961   * Search parameter: <b>type</b>
1962   * <p>
1963   * Description: <b>Type/class  - e.g. specialist referral, disease management</b><br>
1964   * Type: <b>token</b><br>
1965   * Path: <b>EpisodeOfCare.type</b><br>
1966   * </p>
1967   */
1968  @SearchParamDefinition(name="type", path="EpisodeOfCare.type", description="Type/class  - e.g. specialist referral, disease management", type="token" )
1969  public static final String SP_TYPE = "type";
1970 /**
1971   * <b>Fluent Client</b> search parameter constant for <b>type</b>
1972   * <p>
1973   * Description: <b>Type/class  - e.g. specialist referral, disease management</b><br>
1974   * Type: <b>token</b><br>
1975   * Path: <b>EpisodeOfCare.type</b><br>
1976   * </p>
1977   */
1978  public static final ca.uhn.fhir.rest.gclient.TokenClientParam TYPE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_TYPE);
1979
1980 /**
1981   * Search parameter: <b>care-manager</b>
1982   * <p>
1983   * Description: <b>Care manager/care coordinator for the patient</b><br>
1984   * Type: <b>reference</b><br>
1985   * Path: <b>EpisodeOfCare.careManager</b><br>
1986   * </p>
1987   */
1988  @SearchParamDefinition(name="care-manager", path="EpisodeOfCare.careManager.where(resolve() is Practitioner)", description="Care manager/care coordinator for the patient", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Practitioner") }, target={Practitioner.class } )
1989  public static final String SP_CARE_MANAGER = "care-manager";
1990 /**
1991   * <b>Fluent Client</b> search parameter constant for <b>care-manager</b>
1992   * <p>
1993   * Description: <b>Care manager/care coordinator for the patient</b><br>
1994   * Type: <b>reference</b><br>
1995   * Path: <b>EpisodeOfCare.careManager</b><br>
1996   * </p>
1997   */
1998  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CARE_MANAGER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_CARE_MANAGER);
1999
2000/**
2001   * Constant for fluent queries to be used to add include statements. Specifies
2002   * the path value of "<b>EpisodeOfCare:care-manager</b>".
2003   */
2004  public static final ca.uhn.fhir.model.api.Include INCLUDE_CARE_MANAGER = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:care-manager").toLocked();
2005
2006 /**
2007   * Search parameter: <b>status</b>
2008   * <p>
2009   * Description: <b>The current status of the Episode of Care as provided (does not check the status history collection)</b><br>
2010   * Type: <b>token</b><br>
2011   * Path: <b>EpisodeOfCare.status</b><br>
2012   * </p>
2013   */
2014  @SearchParamDefinition(name="status", path="EpisodeOfCare.status", description="The current status of the Episode of Care as provided (does not check the status history collection)", type="token" )
2015  public static final String SP_STATUS = "status";
2016 /**
2017   * <b>Fluent Client</b> search parameter constant for <b>status</b>
2018   * <p>
2019   * Description: <b>The current status of the Episode of Care as provided (does not check the status history collection)</b><br>
2020   * Type: <b>token</b><br>
2021   * Path: <b>EpisodeOfCare.status</b><br>
2022   * </p>
2023   */
2024  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_STATUS);
2025
2026 /**
2027   * Search parameter: <b>incoming-referral</b>
2028   * <p>
2029   * Description: <b>Incoming Referral Request</b><br>
2030   * Type: <b>reference</b><br>
2031   * Path: <b>EpisodeOfCare.referralRequest</b><br>
2032   * </p>
2033   */
2034  @SearchParamDefinition(name="incoming-referral", path="EpisodeOfCare.referralRequest", description="Incoming Referral Request", type="reference", target={ServiceRequest.class } )
2035  public static final String SP_INCOMING_REFERRAL = "incoming-referral";
2036 /**
2037   * <b>Fluent Client</b> search parameter constant for <b>incoming-referral</b>
2038   * <p>
2039   * Description: <b>Incoming Referral Request</b><br>
2040   * Type: <b>reference</b><br>
2041   * Path: <b>EpisodeOfCare.referralRequest</b><br>
2042   * </p>
2043   */
2044  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam INCOMING_REFERRAL = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_INCOMING_REFERRAL);
2045
2046/**
2047   * Constant for fluent queries to be used to add include statements. Specifies
2048   * the path value of "<b>EpisodeOfCare:incoming-referral</b>".
2049   */
2050  public static final ca.uhn.fhir.model.api.Include INCLUDE_INCOMING_REFERRAL = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:incoming-referral").toLocked();
2051
2052
2053}