001package org.hl7.fhir.dstu2.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.ArrayList;
034import java.util.Date;
035import java.util.List;
036
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.Description;
039import ca.uhn.fhir.model.api.annotation.ResourceDef;
040import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
041import org.hl7.fhir.exceptions.FHIRException;
042import org.hl7.fhir.utilities.Utilities;
043
044/**
045 * Used to record and send details about a request for referral service or
046 * transfer of a patient to the care of another provider or provider
047 * organization.
048 */
049@ResourceDef(name = "ReferralRequest", profile = "http://hl7.org/fhir/Profile/ReferralRequest")
050public class ReferralRequest extends DomainResource {
051
052  public enum ReferralStatus {
053    /**
054     * A draft referral that has yet to be send.
055     */
056    DRAFT,
057    /**
058     * The referral has been transmitted, but not yet acknowledged by the recipient.
059     */
060    REQUESTED,
061    /**
062     * The referral has been acknowledged by the recipient, and is in the process of
063     * being actioned.
064     */
065    ACTIVE,
066    /**
067     * The referral has been cancelled without being completed. For example it is no
068     * longer needed.
069     */
070    CANCELLED,
071    /**
072     * The recipient has agreed to deliver the care requested by the referral.
073     */
074    ACCEPTED,
075    /**
076     * The recipient has declined to accept the referral.
077     */
078    REJECTED,
079    /**
080     * The referral has been completely actioned.
081     */
082    COMPLETED,
083    /**
084     * added to help the parsers
085     */
086    NULL;
087
088    public static ReferralStatus fromCode(String codeString) throws FHIRException {
089      if (codeString == null || "".equals(codeString))
090        return null;
091      if ("draft".equals(codeString))
092        return DRAFT;
093      if ("requested".equals(codeString))
094        return REQUESTED;
095      if ("active".equals(codeString))
096        return ACTIVE;
097      if ("cancelled".equals(codeString))
098        return CANCELLED;
099      if ("accepted".equals(codeString))
100        return ACCEPTED;
101      if ("rejected".equals(codeString))
102        return REJECTED;
103      if ("completed".equals(codeString))
104        return COMPLETED;
105      throw new FHIRException("Unknown ReferralStatus code '" + codeString + "'");
106    }
107
108    public String toCode() {
109      switch (this) {
110      case DRAFT:
111        return "draft";
112      case REQUESTED:
113        return "requested";
114      case ACTIVE:
115        return "active";
116      case CANCELLED:
117        return "cancelled";
118      case ACCEPTED:
119        return "accepted";
120      case REJECTED:
121        return "rejected";
122      case COMPLETED:
123        return "completed";
124      case NULL:
125        return null;
126      default:
127        return "?";
128      }
129    }
130
131    public String getSystem() {
132      switch (this) {
133      case DRAFT:
134        return "http://hl7.org/fhir/referralstatus";
135      case REQUESTED:
136        return "http://hl7.org/fhir/referralstatus";
137      case ACTIVE:
138        return "http://hl7.org/fhir/referralstatus";
139      case CANCELLED:
140        return "http://hl7.org/fhir/referralstatus";
141      case ACCEPTED:
142        return "http://hl7.org/fhir/referralstatus";
143      case REJECTED:
144        return "http://hl7.org/fhir/referralstatus";
145      case COMPLETED:
146        return "http://hl7.org/fhir/referralstatus";
147      case NULL:
148        return null;
149      default:
150        return "?";
151      }
152    }
153
154    public String getDefinition() {
155      switch (this) {
156      case DRAFT:
157        return "A draft referral that has yet to be send.";
158      case REQUESTED:
159        return "The referral has been transmitted, but not yet acknowledged by the recipient.";
160      case ACTIVE:
161        return "The referral has been acknowledged by the recipient, and is in the process of being actioned.";
162      case CANCELLED:
163        return "The referral has been cancelled without being completed. For example it is no longer needed.";
164      case ACCEPTED:
165        return "The recipient has agreed to deliver the care requested by the referral.";
166      case REJECTED:
167        return "The recipient has declined to accept the referral.";
168      case COMPLETED:
169        return "The referral has been completely actioned.";
170      case NULL:
171        return null;
172      default:
173        return "?";
174      }
175    }
176
177    public String getDisplay() {
178      switch (this) {
179      case DRAFT:
180        return "Draft";
181      case REQUESTED:
182        return "Requested";
183      case ACTIVE:
184        return "Active";
185      case CANCELLED:
186        return "Cancelled";
187      case ACCEPTED:
188        return "Accepted";
189      case REJECTED:
190        return "Rejected";
191      case COMPLETED:
192        return "Completed";
193      case NULL:
194        return null;
195      default:
196        return "?";
197      }
198    }
199  }
200
201  public static class ReferralStatusEnumFactory implements EnumFactory<ReferralStatus> {
202    public ReferralStatus fromCode(String codeString) throws IllegalArgumentException {
203      if (codeString == null || "".equals(codeString))
204        if (codeString == null || "".equals(codeString))
205          return null;
206      if ("draft".equals(codeString))
207        return ReferralStatus.DRAFT;
208      if ("requested".equals(codeString))
209        return ReferralStatus.REQUESTED;
210      if ("active".equals(codeString))
211        return ReferralStatus.ACTIVE;
212      if ("cancelled".equals(codeString))
213        return ReferralStatus.CANCELLED;
214      if ("accepted".equals(codeString))
215        return ReferralStatus.ACCEPTED;
216      if ("rejected".equals(codeString))
217        return ReferralStatus.REJECTED;
218      if ("completed".equals(codeString))
219        return ReferralStatus.COMPLETED;
220      throw new IllegalArgumentException("Unknown ReferralStatus code '" + codeString + "'");
221    }
222
223    public Enumeration<ReferralStatus> fromType(Base code) throws FHIRException {
224      if (code == null || code.isEmpty())
225        return null;
226      String codeString = ((PrimitiveType) code).asStringValue();
227      if (codeString == null || "".equals(codeString))
228        return null;
229      if ("draft".equals(codeString))
230        return new Enumeration<ReferralStatus>(this, ReferralStatus.DRAFT);
231      if ("requested".equals(codeString))
232        return new Enumeration<ReferralStatus>(this, ReferralStatus.REQUESTED);
233      if ("active".equals(codeString))
234        return new Enumeration<ReferralStatus>(this, ReferralStatus.ACTIVE);
235      if ("cancelled".equals(codeString))
236        return new Enumeration<ReferralStatus>(this, ReferralStatus.CANCELLED);
237      if ("accepted".equals(codeString))
238        return new Enumeration<ReferralStatus>(this, ReferralStatus.ACCEPTED);
239      if ("rejected".equals(codeString))
240        return new Enumeration<ReferralStatus>(this, ReferralStatus.REJECTED);
241      if ("completed".equals(codeString))
242        return new Enumeration<ReferralStatus>(this, ReferralStatus.COMPLETED);
243      throw new FHIRException("Unknown ReferralStatus code '" + codeString + "'");
244    }
245
246    public String toCode(ReferralStatus code) {
247      if (code == ReferralStatus.DRAFT)
248        return "draft";
249      if (code == ReferralStatus.REQUESTED)
250        return "requested";
251      if (code == ReferralStatus.ACTIVE)
252        return "active";
253      if (code == ReferralStatus.CANCELLED)
254        return "cancelled";
255      if (code == ReferralStatus.ACCEPTED)
256        return "accepted";
257      if (code == ReferralStatus.REJECTED)
258        return "rejected";
259      if (code == ReferralStatus.COMPLETED)
260        return "completed";
261      return "?";
262    }
263  }
264
265  /**
266   * The workflow status of the referral or transfer of care request.
267   */
268  @Child(name = "status", type = { CodeType.class }, order = 0, min = 1, max = 1, modifier = true, summary = true)
269  @Description(shortDefinition = "draft | requested | active | cancelled | accepted | rejected | completed", formalDefinition = "The workflow status of the referral or transfer of care request.")
270  protected Enumeration<ReferralStatus> status;
271
272  /**
273   * Business identifier that uniquely identifies the referral/care transfer
274   * request instance.
275   */
276  @Child(name = "identifier", type = {
277      Identifier.class }, order = 1, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
278  @Description(shortDefinition = "Business identifier", formalDefinition = "Business identifier that uniquely identifies the referral/care transfer request instance.")
279  protected List<Identifier> identifier;
280
281  /**
282   * Date/DateTime of creation for draft requests and date of activation for
283   * active requests.
284   */
285  @Child(name = "date", type = { DateTimeType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
286  @Description(shortDefinition = "Date of creation/activation", formalDefinition = "Date/DateTime of creation for draft requests and date of activation for active requests.")
287  protected DateTimeType date;
288
289  /**
290   * An indication of the type of referral (or where applicable the type of
291   * transfer of care) request.
292   */
293  @Child(name = "type", type = { CodeableConcept.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
294  @Description(shortDefinition = "Referral/Transition of care request type", formalDefinition = "An indication of the type of referral (or where applicable the type of transfer of care) request.")
295  protected CodeableConcept type;
296
297  /**
298   * Indication of the clinical domain or discipline to which the referral or
299   * transfer of care request is sent. For example: Cardiology Gastroenterology
300   * Diabetology.
301   */
302  @Child(name = "specialty", type = {
303      CodeableConcept.class }, order = 4, min = 0, max = 1, modifier = false, summary = false)
304  @Description(shortDefinition = "The clinical specialty (discipline) that the referral is requested for", formalDefinition = "Indication of the clinical domain or discipline to which the referral or transfer of care request is sent.  For example: Cardiology Gastroenterology Diabetology.")
305  protected CodeableConcept specialty;
306
307  /**
308   * An indication of the urgency of referral (or where applicable the type of
309   * transfer of care) request.
310   */
311  @Child(name = "priority", type = {
312      CodeableConcept.class }, order = 5, min = 0, max = 1, modifier = false, summary = true)
313  @Description(shortDefinition = "Urgency of referral / transfer of care request", formalDefinition = "An indication of the urgency of referral (or where applicable the type of transfer of care) request.")
314  protected CodeableConcept priority;
315
316  /**
317   * The patient who is the subject of a referral or transfer of care request.
318   */
319  @Child(name = "patient", type = { Patient.class }, order = 6, min = 0, max = 1, modifier = false, summary = true)
320  @Description(shortDefinition = "Patient referred to care or transfer", formalDefinition = "The patient who is the subject of a referral or transfer of care request.")
321  protected Reference patient;
322
323  /**
324   * The actual object that is the target of the reference (The patient who is the
325   * subject of a referral or transfer of care request.)
326   */
327  protected Patient patientTarget;
328
329  /**
330   * The healthcare provider or provider organization who/which initiated the
331   * referral/transfer of care request. Can also be Patient (a self referral).
332   */
333  @Child(name = "requester", type = { Practitioner.class, Organization.class,
334      Patient.class }, order = 7, min = 0, max = 1, modifier = false, summary = true)
335  @Description(shortDefinition = "Requester of referral / transfer of care", formalDefinition = "The healthcare provider or provider organization who/which initiated the referral/transfer of care request. Can also be  Patient (a self referral).")
336  protected Reference requester;
337
338  /**
339   * The actual object that is the target of the reference (The healthcare
340   * provider or provider organization who/which initiated the referral/transfer
341   * of care request. Can also be Patient (a self referral).)
342   */
343  protected Resource requesterTarget;
344
345  /**
346   * The healthcare provider(s) or provider organization(s) who/which is to
347   * receive the referral/transfer of care request.
348   */
349  @Child(name = "recipient", type = { Practitioner.class,
350      Organization.class }, order = 8, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
351  @Description(shortDefinition = "Receiver of referral / transfer of care request", formalDefinition = "The healthcare provider(s) or provider organization(s) who/which is to receive the referral/transfer of care request.")
352  protected List<Reference> recipient;
353  /**
354   * The actual objects that are the target of the reference (The healthcare
355   * provider(s) or provider organization(s) who/which is to receive the
356   * referral/transfer of care request.)
357   */
358  protected List<Resource> recipientTarget;
359
360  /**
361   * The encounter at which the request for referral or transfer of care is
362   * initiated.
363   */
364  @Child(name = "encounter", type = { Encounter.class }, order = 9, min = 0, max = 1, modifier = false, summary = false)
365  @Description(shortDefinition = "Originating encounter", formalDefinition = "The encounter at which the request for referral or transfer of care is initiated.")
366  protected Reference encounter;
367
368  /**
369   * The actual object that is the target of the reference (The encounter at which
370   * the request for referral or transfer of care is initiated.)
371   */
372  protected Encounter encounterTarget;
373
374  /**
375   * Date/DateTime the request for referral or transfer of care is sent by the
376   * author.
377   */
378  @Child(name = "dateSent", type = {
379      DateTimeType.class }, order = 10, min = 0, max = 1, modifier = false, summary = true)
380  @Description(shortDefinition = "Date referral/transfer of care request is sent", formalDefinition = "Date/DateTime the request for referral or transfer of care is sent by the author.")
381  protected DateTimeType dateSent;
382
383  /**
384   * Description of clinical condition indicating why referral/transfer of care is
385   * requested. For example: Pathological Anomalies, Disabled (physical or
386   * mental), Behavioral Management.
387   */
388  @Child(name = "reason", type = {
389      CodeableConcept.class }, order = 11, min = 0, max = 1, modifier = false, summary = true)
390  @Description(shortDefinition = "Reason for referral / transfer of care request", formalDefinition = "Description of clinical condition indicating why referral/transfer of care is requested.  For example:  Pathological Anomalies, Disabled (physical or mental),  Behavioral Management.")
391  protected CodeableConcept reason;
392
393  /**
394   * The reason element gives a short description of why the referral is being
395   * made, the description expands on this to support a more complete clinical
396   * summary.
397   */
398  @Child(name = "description", type = {
399      StringType.class }, order = 12, min = 0, max = 1, modifier = false, summary = false)
400  @Description(shortDefinition = "A textual description of the referral", formalDefinition = "The reason element gives a short description of why the referral is being made, the description expands on this to support a more complete clinical summary.")
401  protected StringType description;
402
403  /**
404   * The service(s) that is/are requested to be provided to the patient. For
405   * example: cardiac pacemaker insertion.
406   */
407  @Child(name = "serviceRequested", type = {
408      CodeableConcept.class }, order = 13, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
409  @Description(shortDefinition = "Actions requested as part of the referral", formalDefinition = "The service(s) that is/are requested to be provided to the patient.  For example: cardiac pacemaker insertion.")
410  protected List<CodeableConcept> serviceRequested;
411
412  /**
413   * Any additional (administrative, financial or clinical) information required
414   * to support request for referral or transfer of care. For example: Presenting
415   * problems/chief complaints Medical History Family History Alerts
416   * Allergy/Intolerance and Adverse Reactions Medications
417   * Observations/Assessments (may include cognitive and fundtional assessments)
418   * Diagnostic Reports Care Plan.
419   */
420  @Child(name = "supportingInformation", type = {}, order = 14, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
421  @Description(shortDefinition = "Additonal information to support referral or transfer of care request", formalDefinition = "Any additional (administrative, financial or clinical) information required to support request for referral or transfer of care.  For example: Presenting problems/chief complaints Medical History Family History Alerts Allergy/Intolerance and Adverse Reactions Medications Observations/Assessments (may include cognitive and fundtional assessments) Diagnostic Reports Care Plan.")
422  protected List<Reference> supportingInformation;
423  /**
424   * The actual objects that are the target of the reference (Any additional
425   * (administrative, financial or clinical) information required to support
426   * request for referral or transfer of care. For example: Presenting
427   * problems/chief complaints Medical History Family History Alerts
428   * Allergy/Intolerance and Adverse Reactions Medications
429   * Observations/Assessments (may include cognitive and fundtional assessments)
430   * Diagnostic Reports Care Plan.)
431   */
432  protected List<Resource> supportingInformationTarget;
433
434  /**
435   * The period of time within which the services identified in the
436   * referral/transfer of care is specified or required to occur.
437   */
438  @Child(name = "fulfillmentTime", type = {
439      Period.class }, order = 15, min = 0, max = 1, modifier = false, summary = true)
440  @Description(shortDefinition = "Requested service(s) fulfillment time", formalDefinition = "The period of time within which the services identified in the referral/transfer of care is specified or required to occur.")
441  protected Period fulfillmentTime;
442
443  private static final long serialVersionUID = 1948652599L;
444
445  /*
446   * Constructor
447   */
448  public ReferralRequest() {
449    super();
450  }
451
452  /*
453   * Constructor
454   */
455  public ReferralRequest(Enumeration<ReferralStatus> status) {
456    super();
457    this.status = status;
458  }
459
460  /**
461   * @return {@link #status} (The workflow status of the referral or transfer of
462   *         care request.). This is the underlying object with id, value and
463   *         extensions. The accessor "getStatus" gives direct access to the value
464   */
465  public Enumeration<ReferralStatus> getStatusElement() {
466    if (this.status == null)
467      if (Configuration.errorOnAutoCreate())
468        throw new Error("Attempt to auto-create ReferralRequest.status");
469      else if (Configuration.doAutoCreate())
470        this.status = new Enumeration<ReferralStatus>(new ReferralStatusEnumFactory()); // bb
471    return this.status;
472  }
473
474  public boolean hasStatusElement() {
475    return this.status != null && !this.status.isEmpty();
476  }
477
478  public boolean hasStatus() {
479    return this.status != null && !this.status.isEmpty();
480  }
481
482  /**
483   * @param value {@link #status} (The workflow status of the referral or transfer
484   *              of care request.). This is the underlying object with id, value
485   *              and extensions. The accessor "getStatus" gives direct access to
486   *              the value
487   */
488  public ReferralRequest setStatusElement(Enumeration<ReferralStatus> value) {
489    this.status = value;
490    return this;
491  }
492
493  /**
494   * @return The workflow status of the referral or transfer of care request.
495   */
496  public ReferralStatus getStatus() {
497    return this.status == null ? null : this.status.getValue();
498  }
499
500  /**
501   * @param value The workflow status of the referral or transfer of care request.
502   */
503  public ReferralRequest setStatus(ReferralStatus value) {
504    if (this.status == null)
505      this.status = new Enumeration<ReferralStatus>(new ReferralStatusEnumFactory());
506    this.status.setValue(value);
507    return this;
508  }
509
510  /**
511   * @return {@link #identifier} (Business identifier that uniquely identifies the
512   *         referral/care transfer request instance.)
513   */
514  public List<Identifier> getIdentifier() {
515    if (this.identifier == null)
516      this.identifier = new ArrayList<Identifier>();
517    return this.identifier;
518  }
519
520  public boolean hasIdentifier() {
521    if (this.identifier == null)
522      return false;
523    for (Identifier item : this.identifier)
524      if (!item.isEmpty())
525        return true;
526    return false;
527  }
528
529  /**
530   * @return {@link #identifier} (Business identifier that uniquely identifies the
531   *         referral/care transfer request instance.)
532   */
533  // syntactic sugar
534  public Identifier addIdentifier() { // 3
535    Identifier t = new Identifier();
536    if (this.identifier == null)
537      this.identifier = new ArrayList<Identifier>();
538    this.identifier.add(t);
539    return t;
540  }
541
542  // syntactic sugar
543  public ReferralRequest addIdentifier(Identifier t) { // 3
544    if (t == null)
545      return this;
546    if (this.identifier == null)
547      this.identifier = new ArrayList<Identifier>();
548    this.identifier.add(t);
549    return this;
550  }
551
552  /**
553   * @return {@link #date} (Date/DateTime of creation for draft requests and date
554   *         of activation for active requests.). This is the underlying object
555   *         with id, value and extensions. The accessor "getDate" gives direct
556   *         access to the value
557   */
558  public DateTimeType getDateElement() {
559    if (this.date == null)
560      if (Configuration.errorOnAutoCreate())
561        throw new Error("Attempt to auto-create ReferralRequest.date");
562      else if (Configuration.doAutoCreate())
563        this.date = new DateTimeType(); // bb
564    return this.date;
565  }
566
567  public boolean hasDateElement() {
568    return this.date != null && !this.date.isEmpty();
569  }
570
571  public boolean hasDate() {
572    return this.date != null && !this.date.isEmpty();
573  }
574
575  /**
576   * @param value {@link #date} (Date/DateTime of creation for draft requests and
577   *              date of activation for active requests.). This is the underlying
578   *              object with id, value and extensions. The accessor "getDate"
579   *              gives direct access to the value
580   */
581  public ReferralRequest setDateElement(DateTimeType value) {
582    this.date = value;
583    return this;
584  }
585
586  /**
587   * @return Date/DateTime of creation for draft requests and date of activation
588   *         for active requests.
589   */
590  public Date getDate() {
591    return this.date == null ? null : this.date.getValue();
592  }
593
594  /**
595   * @param value Date/DateTime of creation for draft requests and date of
596   *              activation for active requests.
597   */
598  public ReferralRequest setDate(Date value) {
599    if (value == null)
600      this.date = null;
601    else {
602      if (this.date == null)
603        this.date = new DateTimeType();
604      this.date.setValue(value);
605    }
606    return this;
607  }
608
609  /**
610   * @return {@link #type} (An indication of the type of referral (or where
611   *         applicable the type of transfer of care) request.)
612   */
613  public CodeableConcept getType() {
614    if (this.type == null)
615      if (Configuration.errorOnAutoCreate())
616        throw new Error("Attempt to auto-create ReferralRequest.type");
617      else if (Configuration.doAutoCreate())
618        this.type = new CodeableConcept(); // cc
619    return this.type;
620  }
621
622  public boolean hasType() {
623    return this.type != null && !this.type.isEmpty();
624  }
625
626  /**
627   * @param value {@link #type} (An indication of the type of referral (or where
628   *              applicable the type of transfer of care) request.)
629   */
630  public ReferralRequest setType(CodeableConcept value) {
631    this.type = value;
632    return this;
633  }
634
635  /**
636   * @return {@link #specialty} (Indication of the clinical domain or discipline
637   *         to which the referral or transfer of care request is sent. For
638   *         example: Cardiology Gastroenterology Diabetology.)
639   */
640  public CodeableConcept getSpecialty() {
641    if (this.specialty == null)
642      if (Configuration.errorOnAutoCreate())
643        throw new Error("Attempt to auto-create ReferralRequest.specialty");
644      else if (Configuration.doAutoCreate())
645        this.specialty = new CodeableConcept(); // cc
646    return this.specialty;
647  }
648
649  public boolean hasSpecialty() {
650    return this.specialty != null && !this.specialty.isEmpty();
651  }
652
653  /**
654   * @param value {@link #specialty} (Indication of the clinical domain or
655   *              discipline to which the referral or transfer of care request is
656   *              sent. For example: Cardiology Gastroenterology Diabetology.)
657   */
658  public ReferralRequest setSpecialty(CodeableConcept value) {
659    this.specialty = value;
660    return this;
661  }
662
663  /**
664   * @return {@link #priority} (An indication of the urgency of referral (or where
665   *         applicable the type of transfer of care) request.)
666   */
667  public CodeableConcept getPriority() {
668    if (this.priority == null)
669      if (Configuration.errorOnAutoCreate())
670        throw new Error("Attempt to auto-create ReferralRequest.priority");
671      else if (Configuration.doAutoCreate())
672        this.priority = new CodeableConcept(); // cc
673    return this.priority;
674  }
675
676  public boolean hasPriority() {
677    return this.priority != null && !this.priority.isEmpty();
678  }
679
680  /**
681   * @param value {@link #priority} (An indication of the urgency of referral (or
682   *              where applicable the type of transfer of care) request.)
683   */
684  public ReferralRequest setPriority(CodeableConcept value) {
685    this.priority = value;
686    return this;
687  }
688
689  /**
690   * @return {@link #patient} (The patient who is the subject of a referral or
691   *         transfer of care request.)
692   */
693  public Reference getPatient() {
694    if (this.patient == null)
695      if (Configuration.errorOnAutoCreate())
696        throw new Error("Attempt to auto-create ReferralRequest.patient");
697      else if (Configuration.doAutoCreate())
698        this.patient = new Reference(); // cc
699    return this.patient;
700  }
701
702  public boolean hasPatient() {
703    return this.patient != null && !this.patient.isEmpty();
704  }
705
706  /**
707   * @param value {@link #patient} (The patient who is the subject of a referral
708   *              or transfer of care request.)
709   */
710  public ReferralRequest setPatient(Reference value) {
711    this.patient = value;
712    return this;
713  }
714
715  /**
716   * @return {@link #patient} The actual object that is the target of the
717   *         reference. The reference library doesn't populate this, but you can
718   *         use it to hold the resource if you resolve it. (The patient who is
719   *         the subject of a referral or transfer of care request.)
720   */
721  public Patient getPatientTarget() {
722    if (this.patientTarget == null)
723      if (Configuration.errorOnAutoCreate())
724        throw new Error("Attempt to auto-create ReferralRequest.patient");
725      else if (Configuration.doAutoCreate())
726        this.patientTarget = new Patient(); // aa
727    return this.patientTarget;
728  }
729
730  /**
731   * @param value {@link #patient} The actual object that is the target of the
732   *              reference. The reference library doesn't use these, but you can
733   *              use it to hold the resource if you resolve it. (The patient who
734   *              is the subject of a referral or transfer of care request.)
735   */
736  public ReferralRequest setPatientTarget(Patient value) {
737    this.patientTarget = value;
738    return this;
739  }
740
741  /**
742   * @return {@link #requester} (The healthcare provider or provider organization
743   *         who/which initiated the referral/transfer of care request. Can also
744   *         be Patient (a self referral).)
745   */
746  public Reference getRequester() {
747    if (this.requester == null)
748      if (Configuration.errorOnAutoCreate())
749        throw new Error("Attempt to auto-create ReferralRequest.requester");
750      else if (Configuration.doAutoCreate())
751        this.requester = new Reference(); // cc
752    return this.requester;
753  }
754
755  public boolean hasRequester() {
756    return this.requester != null && !this.requester.isEmpty();
757  }
758
759  /**
760   * @param value {@link #requester} (The healthcare provider or provider
761   *              organization who/which initiated the referral/transfer of care
762   *              request. Can also be Patient (a self referral).)
763   */
764  public ReferralRequest setRequester(Reference value) {
765    this.requester = value;
766    return this;
767  }
768
769  /**
770   * @return {@link #requester} The actual object that is the target of the
771   *         reference. The reference library doesn't populate this, but you can
772   *         use it to hold the resource if you resolve it. (The healthcare
773   *         provider or provider organization who/which initiated the
774   *         referral/transfer of care request. Can also be Patient (a self
775   *         referral).)
776   */
777  public Resource getRequesterTarget() {
778    return this.requesterTarget;
779  }
780
781  /**
782   * @param value {@link #requester} The actual object that is the target of the
783   *              reference. The reference library doesn't use these, but you can
784   *              use it to hold the resource if you resolve it. (The healthcare
785   *              provider or provider organization who/which initiated the
786   *              referral/transfer of care request. Can also be Patient (a self
787   *              referral).)
788   */
789  public ReferralRequest setRequesterTarget(Resource value) {
790    this.requesterTarget = value;
791    return this;
792  }
793
794  /**
795   * @return {@link #recipient} (The healthcare provider(s) or provider
796   *         organization(s) who/which is to receive the referral/transfer of care
797   *         request.)
798   */
799  public List<Reference> getRecipient() {
800    if (this.recipient == null)
801      this.recipient = new ArrayList<Reference>();
802    return this.recipient;
803  }
804
805  public boolean hasRecipient() {
806    if (this.recipient == null)
807      return false;
808    for (Reference item : this.recipient)
809      if (!item.isEmpty())
810        return true;
811    return false;
812  }
813
814  /**
815   * @return {@link #recipient} (The healthcare provider(s) or provider
816   *         organization(s) who/which is to receive the referral/transfer of care
817   *         request.)
818   */
819  // syntactic sugar
820  public Reference addRecipient() { // 3
821    Reference t = new Reference();
822    if (this.recipient == null)
823      this.recipient = new ArrayList<Reference>();
824    this.recipient.add(t);
825    return t;
826  }
827
828  // syntactic sugar
829  public ReferralRequest addRecipient(Reference t) { // 3
830    if (t == null)
831      return this;
832    if (this.recipient == null)
833      this.recipient = new ArrayList<Reference>();
834    this.recipient.add(t);
835    return this;
836  }
837
838  /**
839   * @return {@link #recipient} (The actual objects that are the target of the
840   *         reference. The reference library doesn't populate this, but you can
841   *         use this to hold the resources if you resolvethemt. The healthcare
842   *         provider(s) or provider organization(s) who/which is to receive the
843   *         referral/transfer of care request.)
844   */
845  public List<Resource> getRecipientTarget() {
846    if (this.recipientTarget == null)
847      this.recipientTarget = new ArrayList<Resource>();
848    return this.recipientTarget;
849  }
850
851  /**
852   * @return {@link #encounter} (The encounter at which the request for referral
853   *         or transfer of care is initiated.)
854   */
855  public Reference getEncounter() {
856    if (this.encounter == null)
857      if (Configuration.errorOnAutoCreate())
858        throw new Error("Attempt to auto-create ReferralRequest.encounter");
859      else if (Configuration.doAutoCreate())
860        this.encounter = new Reference(); // cc
861    return this.encounter;
862  }
863
864  public boolean hasEncounter() {
865    return this.encounter != null && !this.encounter.isEmpty();
866  }
867
868  /**
869   * @param value {@link #encounter} (The encounter at which the request for
870   *              referral or transfer of care is initiated.)
871   */
872  public ReferralRequest setEncounter(Reference value) {
873    this.encounter = value;
874    return this;
875  }
876
877  /**
878   * @return {@link #encounter} The actual object that is the target of the
879   *         reference. The reference library doesn't populate this, but you can
880   *         use it to hold the resource if you resolve it. (The encounter at
881   *         which the request for referral or transfer of care is initiated.)
882   */
883  public Encounter getEncounterTarget() {
884    if (this.encounterTarget == null)
885      if (Configuration.errorOnAutoCreate())
886        throw new Error("Attempt to auto-create ReferralRequest.encounter");
887      else if (Configuration.doAutoCreate())
888        this.encounterTarget = new Encounter(); // aa
889    return this.encounterTarget;
890  }
891
892  /**
893   * @param value {@link #encounter} The actual object that is the target of the
894   *              reference. The reference library doesn't use these, but you can
895   *              use it to hold the resource if you resolve it. (The encounter at
896   *              which the request for referral or transfer of care is
897   *              initiated.)
898   */
899  public ReferralRequest setEncounterTarget(Encounter value) {
900    this.encounterTarget = value;
901    return this;
902  }
903
904  /**
905   * @return {@link #dateSent} (Date/DateTime the request for referral or transfer
906   *         of care is sent by the author.). This is the underlying object with
907   *         id, value and extensions. The accessor "getDateSent" gives direct
908   *         access to the value
909   */
910  public DateTimeType getDateSentElement() {
911    if (this.dateSent == null)
912      if (Configuration.errorOnAutoCreate())
913        throw new Error("Attempt to auto-create ReferralRequest.dateSent");
914      else if (Configuration.doAutoCreate())
915        this.dateSent = new DateTimeType(); // bb
916    return this.dateSent;
917  }
918
919  public boolean hasDateSentElement() {
920    return this.dateSent != null && !this.dateSent.isEmpty();
921  }
922
923  public boolean hasDateSent() {
924    return this.dateSent != null && !this.dateSent.isEmpty();
925  }
926
927  /**
928   * @param value {@link #dateSent} (Date/DateTime the request for referral or
929   *              transfer of care is sent by the author.). This is the underlying
930   *              object with id, value and extensions. The accessor "getDateSent"
931   *              gives direct access to the value
932   */
933  public ReferralRequest setDateSentElement(DateTimeType value) {
934    this.dateSent = value;
935    return this;
936  }
937
938  /**
939   * @return Date/DateTime the request for referral or transfer of care is sent by
940   *         the author.
941   */
942  public Date getDateSent() {
943    return this.dateSent == null ? null : this.dateSent.getValue();
944  }
945
946  /**
947   * @param value Date/DateTime the request for referral or transfer of care is
948   *              sent by the author.
949   */
950  public ReferralRequest setDateSent(Date value) {
951    if (value == null)
952      this.dateSent = null;
953    else {
954      if (this.dateSent == null)
955        this.dateSent = new DateTimeType();
956      this.dateSent.setValue(value);
957    }
958    return this;
959  }
960
961  /**
962   * @return {@link #reason} (Description of clinical condition indicating why
963   *         referral/transfer of care is requested. For example: Pathological
964   *         Anomalies, Disabled (physical or mental), Behavioral Management.)
965   */
966  public CodeableConcept getReason() {
967    if (this.reason == null)
968      if (Configuration.errorOnAutoCreate())
969        throw new Error("Attempt to auto-create ReferralRequest.reason");
970      else if (Configuration.doAutoCreate())
971        this.reason = new CodeableConcept(); // cc
972    return this.reason;
973  }
974
975  public boolean hasReason() {
976    return this.reason != null && !this.reason.isEmpty();
977  }
978
979  /**
980   * @param value {@link #reason} (Description of clinical condition indicating
981   *              why referral/transfer of care is requested. For example:
982   *              Pathological Anomalies, Disabled (physical or mental),
983   *              Behavioral Management.)
984   */
985  public ReferralRequest setReason(CodeableConcept value) {
986    this.reason = value;
987    return this;
988  }
989
990  /**
991   * @return {@link #description} (The reason element gives a short description of
992   *         why the referral is being made, the description expands on this to
993   *         support a more complete clinical summary.). This is the underlying
994   *         object with id, value and extensions. The accessor "getDescription"
995   *         gives direct access to the value
996   */
997  public StringType getDescriptionElement() {
998    if (this.description == null)
999      if (Configuration.errorOnAutoCreate())
1000        throw new Error("Attempt to auto-create ReferralRequest.description");
1001      else if (Configuration.doAutoCreate())
1002        this.description = new StringType(); // bb
1003    return this.description;
1004  }
1005
1006  public boolean hasDescriptionElement() {
1007    return this.description != null && !this.description.isEmpty();
1008  }
1009
1010  public boolean hasDescription() {
1011    return this.description != null && !this.description.isEmpty();
1012  }
1013
1014  /**
1015   * @param value {@link #description} (The reason element gives a short
1016   *              description of why the referral is being made, the description
1017   *              expands on this to support a more complete clinical summary.).
1018   *              This is the underlying object with id, value and extensions. The
1019   *              accessor "getDescription" gives direct access to the value
1020   */
1021  public ReferralRequest setDescriptionElement(StringType value) {
1022    this.description = value;
1023    return this;
1024  }
1025
1026  /**
1027   * @return The reason element gives a short description of why the referral is
1028   *         being made, the description expands on this to support a more
1029   *         complete clinical summary.
1030   */
1031  public String getDescription() {
1032    return this.description == null ? null : this.description.getValue();
1033  }
1034
1035  /**
1036   * @param value The reason element gives a short description of why the referral
1037   *              is being made, the description expands on this to support a more
1038   *              complete clinical summary.
1039   */
1040  public ReferralRequest setDescription(String value) {
1041    if (Utilities.noString(value))
1042      this.description = null;
1043    else {
1044      if (this.description == null)
1045        this.description = new StringType();
1046      this.description.setValue(value);
1047    }
1048    return this;
1049  }
1050
1051  /**
1052   * @return {@link #serviceRequested} (The service(s) that is/are requested to be
1053   *         provided to the patient. For example: cardiac pacemaker insertion.)
1054   */
1055  public List<CodeableConcept> getServiceRequested() {
1056    if (this.serviceRequested == null)
1057      this.serviceRequested = new ArrayList<CodeableConcept>();
1058    return this.serviceRequested;
1059  }
1060
1061  public boolean hasServiceRequested() {
1062    if (this.serviceRequested == null)
1063      return false;
1064    for (CodeableConcept item : this.serviceRequested)
1065      if (!item.isEmpty())
1066        return true;
1067    return false;
1068  }
1069
1070  /**
1071   * @return {@link #serviceRequested} (The service(s) that is/are requested to be
1072   *         provided to the patient. For example: cardiac pacemaker insertion.)
1073   */
1074  // syntactic sugar
1075  public CodeableConcept addServiceRequested() { // 3
1076    CodeableConcept t = new CodeableConcept();
1077    if (this.serviceRequested == null)
1078      this.serviceRequested = new ArrayList<CodeableConcept>();
1079    this.serviceRequested.add(t);
1080    return t;
1081  }
1082
1083  // syntactic sugar
1084  public ReferralRequest addServiceRequested(CodeableConcept t) { // 3
1085    if (t == null)
1086      return this;
1087    if (this.serviceRequested == null)
1088      this.serviceRequested = new ArrayList<CodeableConcept>();
1089    this.serviceRequested.add(t);
1090    return this;
1091  }
1092
1093  /**
1094   * @return {@link #supportingInformation} (Any additional (administrative,
1095   *         financial or clinical) information required to support request for
1096   *         referral or transfer of care. For example: Presenting problems/chief
1097   *         complaints Medical History Family History Alerts Allergy/Intolerance
1098   *         and Adverse Reactions Medications Observations/Assessments (may
1099   *         include cognitive and fundtional assessments) Diagnostic Reports Care
1100   *         Plan.)
1101   */
1102  public List<Reference> getSupportingInformation() {
1103    if (this.supportingInformation == null)
1104      this.supportingInformation = new ArrayList<Reference>();
1105    return this.supportingInformation;
1106  }
1107
1108  public boolean hasSupportingInformation() {
1109    if (this.supportingInformation == null)
1110      return false;
1111    for (Reference item : this.supportingInformation)
1112      if (!item.isEmpty())
1113        return true;
1114    return false;
1115  }
1116
1117  /**
1118   * @return {@link #supportingInformation} (Any additional (administrative,
1119   *         financial or clinical) information required to support request for
1120   *         referral or transfer of care. For example: Presenting problems/chief
1121   *         complaints Medical History Family History Alerts Allergy/Intolerance
1122   *         and Adverse Reactions Medications Observations/Assessments (may
1123   *         include cognitive and fundtional assessments) Diagnostic Reports Care
1124   *         Plan.)
1125   */
1126  // syntactic sugar
1127  public Reference addSupportingInformation() { // 3
1128    Reference t = new Reference();
1129    if (this.supportingInformation == null)
1130      this.supportingInformation = new ArrayList<Reference>();
1131    this.supportingInformation.add(t);
1132    return t;
1133  }
1134
1135  // syntactic sugar
1136  public ReferralRequest addSupportingInformation(Reference t) { // 3
1137    if (t == null)
1138      return this;
1139    if (this.supportingInformation == null)
1140      this.supportingInformation = new ArrayList<Reference>();
1141    this.supportingInformation.add(t);
1142    return this;
1143  }
1144
1145  /**
1146   * @return {@link #supportingInformation} (The actual objects that are the
1147   *         target of the reference. The reference library doesn't populate this,
1148   *         but you can use this to hold the resources if you resolvethemt. Any
1149   *         additional (administrative, financial or clinical) information
1150   *         required to support request for referral or transfer of care. For
1151   *         example: Presenting problems/chief complaints Medical History Family
1152   *         History Alerts Allergy/Intolerance and Adverse Reactions Medications
1153   *         Observations/Assessments (may include cognitive and fundtional
1154   *         assessments) Diagnostic Reports Care Plan.)
1155   */
1156  public List<Resource> getSupportingInformationTarget() {
1157    if (this.supportingInformationTarget == null)
1158      this.supportingInformationTarget = new ArrayList<Resource>();
1159    return this.supportingInformationTarget;
1160  }
1161
1162  /**
1163   * @return {@link #fulfillmentTime} (The period of time within which the
1164   *         services identified in the referral/transfer of care is specified or
1165   *         required to occur.)
1166   */
1167  public Period getFulfillmentTime() {
1168    if (this.fulfillmentTime == null)
1169      if (Configuration.errorOnAutoCreate())
1170        throw new Error("Attempt to auto-create ReferralRequest.fulfillmentTime");
1171      else if (Configuration.doAutoCreate())
1172        this.fulfillmentTime = new Period(); // cc
1173    return this.fulfillmentTime;
1174  }
1175
1176  public boolean hasFulfillmentTime() {
1177    return this.fulfillmentTime != null && !this.fulfillmentTime.isEmpty();
1178  }
1179
1180  /**
1181   * @param value {@link #fulfillmentTime} (The period of time within which the
1182   *              services identified in the referral/transfer of care is
1183   *              specified or required to occur.)
1184   */
1185  public ReferralRequest setFulfillmentTime(Period value) {
1186    this.fulfillmentTime = value;
1187    return this;
1188  }
1189
1190  protected void listChildren(List<Property> childrenList) {
1191    super.listChildren(childrenList);
1192    childrenList.add(new Property("status", "code", "The workflow status of the referral or transfer of care request.",
1193        0, java.lang.Integer.MAX_VALUE, status));
1194    childrenList.add(new Property("identifier", "Identifier",
1195        "Business identifier that uniquely identifies the referral/care transfer request instance.", 0,
1196        java.lang.Integer.MAX_VALUE, identifier));
1197    childrenList.add(new Property("date", "dateTime",
1198        "Date/DateTime of creation for draft requests and date of activation for active requests.", 0,
1199        java.lang.Integer.MAX_VALUE, date));
1200    childrenList.add(new Property("type", "CodeableConcept",
1201        "An indication of the type of referral (or where applicable the type of transfer of care) request.", 0,
1202        java.lang.Integer.MAX_VALUE, type));
1203    childrenList.add(new Property("specialty", "CodeableConcept",
1204        "Indication of the clinical domain or discipline to which the referral or transfer of care request is sent.  For example: Cardiology Gastroenterology Diabetology.",
1205        0, java.lang.Integer.MAX_VALUE, specialty));
1206    childrenList.add(new Property("priority", "CodeableConcept",
1207        "An indication of the urgency of referral (or where applicable the type of transfer of care) request.", 0,
1208        java.lang.Integer.MAX_VALUE, priority));
1209    childrenList.add(new Property("patient", "Reference(Patient)",
1210        "The patient who is the subject of a referral or transfer of care request.", 0, java.lang.Integer.MAX_VALUE,
1211        patient));
1212    childrenList.add(new Property("requester", "Reference(Practitioner|Organization|Patient)",
1213        "The healthcare provider or provider organization who/which initiated the referral/transfer of care request. Can also be  Patient (a self referral).",
1214        0, java.lang.Integer.MAX_VALUE, requester));
1215    childrenList.add(new Property("recipient", "Reference(Practitioner|Organization)",
1216        "The healthcare provider(s) or provider organization(s) who/which is to receive the referral/transfer of care request.",
1217        0, java.lang.Integer.MAX_VALUE, recipient));
1218    childrenList.add(new Property("encounter", "Reference(Encounter)",
1219        "The encounter at which the request for referral or transfer of care is initiated.", 0,
1220        java.lang.Integer.MAX_VALUE, encounter));
1221    childrenList.add(new Property("dateSent", "dateTime",
1222        "Date/DateTime the request for referral or transfer of care is sent by the author.", 0,
1223        java.lang.Integer.MAX_VALUE, dateSent));
1224    childrenList.add(new Property("reason", "CodeableConcept",
1225        "Description of clinical condition indicating why referral/transfer of care is requested.  For example:  Pathological Anomalies, Disabled (physical or mental),  Behavioral Management.",
1226        0, java.lang.Integer.MAX_VALUE, reason));
1227    childrenList.add(new Property("description", "string",
1228        "The reason element gives a short description of why the referral is being made, the description expands on this to support a more complete clinical summary.",
1229        0, java.lang.Integer.MAX_VALUE, description));
1230    childrenList.add(new Property("serviceRequested", "CodeableConcept",
1231        "The service(s) that is/are requested to be provided to the patient.  For example: cardiac pacemaker insertion.",
1232        0, java.lang.Integer.MAX_VALUE, serviceRequested));
1233    childrenList.add(new Property("supportingInformation", "Reference(Any)",
1234        "Any additional (administrative, financial or clinical) information required to support request for referral or transfer of care.  For example: Presenting problems/chief complaints Medical History Family History Alerts Allergy/Intolerance and Adverse Reactions Medications Observations/Assessments (may include cognitive and fundtional assessments) Diagnostic Reports Care Plan.",
1235        0, java.lang.Integer.MAX_VALUE, supportingInformation));
1236    childrenList.add(new Property("fulfillmentTime", "Period",
1237        "The period of time within which the services identified in the referral/transfer of care is specified or required to occur.",
1238        0, java.lang.Integer.MAX_VALUE, fulfillmentTime));
1239  }
1240
1241  @Override
1242  public void setProperty(String name, Base value) throws FHIRException {
1243    if (name.equals("status"))
1244      this.status = new ReferralStatusEnumFactory().fromType(value); // Enumeration<ReferralStatus>
1245    else if (name.equals("identifier"))
1246      this.getIdentifier().add(castToIdentifier(value));
1247    else if (name.equals("date"))
1248      this.date = castToDateTime(value); // DateTimeType
1249    else if (name.equals("type"))
1250      this.type = castToCodeableConcept(value); // CodeableConcept
1251    else if (name.equals("specialty"))
1252      this.specialty = castToCodeableConcept(value); // CodeableConcept
1253    else if (name.equals("priority"))
1254      this.priority = castToCodeableConcept(value); // CodeableConcept
1255    else if (name.equals("patient"))
1256      this.patient = castToReference(value); // Reference
1257    else if (name.equals("requester"))
1258      this.requester = castToReference(value); // Reference
1259    else if (name.equals("recipient"))
1260      this.getRecipient().add(castToReference(value));
1261    else if (name.equals("encounter"))
1262      this.encounter = castToReference(value); // Reference
1263    else if (name.equals("dateSent"))
1264      this.dateSent = castToDateTime(value); // DateTimeType
1265    else if (name.equals("reason"))
1266      this.reason = castToCodeableConcept(value); // CodeableConcept
1267    else if (name.equals("description"))
1268      this.description = castToString(value); // StringType
1269    else if (name.equals("serviceRequested"))
1270      this.getServiceRequested().add(castToCodeableConcept(value));
1271    else if (name.equals("supportingInformation"))
1272      this.getSupportingInformation().add(castToReference(value));
1273    else if (name.equals("fulfillmentTime"))
1274      this.fulfillmentTime = castToPeriod(value); // Period
1275    else
1276      super.setProperty(name, value);
1277  }
1278
1279  @Override
1280  public Base addChild(String name) throws FHIRException {
1281    if (name.equals("status")) {
1282      throw new FHIRException("Cannot call addChild on a singleton property ReferralRequest.status");
1283    } else if (name.equals("identifier")) {
1284      return addIdentifier();
1285    } else if (name.equals("date")) {
1286      throw new FHIRException("Cannot call addChild on a singleton property ReferralRequest.date");
1287    } else if (name.equals("type")) {
1288      this.type = new CodeableConcept();
1289      return this.type;
1290    } else if (name.equals("specialty")) {
1291      this.specialty = new CodeableConcept();
1292      return this.specialty;
1293    } else if (name.equals("priority")) {
1294      this.priority = new CodeableConcept();
1295      return this.priority;
1296    } else if (name.equals("patient")) {
1297      this.patient = new Reference();
1298      return this.patient;
1299    } else if (name.equals("requester")) {
1300      this.requester = new Reference();
1301      return this.requester;
1302    } else if (name.equals("recipient")) {
1303      return addRecipient();
1304    } else if (name.equals("encounter")) {
1305      this.encounter = new Reference();
1306      return this.encounter;
1307    } else if (name.equals("dateSent")) {
1308      throw new FHIRException("Cannot call addChild on a singleton property ReferralRequest.dateSent");
1309    } else if (name.equals("reason")) {
1310      this.reason = new CodeableConcept();
1311      return this.reason;
1312    } else if (name.equals("description")) {
1313      throw new FHIRException("Cannot call addChild on a singleton property ReferralRequest.description");
1314    } else if (name.equals("serviceRequested")) {
1315      return addServiceRequested();
1316    } else if (name.equals("supportingInformation")) {
1317      return addSupportingInformation();
1318    } else if (name.equals("fulfillmentTime")) {
1319      this.fulfillmentTime = new Period();
1320      return this.fulfillmentTime;
1321    } else
1322      return super.addChild(name);
1323  }
1324
1325  public String fhirType() {
1326    return "ReferralRequest";
1327
1328  }
1329
1330  public ReferralRequest copy() {
1331    ReferralRequest dst = new ReferralRequest();
1332    copyValues(dst);
1333    dst.status = status == null ? null : status.copy();
1334    if (identifier != null) {
1335      dst.identifier = new ArrayList<Identifier>();
1336      for (Identifier i : identifier)
1337        dst.identifier.add(i.copy());
1338    }
1339    ;
1340    dst.date = date == null ? null : date.copy();
1341    dst.type = type == null ? null : type.copy();
1342    dst.specialty = specialty == null ? null : specialty.copy();
1343    dst.priority = priority == null ? null : priority.copy();
1344    dst.patient = patient == null ? null : patient.copy();
1345    dst.requester = requester == null ? null : requester.copy();
1346    if (recipient != null) {
1347      dst.recipient = new ArrayList<Reference>();
1348      for (Reference i : recipient)
1349        dst.recipient.add(i.copy());
1350    }
1351    ;
1352    dst.encounter = encounter == null ? null : encounter.copy();
1353    dst.dateSent = dateSent == null ? null : dateSent.copy();
1354    dst.reason = reason == null ? null : reason.copy();
1355    dst.description = description == null ? null : description.copy();
1356    if (serviceRequested != null) {
1357      dst.serviceRequested = new ArrayList<CodeableConcept>();
1358      for (CodeableConcept i : serviceRequested)
1359        dst.serviceRequested.add(i.copy());
1360    }
1361    ;
1362    if (supportingInformation != null) {
1363      dst.supportingInformation = new ArrayList<Reference>();
1364      for (Reference i : supportingInformation)
1365        dst.supportingInformation.add(i.copy());
1366    }
1367    ;
1368    dst.fulfillmentTime = fulfillmentTime == null ? null : fulfillmentTime.copy();
1369    return dst;
1370  }
1371
1372  protected ReferralRequest typedCopy() {
1373    return copy();
1374  }
1375
1376  @Override
1377  public boolean equalsDeep(Base other) {
1378    if (!super.equalsDeep(other))
1379      return false;
1380    if (!(other instanceof ReferralRequest))
1381      return false;
1382    ReferralRequest o = (ReferralRequest) other;
1383    return compareDeep(status, o.status, true) && compareDeep(identifier, o.identifier, true)
1384        && compareDeep(date, o.date, true) && compareDeep(type, o.type, true)
1385        && compareDeep(specialty, o.specialty, true) && compareDeep(priority, o.priority, true)
1386        && compareDeep(patient, o.patient, true) && compareDeep(requester, o.requester, true)
1387        && compareDeep(recipient, o.recipient, true) && compareDeep(encounter, o.encounter, true)
1388        && compareDeep(dateSent, o.dateSent, true) && compareDeep(reason, o.reason, true)
1389        && compareDeep(description, o.description, true) && compareDeep(serviceRequested, o.serviceRequested, true)
1390        && compareDeep(supportingInformation, o.supportingInformation, true)
1391        && compareDeep(fulfillmentTime, o.fulfillmentTime, true);
1392  }
1393
1394  @Override
1395  public boolean equalsShallow(Base other) {
1396    if (!super.equalsShallow(other))
1397      return false;
1398    if (!(other instanceof ReferralRequest))
1399      return false;
1400    ReferralRequest o = (ReferralRequest) other;
1401    return compareValues(status, o.status, true) && compareValues(date, o.date, true)
1402        && compareValues(dateSent, o.dateSent, true) && compareValues(description, o.description, true);
1403  }
1404
1405  public boolean isEmpty() {
1406    return super.isEmpty() && (status == null || status.isEmpty()) && (identifier == null || identifier.isEmpty())
1407        && (date == null || date.isEmpty()) && (type == null || type.isEmpty())
1408        && (specialty == null || specialty.isEmpty()) && (priority == null || priority.isEmpty())
1409        && (patient == null || patient.isEmpty()) && (requester == null || requester.isEmpty())
1410        && (recipient == null || recipient.isEmpty()) && (encounter == null || encounter.isEmpty())
1411        && (dateSent == null || dateSent.isEmpty()) && (reason == null || reason.isEmpty())
1412        && (description == null || description.isEmpty()) && (serviceRequested == null || serviceRequested.isEmpty())
1413        && (supportingInformation == null || supportingInformation.isEmpty())
1414        && (fulfillmentTime == null || fulfillmentTime.isEmpty());
1415  }
1416
1417  @Override
1418  public ResourceType getResourceType() {
1419    return ResourceType.ReferralRequest;
1420  }
1421
1422  @SearchParamDefinition(name = "date", path = "ReferralRequest.date", description = "Creation or activation date", type = "date")
1423  public static final String SP_DATE = "date";
1424  @SearchParamDefinition(name = "requester", path = "ReferralRequest.requester", description = "Requester of referral / transfer of care", type = "reference")
1425  public static final String SP_REQUESTER = "requester";
1426  @SearchParamDefinition(name = "specialty", path = "ReferralRequest.specialty", description = "The specialty that the referral is for", type = "token")
1427  public static final String SP_SPECIALTY = "specialty";
1428  @SearchParamDefinition(name = "patient", path = "ReferralRequest.patient", description = "Who the referral is about", type = "reference")
1429  public static final String SP_PATIENT = "patient";
1430  @SearchParamDefinition(name = "recipient", path = "ReferralRequest.recipient", description = "The person that the referral was sent to", type = "reference")
1431  public static final String SP_RECIPIENT = "recipient";
1432  @SearchParamDefinition(name = "type", path = "ReferralRequest.type", description = "The type of the referral", type = "token")
1433  public static final String SP_TYPE = "type";
1434  @SearchParamDefinition(name = "priority", path = "ReferralRequest.priority", description = "The priority assigned to the referral", type = "token")
1435  public static final String SP_PRIORITY = "priority";
1436  @SearchParamDefinition(name = "status", path = "ReferralRequest.status", description = "The status of the referral", type = "token")
1437  public static final String SP_STATUS = "status";
1438
1439}