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