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