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 Sun, May 6, 2018 17:51-0400 for FHIR v3.4.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/Profile/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}, 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 Practitioner 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 = -1606202327L;
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 Practitioner getCareManagerTarget() { 
1357      if (this.careManagerTarget == null)
1358        if (Configuration.errorOnAutoCreate())
1359          throw new Error("Attempt to auto-create EpisodeOfCare.careManager");
1360        else if (Configuration.doAutoCreate())
1361          this.careManagerTarget = new Practitioner(); // aa
1362      return this.careManagerTarget;
1363    }
1364
1365    /**
1366     * @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.)
1367     */
1368    public EpisodeOfCare setCareManagerTarget(Practitioner value) { 
1369      this.careManagerTarget = value;
1370      return this;
1371    }
1372
1373    /**
1374     * @return {@link #team} (The list of practitioners that may be facilitating this episode of care for specific purposes.)
1375     */
1376    public List<Reference> getTeam() { 
1377      if (this.team == null)
1378        this.team = new ArrayList<Reference>();
1379      return this.team;
1380    }
1381
1382    /**
1383     * @return Returns a reference to <code>this</code> for easy method chaining
1384     */
1385    public EpisodeOfCare setTeam(List<Reference> theTeam) { 
1386      this.team = theTeam;
1387      return this;
1388    }
1389
1390    public boolean hasTeam() { 
1391      if (this.team == null)
1392        return false;
1393      for (Reference item : this.team)
1394        if (!item.isEmpty())
1395          return true;
1396      return false;
1397    }
1398
1399    public Reference addTeam() { //3
1400      Reference t = new Reference();
1401      if (this.team == null)
1402        this.team = new ArrayList<Reference>();
1403      this.team.add(t);
1404      return t;
1405    }
1406
1407    public EpisodeOfCare addTeam(Reference t) { //3
1408      if (t == null)
1409        return this;
1410      if (this.team == null)
1411        this.team = new ArrayList<Reference>();
1412      this.team.add(t);
1413      return this;
1414    }
1415
1416    /**
1417     * @return The first repetition of repeating field {@link #team}, creating it if it does not already exist
1418     */
1419    public Reference getTeamFirstRep() { 
1420      if (getTeam().isEmpty()) {
1421        addTeam();
1422      }
1423      return getTeam().get(0);
1424    }
1425
1426    /**
1427     * @deprecated Use Reference#setResource(IBaseResource) instead
1428     */
1429    @Deprecated
1430    public List<CareTeam> getTeamTarget() { 
1431      if (this.teamTarget == null)
1432        this.teamTarget = new ArrayList<CareTeam>();
1433      return this.teamTarget;
1434    }
1435
1436    /**
1437     * @deprecated Use Reference#setResource(IBaseResource) instead
1438     */
1439    @Deprecated
1440    public CareTeam addTeamTarget() { 
1441      CareTeam r = new CareTeam();
1442      if (this.teamTarget == null)
1443        this.teamTarget = new ArrayList<CareTeam>();
1444      this.teamTarget.add(r);
1445      return r;
1446    }
1447
1448    /**
1449     * @return {@link #account} (The set of accounts that may be used for billing for this EpisodeOfCare.)
1450     */
1451    public List<Reference> getAccount() { 
1452      if (this.account == null)
1453        this.account = new ArrayList<Reference>();
1454      return this.account;
1455    }
1456
1457    /**
1458     * @return Returns a reference to <code>this</code> for easy method chaining
1459     */
1460    public EpisodeOfCare setAccount(List<Reference> theAccount) { 
1461      this.account = theAccount;
1462      return this;
1463    }
1464
1465    public boolean hasAccount() { 
1466      if (this.account == null)
1467        return false;
1468      for (Reference item : this.account)
1469        if (!item.isEmpty())
1470          return true;
1471      return false;
1472    }
1473
1474    public Reference addAccount() { //3
1475      Reference t = new Reference();
1476      if (this.account == null)
1477        this.account = new ArrayList<Reference>();
1478      this.account.add(t);
1479      return t;
1480    }
1481
1482    public EpisodeOfCare addAccount(Reference t) { //3
1483      if (t == null)
1484        return this;
1485      if (this.account == null)
1486        this.account = new ArrayList<Reference>();
1487      this.account.add(t);
1488      return this;
1489    }
1490
1491    /**
1492     * @return The first repetition of repeating field {@link #account}, creating it if it does not already exist
1493     */
1494    public Reference getAccountFirstRep() { 
1495      if (getAccount().isEmpty()) {
1496        addAccount();
1497      }
1498      return getAccount().get(0);
1499    }
1500
1501    /**
1502     * @deprecated Use Reference#setResource(IBaseResource) instead
1503     */
1504    @Deprecated
1505    public List<Account> getAccountTarget() { 
1506      if (this.accountTarget == null)
1507        this.accountTarget = new ArrayList<Account>();
1508      return this.accountTarget;
1509    }
1510
1511    /**
1512     * @deprecated Use Reference#setResource(IBaseResource) instead
1513     */
1514    @Deprecated
1515    public Account addAccountTarget() { 
1516      Account r = new Account();
1517      if (this.accountTarget == null)
1518        this.accountTarget = new ArrayList<Account>();
1519      this.accountTarget.add(r);
1520      return r;
1521    }
1522
1523      protected void listChildren(List<Property> children) {
1524        super.listChildren(children);
1525        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));
1526        children.add(new Property("status", "code", "planned | waitlist | active | onhold | finished | cancelled.", 0, 1, status));
1527        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));
1528        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));
1529        children.add(new Property("diagnosis", "", "The list of diagnosis relevant to this episode of care.", 0, java.lang.Integer.MAX_VALUE, diagnosis));
1530        children.add(new Property("patient", "Reference(Patient)", "The patient who is the focus of this episode of care.", 0, 1, patient));
1531        children.add(new Property("managingOrganization", "Reference(Organization)", "The organization that has assumed the specific responsibilities for the specified duration.", 0, 1, managingOrganization));
1532        children.add(new Property("period", "Period", "The interval during which the managing organization assumes the defined responsibility.", 0, 1, period));
1533        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));
1534        children.add(new Property("careManager", "Reference(Practitioner)", "The practitioner that is the care manager/care coordinator for this patient.", 0, 1, careManager));
1535        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));
1536        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));
1537      }
1538
1539      @Override
1540      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1541        switch (_hash) {
1542        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);
1543        case -892481550: /*status*/  return new Property("status", "code", "planned | waitlist | active | onhold | finished | cancelled.", 0, 1, status);
1544        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);
1545        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);
1546        case 1196993265: /*diagnosis*/  return new Property("diagnosis", "", "The list of diagnosis relevant to this episode of care.", 0, java.lang.Integer.MAX_VALUE, diagnosis);
1547        case -791418107: /*patient*/  return new Property("patient", "Reference(Patient)", "The patient who is the focus of this episode of care.", 0, 1, patient);
1548        case -2058947787: /*managingOrganization*/  return new Property("managingOrganization", "Reference(Organization)", "The organization that has assumed the specific responsibilities for the specified duration.", 0, 1, managingOrganization);
1549        case -991726143: /*period*/  return new Property("period", "Period", "The interval during which the managing organization assumes the defined responsibility.", 0, 1, period);
1550        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);
1551        case -1147746468: /*careManager*/  return new Property("careManager", "Reference(Practitioner)", "The practitioner that is the care manager/care coordinator for this patient.", 0, 1, careManager);
1552        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);
1553        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);
1554        default: return super.getNamedProperty(_hash, _name, _checkValid);
1555        }
1556
1557      }
1558
1559      @Override
1560      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1561        switch (hash) {
1562        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
1563        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<EpisodeOfCareStatus>
1564        case -986695614: /*statusHistory*/ return this.statusHistory == null ? new Base[0] : this.statusHistory.toArray(new Base[this.statusHistory.size()]); // EpisodeOfCareStatusHistoryComponent
1565        case 3575610: /*type*/ return this.type == null ? new Base[0] : this.type.toArray(new Base[this.type.size()]); // CodeableConcept
1566        case 1196993265: /*diagnosis*/ return this.diagnosis == null ? new Base[0] : this.diagnosis.toArray(new Base[this.diagnosis.size()]); // DiagnosisComponent
1567        case -791418107: /*patient*/ return this.patient == null ? new Base[0] : new Base[] {this.patient}; // Reference
1568        case -2058947787: /*managingOrganization*/ return this.managingOrganization == null ? new Base[0] : new Base[] {this.managingOrganization}; // Reference
1569        case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // Period
1570        case -310299598: /*referralRequest*/ return this.referralRequest == null ? new Base[0] : this.referralRequest.toArray(new Base[this.referralRequest.size()]); // Reference
1571        case -1147746468: /*careManager*/ return this.careManager == null ? new Base[0] : new Base[] {this.careManager}; // Reference
1572        case 3555933: /*team*/ return this.team == null ? new Base[0] : this.team.toArray(new Base[this.team.size()]); // Reference
1573        case -1177318867: /*account*/ return this.account == null ? new Base[0] : this.account.toArray(new Base[this.account.size()]); // Reference
1574        default: return super.getProperty(hash, name, checkValid);
1575        }
1576
1577      }
1578
1579      @Override
1580      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1581        switch (hash) {
1582        case -1618432855: // identifier
1583          this.getIdentifier().add(castToIdentifier(value)); // Identifier
1584          return value;
1585        case -892481550: // status
1586          value = new EpisodeOfCareStatusEnumFactory().fromType(castToCode(value));
1587          this.status = (Enumeration) value; // Enumeration<EpisodeOfCareStatus>
1588          return value;
1589        case -986695614: // statusHistory
1590          this.getStatusHistory().add((EpisodeOfCareStatusHistoryComponent) value); // EpisodeOfCareStatusHistoryComponent
1591          return value;
1592        case 3575610: // type
1593          this.getType().add(castToCodeableConcept(value)); // CodeableConcept
1594          return value;
1595        case 1196993265: // diagnosis
1596          this.getDiagnosis().add((DiagnosisComponent) value); // DiagnosisComponent
1597          return value;
1598        case -791418107: // patient
1599          this.patient = castToReference(value); // Reference
1600          return value;
1601        case -2058947787: // managingOrganization
1602          this.managingOrganization = castToReference(value); // Reference
1603          return value;
1604        case -991726143: // period
1605          this.period = castToPeriod(value); // Period
1606          return value;
1607        case -310299598: // referralRequest
1608          this.getReferralRequest().add(castToReference(value)); // Reference
1609          return value;
1610        case -1147746468: // careManager
1611          this.careManager = castToReference(value); // Reference
1612          return value;
1613        case 3555933: // team
1614          this.getTeam().add(castToReference(value)); // Reference
1615          return value;
1616        case -1177318867: // account
1617          this.getAccount().add(castToReference(value)); // Reference
1618          return value;
1619        default: return super.setProperty(hash, name, value);
1620        }
1621
1622      }
1623
1624      @Override
1625      public Base setProperty(String name, Base value) throws FHIRException {
1626        if (name.equals("identifier")) {
1627          this.getIdentifier().add(castToIdentifier(value));
1628        } else if (name.equals("status")) {
1629          value = new EpisodeOfCareStatusEnumFactory().fromType(castToCode(value));
1630          this.status = (Enumeration) value; // Enumeration<EpisodeOfCareStatus>
1631        } else if (name.equals("statusHistory")) {
1632          this.getStatusHistory().add((EpisodeOfCareStatusHistoryComponent) value);
1633        } else if (name.equals("type")) {
1634          this.getType().add(castToCodeableConcept(value));
1635        } else if (name.equals("diagnosis")) {
1636          this.getDiagnosis().add((DiagnosisComponent) value);
1637        } else if (name.equals("patient")) {
1638          this.patient = castToReference(value); // Reference
1639        } else if (name.equals("managingOrganization")) {
1640          this.managingOrganization = castToReference(value); // Reference
1641        } else if (name.equals("period")) {
1642          this.period = castToPeriod(value); // Period
1643        } else if (name.equals("referralRequest")) {
1644          this.getReferralRequest().add(castToReference(value));
1645        } else if (name.equals("careManager")) {
1646          this.careManager = castToReference(value); // Reference
1647        } else if (name.equals("team")) {
1648          this.getTeam().add(castToReference(value));
1649        } else if (name.equals("account")) {
1650          this.getAccount().add(castToReference(value));
1651        } else
1652          return super.setProperty(name, value);
1653        return value;
1654      }
1655
1656      @Override
1657      public Base makeProperty(int hash, String name) throws FHIRException {
1658        switch (hash) {
1659        case -1618432855:  return addIdentifier(); 
1660        case -892481550:  return getStatusElement();
1661        case -986695614:  return addStatusHistory(); 
1662        case 3575610:  return addType(); 
1663        case 1196993265:  return addDiagnosis(); 
1664        case -791418107:  return getPatient(); 
1665        case -2058947787:  return getManagingOrganization(); 
1666        case -991726143:  return getPeriod(); 
1667        case -310299598:  return addReferralRequest(); 
1668        case -1147746468:  return getCareManager(); 
1669        case 3555933:  return addTeam(); 
1670        case -1177318867:  return addAccount(); 
1671        default: return super.makeProperty(hash, name);
1672        }
1673
1674      }
1675
1676      @Override
1677      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1678        switch (hash) {
1679        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
1680        case -892481550: /*status*/ return new String[] {"code"};
1681        case -986695614: /*statusHistory*/ return new String[] {};
1682        case 3575610: /*type*/ return new String[] {"CodeableConcept"};
1683        case 1196993265: /*diagnosis*/ return new String[] {};
1684        case -791418107: /*patient*/ return new String[] {"Reference"};
1685        case -2058947787: /*managingOrganization*/ return new String[] {"Reference"};
1686        case -991726143: /*period*/ return new String[] {"Period"};
1687        case -310299598: /*referralRequest*/ return new String[] {"Reference"};
1688        case -1147746468: /*careManager*/ return new String[] {"Reference"};
1689        case 3555933: /*team*/ return new String[] {"Reference"};
1690        case -1177318867: /*account*/ return new String[] {"Reference"};
1691        default: return super.getTypesForProperty(hash, name);
1692        }
1693
1694      }
1695
1696      @Override
1697      public Base addChild(String name) throws FHIRException {
1698        if (name.equals("identifier")) {
1699          return addIdentifier();
1700        }
1701        else if (name.equals("status")) {
1702          throw new FHIRException("Cannot call addChild on a primitive type EpisodeOfCare.status");
1703        }
1704        else if (name.equals("statusHistory")) {
1705          return addStatusHistory();
1706        }
1707        else if (name.equals("type")) {
1708          return addType();
1709        }
1710        else if (name.equals("diagnosis")) {
1711          return addDiagnosis();
1712        }
1713        else if (name.equals("patient")) {
1714          this.patient = new Reference();
1715          return this.patient;
1716        }
1717        else if (name.equals("managingOrganization")) {
1718          this.managingOrganization = new Reference();
1719          return this.managingOrganization;
1720        }
1721        else if (name.equals("period")) {
1722          this.period = new Period();
1723          return this.period;
1724        }
1725        else if (name.equals("referralRequest")) {
1726          return addReferralRequest();
1727        }
1728        else if (name.equals("careManager")) {
1729          this.careManager = new Reference();
1730          return this.careManager;
1731        }
1732        else if (name.equals("team")) {
1733          return addTeam();
1734        }
1735        else if (name.equals("account")) {
1736          return addAccount();
1737        }
1738        else
1739          return super.addChild(name);
1740      }
1741
1742  public String fhirType() {
1743    return "EpisodeOfCare";
1744
1745  }
1746
1747      public EpisodeOfCare copy() {
1748        EpisodeOfCare dst = new EpisodeOfCare();
1749        copyValues(dst);
1750        if (identifier != null) {
1751          dst.identifier = new ArrayList<Identifier>();
1752          for (Identifier i : identifier)
1753            dst.identifier.add(i.copy());
1754        };
1755        dst.status = status == null ? null : status.copy();
1756        if (statusHistory != null) {
1757          dst.statusHistory = new ArrayList<EpisodeOfCareStatusHistoryComponent>();
1758          for (EpisodeOfCareStatusHistoryComponent i : statusHistory)
1759            dst.statusHistory.add(i.copy());
1760        };
1761        if (type != null) {
1762          dst.type = new ArrayList<CodeableConcept>();
1763          for (CodeableConcept i : type)
1764            dst.type.add(i.copy());
1765        };
1766        if (diagnosis != null) {
1767          dst.diagnosis = new ArrayList<DiagnosisComponent>();
1768          for (DiagnosisComponent i : diagnosis)
1769            dst.diagnosis.add(i.copy());
1770        };
1771        dst.patient = patient == null ? null : patient.copy();
1772        dst.managingOrganization = managingOrganization == null ? null : managingOrganization.copy();
1773        dst.period = period == null ? null : period.copy();
1774        if (referralRequest != null) {
1775          dst.referralRequest = new ArrayList<Reference>();
1776          for (Reference i : referralRequest)
1777            dst.referralRequest.add(i.copy());
1778        };
1779        dst.careManager = careManager == null ? null : careManager.copy();
1780        if (team != null) {
1781          dst.team = new ArrayList<Reference>();
1782          for (Reference i : team)
1783            dst.team.add(i.copy());
1784        };
1785        if (account != null) {
1786          dst.account = new ArrayList<Reference>();
1787          for (Reference i : account)
1788            dst.account.add(i.copy());
1789        };
1790        return dst;
1791      }
1792
1793      protected EpisodeOfCare typedCopy() {
1794        return copy();
1795      }
1796
1797      @Override
1798      public boolean equalsDeep(Base other_) {
1799        if (!super.equalsDeep(other_))
1800          return false;
1801        if (!(other_ instanceof EpisodeOfCare))
1802          return false;
1803        EpisodeOfCare o = (EpisodeOfCare) other_;
1804        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(statusHistory, o.statusHistory, true)
1805           && compareDeep(type, o.type, true) && compareDeep(diagnosis, o.diagnosis, true) && compareDeep(patient, o.patient, true)
1806           && compareDeep(managingOrganization, o.managingOrganization, true) && compareDeep(period, o.period, true)
1807           && compareDeep(referralRequest, o.referralRequest, true) && compareDeep(careManager, o.careManager, true)
1808           && compareDeep(team, o.team, true) && compareDeep(account, o.account, true);
1809      }
1810
1811      @Override
1812      public boolean equalsShallow(Base other_) {
1813        if (!super.equalsShallow(other_))
1814          return false;
1815        if (!(other_ instanceof EpisodeOfCare))
1816          return false;
1817        EpisodeOfCare o = (EpisodeOfCare) other_;
1818        return compareValues(status, o.status, true);
1819      }
1820
1821      public boolean isEmpty() {
1822        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, status, statusHistory
1823          , type, diagnosis, patient, managingOrganization, period, referralRequest, careManager
1824          , team, account);
1825      }
1826
1827  @Override
1828  public ResourceType getResourceType() {
1829    return ResourceType.EpisodeOfCare;
1830   }
1831
1832 /**
1833   * Search parameter: <b>date</b>
1834   * <p>
1835   * Description: <b>The provided date search value falls within the episode of care's period</b><br>
1836   * Type: <b>date</b><br>
1837   * Path: <b>EpisodeOfCare.period</b><br>
1838   * </p>
1839   */
1840  @SearchParamDefinition(name="date", path="EpisodeOfCare.period", description="The provided date search value falls within the episode of care's period", type="date" )
1841  public static final String SP_DATE = "date";
1842 /**
1843   * <b>Fluent Client</b> search parameter constant for <b>date</b>
1844   * <p>
1845   * Description: <b>The provided date search value falls within the episode of care's period</b><br>
1846   * Type: <b>date</b><br>
1847   * Path: <b>EpisodeOfCare.period</b><br>
1848   * </p>
1849   */
1850  public static final ca.uhn.fhir.rest.gclient.DateClientParam DATE = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_DATE);
1851
1852 /**
1853   * Search parameter: <b>identifier</b>
1854   * <p>
1855   * Description: <b>Business Identifier(s) relevant for this EpisodeOfCare</b><br>
1856   * Type: <b>token</b><br>
1857   * Path: <b>EpisodeOfCare.identifier</b><br>
1858   * </p>
1859   */
1860  @SearchParamDefinition(name="identifier", path="EpisodeOfCare.identifier", description="Business Identifier(s) relevant for this EpisodeOfCare", type="token" )
1861  public static final String SP_IDENTIFIER = "identifier";
1862 /**
1863   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1864   * <p>
1865   * Description: <b>Business Identifier(s) relevant for this EpisodeOfCare</b><br>
1866   * Type: <b>token</b><br>
1867   * Path: <b>EpisodeOfCare.identifier</b><br>
1868   * </p>
1869   */
1870  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
1871
1872 /**
1873   * Search parameter: <b>condition</b>
1874   * <p>
1875   * Description: <b>Conditions/problems/diagnoses this episode of care is for</b><br>
1876   * Type: <b>reference</b><br>
1877   * Path: <b>EpisodeOfCare.diagnosis.condition</b><br>
1878   * </p>
1879   */
1880  @SearchParamDefinition(name="condition", path="EpisodeOfCare.diagnosis.condition", description="Conditions/problems/diagnoses this episode of care is for", type="reference", target={Condition.class } )
1881  public static final String SP_CONDITION = "condition";
1882 /**
1883   * <b>Fluent Client</b> search parameter constant for <b>condition</b>
1884   * <p>
1885   * Description: <b>Conditions/problems/diagnoses this episode of care is for</b><br>
1886   * Type: <b>reference</b><br>
1887   * Path: <b>EpisodeOfCare.diagnosis.condition</b><br>
1888   * </p>
1889   */
1890  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CONDITION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_CONDITION);
1891
1892/**
1893   * Constant for fluent queries to be used to add include statements. Specifies
1894   * the path value of "<b>EpisodeOfCare:condition</b>".
1895   */
1896  public static final ca.uhn.fhir.model.api.Include INCLUDE_CONDITION = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:condition").toLocked();
1897
1898 /**
1899   * Search parameter: <b>incomingreferral</b>
1900   * <p>
1901   * Description: <b>Incoming Referral Request</b><br>
1902   * Type: <b>reference</b><br>
1903   * Path: <b>EpisodeOfCare.referralRequest</b><br>
1904   * </p>
1905   */
1906  @SearchParamDefinition(name="incomingreferral", path="EpisodeOfCare.referralRequest", description="Incoming Referral Request", type="reference", target={ServiceRequest.class } )
1907  public static final String SP_INCOMINGREFERRAL = "incomingreferral";
1908 /**
1909   * <b>Fluent Client</b> search parameter constant for <b>incomingreferral</b>
1910   * <p>
1911   * Description: <b>Incoming Referral Request</b><br>
1912   * Type: <b>reference</b><br>
1913   * Path: <b>EpisodeOfCare.referralRequest</b><br>
1914   * </p>
1915   */
1916  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam INCOMINGREFERRAL = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_INCOMINGREFERRAL);
1917
1918/**
1919   * Constant for fluent queries to be used to add include statements. Specifies
1920   * the path value of "<b>EpisodeOfCare:incomingreferral</b>".
1921   */
1922  public static final ca.uhn.fhir.model.api.Include INCLUDE_INCOMINGREFERRAL = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:incomingreferral").toLocked();
1923
1924 /**
1925   * Search parameter: <b>patient</b>
1926   * <p>
1927   * Description: <b>The patient who is the focus of this episode of care</b><br>
1928   * Type: <b>reference</b><br>
1929   * Path: <b>EpisodeOfCare.patient</b><br>
1930   * </p>
1931   */
1932  @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 } )
1933  public static final String SP_PATIENT = "patient";
1934 /**
1935   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
1936   * <p>
1937   * Description: <b>The patient who is the focus of this episode of care</b><br>
1938   * Type: <b>reference</b><br>
1939   * Path: <b>EpisodeOfCare.patient</b><br>
1940   * </p>
1941   */
1942  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
1943
1944/**
1945   * Constant for fluent queries to be used to add include statements. Specifies
1946   * the path value of "<b>EpisodeOfCare:patient</b>".
1947   */
1948  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:patient").toLocked();
1949
1950 /**
1951   * Search parameter: <b>organization</b>
1952   * <p>
1953   * Description: <b>The organization that has assumed the specific responsibilities of this EpisodeOfCare</b><br>
1954   * Type: <b>reference</b><br>
1955   * Path: <b>EpisodeOfCare.managingOrganization</b><br>
1956   * </p>
1957   */
1958  @SearchParamDefinition(name="organization", path="EpisodeOfCare.managingOrganization", description="The organization that has assumed the specific responsibilities of this EpisodeOfCare", type="reference", target={Organization.class } )
1959  public static final String SP_ORGANIZATION = "organization";
1960 /**
1961   * <b>Fluent Client</b> search parameter constant for <b>organization</b>
1962   * <p>
1963   * Description: <b>The organization that has assumed the specific responsibilities of this EpisodeOfCare</b><br>
1964   * Type: <b>reference</b><br>
1965   * Path: <b>EpisodeOfCare.managingOrganization</b><br>
1966   * </p>
1967   */
1968  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam ORGANIZATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_ORGANIZATION);
1969
1970/**
1971   * Constant for fluent queries to be used to add include statements. Specifies
1972   * the path value of "<b>EpisodeOfCare:organization</b>".
1973   */
1974  public static final ca.uhn.fhir.model.api.Include INCLUDE_ORGANIZATION = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:organization").toLocked();
1975
1976 /**
1977   * Search parameter: <b>type</b>
1978   * <p>
1979   * Description: <b>Type/class  - e.g. specialist referral, disease management</b><br>
1980   * Type: <b>token</b><br>
1981   * Path: <b>EpisodeOfCare.type</b><br>
1982   * </p>
1983   */
1984  @SearchParamDefinition(name="type", path="EpisodeOfCare.type", description="Type/class  - e.g. specialist referral, disease management", type="token" )
1985  public static final String SP_TYPE = "type";
1986 /**
1987   * <b>Fluent Client</b> search parameter constant for <b>type</b>
1988   * <p>
1989   * Description: <b>Type/class  - e.g. specialist referral, disease management</b><br>
1990   * Type: <b>token</b><br>
1991   * Path: <b>EpisodeOfCare.type</b><br>
1992   * </p>
1993   */
1994  public static final ca.uhn.fhir.rest.gclient.TokenClientParam TYPE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_TYPE);
1995
1996 /**
1997   * Search parameter: <b>care-manager</b>
1998   * <p>
1999   * Description: <b>Care manager/care coordinator for the patient</b><br>
2000   * Type: <b>reference</b><br>
2001   * Path: <b>EpisodeOfCare.careManager</b><br>
2002   * </p>
2003   */
2004  @SearchParamDefinition(name="care-manager", path="EpisodeOfCare.careManager", description="Care manager/care coordinator for the patient", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Practitioner") }, target={Practitioner.class } )
2005  public static final String SP_CARE_MANAGER = "care-manager";
2006 /**
2007   * <b>Fluent Client</b> search parameter constant for <b>care-manager</b>
2008   * <p>
2009   * Description: <b>Care manager/care coordinator for the patient</b><br>
2010   * Type: <b>reference</b><br>
2011   * Path: <b>EpisodeOfCare.careManager</b><br>
2012   * </p>
2013   */
2014  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CARE_MANAGER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_CARE_MANAGER);
2015
2016/**
2017   * Constant for fluent queries to be used to add include statements. Specifies
2018   * the path value of "<b>EpisodeOfCare:care-manager</b>".
2019   */
2020  public static final ca.uhn.fhir.model.api.Include INCLUDE_CARE_MANAGER = new ca.uhn.fhir.model.api.Include("EpisodeOfCare:care-manager").toLocked();
2021
2022 /**
2023   * Search parameter: <b>status</b>
2024   * <p>
2025   * Description: <b>The current status of the Episode of Care as provided (does not check the status history collection)</b><br>
2026   * Type: <b>token</b><br>
2027   * Path: <b>EpisodeOfCare.status</b><br>
2028   * </p>
2029   */
2030  @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" )
2031  public static final String SP_STATUS = "status";
2032 /**
2033   * <b>Fluent Client</b> search parameter constant for <b>status</b>
2034   * <p>
2035   * Description: <b>The current status of the Episode of Care as provided (does not check the status history collection)</b><br>
2036   * Type: <b>token</b><br>
2037   * Path: <b>EpisodeOfCare.status</b><br>
2038   * </p>
2039   */
2040  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_STATUS);
2041
2042
2043}
2044