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